Changes to the VTK Examples 1

These examples highlight the latest and greatest VTK and are regularly built using the VTK master and will usually compile OK with most tests passing. Some code will not build/run with older versions of VTK, mainly due to new features and classes being added to VTK.

Only the “new” module system is now supported, most of this was implemented in vtk/vtk-examples!258. If you are using VTK versions older than 8.90 then you will have to manually change the CMake files or revert to an old version of vtk-examples.

Changes for C++

VTK third party modules are now appearing in some C++ examples. The most common will be

  • vtk::cli11
  • vtk::json
  • vtk::fmt

If you have built VTK with testing enabled, then these modules will be automatically included. Otherwise you will need to mandate their inclusion in your VTK build by specifying one or more of:

  • -DVTK_MODULE_ENABLE_VTK_cli11=WANT
  • -DVTK_MODULE_ENABLE_VTK_json=WANT (most likely already included)
  • -DVTK_MODULE_ENABLE_VTK_fmt=WANT

Where the complexity of writing specialised code e.g. file path building and checking, features from versions of C++ more recent than C++11 will be used. A good example of this is using std::filesystem from C++17. Of course the alternative is to use boost filesystem or, as a last resort, write your own.

Not all C++ examples will be affected by the inclusion of third party modules. However updates and new additions may incorporate some of these modules.

Changes for Python

There are no significant changes, just a possible rewrite of code to use similar features in C++ code of the same name. Similar includes for the above mentioned VTK third party code have existed for a long while in Python versions. For example: argparse, json and pathlib.

Some other minor changes will be:

  • python3 will replace python in hashbangs
  • using f-strings

Watch this space

I’ll be committing some examples that show these changes over the next few days. An announcement will appear in this forum when each is done so you can see the changes.

1 Like