AGXDynamics  2.35.0.2
ParticleTrajectoriesDrawable.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, is 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 */
agxOSG::ParticleTrajectoriesDrawable::clone
virtual osg::Object * clone(const osg::CopyOp &) const
Definition: ParticleTrajectoriesDrawable.h:71
agxOSG::ParticleTrajectoriesDrawable::m_destroyedParticlesTrajectories
agx::Vector< ParticleTrajectoryData > m_destroyedParticlesTrajectories
Definition: ParticleTrajectoriesDrawable.h:143
agx::Real
double Real
Definition: Real.h:42
agxOSG::ParticleTrajectoriesDrawable::className
virtual const char * className() const
Definition: ParticleTrajectoriesDrawable.h:74
agx::Vector< ParticleTrajectoryData >
Task.h
agxOSG::ParticleTrajectoriesDrawable::m_particleSystem
agx::ParticleSystemObserver m_particleSystem
Definition: ParticleTrajectoriesDrawable.h:140
agxOSG::ParticleTrajectoriesDrawable::m_countBuffer
agxData::BufferRef m_countBuffer
Definition: ParticleTrajectoriesDrawable.h:148
agxOSG::ParticleTrajectoriesDrawable
Definition: ParticleTrajectoriesDrawable.h:34
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
ParticleSystem.h
agx::observer_ptr< ParticleSystem >
agxOSG::ParticleTrajectoriesDrawable::getParticleSystem
agx::ParticleSystem * getParticleSystem()
Definition: ParticleTrajectoriesDrawable.h:157
agxOSG::ParticleTrajectoriesDrawable::getEnable
bool getEnable() const
Definition: ParticleTrajectoriesDrawable.h:159
agxData::Array
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agxOSG::ParticleTrajectoriesDrawable::m_colorBuffer
agxData::BufferRef m_colorBuffer
Definition: ParticleTrajectoriesDrawable.h:147
agx::Physics::ParticlePtr
Pointer to a entity instance of type Physics.Particle.
Definition: ParticleEntity.h:292
agx::ParticleSystem
A basic particle system that contains all the storages and buffers required for basic operation and a...
Definition: ParticleSystem.h:67
agx::ref_ptr< TaskGroup >
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
PushDisableWarnings.h
agxOSG::ParticleTrajectoriesDrawable::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: ParticleTrajectoriesDrawable.h:72
agx::Index
UInt32 Index
Definition: Integer.h:52
agxOSG::ParticleTrajectoriesDrawable::m_firstsBuffer
agxData::BufferRef m_firstsBuffer
Definition: ParticleTrajectoriesDrawable.h:149
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:871
observer_ptr.h
agxOSG::ParticleTrajectoriesDrawable::m_sampling
agx::Real m_sampling
Definition: ParticleTrajectoriesDrawable.h:152
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agxOSG::ParticleTrajectoriesDrawable::m_enable
bool m_enable
Definition: ParticleTrajectoriesDrawable.h:151
agxOSG::ParticleTrajectoriesDrawable::libraryName
virtual const char * libraryName() const
Definition: ParticleTrajectoriesDrawable.h:73
agxOSG::ParticleTrajectoriesDrawable::m_renderTask
agx::TaskGroupRef m_renderTask
Definition: ParticleTrajectoriesDrawable.h:141
export.h
agxOSG::ParticleTrajectoriesDrawable::getSampling
agx::Real getSampling() const
Definition: ParticleTrajectoriesDrawable.h:161
agxOSG::ParticleTrajectoriesDrawable::m_activeParticleTrajectories
TrajectoryTable m_activeParticleTrajectories
Definition: ParticleTrajectoriesDrawable.h:144
agxOSG::ParticleTrajectoriesDrawable::m_verticesBuffer
agxData::BufferRef m_verticesBuffer
Definition: ParticleTrajectoriesDrawable.h:146
agxOSG::ParticleTrajectoriesDrawable::getNumTrajectoryPositions
agx::UInt getNumTrajectoryPositions() const
Get the number of positions used in the trajectories.
Definition: ParticleTrajectoriesDrawable.h:163
agxOSG::ParticleTrajectoriesDrawable::m_particleStorageListener
ParticleStorageListener m_particleStorageListener
Definition: ParticleTrajectoriesDrawable.h:154
agxData::EntityPtr
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:51
agxOSG::ParticleTrajectoriesDrawable::cloneType
virtual osg::Object * cloneType() const
Definition: ParticleTrajectoriesDrawable.h:70
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxData::EntityRange
Definition: EntityPtr.h:247
AGXOSG_EXPORT
#define AGXOSG_EXPORT
agxOSG::ParticleTrajectoriesDrawable::m_maxPosCounts
agx::UInt m_maxPosCounts
Definition: ParticleTrajectoriesDrawable.h:150
PopDisableWarnings.h