ITK/RTK config and build to use CudaBackProjectionImageFilter python wrapper

Hello,
I’m new to ITK/RTK and currently working on a project where we want to use RTK’s reconstruction functionality, specifically CudaFDKBackProjectionImageFilter.
However, due to my limited experience with ITK/RTK, I’ve encountered some challenges and difficulties, and I’m seeking guidance and support.

In short, after some trial and error, I was finally able to complete a successful ITK build using the following configuration:
cmake ../ITK -G “Visual Studio 17 2022” -A x64 ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=“C:/ITKRTK/ITK-install” ^
-DBUILD_EXAMPLES=OFF ^
-DBUILD_TESTING=OFF ^
-DBUILD_SHARED_LIBS=OFF ^
-DITK_WRAP_PYTHON=ON ^
-DITK_BUILD_DEFAULT_MODULES=OFF ^
-DModule_ITKCommon=ON ^
-DModule_ITKIOImageBase=ON ^
-DModule_ITKIONIFTI=ON ^
-DModule_ITKIOPNG=ON ^
-DModule_ITKIOGDCM=ON ^
-DModule_RTK=ON ^
-DModule_CudaCommon=ON ^
-DRTK_USE_CUDA=ON ^
-DITK_WRAP_unsigned_short:BOOL=ON ^
-DITK_WRAP_double:BOOL=ON ^
-DITK_WRAP_complex_double:BOOL=ON ^
-DITK_WRAP_IMAGE_DIMS:STRING=“2;3;4” ^
-DPython3_EXECUTABLE=“c:/Python/Python311/python.exe” ^
-DPython3_INCLUDE_DIR=“c:/Python/Python311/include” ^
-DPython3_LIBRARY=“c:/Python/Python311/libs/python311.lib” ^
-DPY_SITE_PACKAGES_PATH=“C:/Python/Python311/Lib/site-packages” ^
-DModule_ITKHDF5:BOOL=OFF ^
-DModule_ITKIOHDF5:BOOL=OFF ^
-DModule_ITKIOTransformHDF5:BOOL=OFF ^
-DModule_ITKIOTransformBase:BOOL=OFF ^
-DModule_ITKIOTransformMatlab:BOOL=OFF
The build completed successfully, but when I tried the following Python commands (We need to use this CudaFDKBackProjectionImageFilter instead of CudaBackProjectionImageFilter), I received an error indicating that the function was not found:
from itk import RTK
from itk import RTK as rtk
aa = rtk.CudaFDKBackProjectionImageFilter.New()
Any suggestions on how to resolve this will be highly appreciated.

Thank you

James

Sorry to hear your trouble. An easier solution is to download the Cuda compiled by GitHub actions, e.g. here for the latest one (available as artifacts when you log in to GitHub).

For fixing your build, when you do not indicate a specific value to Module_RTK_GIT_TAG, it uses the value in RTK.remote.cmake. Currently, this is 1fb003a0e052fd9fec94520c9fa39ff4339828e0 which is prior to 1f8574496e2c29ef74159ff69018a6b40daa35ec, the commit which wraps this filter. So the solution is to indicate a more recent hash as a CMake option, -DModule_RTK_GIT_TAG=“main”. You can check after the CMake configuration that RTK git HEAD is where you’d like in ../ITK/Modules/Remote/RTK.

1 Like

Thanks, Simon, for the suggestion. I added the option DModule_RTK_GIT_TAG="main", and it seems the rtkCudaFDKBackProjectionImageFilter module was successfully fetched and compiled. However, I’m now encountering other errors. Without this option, the build and installation complete successfully. Do you have any suggestions or insights on how to resolve these new errors? Here are some of them: C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkWarpSequenceImageFilter.hxx(85,5): error C2679: binary ‘=’: no operator found w

hich takes a right-hand operand of type ‘rtk::CudaForwardWarpImageFilter::Pointer’ (or there is no acceptable conversion) [

C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

(compiling source file ‘../RTK/rtkFourDROOSTERConeBeamReconstructionFilterPython.cpp’)

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkWarpSequenceImageFilter.hxx(87,5): error C2679: binary ‘=’: no operator found w

hich takes a right-hand operand of type ‘rtk::CudaWarpImageFilter::Pointer’ (or there is no acceptable conversion) [C:\ITKR

TK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

(compiling source file ‘../RTK/rtkFourDROOSTERConeBeamReconstructionFilterPython.cpp’)

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkWarpSequenceImageFilter.hxx(92,5): error C2679: binary ‘=’: no operator found w

hich takes a right-hand operand of type ‘rtk::CudaCyclicDeformationImageFilter::Pointer’ (or there is no acceptable convers

ion) [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

(compiling source file ‘../RTK/rtkFourDROOSTERConeBeamReconstructionFilterPython.cpp’)

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664: 'void rtk:

:WeidingerForwardModelImageFilter<TMaterialProjections,TPhotonCounts,TSpectrum,TProjections>::SetInputProjectionsOfOnes(con

st TProjections *)': cannot convert argument 1 from ‘itk::Image<float,3> *’ to ‘const TProjections *’ [C:\ITKRTK\ITK-Build\

Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664: wi

th [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664: [

[C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664:

TMaterialProjections=itk::CudaImage<itk::Vector<float,2>,3>, [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664:

TPhotonCounts=itk::CudaImage<itk::Vector<float,2>,3>, [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664:

TSpectrum=itk::CudaImage<float,3>, [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664:

TProjections=itk::CudaImage<float,3> [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664: ]

[C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664: an

d [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664: [

[C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664:

TProjections=itk::CudaImage<float,3> [C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

C:\ITKRTK\ITK\Modules\Remote\RTK\include\rtkMechlemOneStepSpectralReconstructionFilter.hxx(438,23): error C2664: ]

[C:\ITKRTK\ITK-Build\Wrapping\Modules\RTK\RTKPython.vcxproj]

(compiling source file ‘../RTK/rtkMechlemOneStepSpectralReconstructionFilterPython.cpp’)

I don’t know what is the issue, sorry. Can you try to provide a complete log? The errors seem incomplete. Can you also confirm which version of ITK you’re using?

1 Like

Hi Simon,

For ITK, I used version 5.4.4.

Attached are the log files:

Please let me know if you have any suggestions.

Thank you.

I’m not sure I understand but you seem to compile with a mingw terminal? The compiler seems to believe you’re under unix (hence the unistd.h inclusion errors). Check that you’re using a visual studio terminal, which can also be obtained by running cmd.exe and then

call “c:\Program Files (x86)\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat”
1 Like

Hi Simon,

I don’t have a MinGW terminal, only the standard command line for configuring and building. Still, I tried your suggestion using a Visual Studio Developer Command Prompt and ran the config and build steps. As far as I can tell, I’m seeing the same behavior and the same errors. Do you have any other suggestions?

Thanks

Not really. From the log, I see that the compiler has /D VXL_HAS_MINGW_ALIGNED_MALLOC. This is triggered from here. When executing CMake for the first time, you probably see

-- Performing Test VXL_HAS_MINGW_ALIGNED_MALLOC
-- Performing Test VXL_HAS_MINGW_ALIGNED_MALLOC - Success

Maybe try to understand why the test succeeds at CMake configuration but the compilation fails later? You can also try to manually turn VXL_HAS_MINGW_ALIGNED_MALLOC to OFF in the CMakeCache.txt

1 Like

I’ve tried multiple times, including testing on another computer in case my main environment had become corrupted over time. Unfortunately, I continue to encounter the same errors—or different ones when I make adjustments—without any success. It has been quite frustrating.

We definitely want to use your ITK/RTK framework for our reconstruction work, and I will continue to try but I really need some guidance to help get past this issue.

I understand the frustration but I cannot reproduce your problem. If I put the following code in a .bat file and execute it from the regular Windows terminal (cmd), everything works well (except the write_geometry function in the example, most likely because I did not install). Maybe you can provide your CMakeCache.txt to understand your issue? I could compare it to this compilation.

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

cmake ../src/itk/ITK-main -G "Visual Studio 17 2022" -A x64 ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX="C:/james-install" ^
-DBUILD_EXAMPLES=OFF ^
-DBUILD_TESTING=OFF ^
-DBUILD_SHARED_LIBS=OFF ^
-DITK_WRAP_PYTHON=ON ^
-DITK_BUILD_DEFAULT_MODULES=OFF ^
-DModule_ITKCommon=ON ^
-DModule_ITKIOImageBase=ON ^
-DModule_ITKIONIFTI=ON ^
-DModule_ITKIOPNG=ON ^
-DModule_ITKIOGDCM=ON ^
-DModule_RTK=ON ^
-DModule_CudaCommon=ON ^
-DModule_CudaCommon_GIT_TAG="fdca68f53d2c9b4c34c5bacfd83d99cd9e2285a0" ^
-DRTK_USE_CUDA=ON ^
-DModule_RTK_GIT_TAG="c4722ef208891032d72860f0dd036b7c38dbb606" ^
-DITK_WRAP_unsigned_short:BOOL=ON ^
-DITK_WRAP_double:BOOL=ON ^
-DITK_WRAP_complex_double:BOOL=ON ^
-DITK_WRAP_IMAGE_DIMS:STRING="2;3;4" ^
-DPython3_EXECUTABLE="C:/Python311-x64/python.exe" ^
-DPython3_INCLUDE_DIR="C:/Python311-x64/include" ^
-DPython3_LIBRARY="C:/Python311-x64/libs/python311.lib" ^
-DPY_SITE_PACKAGES_PATH="C:/Python311-x64/Lib/site-packages" ^
-DModule_ITKHDF5:BOOL=OFF ^
-DModule_ITKIOHDF5:BOOL=OFF ^
-DModule_ITKIOTransformHDF5:BOOL=OFF ^
-DModule_ITKIOTransformBase:BOOL=OFF ^
-DModule_ITKIOTransformMatlab:BOOL=OFF

devenv ITK.sln /Build "Release|x64"
copy Wrapping\Generators\Python\WrapITK.pth test\Lib\site-packages
C:\Python311-x64\python.exe -m venv test
test\Scripts\activate.bat
pip install numpy
python c:\src\itk\ITK-main\Modules\Remote\RTK\examples\FirstReconstruction\FirstCudaReconstruction.py a.mha a.xml
1 Like