VTK | C++

Filters

VTK pipeline filters wrapping trueform algorithms.

Filters integrate trueform algorithms into VTK's pipeline architecture. Connect them like any VTK filter—they handle caching, MTime tracking, and data conversion automatically. Each filter wraps a corresponding function for use in pipelines.

Include the module with:

#include <trueform/vtk/filters.hpp>

Pipeline Pattern

Most filters require tf::vtk::polydata input for access to cached acceleration structures. Use the adapter filter to convert standard vtkPolyData:

vtkNew<vtkSTLReader> reader;
reader->SetFileName("mesh.stl");

// Convert to tf::vtk::polydata
vtkNew<tf::vtk::adapter> adapter;
adapter->SetInputConnection(reader->GetOutputPort());

// Now use trueform filters
vtkNew<tf::vtk::boolean> boolean_filter;
boolean_filter->SetInputConnection(0, adapter0->GetOutputPort());
boolean_filter->SetInputConnection(1, adapter1->GetOutputPort());

Alternatively, use the stl_reader or obj_reader filters which output tf::vtk::polydata directly.

adapter

Converts vtkPolyData to tf::vtk::polydata with cached acceleration structures. The cached polydata persists between pipeline executions—structures only rebuild when input data changes.

vtkNew<tf::vtk::adapter> adapter;
adapter->SetInputConnection(reader->GetOutputPort());
adapter->Update();

// Access cached polydata directly
auto* poly = adapter->cached_polydata();
PortDirectionType
0InputvtkPolyData
0Outputtf::vtk::polydata

Boolean & Intersection

boolean

Computes boolean operations between two meshes. Wraps make_boolean.

PortDirectionTypeDescription
0Inputtf::vtk::polydataFirst mesh
1Inputtf::vtk::polydataSecond mesh
0Outputtf::vtk::polydataResult mesh with "Labels" cell data
1Outputtf::vtk::polydataIntersection curves (if enabled)
MethodDescription
set_operation(tf::boolean_op)Set operation: merge, intersection, difference
set_return_curves(bool)Enable curves output on port 1
set_matrix0(vtkMatrix4x4*)Transform for first input
set_matrix1(vtkMatrix4x4*)Transform for second input
vtkNew<tf::vtk::boolean> filter;
filter->SetInputConnection(0, adapter0->GetOutputPort());
filter->SetInputConnection(1, adapter1->GetOutputPort());
filter->set_operation(tf::boolean_op::difference);
filter->set_return_curves(true);
filter->Update();

auto* result = filter->GetOutput(0);  // mesh with "Labels"
auto* curves = filter->GetOutput(1);  // intersection curves

intersection_curves

Computes intersection curves between two meshes without performing a boolean operation. Wraps make_intersection_curves.

PortDirectionTypeDescription
0Inputtf::vtk::polydataFirst mesh
1Inputtf::vtk::polydataSecond mesh
0Outputtf::vtk::polydataIntersection curves
MethodDescription
set_matrix0(vtkMatrix4x4*)Transform for first input
set_matrix1(vtkMatrix4x4*)Transform for second input
vtkNew<tf::vtk::intersection_curves> filter;
filter->SetInputConnection(0, adapter0->GetOutputPort());
filter->SetInputConnection(1, adapter1->GetOutputPort());
filter->set_matrix0(actor0->GetUserMatrix());
filter->set_matrix1(actor1->GetUserMatrix());
filter->Update();

auto* curves = filter->GetOutput();

self_intersection_resolver

Finds where a mesh intersects itself and embeds the intersection curves as edges. Wraps resolved_self_intersections.

PortDirectionTypeDescription
0Inputtf::vtk::polydataInput mesh
0Outputtf::vtk::polydataResolved mesh
1Outputtf::vtk::polydataSelf-intersection curves (if enabled)
MethodDescription
set_return_curves(bool)Enable curves output on port 1
vtkNew<tf::vtk::self_intersection_resolver> filter;
filter->SetInputConnection(adapter->GetOutputPort());
filter->set_return_curves(true);
filter->Update();

auto* resolved = filter->GetOutput(0);
auto* curves = filter->GetOutput(1);

Scalar Field Operations

isocontours

Extracts isocontour curves from scalar fields on mesh vertices. Wraps make_isocontours.

PortDirectionTypeDescription
0InputvtkPolyDataMesh with point scalars
0OutputvtkPolyDataIsocontour curves
MethodDescription
set_scalars_name(string)Name of point scalars array (empty for active scalars)
set_cut_values(vector<float>)Scalar values at which to extract contours
add_cut_value(float)Add a single cut value
clear_cut_values()Remove all cut values
vtkNew<tf::vtk::isocontours> filter;
filter->SetInputConnection(reader->GetOutputPort());
filter->set_scalars_name("temperature");
filter->set_cut_values({20.0f, 25.0f, 30.0f});
filter->Update();

auto* contours = filter->GetOutput();

isobands

Extracts isoband regions between scalar values. Wraps make_isobands.

PortDirectionTypeDescription
0InputvtkPolyDataMesh with point scalars
0OutputvtkPolyDataIsoband polygons with "BandLabel" cell data
1OutputvtkPolyDataBoundary curves (if enabled)
MethodDescription
set_scalars_name(string)Name of point scalars array
set_cut_values(vector<float>)Scalar values defining band boundaries
set_selected_bands(vector<int>)Which bands to extract (band i is between cut i and i+1)
set_return_curves(bool)Enable boundary curves output on port 1
vtkNew<tf::vtk::isobands> filter;
filter->SetInputConnection(reader->GetOutputPort());
filter->set_scalars_name("elevation");
filter->set_cut_values({0.0f, 0.5f, 1.0f, 1.5f});
filter->set_selected_bands({1, 2});  // bands between 0.5-1.0 and 1.0-1.5
filter->set_return_curves(true);
filter->Update();

auto* bands = filter->GetOutput(0);   // polygons with "BandLabel"
auto* curves = filter->GetOutput(1);  // boundary curves

Topology Analysis

connected_components

Labels connected components in a mesh. Wraps make_connected_components.

PortDirectionTypeDescription
0Inputtf::vtk::polydataInput mesh
0Outputtf::vtk::polydataMesh with "ComponentLabel" cell data
MethodDescription
set_connectivity(tf::connectivity_type)How faces connect (see below)
n_components()Number of components found (after Update)

Connectivity types:

  • tf::connectivity_type::manifold_edge — only through manifold edges (separates at boundaries/non-manifold)
  • tf::connectivity_type::edge — through any shared edge
  • tf::connectivity_type::vertex — through any shared vertex (most permissive)
vtkNew<tf::vtk::connected_components> filter;
filter->SetInputConnection(adapter->GetOutputPort());
filter->set_connectivity(tf::connectivity_type::edge);
filter->Update();

int n = filter->n_components();
auto* labeled = filter->GetOutput();  // has "ComponentLabel" cell data

boundary_paths

Extracts boundary edges connected into continuous paths. Wraps make_boundary_paths.

PortDirectionTypeDescription
0InputvtkPolyDataInput mesh
0OutputvtkPolyDataBoundary curves (shares points with input)
vtkNew<tf::vtk::boundary_paths> filter;
filter->SetInputConnection(reader->GetOutputPort());
filter->Update();

auto* boundaries = filter->GetOutput();

non_simple_edges

Extracts boundary and/or non-manifold edges. Wraps make_non_simple_edges, make_boundary_edges, and make_non_manifold_edges.

PortDirectionTypeDescription
0Inputtf::vtk::polydataInput mesh
0OutputvtkPolyDataEdges with "EdgeType" cell data (if both types enabled)
MethodDescription
set_boundary_edges(bool)Include boundary edges (default: true)
set_non_manifold_edges(bool)Include non-manifold edges (default: true)

Edge types in "EdgeType" cell data:

  • 0 — boundary edge (used by one face)
  • 1 — non-manifold edge (used by three or more faces)
vtkNew<tf::vtk::non_simple_edges> filter;
filter->SetInputConnection(adapter->GetOutputPort());
filter->set_boundary_edges(true);
filter->set_non_manifold_edges(true);
filter->Update();

auto* edges = filter->GetOutput();  // has "EdgeType" if both enabled

Normals

normals_generator

Computes normals and optionally orients faces consistently. Wraps orient_faces_consistently, compute_cell_normals, and compute_point_normals.

PortDirectionTypeDescription
0InputvtkPolyDataInput mesh
0OutputvtkPolyDataMesh with "Normals" cell/point data
MethodDefaultDescription
set_orient_faces(bool)trueOrient faces for consistent winding
set_compute_point_normals(bool)trueCompute vertex normals (cell normals always computed)

Operations are performed in order:

  1. Orient faces consistently (if enabled)
  2. Compute cell normals (always)
  3. Compute point normals (if enabled)
vtkNew<tf::vtk::normals_generator> filter;
filter->SetInputConnection(reader->GetOutputPort());
filter->set_orient_faces(true);
filter->set_compute_point_normals(true);
filter->Update();

auto* mesh = filter->GetOutput();
// mesh->GetCellData()->GetNormals()
// mesh->GetPointData()->GetNormals()

Cleaning

polygon_cleaner

Removes duplicate points and degenerate faces. Wraps cleaned_polygons.

PortDirectionTypeDescription
0InputvtkPolyDataInput mesh
0OutputvtkPolyDataCleaned mesh
MethodDefaultDescription
set_tolerance(float)0Distance for merging points (0 = exact duplicates)
set_preserve_data(bool)trueRemap point/cell data arrays
vtkNew<tf::vtk::polygon_cleaner> filter;
filter->SetInputConnection(reader->GetOutputPort());
filter->set_tolerance(1e-6f);
filter->set_preserve_data(true);
filter->Update();

auto* clean = filter->GetOutput();

line_cleaner

Cleans line data: merges duplicate points, removes degenerate edges, and reconnects edges into continuous paths. Wraps cleaned_lines.

PortDirectionTypeDescription
0InputvtkPolyDataInput lines
0OutputvtkPolyDataCleaned paths
MethodDefaultDescription
set_tolerance(float)0Distance for merging points
set_preserve_data(bool)trueRemap point data arrays
Cell data cannot be preserved because edges are reconnected into paths.
vtkNew<tf::vtk::line_cleaner> filter;
filter->SetInputConnection(curves_source->GetOutputPort());
filter->set_tolerance(1e-6f);
filter->Update();

auto* clean = filter->GetOutput();

File I/O

These readers output tf::vtk::polydata directly, with cached acceleration structures ready for use. They wrap the corresponding I/O functions.

stl_reader

Reads an STL file. Wraps read_stl.

PortDirectionTypeDescription
0Outputtf::vtk::polydataLoaded mesh with cached structures
MethodDescription
set_file_name(string)Path to STL file
Normals are not read from the file.
vtkNew<tf::vtk::stl_reader> reader;
reader->set_file_name("model.stl");
reader->Update();

// Output is tf::vtk::polydata - no adapter needed
vtkNew<tf::vtk::boolean> boolean_filter;
boolean_filter->SetInputConnection(0, reader0->GetOutputPort());
boolean_filter->SetInputConnection(1, reader1->GetOutputPort());

obj_reader

Reads an OBJ file. Wraps read_obj.

PortDirectionTypeDescription
0Outputtf::vtk::polydataLoaded mesh with cached structures
MethodDescription
set_file_name(string)Path to OBJ file
Only vertices and faces are read. Normals and texture coordinates are not read.
vtkNew<tf::vtk::obj_reader> reader;
reader->set_file_name("model.obj");
reader->Update();

auto* mesh = reader->GetOutput();