AGX Dynamics  2.37.3.2
ParticleTrajectoriesDrawable.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_PARTICLE_TRAJECTORIES_DRAWABLE_H
18 #define AGXOSG_PARTICLE_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 <agx/Task.h>
28 #include <agx/observer_ptr.h>
29 #include <agx/ParticleSystem.h>
30 
31 
32 namespace agxOSG
33 {
34  class AGXOSG_EXPORT ParticleTrajectoriesDrawable : public osg::Drawable
35  {
36  //typedef agx::Vec3Vector PositionBuffer;
37  //typedef agx::Vec4fVector ColorsBuffer;
38  typedef std::deque<agx::Vec3> PositionBuffer;
39  typedef std::deque<agx::Vec4f> ColorsBuffer;
40  typedef std::pair<PositionBuffer, ColorsBuffer> ParticleTrajectoryData;
41 
43 
44  class ParticleStorageListener : public agxData::EntityStorage::EventListener
45  {
46 
47  public:
48  ParticleStorageListener(ParticleTrajectoriesDrawable* psdraw);
49 
50  virtual void destroyCallback(agxData::EntityStorage* storage) override;
51  virtual void createInstanceCallback(agxData::EntityStorage* storage, agxData::EntityPtr instance) override;
52  virtual void createInstancesCallback(agxData::EntityStorage* storage, agxData::EntityRange range) override;
53  virtual void destroyInstanceCallback(agxData::EntityStorage* storage, agxData::EntityPtr instance) override;
54  virtual void destroyInstancesCallback(agxData::EntityStorage* storage, agxData::Array<agxData::EntityPtr> instances) override;
55  virtual void createInstancesCallback(agxData::EntityStorage* storage, agxData::Array<agxData::EntityPtr> instances) override;
56  virtual void destroyInstancesCallback(agxData::EntityStorage* storage, agxData::EntityRange instance) override;
57  virtual void permuteCallback(agxData::EntityStorage* storage, agxData::Array< agx::Index > permutation) override;
58 
60  // Variables
62  protected:
63  ParticleTrajectoriesDrawable * m_psDrawable;
64  };
65 
66  public:
68  // ParticleSystemDrawable( const ParticleSystemDrawable&c, const osg::CopyOp& copyOp );
69 
70  virtual osg::Object* cloneType() const { return new ParticleTrajectoriesDrawable(m_particleSystem.get()); }
71  virtual osg::Object* clone(const osg::CopyOp&) const { return new ParticleTrajectoriesDrawable(*this); }
72  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ParticleTrajectoriesDrawable *>(obj) != nullptr; }
73  virtual const char* libraryName() const { return "agxOSG"; }
74  virtual const char* className() const { return "ParticleTrajectoriesDrawable"; }
75 
76 
78 # if OSG_VERSION_GREATER_OR_EQUAL(3,4,0)
79  virtual osg::BoundingSphere computeBound() const;
80  virtual osg::BoundingBox computeBoundingBox() const;
81 #else
82  virtual osg::BoundingBox computeBound() const;
83 #endif
84 
86  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
87 
89  void updateParticleTrajectories();
90 
92  void setNumTrajectoryPositions(agx::UInt num);
93 
95  agx::UInt getNumTrajectoryPositions() const;
96 
98  void resetTrajectories();
99 
101  void popLatestPositions();
102 
104  void removeParticleTrajectoryFromId(agx::Index particleId);
105 
106  void createParticleTrajectoryFromId( agx::Index particleId );
107 
108  bool particleIsRendered( agx::Physics::ParticlePtr& ptr );
109 
110  void setEnable(bool enable);
111 
112  bool getEnable() const;
113 
114  // Amount of particles that should sampled in the tracing. 0 None ; 1 All
115  void setSampling(agx::Real sampling, bool doResample=true);
116 
117  agx::Real getSampling() const;
118 
119  agx::ParticleSystem * getParticleSystem();
120 
121  void resample();
122 
123  protected:
124  virtual ~ParticleTrajectoriesDrawable();
125 
126  void updateKernelBuffers();
127 
128  void handleCreationEvent(agx::Index index);
129 
130  void handleDestructionEvent(agx::Index index);
131 
132  void sample(agx::Index index);
133 
134  void popOldPositionsInDeadTrajectories();
135 
137  // Variables
139  protected:
142 
145 
151  bool m_enable;
153 
154  ParticleStorageListener m_particleStorageListener;
155  };
156 
158 
160 
162 
164 }
165 
166 #endif /* AGXOSG_PARTICLE_SYSTEMDRAWABLE_H */
#define AGXOSG_EXPORT
virtual bool isSameKindAs(const osg::Object *obj) const
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:51
agx::Vector< ParticleTrajectoryData > m_destroyedParticlesTrajectories
#define AGX_FORCE_INLINE
Definition: Object.h:59
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
A basic particle system that contains all the storages and buffers required for basic operation and a...
uint32_t UInt
Definition: Integer.h:34
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
UInt32 Index
Definition: Integer.h:52
agx::UInt getNumTrajectoryPositions() const
Get the number of positions used in the trajectories.
virtual osg::Object * clone(const osg::CopyOp &) const
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
Pointer to a entity instance of type Physics.Particle.