PeriDyno 1.0.0
Loading...
Searching...
No Matches
Node.h
Go to the documentation of this file.
1
16#pragma once
17#include "OBase.h"
18#include "Field.h"
19#include "Platform.h"
20#include "DeclarePort.h"
21#include "NodePort.h"
22
27
28namespace dyno
29{
30 class Action;
31 class SceneGraph;
32
34 {
36 lower = Vec3f(-1);
37 upper = Vec3f(1);
38 }
39
41 lower = lo;
42 upper = hi;
43 }
44
47
49 lower = lower.minimum(box.lower);
50 upper = upper.maximum(box.upper);
51
52 return *this;
53 }
54
56 lower = lower.maximum(box.lower);
57 upper = upper.minimum(box.upper);
58
59 return *this;
60 }
61
62 float maxLength() {
63 return std::max(upper[0] - lower[0], std::max(upper[1] - lower[1], upper[2] - lower[2]));
64 }
65 };
66
67 class Node : public OBase
68 {
69 public:
70
71 template<class T>
72 using SPtr = std::shared_ptr<T>;
73
74 Node();
75 ~Node() override;
76
77 void setName(std::string name);
78 std::string getName() override;
79
80 virtual std::string getNodeType();
81
82 bool isAutoSync();
83
84 bool isAutoHidden();
85
91 void setAutoSync(bool con);
92
93 void setAutoHidden(bool con);
94
96 virtual bool isActive();
97
99 virtual void setActive(bool active);
100
102 virtual bool isVisible();
103
105 virtual void setVisible(bool visible);
106
108 virtual Real getDt();
109
110 void setDt(Real dt);
111
112 void setSceneGraph(SceneGraph* scn);
114
115 std::vector<NodePort*>& getImportNodes() { return mImportNodes; }
116 std::vector<NodePort*>& getExportNodes() { return mExportNodes; }
117
125 bool addModule(std::shared_ptr<Module> module);
126 bool deleteModule(std::shared_ptr<Module> module);
127
136 template<class TModule>
137 bool addModule(std::shared_ptr<TModule> tModule)
138 {
139 std::shared_ptr<Module> module = std::dynamic_pointer_cast<Module>(tModule);
140 return addModule(module);
141 }
142 template<class TModule>
143 bool deleteModule(std::shared_ptr<TModule> tModule)
144 {
145 std::shared_ptr<Module> module = std::dynamic_pointer_cast<Module>(tModule);
146 return deleteModule(module);
147 }
148
149 std::list<std::shared_ptr<Module>>& getModuleList() { return mModuleList; }
150
151 bool hasModule(std::string name);
152
159 std::shared_ptr<Module> getModule(std::string name);
160
167 template<class TModule>
168 std::shared_ptr<TModule> getModule()
169 {
170 TModule* tmp = new TModule;
171 std::shared_ptr<Module> base;
172 std::list<std::shared_ptr<Module>>::iterator iter;
173 for (iter = mModuleList.begin(); iter != mModuleList.end(); iter++)
174 {
175 if ((*iter)->getClassInfo() == tmp->getClassInfo())
176 {
177 base = *iter;
178 break;
179 }
180 }
181 delete tmp;
182 return TypeInfo::cast<TModule>(base);
183 }
184
185 template<class TModule>
186 std::shared_ptr<TModule> getModule(std::string name)
187 {
188 std::shared_ptr<Module> base = getModule(name);
189
190 return TypeInfo::cast<TModule>(base);
191 }
192
193 std::shared_ptr<Pipeline> resetPipeline();
194 std::shared_ptr<AnimationPipeline> animationPipeline();
195 std::shared_ptr<GraphicsPipeline> graphicsPipeline();
196
197 template<class TModule>
198 std::shared_ptr<TModule> addModule(std::string name)
199 {
200 if (hasModule(name))
201 {
202 Log::sendMessage(Log::Error, std::string("Module ") + name + std::string(" already exists!"));
203 return nullptr;
204 }
205 std::shared_ptr<TModule> module = std::make_shared<TModule>();
206 module->setName(name);
207 this->addModule(module);
208
209 return module;
210 }
211
215 void update();
216
218
219 void reset();
220
221 virtual NBoundingBox boundingBox();
222// /**
223// * @brief Depth-first tree traversal
224// *
225// * @param act Operation on the node
226// */
227// void traverseBottomUp(Action* act);
228// template<class Act, class ... Args>
229// void traverseBottomUp(Args&& ... args) {
230// Act action(std::forward<Args>(args)...);
231// doTraverseBottomUp(&action);
232// }
233//
234// /**
235// * @brief Breadth-first tree traversal
236// *
237// * @param act Operation on the node
238// */
239// void traverseTopDown(Action* act);
240// template<class Act, class ... Args>
241// void traverseTopDown(Args&& ... args) {
242// Act action(std::forward<Args>(args)...);
243// doTraverseTopDown(&action);
244// }
245
246 bool connect(NodePort* nPort);
247 bool disconnect(NodePort* nPort);
248
259 bool attachField(FBase* field, std::string name, std::string desc, bool autoDestroy = true) override;
260
261 std::vector<NodePort*>& getAllNodePorts() { return mImportNodes; }
262
263 uint sizeOfNodePorts() { return (uint)mImportNodes.size(); }
264
265 uint sizeOfImportNodes() const;
266 uint sizeOfExportNodes() const { return (uint)mExportNodes.size(); }
267
268 void setForceUpdate(bool b);
269
270 protected:
271// virtual void doTraverseBottomUp(Action* act);
272// virtual void doTraverseTopDown(Action* act);
273
274 bool appendExportNode(NodePort* nodePort);
275 bool removeExportNode(NodePort* nodePort);
276
277 virtual void preUpdateStates();
278 virtual void updateStates();
279 virtual void postUpdateStates();
280
281 virtual void updateTopology();
282
283 virtual void resetStates();
284
285 virtual bool validateInputs();
286
287 virtual bool requireUpdate();
288
292 void tick();
293
294 private:
295 bool addNodePort(NodePort* port);
296
297 bool addToModuleList(std::shared_ptr<Module> module);
298 bool deleteFromModuleList(std::shared_ptr<Module> module);
299
300 public:
301 std::string m_node_name;
302
303 DEF_VAR_STATE(Real, ElapsedTime, 0, "Elapsed Time");
304 DEF_VAR_STATE(Real, TimeStep, Real(0.033), "Time step size");
305
306 DEF_VAR_STATE(uint, FrameNumber, 0, "Frame number");
307
308 private:
312 bool mAutoSync = false;
313
314 bool mPhysicsEnabled = true;
315
316 bool mRenderingEnabled = true;
317
318 bool mExported = true;
319
320 bool mForceUpdate = true;
321
322 bool mAutoHidden = false;
323
329
334 std::list<std::shared_ptr<Module>> mModuleList;
335
340 std::shared_ptr<Pipeline> mResetPipeline;
341 std::shared_ptr<AnimationPipeline> mAnimationPipeline;
342 std::shared_ptr<GraphicsPipeline> mGraphicsPipeline;
343
344// //std::shared_ptr<DeviceContext> m_context;
345//
346 std::vector<NodePort*> mImportNodes;
347
348 std::vector<NodePort*> mExportNodes;
349
351
352 friend class NodePort;
353 };
354}
double Real
Definition Typedef.inl:23
@ Error
Error information while executing something.
Definition Log.h:50
static void sendMessage(MessageType type, const std::string &text)
Add a new message to log.
Definition Log.cpp:41
uint sizeOfImportNodes() const
Definition Node.cpp:533
bool attachField(FBase *field, std::string name, std::string desc, bool autoDestroy=true) override
Attach a field to Node.
Definition Node.cpp:493
bool appendExportNode(NodePort *nodePort)
Definition Node.cpp:435
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
bool mAutoHidden
Definition Node.h:322
std::vector< NodePort * > mExportNodes
Definition Node.h:348
std::list< std::shared_ptr< Module > > & getModuleList()
Definition Node.h:149
virtual void updateTopology()
Definition Node.cpp:476
bool addModule(std::shared_ptr< Module > module)
Add a module to m_module_list and other special module lists.
Definition Node.cpp:365
virtual void resetStates()
Definition Node.cpp:214
virtual bool isActive()
Check the state of dynamics.
Definition Node.cpp:73
virtual void setActive(bool active)
Set the state of dynamics.
Definition Node.cpp:78
void setForceUpdate(bool b)
Definition Node.cpp:544
void setAutoSync(bool con)
Whether the node can be automatically synchronized when its ancestor is updated.
Definition Node.cpp:63
void setDt(Real dt)
Definition Node.cpp:98
virtual Real getDt()
Simulation timestep.
Definition Node.cpp:93
bool disconnect(NodePort *nPort)
Definition Node.cpp:488
virtual void updateStates()
Definition Node.cpp:141
bool isAutoSync()
Definition Node.cpp:53
bool addModule(std::shared_ptr< TModule > tModule)
Add a speical kind of module.
Definition Node.h:137
friend class NodePort
Definition Node.h:352
std::string m_node_name
Definition Node.h:301
bool mPhysicsEnabled
Definition Node.h:314
DEF_VAR_STATE(Real, TimeStep, Real(0.033), "Time step size")
uint sizeOfExportNodes() const
Definition Node.h:266
bool addNodePort(NodePort *port)
Definition Node.cpp:580
std::shared_ptr< Pipeline > mResetPipeline
Pointer of the pipeline.
Definition Node.h:340
virtual std::string getNodeType()
Definition Node.cpp:48
virtual bool requireUpdate()
Definition Node.cpp:237
std::shared_ptr< TModule > addModule(std::string name)
Definition Node.h:198
bool removeExportNode(NodePort *nodePort)
Definition Node.cpp:453
uint sizeOfNodePorts()
Definition Node.h:263
bool addToModuleList(std::shared_ptr< Module > module)
Definition Node.cpp:657
std::shared_ptr< AnimationPipeline > mAnimationPipeline
Definition Node.h:341
void update()
Called every time interval.
Definition Node.cpp:146
void setSceneGraph(SceneGraph *scn)
Definition Node.cpp:103
Real mDt
Time step size.
Definition Node.h:328
virtual void preUpdateStates()
Definition Node.cpp:136
std::shared_ptr< Pipeline > resetPipeline()
Definition Node.cpp:302
void updateGraphicsContext()
Definition Node.cpp:206
void tick()
notify all state and output fields are updated
Definition Node.cpp:266
bool mAutoSync
A parameter to control whether the node can be updated automatically by its ancestor.
Definition Node.h:312
SceneGraph * getSceneGraph()
Definition Node.cpp:108
SceneGraph * mSceneGraph
Definition Node.h:350
virtual NBoundingBox boundingBox()
Definition Node.cpp:196
bool deleteFromModuleList(std::shared_ptr< Module > module)
Definition Node.cpp:670
bool isAutoHidden()
Definition Node.cpp:58
~Node() override
Definition Node.cpp:16
bool deleteModule(std::shared_ptr< Module > module)
Definition Node.cpp:373
std::list< std::shared_ptr< Module > > mModuleList
A module list containing all modules.
Definition Node.h:334
void setName(std::string name)
Definition Node.cpp:38
void reset()
Definition Node.cpp:183
DEF_VAR_STATE(Real, ElapsedTime, 0, "Elapsed Time")
std::shared_ptr< T > SPtr
Definition Node.h:72
std::shared_ptr< TModule > getModule()
Get the Module by the module class name.
Definition Node.h:168
std::shared_ptr< AnimationPipeline > animationPipeline()
Definition Node.cpp:311
bool deleteModule(std::shared_ptr< TModule > tModule)
Definition Node.h:143
std::shared_ptr< TModule > getModule(std::string name)
Definition Node.h:186
virtual bool validateInputs()
Definition Node.cpp:219
std::string getName() override
Definition Node.cpp:43
bool mRenderingEnabled
Definition Node.h:316
std::shared_ptr< GraphicsPipeline > mGraphicsPipeline
Definition Node.h:342
std::vector< NodePort * > mImportNodes
Definition Node.h:346
virtual void setVisible(bool visible)
Set the visibility of context.
Definition Node.cpp:88
std::vector< NodePort * > & getExportNodes()
Definition Node.h:116
bool connect(NodePort *nPort)
Depth-first tree traversal.
Definition Node.cpp:481
void setAutoHidden(bool con)
Definition Node.cpp:68
DEF_VAR_STATE(uint, FrameNumber, 0, "Frame number")
virtual bool isVisible()
Check the visibility of context.
Definition Node.cpp:83
bool mForceUpdate
Definition Node.h:320
virtual void postUpdateStates()
Definition Node.cpp:201
bool mExported
Definition Node.h:318
std::vector< NodePort * > & getAllNodePorts()
Definition Node.h:261
bool hasModule(std::string name)
Definition Node.cpp:637
std::vector< NodePort * > & getImportNodes()
Definition Node.h:115
Input ports for Node.
Definition NodePort.h:38
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
unsigned int uint
Definition VkProgram.h:14
float maxLength()
Definition Node.h:62
NBoundingBox(Vec3f lo, Vec3f hi)
Definition Node.h:40
NBoundingBox & intersect(const NBoundingBox box)
Definition Node.h:55
NBoundingBox & join(const NBoundingBox box)
Definition Node.h:48