# \[SOLVED\] VTK as external module

**URL:** <https://discourse.itk.org/t/solved-vtk-as-external-module/1037>\
**Category:** Engineering\
**Created:** [June 26, 2018, 9:38pm UTC](https://discourse.itk.org/t/solved-vtk-as-external-module/1037 "2018-06-26T21:38:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)\
**Post date:** [June 26, 2018, 9:38pm UTC](https://discourse.itk.org/t/solved-vtk-as-external-module/1037/1 "2018-06-26T21:38:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rolof](https://discourse.itk.org/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@rolof](https://discourse.itk.org/u/rolof)\
**Post date:** [June 26, 2018, 9:55pm UTC](https://discourse.itk.org/t/solved-vtk-as-external-module/1037/2 "2018-06-26T21:55:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)\
**Post date:** [June 26, 2018, 10:10pm UTC](https://discourse.itk.org/t/solved-vtk-as-external-module/1037/3 "2018-06-26T22:10:47Z")

</div>

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](https://github.com/InsightSoftwareConsortium/ITKModuleTemplate).

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?

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [June 26, 2018, 10:33pm UTC](https://discourse.itk.org/t/solved-vtk-as-external-module/1037/4 "2018-06-26T22:33:26Z")

</div>

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

[https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Video/BridgeOpenCV](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Video/BridgeOpenCV)

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [June 26, 2018, 11:13pm UTC](https://discourse.itk.org/t/solved-vtk-as-external-module/1037/5 "2018-06-26T23:13:52Z")

</div>

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](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Segmentation/LevelSetsv4/itk-module.cmake)

Not sure if it will require extra steps in your case.

---

<div class="post-metadata">

**Author:** ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)\
**Post date:** [June 27, 2018, 8:45am UTC](https://discourse.itk.org/t/solved-vtk-as-external-module/1037/6 "2018-06-27T08:45:13Z")

</div>

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! 🙂

The CMakeList.txt is used unchanged from [ITKModuleTemplate](https://github.com/InsightSoftwareConsortium/ITKModuleTemplate).
