[SOLVED] VTK as external module

Hello,

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?

Thanks in advance,
Gordian

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" )

I hope that my answer would be helpful for you.

Hi @rolof,

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:

cmake_minimum_required(VERSION 3.10.2)
project(ORA)

set(ORA_LIBRARIES ORA)

if(NOT ITK_SOURCE_DIR)
  find_package(ITK REQUIRED)
  list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
  include(ITKModuleExternal)
else()
  itk_module_impl()
endif()

find_package(VTK)
if(VTK_FOUND)
  include(${VTK_USE_FILE})
endif(VTK_FOUND)

and the itk-moule.cmake 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
  COMPILE_DEPENDS
    ITKImageSources
  TEST_DEPENDS
    ITKTestKernel
    ITKMetaIO
	ITKIOTransformBase
  DESCRIPTION
    "${DOCUMENTATION}"
  EXCLUDE_FROM_DEFAULT
  ENABLE_SHARED
)

What could be the next step?

Would one of the Bridge module be the module kind you are looking for?

https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Video/BridgeOpenCV

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.

2 Likes

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
)

Important note: Its ITKVtkGlue. Not ITKVTKGlue! :slight_smile:

The CMakeList.txt is used unchanged from ITKModuleTemplate.

1 Like