MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
PointCloudNetwork.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "NodeNetwork.hpp"
5
8
10
12
13/**
14 * @class PointCloudNetwork
15 * @brief Spatial relational network operating on unordered point sets.
16 *
17 * PointCloudNetwork represents a literal point cloud:
18 * a collection of spatial samples (positions + optional attributes)
19 * with no inherent identity, persistence, or physics semantics.
20 *
21 * The network itself performs no computation. All structural,
22 * topological, or interpolative behavior is delegated to
23 * attached NetworkOperator instances.
24 *
25 * --------------------------------------------------------------------------
26 * Conceptual Model
27 * --------------------------------------------------------------------------
28 *
29 * Designed for computational graphics and data visualization.
30 * While it can ingest point cloud data from external sources
31 * (lidar, scanning, etc.), its purpose is generating and visualizing
32 * structure through algorithmic relationships — not surface reconstruction
33 * or scene analysis.
34 *
35 * - ParticleNetwork models entities that evolve over time.
36 * - PointCloudNetwork models spatial samples whose meaning
37 * emerges through algorithmically defined relationships.
38 *
39 * Points in this network:
40 * - Have no identity beyond index.
41 * - Do not simulate motion or forces.
42 * - Do not own connectivity.
43 * - Exist purely as a spatial substrate.
44 *
45 * Operators define interpretation:
46 * - TopologyOperator infers connectivity (KNN, radius, Delaunay, MST, etc.)
47 * - PathOperator interpolates structure through control points.
48 *
49 * Rendering and processing backends remain completely agnostic
50 * to network type — they consume vertex data produced by operators.
51 *
52 * --------------------------------------------------------------------------
53 * Modality-Agnostic Design
54 * --------------------------------------------------------------------------
55 *
56 * Points may originate from any source:
57 * - Procedural generation
58 * - Texture sampling
59 * - Image analysis
60 * - Audio feature extraction
61 * - External datasets
62 *
63 * Once spatialized, the network treats them uniformly as relational samples.
64 *
65 * --------------------------------------------------------------------------
66 * Important Distinction
67 * --------------------------------------------------------------------------
68 *
69 * If you need per-entity state, temporal evolution, or physics simulation,
70 * use ParticleNetwork.
71 *
72 * If you need structural relationships between spatial samples,
73 * use PointCloudNetwork.
74 *
75 * PointCloudNetwork is for STRUCTURE.
76 * ParticleNetwork is for MOTION.
77 *
78 * Common use cases:
79 * - Network graphs (social, neural, data visualization)
80 * - Procedural topology generation (Delaunay, MST, proximity)
81 * - Path visualization (trajectories, routes, flow lines)
82 * - Data-driven connectivity inference
83 * - Gradient-based color visualization
84 *
85 * --------------------------------------------------------------------------
86 * Usage Example
87 * --------------------------------------------------------------------------
88 *
89 * ```cpp
90 * // Single topology network
91 * auto cloud = std::make_shared<PointCloudNetwork>(500);
92 * cloud->create_operator<TopologyOperator>(Kinesis::ProximityMode::K_NEAREST);
93 * cloud->initialize();
94 *
95 * // Multiple independent topologies
96 * auto cloud = std::make_shared<PointCloudNetwork>();
97 * auto topo = cloud->create_operator<TopologyOperator>(Kinesis::ProximityMode::RADIUS);
98 * topo->initialize_topologies({group1_points, group2_points}, mode);
99 * cloud->set_operator(std::move(topo));
100 *
101 * // Path-based visualization
102 * auto cloud = std::make_shared<PointCloudNetwork>();
103 * auto paths = cloud->create_operator<PathOperator>();
104 * paths->initialize_paths({path1, path2, path3}, InterpolationMode::CATMULL_ROM);
105 * cloud->set_operator(std::move(paths));
106 *
107 * // Per-point color gradient
108 * cloud->apply_color_gradient(start_color, end_color);
109 * cloud->set_point_colors(custom_colors);
110 * ```
111 */
112class MAYAFLUX_API PointCloudNetwork : public NodeNetwork {
113public:
114 /**
115 * @brief Create empty point cloud network
116 */
118
119 /**
120 * @brief Create network with initial point count and bounds
121 * @param num_points Number of points to generate
122 * @param bounds_min Minimum coordinate bounds
123 * @param bounds_max Maximum coordinate bounds
124 * @param init_mode How to distribute initial positions
125 */
126 explicit PointCloudNetwork(
127 size_t num_points,
128 const glm::vec3& bounds_min = glm::vec3(-1.0F),
129 const glm::vec3& bounds_max = glm::vec3(1.0F),
130 Kinesis::SpatialDistribution init_mode = Kinesis::SpatialDistribution::RANDOM_CUBE);
131
132 void initialize() override;
133 void reset() override;
134 void process_batch(unsigned int num_samples) override;
135 void set_topology(Topology topology) override;
136
137 /**
138 * @brief Reinitialize point cloud with new parameters
139 * @param count Number of points to generate
140 * @param bounds_min Minimum coordinate bounds
141 * @param bounds_max Maximum coordinate bounds
142 * @param mode How to distribute initial positions
143 */
144 void reinitialize(
145 size_t count,
146 const glm::vec3& bounds_min,
147 const glm::vec3& bounds_max,
149
150 [[nodiscard]] size_t get_node_count() const override;
151 [[nodiscard]] std::optional<double> get_node_output(size_t index) const override;
152 [[nodiscard]] std::unordered_map<std::string, std::string> get_metadata() const override;
153
154 /**
155 * @brief Set all point vertices
156 * @param vertices Vector of LineVertex containing position, color, thickness
157 */
158 void set_vertices(const std::vector<LineVertex>& vertices);
159
160 /**
161 * @brief Set colors for all points
162 * @param colors Vector of RGB colors
163 */
164 // void set_colors(const std::vector<glm::vec3>& colors);
165
166 /**
167 * @brief Apply linear color gradient across points
168 * @param start_color Color for first point
169 * @param end_color Color for last point
170 */
171 void apply_color_gradient(const glm::vec3& start_color, const glm::vec3& end_color);
172
173 /**
174 * @brief Apply radial color gradient from center
175 * @param center_color Color at center
176 * @param edge_color Color at maximum distance
177 * @param center Center point for gradient calculation
178 */
179 void apply_radial_gradient(
180 const glm::vec3& center_color,
181 const glm::vec3& edge_color,
182 const glm::vec3& center = glm::vec3(0.0F));
183
184 /**
185 * @brief Get all point vertices
186 */
187 [[nodiscard]] std::vector<LineVertex> get_vertices() const;
188
189 /**
190 * @brief Update single vertex completely
191 * @param index Point index
192 * @param vertex New LineVertex data
193 */
194 void update_vertex(size_t index, const LineVertex& vertex);
195
196 /**
197 * @brief Set global line color for topology/path rendering
198 * @param color RGB color
199 */
200 void set_line_color(const glm::vec3& color);
201
202 /**
203 * @brief Set connection radius for topology generation (TopologyOperator only)
204 * @param radius Maximum distance for connections
205 */
206 void set_connection_radius(float radius);
207
208 /**
209 * @brief Set K value for K-nearest neighbors (TopologyOperator only)
210 * @param k Number of nearest neighbors
211 */
212 void set_k_neighbors(size_t k);
213
214 /**
215 * @brief Set line thickness for topology/path rendering
216 * @param thickness Line thickness in pixels
217 */
218 void set_line_thickness(float thickness);
219
220 /**
221 * @brief Set samples per segment for path interpolation (PathOperator only)
222 * @param samples Number of samples between control points
223 */
224 void set_samples_per_segment(size_t samples);
225
226 /**
227 * @brief Set tension for Catmull-Rom interpolation (PathOperator only)
228 * @param tension Tension parameter (0.0 = loose, 1.0 = tight)
229 */
230 void set_tension(double tension);
231
232 NetworkOperator* get_operator() override { return m_operator.get(); }
233 const NetworkOperator* get_operator() const override { return m_operator.get(); }
234 bool has_operator() const override { return m_operator != nullptr; }
235
236 /**
237 * @brief Create and set operator in one call
238 */
239 template <typename OpType, typename... Args>
240 OpType* create_operator(Args&&... args)
241 {
242 auto op = std::make_unique<OpType>(std::forward<Args>(args)...);
243 auto* ptr = op.get();
244 set_operator(std::move(op));
245 return ptr;
246 }
247
248 void set_operator(std::unique_ptr<NetworkOperator> op);
249
250private:
251 size_t m_num_points {};
253 Kinesis::SpatialDistribution m_init_mode { Kinesis::SpatialDistribution::RANDOM_CUBE };
255
256 std::unique_ptr<NetworkOperator> m_operator;
257
258 std::vector<LineVertex> m_cached_vertices;
259
260 [[nodiscard]] std::vector<LineVertex> generate_initial_positions();
261
262 /**
263 * @brief Update mapped parameters before path/topology processing
264 */
265 void update_mapped_parameters();
266};
267
268} // namespace MayaFlux::Nodes::Network
Eigen::Index count
Unified generative infrastructure for stochastic and procedural algorithms.
Domain-agnostic interpretive lens for network processing.
Abstract base class for structured collections of nodes with defined relationships.
std::unique_ptr< NetworkOperator > m_operator
OpType * create_operator(Args &&... args)
Create and set operator in one call.
Kinesis::Stochastic::Stochastic m_random_gen
const NetworkOperator * get_operator() const override
Spatial relational network operating on unordered point sets.
void initialize()
Definition main.cpp:11
SpatialDistribution
Spatial distribution mode for point cloud and particle generation.
Topology
Defines the structural relationships between nodes in the network.
Spatial domain for vertex generation.