# VTK Examples - Removing Unneeded Includes and Upgrading VTKClassesUsedInExamples

**URL:** https://discourse.vtk.org/t/vtk-examples-removing-unneeded-includes-and-upgrading-vtkclassesusedinexamples/12171
**Category:** Announcements
**Created:** [August 21, 2023, 12:03am UTC](https://discourse.vtk.org/t/vtk-examples-removing-unneeded-includes-and-upgrading-vtkclassesusedinexamples/12171 "2023-08-21T00:03:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [August 21, 2023, 12:03am UTC](https://discourse.vtk.org/t/vtk-examples-removing-unneeded-includes-and-upgrading-vtkclassesusedinexamples/12171/1 "2023-08-21T00:03:56Z")

</div>

This was undertaken to make the **Online Examples** of the VTK Documentation more accurate. _As a side note: a maximum of 10 online examples are shown, and, if there are more than 10 examples, then a randomised set is produced which will change the next time the documentation is built._ You can also run [SelectExamples](https://examples.vtk.org/site/Python/Utilities/SelectExamples/) to get a customised list of a VTK class and links to relevant examples for a selected language.

In many of the C++ examples, there are includes for VTK classes that are unused (mostly copy/paste issues) and others that are needed but not directly implemented. The latter are required because they refer to pointers of incomplete class types.

An example of a referral to an incomplete pointer class, you often see `#include <vtkProperty.h>` and statements like `actor->GetProperty()->...` but no statement like `vtkNew<vtkProperty> = ...` in the implementation. See [vtkProperty](https://vtk.org/doc/nightly/html/classvtkProperty.html#details) - most of the Online Examples shown here exhibit this behaviour.

A script was written to scan the VTK C++ examples for includes with no subsequent implementation of the class. As a result, 784 examples were detected with possible unneeded includes (a total of 1918 includes). I reviewed each example one by one (_build and run_) and ended up with 516 examples with a total of 819 VTK classes that are needed but not implemented. A few of the examples were rewritten for various reasons. The outcome of this is that only necessary includes are now present in these C++ examples. Some examples that were unable to use OpenGL2 were moved to the **Deprecated** folder.

**VTKClassesUsedInExamples.py**

The main changes in this script are:

- The regular expressions were simplified and moved into a dataclass
- When parsing, comments within the example code are now ignored
- While Python has only inline comments (# …) I also added code to ignore docstrings (a bit tricky)
- C++ interface and implementation files are separately processed and then merged into the implementation file (_.cxx) and removing the interface file (_.h) of the same name
- Better documentation in the code
- More status information printed

These changes have improved the accuracy of linking VTK classes, languages and examples together.
