Two questions about new module system

Hi all,

Having a first look at porting our application to VTK 9.0.0.

First question is about vtkRenderingContextOpenGL2. With 9.0.0 it seems we no longer get that library? What should I link against to pick the OpenGL2 backend for context views? Or has the library been removed and they are now using OpenGL2 by default?

Second question: CMake of our project finishes successfully, but VTK_INCLUDE_DIRS is now empty. I’m guessing this has to do with the VTK CMake changes/new module system? How do I get the VTK include directories added nowadays? I looked at @ben.boeckel’s post at https://vtk.org/pipermail/vtk-developers/2019-January/036648.html under the “For consumers of VTK” section but couldn’t find any info about changes in how to consume VTK include directories.

I guess I have a third question :slight_smile:

The mail also mentions

  • For object factories to work, vtk_module_autoinit should be used.
    This generates the proper -D flags for getting initialization to
    work.

Will the CMake machinery still add automatic compile flags like -DvtkRenderingContext2D_AUTOINIT="1(vtkRenderingContextOpenGL2)", or must I do something manually with vtk_module_autoinit myself?

Nevermind this question, I see I sort of already asked it back in Bill’s ML thread “vtk_module_autoinit in new module system” ([vtk-developers] vtk_module_autoinit in new module system). So I will have to make a call to that function.

I should have done some more digging. I got everything working by 1) Adding the vtk_module_autoinit calls for our targets. 2) Fixing to use VTK::Foo instead of vtkFoo in some places.

Or well, I still have uses of deprecated stuff to take care of, but at least now the compile/link lines are all good :slight_smile:

First question is about vtkRenderingContextOpenGL2 . With 9.0.0 it seems we no longer get that library? What should I link against to pick the OpenGL2 backend for context views? Or has the library been removed and they are now using OpenGL2 by default?

Hm, now that I got the program built, it crashes at runtime with:

2020-03-22 11:51:44.120 (   0,477s) [        F002EC40] vtkContextDevice2D.cxx:32    WARN| Error: no override found for 'vtkContextDevice2D'.

So I’m guessing there’s something missing after all. In VTK 8 I could link against vtkRenderingContextOpenGL2 to pick an implementation. What should I link against in VTK 9?

In VTK 8 I had:

estan@edison:~$ ls /opt/VTK8/lib/*OpenGL2*
/opt/VTK8/lib/libvtkDomainsChemistryOpenGL2-8.2.so                 /opt/VTK8/lib/libvtkRenderingContextOpenGL2-8.2.so                 /opt/VTK8/lib/libvtkRenderingOpenGL2-8.2.so
/opt/VTK8/lib/libvtkDomainsChemistryOpenGL2-8.2.so.8.2             /opt/VTK8/lib/libvtkRenderingContextOpenGL2-8.2.so.8.2             /opt/VTK8/lib/libvtkRenderingOpenGL2-8.2.so.8.2
/opt/VTK8/lib/libvtkDomainsChemistryOpenGL2-8.2.so.8.2.0           /opt/VTK8/lib/libvtkRenderingContextOpenGL2-8.2.so.8.2.0           /opt/VTK8/lib/libvtkRenderingOpenGL2-8.2.so.8.2.0
/opt/VTK8/lib/libvtkDomainsChemistryOpenGL2Python36D-8.2.so        /opt/VTK8/lib/libvtkRenderingContextOpenGL2Python36D-8.2.so        /opt/VTK8/lib/libvtkRenderingOpenGL2Python36D-8.2.so
/opt/VTK8/lib/libvtkDomainsChemistryOpenGL2Python36D-8.2.so.8.2    /opt/VTK8/lib/libvtkRenderingContextOpenGL2Python36D-8.2.so.8.2    /opt/VTK8/lib/libvtkRenderingOpenGL2Python36D-8.2.so.8.2
/opt/VTK8/lib/libvtkDomainsChemistryOpenGL2Python36D-8.2.so.8.2.0  /opt/VTK8/lib/libvtkRenderingContextOpenGL2Python36D-8.2.so.8.2.0  /opt/VTK8/lib/libvtkRenderingOpenGL2Python36D-8.2.so.8.2.0
/opt/VTK8/lib/libvtkIOExportOpenGL2-8.2.so                         /opt/VTK8/lib/libvtkRenderingGL2PSOpenGL2-8.2.so                   /opt/VTK8/lib/libvtkRenderingVolumeOpenGL2-8.2.so
/opt/VTK8/lib/libvtkIOExportOpenGL2-8.2.so.8.2                     /opt/VTK8/lib/libvtkRenderingGL2PSOpenGL2-8.2.so.8.2               /opt/VTK8/lib/libvtkRenderingVolumeOpenGL2-8.2.so.8.2
/opt/VTK8/lib/libvtkIOExportOpenGL2-8.2.so.8.2.0                   /opt/VTK8/lib/libvtkRenderingGL2PSOpenGL2-8.2.so.8.2.0             /opt/VTK8/lib/libvtkRenderingVolumeOpenGL2-8.2.so.8.2.0
/opt/VTK8/lib/libvtkIOExportOpenGL2Python36D-8.2.so                /opt/VTK8/lib/libvtkRenderingGL2PSOpenGL2Python36D-8.2.so          /opt/VTK8/lib/libvtkRenderingVolumeOpenGL2Python36D-8.2.so
/opt/VTK8/lib/libvtkIOExportOpenGL2Python36D-8.2.so.8.2            /opt/VTK8/lib/libvtkRenderingGL2PSOpenGL2Python36D-8.2.so.8.2      /opt/VTK8/lib/libvtkRenderingVolumeOpenGL2Python36D-8.2.so.8.2
/opt/VTK8/lib/libvtkIOExportOpenGL2Python36D-8.2.so.8.2.0          /opt/VTK8/lib/libvtkRenderingGL2PSOpenGL2Python36D-8.2.so.8.2.0    /opt/VTK8/lib/libvtkRenderingVolumeOpenGL2Python36D-8.2.so.8.2.0
estan@edison:~$

But in VTK 9 I only have:

estan@edison:~$ ls /opt/VTK9/lib/*OpenGL2*
/opt/VTK9/lib/libvtkRenderingGL2PSOpenGL2.so        /opt/VTK9/lib/libvtkRenderingOpenGL2.so        /opt/VTK9/lib/libvtkRenderingVolumeOpenGL2.so
/opt/VTK9/lib/libvtkRenderingGL2PSOpenGL2.so.9.0    /opt/VTK9/lib/libvtkRenderingOpenGL2.so.9.0    /opt/VTK9/lib/libvtkRenderingVolumeOpenGL2.so.9.0
/opt/VTK9/lib/libvtkRenderingGL2PSOpenGL2.so.9.0.0  /opt/VTK9/lib/libvtkRenderingOpenGL2.so.9.0.0  /opt/VTK9/lib/libvtkRenderingVolumeOpenGL2.so.9.0.0
estan@edison:~$

My CMake line for VTK 8 had:

	-DCMAKE_INSTALL_PREFIX=/opt/VTK8 \
	-DCMAKE_INSTALL_RPATH=/opt/VTK8/lib \
	-DVTK_Group_Qt=ON \
	-DVTK_QT_VERSION=5 \
	-DVTK_Group_Imaging=ON \
	-DVTK_Group_Views=ON \
	-DModule_vtkRenderingFreeTypeFontConfig=ON \
	-DVTK_WRAP_PYTHON=ON \
	-DVTK_PYTHON_VERSION=3 \
	-DPYTHON_EXECUTABLE=/usr/bin/python3 \
	-DPYTHON_INCLUDE_DIR=/usr/include/python3.6 \
	-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so \
	-DBUILD_TESTING=OFF \
	-DVTK_USE_SYSTEM_LIBRARIES=ON \
	-DVTK_USE_SYSTEM_LIBPROJ4=OFF \
	-DVTK_USE_SYSTEM_GL2PS=OFF \
	-DVTK_USE_SYSTEM_LIBHARU=OFF \
	-DVTK_USE_SYSTEM_PUGIXML=OFF \
	-DCMAKE_BUILD_TYPE=None

While my CMake line for VTK 9 had:

	-DCMAKE_INSTALL_PREFIX=/opt/VTK9 \
	-DCMAKE_INSTALL_RPATH=/opt/VTK9/lib \
	-DVTK_GROUP_ENABLE_Qt=YES \
	-DVTK_GROUP_ENABLE_Imaging=YES \
	-DVTK_GROUP_ENABLE_Views=YES \
	-DVTK_WRAP_PYTHON=ON \
	-DVTK_PYTHON_VERSION=3 \
	-DVTK_MODULE_ENABLE_VTK_RenderingFreeTypeFontConfig=YES \
	-DVTK_BUILD_TESTING=OFF \
	-DVTK_USE_EXTERNAL=YES \
	-DVTK_MODULE_USE_EXTERNAL_VTK_gl2ps=OFF \
	-DVTK_MODULE_USE_EXTERNAL_VTK_libharu=OFF \
	-DVTK_MODULE_USE_EXTERNAL_VTK_pugixml=OFF \
	-DVTK_CUSTOM_LIBRARY_SUFFIX="" \
	-DCMAKE_BUILD_TYPE=None

I see that, unlike e.g. VolumeOpenGL2, the ContextOpenGL2 module is not part of the Rendering group.

I do wonder how come we got that library built when using VTK 8 though, but not with VTK 9. Is VTK 9 in general building less stuff by default?

Must I enable the ContextOpenGL2 module explicity?

It’s still there. Is it just disabled in your build?

Yes, this is gone. Use the targets (VTK::CommonCore) instead.

It is no longer automatic because that gave you one autoinit set per find_package. Now it is done per target. You should do:

target_link_libraries(my_vtk_using_lib ${visibility}VTK::CommonCore ${other_vtk_libs})
vtk_module_autoinit(TARGETS my_vtk_using_lib MODULES VTK::CommonCore ${other_vtk_libs})

The latter call generates the required -D flags for the module set but just for the targets listed.

This is possible. I did end up fixing a lot of bogus dependencies when I went through with the build system.

Thanks a lot for all the answers. Makes perfect sense.

I must have gotten the RenderingContextOpenGL2 by “luck” in my earlier VTK 8 build due to some dependency.

Since RenderingContextOpenGL2, unlike e.g. RenderingVolumeOpenGL2, is not part of the Rendering group (should it be?), I guess I must enable that module explicitly to get it?

Edit: Running a VTK build now with:

                -DVTK_GROUP_ENABLE_Rendering=YES \
                -DVTK_GROUP_ENABLE_Imaging=YES \
                -DVTK_GROUP_ENABLE_Views=YES \
                -DVTK_GROUP_ENABLE_Qt=YES \
                -DVTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2=YES \
                -DVTK_MODULE_ENABLE_VTK_RenderingFreeTypeFontConfig=YES \

to check. Then I think I should get it for sure.

Looking back at the CMake output from my old VTK 8 build, it lists vtkRenderingContextOpenGL2 under “Backend OpenGL2 modules:”:

Backend OpenGL2 modules: vtkDomainsChemistryOpenGL2;vtkIOExportOpenGL2;vtkImagingOpenGL2;vtkRenderingContextOpenGL2;vtkRenderingGL2PSOpenGL2;vtkRenderingLICOpenGL2;vtkRenderingOpenGL2;vtkRenderingOpenVR;vtkRenderingVolumeOpenGL2

So there seems to have been a mechanism that brought in all these *OpenGL2 modules in one go according to the chosen backend. I did not specify the OpenGL2 backend in that CMake run explicitly (I.e. did not pass -DVTK_RENDERING_BACKEND), so it was picked by default.

In VTK 9, with the old OpenGL backend gone (right?), should not (for example) RenderingContext depend on RenderingContextOpenGL2, because it won’t function without it?

Looking at the old module.cmake file, it was never part of the Rendering group. It was probably dragged in by IMPLEMENTATION_REQUIRED_BY_BACKEND (your newest reply seems to confirm that) which is…hairy logic to say the least. It’s tough to say what should be done here because the logic to implement that flag would be extremely difficult to get right.

That’s gone now. Hopefully, the Vulkan backend will be a runtime selection, not a compile-time selection thing.

Alright thanks. I’ll pretend the hairy IMPLEMENTATION_REQUIRED_BY_BACKEND never existed and enable the module explicitly :slight_smile: I wonder though why RenderingVolumeOpenGL2 is part of the Rendering group while RenderingContextOpenGL2 is not.

Everything works fine now with the flags I used in Two questions about new module system :+1:

Hi,

I think I’m asking about something similar so I don’t create new topic.
With VTK 9.0 and Qt I cannot launch 2D examples from VTK web-site.
Previously with VTK 8.2 I used to add few lines in my code from mailing list:

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingContextOpenGL2);
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)

But now I get the error:
Error: no override found for 'vtkcontextdevice2d’
How to overcome this?

Best regards,
kerim

Use vtk_module_autoinit() function with VTK 9.0 to make this work without needing to call VTK_MODULE_INIT manually. See this section.

Thank you for reply Ben,

Honestly saying I don’t fully understand how to use vtk_module_autoinit()
I have the problems like described here but adding:

#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2,vtkInteractionStyle)
#define vtkRenderingContext2D_AUTOINIT 1(vtkRenderingContextOpenGL2)

Doesn’t help. Probably this is because I don’t have vtkRenderingContextOpenGL2-9.0.lib in the lib folder

I don’t use CMake, I’m working with Qt 5.14.1, QMake, Windows 10, MSVC 2017 x64

Yeah, without the vtkRenderingContextOpenGL2 library, you’ll have to drop the vtkRenderingContext2D_AUTOINIT line.

If you’re not using CMake, you’ll have to do what vtk_module_autoinit is doing for you manually. That is described in this section.

Yes I read these abstracts from the link few times but I can’t say that I understand what it is about. For now I don’t fully understand the problem and the solution as well. I don’t have enough knowledge yet to understand it.
I would very appreciate if you give something like copy-past example how to launch any of 2D VTK example, maybe this one

By the way is it ok that I don’t have vtkRenderingContextOpenGL2-9.0.lib in VTK 9.0 or I should recompile the VTK library?

It’s only a problem if you want to use a class that has an implementation in that module. Since you’re asking, the answer is probably “yes” though :slight_smile: . You’ll need to recompile VTK for that.

What you can do is make a small CMake project which links to what you’re linking to, use vtk_module_autoinit, and see what the header it ends up generating is. You can put that at the top of whatever file(s) you need it in then.

1 Like

I just reopened VTK in CMake-GUI and I found that module (in the picture).
I have a feeling that I should postpone the recompilation because there is many “interesting-labeled” modules so this is going to be not the last recompilation :slight_smile:
Thank you for advices, I hope everything is going to work well.
image