Class vtkMapper and its derived classes convert the input data into geometric primiples (such as points, lines, planes, etc.) for rendering. This class stores the data that needs to be rendered, and some rendering information.

We often see vtkImageActor (derived from vtkActor) in VTK programs using the vtkActor::SetMapper() function. This function sets up the Mapper that generates the geometry primitives, that is, connecting vtkActor, the rendering engine responsible for image display and rendering, to the Mapper that generates the geometry primitives for rendering.

Here’s another example:

We first load a 3D data and then extract the isosurfaces using the MarchingCubes algorithm.

`vtkSmartPointer<vtkStructuredPointsReader> reader = vtkSmartPointer<vtkStructuredPointsReader>::New(); reader->SetFileName("image.mhd"); vtkSmartPointer<vtkMarchingCubes> marchingCubes = vtkSmartPointer<vtkMarchingCubes>::New(); marchingCubes->SetInputConnection(reader->GetOutputPort()); MarchingCubes - > SetValue (0500); `Copy the code

Then we use the Mapper class:

`vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(marchingCubes->GetOutputPort()); `Copy the code

Here, we extract the data in Mapper class into polygon data, generate polygon Mapper.

The data is then sent to the rendering engine

`vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); `Copy the code

This is the main role and flow of Mapper. The rest is all about rendering engine setup.

Mapper is often said to be the endpoint of a visual pipeline. Let’s start with the visualization pipeline, which is not quite the same as the visualization pipeline in foreign rendering fields. It just involves obtaining (and creating) the data to be displayed, performing preliminary processing on the data, and then passing the data to the rendering engine. The rendering engine is not part of the visual pipeline.