Expand description
Polyline → Catmull-Rom fitting.
Reduces a dense streamline to a sparse set of control points whose Catmull-Rom interpolation reproduces the input within a user-specified Hausdorff tolerance. Useful for editor tools (which want few sculptable control points) and for compressing dense atlas tractograms.
The algorithm:
- Start with the two endpoints as kept control points.
- For each segment between consecutive kept points, tessellate the Catmull-Rom curve, then walk the interior input vertices in that segment and find the one whose perpendicular distance to the tessellated polyline is largest.
- If any segment’s worst vertex is farther than
epsilon_mm, add the worst vertex from each violating segment as a new kept point and iterate. Adding many points per iteration converges in O(log n) passes for smooth curves while staying stable on degenerate inputs. - Stop when no segment’s worst error exceeds the tolerance.
Distances are computed as squared distances throughout (no sqrt in the
hot loop) and the per-segment tessellation buffer is reused across
iterations so the working set stays compact.
§Endpoint convention
Both endpoints of every input streamline are always retained, matching
how trxviz-draw and most editor UIs treat streamline terminations
(cortical/sub-cortical anchors are anatomically meaningful).
§Coordinate units
epsilon_mm matches the units of points, which in TRX is RAS+ mm.
Structs§
- Fitted
Marker - Schema for the
FITTED_MARKER_KEYpayload. Stable across releases of this crate; consumers should treat unknown fields as ignorable. - Simplify
Options - Simplify
Stats
Constants§
- FITTED_
MARKER_ KEY - JSON key written under
Tractogram::extra_mutto mark a tractogram as already Catmull-Rom-fitted. - MIN_
KEPT_ POINTS - Endpoints are always kept, so the minimum output size is 2 — even when the input has fewer points the function returns the input unchanged.
Functions§
- fit_
catmull_ rom_ indices - Fit a Catmull-Rom curve through a sparse subset of
pointssuch that the curve stays withinepsilon_mmof every input vertex. Returns the retained input indices in ascending order. - sample_
catmull_ rom - Sample a Catmull-Rom curve through
cpswithsamples_per_segmentevenly-spaced parameter steps per segment. The first CP appears once at the start; each subsequent segment contributessamples_per_segmentpoints (so the final CP appears once at the end). Returns owned points. - sample_
catmull_ rom_ into - Sample a Catmull-Rom curve into a caller-provided buffer. The buffer is cleared first; capacity is reused. Useful in tight loops to avoid per-call allocations.
- simplify_
streamline - Convenience: return the simplified streamline as owned positions.
- simplify_
tractogram - Build a new
Tractogramfrominputwith each streamline simplified to a Catmull-Rom-fittable control polygon. Preserves the source header (so spatial metadata round-trips) and writes theFITTED_MARKER_KEYmarker.