MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TopologyOperator.cpp
Go to the documentation of this file.
3
5
6//-----------------------------------------------------------------------------
7// Construction
8//-----------------------------------------------------------------------------
9
11 : m_default_mode(mode)
12{
14 "TopologyOperator created with mode {}", static_cast<int>(mode));
15}
16
17//-----------------------------------------------------------------------------
18// GraphicsOperator Interface (Simple Initialization)
19//-----------------------------------------------------------------------------
20
21void TopologyOperator::initialize(const std::vector<LineVertex>& vertices)
22{
23 if (vertices.empty()) {
25 "Cannot initialize topology with zero vertices");
26 return;
27 }
28
29 m_topologies.clear();
31
33 "TopologyOperator initialized with {} points in 1 topology",
34 vertices.size());
35}
36
37//-----------------------------------------------------------------------------
38// Advanced Initialization (Multiple Topologies)
39//-----------------------------------------------------------------------------
40
42 const std::vector<std::vector<LineVertex>>& topologies,
44{
45 for (const auto& topo : topologies) {
46 add_topology(topo, mode);
47 }
48
50 "TopologyOperator initialized with {} topologies",
51 topologies.size());
52}
53
55 const std::vector<LineVertex>& vertices,
57{
58 if (vertices.empty()) {
60 "Cannot add topology with zero vertices");
61 return;
62 }
63
64 auto topology = std::make_shared<GpuSync::TopologyGeneratorNode>(mode, 1024);
65
66 topology->set_points(vertices);
67 topology->compute_frame();
68
69 m_topologies.push_back(std::move(topology));
70
72 "Added topology #{} with {} points, {} connections",
73 m_topologies.size(), vertices.size(),
74 m_topologies.back()->get_connection_count());
75}
76
77//-----------------------------------------------------------------------------
78// Processing
79//-----------------------------------------------------------------------------
80
81void TopologyOperator::process(float /*dt*/)
82{
83 if (m_topologies.empty()) {
84 return;
85 }
86
87 for (auto& topology : m_topologies) {
88 topology->compute_frame();
89 }
90}
91
92//-----------------------------------------------------------------------------
93// GraphicsOperator Interface (Data Extraction)
94//-----------------------------------------------------------------------------
95
96std::vector<LineVertex> TopologyOperator::extract_vertices() const
97{
98 std::vector<LineVertex> positions;
99
100 for (const auto& topology : m_topologies) {
101 auto points = topology->get_points();
102 for (const auto& pt : points) {
103 positions.push_back(pt);
104 }
105 }
106
107 return positions;
108}
109
110std::span<const uint8_t> TopologyOperator::get_vertex_data_for_collection(uint32_t idx) const
111{
112 if (m_topologies.empty() || idx >= m_topologies.size()) {
113 return {};
114 }
115 return m_topologies[idx]->get_vertex_data();
116}
117
118std::span<const uint8_t> TopologyOperator::get_vertex_data() const
119{
121 for (const auto& group : m_topologies) {
122 auto span = group->get_vertex_data();
125 span.begin(), span.end());
126 }
127 return { m_vertex_data_aggregate.data(), m_vertex_data_aggregate.size() };
128}
129
131{
132 if (m_topologies.empty()) {
133 return {};
134 }
135
136 auto layout_opt = m_topologies[0]->get_vertex_layout();
137 if (!layout_opt) {
138 return {};
139 }
140
141 return *layout_opt;
142}
143
145{
146 size_t total = 0;
147 for (const auto& topology : m_topologies) {
148 total += topology->get_vertex_count();
149 }
150 return total;
151}
152
154{
155 return std::ranges::any_of(
157 [](const auto& group) { return group->needs_gpu_update(); });
158}
159
161{
162 for (auto& topology : m_topologies) {
163 topology->mark_vertex_data_dirty(false);
164 }
165}
166
168{
169 size_t total = 0;
170 for (const auto& topology : m_topologies) {
171 total += topology->get_point_count();
172 }
173 return total;
174}
175
176//-----------------------------------------------------------------------------
177// Parameter Control
178//-----------------------------------------------------------------------------
179
180void TopologyOperator::set_parameter(std::string_view param, double value)
181{
182 if (param == "connection_radius") {
183 for (auto& topology : m_topologies) {
184 topology->set_connection_radius(static_cast<float>(value));
185 }
186 } else if (param == "k_neighbors") {
187 for (auto& topology : m_topologies) {
188 topology->set_k_neighbors(static_cast<size_t>(value));
189 }
190 } else if (param == "line_thickness") {
191 m_default_thickness = static_cast<float>(value);
192 for (auto& topology : m_topologies) {
193 topology->set_line_thickness(m_default_thickness);
194 }
195 }
196}
197
198std::optional<double> TopologyOperator::query_state(std::string_view query) const
199{
200 if (query == "point_count") {
201 return static_cast<double>(get_point_count());
202 }
203
204 if (query == "connection_count") {
205 size_t total_connections = 0;
206 for (const auto& topology : m_topologies) {
207 total_connections += topology->get_connection_count();
208 }
209 return static_cast<double>(total_connections);
210 }
211
212 if (query == "topology_count") {
213 return static_cast<double>(m_topologies.size());
214 }
215 return std::nullopt;
216}
217
218//-----------------------------------------------------------------------------
219// Topology Configuration
220//-----------------------------------------------------------------------------
221
223{
224 for (auto& topology : m_topologies) {
225 topology->set_connection_radius(radius);
226 }
227}
228
230{
231 m_default_thickness = thickness;
232 for (auto& topology : m_topologies) {
233 topology->set_line_thickness(thickness);
234 }
235}
236
237void TopologyOperator::set_global_line_color(const glm::vec3& color)
238{
239 for (auto& topology : m_topologies) {
240 topology->set_line_color(color);
241 }
242}
243
244void* TopologyOperator::get_data_at(size_t global_index)
245{
246 size_t offset = 0;
247 for (auto& group : m_topologies) {
248 if (global_index < offset + group->get_point_count()) {
249 size_t local_index = global_index - offset;
250 return &group->get_points()[local_index];
251 }
252 offset += group->get_point_count();
253 }
254 return nullptr;
255}
256
257} // namespace MayaFlux::Nodes::Network
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
void * get_data_at(size_t global_index) override
Get mutable access to point at global index.
void add_topology(const std::vector< LineVertex > &vertices, Kinesis::ProximityMode mode)
Add a single topology with full per-vertex control.
std::span< const uint8_t > get_vertex_data_for_collection(uint32_t idx) const override
Get vertex data for specific collection (if multiple)
void initialize(const std::vector< LineVertex > &vertices)
Initialize a single topology with single set of vertices.
void process(float dt) override
Process for one batch cycle.
bool is_vertex_data_dirty() const override
Check if geometry changed this frame.
void set_parameter(std::string_view param, double value) override
Set operator parameter.
void set_connection_radius(float radius)
Set the connection radius for topology generation.
size_t get_vertex_count() const override
Get number of vertices (may differ from point count for topology/path)
std::vector< LineVertex > extract_vertices() const
Extract current vertex data as LineVertex array.
void set_global_line_color(const glm::vec3 &color)
Set the line color for all topologies.
Kakshya::VertexLayout get_vertex_layout() const override
Get vertex layout describing vertex structure.
std::vector< std::shared_ptr< GpuSync::TopologyGeneratorNode > > m_topologies
std::span< const uint8_t > get_vertex_data() const override
Get vertex data for GPU upload.
void set_global_line_thickness(float thickness)
Set the number of neighbors (k) for K-Nearest topology mode.
void mark_vertex_data_clean() override
Clear dirty flag after GPU upload.
size_t get_point_count() const override
Get source point count (before topology expansion)
void initialize_topologies(const std::vector< std::vector< LineVertex > > &topologies, Kinesis::ProximityMode mode)
Initialize multiple topologies with given positions and properties.
std::optional< double > query_state(std::string_view query) const override
Query operator internal state.
TopologyOperator(Kinesis::ProximityMode mode=Kinesis::ProximityMode::K_NEAREST)
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
Complete description of vertex data layout in a buffer.