Building vtkITK Lib with Emscripten

I just read @matt.mccormick answer to @prashanth.dumpuri about building with Emscripten for beginners (Building ITK with emscripten - #5 by matt.mccormick) and it helped me a lot.

I am using insighttoolkit/itk-js in docker and it works great for both examples mentioned there (Hello World and Median filter test). I can build javascript (as well as wasm), run it with runPipelineNode and runPipelineBrowser.

Can I do the same with the content of vtkItk Library (Slicer/Libs/vtkITK at 08789e8f2224f89206b2d6a49d1d452d4e677994 · Slicer/Slicer · GitHub)? Is it possible to define CmakeLists.txt and a proper pipeline for vtkItkLevelTracingImageFilter in main function, so it can be converted to javascript?

I need to use vtkItkLevelTracingImageFilter to generate vtkPolyData. However, I do not know if I can convert vtkItk Library with Emscripten to js at all.
I did a small experiment : just added #include ‚ÄúvtkItkLevelTracingImageFilter.h‚ÄĚ to MedianFilterTest.cxx code and then I had error as below

I will appreciate any help

shared:ERROR: '/emsdk_portable/fastcomp/fastcomp/bin/clang++ -target asmjs-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=10 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/include/libcxx -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/lib/libcxxabi/include -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/include/compat -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/include -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/include/libc -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/lib/libc/musl/arch/emscripten -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/local/include -Xclang -isystem/emsdk_portable/.data/cache/asmjs/include -DITK_IO_FACTORY_REGISTER_MANAGER -IITKFactoryRegistration -I/ITK/Modules/Filtering/Smoothing/include -I/ITK/Modules/Filtering/ImageFilterBase/include -I/ITK/Modules/Core/Transform/include -I/ITK-build/Modules/ThirdParty/Netlib -I/ITK/Modules/Numerics/Statistics/include -I/ITK/Modules/Core/ImageAdaptors/include -I/ITK/Modules/Core/ImageFunction/include -I/ITK/Modules/IO/ImageBase/include -I/ITK-build/Modules/IO/ImageBase -I/ITK-build/Modules/ThirdParty/VNL/src/vxl/core -I/ITK-build/Modules/ThirdParty/VNL/src/vxl/vcl -I/ITK-build/Modules/ThirdParty/VNL/src/vxl/v3p/netlib -I/ITK/Modules/ThirdParty/VNL/src/vxl/core -I/ITK/Modules/ThirdParty/KWIML/src -I/ITK-build/Modules/ThirdParty/KWIML/src -I/ITK-build/Modules/ThirdParty/Eigen3/src -I/ITK/Modules/Core/Common/include -I/ITK-build/Modules/Core/Common -I/ITKBridgeJavaScript-build/include -I/ITKBridgeJavaScript/include -isystem /ITK/Modules/ThirdParty/VNL/src/vxl/vcl -isystem /ITK/Modules/ThirdParty/VNL/src/vxl/v3p/netlib -isystem /ITK-build/Modules/ThirdParty/KWSys/src -isystem /ITK/Modules/ThirdParty/Eigen3/src/itkeigen/.. -isystem /ITK/Modules/ThirdParty/VNL/src/vxl/core/vnl/algo -isystem /ITK/Modules/ThirdParty/VNL/src/vxl/core/vnl -isystem /ITK-build/Modules/ThirdParty/VNL/src/vxl/core/vnl -std=c++11 -DNDEBUG -O2 -std=gnu++11 -MD -MT CMakeFiles/MedianFilterTest.dir/MedianFilterTest.cxx.o -MF CMakeFiles/MedianFilterTest.dir/MedianFilterTest.cxx.o.d -c -DEMSCRIPTEN -mllvm -disable-llvm-optzns ../MedianFilterTest.cxx -Xclang -disable-O0-optnone -Xclang -isystem/emsdk_portable/fastcomp/emscripten/system/include/SDL -c -o CMakeFiles/MedianFilterTest.dir/MedianFilterTest.cxx.o -emit-llvm' failed (1)
ninja: build stopped: subcommand failed.
1 Like

Hi @Andrzej_Marciniak ,

Thanks for sharing your success with itk.js!

Yes, it should be possible. A Docker image is provided with both ITK and VTK available, and if your CMakeList.txt contains find_package(ITK) or find_package(VTK), they will be found without any other steps required. To use this kitware/itk-js-vtk image, specify it via the itk-js CLI:

$ itk-js build --image kitware/itk-js-vtk:latest my/source/path

Also, note that recent versions of itk-js Docker images ship with support for SlicerExecutionModel CLI’s.

Thank you Matt! It is a very helpful answer!

1 Like