MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
VertexSampler.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Stochastic.hpp"
4
6
7namespace MayaFlux::Kinesis {
8
9/**
10 * @brief Spatial distribution mode for point cloud and particle generation.
11 *
12 * Shared enumeration consumed by both ParticleNetwork and PointCloudNetwork.
13 * Separates the concern of spatial distribution from vertex type construction.
14 */
34
35/**
36 * @struct SamplerBounds
37 * @brief Spatial domain for vertex generation.
38 */
40 glm::vec3 min { -1.0F };
41 glm::vec3 max { 1.0F };
42
43 [[nodiscard]] glm::vec3 center() const noexcept { return (min + max) * 0.5F; }
44 [[nodiscard]] glm::vec3 extent() const noexcept { return max - min; }
45 [[nodiscard]] float max_radius() const noexcept { return glm::length(extent()) * 0.5F; }
46};
47
48/**
49 * @struct SampleResult
50 * @brief Position, color, orientation, and scalar derived from spatial sampling.
51 *
52 * Color is a spatially-derived hint (normalised position, spherical angle, etc.)
53 * and may be overridden by the caller. normal and tangent default to the
54 * canonical Z-up / X-right frame; distribution functions that have a meaningful
55 * surface orientation (sphere surface, torus) should override them.
56 * No vertex-type-specific fields are present.
57 */
59 glm::vec3 position;
60 glm::vec3 color { 1.0F };
61 float scalar { 1.0F }; ///< Normalised scalar; maps to size (PointVertex) or thickness (LineVertex)
62 glm::vec3 normal { 0.0F, 0.0F, 1.0F };
63 glm::vec3 tangent { 1.0F, 0.0F, 0.0F };
64};
65
66/**
67 * @brief Generate a batch of spatially distributed samples.
68 * @param distribution Spatial distribution algorithm to apply
69 * @param count Number of samples to generate
70 * @param bounds Spatial domain
71 * @param rng Stochastic engine (caller owns; enables reproducible sequences)
72 * @return SampleResult vector of length <= count (exact for all deterministic modes)
73 *
74 * All geometry is computed here. Callers convert SampleResult to their
75 * concrete vertex type via the projection helpers below.
76 */
77[[nodiscard]] std::vector<SampleResult> generate_samples(
78 SpatialDistribution distribution,
79 size_t count,
80 const SamplerBounds& bounds,
82
83/**
84 * @brief Generate a single sample at a specific index (for indexed/sequential modes).
85 * @param distribution Spatial distribution algorithm
86 * @param index Sample index within the total sequence
87 * @param total Total number of samples in the sequence
88 * @param bounds Spatial domain
89 * @param rng Stochastic engine
90 * @return Single SampleResult
91 *
92 * Useful for ParticleNetwork's per-index generation pattern.
93 */
94[[nodiscard]] SampleResult generate_sample_at(
95 SpatialDistribution distribution,
96 size_t index,
97 size_t total,
98 const SamplerBounds& bounds,
100
101//-----------------------------------------------------------------------------
102// Vertex projection — convert SampleResult to concrete vertex types.
103// These are the ONLY places that touch PointVertex / LineVertex fields.
104// Adding a new vertex type means adding one function here, nothing else.
105//-----------------------------------------------------------------------------
106
107/**
108 * @brief Project SampleResult to PointVertex.
109 * @param s Source sample
110 * @param size_range Min/max point size; scalar linearly interpolates within it
111 * @return PointVertex with all fields populated from sample
112 */
114 const SampleResult& s,
115 glm::vec2 size_range = { 8.0F, 12.0F }) noexcept
116{
117 return {
118 .position = s.position,
119 .color = s.color,
120 .size = glm::mix(size_range.x, size_range.y, s.scalar),
121 .uv = glm::vec2(0.0F),
122 .normal = s.normal,
123 .tangent = s.tangent,
124 };
125}
126
127/**
128 * @brief Project SampleResult to LineVertex.
129 * @param s Source sample
130 * @param thickness_range Min/max line thickness; scalar linearly interpolates within it
131 * @return LineVertex with all fields populated from sample
132 */
134 const SampleResult& s,
135 glm::vec2 thickness_range = { 1.0F, 2.0F }) noexcept
136{
137 return {
138 .position = s.position,
139 .color = s.color,
140 .thickness = glm::mix(thickness_range.x, thickness_range.y, s.scalar),
141 .uv = glm::vec2(0.0F),
142 .normal = s.normal,
143 .tangent = s.tangent,
144 };
145}
146
147/**
148 * @brief Project SampleResult to MeshVertex.
149 * @param s Source sample
150 * @return MeshVertex with all fields populated from sample
151 *
152 * MeshVertex doesn't have a size/thickness field, so scalar is passed through
153 * as weight for potential use in shader-based deformation or other effects.
154 */
156 const SampleResult& s,
157 glm::vec2 weight_range = { 0.0F, 1.0F }) noexcept
158{
159 return {
160 .position = s.position,
161 .color = s.color,
162 .weight = glm::mix(weight_range.x, weight_range.y, s.scalar),
163 .uv = glm::vec2(0.0F),
164 .normal = s.normal,
165 .tangent = s.tangent,
166 };
167}
168
169/**
170 * @brief Batch-project SampleResult vector to PointVertex.
171 * @param samples Source samples
172 * @param size_range Size range passed to to_point_vertex
173 * @return PointVertex vector of equal length
174 */
175[[nodiscard]] std::vector<Nodes::PointVertex> to_point_vertices(
176 std::span<const SampleResult> samples,
177 glm::vec2 size_range = { 8.0F, 12.0F });
178
179/**
180 * @brief Batch-project SampleResult vector to LineVertex.
181 * @param samples Source samples
182 * @param thickness_range Thickness range passed to to_line_vertex
183 * @return LineVertex vector of equal length
184 */
185[[nodiscard]] std::vector<Nodes::LineVertex> to_line_vertices(
186 std::span<const SampleResult> samples,
187 glm::vec2 thickness_range = { 1.0F, 2.0F });
188
189/**
190 * @brief Batch-project SampleResult vector to MeshVertex.
191 * @param samples Source samples
192 * @param weight_range Weight range passed to to_mesh_vertex (for potential shader use)
193 * @return MeshVertex vector of equal length
194 */
195[[nodiscard]] std::vector<Nodes::MeshVertex> to_mesh_vertices(
196 std::span<const SampleResult> samples,
197 glm::vec2 weight_range = { 0.0F, 1.0F });
198
199} // namespace MayaFlux::Kinesis
Eigen::Index count
Unified generative infrastructure for stochastic and procedural algorithms.
SampleResult generate_sample_at(SpatialDistribution dist, size_t index, size_t total, const SamplerBounds &bounds, Stochastic::Stochastic &rng)
Generate a single sample at a specific index (for indexed/sequential modes).
Nodes::PointVertex to_point_vertex(const SampleResult &s, glm::vec2 size_range={ 8.0F, 12.0F }) noexcept
Project SampleResult to PointVertex.
std::vector< Nodes::PointVertex > to_point_vertices(std::span< const SampleResult > samples, glm::vec2 size_range)
Batch-project SampleResult vector to PointVertex.
Nodes::MeshVertex to_mesh_vertex(const SampleResult &s, glm::vec2 weight_range={ 0.0F, 1.0F }) noexcept
Project SampleResult to MeshVertex.
std::vector< Nodes::MeshVertex > to_mesh_vertices(std::span< const SampleResult > samples, glm::vec2 weight_range)
Batch-project SampleResult vector to MeshVertex.
std::vector< Nodes::LineVertex > to_line_vertices(std::span< const SampleResult > samples, glm::vec2 thickness_range)
Batch-project SampleResult vector to LineVertex.
SpatialDistribution
Spatial distribution mode for point cloud and particle generation.
Nodes::LineVertex to_line_vertex(const SampleResult &s, glm::vec2 thickness_range={ 1.0F, 2.0F }) noexcept
Project SampleResult to LineVertex.
std::vector< SampleResult > generate_samples(SpatialDistribution dist, size_t count, const SamplerBounds &bounds, Stochastic::Stochastic &rng)
Generate a batch of spatially distributed samples.
float scalar
Normalised scalar; maps to size (PointVertex) or thickness (LineVertex)
Position, color, orientation, and scalar derived from spatial sampling.
float max_radius() const noexcept
glm::vec3 center() const noexcept
glm::vec3 extent() const noexcept
Spatial domain for vertex generation.
Vertex type for line primitives (LINE_LIST / LINE_STRIP topology)
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)
Vertex type for point primitives (POINT_LIST topology)