MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
PathOperator.hpp
Go to the documentation of this file.
1#pragma once
4
6
7class MAYAFLUX_API PathOperator : public GraphicsOperator {
8public:
9 explicit PathOperator(
10 Kinesis::InterpolationMode mode = Kinesis::InterpolationMode::CATMULL_ROM,
11 Eigen::Index samples_per_segment = 32);
12
13 ~PathOperator() override { m_shutdown.store(true, std::memory_order_release); }
14
15 /**
16 * @brief Initialize a single path with given control points and properties.
17 */
18 void initialize(const std::vector<LineVertex>& vertices);
19
20 /**
21 * @brief Initialize multiple paths with given control points and properties.
22 * @param paths Vector of control point vectors, one per path.
23 * @param mode Interpolation mode for all paths.
24 */
25 void initialize_paths(
26 const std::vector<std::vector<LineVertex>>& paths,
28
29 /**
30 * @brief Add a new path with given control points and properties.
31 * @param control_points Vector of control points for the path.
32 * @param mode Interpolation mode for the path.
33 * @param default_samples_per_segment Number of samples to generate per segment (between control points).
34 * @param max_control_points Maximum number of control points to store in history for this path
35 * @param tension Tension parameter for applicable interpolation modes (e.g. Catmull-Rom)
36 */
37 void add_path(
38 const std::vector<LineVertex>& control_vertices,
39 Kinesis::InterpolationMode mode, uint32_t default_samples_per_segment = 32, size_t max_control_points = 64, double tension = 0.5);
40
41 /**
42 * @brief Add an externally constructed PathGeneratorNode subtype to the operator.
43 *
44 * Accepts any PathGeneratorNode subclass (e.g. LineSegmentNode) that was
45 * constructed and configured by the caller. The node is appended to m_paths
46 * and will participate in process(), get_vertex_data(), and extract_vertices()
47 * identically to nodes created by add_path().
48 *
49 * compute_frame() is called once before insertion so the node's vertex buffer
50 * is populated on the first frame.
51 *
52 * @param node Non-null shared_ptr to a PathGeneratorNode or subclass.
53 */
54 void add_node(std::shared_ptr<GpuSync::PathGeneratorNode> node);
55
56 void process(float dt) override;
57
58 [[nodiscard]] std::span<const uint8_t> get_vertex_data() const override;
59 [[nodiscard]] std::span<const uint8_t> get_vertex_data_for_collection(uint32_t idx) const override;
60 [[nodiscard]] Kakshya::VertexLayout get_vertex_layout() const override;
61 [[nodiscard]] size_t get_vertex_count() const override;
62 [[nodiscard]] bool is_vertex_data_dirty() const override;
63 void mark_vertex_data_clean() override;
64
65 /**
66 * @brief Extract current vertex data as LineVertex array
67 * @return Vector of LineVertex with current positions, colors, thicknesses
68 */
69 [[nodiscard]] std::vector<LineVertex> extract_vertices() const;
70
71 void set_parameter(std::string_view param, double value) override;
72 [[nodiscard]] std::optional<double> query_state(std::string_view query) const override;
73 [[nodiscard]] std::string_view get_type_name() const override { return "Path"; }
74 [[nodiscard]] size_t get_point_count() const override;
75
76 /**
77 * @brief Access a specific path node directly.
78 * @param i Collection index.
79 * @return Shared pointer to the PathGeneratorNode, or nullptr if out of range.
80 */
81 [[nodiscard]] std::shared_ptr<GpuSync::PathGeneratorNode> get_path(size_t i) const
82 {
83 if (i >= m_paths.size()) {
84 return nullptr;
85 }
86 return m_paths[i];
87 }
88
89 /**
90 * @brief Set the number of samples per segment for all paths.
91 * @param samples Number of samples to generate per segment between control points.
92 */
93 void set_samples_per_segment(Eigen::Index samples);
94
95 /**
96 * @brief Set the tension parameter for all paths (if supported by mode).
97 * @param tension Tension value (e.g., for cubic Hermite interpolation).
98 */
99 void set_tension(double tension);
100
101 /**
102 * @brief Set the global thickness for all paths.
103 * @param thickness Thickness value to apply to all paths.
104 */
105 void set_global_thickness(float thickness);
106
107 /**
108 * @brief Set the global color tint for all paths.
109 * @param color Color tint to apply to all paths (multiplied with individual tints).
110 */
111 void set_global_color(const glm::vec3& color);
112
113 /**
114 * @brief Get the number of paths currently managed by this operator.
115 * @return Number of path collections.
116 */
117 [[nodiscard]] size_t get_path_count() const { return m_paths.size(); }
118
119 const char* get_vertex_type_name() const override { return "PathVertex"; }
120
121protected:
122 void* get_data_at(size_t global_index) override;
123
124private:
125 std::vector<std::shared_ptr<GpuSync::PathGeneratorNode>> m_paths;
126
127 mutable std::vector<uint8_t> m_vertex_data_aggregate;
128
131 float m_default_thickness { 2.0F };
132
133 mutable std::atomic<uint32_t> m_access_token { 0 };
134 std::atomic<bool> m_shutdown { false };
135};
136
137} // namespace MayaFlux::Nodes::Network
Operator that produces GPU-renderable geometry.
const char * get_vertex_type_name() const override
Get human-readable vertex type name (for validation/debugging)
std::vector< uint8_t > m_vertex_data_aggregate
Kinesis::InterpolationMode m_default_mode
std::vector< std::shared_ptr< GpuSync::PathGeneratorNode > > m_paths
size_t get_path_count() const
Get the number of paths currently managed by this operator.
std::string_view get_type_name() const override
Type name for introspection.
std::shared_ptr< GpuSync::PathGeneratorNode > get_path(size_t i) const
Access a specific path node directly.
void initialize()
Definition main.cpp:11
InterpolationMode
Mathematical interpolation methods.
Complete description of vertex data layout in a buffer.