if I want to use the VTK (in this case for function parsing (vtkSmartPointer.h and vtkFunctionParser.h) without any other image interchange.
I tried to add VTK .as an external module (using ITKVTK in the itk-module.cmake file).and to use it with:
find_package(VTK)
include(${VTK_USE_FILE})
Is there an proposed wayfrom Kitware to add VTK to ITK projects?
You can put the next in your “cmakelist.txt” file:
set (CMAKE_CXX_STANDARD 11) # you need to put it since... I do not remember that version of VTK
set( VTK_DIR "path to your vtk build" )
FIND_PACKAGE (VTK REQUIRED)
IF(VTK_FOUND)
INCLUDE(${VTK_USE_FILE})
ENDIF(VTK_FOUND)
set( ITK_DIR "path to your itk build" )
find_package(ITK REQUIRED)
IF(ITK_FOUND)
include(${ITK_USE_FILE})
ENDIF(ITK_FOUND)
add_executable(XnameofyourprogramX yourfiles.cpp)
target_link_libraries(XnameofyourprogramX ${VTK_LIBRARIES} ${ITK_LIBRARIES})
And remember to put the next before “FIND_PACKAGE” if you do not have installed itk or vtk and you only built it:
set( VTK_DIR "path to your vtk build" ) set( ITK_DIR "path to your itk build" )
thank you for the fast response. I wasnt clear about what I try to achieve. I do not write a program. The code i write is for an external module. Therefore, my CMakeList.txt is based on the one from the itktmoduletemplate.
Adding the way you proposed did not fix the issue. It is more for general program based on VTK/ITK.
My current CMakeList.txt looks like this:
I think the standard way to add other projects to a ExternalModule is creating a file itk-module-init.cmake with find_package(...) as @blowekamp pointed out.
But in the case of VTK, you might have an easier time making your module dependent of ITKVtkGlue, which already handles VTK. One module doing this approach is LevelSetsv4
Not sure if it will require extra steps in your case.
As @phcerdan pointed out it seems to work easier using the ITKVtkGlue option.
Therefore the ITK and VTK needed to be rebuild if this option wasn’t selected. Now it works fine.
The itk-module.cmake file looks like this:
get_filename_component(MY_CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(READ "${MY_CURRENT_DIR}/README.rst" DOCUMENTATION)
# define the dependencies of the include module and the tests
itk_module(ORA
DEPENDS
ITKCommon
RTK
ITKImageGrid
ITKVtkGlue
COMPILE_DEPENDS
ITKImageSources
TEST_DEPENDS
ITKTestKernel
ITKMetaIO
ITKIOTransformBase
DESCRIPTION
"${DOCUMENTATION}"
EXCLUDE_FROM_DEFAULT
ENABLE_SHARED
)