Enzo
Loading...
Searching...
No Matches
GeometryOperator.h
1#pragma once
2#include "Engine/Operator/GeometryConnection.h"
3#include "Engine/Operator/OpInfo.h"
4#include "Engine/Operator/GeometryOpDef.h"
5#include "Engine/Operator/NodePacket.h"
6#include "Engine/Parameter/Parameter.h"
7#include "Engine/Types.h"
8#include <functional>
9#include <optional>
10#include <memory>
11
12namespace enzo::nt {
13std::weak_ptr<GeometryConnection> connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex);
14
20{
21public:
32 virtual ~GeometryOperator()=default;
37
40 void cookOp(op::Context context);
41
49 std::shared_ptr<const enzo::NodePacket> getOutputPacket(unsigned int outputIndex) const;
50
58 void addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
59
67 void addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection);
68
77 void removeInputConnection(unsigned int inputIndex);
78
87 void removeOutputConnection(const nt::GeometryConnection* connection);
88
95 std::vector<std::weak_ptr<GeometryConnection>> getInputConnections() const;
96
103 std::vector<std::weak_ptr<GeometryConnection>> getOutputConnections() const;
104
110 std::weak_ptr<GeometryConnection> getInputConnection(size_t index) const;
111
113 std::vector<std::weak_ptr<prm::Parameter>> getParameters();
114
117 std::weak_ptr<prm::Parameter> getParameter(std::string parameterName);
118
123 std::string getLabel(); // TODO: implement node labels
124
132 std::string getTypeName();
133
141 void dirtyNode(bool dirtyDescendents=true);
142
144 bool isDirty();
145
149 unsigned int getMinInputs() const;
151 unsigned int getMaxInputs() const;
153 unsigned int getMaxOutputs() const;
154
156 bt::Vector2f getPosition() const { return position_; }
158 void setPosition(bt::Vector2f pos) { position_ = pos; }
159
161 boost::signals2::signal<void (nt::OpId opId, bool dirtyDescendents)> nodeDirtied;
162
163private:
164 void initParameters();
165
166 // TODO: avoid duplicate connections
167 std::vector<std::shared_ptr<nt::GeometryConnection>> inputConnections_;
168 std::vector<std::shared_ptr<nt::GeometryConnection>> outputConnections_;
169 std::vector<std::shared_ptr<prm::Parameter>> parameters_;
170 std::unique_ptr<enzo::nt::GeometryOpDef> opDef_;
171 enzo::nt::OpId opId_;
172 enzo::op::OpInfo opInfo_;
173 bt::Vector2f position_{0.f, 0.f};
174 bool dirty_ = true;
175};
176}
Basic attribute, parameter, and node types for Enzo.
uint64_t OpId
The unique ID assigned to each node in the network.
Definition Types.h:87
Directional edges to connect nodes.
Definition GeometryConnection.h:27
The unique runtime representation of a node.
Definition GeometryOperator.h:20
void addInputConnection(std::shared_ptr< nt::GeometryConnection > connection)
Adds a GeometryConnection to one of the inputs. Replacing old connections if needed.
Definition GeometryOperator.cpp:92
std::string getLabel()
NOT YET IMPLEMENTED. Returns the runtime label given to this node as a unique identifier within it's ...
Definition GeometryOperator.cpp:185
std::shared_ptr< const enzo::NodePacket > getOutputPacket(unsigned int outputIndex) const
Returns the current output geometry.
Definition GeometryOperator.cpp:87
boost::signals2::signal< void(nt::OpId opId, bool dirtyDescendents)> nodeDirtied
A signal emitted when the node is dirtied. This will usually notify the NetworkManager.
Definition GeometryOperator.h:161
unsigned int getMaxInputs() const
Returns the maximum number of input connections accepted by the node.
Definition GeometryOperator.cpp:235
std::vector< std::weak_ptr< GeometryConnection > > getInputConnections() const
Returns a vector containing weak pointers for all input connections.
Definition GeometryOperator.cpp:176
unsigned int getMaxOutputs() const
Returns the number of available outputs the node provides.
Definition GeometryOperator.cpp:239
unsigned int getMinInputs() const
Returns the minimum number of input connections required for the node to function....
Definition GeometryOperator.cpp:243
bool isDirty()
Returns true if the node is dirty and false if the node is clean (does not need cooking).
Definition GeometryOperator.cpp:71
void addOutputConnection(std::shared_ptr< nt::GeometryConnection > connection)
Adds a GeometryConnection to one of the outputs. Replacing old connections if needed.
Definition GeometryOperator.cpp:117
void removeInputConnection(unsigned int inputIndex)
Removes an input from the node's container.
Definition GeometryOperator.cpp:125
void removeOutputConnection(const nt::GeometryConnection *connection)
Removes an output from the node's container.
Definition GeometryOperator.cpp:141
void cookOp(op::Context context)
Computes the output geometry based on the cookOp definition in nt::GeometryOpDef. This is set by the ...
Definition GeometryOperator.cpp:77
void setPosition(bt::Vector2f pos)
Sets the node's position in the network graph.
Definition GeometryOperator.h:158
void dirtyNode(bool dirtyDescendents=true)
Marks the outputed geometry as outdated and notifies the network.
Definition GeometryOperator.cpp:64
std::weak_ptr< prm::Parameter > getParameter(std::string parameterName)
Returns a parameter with the given name belonging to this node.
Definition GeometryOperator.cpp:163
std::string getTypeName()
Returns the name belonging to this type of node (eg. grid or transform). Not to be confused with the ...
Definition GeometryOperator.cpp:196
bt::Vector2f getPosition() const
Returns the node's position in the network graph.
Definition GeometryOperator.h:156
GeometryOperator(const GeometryOperator &)=delete
Deleted copy constructor to avoid accidental copies.
std::vector< std::weak_ptr< GeometryConnection > > getOutputConnections() const
Returns a vector containing weak pointers for all output connections.
Definition GeometryOperator.cpp:191
GeometryOperator & operator=(const GeometryOperator &)=delete
Deleted copy assignment operator to avoid accidental copies.
GeometryOperator(enzo::nt::OpId opId, op::OpInfo opInfo)
Constructs a new node.
Definition GeometryOperator.cpp:43
std::weak_ptr< GeometryConnection > getInputConnection(size_t index) const
Returns an optional connection from a specific input index.
Definition GeometryOperator.cpp:202
std::vector< std::weak_ptr< prm::Parameter > > getParameters()
Returns all parameters belonging to this node.
Definition GeometryOperator.cpp:180
Provides network context for the cookOp function.
Definition Context.h:20
Definition OpInfo.h:20