MayaFlux 0.2.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 and normalised color derived from spatial sampling.
51 *
52 * Color is a spatially-derived hint (normalized position, spherical angle, etc.)
53 * and may be overridden by the caller. No vertex-type-specific fields are present.
54 */
56 glm::vec3 position;
57 glm::vec3 color { 1.0F };
58 float scalar { 1.0F }; ///< Normalised scalar; maps to size (PointVertex) or thickness (LineVertex)
59};
60
61/**
62 * @brief Generate a batch of spatially distributed samples.
63 * @param distribution Spatial distribution algorithm to apply
64 * @param count Number of samples to generate
65 * @param bounds Spatial domain
66 * @param rng Stochastic engine (caller owns; enables reproducible sequences)
67 * @return SampleResult vector of length <= count (exact for all deterministic modes)
68 *
69 * All geometry is computed here. Callers convert SampleResult to their
70 * concrete vertex type via the projection helpers below.
71 */
72[[nodiscard]] std::vector<SampleResult> generate_samples(
73 SpatialDistribution distribution,
74 size_t count,
75 const SamplerBounds& bounds,
77
78/**
79 * @brief Generate a single sample at a specific index (for indexed/sequential modes).
80 * @param distribution Spatial distribution algorithm
81 * @param index Sample index within the total sequence
82 * @param total Total number of samples in the sequence
83 * @param bounds Spatial domain
84 * @param rng Stochastic engine
85 * @return Single SampleResult
86 *
87 * Useful for ParticleNetwork's per-index generation pattern.
88 */
89[[nodiscard]] SampleResult generate_sample_at(
90 SpatialDistribution distribution,
91 size_t index,
92 size_t total,
93 const SamplerBounds& bounds,
95
96//-----------------------------------------------------------------------------
97// Vertex projection — convert SampleResult to concrete vertex types.
98// These are the ONLY places that touch PointVertex / LineVertex fields.
99// Adding a new vertex type means adding one function here, nothing else.
100//-----------------------------------------------------------------------------
101
102/**
103 * @brief Project SampleResult to PointVertex.
104 * @param s Source sample
105 * @param size_range Min/max point size range; scalar linearly interpolates within it
106 * @return PointVertex with position, color, and size derived from sample
107 */
109 const SampleResult& s,
110 glm::vec2 size_range = { 8.0F, 12.0F }) noexcept
111{
112 return {
113 .position = s.position,
114 .color = s.color,
115 .size = glm::mix(size_range.x, size_range.y, s.scalar)
116 };
117}
118
119/**
120 * @brief Project SampleResult to LineVertex.
121 * @param s Source sample
122 * @param thickness_range Min/max line thickness range; scalar linearly interpolates within it
123 * @return LineVertex with position, color, and thickness derived from sample
124 */
126 const SampleResult& s,
127 glm::vec2 thickness_range = { 1.0F, 2.0F }) noexcept
128{
129 return {
130 .position = s.position,
131 .color = s.color,
132 .thickness = glm::mix(thickness_range.x, thickness_range.y, s.scalar)
133 };
134}
135
136/**
137 * @brief Batch-project SampleResult vector to PointVertex.
138 * @param samples Source samples
139 * @param size_range Size range passed to to_point_vertex
140 * @return PointVertex vector of equal length
141 */
142[[nodiscard]] std::vector<Nodes::PointVertex> to_point_vertices(
143 std::span<const SampleResult> samples,
144 glm::vec2 size_range = { 8.0F, 12.0F });
145
146/**
147 * @brief Batch-project SampleResult vector to LineVertex.
148 * @param samples Source samples
149 * @param thickness_range Thickness range passed to to_line_vertex
150 * @return LineVertex vector of equal length
151 */
152[[nodiscard]] std::vector<Nodes::LineVertex> to_line_vertices(
153 std::span<const SampleResult> samples,
154 glm::vec2 thickness_range = { 1.0F, 2.0F });
155
156} // 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.
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 and normalised color derived from spatial sampling.
float max_radius() const noexcept
glm::vec3 center() const noexcept
glm::vec3 extent() const noexcept
Spatial domain for vertex generation.