AGX Dynamics  2.37.2.0
RigidBodyTrajectoryDrawable.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXOSG_RIGIDBODY_TRAJECTORIES_DRAWABLE_H
18 #define AGXOSG_RIGIDBODY_TRAJECTORIES_DRAWABLE_H
19 
20 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
21 #include <osg/Drawable>
22 #include <osgViewer/Viewer>
23 #include <osg/Version>
24 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
25 
26 #include <agxOSG/export.h>
27 #include <agxOSG/ScalarColorMap.h>
28 #include <agx/Task.h>
29 #include <agx/observer_ptr.h>
30 #include <agxSDK/Simulation.h>
31 
32 namespace agxOSG
33 {
35  class AGXOSG_EXPORT RigidBodyTrajectoryDrawable : public osg::Drawable
36  {
37  typedef std::deque<agx::Vec3> PositionBuffer;
38  typedef std::deque<agx::Vec4f> ColorsBuffer;
39  typedef std::pair<PositionBuffer, ColorsBuffer> TrajectoryData;
41 
42  public:
44 
45  virtual osg::Object* cloneType() const { return new RigidBodyTrajectoryDrawable(m_simulation); }
46  virtual osg::Object* clone(const osg::CopyOp&) const { return new RigidBodyTrajectoryDrawable(*this); }
47  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const RigidBodyTrajectoryDrawable *>(obj) != nullptr; }
48  virtual const char* libraryName() const { return "agxOSG"; }
49  virtual const char* className() const { return "RigidBodyTrajectoryDrawable"; }
50 
52 # if OSG_VERSION_GREATER_OR_EQUAL(3,4,0)
53  virtual osg::BoundingSphere computeBound() const;
54  virtual osg::BoundingBox computeBoundingBox() const;
55 #else
56  virtual osg::BoundingBox computeBound() const;
57 #endif
58 
60  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
61 
63  void updateTrajectories();
64 
66  void setNumTrajectoryPositions(agx::UInt num);
67 
69  agx::UInt getNumTrajectoryPositions() const;
70 
72  void setDefaultTrajectoryColor(const agx::Vec4f& color);
73 
75  void resetTrajectories();
76 
78  void removeTrajectoryFromId(agx::Index particleId);
79 
80  void setEnable( bool enable, bool doResample = true );
81 
82  bool getEnable() const;
83 
84  void setOnlyDrawRigidBodyEmitterBodies( bool enable );
85 
86  bool getOnlyDrawRigidBodyEmitterBodies() const;
87 
88  // Amount of particles that should sampled in the tracing. 0 None ; 1 All
89  void setSampling(agx::Real sampling, bool doResample = true);
90 
91  agx::Real getSampling() const;
92 
93  agxSDK::Simulation * getSimulation();
94 
95  void resample();
96 
97  void addRigidBodyCallback(agxSDK::Simulation *, agx::RigidBody *body);
98 
99  void removeRigidBodyCallback(agxSDK::Simulation *, agx::RigidBody *body);
100 
108  void setColorMap(ScalarColorMap* colorMap);
109 
114  ScalarColorMap* getColorMap() const;
115 
116  protected:
117  virtual ~RigidBodyTrajectoryDrawable();
118 
119  void updateKernelBuffers();
120 
121  void handleCreationEvent(agx::Index index);
122 
123  void handleDestructionEvent(agx::Index index);
124 
125  void sample(agx::Index index);
126 
127  void popOldPositionsInDeadTrajectories();
128 
130  // Variables
132  protected:
133 
136 
139 
141  TrajectoryTable m_activeTrajectories;
143 
149  bool m_enable;
153  };
154 
156 
158 
160 
162 
164 }
165 
166 #endif /* AGXOSG_PARTICLE_SYSTEMDRAWABLE_H */
agx::UInt getNumTrajectoryPositions() const
Get the number of positions used in the trajectories.
#define AGXOSG_EXPORT
agx::Vector< TrajectoryData > m_destroyedTrajectories
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
virtual bool isSameKindAs(const osg::Object *obj) const
agxSDK::Simulation::RigidBodyEvent::CallbackType m_removeRigidBodyCallback
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
void setDefaultTrajectoryColor(const agx::Vec4f &color)
Set default color of trajectories.
uint32_t UInt
Definition: Integer.h:34
agxSDK::Simulation::RigidBodyEvent::CallbackType m_addRigidBodyCallback
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
UInt32 Index
Definition: Integer.h:52
Callback2< T1, T2 > CallbackType
Definition: Event.h:37
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
virtual osg::Object * clone(const osg::CopyOp &) const
double Real
Definition: Real.h:42
Class that represents a linear scalar color map that converts a scalar interval to a specified color ...
Inheritance with partial specialization due to bug with ref_ptr containers.