From d6d576d2b7ff5df59da97343cc102770d2f627ed Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 20 Jun 2023 10:58:56 -0400 Subject: [PATCH 1/6] COMP: Avoid mutex use with WASI toolchain Currently unsupported. Addresses: ``` /work/wasi-build/_deps/elx-src/Common/itkComputeImageExtremaFilter.h:132:8: error: no type named 'mutex' in namespace 'std' std::mutex m_Mutex{}; ~~~~~^ ``` --- Common/itkComputeImageExtremaFilter.h | 2 ++ Common/itkComputeImageExtremaFilter.hxx | 4 ++++ Core/Kernel/elxlog.cxx | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/Common/itkComputeImageExtremaFilter.h b/Common/itkComputeImageExtremaFilter.h index 5eda9238b..cbf9b16f4 100644 --- a/Common/itkComputeImageExtremaFilter.h +++ b/Common/itkComputeImageExtremaFilter.h @@ -129,7 +129,9 @@ class ITK_TEMPLATE_EXPORT ComputeImageExtremaFilter : public StatisticsImageFilt PixelType m_ThreadMin{ 1 }; PixelType m_ThreadMax{ 1 }; +#ifndef __wasi__ std::mutex m_Mutex{}; +#endif }; // end of class } // end namespace itk diff --git a/Common/itkComputeImageExtremaFilter.hxx b/Common/itkComputeImageExtremaFilter.hxx index ef288d55d..f91aabfe5 100644 --- a/Common/itkComputeImageExtremaFilter.hxx +++ b/Common/itkComputeImageExtremaFilter.hxx @@ -176,7 +176,9 @@ ComputeImageExtremaFilter::ThreadedGenerateDataImageSpatialMask(con } // end for } // end if +#ifndef __wasi__ std::lock_guard mutexHolder(m_Mutex); +#endif m_ThreadSum += sum; m_SumOfSquares += sumOfSquares; m_Count += count; @@ -227,7 +229,9 @@ ComputeImageExtremaFilter::ThreadedGenerateDataImageMask(const Regi ++it; } // end while +#ifndef __wasi__ std::lock_guard mutexHolder(m_Mutex); +#endif m_ThreadSum += sum; m_SumOfSquares += sumOfSquares; m_Count += count; diff --git a/Core/Kernel/elxlog.cxx b/Core/Kernel/elxlog.cxx index 2633ef808..14a4974ab 100644 --- a/Core/Kernel/elxlog.cxx +++ b/Core/Kernel/elxlog.cxx @@ -22,7 +22,9 @@ #include #include #include +#ifndef __wasi__ #include +#endif namespace elastix { @@ -50,7 +52,9 @@ class logger void to_file(const std::string & message) { +#ifndef __wasi__ const std::lock_guard lock(m_file_mutex); +#endif if (!m_data.log_filename.empty()) { @@ -66,7 +70,9 @@ class logger void to_stdout(const std::string & message) { +#ifndef __wasi__ const std::lock_guard lock(m_stdout_mutex); +#endif std::cout << message << std::endl; } @@ -115,8 +121,10 @@ class logger data m_data{}; +#ifndef __wasi__ std::mutex m_file_mutex{}; std::mutex m_stdout_mutex{}; +#endif }; From 6492d1e705553ff95083ff74e036ac7e29847c63 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 20 Jun 2023 11:25:44 -0400 Subject: [PATCH 2/6] COMP: Remove IO depends for Wasm builds Reduces Wasm binary size and addresses the build error: ``` wasm-ld-15: error: _deps/elx-build/bin/libelastix-5.1.a(elxComponentLoader.cxx.o): undefined symbol: __cxa_thread_atexit wasm-ld-15: error: _deps/elx-build/bin/libelastix-5.1.a(elxComponentLoader.cxx.o): undefined symbol: __cxa_thread_atexit wasm-ld-15: error: _deps/elx-build/bin/libelastix-5.1.a(elxComponentLoader.cxx.o): undefined symbol: __cxa_thread_atexit wasm-ld-15: error: _deps/elx-build/bin/libelastix-5.1.a(elxComponentLoader.cxx.o): undefined symbol: __cxa_thread_atexit wasm-ld-15: error: /ITK-build/lib/libitkgdcmCommon-5.4.a(gdcmSystem.cxx.o): undefined symbol: gethostname wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5PLint.c.o): undefined symbol: H5PL_CLOSE_LIB wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5system.c.o): undefined symbol: tzset wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5Fint.c.o): undefined symbol: realpath wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5FDcore.c.o): undefined symbol: itk_Pflock wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5FDcore.c.o): undefined symbol: itk_Pflock wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5PLint.c.o): undefined symbol: H5PL_GET_LIB_FUNC wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5PLint.c.o): undefined symbol: H5PL_GET_LIB_FUNC wasm-ld-15: error: /ITK-build/lib/libitkhdf5-static-5.4.a(H5PLint.c.o): undefined symbol: H5PL_GET_LIB_FUNC ``` --- CMakeLists.txt | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dac479907..dd25f7198 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,23 @@ if(ELASTIX_USE_OPENCL) list(APPEND _GPU_depends ITKGPUCommon) endif() +set(_ITK_io_depends + ITKImageIO + ITKTransformIO + ITKMeshIO + ITKIOImageBase + ITKIOMeshBase + ITKIOMeshOBJ + ITKIOMeta + ITKIOTransformBase + ITKIOXML +) + +if(WASI OR EMSCRIPTEN) + # Keep Wasm binaries small + set(_ITK_io_depends) +endif() + # Find ITK. find_package(ITK 5.3 REQUIRED COMPONENTS ITKCommon @@ -43,12 +60,6 @@ find_package(ITK 5.3 REQUIRED COMPONENTS ITKImageGrid ITKImageIntensity ITKImageStatistics - ITKIOImageBase - ITKIOMeshBase - ITKIOMeshOBJ - ITKIOMeta - ITKIOTransformBase - ITKIOXML ITKMathematicalMorphology ITKMesh ITKOptimizers @@ -61,9 +72,7 @@ find_package(ITK 5.3 REQUIRED COMPONENTS ITKTransform ITKTransformFactory ${_GPU_depends} - ITKImageIO - ITKTransformIO - ITKMeshIO + ${_ITK_io_depends} ) include(${ITK_USE_FILE}) From 7244b04485f1e5231d5dd6cd90f63802e713f477 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 20 Jun 2023 11:37:45 -0400 Subject: [PATCH 3/6] BUG: Remove unused itkImageFileCastWriter includes --- Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx | 3 +++ Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx | 3 +++ Core/ComponentBaseClasses/elxResamplerBase.hxx | 1 - 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx b/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx index f9d881cd8..f13b9a32e 100644 --- a/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx +++ b/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx @@ -20,7 +20,10 @@ #include "elxFixedImagePyramidBase.h" #include "elxDeref.h" + +#ifndef __wasm32__ #include "itkImageFileCastWriter.h" +#endif namespace elastix { diff --git a/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx b/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx index de50added..0f0452b54 100644 --- a/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx +++ b/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx @@ -21,7 +21,10 @@ #include "elxMovingImagePyramidBase.h" #include "elxDeref.h" + +#ifndef __wasm32__ #include "itkImageFileCastWriter.h" +#endif namespace elastix { diff --git a/Core/ComponentBaseClasses/elxResamplerBase.hxx b/Core/ComponentBaseClasses/elxResamplerBase.hxx index 22ded08b6..b2cbe025d 100644 --- a/Core/ComponentBaseClasses/elxResamplerBase.hxx +++ b/Core/ComponentBaseClasses/elxResamplerBase.hxx @@ -22,7 +22,6 @@ #include "elxConversion.h" #include "elxDeref.h" -#include "itkImageFileCastWriter.h" #include "itkChangeInformationImageFilter.h" #include "itkAdvancedRayCastInterpolateImageFunction.h" #include "itkTimeProbe.h" From bc1829f6279eee59f2b49c0d6770b70fb687223c Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 20 Jun 2023 11:49:09 -0400 Subject: [PATCH 4/6] COMP: Do not use file IO with Wasm Avoid Wasm binary size issues and file access issues. --- .../itkImageToVectorContainerFilter.hxx | 2 -- Common/Transforms/elxTransformIO.cxx | 16 ++++++++++ Common/itkMeshFileReaderBase.h | 6 +++- .../elxMissingStructurePenalty.h | 3 -- .../elxMissingStructurePenalty.hxx | 32 ++++++++++++++++++- .../elxPolydataDummyPenalty.h | 3 -- .../elxPolydataDummyPenalty.hxx | 19 ++++++++++- .../elxStatisticalShapePenalty.hxx | 10 +++++- .../elxFixedImagePyramidBase.hxx | 11 ++++++- .../elxMovingImagePyramidBase.hxx | 9 ++++++ .../ComponentBaseClasses/elxResamplerBase.hxx | 11 ++++++- .../ComponentBaseClasses/elxTransformBase.hxx | 9 +++++- Core/Install/elxComponentLoader.cxx | 4 +++ Core/Main/elxParameterObject.cxx | 2 +- Core/Main/itkTransformixFilter.hxx | 3 +- 15 files changed, 122 insertions(+), 18 deletions(-) diff --git a/Common/ImageSamplers/itkImageToVectorContainerFilter.hxx b/Common/ImageSamplers/itkImageToVectorContainerFilter.hxx index d3d457427..eb28fef2e 100644 --- a/Common/ImageSamplers/itkImageToVectorContainerFilter.hxx +++ b/Common/ImageSamplers/itkImageToVectorContainerFilter.hxx @@ -18,8 +18,6 @@ #ifndef itkImageToVectorContainerFilter_hxx #define itkImageToVectorContainerFilter_hxx -#include "itkImageToVectorContainerFilter.h" - #include "itkMath.h" namespace itk diff --git a/Common/Transforms/elxTransformIO.cxx b/Common/Transforms/elxTransformIO.cxx index cfd5367f0..e5203ed87 100644 --- a/Common/Transforms/elxTransformIO.cxx +++ b/Common/Transforms/elxTransformIO.cxx @@ -32,8 +32,10 @@ #include #include +#ifndef __wasm32__ #include #include +#endif #include @@ -191,6 +193,11 @@ elastix::TransformIO::ConvertItkTransformBaseToSingleItkTransform(const itk::Tra void elastix::TransformIO::Write(const itk::Object & itkTransform, const std::string & fileName) { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + throw std::runtime_error(message); +#else try { const auto writer = itk::TransformFileWriter::New(); @@ -203,12 +210,20 @@ elastix::TransformIO::Write(const itk::Object & itkTransform, const std::string { log::error(std::ostringstream{} << "Error trying to write " << fileName << ":\n" << stdException.what()); } +#endif } itk::SmartPointer elastix::TransformIO::Read(const std::string & fileName) { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + throw std::runtime_error(message); + return nullptr; +#else + const auto reader = itk::TransformFileReader::New(); reader->SetFileName(fileName); @@ -221,6 +236,7 @@ elastix::TransformIO::Read(const std::string & fileName) assert(transformList->size() <= 1); return transformList->empty() ? nullptr : transformList->front(); +#endif } diff --git a/Common/itkMeshFileReaderBase.h b/Common/itkMeshFileReaderBase.h index c2b4da551..dbcef1bfc 100644 --- a/Common/itkMeshFileReaderBase.h +++ b/Common/itkMeshFileReaderBase.h @@ -20,7 +20,11 @@ #include "itkMeshSource.h" #include "itkMacro.h" -#include "itkMeshFileReader.h" // for MeshFileReaderException +#ifndef __wasm32__ +#include "itkMeshFileReaderException.h" +#else +#define MeshFileReaderException ExceptionObject +#endif namespace itk { diff --git a/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.h b/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.h index 53d9b4272..71e69897a 100644 --- a/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.h +++ b/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.h @@ -21,9 +21,6 @@ #include "elxIncludes.h" #include "itkMissingStructurePenalty.h" -#include "itkMeshFileReader.h" -#include "itkMeshFileWriter.h" - namespace elastix { diff --git a/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.hxx b/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.hxx index b335cfa7e..001f99113 100644 --- a/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.hxx +++ b/Components/Metrics/MissingStructurePenalty/elxMissingStructurePenalty.hxx @@ -21,6 +21,11 @@ #include "elxMissingStructurePenalty.h" #include "itkTimeProbe.h" +#ifndef __wasm32__ +#include "itkMeshFileReader.h" +#include "itkMeshFileWriter.h" +#endif + namespace elastix { @@ -145,6 +150,11 @@ MissingStructurePenalty::BeforeRegistration() fmeshArgument << ch << metricNumber; std::string fixedMeshName = this->GetConfiguration()->GetCommandLineArgument(fmeshArgument.str()); typename MeshType::Pointer fixedMesh; // default-constructed (null) +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); +#else if (itksys::SystemTools::GetFilenameLastExtension(fixedMeshName) == ".txt") { this->ReadTransformixPoints(fixedMeshName, fixedMesh); @@ -153,6 +163,7 @@ MissingStructurePenalty::BeforeRegistration() { this->ReadMesh(fixedMeshName, fixedMesh); } +#endif meshPointerContainer->SetElement(meshNumber, fixedMesh.GetPointer()); } @@ -281,6 +292,12 @@ template unsigned int MissingStructurePenalty::ReadMesh(const std::string & meshFileName, typename FixedMeshType::Pointer & mesh) { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); + return 0; +#else /** Read the input mesh. */ auto meshReader = itk::MeshFileReader::New(); meshReader->SetFileName(meshFileName); @@ -300,6 +317,7 @@ MissingStructurePenalty::ReadMesh(const std::string & meshFileName, ty log::info(std::ostringstream{} << " Number of specified input points: " << nrofpoints); return nrofpoints; +#endif } // end ReadMesh() @@ -311,6 +329,11 @@ template void MissingStructurePenalty::WriteResultMesh(const std::string & filename, MeshIdType meshId) { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); +#else /** Setup the pipeline. */ /** Set the points of the latest transformation. */ @@ -376,7 +399,7 @@ MissingStructurePenalty::WriteResultMesh(const std::string & filename, // restore celldata as undefined mappedMesh->SetCellData(nullptr); } - +#endif } // end WriteResultMesh() @@ -389,6 +412,12 @@ unsigned int MissingStructurePenalty::ReadTransformixPoints(const std::string & filename, typename MeshType::Pointer & mesh) // const { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); + return 0; +#else /* FB: Majority of the code is copied from elxTransformBase.hxx: TransformPointsSomePoints() Function to read 2d structures by reading elastix point files (transformix format) and connecting @@ -528,6 +557,7 @@ the sequence of points to form a 2d connected polydata contour. } } return nrofpoints; +#endif } // end ReadTransformixPoints() diff --git a/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.h b/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.h index 86108f3e3..0fbe8eee8 100644 --- a/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.h +++ b/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.h @@ -23,9 +23,6 @@ //#include "elxMetricBase.h" -#include "itkMeshFileReader.h" -#include "itkMeshFileWriter.h" - namespace elastix { /** diff --git a/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.hxx b/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.hxx index d3f4a569b..fdf7f934c 100644 --- a/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.hxx +++ b/Components/Metrics/PolydataDummyPenalty/elxPolydataDummyPenalty.hxx @@ -20,6 +20,11 @@ #include +#ifndef __wasm32__ +#include "itkMeshFileReader.h" +#include "itkMeshFileWriter.h" +#endif + namespace elastix { @@ -270,6 +275,12 @@ template unsigned int PolydataDummyPenalty::ReadMesh(const std::string & meshFileName, typename FixedMeshType::Pointer & mesh) { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); + return 0; +#else /** Read the input mesh. */ auto meshReader = itk::MeshFileReader::New(); meshReader->SetFileName(meshFileName); @@ -291,6 +302,7 @@ PolydataDummyPenalty::ReadMesh(const std::string & meshFileName, typen log::info(std::ostringstream{} << " Number of specified input points: " << nrofpoints); return nrofpoints; +#endif } // end ReadMesh() @@ -302,6 +314,11 @@ template void PolydataDummyPenalty::WriteResultMesh(const std::string & filename, MeshIdType meshId) { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); +#else /** Set the points of the latest transformation. */ const MappedMeshContainerPointer mappedMeshContainer = this->GetModifiableMappedMeshContainer(); FixedMeshPointer mappedMesh = mappedMeshContainer->ElementAt(meshId); @@ -360,7 +377,7 @@ PolydataDummyPenalty::WriteResultMesh(const std::string & filename, Me { mappedMesh->SetCellData(nullptr); } - +#endif } // end WriteResultMesh() diff --git a/Components/Metrics/StatisticalShapePenalty/elxStatisticalShapePenalty.hxx b/Components/Metrics/StatisticalShapePenalty/elxStatisticalShapePenalty.hxx index 263a3e9fa..31e576035 100644 --- a/Components/Metrics/StatisticalShapePenalty/elxStatisticalShapePenalty.hxx +++ b/Components/Metrics/StatisticalShapePenalty/elxStatisticalShapePenalty.hxx @@ -25,7 +25,9 @@ #include "itkDefaultStaticMeshTraits.h" #include "itkTransformMeshFilter.h" #include +#ifndef __wasm32__ #include +#endif #include #include @@ -352,6 +354,12 @@ StatisticalShapePenalty::ReadShape(const std::string & typename PointSetType::Pointer & pointSet, const typename ImageType::ConstPointer image) { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); + return 0; +#else /** Typedef's. \todo test DummyIPPPixelType=bool. */ using DummyIPPPixelType = double; using MeshTraitsType = @@ -380,7 +388,7 @@ StatisticalShapePenalty::ReadShape(const std::string & pointSet = PointSetType::New(); pointSet->SetPoints(mesh->GetPoints()); return nrofpoints; - +#endif } // end ReadShape() diff --git a/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx b/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx index f13b9a32e..f39aff6ef 100644 --- a/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx +++ b/Core/ComponentBaseClasses/elxFixedImagePyramidBase.hxx @@ -178,12 +178,17 @@ FixedImagePyramidBase::WritePyramidImage(const std::string & filename, /** Do the writing. */ log::to_stdout(" Writing fixed pyramid image ..."); +#ifndef __wasm32__ try { - itk::WriteCastedImage(*(this->GetAsITKBaseType()->GetOutput(level)), filename, resultImagePixelType, doCompression); + itk::WriteCastedImage(*(this->GetAsITKBaseType()->GetOutput(level)), filename, resultImagePixelType, doCompression); } catch (itk::ExceptionObject & excp) { +#else +// Always throw -- do not include support code or access filesystem with wasm + itk::ExceptionObject excp; +#endif /** Add information to the exception. */ excp.SetLocation("FixedImagePyramidBase - BeforeEachResolutionBase()"); std::string err_str = excp.GetDescription(); @@ -191,8 +196,12 @@ FixedImagePyramidBase::WritePyramidImage(const std::string & filename, excp.SetDescription(err_str); /** Pass the exception to an higher level. */ +#ifndef __wasm32__ throw; } +#else + throw excp; +#endif } // end WritePyramidImage() diff --git a/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx b/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx index 0f0452b54..2d4ff0dbe 100644 --- a/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx +++ b/Core/ComponentBaseClasses/elxMovingImagePyramidBase.hxx @@ -179,12 +179,17 @@ MovingImagePyramidBase::WritePyramidImage(const std::string & filename /** Do the writing. */ log::to_stdout(" Writing moving pyramid image ..."); +#ifndef __wasm32__ try { itk::WriteCastedImage(*(this->GetAsITKBaseType()->GetOutput(level)), filename, resultImagePixelType, doCompression); } catch (itk::ExceptionObject & excp) { +#else +// Always throw -- do not include support code or access filesystem with wasm + itk::ExceptionObject excp; +#endif /** Add information to the exception. */ excp.SetLocation("MovingImagePyramidBase - BeforeEachResolutionBase()"); std::string err_str = excp.GetDescription(); @@ -192,8 +197,12 @@ MovingImagePyramidBase::WritePyramidImage(const std::string & filename excp.SetDescription(err_str); /** Pass the exception to an higher level. */ +#ifndef __wasm32__ throw; } +#else + throw excp; +#endif } // end WritePyramidImage() diff --git a/Core/ComponentBaseClasses/elxResamplerBase.hxx b/Core/ComponentBaseClasses/elxResamplerBase.hxx index b2cbe025d..4e963565e 100644 --- a/Core/ComponentBaseClasses/elxResamplerBase.hxx +++ b/Core/ComponentBaseClasses/elxResamplerBase.hxx @@ -395,12 +395,17 @@ ResamplerBase::WriteResultImage(OutputImageType * image, { log::to_stdout("\n Writing image ..."); } +#ifndef __wasm32__ try { - itk::WriteCastedImage(*(infoChanger->GetOutput()), filename, resultImagePixelType, doCompression); + itk::WriteCastedImage(*(infoChanger->GetOutput()), filename, resultImagePixelType, doCompression); } catch (itk::ExceptionObject & excp) { +#else +// Always throw -- do not include support code or access filesystem with wasm + itk::ExceptionObject excp; +#endif /** Add information to the exception. */ excp.SetLocation("ResamplerBase - AfterRegistrationBase()"); std::string err_str = excp.GetDescription(); @@ -408,8 +413,12 @@ ResamplerBase::WriteResultImage(OutputImageType * image, excp.SetDescription(err_str); /** Pass the exception to an higher level. */ +#ifndef __wasm32__ throw; } +#else + throw excp; +#endif } // end WriteResultImage() diff --git a/Core/ComponentBaseClasses/elxTransformBase.hxx b/Core/ComponentBaseClasses/elxTransformBase.hxx index 635a78cc7..766de2524 100644 --- a/Core/ComponentBaseClasses/elxTransformBase.hxx +++ b/Core/ComponentBaseClasses/elxTransformBase.hxx @@ -38,8 +38,10 @@ #include "itkContinuousIndex.h" #include "itkChangeInformationImageFilter.h" #include "itkMesh.h" +#ifndef __wasm32__ #include "itkMeshFileReader.h" #include "itkMeshFileWriter.h" +#endif #include "itkCommonEnums.h" #include @@ -924,6 +926,11 @@ template void TransformBase::TransformPointsSomePointsVTK(const std::string & filename) const { +#ifdef __wasm32__ + const std::string message = "File IO not supported in WebAssembly builds."; + log::error(message); + itkExceptionMacro(<< message); +#else /** Typedef's. \todo test DummyIPPPixelType=bool. */ using DummyIPPPixelType = float; using MeshTraitsType = @@ -982,7 +989,7 @@ TransformBase::TransformPointsSomePointsVTK(const std::string & filena log::error(std::ostringstream{} << " Error while saving points.\n" << err); } } - +#endif } // end TransformPointsSomePointsVTK() diff --git a/Core/Install/elxComponentLoader.cxx b/Core/Install/elxComponentLoader.cxx index fb55a9b93..198c3206e 100644 --- a/Core/Install/elxComponentLoader.cxx +++ b/Core/Install/elxComponentLoader.cxx @@ -23,9 +23,11 @@ #include "elxInstallAllComponents.h" // ITKFactoryRegistration headers: +#ifndef __wasm32__ #include #include #include +#endif #include #include @@ -133,6 +135,7 @@ ComponentLoader::InstallSupportedImageTypes() int ComponentLoader::LoadComponents() { +#ifndef __wasm32__ // Retrieve those IOFactoryRegisterManager instances, just to ensure that they are really constructed. const volatile auto ioFactoryRegisterManagerInstances = std::make_tuple(itk::ImageIOFactoryRegisterManagerInstance, @@ -165,6 +168,7 @@ ComponentLoader::LoadComponents() } log::info("InstallingComponents was successful.\n"); +#endif return 0; diff --git a/Core/Main/elxParameterObject.cxx b/Core/Main/elxParameterObject.cxx index badddfc09..b0430e748 100644 --- a/Core/Main/elxParameterObject.cxx +++ b/Core/Main/elxParameterObject.cxx @@ -21,7 +21,7 @@ #include "itkParameterFileParser.h" -#include "itkFileTools.h" +#include "itksys/SystemTools.hxx" #include #include #include diff --git a/Core/Main/itkTransformixFilter.hxx b/Core/Main/itkTransformixFilter.hxx index dd7e52ec8..851da0334 100644 --- a/Core/Main/itkTransformixFilter.hxx +++ b/Core/Main/itkTransformixFilter.hxx @@ -35,8 +35,6 @@ #ifndef itkTransformixFilter_hxx #define itkTransformixFilter_hxx -#include "itkTransformixFilter.h" - #include "elxLibUtilities.h" #include "elxPixelTypeToString.h" #include "elxTransformBase.h" @@ -44,6 +42,7 @@ #include "elxDefaultConstruct.h" #include +#include #include // For unique_ptr. From 10544679e20caa08f0e7ef399a9d99bc82d0da59 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 10 Jul 2023 09:06:44 -0400 Subject: [PATCH 5/6] COMP: Load elastix components in webassembly builds We still need to load the elastix components. --- Core/Install/elxComponentLoader.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Install/elxComponentLoader.cxx b/Core/Install/elxComponentLoader.cxx index 198c3206e..e24344c75 100644 --- a/Core/Install/elxComponentLoader.cxx +++ b/Core/Install/elxComponentLoader.cxx @@ -142,6 +142,7 @@ ComponentLoader::LoadComponents() itk::MeshIOFactoryRegisterManagerInstance, itk::TransformIOFactoryRegisterManagerInstance); (void)ioFactoryRegisterManagerInstances; +#endif int installReturnCode = 0; @@ -168,7 +169,6 @@ ComponentLoader::LoadComponents() } log::info("InstallingComponents was successful.\n"); -#endif return 0; From 022aa6cdaaa5621f3d6b2f245c388a9669cc7ef9 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 26 Aug 2023 15:46:52 -0400 Subject: [PATCH 6/6] COMP: Do not write transforms to file with wasm In itkElastixRegistrationMethod.hxx. --- Core/Main/itkElastixRegistrationMethod.hxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/Main/itkElastixRegistrationMethod.hxx b/Core/Main/itkElastixRegistrationMethod.hxx index 4f2e6232c..97dc637b2 100644 --- a/Core/Main/itkElastixRegistrationMethod.hxx +++ b/Core/Main/itkElastixRegistrationMethod.hxx @@ -268,6 +268,7 @@ ElastixRegistrationMethod::GenerateData() { const auto transformFileName = "InitialTransform." + std::to_string(i) + '.' + outputFileNameExtension; +#ifndef __wasm32__ // Write the external transform to file. elx::TransformIO::Write(elx::Deref(externalTransform), m_OutputDirectory + transformFileName); @@ -275,6 +276,7 @@ ElastixRegistrationMethod::GenerateData() transformFound->second = { "File" }; transformParameterMap["TransformFileName"] = { transformFileName }; transformParameterMap.erase("TransformAddress"); +#endif } }