MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GeometryPrimitives.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Kinesis {
6
7/**
8 * @brief Generate vertices along a circular path
9 * @param center Circle center in 3D space
10 * @param radius Circle radius
11 * @param segments Number of subdivisions (must be >= 3)
12 * @param normal Circle plane normal (default: XY plane, Z-up)
13 * @return Vertices generated by angle θ ∈ [0, 2π)
14 *
15 * Generates N+1 vertices where last vertex equals first (closed curve).
16 * For LINE_STRIP topology. For POINT_LIST, use N vertices.
17 */
18std::vector<glm::vec3> generate_circle(
19 const glm::vec3& center,
20 float radius,
21 size_t segments,
22 const glm::vec3& normal = glm::vec3(0, 0, 1));
23
24/**
25 * @brief Generate vertices along an elliptical path
26 * @param center Ellipse center
27 * @param semi_major Semi-major axis length
28 * @param semi_minor Semi-minor axis length
29 * @param segments Number of subdivisions
30 * @param normal Ellipse plane normal
31 * @return Vertices generated by eccentric anomaly
32 */
33std::vector<glm::vec3> generate_ellipse(
34 const glm::vec3& center,
35 float semi_major,
36 float semi_minor,
37 size_t segments,
38 const glm::vec3& normal = glm::vec3(0, 0, 1));
39
40/**
41 * @brief Generate vertices of an axis-aligned rectangular path
42 * @param center Rectangle centroid
43 * @param width Extent along local X axis
44 * @param height Extent along local Y axis
45 * @param normal Rectangle plane normal
46 * @return 5 vertices (closed rectangular path for LINE_STRIP)
47 */
48std::vector<glm::vec3> generate_rectangle(
49 const glm::vec3& center,
50 float width,
51 float height,
52 const glm::vec3& normal = glm::vec3(0, 0, 1));
53
54/**
55 * @brief Generate vertices of a regular n-gon
56 * @param center Polygon centroid
57 * @param radius Circumradius (center to vertex distance)
58 * @param sides Number of sides (must be >= 3)
59 * @param normal Polygon plane normal
60 * @param phase_offset Angular offset in radians (default: 0)
61 * @return N+1 vertices (closed path)
62 *
63 * Vertices positioned at angles: θ_k = (2πk/N) + phase_offset
64 */
65std::vector<glm::vec3> generate_regular_polygon(
66 const glm::vec3& center,
67 float radius,
68 size_t sides,
69 const glm::vec3& normal = glm::vec3(0, 0, 1),
70 float phase_offset = 0.0F);
71
72/**
73 * @brief Apply rigid transformation to vertex set
74 * @param vertices Vertices to transform (modified in-place)
75 * @param transform Affine transformation matrix (4x4)
76 */
78 std::vector<glm::vec3>& vertices,
79 const glm::mat4& transform);
80
81/**
82 * @brief Apply rotation to vertex set around arbitrary axis
83 * @param vertices Vertices to transform (modified in-place)
84 * @param axis Rotation axis (will be normalized)
85 * @param angle Rotation angle in radians (right-hand rule)
86 * @param origin Rotation center (default: world origin)
87 */
89 std::vector<glm::vec3>& vertices,
90 const glm::vec3& axis,
91 float angle,
92 const glm::vec3& origin = glm::vec3(0));
93
94/**
95 * @brief Apply translation to vertex set
96 * @param vertices Vertices to transform (modified in-place)
97 * @param displacement Translation vector
98 */
100 std::vector<glm::vec3>& vertices,
101 const glm::vec3& displacement);
102
103/**
104 * @brief Apply uniform scaling to vertex set
105 * @param vertices Vertices to transform (modified in-place)
106 * @param scale Scale factor (must be > 0)
107 * @param origin Scaling center (default: world origin)
108 */
110 std::vector<glm::vec3>& vertices,
111 float scale,
112 const glm::vec3& origin = glm::vec3(0));
113
114/**
115 * @brief Apply non-uniform scaling to vertex set
116 * @param vertices Vertices to transform (modified in-place)
117 * @param scale Per-axis scale factors
118 * @param origin Scaling center
119 */
120void apply_scale(
121 std::vector<glm::vec3>& vertices,
122 const glm::vec3& scale,
123 const glm::vec3& origin = glm::vec3(0));
124
125/**
126 * @brief Compute normal vectors along a piecewise-linear path
127 * @param path_vertices Sequential vertices defining curve
128 * @param normal_length Magnitude of normal vectors
129 * @param stride Sample every stride-th vertex (default: 1)
130 * @return Line segments (pairs) representing normals (for LINE_LIST topology)
131 *
132 * Normal at vertex i: perpendicular to tangent (v[i+1] - v[i])
133 * Returned as pairs: [midpoint - normal/2, midpoint + normal/2]
134 */
135std::vector<Nodes::LineVertex> compute_path_normals(
136 const std::vector<Nodes::LineVertex>& path_vertices,
137 float normal_length,
138 size_t stride = 1);
139
140/**
141 * @brief Compute tangent vectors along a piecewise-linear path
142 * @param path_vertices Sequential vertices defining curve
143 * @param tangent_length Magnitude of tangent vectors
144 * @param stride Sample every stride-th vertex
145 * @return Line segments (pairs) representing tangents (for LINE_LIST topology)
146 *
147 * Tangent at vertex i: direction (v[i+1] - v[i])
148 * Returned as pairs: [vertex - tangent/2, vertex + tangent/2]
149 */
150std::vector<Nodes::LineVertex> compute_path_tangents(
151 const std::vector<Nodes::LineVertex>& path_vertices,
152 float tangent_length,
153 size_t stride = 1);
154
155/**
156 * @brief Compute curvature vectors along a path (2nd derivative approximation)
157 * @param path_vertices Sequential vertices defining curve
158 * @param curvature_scale Magnitude scaling factor
159 * @param stride Sample every stride-th vertex
160 * @return Line segments representing discrete curvature
161 *
162 * Curvature at i approximated by: (v[i+1] - 2*v[i] + v[i-1])
163 */
164std::vector<Nodes::LineVertex> compute_path_curvature(
165 const std::vector<Nodes::LineVertex>& path_vertices,
166 float curvature_scale,
167 size_t stride = 1);
168
169/**
170 * @brief Sample parametric curve uniformly in parameter space
171 * @param curve Parametric function: [0,1] → ℝ³
172 * @param samples Number of samples
173 * @return Vertices sampled at t_k = k/(N-1) for k ∈ [0, N-1]
174 */
175std::vector<glm::vec3> sample_parametric_curve(
176 const std::function<glm::vec3(float)>& curve,
177 size_t samples);
178
179/**
180 * @brief Resample path vertices for arc-length parameterization
181 * @param path_vertices Input vertices (arbitrary spacing)
182 * @param num_samples Desired output sample count
183 * @return Vertices uniformly distributed by arc length
184 *
185 * Uses piecewise linear arc length estimation.
186 * Output vertices have constant spacing along curve.
187 */
188std::vector<Nodes::LineVertex> reparameterize_by_arc_length(
189 const std::vector<Nodes::LineVertex>& path_vertices,
190 size_t num_samples);
191
192/**
193 * @brief Project vertices onto plane defined by normal
194 * @param vertices Vertices to project (modified in-place)
195 * @param plane_point Point on projection plane
196 * @param plane_normal Plane normal vector
197 */
199 std::vector<glm::vec3>& vertices,
200 const glm::vec3& plane_point,
201 const glm::vec3& plane_normal);
202
203/**
204 * @brief Compute convex hull of vertex set (2D projection)
205 * @param vertices Input vertex set
206 * @param projection_normal Normal of projection plane (default: Z-axis)
207 * @return Vertices forming convex hull boundary (closed path)
208 *
209 * Uses Graham scan on projected coordinates.
210 */
211std::vector<glm::vec3> compute_convex_hull_2d(
212 const std::vector<glm::vec3>& vertices,
213 const glm::vec3& projection_normal = glm::vec3(0, 0, 1));
214
215/**
216 * @brief Apply color interpolation to position vertices
217 * @param positions Input position vertices
218 * @param colors Color stops for interpolation
219 * @param color_positions Normalized positions [0,1] for each color stop
220 * @param default_thickness Line thickness for all vertices (default: 1.0)
221 * @return LineVertex array with interpolated colors
222 *
223 * Example:
224 * colors = {red, blue}
225 * color_positions = {0.0, 1.0}
226 * → Linear gradient from red to blue along path
227 *
228 * If color_positions.empty(), distributes colors uniformly.
229 */
230std::vector<Nodes::LineVertex> apply_color_gradient(
231 const std::vector<glm::vec3>& positions,
232 const std::vector<glm::vec3>& colors,
233 const std::vector<float>& color_positions = {},
234 float default_thickness = 1.0F);
235
236/**
237 * @brief Apply uniform color to position vertices
238 */
239std::vector<Nodes::LineVertex> apply_uniform_color(
240 const std::vector<glm::vec3>& positions,
241 const glm::vec3& color,
242 float default_thickness = 1.0F);
243
244/**
245 * @brief Convert positions to LineVertex with per-vertex colors
246 */
247std::vector<Nodes::LineVertex> apply_vertex_colors(
248 const std::vector<glm::vec3>& positions,
249 const std::vector<glm::vec3>& colors,
250 float default_thickness = 1.0F);
251
252} // namespace MayaFlux::Kinesis
std::vector< Nodes::LineVertex > compute_path_normals(const std::vector< Nodes::LineVertex > &path_vertices, float normal_length, size_t stride)
Compute normal vectors along a piecewise-linear path.
std::vector< Nodes::LineVertex > reparameterize_by_arc_length(const std::vector< Nodes::LineVertex > &path_vertices, size_t num_samples)
Resample path vertices for arc-length parameterization.
void apply_transform(std::vector< glm::vec3 > &vertices, const glm::mat4 &transform)
Apply rigid transformation to vertex set.
void apply_translation(std::vector< glm::vec3 > &vertices, const glm::vec3 &displacement)
Apply translation to vertex set.
std::vector< Nodes::LineVertex > apply_color_gradient(const std::vector< glm::vec3 > &positions, const std::vector< glm::vec3 > &colors, const std::vector< float > &color_positions, float default_thickness)
Apply color interpolation to position vertices.
std::vector< Nodes::LineVertex > compute_path_tangents(const std::vector< Nodes::LineVertex > &path_vertices, float tangent_length, size_t stride)
Compute tangent vectors along a piecewise-linear path.
std::vector< Nodes::LineVertex > apply_vertex_colors(const std::vector< glm::vec3 > &positions, const std::vector< glm::vec3 > &colors, float default_thickness)
Convert positions to LineVertex with per-vertex colors.
std::vector< Nodes::LineVertex > apply_uniform_color(const std::vector< glm::vec3 > &positions, const glm::vec3 &color, float default_thickness)
Apply uniform color to position vertices.
std::vector< glm::vec3 > compute_convex_hull_2d(const std::vector< glm::vec3 > &vertices, const glm::vec3 &projection_normal)
Compute convex hull of vertex set (2D projection)
void project_onto_plane(std::vector< glm::vec3 > &vertices, const glm::vec3 &plane_point, const glm::vec3 &plane_normal)
Project vertices onto plane defined by normal.
std::vector< glm::vec3 > generate_ellipse(const glm::vec3 &center, float semi_major, float semi_minor, size_t segments, const glm::vec3 &normal)
Generate vertices along an elliptical path.
std::vector< glm::vec3 > sample_parametric_curve(const std::function< glm::vec3(float)> &curve, size_t samples)
Sample parametric curve uniformly in parameter space.
std::vector< glm::vec3 > generate_circle(const glm::vec3 &center, float radius, size_t segments, const glm::vec3 &normal)
Generate vertices along a circular path.
std::vector< glm::vec3 > generate_rectangle(const glm::vec3 &center, float width, float height, const glm::vec3 &normal)
Generate vertices of an axis-aligned rectangular path.
void apply_scale(std::vector< glm::vec3 > &vertices, const glm::vec3 &scale, const glm::vec3 &origin)
Apply non-uniform scaling to vertex set.
std::vector< glm::vec3 > generate_regular_polygon(const glm::vec3 &center, float radius, size_t sides, const glm::vec3 &normal, float phase_offset)
Generate vertices of a regular n-gon.
void apply_rotation(std::vector< glm::vec3 > &vertices, const glm::vec3 &axis, float angle, const glm::vec3 &origin)
Apply rotation to vertex set around arbitrary axis.
void apply_uniform_scale(std::vector< glm::vec3 > &vertices, float scale, const glm::vec3 &origin)
Apply uniform scaling to vertex set.
std::vector< Nodes::LineVertex > compute_path_curvature(const std::vector< Nodes::LineVertex > &path_vertices, float curvature_scale, size_t stride)
Compute curvature vectors along a path (2nd derivative approximation)