Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ StatementMacros:
- ITK_CLANG_PRAGMA_PUSH
- ITK_CLANG_PRAGMA_POP
- ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
- ITK_CLANG_SUPPRESS_Wduplicate_enum
- CLANG_PRAGMA_PUSH
- CLANG_PRAGMA_POP
- CLANG_SUPPRESS_Wfloat_equal
Expand Down
4 changes: 3 additions & 1 deletion examples/hello-world/hello.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include "itkPipeline.h"

int main(int argc, char* argv[]) {
int
main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("hello-world", "Hello world example", argc, argv);

std::cout << "Hello Wasm world!" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion include/itkInputTextStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace wasm
*
* \ingroup WebAssemblyInterface
*/
class InputTextStream: public InputStreamBase
class InputTextStream : public InputStreamBase
{
public:
void
Expand Down
21 changes: 13 additions & 8 deletions include/itkMeshJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ meshToMeshJSON(const TMesh * mesh, const WasmMesh<TMesh> * wasmMesh, bool inMemo
}

template <typename TPixel, unsigned int VDimension>
auto meshToMeshJSON(const QuadEdgeMesh<TPixel, VDimension> * mesh, const WasmMesh<QuadEdgeMesh<TPixel, VDimension>> * wasmMesh, bool inMemory) -> MeshJSON
auto
meshToMeshJSON(const QuadEdgeMesh<TPixel, VDimension> * mesh,
const WasmMesh<QuadEdgeMesh<TPixel, VDimension>> * wasmMesh,
bool inMemory) -> MeshJSON
{
using MeshType = QuadEdgeMesh<TPixel, VDimension>;

Expand All @@ -189,13 +192,15 @@ auto meshToMeshJSON(const QuadEdgeMesh<TPixel, VDimension> * mesh, const WasmMes
meshJSON.meshType.pointComponentType = wasm::MapComponentType<typename MeshType::CoordRepType>::JSONFloatTypeEnum;
using PointPixelType = typename MeshType::PixelType;
using ConvertPointPixelTraits = MeshConvertPixelTraits<PointPixelType>;
meshJSON.meshType.pointPixelComponentType = wasm::MapComponentType<typename ConvertPointPixelTraits::ComponentType>::JSONComponentEnum;
meshJSON.meshType.pointPixelComponentType =
wasm::MapComponentType<typename ConvertPointPixelTraits::ComponentType>::JSONComponentEnum;
meshJSON.meshType.pointPixelType = wasm::MapPixelType<PointPixelType>::JSONPixelEnum;
meshJSON.meshType.pointPixelComponents = ConvertPointPixelTraits::GetNumberOfComponents();
meshJSON.meshType.cellComponentType = wasm::MapComponentType<typename MeshType::CellIdentifier>::JSONIntTypeEnum;
using CellPixelType = typename MeshType::CellPixelType;
using ConvertCellPixelTraits = MeshConvertPixelTraits<CellPixelType>;
meshJSON.meshType.cellPixelComponentType = wasm::MapComponentType<typename ConvertPointPixelTraits::ComponentType>::JSONComponentEnum;
meshJSON.meshType.cellPixelComponentType =
wasm::MapComponentType<typename ConvertPointPixelTraits::ComponentType>::JSONComponentEnum;
meshJSON.meshType.cellPixelType = wasm::MapPixelType<CellPixelType>::JSONPixelEnum;
meshJSON.meshType.cellPixelComponents = ConvertCellPixelTraits::GetNumberOfComponents();

Expand All @@ -222,15 +227,15 @@ auto meshToMeshJSON(const QuadEdgeMesh<TPixel, VDimension> * mesh, const WasmMes
{
meshJSON.cellBufferSize = wasmMesh->GetCellBuffer()->Size();

const auto pointsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetPointsBuffer().at(0)) );
const auto pointsAddress = reinterpret_cast<size_t>(&(wasmMesh->GetPointsBuffer().at(0)));
std::ostringstream pointsStream;
pointsStream << "data:application/vnd.itk.address,0:";
pointsStream << pointsAddress;
meshJSON.points = pointsStream.str();
size_t cellsAddress = 0;
if (mesh->GetNumberOfCells() > 0)
{
cellsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetCellBuffer()->at(0)) );
cellsAddress = reinterpret_cast<size_t>(&(wasmMesh->GetCellBuffer()->at(0)));
}
std::ostringstream cellsStream;
cellsStream << "data:application/vnd.itk.address,0:";
Expand All @@ -240,7 +245,7 @@ auto meshToMeshJSON(const QuadEdgeMesh<TPixel, VDimension> * mesh, const WasmMes
size_t pointDataAddress = 0;
if (mesh->GetPointData() != nullptr && mesh->GetPointData()->Size() > 0)
{
pointDataAddress = reinterpret_cast< size_t >( &(wasmMesh->GetPointDataBuffer().at(0)) );
pointDataAddress = reinterpret_cast<size_t>(&(wasmMesh->GetPointDataBuffer().at(0)));
}
std::ostringstream pointDataStream;
pointDataStream << "data:application/vnd.itk.address,0:";
Expand All @@ -250,10 +255,10 @@ auto meshToMeshJSON(const QuadEdgeMesh<TPixel, VDimension> * mesh, const WasmMes
size_t cellDataAddress = 0;
if (mesh->GetCellData() != nullptr && mesh->GetCellData()->Size() > 0)
{
cellDataAddress = reinterpret_cast< size_t >( &(wasmMesh->GetCellDataBuffer().at(0)) );
cellDataAddress = reinterpret_cast<size_t>(&(wasmMesh->GetCellDataBuffer().at(0)));
}
std::ostringstream cellDataStream;
cellDataStream << "data:application/vnd.itk.address,0:";
cellDataStream << "data:application/vnd.itk.address,0:";
cellDataStream << cellDataAddress;
meshJSON.cellData = cellDataStream.str();
}
Expand Down
44 changes: 16 additions & 28 deletions include/itkMeshToWasmMeshFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ MeshToWasmMeshFilter<TMesh>::PrintSelf(std::ostream & os, Indent indent) const
}

template <typename TPixel, unsigned int VDimension>
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::MeshToWasmMeshFilter()
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::MeshToWasmMeshFilter()
{
this->SetNumberOfRequiredInputs(1);

Expand All @@ -149,42 +148,37 @@ MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>

template <typename TPixel, unsigned int VDimension>
ProcessObject::DataObjectPointer
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::MakeOutput(ProcessObject::DataObjectPointerArraySizeType)
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::MakeOutput(ProcessObject::DataObjectPointerArraySizeType)
{
return WasmMeshType::New().GetPointer();
}

template <typename TPixel, unsigned int VDimension>
ProcessObject::DataObjectPointer
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::MakeOutput(const ProcessObject::DataObjectIdentifierType &)
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::MakeOutput(const ProcessObject::DataObjectIdentifierType &)
{
return WasmMeshType::New().GetPointer();
}

template <typename TPixel, unsigned int VDimension>
auto
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::GetOutput() -> WasmMeshType *
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::GetOutput() -> WasmMeshType *
{
// we assume that the first output is of the templated type
return itkDynamicCastInDebugMode<WasmMeshType *>(this->GetPrimaryOutput());
}

template <typename TPixel, unsigned int VDimension>
auto
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::GetOutput() const -> const WasmMeshType *
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::GetOutput() const -> const WasmMeshType *
{
// we assume that the first output is of the templated type
return itkDynamicCastInDebugMode<const WasmMeshType *>(this->GetPrimaryOutput());
}

template <typename TPixel, unsigned int VDimension>
auto
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::GetOutput(unsigned int idx) -> WasmMeshType *
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::GetOutput(unsigned int idx) -> WasmMeshType *
{
auto * out = dynamic_cast<WasmMeshType *>(this->ProcessObject::GetOutput(idx));

Expand All @@ -197,52 +191,47 @@ MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>

template <typename TPixel, unsigned int VDimension>
void
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::SetInput(const MeshType * input)
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::SetInput(const MeshType * input)
{
// Process object is not const-correct so the const_cast is required here
this->ProcessObject::SetNthInput(0, const_cast<MeshType *>(input));
}

template <typename TPixel, unsigned int VDimension>
void
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::SetInput(unsigned int index, const MeshType * mesh)
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::SetInput(unsigned int index, const MeshType * mesh)
{
// Process object is not const-correct so the const_cast is required here
this->ProcessObject::SetNthInput(index, const_cast<MeshType *>(mesh));
}

template <typename TPixel, unsigned int VDimension>
const typename MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::MeshType *
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::GetInput()
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::GetInput()
{
return itkDynamicCastInDebugMode<const MeshType *>(this->GetPrimaryInput());
}

template <typename TPixel, unsigned int VDimension>
const typename MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::MeshType *
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::GetInput(unsigned int idx)
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::GetInput(unsigned int idx)
{
return itkDynamicCastInDebugMode<const MeshType *>(this->ProcessObject::GetInput(idx));
}

template <typename TPixel, unsigned int VDimension>
void
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::GenerateData()
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::GenerateData()
{
// Get the input and output pointers
const MeshType * mesh = this->GetInput();
WasmMeshType * wasmMesh = this->GetOutput();
WasmMeshType * wasmMesh = this->GetOutput();

wasmMesh->SetMesh(mesh);
constexpr bool inMemory = true;
const auto meshJSON = meshToMeshJSON<TPixel, VDimension>(mesh, wasmMesh, inMemory);
std::string serialized{};
auto ec = glz::write<glz::opts{ .prettify = true }>(meshJSON, serialized);
const auto meshJSON = meshToMeshJSON<TPixel, VDimension>(mesh, wasmMesh, inMemory);
std::string serialized{};
auto ec = glz::write<glz::opts{ .prettify = true }>(meshJSON, serialized);
if (ec)
{
itkExceptionMacro("Failed to serialize MeshJSON");
Expand All @@ -253,8 +242,7 @@ MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>

template <typename TPixel, unsigned int VDimension>
void
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>
::PrintSelf(std::ostream & os, Indent indent) const
MeshToWasmMeshFilter<QuadEdgeMesh<TPixel, VDimension>>::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
Expand Down
2 changes: 1 addition & 1 deletion include/itkOutputBinaryStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace wasm
*
* \ingroup WebAssemblyInterface
*/
class OutputBinaryStream: public OutputStreamBase
class OutputBinaryStream : public OutputStreamBase
{
public:
void
Expand Down
58 changes: 34 additions & 24 deletions include/itkOutputMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,49 +166,56 @@ class OutputMesh<itk::QuadEdgeMesh<TPixel, VDimension>>
public:
using MeshType = itk::QuadEdgeMesh<TPixel, VDimension>;

void Set(const MeshType * mesh) {
void
Set(const MeshType * mesh)
{
this->m_Mesh = mesh;
}

const MeshType * Get() const {
const MeshType *
Get() const
{
return this->m_Mesh.GetPointer();
}

/** FileName or output index. */
void SetIdentifier(const std::string & identifier)
void
SetIdentifier(const std::string & identifier)
{
this->m_Identifier = identifier;
}
const std::string & GetIdentifier() const
const std::string &
GetIdentifier() const
{
return this->m_Identifier;
}

OutputMesh() = default;
~OutputMesh() {
if(wasm::Pipeline::get_use_memory_io())
~OutputMesh()
{
if (wasm::Pipeline::get_use_memory_io())
{
#ifndef ITK_WASM_NO_MEMORY_IO
if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty())
if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty())
{
using MeshToWasmMeshFilterType = MeshToWasmMeshFilter<MeshType>;
auto meshToWasmMeshFilter = MeshToWasmMeshFilterType::New();
meshToWasmMeshFilter->SetInput(this->m_Mesh);
meshToWasmMeshFilter->Update();
auto wasmMesh = meshToWasmMeshFilter->GetOutput();
auto wasmMesh = meshToWasmMeshFilter->GetOutput();
const auto index = std::stoi(this->m_Identifier);
setMemoryStoreOutputDataObject(0, index, wasmMesh);

if (this->m_Mesh->GetNumberOfPoints() > 0)
{
const auto pointsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetPointsBuffer().at(0)) );
const auto pointsAddress = reinterpret_cast<size_t>(&(wasmMesh->GetPointsBuffer().at(0)));
const auto pointsSize = wasmMesh->GetPointsBuffer().size() * sizeof(typename MeshType::PointIdentifier);
setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize);
}

if (this->m_Mesh->GetNumberOfCells() > 0)
{
const auto cellsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetCellBuffer()->at(0)) );
const auto cellsAddress = reinterpret_cast<size_t>(&(wasmMesh->GetCellBuffer()->at(0)));
const auto cellsSize = wasmMesh->GetCellBuffer()->Size() * sizeof(typename MeshType::CellIdentifier);
setMemoryStoreOutputArray(0, index, 1, cellsAddress, cellsSize);
}
Expand All @@ -217,42 +224,45 @@ class OutputMesh<itk::QuadEdgeMesh<TPixel, VDimension>>
{
using PointPixelType = typename MeshType::PixelType;
using ConvertPointPixelTraits = MeshConvertPixelTraits<PointPixelType>;
const auto pointDataAddress = reinterpret_cast< size_t >( &(wasmMesh->GetPointDataBuffer().at(0)) );
const auto pointDataSize = wasmMesh->GetPointDataBuffer().size() * sizeof(typename ConvertPointPixelTraits::ComponentType);
const auto pointDataAddress = reinterpret_cast<size_t>(&(wasmMesh->GetPointDataBuffer().at(0)));
const auto pointDataSize =
wasmMesh->GetPointDataBuffer().size() * sizeof(typename ConvertPointPixelTraits::ComponentType);
setMemoryStoreOutputArray(0, index, 2, pointDataAddress, pointDataSize);
}

if (this->m_Mesh->GetCellData() != nullptr && this->m_Mesh->GetCellData()->Size() > 0)
{
using CellPixelType = typename MeshType::CellPixelType;
using ConvertCellPixelTraits = MeshConvertPixelTraits<CellPixelType>;
const auto cellDataAddress = reinterpret_cast< size_t >( &(wasmMesh->GetCellDataBuffer().at(0)) );
const auto cellDataSize = wasmMesh->GetCellDataBuffer().size() * sizeof(typename ConvertCellPixelTraits::ComponentType);
const auto cellDataAddress = reinterpret_cast<size_t>(&(wasmMesh->GetCellDataBuffer().at(0)));
const auto cellDataSize =
wasmMesh->GetCellDataBuffer().size() * sizeof(typename ConvertCellPixelTraits::ComponentType);
setMemoryStoreOutputArray(0, index, 3, cellDataAddress, cellDataSize);
}
}
#else
std::cerr << "Memory IO not supported" << std::endl;
abort();
std::cerr << "Memory IO not supported" << std::endl;
abort();
#endif
}
else
{
#ifndef ITK_WASM_NO_FILESYSTEM_IO
if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty())
if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty())
{
using MeshWriterType = itk::MeshFileWriter<MeshType>;
auto meshWriter = MeshWriterType::New();
meshWriter->SetFileName(this->m_Identifier);
meshWriter->SetInput(this->m_Mesh);
meshWriter->Update();
using MeshWriterType = itk::MeshFileWriter<MeshType>;
auto meshWriter = MeshWriterType::New();
meshWriter->SetFileName(this->m_Identifier);
meshWriter->SetInput(this->m_Mesh);
meshWriter->Update();
}
#else
std::cerr << "Filesystem IO not supported" << std::endl;
abort();
std::cerr << "Filesystem IO not supported" << std::endl;
abort();
#endif
}
}

protected:
typename MeshType::ConstPointer m_Mesh;

Expand Down
2 changes: 1 addition & 1 deletion include/itkOutputTextStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace wasm
*
* \ingroup WebAssemblyInterface
*/
class OutputTextStream: public OutputStreamBase
class OutputTextStream : public OutputStreamBase
{
public:
void
Expand Down
9 changes: 5 additions & 4 deletions include/itkSupportInputTransformTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ namespace wasm

/** \class SupportInputTransformTypes
*
* \brief Instantiatiate a Pipeline functor over multiple transform parameter types and dimensions and match to the input transform type.
* \brief Instantiatiate a Pipeline functor over multiple transform parameter types and dimensions and match to the
input transform type.
*
* Instantiate the PipelineFunctor (function object) over multiple transform types.
* If the input transform matches these parameter types and dimensions, use the compile-time optimized pipeline for that transform type.
* If the input transform matches these parameter types and dimensions, use the compile-time optimized pipeline for
that transform type.
* Otherwise, exit the pipeline with an error identifying the unsupported transform type.
*
* Example usage:
Expand Down Expand Up @@ -120,8 +122,7 @@ class SupportInputTransformTypes
{
using ParameterValueType = TParameterValues;

if (passThrough ||
transformType.parametersValueType == MapComponentType<ParameterValueType>::JSONFloatTypeEnum)
if (passThrough || transformType.parametersValueType == MapComponentType<ParameterValueType>::JSONFloatTypeEnum)
{
using TransformType = Transform<ParameterValueType, VDimension, VDimension>;

Expand Down
Loading
Loading