VTK Examples - FroggieSurface and FroggieView

Introduction

The VTK Frog example has been popular since the earliest days of the software. I am happy to announce that we have rejuvenated the code and made it easier to use. The original code – Frog.py, FrogDemo.py and FrogReconstruction.py – has been rewritten and reorganized, using modern coding practices.

In particular, Frog.py and FrogDemo.py have been combined and renamed as FroggieView.py, whilst FrogReconstruction.py has been renamed to FroggieSurface.py.

Other changes include:

  • FroggieSurface uses a JSON file called vtk-examples/src/Testing/Data/Frog_mhd.json which stores the paths to the .mhd files and the parameters for each individual tissue, tissue colors etc.

  • FroggieView uses a JSON parameter file vtk-examples/src/Testing/Data/Frog_vtk.json to store essential parameters such as paths to the .vtk files, tissue names, colors etc. In addition, slsiders are provided to control the opacity of each tissue.

  • New C++ versions: FroggieSurface.cxx and FroggieView.cxx using the same JSON files and options as the Python versions.

The key advantage of using the JSON files is that it has simplified the specification of data structures and parameters. This has also allowed us, along with using CLI11, to implement the C++ versions more easily.

Note that while it is possible to just have a single JSON file, it is simpler to have one specifically for the MHD files (3.8Kib) and one for the VTK files (610B).

Frog MHD Format and Frog VTK Format document the format of these JSON files.

Features

C++

With respect to FrogSurface.cxx we use std::variant (C++17) to hold the various parameters for each tissue. This has necessitated the addition of a data structure holding the parameter types called parameter types in Frog_mhd.json. You can see the usage of this in the function ParseJSON() where there is a lambda called populate that does all the work.

Then, when we need a specific parameter, we get it from the variant as follows (see the function CreateTissueActor()):


auto pixelSize = *std::get_if<int>(&tissue["pixel_size"]);

So we can handle parameters of many types in a safe way.

Command line parameters are handled through the VTK version of CLI11. This gives an interface that is much the same as that when using argparse in Python. One interesting exercise was to replicate mutually exclusive flags. This was done by adding an option group and an array of booleans.

C++ and Python

The tissues need to be oriented correctly. A class SliceOrder is defined that stores a series of vtkTransforms accessible by a key such as is or hfis, the function Get(...) returns the transform. You can also display the homogeneous matrix of the transform, see PrintAlltransforms()or PrintTransform()

VTK Textbook Ch12 Figures

Here are the figures approximating those in the VTK Book Ch12 and the PDF, (the vtkCameraOrientationWidget has been turned off).

Figure 12-9a:

Figure 12-9b:

Figure 12-9c:

Figure 12-9d:

Original Code and Data

The original TCL Code and Frog data can be found here vtk-examples/src/OriginalSources/.

4 Likes

Related Kitware blog post:

https://www.kitware.com/froggie-and-the-joy-of-open-source-community/

1 Like