The Clean module provides high-performance tools for removing duplicate, degenerate, and unreferenced elements from geometric data. It operates directly on trueform's primitive ranges and automatically maintains referential integrity across complex data structures while providing optional index maps for downstream processing.
Include the module with:
#include <trueform/clean.hpp>
Cleaning in trueform addresses several common geometric data quality issues:
The module provides both immediate cleaning operations and optional index map returns for tracking transformations.
Remove duplicate points from point collections:
// Basic point cleaning - removes exact duplicates
auto cleaned_points = tf::cleaned<int>(points);
// Tolerance-based cleaning - merges points within distance
float tolerance = 1e-6f;
auto tolerance_cleaned_points = tf::cleaned<int>(points, tolerance);
// Get index map for downstream processing
auto [clean_points, point_map] =
tf::cleaned<int>(points, tolerance, tf::return_index_map);
// Reindex associated data using the map
auto clean_normals = tf::reindexed(point_normals, point_map);
auto clean_attributes = tf::reindexed(tf::make_range(point_attributes), point_map);
Clean segment collections by removing duplicates, degenerates, and unreferenced points:
// Clean segments - removes duplicate edges and unused points
auto clean_segments = tf::cleaned<int>(segments);
// Tolerance-based segment cleaning
float tolerance = 1e-5f;
auto tolerance_clean_segments = tf::cleaned<int>(segments, tolerance);
// Get both edge and point index maps
auto [clean_segments_with_maps, edge_map, point_map] =
tf::cleaned<int>(segments, tolerance, tf::return_index_map);
// Reindex edge and point attributes
auto clean_edge_properties = tf::reindexed(tf::make_edges(edge_properties), edge_map);
auto clean_point_properties = tf::reindexed(tf::make_edges(point_properties), point_map);
Clean curve collections (connected paths) by merging points, removing degenerate edges, and reconnecting into continuous paths:
// Clean curves - merges points, removes degenerates, reconnects paths
auto clean_curves = tf::cleaned<int>(curves);
// Tolerance-based curve cleaning
float tolerance = 1e-5f;
auto tolerance_clean_curves = tf::cleaned<int>(curves, tolerance);
// Get point index map (edge map not available since paths are reconnected)
auto [clean_curves_with_map, point_map] =
tf::cleaned<int>(curves, tolerance, tf::return_index_map);
// Reindex point attributes
auto clean_point_properties = tf::reindexed(point_properties, point_map);
Clean mesh data by removing duplicates, degenerate faces, and unreferenced vertices:
// Clean polygons - removes duplicate faces and unused vertices
auto clean_polygons = tf::cleaned<int>(polygons);
// Tolerance-based polygon cleaning
double tolerance = 1e-8;
auto tolerance_clean_polygons = tf::cleaned<int>(polygons, tolerance);
// Get both face and point index maps
auto [clean_polygons_with_maps, face_map, point_map] =
tf::cleaned<int>(polygons, tolerance, tf::return_index_map);
// Reindex all associated mesh data
auto clean_face_normals = tf::reindexed(face_normals, face_map);
auto clean_vertex_attributes = tf::reindexed(tf::make_edges(vertex_attributes), point_map);