diff --git a/wrapping/itkCudaImageRTK.wrap b/wrapping/itkCudaImageRTK.wrap index 66573ed53..44b0d48d8 100644 --- a/wrapping/itkCudaImageRTK.wrap +++ b/wrapping/itkCudaImageRTK.wrap @@ -1,14 +1,31 @@ if(RTK_USE_CUDA) + if(CudaCommon_SOURCE_DIR) + configure_file("${CudaCommon_SOURCE_DIR}/wrapping/CudaImage.i.init" "${CMAKE_CURRENT_BINARY_DIR}/CudaImageRTK.i" @ONLY) + endif() + + function(wrap_CudaImage_swig_ext type px_type) + if(CudaCommon_SOURCE_DIR) + set(CudaImageTypes ${type}) + set(PixelType ${px_type}) + configure_file(${CudaCommon_SOURCE_DIR}/wrapping/CudaImage.i.in ${CMAKE_CURRENT_BINARY_DIR}/CudaImageRTK.i.temp @ONLY) + file(READ ${CMAKE_CURRENT_BINARY_DIR}/CudaImageRTK.i.temp CudaImageInterfaceTemp) + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/CudaImageRTK.i ${CudaImageInterfaceTemp}) + endif() + endfunction() + itk_wrap_class("itk::CudaImage" POINTER_WITH_CONST_POINTER) # Add all missing image with dim == 4 list(FIND ITK_WRAP_IMAGE_DIMS "4" _index) if (${_index} EQUAL -1) itk_wrap_template("F4" "${ITKT_F}, 4") - foreach(c 2 3 4) - itk_wrap_template("${ITKM_VF${c}}4" "${ITKT_VF${c}}, 4") - itk_wrap_template("${ITKM_CVF${c}}4" "${ITKT_CVF${c}}, 4") + wrap_CudaImage_swig_ext(F4 F) + foreach(vector_type VF CVF) + foreach(c 2 3 4) + itk_wrap_template("${ITKM_${vector_type}${c}}4" "${ITKT_${vector_type}${c}}, 4") + wrap_CudaImage_swig_ext(${ITKM_${vector_type}${c}}4 F) + endforeach() endforeach() endif() @@ -17,11 +34,33 @@ if(RTK_USE_CUDA) if(${_index} EQUAL -1) UNIQUE(imageDimensions "${ITK_WRAP_IMAGE_DIMS};2;3;4") foreach(d ${imageDimensions}) - itk_wrap_template("${ITKM_VF5}${d}" "${ITKT_VF5}, ${d}") - itk_wrap_template("${ITKM_CVF5}${d}" "${ITKT_CVF5}, ${d}") + foreach(vector_type VF CVF) + itk_wrap_template("${ITKM_${vector_type}5}${d}" "${ITKT_${vector_type}5}, ${d}") + wrap_CudaImage_swig_ext(${ITKM_${vector_type}5}${d} F) + endforeach() endforeach() endif() itk_end_wrap_class() + if(CudaCommon_SOURCE_DIR) + # Add library files to be included at a submodule level and copy them into + # ITK's wrapping typedef directory. + # Another approach is to add CudaImage.i to the WRAPPER_SWIG_LIBRARY_FILES list + # but then the %pythoncode from CudaImage.i.init gets only included in + # itkCudaDataManagerPython.py even if the WRAPPER_SUBMODULE_ORDER is set. + # Prefer using ITK_WRAP_PYTHON_SWIG_EXT to make sure the block is included in + # the right file exclusively. + set(ITK_WRAP_PYTHON_SWIG_EXT + "%include CudaImageRTK.i\n${ITK_WRAP_PYTHON_SWIG_EXT}") + + file(COPY "${CMAKE_CURRENT_BINARY_DIR}/CudaImageRTK.i" + DESTINATION "${WRAPPER_MASTER_INDEX_OUTPUT_DIR}") + + # Make sure to rebuild the python file when CudaImage.i is modified. + # Touching CudaImage.i directly does not force a rebuild because it is just + # appended to the ITK_WRAP_PYTHON_SWIG_EXT variable + file(TOUCH ${WRAPPER_MASTER_INDEX_OUTPUT_DIR}/itkCudaImageRTK.i) + endif() + endif()