VTK Examples - Text & Scalar Bar Widgets

Text & ScalarBar Widgets

Until now there have been only two examples in C++ namely TextWidget.cxx and ScalarBarWidget.cxx. These examples are very simple. In the PythonicAPI examples, about 20 examples already use these widgets.

The main reason for using these widgets is their versatility. Since these are widgets, the user can interact with the widget, rescaling and repositioning it. Useful if they obstruct the object being viewed.

To rectify this, the Curvature examples have been enhanced along with RescaleReverseLUT in both the C++ and PythonicAPI examples. It is hoped that these examples will provide people with code to easily implement the use these these widgets in their own code.

In order to facilitate this, some ancillary structs/classes and functions have been provided:

  • GetTextPositions(...) and get_text_positions(...): these take lists or vectors of text and return coordinates that are used to position the relevant vtkTextWidget using the text. It is pretty basic, just using the characters of the text to position it. See RescaleReverseLUT.cxx, RescaleReverseLUT.py where text is positioned in four viewports. Note the use of a Courier font to ensure that centered text of the same text height is centered in all four viewports.

  • A struct: ScalarBarProperties and class: scalar_bar_properties, these aggregate all the necessary scalar bar properties into one place. This makes it simple to create a function MakeScalarBarWidget(...) and make_scalar_barWidget(...) returning the vtkScalarBarWidget. See: CurvaturesAdjustEdges.cxx, CurvaturesAdjustEdges.py.

Edit and change these as you need.

Other changes in the curvature examples are:

  • The use of cli11, making the specification, parsing and checking of command line parameters in C++ very easy. Also see how SetWindowName() uses this and the std::filesystem to name the window. See Curvatures.cxx where this is used to name the window along with appending the file name used - if applicable.

  • The use of fmt replacing stream formatting.

Remember to add


cli11

fmt

to your CMakeLists.txt file.

Note:

  1. In most cases the curvature calculations have been moved into functions returning a struct or class.

  2. In the PythonicAPI, NormalsCurvaturesElevations is now called CurvaturesNormalsElevations.py.