Examples | C++

VTK Integration

Using trueform with VTK applications.

The tf::vtk library provides a compiled interface for trueform integration with VTK.

Source: examples/vtk/

Overview

Wrap any vtkPolyData to access trueform's API with zero-copy data access:

#include <trueform/vtk.hpp>

// Wrap existing VTK data
auto mesh = vtkSmartPointer<tf::vtk::polydata>::New();
mesh->ShallowCopy(reader->GetOutput());

// Iterate as trueform primitives
for (auto polygon : mesh->polygons()) {
    for (auto pt : polygon) { /* ... */ }
}

// Cached acceleration structures
auto& tree = mesh->poly_tree();  // builds lazily, tracks MTime

Boolean operations, spatial queries, collision detection:

// Boolean union
auto [result, curves] = tf::vtk::make_boolean(
    mesh0, mesh1, tf::boolean_op::merge, tf::return_curves);

// Collision detection
if (tf::vtk::intersects(mesh0, mesh1)) { /* ... */ }

// Ray casting
if (auto hit = tf::vtk::ray_hit(ray, mesh)) {
    // hit.element, hit.info.t, hit.info.point
}

VTK pipeline filters wrap trueform algorithms:

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

vtkNew<tf::vtk::boolean> boolean_filter;
boolean_filter->SetInputConnection(0, adapter0->GetOutputPort());
boolean_filter->SetInputConnection(1, adapter1->GetOutputPort());
boolean_filter->set_operation(tf::boolean_op::merge);
See VTK for full documentation: core utilities, functions reference, filters, and interactive examples.