diff --git a/.clang-format b/.clang-format index 7252d3eee..2fd9142be 100644 --- a/.clang-format +++ b/.clang-format @@ -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 diff --git a/examples/hello-world/hello.cxx b/examples/hello-world/hello.cxx index 04ec5daa8..49a19c5de 100644 --- a/examples/hello-world/hello.cxx +++ b/examples/hello-world/hello.cxx @@ -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; diff --git a/include/itkInputTextStream.h b/include/itkInputTextStream.h index 7bb602083..58fc3fdce 100644 --- a/include/itkInputTextStream.h +++ b/include/itkInputTextStream.h @@ -34,7 +34,7 @@ namespace wasm * * \ingroup WebAssemblyInterface */ -class InputTextStream: public InputStreamBase +class InputTextStream : public InputStreamBase { public: void diff --git a/include/itkMeshJSON.h b/include/itkMeshJSON.h index 1dcda5251..e4a971849 100644 --- a/include/itkMeshJSON.h +++ b/include/itkMeshJSON.h @@ -178,7 +178,10 @@ meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool inMemo } template -auto meshToMeshJSON(const QuadEdgeMesh * mesh, const WasmMesh> * wasmMesh, bool inMemory) -> MeshJSON +auto +meshToMeshJSON(const QuadEdgeMesh * mesh, + const WasmMesh> * wasmMesh, + bool inMemory) -> MeshJSON { using MeshType = QuadEdgeMesh; @@ -189,13 +192,15 @@ auto meshToMeshJSON(const QuadEdgeMesh * mesh, const WasmMes meshJSON.meshType.pointComponentType = wasm::MapComponentType::JSONFloatTypeEnum; using PointPixelType = typename MeshType::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - meshJSON.meshType.pointPixelComponentType = wasm::MapComponentType::JSONComponentEnum; + meshJSON.meshType.pointPixelComponentType = + wasm::MapComponentType::JSONComponentEnum; meshJSON.meshType.pointPixelType = wasm::MapPixelType::JSONPixelEnum; meshJSON.meshType.pointPixelComponents = ConvertPointPixelTraits::GetNumberOfComponents(); meshJSON.meshType.cellComponentType = wasm::MapComponentType::JSONIntTypeEnum; using CellPixelType = typename MeshType::CellPixelType; using ConvertCellPixelTraits = MeshConvertPixelTraits; - meshJSON.meshType.cellPixelComponentType = wasm::MapComponentType::JSONComponentEnum; + meshJSON.meshType.cellPixelComponentType = + wasm::MapComponentType::JSONComponentEnum; meshJSON.meshType.cellPixelType = wasm::MapPixelType::JSONPixelEnum; meshJSON.meshType.cellPixelComponents = ConvertCellPixelTraits::GetNumberOfComponents(); @@ -222,7 +227,7 @@ auto meshToMeshJSON(const QuadEdgeMesh * mesh, const WasmMes { meshJSON.cellBufferSize = wasmMesh->GetCellBuffer()->Size(); - const auto pointsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetPointsBuffer().at(0)) ); + const auto pointsAddress = reinterpret_cast(&(wasmMesh->GetPointsBuffer().at(0))); std::ostringstream pointsStream; pointsStream << "data:application/vnd.itk.address,0:"; pointsStream << pointsAddress; @@ -230,7 +235,7 @@ auto meshToMeshJSON(const QuadEdgeMesh * mesh, const WasmMes size_t cellsAddress = 0; if (mesh->GetNumberOfCells() > 0) { - cellsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetCellBuffer()->at(0)) ); + cellsAddress = reinterpret_cast(&(wasmMesh->GetCellBuffer()->at(0))); } std::ostringstream cellsStream; cellsStream << "data:application/vnd.itk.address,0:"; @@ -240,7 +245,7 @@ auto meshToMeshJSON(const QuadEdgeMesh * 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(&(wasmMesh->GetPointDataBuffer().at(0))); } std::ostringstream pointDataStream; pointDataStream << "data:application/vnd.itk.address,0:"; @@ -250,10 +255,10 @@ auto meshToMeshJSON(const QuadEdgeMesh * 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(&(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(); } diff --git a/include/itkMeshToWasmMeshFilter.hxx b/include/itkMeshToWasmMeshFilter.hxx index a5faeb23b..f06fa3b20 100644 --- a/include/itkMeshToWasmMeshFilter.hxx +++ b/include/itkMeshToWasmMeshFilter.hxx @@ -137,8 +137,7 @@ MeshToWasmMeshFilter::PrintSelf(std::ostream & os, Indent indent) const } template -MeshToWasmMeshFilter> -::MeshToWasmMeshFilter() +MeshToWasmMeshFilter>::MeshToWasmMeshFilter() { this->SetNumberOfRequiredInputs(1); @@ -149,24 +148,21 @@ MeshToWasmMeshFilter> template ProcessObject::DataObjectPointer -MeshToWasmMeshFilter> -::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) +MeshToWasmMeshFilter>::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return WasmMeshType::New().GetPointer(); } template ProcessObject::DataObjectPointer -MeshToWasmMeshFilter> -::MakeOutput(const ProcessObject::DataObjectIdentifierType &) +MeshToWasmMeshFilter>::MakeOutput(const ProcessObject::DataObjectIdentifierType &) { return WasmMeshType::New().GetPointer(); } template auto -MeshToWasmMeshFilter> -::GetOutput() -> WasmMeshType * +MeshToWasmMeshFilter>::GetOutput() -> WasmMeshType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -174,8 +170,7 @@ MeshToWasmMeshFilter> template auto -MeshToWasmMeshFilter> -::GetOutput() const -> const WasmMeshType * +MeshToWasmMeshFilter>::GetOutput() const -> const WasmMeshType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -183,8 +178,7 @@ MeshToWasmMeshFilter> template auto -MeshToWasmMeshFilter> -::GetOutput(unsigned int idx) -> WasmMeshType * +MeshToWasmMeshFilter>::GetOutput(unsigned int idx) -> WasmMeshType * { auto * out = dynamic_cast(this->ProcessObject::GetOutput(idx)); @@ -197,8 +191,7 @@ MeshToWasmMeshFilter> template void -MeshToWasmMeshFilter> -::SetInput(const MeshType * input) +MeshToWasmMeshFilter>::SetInput(const MeshType * input) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(0, const_cast(input)); @@ -206,8 +199,7 @@ MeshToWasmMeshFilter> template void -MeshToWasmMeshFilter> -::SetInput(unsigned int index, const MeshType * mesh) +MeshToWasmMeshFilter>::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(mesh)); @@ -215,34 +207,31 @@ MeshToWasmMeshFilter> template const typename MeshToWasmMeshFilter>::MeshType * -MeshToWasmMeshFilter> -::GetInput() +MeshToWasmMeshFilter>::GetInput() { return itkDynamicCastInDebugMode(this->GetPrimaryInput()); } template const typename MeshToWasmMeshFilter>::MeshType * -MeshToWasmMeshFilter> -::GetInput(unsigned int idx) +MeshToWasmMeshFilter>::GetInput(unsigned int idx) { return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(idx)); } template void -MeshToWasmMeshFilter> -::GenerateData() +MeshToWasmMeshFilter>::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(mesh, wasmMesh, inMemory); - std::string serialized{}; - auto ec = glz::write(meshJSON, serialized); + const auto meshJSON = meshToMeshJSON(mesh, wasmMesh, inMemory); + std::string serialized{}; + auto ec = glz::write(meshJSON, serialized); if (ec) { itkExceptionMacro("Failed to serialize MeshJSON"); @@ -253,8 +242,7 @@ MeshToWasmMeshFilter> template void -MeshToWasmMeshFilter> -::PrintSelf(std::ostream & os, Indent indent) const +MeshToWasmMeshFilter>::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); } diff --git a/include/itkOutputBinaryStream.h b/include/itkOutputBinaryStream.h index f965be8dd..be45e2e06 100644 --- a/include/itkOutputBinaryStream.h +++ b/include/itkOutputBinaryStream.h @@ -34,7 +34,7 @@ namespace wasm * * \ingroup WebAssemblyInterface */ -class OutputBinaryStream: public OutputStreamBase +class OutputBinaryStream : public OutputStreamBase { public: void diff --git a/include/itkOutputMesh.h b/include/itkOutputMesh.h index 8608f418d..b5e2c7dd7 100644 --- a/include/itkOutputMesh.h +++ b/include/itkOutputMesh.h @@ -166,49 +166,56 @@ class OutputMesh> public: using MeshType = itk::QuadEdgeMesh; - 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; 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(&(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(&(wasmMesh->GetCellBuffer()->at(0))); const auto cellsSize = wasmMesh->GetCellBuffer()->Size() * sizeof(typename MeshType::CellIdentifier); setMemoryStoreOutputArray(0, index, 1, cellsAddress, cellsSize); } @@ -217,8 +224,9 @@ class OutputMesh> { using PointPixelType = typename MeshType::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - 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(&(wasmMesh->GetPointDataBuffer().at(0))); + const auto pointDataSize = + wasmMesh->GetPointDataBuffer().size() * sizeof(typename ConvertPointPixelTraits::ComponentType); setMemoryStoreOutputArray(0, index, 2, pointDataAddress, pointDataSize); } @@ -226,33 +234,35 @@ class OutputMesh> { using CellPixelType = typename MeshType::CellPixelType; using ConvertCellPixelTraits = MeshConvertPixelTraits; - 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(&(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; - auto meshWriter = MeshWriterType::New(); - meshWriter->SetFileName(this->m_Identifier); - meshWriter->SetInput(this->m_Mesh); - meshWriter->Update(); + using MeshWriterType = itk::MeshFileWriter; + 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; diff --git a/include/itkOutputTextStream.h b/include/itkOutputTextStream.h index 377ad2f76..2760687b4 100644 --- a/include/itkOutputTextStream.h +++ b/include/itkOutputTextStream.h @@ -34,7 +34,7 @@ namespace wasm * * \ingroup WebAssemblyInterface */ -class OutputTextStream: public OutputStreamBase +class OutputTextStream : public OutputStreamBase { public: void diff --git a/include/itkSupportInputTransformTypes.h b/include/itkSupportInputTransformTypes.h index 5921f5dac..6a0e7ed2e 100644 --- a/include/itkSupportInputTransformTypes.h +++ b/include/itkSupportInputTransformTypes.h @@ -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: @@ -120,8 +122,7 @@ class SupportInputTransformTypes { using ParameterValueType = TParameterValues; - if (passThrough || - transformType.parametersValueType == MapComponentType::JSONFloatTypeEnum) + if (passThrough || transformType.parametersValueType == MapComponentType::JSONFloatTypeEnum) { using TransformType = Transform; diff --git a/include/itkWasmMesh.h b/include/itkWasmMesh.h index 7f9b156a5..4a9009fe5 100644 --- a/include/itkWasmMesh.h +++ b/include/itkWasmMesh.h @@ -71,16 +71,14 @@ class ITK_TEMPLATE_EXPORT WasmMesh : public WasmDataObject return static_cast(this->GetDataObject()); } - const CellBufferType * GetCellBuffer() const + const CellBufferType * + GetCellBuffer() const { return this->m_CellBuffer.GetPointer(); } protected: - WasmMesh() - { - this->m_CellBuffer = CellBufferType::New(); - } + WasmMesh() { this->m_CellBuffer = CellBufferType::New(); } ~WasmMesh() override = default; typename CellBufferType::Pointer m_CellBuffer; @@ -113,38 +111,46 @@ class WasmMesh> : public WasmDataObject using PointDataBufferType = std::vector; using CellDataBufferType = std::vector; - void SetMesh(const MeshType * mesh); + void + SetMesh(const MeshType * mesh); - const MeshType * GetMesh() const { - return static_cast< const MeshType * >(this->GetDataObject()); + const MeshType * + GetMesh() const + { + return static_cast(this->GetDataObject()); } - const PointsBufferType & GetPointsBuffer() const { + const PointsBufferType & + GetPointsBuffer() const + { return this->m_PointsBuffer; } - const CellBufferType * GetCellBuffer() const { + const CellBufferType * + GetCellBuffer() const + { return this->m_CellBuffer.GetPointer(); } - const PointDataBufferType & GetPointDataBuffer() const { + const PointDataBufferType & + GetPointDataBuffer() const + { return this->m_PointDataBuffer; } - const CellDataBufferType & GetCellDataBuffer() const { + const CellDataBufferType & + GetCellDataBuffer() const + { return this->m_CellDataBuffer; } - WasmMesh() - { - this->m_CellBuffer = CellBufferType::New(); - } + WasmMesh() { this->m_CellBuffer = CellBufferType::New(); } ~WasmMesh() override = default; - PointsBufferType m_PointsBuffer; + PointsBufferType m_PointsBuffer; typename CellBufferType::Pointer m_CellBuffer; - PointDataBufferType m_PointDataBuffer; - CellDataBufferType m_CellDataBuffer; + PointDataBufferType m_PointDataBuffer; + CellDataBufferType m_CellDataBuffer; }; diff --git a/include/itkWasmMesh.hxx b/include/itkWasmMesh.hxx index 5d664126a..ed1f052f3 100644 --- a/include/itkWasmMesh.hxx +++ b/include/itkWasmMesh.hxx @@ -33,8 +33,7 @@ WasmMesh::SetMesh(const MeshType * mesh) template void -WasmMesh> -::SetMesh(const MeshType * mesh) +WasmMesh>::SetMesh(const MeshType * mesh) { m_PointsBuffer.resize(mesh->GetNumberOfPoints() * VDimension); for (unsigned int i = 0; i < mesh->GetNumberOfPoints(); ++i) diff --git a/include/itkWasmMeshToMeshFilter.hxx b/include/itkWasmMeshToMeshFilter.hxx index 2feed7698..43aa468c5 100644 --- a/include/itkWasmMeshToMeshFilter.hxx +++ b/include/itkWasmMeshToMeshFilter.hxx @@ -136,7 +136,7 @@ populateCells(TMesh * mesh, itk::SizeValueType cellBufferSize, TCellBufferType * } CellAutoPointer cell; - auto * polylineCell = new PolyLineCellType; + auto * polylineCell = new PolyLineCellType; for (unsigned int jj = 0; jj < cellPoints; ++jj) { polylineCell->SetPointId(jj, static_cast(cellsBufferPtr[index++])); @@ -461,9 +461,10 @@ WasmMeshToMeshFilter::GenerateData() const SizeValueType cellBufferSize = meshJSON.cellBufferSize; - const std::string cellsString = meshJSON.cells; + const std::string cellsString = meshJSON.cells; using CellBufferType = typename WasmMeshType::CellBufferType::Element; - CellBufferType * cellsBufferPtr = reinterpret_cast< CellBufferType * >( static_cast< size_t >(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10)) ); + CellBufferType * cellsBufferPtr = + reinterpret_cast(static_cast(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10))); if (cellComponentType == JSONIntTypesEnum::uint32) { uint32_t * cellsBufferPtr = @@ -513,8 +514,7 @@ WasmMeshToMeshFilter::PrintSelf(std::ostream & os, Indent indent) const } template -WasmMeshToMeshFilter> -::WasmMeshToMeshFilter() +WasmMeshToMeshFilter>::WasmMeshToMeshFilter() { this->SetNumberOfRequiredInputs(1); @@ -525,24 +525,21 @@ WasmMeshToMeshFilter> template ProcessObject::DataObjectPointer -WasmMeshToMeshFilter> -::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) +WasmMeshToMeshFilter>::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return MeshType::New().GetPointer(); } template ProcessObject::DataObjectPointer -WasmMeshToMeshFilter> -::MakeOutput(const ProcessObject::DataObjectIdentifierType &) +WasmMeshToMeshFilter>::MakeOutput(const ProcessObject::DataObjectIdentifierType &) { return MeshType::New().GetPointer(); } template auto -WasmMeshToMeshFilter> -::GetOutput() -> MeshType * +WasmMeshToMeshFilter>::GetOutput() -> MeshType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -550,8 +547,7 @@ WasmMeshToMeshFilter> template auto -WasmMeshToMeshFilter> -::GetOutput() const -> const MeshType * +WasmMeshToMeshFilter>::GetOutput() const -> const MeshType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -559,8 +555,7 @@ WasmMeshToMeshFilter> template auto -WasmMeshToMeshFilter> -::GetOutput(unsigned int idx) -> MeshType * +WasmMeshToMeshFilter>::GetOutput(unsigned int idx) -> MeshType * { auto * out = dynamic_cast(this->ProcessObject::GetOutput(idx)); @@ -573,8 +568,7 @@ WasmMeshToMeshFilter> template void -WasmMeshToMeshFilter> -::SetInput(const WasmMeshType * input) +WasmMeshToMeshFilter>::SetInput(const WasmMeshType * input) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(0, const_cast(input)); @@ -582,8 +576,7 @@ WasmMeshToMeshFilter> template void -WasmMeshToMeshFilter> -::SetInput(unsigned int index, const WasmMeshType * mesh) +WasmMeshToMeshFilter>::SetInput(unsigned int index, const WasmMeshType * mesh) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(index, const_cast(mesh)); @@ -591,28 +584,25 @@ WasmMeshToMeshFilter> template const typename WasmMeshToMeshFilter>::WasmMeshType * -WasmMeshToMeshFilter> -::GetInput() +WasmMeshToMeshFilter>::GetInput() { return itkDynamicCastInDebugMode(this->GetPrimaryInput()); } template const typename WasmMeshToMeshFilter>::WasmMeshType * -WasmMeshToMeshFilter> -::GetInput(unsigned int idx) +WasmMeshToMeshFilter>::GetInput(unsigned int idx) { return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(idx)); } template void -WasmMeshToMeshFilter> -::GenerateData() +WasmMeshToMeshFilter>::GenerateData() { // Get the input and output pointers const WasmMeshType * wasmMesh = this->GetInput(); - MeshType * mesh = this->GetOutput(); + MeshType * mesh = this->GetOutput(); using PointPixelType = typename MeshType::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; @@ -620,7 +610,7 @@ WasmMeshToMeshFilter> using ConvertCellPixelTraits = MeshConvertPixelTraits; const std::string json(wasmMesh->GetJSON()); - auto deserializedAttempt = glz::read_json(json); + auto deserializedAttempt = glz::read_json(json); if (!deserializedAttempt) { const std::string descriptiveError = glz::format_error(deserializedAttempt, json); @@ -644,22 +634,26 @@ WasmMeshToMeshFilter> { throw std::runtime_error("Unexpected dimension"); } - if (numberOfPointPixels && pointPixelComponentType != itk::wasm::MapComponentType::JSONComponentEnum ) + if (numberOfPointPixels && + pointPixelComponentType != + itk::wasm::MapComponentType::JSONComponentEnum) { throw std::runtime_error("Unexpected point pixel component type"); } - if (numberOfPointPixels && pointPixelType != itk::wasm::MapPixelType::JSONPixelEnum ) + if (numberOfPointPixels && pointPixelType != itk::wasm::MapPixelType::JSONPixelEnum) { throw std::runtime_error("Unexpected point pixel type"); } - if (numberOfCellPixels && cellPixelComponentType != itk::wasm::MapComponentType::JSONComponentEnum ) + if (numberOfCellPixels && + cellPixelComponentType != + itk::wasm::MapComponentType::JSONComponentEnum) { throw std::runtime_error("Unexpected cell pixel component type"); } - if (numberOfCellPixels && cellPixelType != itk::wasm::MapPixelType::JSONPixelEnum ) + if (numberOfCellPixels && cellPixelType != itk::wasm::MapPixelType::JSONPixelEnum) { throw std::runtime_error("Unexpected cell pixel type"); } @@ -672,7 +666,8 @@ WasmMeshToMeshFilter> { if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) { - const auto * pointsPtr = reinterpret_cast< PointType * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); + const auto * pointsPtr = + reinterpret_cast(std::strtoull(pointsString.substr(35).c_str(), nullptr, 10)); for (SizeValueType i = 0; i < meshJSON.numberOfPoints; ++i) { mesh->SetPoint(i, pointsPtr[i]); @@ -680,7 +675,7 @@ WasmMeshToMeshFilter> } else if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) { - auto * pointsPtr = reinterpret_cast< float * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); + auto * pointsPtr = reinterpret_cast(std::strtoull(pointsString.substr(35).c_str(), nullptr, 10)); for (SizeValueType i = 0; i < meshJSON.numberOfPoints; ++i) { PointType point; @@ -693,7 +688,7 @@ WasmMeshToMeshFilter> } else if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) { - auto * pointsPtr = reinterpret_cast< double * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); + auto * pointsPtr = reinterpret_cast(std::strtoull(pointsString.substr(35).c_str(), nullptr, 10)); for (SizeValueType i = 0; i < meshJSON.numberOfPoints; ++i) { PointType point; @@ -712,17 +707,20 @@ WasmMeshToMeshFilter> const SizeValueType cellBufferSize = meshJSON.cellBufferSize; - const std::string cellsString = meshJSON.cells; + const std::string cellsString = meshJSON.cells; using CellBufferType = typename WasmMeshType::CellIdentifier; - CellBufferType * cellsBufferPtr = reinterpret_cast< CellBufferType * >( static_cast< size_t >(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10)) ); + CellBufferType * cellsBufferPtr = + reinterpret_cast(static_cast(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10))); if (cellComponentType == JSONIntTypesEnum::uint32) { - uint32_t * cellsBufferPtr = reinterpret_cast< uint32_t * >( static_cast< size_t >(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10)) ); + uint32_t * cellsBufferPtr = + reinterpret_cast(static_cast(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10))); populateCells(mesh, cellBufferSize, cellsBufferPtr); } else if (cellComponentType == JSONIntTypesEnum::uint64) { - uint64_t * cellsBufferPtr = reinterpret_cast< uint64_t * >( static_cast< size_t >(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10)) ); + uint64_t * cellsBufferPtr = + reinterpret_cast(static_cast(std::strtoull(cellsString.substr(35).c_str(), nullptr, 10))); populateCells(mesh, cellBufferSize, cellsBufferPtr); } else @@ -732,7 +730,8 @@ WasmMeshToMeshFilter> using PointPixelType = typename MeshType::PixelType; const std::string pointDataString = meshJSON.pointData; - auto pointDataPtr = reinterpret_cast< PointPixelType * >( std::strtoull(pointDataString.substr(35).c_str(), nullptr, 10) ); + auto pointDataPtr = + reinterpret_cast(std::strtoull(pointDataString.substr(35).c_str(), nullptr, 10)); mesh->GetPointData()->Reserve(numberOfPointPixels); for (SizeValueType i = 0; i < numberOfPointPixels; ++i) { @@ -741,7 +740,7 @@ WasmMeshToMeshFilter> using CellPixelType = typename MeshType::CellPixelType; const std::string cellDataString = meshJSON.cellData; - auto cellDataPtr = reinterpret_cast< CellPixelType * >( std::strtoull(cellDataString.substr(35).c_str(), nullptr, 10) ); + auto cellDataPtr = reinterpret_cast(std::strtoull(cellDataString.substr(35).c_str(), nullptr, 10)); if (mesh->GetCellData() == nullptr) { mesh->SetCellData(MeshType::CellDataContainer::New()); @@ -761,8 +760,7 @@ WasmMeshToMeshFilter> template void -WasmMeshToMeshFilter> -::PrintSelf(std::ostream & os, Indent indent) const +WasmMeshToMeshFilter>::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); } diff --git a/include/itkWasmTransformIO.h b/include/itkWasmTransformIO.h index 24d7ab176..0bf73221d 100644 --- a/include/itkWasmTransformIO.h +++ b/include/itkWasmTransformIO.h @@ -147,6 +147,7 @@ ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes") extern template class WebAssemblyInterface_EXPORT_EXPLICIT WasmTransformIOTemplate; extern template class WebAssemblyInterface_EXPORT_EXPLICIT WasmTransformIOTemplate; +using WasmTransformIO = WasmTransformIOTemplate; ITK_GCC_PRAGMA_DIAG_POP() diff --git a/packages/compare-meshes/compare-meshes/compare-meshes.cxx b/packages/compare-meshes/compare-meshes/compare-meshes.cxx index 486abc739..d72bffb06 100644 --- a/packages/compare-meshes/compare-meshes/compare-meshes.cxx +++ b/packages/compare-meshes/compare-meshes/compare-meshes.cxx @@ -643,16 +643,9 @@ main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("compare-meshes", "Compare meshes with a tolerance for regression testing.", argc, argv); - return itk::wasm::SupportInputMeshTypes:: - Dimensions< - // 2U, - 3U>("test-mesh", pipeline); + return itk::wasm:: + SupportInputMeshTypes:: + Dimensions< + // 2U, + 3U>("test-mesh", pipeline); } diff --git a/packages/core/typescript/itk-wasm/test/pipelines/composite-transform-pipeline/composite-transform-test.cxx b/packages/core/typescript/itk-wasm/test/pipelines/composite-transform-pipeline/composite-transform-test.cxx index f88d87873..30e38e7a7 100644 --- a/packages/core/typescript/itk-wasm/test/pipelines/composite-transform-pipeline/composite-transform-test.cxx +++ b/packages/core/typescript/itk-wasm/test/pipelines/composite-transform-pipeline/composite-transform-test.cxx @@ -25,7 +25,8 @@ int main(int argc, char * argv[]) { - itk::wasm::Pipeline pipeline("composite-transform-test", "A test for creating and writing composite transforms", argc, argv); + itk::wasm::Pipeline pipeline( + "composite-transform-test", "A test for creating and writing composite transforms", argc, argv); using ParametersValueType = float; constexpr unsigned int Dimension = 2; @@ -71,8 +72,10 @@ main(int argc, char * argv[]) // Set non-trivial matrix parameters AffineTransformType::MatrixType matrix; - matrix(0, 0) = 1.2; matrix(0, 1) = 0.3; - matrix(1, 0) = 0.2; matrix(1, 1) = 1.1; + matrix(0, 0) = 1.2; + matrix(0, 1) = 0.3; + matrix(1, 0) = 0.2; + matrix(1, 1) = 1.1; affineTransform->SetMatrix(matrix); // Set center for affine transform (fixed parameters) diff --git a/packages/core/typescript/itk-wasm/test/pipelines/cxx-threads-pipeline/cxx-threads-test.cxx b/packages/core/typescript/itk-wasm/test/pipelines/cxx-threads-pipeline/cxx-threads-test.cxx index d0adfb2df..1d89247fd 100644 --- a/packages/core/typescript/itk-wasm/test/pipelines/cxx-threads-pipeline/cxx-threads-test.cxx +++ b/packages/core/typescript/itk-wasm/test/pipelines/cxx-threads-pipeline/cxx-threads-test.cxx @@ -26,7 +26,8 @@ static std::atomic createdThreads(0); -int main(int argc, char * argv[]) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("cxx-threads-test", "A pipeline to test C++11 threads support", argc, argv); @@ -44,14 +45,13 @@ int main(int argc, char * argv[]) for (int i = 0; i < numberOfThreads; ++i) { - threads.emplace_back([i]() - { + threads.emplace_back([i]() { std::cout << " in thread " << i << std::endl; createdThreads++; }); } - for (auto &t : threads) + for (auto & t : threads) { t.join(); } diff --git a/packages/core/typescript/itk-wasm/test/pipelines/pthreads-pipeline/pthreads-test.cxx b/packages/core/typescript/itk-wasm/test/pipelines/pthreads-pipeline/pthreads-test.cxx index 490e609f3..703de3a42 100644 --- a/packages/core/typescript/itk-wasm/test/pipelines/pthreads-pipeline/pthreads-test.cxx +++ b/packages/core/typescript/itk-wasm/test/pipelines/pthreads-pipeline/pthreads-test.cxx @@ -26,14 +26,17 @@ static std::atomic createdThreads(0); -void *thread_entry_point(void *ctx) { - size_t id = *((size_t*) ctx); +void * +thread_entry_point(void * ctx) +{ + size_t id = *((size_t *)ctx); printf(" in thread %zu\n", id); createdThreads++; return 0; } -int main( int argc, char * argv[] ) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("pthreads-test", "A pipeline to test pthreads support", argc, argv); @@ -47,12 +50,14 @@ int main( int argc, char * argv[] ) // Based on: https://bytecodealliance.org/articles/wasi-threads pthread_t threads[512]; - size_t thread_ids[512]; + size_t thread_ids[512]; createdThreads = 0; - for (int i = 0; i < numberOfThreads; i++) { + for (int i = 0; i < numberOfThreads; i++) + { thread_ids[i] = i; int ret = pthread_create(&threads[i], NULL, &thread_entry_point, &thread_ids[i]); - if (ret) { + if (ret) + { printf("failed to spawn thread: %s", strerror(ret)); } } diff --git a/packages/core/typescript/itk-wasm/test/pipelines/transform-read-write-pipeline/transform-read-write-composite-test.cxx b/packages/core/typescript/itk-wasm/test/pipelines/transform-read-write-pipeline/transform-read-write-composite-test.cxx index 3ab72d6ac..1324cc0ac 100644 --- a/packages/core/typescript/itk-wasm/test/pipelines/transform-read-write-pipeline/transform-read-write-composite-test.cxx +++ b/packages/core/typescript/itk-wasm/test/pipelines/transform-read-write-pipeline/transform-read-write-composite-test.cxx @@ -23,7 +23,8 @@ int main(int argc, char * argv[]) { - itk::wasm::Pipeline pipeline("transform-read-write-composite-test", "A test for reading and writing composite transforms", argc, argv); + itk::wasm::Pipeline pipeline( + "transform-read-write-composite-test", "A test for reading and writing composite transforms", argc, argv); using ParametersValueType = float; constexpr unsigned int Dimension = 2; diff --git a/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.cxx b/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.cxx index 62690cefb..22c2b3b51 100644 --- a/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.cxx +++ b/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.cxx @@ -45,273 +45,239 @@ #include "rtss_roi.h" #include "string_util.h" -Itk_wasm_dcmtk_rt_study::Itk_wasm_dcmtk_rt_study () -{ -} +Itk_wasm_dcmtk_rt_study::Itk_wasm_dcmtk_rt_study() {} -Itk_wasm_dcmtk_rt_study::~Itk_wasm_dcmtk_rt_study () -{ -} +Itk_wasm_dcmtk_rt_study::~Itk_wasm_dcmtk_rt_study() {} void -Itk_wasm_dcmtk_rt_study::save_rtss (const char * fname, const ItkWasmRtStudyMetadata & metadata) +Itk_wasm_dcmtk_rt_study::save_rtss(const char * fname, const ItkWasmRtStudyMetadata & metadata) { - // Modified: - // rt_study.cxx Rt_study::save_dicom - this->d_ptr->rt_study_metadata->generate_new_rtstruct_instance_uid (); - - // Modified: - // rtds_dcmtk.cxx Rt_study::rtss_save - - OFCondition ofc; - Rtss::Pointer& rtss = this->d_ptr->rtss; - Metadata::Pointer rtstruct_metadata; - if (this->d_ptr->rt_study_metadata) { - rtstruct_metadata = d_ptr->rt_study_metadata->get_rtstruct_metadata (); + // Modified: + // rt_study.cxx Rt_study::save_dicom + this->d_ptr->rt_study_metadata->generate_new_rtstruct_instance_uid(); + + // Modified: + // rtds_dcmtk.cxx Rt_study::rtss_save + + OFCondition ofc; + Rtss::Pointer & rtss = this->d_ptr->rtss; + Metadata::Pointer rtstruct_metadata; + if (this->d_ptr->rt_study_metadata) + { + rtstruct_metadata = d_ptr->rt_study_metadata->get_rtstruct_metadata(); + } + + /* Prepare structure set with slice uids */ + const Slice_list * slice_list = d_ptr->rt_study_metadata->get_slice_list(); + rtss->apply_slice_list(slice_list); + + /* Prepare dcmtk */ + DcmFileFormat fileformat; + DcmDataset * dataset = fileformat.getDataset(); + + /* Add entries for common modules */ + Dcmtk_module::set_sop_common(dataset); + + /* GCS FIX, remove below code, use common modules instead */ + + /* ----------------------------------------------------------------- */ + /* Part 1 -- General header */ + /* ----------------------------------------------------------------- */ + dataset->putAndInsertOFStringArray(DCM_InstanceCreationDate, d_ptr->rt_study_metadata->get_study_date()); + dataset->putAndInsertOFStringArray(DCM_InstanceCreationTime, d_ptr->rt_study_metadata->get_study_time()); + dataset->putAndInsertOFStringArray(DCM_InstanceCreatorUID, PlmUidPrefix::getInstance().get().c_str()); + dataset->putAndInsertString(DCM_SOPClassUID, UID_RTStructureSetStorage); + dcmtk_put(dataset, DCM_SOPInstanceUID, d_ptr->rt_study_metadata->get_rtstruct_instance_uid()); + dataset->putAndInsertOFStringArray(DCM_StudyDate, d_ptr->rt_study_metadata->get_study_date()); + dataset->putAndInsertOFStringArray(DCM_StudyTime, d_ptr->rt_study_metadata->get_study_time()); + dcmtk_copy_from_metadata(dataset, rtstruct_metadata, DCM_StudyDescription, ""); + + dataset->putAndInsertOFStringArray(DCM_AccessionNumber, ""); + dataset->putAndInsertOFStringArray(DCM_Modality, "RTSTRUCT"); + dataset->putAndInsertString(DCM_Manufacturer, metadata.manufacturer.c_str()); + dataset->putAndInsertString(DCM_InstitutionName, ""); + dataset->putAndInsertString(DCM_ReferringPhysicianName, ""); + dataset->putAndInsertString(DCM_StationName, ""); + dcmtk_copy_from_metadata(dataset, rtstruct_metadata, DCM_SeriesDescription, ""); + dataset->putAndInsertString(DCM_ManufacturerModelName, metadata.manufacturerModelName.c_str()); + + dcmtk_copy_from_metadata(dataset, rtstruct_metadata, DCM_PatientName, ""); + dcmtk_copy_from_metadata(dataset, rtstruct_metadata, DCM_PatientID, ""); + dataset->putAndInsertString(DCM_PatientBirthDate, ""); + dcmtk_copy_from_metadata(dataset, rtstruct_metadata, DCM_PatientSex, "O"); + dataset->putAndInsertString(DCM_SoftwareVersions, metadata.softwareVersions.c_str()); + + dataset->putAndInsertString(DCM_StudyInstanceUID, d_ptr->rt_study_metadata->get_study_uid().c_str()); + dataset->putAndInsertString(DCM_SeriesInstanceUID, d_ptr->rt_study_metadata->get_rtstruct_series_uid()); + dcmtk_copy_from_metadata(dataset, rtstruct_metadata, DCM_StudyID, "10001"); + dcmtk_copy_from_metadata(dataset, rtstruct_metadata, DCM_SeriesNumber, "1"); + dataset->putAndInsertString(DCM_InstanceNumber, "1"); + dataset->putAndInsertString(DCM_StructureSetLabel, metadata.structureSetLabel.c_str()); + dataset->putAndInsertString(DCM_StructureSetName, metadata.structureSetName.c_str()); + dataset->putAndInsertOFStringArray(DCM_StructureSetDate, d_ptr->rt_study_metadata->get_study_date()); + dataset->putAndInsertOFStringArray(DCM_StructureSetTime, d_ptr->rt_study_metadata->get_study_time()); + + /* ----------------------------------------------------------------- */ + /* Part 2 -- UID's for CT series */ + /* ----------------------------------------------------------------- */ + DcmSequenceOfItems * rfor_seq = 0; + DcmItem * rfor_item = 0; + dataset->findOrCreateSequenceItem(DCM_ReferencedFrameOfReferenceSequence, rfor_item, -2); + rfor_item->putAndInsertString(DCM_FrameOfReferenceUID, + d_ptr->rt_study_metadata->get_frame_of_reference_uid().c_str()); + dataset->findAndGetSequence(DCM_ReferencedFrameOfReferenceSequence, rfor_seq); + DcmItem * rtrstudy_item = 0; + rfor_item->findOrCreateSequenceItem(DCM_RTReferencedStudySequence, rtrstudy_item, -2); + rtrstudy_item->putAndInsertString(DCM_ReferencedSOPClassUID, UID_RETIRED_StudyComponentManagementSOPClass); + rtrstudy_item->putAndInsertString(DCM_ReferencedSOPInstanceUID, d_ptr->rt_study_metadata->get_study_uid().c_str()); + DcmItem * rtrseries_item = 0; + rtrstudy_item->findOrCreateSequenceItem(DCM_RTReferencedSeriesSequence, rtrseries_item, -2); + rtrseries_item->putAndInsertString(DCM_SeriesInstanceUID, d_ptr->rt_study_metadata->get_ct_series_uid()); + + for (int k = 0; k < d_ptr->rt_study_metadata->num_slices(); k++) + { + DcmItem * ci_item = 0; + rtrseries_item->findOrCreateSequenceItem(DCM_ContourImageSequence, ci_item, -2); + ci_item->putAndInsertString(DCM_ReferencedSOPClassUID, UID_CTImageStorage); + ci_item->putAndInsertString(DCM_ReferencedSOPInstanceUID, d_ptr->rt_study_metadata->get_slice_uid(k)); + } + + /* ----------------------------------------------------------------- */ + /* Part 3 -- Structure info */ + /* ----------------------------------------------------------------- */ + for (size_t i = 0; i < rtss->num_structures; i++) + { + DcmItem * ssroi_item = 0; + std::string tmp; + dataset->findOrCreateSequenceItem(DCM_StructureSetROISequence, ssroi_item, -2); + tmp = string_format("%d", rtss->slist[i]->id); + ssroi_item->putAndInsertString(DCM_ROINumber, tmp.c_str()); + ssroi_item->putAndInsertString(DCM_ReferencedFrameOfReferenceUID, + d_ptr->rt_study_metadata->get_frame_of_reference_uid().c_str()); + ssroi_item->putAndInsertString(DCM_ROIName, rtss->slist[i]->name.c_str()); + if (metadata.roiMetadata.size() > i) + { + ssroi_item->putAndInsertString(DCM_ROIGenerationAlgorithm, + metadata.roiMetadata[i].roiGenerationAlgorithm.c_str()); + ssroi_item->putAndInsertString(DCM_ROIDescription, metadata.roiMetadata[i].roiDescription.c_str()); } - - /* Prepare structure set with slice uids */ - const Slice_list *slice_list = d_ptr->rt_study_metadata->get_slice_list (); - rtss->apply_slice_list (slice_list); - - /* Prepare dcmtk */ - DcmFileFormat fileformat; - DcmDataset *dataset = fileformat.getDataset(); - - /* Add entries for common modules */ - Dcmtk_module::set_sop_common (dataset); - - /* GCS FIX, remove below code, use common modules instead */ - - /* ----------------------------------------------------------------- */ - /* Part 1 -- General header */ - /* ----------------------------------------------------------------- */ - dataset->putAndInsertOFStringArray(DCM_InstanceCreationDate, - d_ptr->rt_study_metadata->get_study_date()); - dataset->putAndInsertOFStringArray(DCM_InstanceCreationTime, - d_ptr->rt_study_metadata->get_study_time()); - dataset->putAndInsertOFStringArray(DCM_InstanceCreatorUID, - PlmUidPrefix::getInstance().get().c_str()); - dataset->putAndInsertString (DCM_SOPClassUID, UID_RTStructureSetStorage); - dcmtk_put (dataset, DCM_SOPInstanceUID, - d_ptr->rt_study_metadata->get_rtstruct_instance_uid()); - dataset->putAndInsertOFStringArray (DCM_StudyDate, - d_ptr->rt_study_metadata->get_study_date()); - dataset->putAndInsertOFStringArray (DCM_StudyTime, - d_ptr->rt_study_metadata->get_study_time()); - dcmtk_copy_from_metadata (dataset, rtstruct_metadata, - DCM_StudyDescription, ""); - - dataset->putAndInsertOFStringArray (DCM_AccessionNumber, ""); - dataset->putAndInsertOFStringArray (DCM_Modality, "RTSTRUCT"); - dataset->putAndInsertString (DCM_Manufacturer, metadata.manufacturer.c_str()); - dataset->putAndInsertString (DCM_InstitutionName, ""); - dataset->putAndInsertString (DCM_ReferringPhysicianName, ""); - dataset->putAndInsertString (DCM_StationName, ""); - dcmtk_copy_from_metadata (dataset, rtstruct_metadata, - DCM_SeriesDescription, ""); - dataset->putAndInsertString (DCM_ManufacturerModelName, metadata.manufacturerModelName.c_str()); - - dcmtk_copy_from_metadata (dataset, rtstruct_metadata, DCM_PatientName, ""); - dcmtk_copy_from_metadata (dataset, rtstruct_metadata, DCM_PatientID, ""); - dataset->putAndInsertString (DCM_PatientBirthDate, ""); - dcmtk_copy_from_metadata (dataset, rtstruct_metadata, DCM_PatientSex, "O"); - dataset->putAndInsertString (DCM_SoftwareVersions, - metadata.softwareVersions.c_str()); - - dataset->putAndInsertString (DCM_StudyInstanceUID, - d_ptr->rt_study_metadata->get_study_uid().c_str()); - dataset->putAndInsertString (DCM_SeriesInstanceUID, - d_ptr->rt_study_metadata->get_rtstruct_series_uid()); - dcmtk_copy_from_metadata (dataset, rtstruct_metadata, DCM_StudyID, "10001"); - dcmtk_copy_from_metadata (dataset, rtstruct_metadata, DCM_SeriesNumber, "1"); - dataset->putAndInsertString (DCM_InstanceNumber, "1"); - dataset->putAndInsertString (DCM_StructureSetLabel, metadata.structureSetLabel.c_str()); - dataset->putAndInsertString (DCM_StructureSetName, metadata.structureSetName.c_str()); - dataset->putAndInsertOFStringArray (DCM_StructureSetDate, - d_ptr->rt_study_metadata->get_study_date()); - dataset->putAndInsertOFStringArray (DCM_StructureSetTime, - d_ptr->rt_study_metadata->get_study_time()); - - /* ----------------------------------------------------------------- */ - /* Part 2 -- UID's for CT series */ - /* ----------------------------------------------------------------- */ - DcmSequenceOfItems *rfor_seq = 0; - DcmItem *rfor_item = 0; - dataset->findOrCreateSequenceItem ( - DCM_ReferencedFrameOfReferenceSequence, rfor_item, -2); - rfor_item->putAndInsertString (DCM_FrameOfReferenceUID, - d_ptr->rt_study_metadata->get_frame_of_reference_uid().c_str()); - dataset->findAndGetSequence ( - DCM_ReferencedFrameOfReferenceSequence, rfor_seq); - DcmItem *rtrstudy_item = 0; - rfor_item->findOrCreateSequenceItem ( - DCM_RTReferencedStudySequence, rtrstudy_item, -2); - rtrstudy_item->putAndInsertString ( - DCM_ReferencedSOPClassUID, - UID_RETIRED_StudyComponentManagementSOPClass); - rtrstudy_item->putAndInsertString ( - DCM_ReferencedSOPInstanceUID, - d_ptr->rt_study_metadata->get_study_uid().c_str()); - DcmItem *rtrseries_item = 0; - rtrstudy_item->findOrCreateSequenceItem ( - DCM_RTReferencedSeriesSequence, rtrseries_item, -2); - rtrseries_item->putAndInsertString ( - DCM_SeriesInstanceUID, d_ptr->rt_study_metadata->get_ct_series_uid()); - - for (int k = 0; k < d_ptr->rt_study_metadata->num_slices(); k++) { - DcmItem *ci_item = 0; - rtrseries_item->findOrCreateSequenceItem ( - DCM_ContourImageSequence, ci_item, -2); - ci_item->putAndInsertString ( - DCM_ReferencedSOPClassUID, UID_CTImageStorage); - ci_item->putAndInsertString ( - DCM_ReferencedSOPInstanceUID, - d_ptr->rt_study_metadata->get_slice_uid (k)); - } - - /* ----------------------------------------------------------------- */ - /* Part 3 -- Structure info */ - /* ----------------------------------------------------------------- */ - for (size_t i = 0; i < rtss->num_structures; i++) { - DcmItem *ssroi_item = 0; - std::string tmp; - dataset->findOrCreateSequenceItem ( - DCM_StructureSetROISequence, ssroi_item, -2); - tmp = string_format ("%d", rtss->slist[i]->id); - ssroi_item->putAndInsertString (DCM_ROINumber, tmp.c_str()); - ssroi_item->putAndInsertString (DCM_ReferencedFrameOfReferenceUID, - d_ptr->rt_study_metadata->get_frame_of_reference_uid().c_str()); - ssroi_item->putAndInsertString (DCM_ROIName, - rtss->slist[i]->name.c_str()); - if (metadata.roiMetadata.size() > i) { - ssroi_item->putAndInsertString (DCM_ROIGenerationAlgorithm, - metadata.roiMetadata[i].roiGenerationAlgorithm.c_str()); - ssroi_item->putAndInsertString (DCM_ROIDescription, - metadata.roiMetadata[i].roiDescription.c_str()); - } - else { - ssroi_item->putAndInsertString (DCM_ROIGenerationAlgorithm, ""); - } + else + { + ssroi_item->putAndInsertString(DCM_ROIGenerationAlgorithm, ""); } - - /* ----------------------------------------------------------------- */ - /* Part 4 -- Contour info */ - /* ----------------------------------------------------------------- */ - for (size_t i = 0; i < rtss->num_structures; i++) { - Rtss_roi *curr_structure = rtss->slist[i]; - DcmItem *roic_item = 0; - dataset->findOrCreateSequenceItem ( - DCM_ROIContourSequence, roic_item, -2); - std::string tmp = curr_structure->get_dcm_color_string (); - roic_item->putAndInsertString (DCM_ROIDisplayColor, tmp.c_str()); - for (size_t j = 0; j < curr_structure->num_contours; j++) { - Rtss_contour *curr_contour = curr_structure->pslist[j]; - if (curr_contour->num_vertices <= 0) continue; - -#if defined (commentout) - /* GCS 2013-07-02: DICOM standard allows contours without - an associated slice UID. Maybe this bug is now - fixed in XiO??? */ - /* GE -> XiO transfer does not work if contour does not have - corresponding slice uid */ - if (curr_contour->ct_slice_uid.empty()) { - printf ("Warning: Omitting contour (%ld,%ld)\n", - (long) i, (long) j); - continue; - } + } + + /* ----------------------------------------------------------------- */ + /* Part 4 -- Contour info */ + /* ----------------------------------------------------------------- */ + for (size_t i = 0; i < rtss->num_structures; i++) + { + Rtss_roi * curr_structure = rtss->slist[i]; + DcmItem * roic_item = 0; + dataset->findOrCreateSequenceItem(DCM_ROIContourSequence, roic_item, -2); + std::string tmp = curr_structure->get_dcm_color_string(); + roic_item->putAndInsertString(DCM_ROIDisplayColor, tmp.c_str()); + for (size_t j = 0; j < curr_structure->num_contours; j++) + { + Rtss_contour * curr_contour = curr_structure->pslist[j]; + if (curr_contour->num_vertices <= 0) + continue; + +#if defined(commentout) + /* GCS 2013-07-02: DICOM standard allows contours without + an associated slice UID. Maybe this bug is now + fixed in XiO??? */ + /* GE -> XiO transfer does not work if contour does not have + corresponding slice uid */ + if (curr_contour->ct_slice_uid.empty()) + { + printf("Warning: Omitting contour (%ld,%ld)\n", (long)i, (long)j); + continue; + } #endif - /* Add item to ContourSequence */ - DcmItem *c_item = 0; - roic_item->findOrCreateSequenceItem ( - DCM_ContourSequence, c_item, -2); - - /* ContourImageSequence */ - if (curr_contour->ct_slice_uid != "") { - DcmItem *ci_item = 0; - c_item->findOrCreateSequenceItem ( - DCM_ContourImageSequence, ci_item, -2); - ci_item->putAndInsertString (DCM_ReferencedSOPClassUID, - UID_CTImageStorage); - ci_item->putAndInsertString (DCM_ReferencedSOPInstanceUID, - curr_contour->ct_slice_uid.c_str()); - } - - /* ContourGeometricType */ - c_item->putAndInsertString (DCM_ContourGeometricType, - "CLOSED_PLANAR"); - - /* NumberOfContourPoints */ - tmp = string_format ("%d", curr_contour->num_vertices); - c_item->putAndInsertString (DCM_NumberOfContourPoints, tmp.c_str()); - - /* ContourData */ - tmp = string_format ("%.8g\\%.8g\\%.8g", - curr_contour->x[0], - curr_contour->y[0], - curr_contour->z[0]); - for (size_t k = 1; k < curr_contour->num_vertices; k++) { - std::string tmp2 = string_format ("\\%.8g\\%.8g\\%.8g", - curr_contour->x[k], - curr_contour->y[k], - curr_contour->z[k]); - tmp += tmp2; - } - c_item->putAndInsertString (DCM_ContourData, tmp.c_str()); - } - - tmp = string_format ("%d", (int) curr_structure->id); - roic_item->putAndInsertString (DCM_ReferencedROINumber, tmp.c_str()); + /* Add item to ContourSequence */ + DcmItem * c_item = 0; + roic_item->findOrCreateSequenceItem(DCM_ContourSequence, c_item, -2); + + /* ContourImageSequence */ + if (curr_contour->ct_slice_uid != "") + { + DcmItem * ci_item = 0; + c_item->findOrCreateSequenceItem(DCM_ContourImageSequence, ci_item, -2); + ci_item->putAndInsertString(DCM_ReferencedSOPClassUID, UID_CTImageStorage); + ci_item->putAndInsertString(DCM_ReferencedSOPInstanceUID, curr_contour->ct_slice_uid.c_str()); + } + + /* ContourGeometricType */ + c_item->putAndInsertString(DCM_ContourGeometricType, "CLOSED_PLANAR"); + + /* NumberOfContourPoints */ + tmp = string_format("%d", curr_contour->num_vertices); + c_item->putAndInsertString(DCM_NumberOfContourPoints, tmp.c_str()); + + /* ContourData */ + tmp = string_format("%.8g\\%.8g\\%.8g", curr_contour->x[0], curr_contour->y[0], curr_contour->z[0]); + for (size_t k = 1; k < curr_contour->num_vertices; k++) + { + std::string tmp2 = + string_format("\\%.8g\\%.8g\\%.8g", curr_contour->x[k], curr_contour->y[k], curr_contour->z[k]); + tmp += tmp2; + } + c_item->putAndInsertString(DCM_ContourData, tmp.c_str()); } - /* ----------------------------------------------------------------- */ - /* Part 5 -- More structure info */ - /* ----------------------------------------------------------------- */ - for (size_t i = 0; i < rtss->num_structures; i++) { - Rtss_roi *curr_structure = rtss->slist[i]; - std::string tmp; - - /* RTROIObservationsSequence */ - DcmItem *rtroio_item = 0; - dataset->findOrCreateSequenceItem ( - DCM_RTROIObservationsSequence, rtroio_item, -2); - - /* ObservationNumber */ - tmp = string_format ("%d", (int) curr_structure->id); - rtroio_item->putAndInsertString (DCM_ObservationNumber, tmp.c_str()); - /* ReferencedROINumber */ - rtroio_item->putAndInsertString (DCM_ReferencedROINumber, tmp.c_str()); - if (metadata.roiMetadata.size() > i) { - rtroio_item->putAndInsertString (DCM_RTROIInterpretedType, - metadata.roiMetadata[i].rtRoiInterpretedType.c_str()); - } - else { - rtroio_item->putAndInsertString (DCM_RTROIInterpretedType, ""); - } - /* ROIInterpreter */ - rtroio_item->putAndInsertString (DCM_ROIInterpreter, ""); - ///* ROIPhysicalProperty */ - if(rtss->slist[i]->rsp_value > -1.0) - { - DcmItem *rsp_item = NULL; - if (rtroio_item->findOrCreateSequenceItem( - DCM_ROIPhysicalPropertiesSequence, rsp_item, -2).good()) - { - rsp_item->putAndInsertString(DCM_ROIPhysicalProperty, "REL_STOP_RATIO"); - rsp_item->putAndInsertString(DCM_ROIPhysicalPropertyValue, std::to_string(rtss->slist[i]->rsp_value).c_str()); - } - } + tmp = string_format("%d", (int)curr_structure->id); + roic_item->putAndInsertString(DCM_ReferencedROINumber, tmp.c_str()); + } + + /* ----------------------------------------------------------------- */ + /* Part 5 -- More structure info */ + /* ----------------------------------------------------------------- */ + for (size_t i = 0; i < rtss->num_structures; i++) + { + Rtss_roi * curr_structure = rtss->slist[i]; + std::string tmp; + + /* RTROIObservationsSequence */ + DcmItem * rtroio_item = 0; + dataset->findOrCreateSequenceItem(DCM_RTROIObservationsSequence, rtroio_item, -2); + + /* ObservationNumber */ + tmp = string_format("%d", (int)curr_structure->id); + rtroio_item->putAndInsertString(DCM_ObservationNumber, tmp.c_str()); + /* ReferencedROINumber */ + rtroio_item->putAndInsertString(DCM_ReferencedROINumber, tmp.c_str()); + if (metadata.roiMetadata.size() > i) + { + rtroio_item->putAndInsertString(DCM_RTROIInterpretedType, metadata.roiMetadata[i].rtRoiInterpretedType.c_str()); } - - /* ----------------------------------------------------------------- */ - /* Write the output file */ - /* ----------------------------------------------------------------- */ - make_parent_directories (fname); - - ofc = fileformat.saveFile (fname, EXS_LittleEndianExplicit); - if (ofc.bad()) { - print_and_exit ("Error: cannot write DICOM RTSTRUCT (%s)\n", - ofc.text()); + else + { + rtroio_item->putAndInsertString(DCM_RTROIInterpretedType, ""); + } + /* ROIInterpreter */ + rtroio_item->putAndInsertString(DCM_ROIInterpreter, ""); + ///* ROIPhysicalProperty */ + if (rtss->slist[i]->rsp_value > -1.0) + { + DcmItem * rsp_item = NULL; + if (rtroio_item->findOrCreateSequenceItem(DCM_ROIPhysicalPropertiesSequence, rsp_item, -2).good()) + { + rsp_item->putAndInsertString(DCM_ROIPhysicalProperty, "REL_STOP_RATIO"); + rsp_item->putAndInsertString(DCM_ROIPhysicalPropertyValue, std::to_string(rtss->slist[i]->rsp_value).c_str()); + } } + } + + /* ----------------------------------------------------------------- */ + /* Write the output file */ + /* ----------------------------------------------------------------- */ + make_parent_directories(fname); + + ofc = fileformat.saveFile(fname, EXS_LittleEndianExplicit); + if (ofc.bad()) + { + print_and_exit("Error: cannot write DICOM RTSTRUCT (%s)\n", ofc.text()); + } } \ No newline at end of file diff --git a/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.h b/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.h index cca68d3f6..9ced8f2c6 100644 --- a/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.h +++ b/packages/dicom/dcmtk/itk_wasm_dcmtk_rt_study.h @@ -22,12 +22,15 @@ #include "itk_wasm_rt_study_metadata.h" -class PLMBASE_API Itk_wasm_dcmtk_rt_study: public Dcmtk_rt_study { +class PLMBASE_API Itk_wasm_dcmtk_rt_study : public Dcmtk_rt_study +{ public: - Itk_wasm_dcmtk_rt_study (); - ~Itk_wasm_dcmtk_rt_study (); + Itk_wasm_dcmtk_rt_study(); + ~Itk_wasm_dcmtk_rt_study(); + + void + save_rtss(const char * fname, const ItkWasmRtStudyMetadata & metadata); - void save_rtss (const char *fname, const ItkWasmRtStudyMetadata& metadata); protected: }; diff --git a/packages/dicom/dcmtk/itk_wasm_rt_study.cxx b/packages/dicom/dcmtk/itk_wasm_rt_study.cxx index 8b145ffa3..b24da786f 100644 --- a/packages/dicom/dcmtk/itk_wasm_rt_study.cxx +++ b/packages/dicom/dcmtk/itk_wasm_rt_study.cxx @@ -20,44 +20,43 @@ #include "rt_study_p.h" #include "itk_wasm_dcmtk_rt_study.h" -Itk_wasm_rt_study::Itk_wasm_rt_study () -{ -} +Itk_wasm_rt_study::Itk_wasm_rt_study() {} -Itk_wasm_rt_study::~Itk_wasm_rt_study () -{ -} +Itk_wasm_rt_study::~Itk_wasm_rt_study() {} void -Itk_wasm_rt_study::save_rtss (const char* fname, const ItkWasmRtStudyMetadata& metadata, bool quiet) +Itk_wasm_rt_study::save_rtss(const char * fname, const ItkWasmRtStudyMetadata & metadata, bool quiet) { // Modified: // rt_study.cxx Rt_study::save_dicom - if (this->d_ptr->m_img) { - this->d_ptr->m_drs->set_image_header (this->d_ptr->m_img); + if (this->d_ptr->m_img) + { + this->d_ptr->m_drs->set_image_header(this->d_ptr->m_img); } - if (this->d_ptr->m_seg) { - this->d_ptr->m_seg->cxt_extract (); + if (this->d_ptr->m_seg) + { + this->d_ptr->m_seg->cxt_extract(); } // Modified: // rtds_dcmtk.cxx Rt_study::save_dcmtk Itk_wasm_dcmtk_rt_study drs; - drs.set_rt_study_metadata (this->d_ptr->m_drs); - drs.set_image (this->d_ptr->m_img); - if (d_ptr->m_seg) { + drs.set_rt_study_metadata(this->d_ptr->m_drs); + drs.set_image(this->d_ptr->m_img); + if (d_ptr->m_seg) + { /* GCS FIX. This call to prune_empty() is a hack. It should be allowed to write empty structures, but current plastimatch logic sets num_structures to max when performing cxt_extract(). Segmentation class logic should be improved to better keep track of when structure names are valid to avoid this. */ - this->d_ptr->m_seg->prune_empty (); - this->d_ptr->m_seg->keyholize (quiet); - drs.set_rtss (this->d_ptr->m_seg->get_structure_set()); + this->d_ptr->m_seg->prune_empty(); + this->d_ptr->m_seg->keyholize(quiet); + drs.set_rtss(this->d_ptr->m_seg->get_structure_set()); } - drs.set_dose (this->d_ptr->m_dose); - drs.set_rtplan (this->d_ptr->m_rtplan); + drs.set_dose(this->d_ptr->m_dose); + drs.set_rtplan(this->d_ptr->m_rtplan); drs.save_rtss(fname, metadata); } \ No newline at end of file diff --git a/packages/dicom/dcmtk/itk_wasm_rt_study.h b/packages/dicom/dcmtk/itk_wasm_rt_study.h index 378600f3e..d2accc2e5 100644 --- a/packages/dicom/dcmtk/itk_wasm_rt_study.h +++ b/packages/dicom/dcmtk/itk_wasm_rt_study.h @@ -30,14 +30,16 @@ * Itk_wasm_rt_study supports writing to an output RT Struct file and setting * additional metadata. */ -class PLMBASE_API Itk_wasm_rt_study: public Rt_study { +class PLMBASE_API Itk_wasm_rt_study : public Rt_study +{ public: - SMART_POINTER_SUPPORT (Itk_wasm_rt_study); + SMART_POINTER_SUPPORT(Itk_wasm_rt_study); - Itk_wasm_rt_study (); - ~Itk_wasm_rt_study (); + Itk_wasm_rt_study(); + ~Itk_wasm_rt_study(); - void save_rtss (const char *fname, const ItkWasmRtStudyMetadata &metadata, bool quiet = true); + void + save_rtss(const char * fname, const ItkWasmRtStudyMetadata & metadata, bool quiet = true); protected: }; diff --git a/packages/dicom/dcmtk/itk_wasm_rt_study_metadata.h b/packages/dicom/dcmtk/itk_wasm_rt_study_metadata.h index c887de815..7e82cb77e 100644 --- a/packages/dicom/dcmtk/itk_wasm_rt_study_metadata.h +++ b/packages/dicom/dcmtk/itk_wasm_rt_study_metadata.h @@ -30,12 +30,12 @@ struct ItkWasmRtStudyMetadata { // ITK-Wasm's DICOM UID Prefix // Vendor's should replace this with their own UID prefix - std::string uidPrefix{ "1.2.826.0.1.3680043.10.1541.1" }; - std::string manufacturer{ "ITK-Wasm" }; - std::string manufacturerModelName{ "ITK-Wasm RT Struct" }; - std::string structureSetLabel{ "AutoSS" }; - std::string structureSetName{ "AutoSS" }; - std::string softwareVersions{ "" }; + std::string uidPrefix{ "1.2.826.0.1.3680043.10.1541.1" }; + std::string manufacturer{ "ITK-Wasm" }; + std::string manufacturerModelName{ "ITK-Wasm RT Struct" }; + std::string structureSetLabel{ "AutoSS" }; + std::string structureSetName{ "AutoSS" }; + std::string softwareVersions{ "" }; std::vector roiMetadata; }; diff --git a/packages/dicom/dcmtk/write-rt-struct.cxx b/packages/dicom/dcmtk/write-rt-struct.cxx index fcd2906e5..e983feea5 100644 --- a/packages/dicom/dcmtk/write-rt-struct.cxx +++ b/packages/dicom/dcmtk/write-rt-struct.cxx @@ -29,19 +29,30 @@ #include "glaze/glaze.hpp" -int main (int argc, char * argv[]) +int +main(int argc, char * argv[]) { - itk::wasm::Pipeline pipeline("write-rt-struct", "Write a DICOM RT Struct Structured Set for the given ROI contours and DICOM metadata", argc, argv); + itk::wasm::Pipeline pipeline("write-rt-struct", + "Write a DICOM RT Struct Structured Set for the given ROI contours and DICOM metadata", + argc, + argv); pipeline.set_version("0.2.0"); std::string inputCxt; - auto inputCxtOption = pipeline.add_option("input-cxt", inputCxt, "Input Plastimatch CXT structure set file")->required()->check(CLI::ExistingFile)->type_name("INPUT_TEXT_FILE"); + auto inputCxtOption = pipeline.add_option("input-cxt", inputCxt, "Input Plastimatch CXT structure set file") + ->required() + ->check(CLI::ExistingFile) + ->type_name("INPUT_TEXT_FILE"); std::string outputDicom; - auto outputDicomOption = pipeline.add_option("output-dicom", outputDicom, "Output DICOM RT Struct Structure Set file")->required()->type_name("OUTPUT_BINARY_FILE"); + auto outputDicomOption = + pipeline.add_option("output-dicom", outputDicom, "Output DICOM RT Struct Structure Set file") + ->required() + ->type_name("OUTPUT_BINARY_FILE"); itk::wasm::InputTextStream dicomMetadataJson; - auto dicomMetadataOption = pipeline.add_option("--dicom-metadata", dicomMetadataJson, "Additional DICOM metadata")->type_name("INPUT_JSON"); + auto dicomMetadataOption = + pipeline.add_option("--dicom-metadata", dicomMetadataJson, "Additional DICOM metadata")->type_name("INPUT_JSON"); ITK_WASM_PARSE(pipeline); diff --git a/packages/downsample/downsample-bin-shrink.cxx b/packages/downsample/downsample-bin-shrink.cxx index 793dcff93..56f99b4c7 100644 --- a/packages/downsample/downsample-bin-shrink.cxx +++ b/packages/downsample/downsample-bin-shrink.cxx @@ -98,6 +98,6 @@ main(int argc, char * argv[]) itk::VariableLengthVector, itk::VariableLengthVector, itk::VariableLengthVector, - itk::VariableLengthVector - >::Dimensions<2U, 3U, 4U, 5U>("input", pipeline); + itk::VariableLengthVector>::Dimensions<2U, 3U, 4U, 5U>("input", + pipeline); } diff --git a/packages/downsample/downsample.cxx b/packages/downsample/downsample.cxx index b4eb70b94..51131490b 100644 --- a/packages/downsample/downsample.cxx +++ b/packages/downsample/downsample.cxx @@ -146,8 +146,7 @@ class PipelineFunctor> pipeline.add_option("-s,--shrink-factors", shrinkFactors, "Shrink factors")->required()->type_size(Dimension); std::vector cropRadius; - pipeline.add_option("-r,--crop-radius", cropRadius, "Optional crop radius in pixel units.") - ->type_size(Dimension); + pipeline.add_option("-r,--crop-radius", cropRadius, "Optional crop radius in pixel units.")->type_size(Dimension); using OutputImageType = itk::wasm::OutputImage; OutputImageType downsampledImage; @@ -253,6 +252,6 @@ main(int argc, char * argv[]) itk::VariableLengthVector, itk::VariableLengthVector, itk::VariableLengthVector, - itk::VariableLengthVector - >::Dimensions<2U, 3U, 4U, 5U>("input", pipeline); + itk::VariableLengthVector>::Dimensions<2U, 3U, 4U, 5U>("input", + pipeline); } \ No newline at end of file diff --git a/packages/mesh-filters/geogram-conversion.cxx b/packages/mesh-filters/geogram-conversion.cxx index 0fa80e8d6..aec375bfb 100644 --- a/packages/mesh-filters/geogram-conversion.cxx +++ b/packages/mesh-filters/geogram-conversion.cxx @@ -24,13 +24,15 @@ #include "itkmeshToGeogramMesh.h" #include "itkgeogramMeshToMesh.h" -int main( int argc, char * argv[] ) +int +main(int argc, char * argv[]) { - itk::wasm::Pipeline pipeline("geogram-conversion", "A test for reading and writing with geogram, itk::QuadEdgeMesh meshes", argc, argv); + itk::wasm::Pipeline pipeline( + "geogram-conversion", "A test for reading and writing with geogram, itk::QuadEdgeMesh meshes", argc, argv); using PixelType = float; constexpr unsigned int Dimension = 3; - using MeshType = itk::QuadEdgeMesh< PixelType, Dimension >; + using MeshType = itk::QuadEdgeMesh; static constexpr bool SinglePrecision = std::is_same::value; diff --git a/packages/mesh-filters/itkgeogramMeshToMesh.h b/packages/mesh-filters/itkgeogramMeshToMesh.h index cb5500d87..390d84a7a 100644 --- a/packages/mesh-filters/itkgeogramMeshToMesh.h +++ b/packages/mesh-filters/itkgeogramMeshToMesh.h @@ -52,19 +52,19 @@ geogramMeshToMesh(const GEO::Mesh & geoMesh, TMesh * itkMesh) // Copy vertices if (singlePrecision) { - for(GEO::index_t v = 0; v < geoMesh.vertices.nb(); ++v) + for (GEO::index_t v = 0; v < geoMesh.vertices.nb(); ++v) { PointType point; for (unsigned int d = 0; d < Dimension; ++d) - { + { point[d] = static_cast(geoMesh.vertices.single_precision_point_ptr(v)[d]); - } + } itkMesh->SetPoint(v, point); } } else { - for(GEO::index_t v = 0; v < geoMesh.vertices.nb(); ++v) + for (GEO::index_t v = 0; v < geoMesh.vertices.nb(); ++v) { PointType point; for (unsigned int d = 0; d < Dimension; ++d) @@ -76,23 +76,24 @@ geogramMeshToMesh(const GEO::Mesh & geoMesh, TMesh * itkMesh) } // Copy facets - for(GEO::index_t f = 0; f < geoMesh.facets.nb(); ++f) { - auto numVertices = geoMesh.facets.nb_vertices(f); + for (GEO::index_t f = 0; f < geoMesh.facets.nb(); ++f) + { + auto numVertices = geoMesh.facets.nb_vertices(f); CellAutoPointer cell; - if(numVertices == 3) + if (numVertices == 3) { auto * triangleCell = new TriangleCellType; - for(GEO::index_t lv = 0; lv < 3; ++lv) + for (GEO::index_t lv = 0; lv < 3; ++lv) { triangleCell->SetPointId(lv, geoMesh.facets.vertex(f, lv)); } cell.TakeOwnership(triangleCell); } - else if(numVertices == 4) + else if (numVertices == 4) { auto * quadCell = new QuadCellType; - for(GEO::index_t lv = 0; lv < 4; ++lv) + for (GEO::index_t lv = 0; lv < 4; ++lv) { quadCell->SetPointId(lv, geoMesh.facets.vertex(f, lv)); } @@ -101,7 +102,7 @@ geogramMeshToMesh(const GEO::Mesh & geoMesh, TMesh * itkMesh) else { auto * polygonCell = new PolygonCellType; - for(GEO::index_t lv = 0; lv < numVertices; ++lv) + for (GEO::index_t lv = 0; lv < numVertices; ++lv) { polygonCell->SetPointId(lv, geoMesh.facets.vertex(f, lv)); } @@ -110,20 +111,20 @@ geogramMeshToMesh(const GEO::Mesh & geoMesh, TMesh * itkMesh) } // Copy vertex attributes if they exist - if(geoMesh.vertices.attributes().is_defined("PointData")) + if (geoMesh.vertices.attributes().is_defined("PointData")) { auto vertexAttribute = GEO::Attribute(geoMesh.vertices.attributes(), "PointData"); - for(GEO::index_t v = 0; v < geoMesh.vertices.nb(); ++v) + for (GEO::index_t v = 0; v < geoMesh.vertices.nb(); ++v) { itkMesh->SetPointData(v, static_cast(vertexAttribute[v])); } } // Copy facet attributes if they exist - if(geoMesh.facets.attributes().is_defined("CellData")) + if (geoMesh.facets.attributes().is_defined("CellData")) { auto facetAttribute = GEO::Attribute(geoMesh.facets.attributes(), "CellData"); - for(GEO::index_t f = 0; f < geoMesh.facets.nb(); ++f) + for (GEO::index_t f = 0; f < geoMesh.facets.nb(); ++f) { itkMesh->SetCellData(f, static_cast(facetAttribute[f])); } diff --git a/packages/mesh-filters/itkmeshToGeogramMesh.h b/packages/mesh-filters/itkmeshToGeogramMesh.h index 7feab758a..b7d12e967 100644 --- a/packages/mesh-filters/itkmeshToGeogramMesh.h +++ b/packages/mesh-filters/itkmeshToGeogramMesh.h @@ -30,7 +30,7 @@ meshToGeogramMesh(const TMesh * itkMesh, GEO::Mesh & geoMesh) using MeshType = TMesh; using PixelType = typename MeshType::PixelType; static constexpr unsigned int Dimension = MeshType::PointDimension; - static constexpr bool ITKSinglePrecision = std::is_same::value; + static constexpr bool ITKSinglePrecision = std::is_same::value; // Copy vertices auto points = itkMesh->GetPoints(); @@ -39,9 +39,9 @@ meshToGeogramMesh(const TMesh * itkMesh, GEO::Mesh & geoMesh) if (geoMesh.vertices.single_precision() && ITKSinglePrecision) { using CoordType = float; - for(auto it = points->Begin(); it != points->End(); ++it) + for (auto it = points->Begin(); it != points->End(); ++it) { - const auto& point = it.Value(); + const auto & point = it.Value(); GEO::index_t v = it.Index(); for (unsigned int d = 0; d < Dimension; ++d) { @@ -52,9 +52,9 @@ meshToGeogramMesh(const TMesh * itkMesh, GEO::Mesh & geoMesh) else { using CoordType = double; - for(auto it = points->Begin(); it != points->End(); ++it) + for (auto it = points->Begin(); it != points->End(); ++it) { - const auto& point = it.Value(); + const auto & point = it.Value(); GEO::index_t v = it.Index(); for (unsigned int d = 0; d < Dimension; ++d) { @@ -65,12 +65,13 @@ meshToGeogramMesh(const TMesh * itkMesh, GEO::Mesh & geoMesh) // Copy faces/cells auto cells = itkMesh->GetCells(); - for(auto it = cells->Begin(); it != cells->End(); ++it) + for (auto it = cells->Begin(); it != cells->End(); ++it) { - const auto& cell = it.Value(); + const auto & cell = it.Value(); GEO::vector vertices; - for(auto* pit = cell->PointIdsBegin(); pit != cell->PointIdsEnd(); ++pit) { - vertices.push_back(*pit); + for (auto * pit = cell->PointIdsBegin(); pit != cell->PointIdsEnd(); ++pit) + { + vertices.push_back(*pit); } if (vertices.size() == 3) { @@ -82,7 +83,7 @@ meshToGeogramMesh(const TMesh * itkMesh, GEO::Mesh & geoMesh) } else { - geoMesh.facets.create_polygon(vertices); + geoMesh.facets.create_polygon(vertices); } } @@ -91,7 +92,7 @@ meshToGeogramMesh(const TMesh * itkMesh, GEO::Mesh & geoMesh) if (pointData && pointData->Size() > 0) { GEO::Attribute vertexAttribute(geoMesh.vertices.attributes(), "PointData"); - for(auto it = pointData->Begin(); it != pointData->End(); ++it) + for (auto it = pointData->Begin(); it != pointData->End(); ++it) { vertexAttribute[it.Index()] = static_cast(it.Value()); } @@ -102,7 +103,7 @@ meshToGeogramMesh(const TMesh * itkMesh, GEO::Mesh & geoMesh) if (cellData && cellData->Size() > 0) { GEO::Attribute facetAttribute(geoMesh.facets.attributes(), "CellData"); - for(auto it = cellData->Begin(); it != cellData->End(); ++it) + for (auto it = cellData->Begin(); it != cellData->End(); ++it) { facetAttribute[it.Index()] = static_cast(it.Value()); } diff --git a/packages/mesh-filters/keep-largest-component.cxx b/packages/mesh-filters/keep-largest-component.cxx index b514f4ffe..7da409a1d 100644 --- a/packages/mesh-filters/keep-largest-component.cxx +++ b/packages/mesh-filters/keep-largest-component.cxx @@ -37,7 +37,8 @@ #include template -int keepLargestComponent(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) +int +keepLargestComponent(itk::wasm::Pipeline & pipeline, const TMesh * inputMesh) { using MeshType = TMesh; constexpr unsigned int Dimension = MeshType::PointDimension; @@ -48,13 +49,15 @@ int keepLargestComponent(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) pipeline.get_option("input-mesh")->required()->type_name("INPUT_MESH"); itk::wasm::OutputMesh outputMesh; - pipeline.add_option("output-mesh", outputMesh, "The output mesh with only the largest component.")->type_name("OUTPUT_MESH"); + pipeline.add_option("output-mesh", outputMesh, "The output mesh with only the largest component.") + ->type_name("OUTPUT_MESH"); ITK_WASM_PARSE(pipeline); // GEO::initialize(GEO::GEOGRAM_INSTALL_ALL); - GEO::Logger::initialize(); GEO::Logger::instance()->set_quiet(true); + GEO::Logger::initialize(); + GEO::Logger::instance()->set_quiet(true); GEO::CmdLine::initialize(); const auto flags = GEO::GEOGRAM_INSTALL_ALL; GEO::Process::initialize(flags); @@ -65,60 +68,65 @@ int keepLargestComponent(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) // component[f] will correspond to the component id of facet f GEO::vector component(geoMesh.facets.nb(), index_t(-1)); - index_t nb_comp = 0; + index_t nb_comp = 0; // Iterates on all the facets of M // (equivalent to for(index_t f = 0; f < M.facets.nb(); ++f)) - for(index_t f: geoMesh.facets) { - if(component[f] == index_t(-1)) { - // recursive traversal of the connected component - // incident to facet f (if it was not already traversed) - component[f] = nb_comp; - std::stack S; - S.push(f); - while(!S.empty()) { - index_t top_f = S.top(); - S.pop(); - // Push the neighbors of facet top_f onto the stack if - // they were not already visited - for( - index_t le=0; - le S; + S.push(f); + while (!S.empty()) + { + index_t top_f = S.top(); + S.pop(); + // Push the neighbors of facet top_f onto the stack if + // they were not already visited + for (index_t le = 0; le < geoMesh.facets.nb_vertices(top_f); ++le) + { + index_t adj_f = geoMesh.facets.adjacent(top_f, le); + if (adj_f != index_t(-1) && component[adj_f] == index_t(-1)) + { + component[adj_f] = nb_comp; + S.push(adj_f); } - ++nb_comp; + } } + ++nb_comp; + } } // Now compute the number of facets in each connected component - GEO::vector comp_size(nb_comp,0); - for(index_t f: geoMesh.facets) { - ++comp_size[component[f]]; + GEO::vector comp_size(nb_comp, 0); + for (index_t f : geoMesh.facets) + { + ++comp_size[component[f]]; } // Determine the id of the largest component index_t largest_comp = 0; index_t largest_comp_size = 0; - for(index_t comp=0; comp= largest_comp_size) { - largest_comp_size = comp_size[comp]; - largest_comp = comp; - } + for (index_t comp = 0; comp < nb_comp; ++comp) + { + if (comp_size[comp] >= largest_comp_size) + { + largest_comp_size = comp_size[comp]; + largest_comp = comp; + } } // Remove all the facets that are not in the largest component // component[] is now used as follows: // component[f] = 0 if f should be kept // component[f] = 1 if f should be deleted // See GEO::MeshElements::delete_elements() documentation. - for(index_t f: geoMesh.facets) { - component[f] = (component[f] != largest_comp) ? 1 : 0; + for (index_t f : geoMesh.facets) + { + component[f] = (component[f] != largest_comp) ? 1 : 0; } geoMesh.facets.delete_elements(component); @@ -134,7 +142,8 @@ template class PipelineFunctor { public: - int operator()(itk::wasm::Pipeline &pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using MeshType = TMesh; @@ -148,18 +157,12 @@ class PipelineFunctor } }; -int main(int argc, char *argv[]) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("keep-largest-component", "Keep only the largest component in the mesh.", argc, argv); - return itk::wasm::SupportInputMeshTypes::Dimensions< - 3U>("input-mesh", pipeline); + return itk::wasm:: + SupportInputMeshTypes:: + Dimensions<3U>("input-mesh", pipeline); } diff --git a/packages/mesh-filters/repair.cxx b/packages/mesh-filters/repair.cxx index ab0fcf777..365b4773a 100644 --- a/packages/mesh-filters/repair.cxx +++ b/packages/mesh-filters/repair.cxx @@ -34,7 +34,8 @@ #include template -int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) +int +repairMesh(itk::wasm::Pipeline & pipeline, const TMesh * inputMesh) { using MeshType = TMesh; constexpr unsigned int Dimension = MeshType::PointDimension; @@ -45,19 +46,30 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) pipeline.get_option("input-mesh")->required()->type_name("INPUT_MESH"); double pointMergeTolerance = 1e-6; - pipeline.add_option("--merge-tolerance", pointMergeTolerance, "Point merging tolerance as a percent of the bounding box diagonal."); + pipeline.add_option( + "--merge-tolerance", pointMergeTolerance, "Point merging tolerance as a percent of the bounding box diagonal."); double minimumComponentArea = 3.0; - pipeline.add_option("--minimum-component-area", minimumComponentArea, "Minimum component area as a percent of the total area. Components smaller than this are removed."); + pipeline.add_option( + "--minimum-component-area", + minimumComponentArea, + "Minimum component area as a percent of the total area. Components smaller than this are removed."); double maximumHoleArea = 1e-1; - pipeline.add_option("--maximum-hole-area", maximumHoleArea, "Maximum area of a hole as a percent of the total area. Holes smaller than this are filled."); + pipeline.add_option("--maximum-hole-area", + maximumHoleArea, + "Maximum area of a hole as a percent of the total area. Holes smaller than this are filled."); uint64_t maximumHoleEdges = 2000; - pipeline.add_option("--maximum-hole-edges", maximumHoleEdges, "Maximum number of edges in a hole. Holes with fewer edges than this are filled."); + pipeline.add_option("--maximum-hole-edges", + maximumHoleEdges, + "Maximum number of edges in a hole. Holes with fewer edges than this are filled."); double maximumDegree3VerticesDistance = 0.0; - pipeline.add_option("--maximum-degree3-distance", maximumDegree3VerticesDistance, "Maximum distance as a percent of the bounding box diagonal. Vertices with degree 3 that are closer than this are merged."); + pipeline.add_option("--maximum-degree3-distance", + maximumDegree3VerticesDistance, + "Maximum distance as a percent of the bounding box diagonal. Vertices with degree 3 that are " + "closer than this are merged."); bool removeIntersectingTriangles = false; pipeline.add_flag("--remove-intersecting-triangles", removeIntersectingTriangles, "Remove intersecting triangles."); @@ -93,27 +105,31 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) if (noTriangulate) { - GEO::mesh_repair(geoMesh, GEO::MeshRepairMode(GEO::MESH_REPAIR_COLOCATE | GEO::MESH_REPAIR_DUP_F), pointMergeTolerance); + GEO::mesh_repair( + geoMesh, GEO::MeshRepairMode(GEO::MESH_REPAIR_COLOCATE | GEO::MESH_REPAIR_DUP_F), pointMergeTolerance); } else { GEO::mesh_repair(geoMesh, GEO::MESH_REPAIR_DEFAULT, pointMergeTolerance); } - if(minimumComponentArea != 0.0) { - double numberOfFacesRemoved = geoMesh.facets.nb(); - GEO::remove_small_connected_components(geoMesh, minimumComponentArea); - numberOfFacesRemoved -= geoMesh.facets.nb(); - if(numberOfFacesRemoved != 0) { - if (noTriangulate) - { - GEO::mesh_repair(geoMesh, GEO::MeshRepairMode(GEO::MESH_REPAIR_COLOCATE | GEO::MESH_REPAIR_DUP_F), pointMergeTolerance); - } - else - { - GEO::mesh_repair(geoMesh, GEO::MESH_REPAIR_DEFAULT, pointMergeTolerance); - } + if (minimumComponentArea != 0.0) + { + double numberOfFacesRemoved = geoMesh.facets.nb(); + GEO::remove_small_connected_components(geoMesh, minimumComponentArea); + numberOfFacesRemoved -= geoMesh.facets.nb(); + if (numberOfFacesRemoved != 0) + { + if (noTriangulate) + { + GEO::mesh_repair( + geoMesh, GEO::MeshRepairMode(GEO::MESH_REPAIR_COLOCATE | GEO::MESH_REPAIR_DUP_F), pointMergeTolerance); + } + else + { + GEO::mesh_repair(geoMesh, GEO::MESH_REPAIR_DEFAULT, pointMergeTolerance); } + } } if (maximumHoleArea != 0.0 && maximumHoleEdges != 0) @@ -144,7 +160,8 @@ template class PipelineFunctor { public: - int operator()(itk::wasm::Pipeline &pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using MeshType = TMesh; @@ -158,18 +175,12 @@ class PipelineFunctor } }; -int main(int argc, char *argv[]) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("repair", "Repair a mesh so it is 2-manifold and optionally watertight.", argc, argv); - return itk::wasm::SupportInputMeshTypes::Dimensions< - 3U>("input-mesh", pipeline); + return itk::wasm:: + SupportInputMeshTypes:: + Dimensions<3U>("input-mesh", pipeline); } diff --git a/packages/mesh-filters/slice-mesh.cxx b/packages/mesh-filters/slice-mesh.cxx index 2afe42dec..dbeb605da 100644 --- a/packages/mesh-filters/slice-mesh.cxx +++ b/packages/mesh-filters/slice-mesh.cxx @@ -28,7 +28,8 @@ #include "glaze/glaze.hpp" template -int sliceMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) +int +sliceMesh(itk::wasm::Pipeline & pipeline, const TMesh * inputMesh) { using MeshType = TMesh; constexpr unsigned int Dimension = MeshType::PointDimension; @@ -53,10 +54,21 @@ int sliceMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) pipeline.get_option("input-mesh")->required()->type_name("INPUT_MESH"); itk::wasm::InputTextStream planesJson; - pipeline.add_option("planes", planesJson, "An array of plane locations to slice the mesh. Each plane is defined by an array of 'origin' and 'spacing' values.")->required()->type_name("INPUT_JSON"); + pipeline + .add_option("planes", + planesJson, + "An array of plane locations to slice the mesh. Each plane is defined by an array of 'origin' and " + "'spacing' values.") + ->required() + ->type_name("INPUT_JSON"); itk::wasm::OutputMesh outputMesh; - pipeline.add_option("polylines", outputMesh, "The output mesh comprised of polylines. Cell data indicates whether part of a closed line. Point data indicates the slice index.")->type_name("OUTPUT_MESH"); + pipeline + .add_option("polylines", + outputMesh, + "The output mesh comprised of polylines. Cell data indicates whether part of a closed line. Point data " + "indicates the slice index.") + ->type_name("OUTPUT_MESH"); ITK_WASM_PARSE(pipeline); @@ -65,7 +77,7 @@ int sliceMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) for (itk::SizeValueType i = 0; i < inputMesh->GetNumberOfPoints(); ++i) { typename MeshType::PointType point = inputMesh->GetPoint(i); - Vec3D vertex; + Vec3D vertex; for (unsigned int d = 0; d < Dimension; d++) { vertex[d] = point[d]; @@ -88,7 +100,7 @@ int sliceMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) return EXIT_FAILURE; } typename MeshType::CellType::PointIdIterator pointIdIterator = cell->PointIdsBegin(); - Face face; + Face face; for (unsigned int j = 0; j < cell->GetNumberOfPoints(); ++j) { face[j] = *pointIdIterator; @@ -99,7 +111,7 @@ int sliceMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) } const std::string planesJsonString(std::istreambuf_iterator(planesJson.Get()), {}); - auto deserializedAttempt = glz::read_json(planesJsonString); + auto deserializedAttempt = glz::read_json(planesJsonString); if (!deserializedAttempt) { const std::string descriptiveError = glz::format_error(deserializedAttempt, planesJsonString); @@ -110,23 +122,23 @@ int sliceMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) typename OutputMeshType::Pointer outputMeshPtr = OutputMeshType::New(); - PointIdentifierType pointId = 0; - CellIdentifierType cellId = 0; - size_t sliceIndex = 0; - PointDataContainer *pointData = outputMeshPtr->GetPointData(); - CellDataContainer *cellData = outputMeshPtr->GetCellData(); + PointIdentifierType pointId = 0; + CellIdentifierType cellId = 0; + size_t sliceIndex = 0; + PointDataContainer * pointData = outputMeshPtr->GetPointData(); + CellDataContainer * cellData = outputMeshPtr->GetCellData(); typename MeshPlaneIntersectType::Mesh meshPlaneIntersect(vertices, faces); - for (const auto &plane : planes) + for (const auto & plane : planes) { const auto paths = meshPlaneIntersect.Intersect(plane); - for (const auto &path : paths) + for (const auto & path : paths) { CellAutoPointer cell; cell.TakeOwnership(new PolyLineCellType); PointIdentifierType polyPointId = 0; - const auto initialPointId = pointId; - for (const auto &point : path.points) + const auto initialPointId = pointId; + for (const auto & point : path.points) { typename OutputMeshType::PointType outputPoint; for (unsigned int d = 0; d < Dimension; d++) @@ -158,7 +170,8 @@ template class PipelineFunctor { public: - int operator()(itk::wasm::Pipeline &pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using MeshType = TMesh; @@ -172,18 +185,12 @@ class PipelineFunctor } }; -int main(int argc, char *argv[]) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("slice-mesh", "Slice a mesh along planes into polylines.", argc, argv); - return itk::wasm::SupportInputMeshTypes::Dimensions< - 3U>("input-mesh", pipeline); + return itk::wasm:: + SupportInputMeshTypes:: + Dimensions<3U>("input-mesh", pipeline); } diff --git a/packages/mesh-filters/smooth-remesh.cxx b/packages/mesh-filters/smooth-remesh.cxx index cf70f80a6..763bbeeb5 100644 --- a/packages/mesh-filters/smooth-remesh.cxx +++ b/packages/mesh-filters/smooth-remesh.cxx @@ -35,7 +35,8 @@ #include template -int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) +int +repairMesh(itk::wasm::Pipeline & pipeline, const TMesh * inputMesh) { using MeshType = TMesh; constexpr unsigned int Dimension = MeshType::PointDimension; @@ -44,13 +45,18 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) pipeline.get_option("input-mesh")->required()->type_name("INPUT_MESH"); double numberPointsPercent = 75.0; - pipeline.add_option("--number-points", numberPointsPercent, "Number of points as a percent of the bounding box diagonal. Output may have slightly more points."); + pipeline.add_option( + "--number-points", + numberPointsPercent, + "Number of points as a percent of the bounding box diagonal. Output may have slightly more points."); double triangleShapeAdaptation = 1.0; - pipeline.add_option("--triangle-shape-adaptation", triangleShapeAdaptation, "Triangle shape adaptation factor. Use 0.0 to disable."); + pipeline.add_option( + "--triangle-shape-adaptation", triangleShapeAdaptation, "Triangle shape adaptation factor. Use 0.0 to disable."); double triangleSizeAdaptation = 0.0; - pipeline.add_option("--triangle-size-adaptation", triangleSizeAdaptation, "Triangle size adaptation factor. Use 0.0 to disable."); + pipeline.add_option( + "--triangle-size-adaptation", triangleSizeAdaptation, "Triangle size adaptation factor. Use 0.0 to disable."); uint32_t normalIterations = 3; pipeline.add_option("--normal-iterations", normalIterations, "Number of normal smoothing iterations."); @@ -65,7 +71,8 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) pipeline.add_option("--newton-m", newtonM, "Number of Newton evaluations per step for Hessian approximation."); uint64_t lfsSamples = 10000; - pipeline.add_option("--lfs-samples", lfsSamples, "Number of samples for size adaptation if triangle size adaptation is not 0.0."); + pipeline.add_option( + "--lfs-samples", lfsSamples, "Number of samples for size adaptation if triangle size adaptation is not 0.0."); itk::wasm::OutputMesh outputMesh; pipeline.add_option("output-mesh", outputMesh, "The output repaired mesh.")->type_name("OUTPUT_MESH"); @@ -74,7 +81,8 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) // GEO::initialize(GEO::GEOGRAM_INSTALL_ALL); - GEO::Logger::initialize(); GEO::Logger::instance()->set_quiet(true); + GEO::Logger::initialize(); + GEO::Logger::instance()->set_quiet(true); GEO::CmdLine::initialize(); const auto flags = GEO::GEOGRAM_INSTALL_ALL; GEO::Process::initialize(flags); @@ -97,29 +105,29 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) uint64_t numberPoints = static_cast(std::ceil(numberPointsPercent * 0.01 * geoMesh.vertices.nb())); - if(triangleShapeAdaptation != 0.0) + if (triangleShapeAdaptation != 0.0) { - triangleShapeAdaptation *= 0.02; - GEO::compute_normals(geoMesh); - if(normalIterations != 0) - { - GEO::simple_Laplacian_smooth(geoMesh, normalIterations, true); - } - GEO::set_anisotropy(geoMesh, triangleShapeAdaptation); + triangleShapeAdaptation *= 0.02; + GEO::compute_normals(geoMesh); + if (normalIterations != 0) + { + GEO::simple_Laplacian_smooth(geoMesh, normalIterations, true); + } + GEO::set_anisotropy(geoMesh, triangleShapeAdaptation); } else { geoMesh.vertices.set_dimension(3); } - if(triangleSizeAdaptation != 0.0) + if (triangleSizeAdaptation != 0.0) { GEO::compute_sizing_field(geoMesh, triangleSizeAdaptation, lfsSamples); } else { - GEO::AttributesManager& attributes = geoMesh.vertices.attributes(); - if(attributes.is_defined("weight")) + GEO::AttributesManager & attributes = geoMesh.vertices.attributes(); + if (attributes.is_defined("weight")) { attributes.delete_attribute_store("weight"); } @@ -129,9 +137,8 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh) GEO::remesh_smooth(geoMesh, remesh, numberPoints, 0, lloydIterations, newtonIterations, newtonM); - GEO::MeshElementsFlags what = GEO::MeshElementsFlags( - GEO::MESH_VERTICES | GEO::MESH_EDGES | GEO::MESH_FACETS | GEO::MESH_CELLS - ); + GEO::MeshElementsFlags what = + GEO::MeshElementsFlags(GEO::MESH_VERTICES | GEO::MESH_EDGES | GEO::MESH_FACETS | GEO::MESH_CELLS); geoMesh.clear(); geoMesh.copy(remesh, true, what); @@ -147,7 +154,8 @@ template class PipelineFunctor { public: - int operator()(itk::wasm::Pipeline &pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using MeshType = TMesh; @@ -161,18 +169,12 @@ class PipelineFunctor } }; -int main(int argc, char *argv[]) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("smooth-remesh", "Smooth and remesh a mesh to improve quality.", argc, argv); - return itk::wasm::SupportInputMeshTypes::Dimensions< - 3U>("input-mesh", pipeline); + return itk::wasm:: + SupportInputMeshTypes:: + Dimensions<3U>("input-mesh", pipeline); } diff --git a/packages/transform/affine-ops.cxx b/packages/transform/affine-ops.cxx index b1817641c..76d39dcd6 100644 --- a/packages/transform/affine-ops.cxx +++ b/packages/transform/affine-ops.cxx @@ -33,49 +33,49 @@ // Define operation structures for JSON parsing struct TranslateOperation { - std::string method = "Translate"; + std::string method = "Translate"; std::vector translation; - bool pre = false; + bool pre = false; }; struct ScaleOperation { - std::string method = "Scale"; + std::string method = "Scale"; std::variant> factor; - bool pre = false; + bool pre = false; }; struct RotateOperation { std::string method = "Rotate"; - int axis1; - int axis2; - double angle; - bool pre = false; + int axis1; + int axis2; + double angle; + bool pre = false; }; struct Rotate2DOperation { std::string method = "Rotate2D"; - double angle; - bool pre = false; + double angle; + bool pre = false; }; struct Rotate3DOperation { - std::string method = "Rotate3D"; + std::string method = "Rotate3D"; std::vector axis; - double angle; - bool pre = false; + double angle; + bool pre = false; }; struct ShearOperation { std::string method = "Shear"; - int axis1; - int axis2; - double coef; - bool pre = false; + int axis1; + int axis2; + double coef; + bool pre = false; }; struct SetIdentityOperation @@ -84,94 +84,67 @@ struct SetIdentityOperation }; // Glaze metadata for JSON operations -template<> +template <> struct glz::meta { using T = TranslateOperation; - static constexpr auto value = object( - "method", &T::method, - "translation", &T::translation, - "pre", &T::pre - ); + static constexpr auto value = object("method", &T::method, "translation", &T::translation, "pre", &T::pre); }; -template<> +template <> struct glz::meta { using T = ScaleOperation; - static constexpr auto value = object( - "method", &T::method, - "factor", &T::factor, - "pre", &T::pre - ); + static constexpr auto value = object("method", &T::method, "factor", &T::factor, "pre", &T::pre); }; -template<> +template <> struct glz::meta { using T = RotateOperation; - static constexpr auto value = object( - "method", &T::method, - "axis1", &T::axis1, - "axis2", &T::axis2, - "angle", &T::angle, - "pre", &T::pre - ); + static constexpr auto value = + object("method", &T::method, "axis1", &T::axis1, "axis2", &T::axis2, "angle", &T::angle, "pre", &T::pre); }; -template<> +template <> struct glz::meta { using T = Rotate2DOperation; - static constexpr auto value = object( - "method", &T::method, - "angle", &T::angle, - "pre", &T::pre - ); + static constexpr auto value = object("method", &T::method, "angle", &T::angle, "pre", &T::pre); }; -template<> +template <> struct glz::meta { using T = Rotate3DOperation; - static constexpr auto value = object( - "method", &T::method, - "axis", &T::axis, - "angle", &T::angle, - "pre", &T::pre - ); + static constexpr auto value = object("method", &T::method, "axis", &T::axis, "angle", &T::angle, "pre", &T::pre); }; -template<> +template <> struct glz::meta { using T = ShearOperation; - static constexpr auto value = object( - "method", &T::method, - "axis1", &T::axis1, - "axis2", &T::axis2, - "coef", &T::coef, - "pre", &T::pre - ); + static constexpr auto value = + object("method", &T::method, "axis1", &T::axis1, "axis2", &T::axis2, "coef", &T::coef, "pre", &T::pre); }; -template<> +template <> struct glz::meta { using T = SetIdentityOperation; - static constexpr auto value = object( - "method", &T::method - ); + static constexpr auto value = object("method", &T::method); }; -template +template class AffineOpsPipelineFunctor { public: - int operator()(itk::wasm::Pipeline & pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using TransformType = TTransform; - using AffineTransformType = itk::AffineTransform; + using AffineTransformType = + itk::AffineTransform; using InputTransformType = itk::wasm::InputTransform; InputTransformType inputTransform; @@ -193,12 +166,12 @@ class AffineOpsPipelineFunctor ITK_WASM_PARSE(pipeline); // Read the operations JSON - std::string operationsJson{std::istreambuf_iterator(operationsStream.Get()), - std::istreambuf_iterator()}; + std::string operationsJson{ std::istreambuf_iterator(operationsStream.Get()), + std::istreambuf_iterator() }; // Parse as a vector of generic JSON objects first std::vector operations; - auto parseResult = glz::read_json(operations, operationsJson); + auto parseResult = glz::read_json(operations, operationsJson); if (parseResult) { std::cerr << "Error parsing operations JSON: " << glz::format_error(parseResult, operationsJson) << std::endl; @@ -209,7 +182,7 @@ class AffineOpsPipelineFunctor auto affineTransform = AffineTransformType::New(); // Try to cast input transform to affine transform first, otherwise copy parameters - auto inputAffineTransform = dynamic_cast(inputTransform.Get()); + auto inputAffineTransform = dynamic_cast(inputTransform.Get()); if (inputAffineTransform) { affineTransform->SetParameters(inputAffineTransform->GetParameters()); @@ -223,7 +196,7 @@ class AffineOpsPipelineFunctor } // Process each operation - for (const auto& opJson : operations) + for (const auto & opJson : operations) { try { @@ -232,7 +205,7 @@ class AffineOpsPipelineFunctor // Parse the operation as a generic object to extract the method std::map opMap; - auto parseResult = glz::read_json(opMap, opJsonStr); + auto parseResult = glz::read_json(opMap, opJsonStr); if (parseResult) { std::cerr << "Error parsing operation object: " << glz::format_error(parseResult, opJsonStr) << std::endl; @@ -247,7 +220,7 @@ class AffineOpsPipelineFunctor } std::string method; - auto methodResult = glz::read_json(method, glz::write_json(methodIter->second).value_or("")); + auto methodResult = glz::read_json(method, glz::write_json(methodIter->second).value_or("")); if (methodResult) { std::cerr << "Error parsing method field" << std::endl; @@ -257,7 +230,7 @@ class AffineOpsPipelineFunctor if (method == "Translate") { TranslateOperation op; - auto result = glz::read_json(op, opJsonStr); + auto result = glz::read_json(op, opJsonStr); if (result) { std::cerr << "Error parsing Translate operation: " << glz::format_error(result, opJsonStr) << std::endl; @@ -266,7 +239,8 @@ class AffineOpsPipelineFunctor if (op.translation.size() != AffineTransformType::InputSpaceDimension) { - std::cerr << "Translation vector must have " << AffineTransformType::InputSpaceDimension << " elements" << std::endl; + std::cerr << "Translation vector must have " << AffineTransformType::InputSpaceDimension << " elements" + << std::endl; return EXIT_FAILURE; } @@ -281,7 +255,7 @@ class AffineOpsPipelineFunctor else if (method == "Scale") { ScaleOperation op; - auto result = glz::read_json(op, opJsonStr); + auto result = glz::read_json(op, opJsonStr); if (result) { std::cerr << "Error parsing Scale operation: " << glz::format_error(result, opJsonStr) << std::endl; @@ -298,7 +272,8 @@ class AffineOpsPipelineFunctor auto factorVec = std::get>(op.factor); if (factorVec.size() != AffineTransformType::InputSpaceDimension) { - std::cerr << "Scale factor vector must have " << AffineTransformType::InputSpaceDimension << " elements" << std::endl; + std::cerr << "Scale factor vector must have " << AffineTransformType::InputSpaceDimension << " elements" + << std::endl; return EXIT_FAILURE; } @@ -313,21 +288,22 @@ class AffineOpsPipelineFunctor else if (method == "Rotate") { RotateOperation op; - auto result = glz::read_json(op, opJsonStr); + auto result = glz::read_json(op, opJsonStr); if (result) { std::cerr << "Error parsing Rotate operation: " << glz::format_error(result, opJsonStr) << std::endl; return EXIT_FAILURE; } - affineTransform->Rotate(op.axis1, op.axis2, static_cast(op.angle), op.pre); + affineTransform->Rotate( + op.axis1, op.axis2, static_cast(op.angle), op.pre); } else if (method == "Rotate2D") { if constexpr (AffineTransformType::InputSpaceDimension == 2) { Rotate2DOperation op; - auto result = glz::read_json(op, opJsonStr); + auto result = glz::read_json(op, opJsonStr); if (result) { std::cerr << "Error parsing Rotate2D operation: " << glz::format_error(result, opJsonStr) << std::endl; @@ -347,7 +323,7 @@ class AffineOpsPipelineFunctor if constexpr (AffineTransformType::InputSpaceDimension == 3) { Rotate3DOperation op; - auto result = glz::read_json(op, opJsonStr); + auto result = glz::read_json(op, opJsonStr); if (result) { std::cerr << "Error parsing Rotate3D operation: " << glz::format_error(result, opJsonStr) << std::endl; @@ -377,14 +353,15 @@ class AffineOpsPipelineFunctor else if (method == "Shear") { ShearOperation op; - auto result = glz::read_json(op, opJsonStr); + auto result = glz::read_json(op, opJsonStr); if (result) { std::cerr << "Error parsing Shear operation: " << glz::format_error(result, opJsonStr) << std::endl; return EXIT_FAILURE; } - affineTransform->Shear(op.axis1, op.axis2, static_cast(op.coef), op.pre); + affineTransform->Shear( + op.axis1, op.axis2, static_cast(op.coef), op.pre); } else if (method == "SetIdentity") { @@ -396,7 +373,7 @@ class AffineOpsPipelineFunctor return EXIT_FAILURE; } } - catch (const std::exception& e) + catch (const std::exception & e) { std::cerr << "Error processing operation: " << e.what() << std::endl; return EXIT_FAILURE; @@ -415,6 +392,6 @@ main(int argc, char * argv[]) itk::wasm::Pipeline pipeline("affine-ops", "Apply operations to an affine transform", argc, argv); // Support float and double parameter types, and dimensions 2, 3, and 4 - return itk::wasm::SupportInputTransformTypes - ::Dimensions<2U, 3U, 4U>("input-transform", pipeline); + return itk::wasm::SupportInputTransformTypes::Dimensions<2U, 3U, 4U>( + "input-transform", pipeline); } diff --git a/packages/transform/create-transform.cxx b/packages/transform/create-transform.cxx index 3fccbffae..8d944347b 100644 --- a/packages/transform/create-transform.cxx +++ b/packages/transform/create-transform.cxx @@ -17,7 +17,7 @@ *=========================================================================*/ #ifndef TRANSFORM_NAME -#error "TRANSFORM_NAME must be defined" +# error "TRANSFORM_NAME must be defined" #endif #define VALUE(string) #string @@ -58,17 +58,15 @@ #include "itkVelocityFieldTransform.h" template -int CreateTransformParameterization( - itk::wasm::Pipeline & pipeline) +int +CreateTransformParameterization(itk::wasm::Pipeline & pipeline) { using TransformType = TTransform; using ParametersValueType = typename TransformType::ParametersValueType; using OutputTransformType = itk::wasm::OutputTransform; OutputTransformType outputTransform; - pipeline.add_option("transform", outputTransform, "Output transform") - ->type_name("OUTPUT_TRANSFORM") - ->required(); + pipeline.add_option("transform", outputTransform, "Output transform")->type_name("OUTPUT_TRANSFORM")->required(); ITK_WASM_PARSE(pipeline); @@ -137,81 +135,82 @@ int CreateTransformParameterization( } template -int CreateTransformDimension( - itk::wasm::Pipeline & pipeline) +int +CreateTransformDimension(itk::wasm::Pipeline & pipeline) { using ParametersValueType = TParameterValues; #ifdef TRANSFORM_COMPOSITE - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_IDENTITY) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_TRANSLATION) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_EULER2D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_EULER3D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_RIGID2D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_RIGID3D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_RIGID3D_PERSPECTIVE) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_VERSOR_RIGID3D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_VERSOR) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_SCALE) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_SCALE_LOGARITHMIC) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_SCALE_SKEW_VERSOR3D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_SIMILARITY2D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_SIMILARITY3D) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_QUATERNION_RIGID) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_AFFINE) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_SCALABLE_AFFINE) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_AZIMUTH_ELEVATION_TO_CARTESIAN) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_BSPLINE) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_BSPLINE_SMOOTHING_ON_UPDATE_DISPLACEMENT_FIELD) - return CreateTransformParameterization< - itk::BSplineSmoothingOnUpdateDisplacementFieldTransform>(pipeline); + return CreateTransformParameterization< + itk::BSplineSmoothingOnUpdateDisplacementFieldTransform>(pipeline); #elif defined(TRANSFORM_CONSTANT_VELOCITY_FIELD) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>( + pipeline); #elif defined(TRANSFORM_DISPLACEMENT_FIELD) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_GAUSSIAN_SMOOTHING_ON_UPDATE_DISPLACEMENT_FIELD) - return CreateTransformParameterization< - itk::GaussianSmoothingOnUpdateDisplacementFieldTransform>(pipeline); + return CreateTransformParameterization< + itk::GaussianSmoothingOnUpdateDisplacementFieldTransform>(pipeline); #elif defined(TRANSFORM_GAUSSIAN_EXPONENTIAL_DIFFEOMORPHIC) - return CreateTransformParameterization< - itk::GaussianExponentialDiffeomorphicTransform>(pipeline); + return CreateTransformParameterization< + itk::GaussianExponentialDiffeomorphicTransform>(pipeline); #elif defined(TRANSFORM_VELOCITY_FIELD) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>(pipeline); #elif defined(TRANSFORM_TIME_VARYING_VELOCITY_FIELD) - return CreateTransformParameterization>(pipeline); + return CreateTransformParameterization>( + pipeline); #elif defined(TRANSFORM_GAUSSIAN_SMOOTHING_ON_UPDATE_TIME_VARYING_VELOCITY_FIELD) - return CreateTransformParameterization< - itk::GaussianSmoothingOnUpdateTimeVaryingVelocityFieldTransform>(pipeline); + return CreateTransformParameterization< + itk::GaussianSmoothingOnUpdateTimeVaryingVelocityFieldTransform>(pipeline); #else - std::cerr << "Unsupported transform parameterization: " << TO_LITERAL(TRANSFORM_NAME) << std::endl; - throw std::logic_error("Unsupported transform parameterization"); + std::cerr << "Unsupported transform parameterization: " << TO_LITERAL(TRANSFORM_NAME) << std::endl; + throw std::logic_error("Unsupported transform parameterization"); #endif } template -int CreateTransformParameterValues( - itk::wasm::Pipeline & pipeline, - unsigned int dimension) +int +CreateTransformParameterValues(itk::wasm::Pipeline & pipeline, unsigned int dimension) { using ParametersValueType = TParameterValues; @@ -221,13 +220,18 @@ int CreateTransformParameterValues( case 2: return CreateTransformDimension(pipeline); default: - std::cerr << "Transform " << TO_LITERAL(TRANSFORM_NAME) << " only supports 2D. Unsupported dimension: " << dimension << std::endl; + std::cerr << "Transform " << TO_LITERAL(TRANSFORM_NAME) + << " only supports 2D. Unsupported dimension: " << dimension << std::endl; throw std::logic_error("Unsupported dimension"); -#elif defined(TRANSFORM_EULER3D) || defined(TRANSFORM_RIGID3D) || defined(TRANSFORM_VERSOR_RIGID3D) || defined(TRANSFORM_VERSOR) || defined(TRANSFORM_SCALE_SKEW_VERSOR3D) || defined(TRANSFORM_SIMILARITY3D) || defined(TRANSFORM_QUATERNION_RIGID) || defined(TRANSFORM_RIGID3D_PERSPECTIVE) || defined(TRANSFORM_AZIMUTH_ELEVATION_TO_CARTESIAN) +#elif defined(TRANSFORM_EULER3D) || defined(TRANSFORM_RIGID3D) || defined(TRANSFORM_VERSOR_RIGID3D) || \ + defined(TRANSFORM_VERSOR) || defined(TRANSFORM_SCALE_SKEW_VERSOR3D) || defined(TRANSFORM_SIMILARITY3D) || \ + defined(TRANSFORM_QUATERNION_RIGID) || defined(TRANSFORM_RIGID3D_PERSPECTIVE) || \ + defined(TRANSFORM_AZIMUTH_ELEVATION_TO_CARTESIAN) case 3: return CreateTransformDimension(pipeline); default: - std::cerr << "Transform " << TO_LITERAL(TRANSFORM_NAME) << " only supports 3D. Unsupported dimension: " << dimension << std::endl; + std::cerr << "Transform " << TO_LITERAL(TRANSFORM_NAME) + << " only supports 3D. Unsupported dimension: " << dimension << std::endl; throw std::logic_error("Unsupported dimension"); #else // Multi-dimensional transforms (2D, 3D, 4D) @@ -255,7 +259,10 @@ main(int argc, char * argv[]) #if defined(TRANSFORM_EULER2D) || defined(TRANSFORM_RIGID2D) || defined(TRANSFORM_SIMILARITY2D) constexpr unsigned int dimension = 2; -#elif defined(TRANSFORM_EULER) || defined(TRANSFORM_RIGID) || defined(TRANSFORM_VERSOR_RIGID) || defined(TRANSFORM_VERSOR) || defined(TRANSFORM_SCALE_SKEW_VERSOR) || defined(TRANSFORM_SIMILARITY) || defined(TRANSFORM_QUATERNION_RIGID) || defined(TRANSFORM_RIGID_PERSPECTIVE) || defined(TRANSFORM_AZIMUTH_ELEVATION_TO_CARTESIAN) +#elif defined(TRANSFORM_EULER) || defined(TRANSFORM_RIGID) || defined(TRANSFORM_VERSOR_RIGID) || \ + defined(TRANSFORM_VERSOR) || defined(TRANSFORM_SCALE_SKEW_VERSOR) || defined(TRANSFORM_SIMILARITY) || \ + defined(TRANSFORM_QUATERNION_RIGID) || defined(TRANSFORM_RIGID_PERSPECTIVE) || \ + defined(TRANSFORM_AZIMUTH_ELEVATION_TO_CARTESIAN) constexpr unsigned int dimension = 3; #else unsigned int dimension = 3; diff --git a/src/exceptionShimInitPrimaryException.cxx b/src/exceptionShimInitPrimaryException.cxx index e89720ae5..a0aab3501 100644 --- a/src/exceptionShimInitPrimaryException.cxx +++ b/src/exceptionShimInitPrimaryException.cxx @@ -20,16 +20,17 @@ #ifdef __cplusplus -#include +# include -extern "C" { - -// Only triggered with Debug wasi-threads builds -int __cxa_init_primary_exception(void *, void *, void *) +extern "C" { - return 0; -} + // Only triggered with Debug wasi-threads builds + int + __cxa_init_primary_exception(void *, void *, void *) + { + return 0; + } } #endif // __cplusplus diff --git a/src/itkMetaDataDictionaryJSON.cxx b/src/itkMetaDataDictionaryJSON.cxx index e23293668..f9b94c390 100644 --- a/src/itkMetaDataDictionaryJSON.cxx +++ b/src/itkMetaDataDictionaryJSON.cxx @@ -20,59 +20,75 @@ namespace itk { -namespace { - // Sanitize string for JSON: replace invalid UTF-8 and control characters with U+FFFD - // See: https://github.com/nlohmann/json/pull/1314 - std::string sanitizeForJSON(const std::string& input) { - std::string output; - output.reserve(input.size()); +namespace +{ +// Sanitize string for JSON: replace invalid UTF-8 and control characters with U+FFFD +// See: https://github.com/nlohmann/json/pull/1314 +std::string +sanitizeForJSON(const std::string & input) +{ + std::string output; + output.reserve(input.size()); - for (size_t i = 0; i < input.size(); ++i) { - const unsigned char c = static_cast(input[i]); + for (size_t i = 0; i < input.size(); ++i) + { + const unsigned char c = static_cast(input[i]); - // Control characters (except tab, newline, CR) and DEL break JSON - if ((c < 0x20 && c != 0x09 && c != 0x0A && c != 0x0D) || c == 0x7F) { + // Control characters (except tab, newline, CR) and DEL break JSON + if ((c < 0x20 && c != 0x09 && c != 0x0A && c != 0x0D) || c == 0x7F) + { + output.append("\xEF\xBF\xBD"); + continue; + } + else if (c < 0x80) + { + output.push_back(c); + } + else + { + size_t bytes_needed = 0; + if ((c & 0xE0) == 0xC0) + bytes_needed = 1; + else if ((c & 0xF0) == 0xE0) + bytes_needed = 2; + else if ((c & 0xF8) == 0xF0) + bytes_needed = 3; + else + { + // Invalid UTF-8 start byte - replace with U+FFFD (UTF-8: 0xEF 0xBF 0xBD) output.append("\xEF\xBF\xBD"); continue; } - else if (c < 0x80) { - output.push_back(c); - } - else { - size_t bytes_needed = 0; - if ((c & 0xE0) == 0xC0) bytes_needed = 1; - else if ((c & 0xF0) == 0xE0) bytes_needed = 2; - else if ((c & 0xF8) == 0xF0) bytes_needed = 3; - else { - // Invalid UTF-8 start byte - replace with U+FFFD (UTF-8: 0xEF 0xBF 0xBD) - output.append("\xEF\xBF\xBD"); - continue; - } - bool valid = (i + bytes_needed < input.size()); - for (size_t j = 1; j <= bytes_needed && valid; ++j) { - const unsigned char cont = static_cast(input[i + j]); - if ((cont & 0xC0) != 0x80) { - valid = false; - } + bool valid = (i + bytes_needed < input.size()); + for (size_t j = 1; j <= bytes_needed && valid; ++j) + { + const unsigned char cont = static_cast(input[i + j]); + if ((cont & 0xC0) != 0x80) + { + valid = false; } + } - if (valid) { - for (size_t j = 0; j <= bytes_needed; ++j) { - output.push_back(input[i + j]); - } - i += bytes_needed; - } - else { - // Invalid UTF-8 sequence - replace with U+FFFD - output.append("\xEF\xBF\xBD"); + if (valid) + { + for (size_t j = 0; j <= bytes_needed; ++j) + { + output.push_back(input[i + j]); } + i += bytes_needed; + } + else + { + // Invalid UTF-8 sequence - replace with U+FFFD + output.append("\xEF\xBF\xBD"); } } - - return output; } + + return output; } +} // namespace void metaDataDictionaryToJSON(const itk::MetaDataDictionary & dictionary, MetadataJSON & metaDataJSON) @@ -150,9 +166,10 @@ metaDataDictionaryToJSON(const itk::MetaDataDictionary & dictionary, MetadataJSO if (stringVectorValue) { const std::vector values = stringVectorValue->GetMetaDataObjectValue(); - glz::json_t::array_t valueString; + glz::json_t::array_t valueString; valueString.reserve(values.size()); - for (const auto& str : values) { + for (const auto & str : values) + { valueString.push_back(sanitizeForJSON(str)); } metaDataJSON.push_back({ key, valueString }); diff --git a/src/itkSupportInputTransformTypes.cxx b/src/itkSupportInputTransformTypes.cxx index 5398d1408..db31d5a13 100644 --- a/src/itkSupportInputTransformTypes.cxx +++ b/src/itkSupportInputTransformTypes.cxx @@ -50,7 +50,8 @@ lexical_cast(const std::string & input, TransformTypeJSON & transformType) { #ifndef ITK_WASM_NO_FILESYSTEM_IO using TransformIOFactoryFloatType = itk::TransformIOFactoryTemplate; - TransformIOBaseTemplate::Pointer transformIOFloat = TransformIOFactoryFloatType::CreateTransformIO(input.c_str(), CommonEnums::IOFileMode::ReadMode); + TransformIOBaseTemplate::Pointer transformIOFloat = + TransformIOFactoryFloatType::CreateTransformIO(input.c_str(), CommonEnums::IOFileMode::ReadMode); if (transformIOFloat.IsNull()) { std::cerr << "IO not available for: " << input << std::endl; @@ -60,8 +61,8 @@ lexical_cast(const std::string & input, TransformTypeJSON & transformType) transformIOFloat->SetFileName(input); transformIOFloat->Read(); - const auto transformList = transformIOFloat->GetReadTransformList(); - const auto firstTransform = transformList.front(); + const auto transformList = transformIOFloat->GetReadTransformList(); + const auto firstTransform = transformList.front(); const std::string transformName = firstTransform->GetTransformTypeAsString(); // if the transformName contains "float", then set the transformType to float if (transformName.find("float") != std::string::npos) diff --git a/src/pthreadShim.cxx b/src/pthreadShim.cxx index 3ac306cda..d3911f784 100644 --- a/src/pthreadShim.cxx +++ b/src/pthreadShim.cxx @@ -20,20 +20,22 @@ #include -extern "C" { - -int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope) +extern "C" { - return 0; -} -int pthread_atfork( - void (*prepare)(void), // Called before fork - void (*parent)(void), // Called in parent after fork - void (*child)(void) // Called in child after fork -) -{ - return 0; -} + int + pthread_attr_setscope(pthread_attr_t * attr, int contentionscope) + { + return 0; + } + + int + pthread_atfork(void (*prepare)(void), // Called before fork + void (*parent)(void), // Called in parent after fork + void (*child)(void) // Called in child after fork + ) + { + return 0; + } } // end extern "C" diff --git a/test/itkSupportInputTransformTypesTest.cxx b/test/itkSupportInputTransformTypesTest.cxx index 25da5ec8f..17c991173 100644 --- a/test/itkSupportInputTransformTypesTest.cxx +++ b/test/itkSupportInputTransformTypesTest.cxx @@ -30,11 +30,14 @@ class PipelineFunctor int operator()(itk::wasm::Pipeline & pipeline) { - using TransformType = itk::AffineTransform; + using TransformType = + itk::AffineTransform; using InputTransformType = itk::wasm::InputTransform; InputTransformType inputTransform; - pipeline.add_option("input-transform", inputTransform, "The input transform")->required()->type_name("INPUT_TRANSFORM"); + pipeline.add_option("input-transform", inputTransform, "The input transform") + ->required() + ->type_name("INPUT_TRANSFORM"); using OutputTransformType = itk::wasm::OutputTransform; OutputTransformType outputTransform; @@ -58,5 +61,6 @@ itkSupportInputTransformTypesTest(int argc, char * argv[]) itk::WasmTransformIOFactory::RegisterOneFactory(); - return itk::wasm::SupportInputTransformTypes::Dimensions<2U, 3U>("input-transform", pipeline); + return itk::wasm::SupportInputTransformTypes::Dimensions<2U, 3U>("input-transform", + pipeline); }