How to determine the CMake VTK "COMPONENTS" necessary for a class?

I haven’t written a CMakeLists.txt file for VTK in a while, and things seem to have evolved somewhat. I’m sure that the reasons are important, and the results are great, but it did take me a while to figure out why I was getting link errors on vtkXMLPolyDataReader. My original code:

find_package(VTK COMPONENTS

The fixed code:

find_package(VTK COMPONENTS

Granted IOXML is fairly easy to figure out, but there is nothing on the documentation page that mentions that I needed this …

Hi @rexthor ,

since you are using vtkXMLPolyDataReader you need to include the vtk module that defines this class. Notice that in the VTK source tree the header is located under IO/XML which is where the IOXML name comes from.

Another way to find the module name is the vtk.module file in the same directory with the header. This is where the module is defined.

Check also this script from vtk-examples website that creates the “find_package” string for you.


Hi agree with @rexthor , the needed module dependencies should be listed in the class doc.

Should be added in the automatic documentation process imo.

1 Like

Since people in general are quick to say what they don’t like, and often don’t say what they do like: VTK has great documentation, and even lots of examples … so … kudos to all involved.


Note that some classes will require module X to compile, but to get real implementations, another module will be needed (e.g., VTK::RenderingOpenGL2 is rarely used directly rather than via VTK::RenderingCore factory classes).

1 Like

Good point, but better to have something than nothing I think.

This is why VTKModulesForCxx generates a series of commented out modules that the user may need to uncomment.

    # These modules are suggested since they implement an existing module.
    # You may need to uncomment one or more of these.
    # If vtkRenderWindow is used and you want to use OpenGL,
    #   you also need the RenderingOpenGL2 module.
    # If vtkRenderWindowInteractor is used,
    #    uncomment RenderingUI and possibly InteractionStyle.
    # If text rendering is used, uncomment RenderingFreeType
    # FiltersParallel     # implements VTK::FiltersCore
    # FiltersParallelDIY2 # implements VTK::FiltersCore
    # RenderingCellGrid   # implements VTK::RenderingCore
    # RenderingFreeType   # implements VTK::RenderingCore
    # RenderingOpenGL2    # implements VTK::RenderingCore
    # RenderingUI         # implements VTK::RenderingCore

SImilarly with VTKImportsForPython you get:

# You may need to uncomment one or more of the following imports.
# If vtkRenderWindow is used and you want to use OpenGL,
#   you also need the vtkRenderingOpenGL2 module.
# If vtkRenderWindowInteractor is used, uncomment vtkInteractionStyle
# If text rendering is used, uncomment vtkRenderingFreeType.
# If using PyCharm, preface each one you select with this line:
# noinspection PyUnresolvedReferences
# import vtkmodules.vtkInteractionStyle
# import vtkmodules.vtkRenderingContextOpenGL2
# import vtkmodules.vtkRenderingFreeType
# import vtkmodules.vtkRenderingOpenGL2
# import vtkmodules.vtkRenderingUI
# import vtkmodules.vtkRenderingVolumeOpenGL2

I’m not sure if this can be improved on.

1 Like

As infrequently as I make new C++ projects, the script solution you guys mention would work for me. I can only imagine how much of a headache it would be to go back and annotate all of the documents.

python3 "$VTK_ROOT/Utilities/Maintenance/" -j $VTK_ROOT/build/modules.json -s vtkHelloworld.cpp worked for me: VTK-9: How to know which VTK COMPONENT contains which VTK class?.

Not sure what is the recommended way to go