|
scimesh 0.3.4
Headless CPU-only 3D software renderer for scientific mesh visualization
|
Smooth curve sampling through ordered 3D points (splines). More...
#include <scimesh/types.h>#include <glm/geometric.hpp>#include <algorithm>#include <cmath>#include <vector>
Go to the source code of this file.
Namespaces | |
| namespace | scimesh |
| namespace | scimesh::detail |
| Internal helpers of the text renderer. | |
Functions | |
| Vec3 | scimesh::detail::hermite_segment (const Vec3 &p0, const Vec3 &p1, const Vec3 &m0, const Vec3 &m1, double h, double s) |
| Cubic Hermite basis evaluation of a single curve segment. | |
| size_t | scimesh::detail::segment_count (size_t num_points, bool closed) |
| Number of segments a sampling function has to emit. | |
| size_t | scimesh::detail::next_index (size_t i, size_t num_points, bool closed) |
Index of the point after i, wrapping around for closed curves. | |
| int | scimesh::detail::sample_count (int samples_per_segment) |
| Clamp a requested sample count to at least one. | |
| float | scimesh::path_length (const std::vector< Vec3 > &path, bool closed=false) |
| Total length of a polyline path. | |
| std::vector< Vec3 > | scimesh::remove_duplicate_points (const std::vector< Vec3 > &path, float epsilon=1e-6f) |
| Remove points that repeat their predecessor. | |
| std::vector< Vec3 > | scimesh::path_tangents (const std::vector< Vec3 > &path, bool closed=false) |
| Unit tangent direction at every point of a path. | |
| std::vector< float > | scimesh::path_curvature (const std::vector< Vec3 > &path, bool closed=false) |
| Discrete curvature at every point of a path. | |
| std::vector< Vec3 > | scimesh::resample_by_arclength (const std::vector< Vec3 > &path, float step, bool closed=false) |
| Resample a path at a fixed arc-length step. | |
| std::vector< Vec3 > | scimesh::hermite_path (const std::vector< Vec3 > &points, const std::vector< Vec3 > &tangents, int samples_per_segment=8, bool closed=false) |
| Sample a cubic Hermite curve with caller-supplied tangents. | |
| std::vector< Vec3 > | scimesh::catmull_rom_path (const std::vector< Vec3 > &points, int samples_per_segment=8, bool closed=false, float alpha=0.5f) |
| Sample a non-uniform Catmull-Rom curve through the given points. | |
| std::vector< Vec3 > | scimesh::bspline_path (const std::vector< Vec3 > &points, int samples_per_segment=8, bool closed=false) |
| Sample a uniform cubic B-spline through the given points. | |
| std::vector< Vec3 > | scimesh::bezier_path (const std::vector< Vec3 > &control_points, int samples=64) |
| Sample a Bezier curve from a control polygon. | |
Variables | |
| constexpr size_t | scimesh::detail::kMinPathPoints = 2u |
| Minimum number of points that can describe a path. | |
| constexpr double | scimesh::detail::kMinKnotInterval = 1e-6 |
| Smallest knot interval, to keep a degenerate point pair from producing a zero-length interval (and a division by zero). | |
| constexpr double | scimesh::detail::kArcLengthEpsilon = 1e-9 |
| Tolerance used when deciding whether an arc-length sample coincides with the end of a path, relative to the total path length. | |
Smooth curve sampling through ordered 3D points (splines).
These functions turn a coarse list of waypoints into a dense, smooth polyline, here called a path. A path is what the path-taking parts of the library expect: generate_tube() sweeps a cross-section along one, and line layers (render_segments(), LineLayer) draw one straight segment per consecutive pair of points. Feeding a handful of control points directly to those produces a visibly faceted tube and a polygonal line; a spline is how you get the smooth version.
Nothing here knows about meshes, scenes or the renderer: this is pure geometry on std::vector<Vec3>, so it composes with primitives.h, lines.h and your own code alike.
float (that is what Vec3 is), but the curve parameterization is computed in double. The knot spacing of a centripetal Catmull-Rom curve involves pow(), and doing that in float would make the parameterization — not the geometry — the dominant source of error on long paths. Definition in file spline.h.