AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
ParticleTrajectoriesDrawable.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
32namespace 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
90
93
95 agx::UInt getNumTrajectoryPositions() const;
96
99
102
105
107
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:
125
127
129
131
132 void sample(agx::Index index);
133
135
137 // Variables
139 protected:
142
145
153
154 ParticleStorageListener m_particleStorageListener;
155 };
156
158
160
162
164}
165
166#endif /* AGXOSG_PARTICLE_SYSTEMDRAWABLE_H */
#define AGXOSG_EXPORT
Type-specific Array used for fast access into the data held by a Buffer.
Definition: Array.h:107
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:52
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
bool particleIsRendered(agx::Physics::ParticlePtr &ptr)
virtual osg::BoundingBox computeBound() const
Compute the bounding box around Drawables's geometry.
virtual bool isSameKindAs(const osg::Object *obj) const
void removeParticleTrajectoryFromId(agx::Index particleId)
Remove the current stored trajectory from the drawable for a particle with given id.
ParticleTrajectoriesDrawable(agx::ParticleSystem *particleSystem)
agx::UInt getNumTrajectoryPositions() const
Get the number of positions used in the trajectories.
void handleCreationEvent(agx::Index index)
void setNumTrajectoryPositions(agx::UInt num)
Set the number of positions used in the trajectories.
void handleDestructionEvent(agx::Index index)
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
The actual draw method for the particle system.
void createParticleTrajectoryFromId(agx::Index particleId)
virtual osg::Object * clone(const osg::CopyOp &) const
agx::Vector< ParticleTrajectoryData > m_destroyedParticlesTrajectories
void updateParticleTrajectories()
Update the trajectory structures.
void resetTrajectories()
Reset trajectories.
void popLatestPositions()
Pops latest positions in all trajectories. Useful when stepping backwards in a journal.
void setSampling(agx::Real sampling, bool doResample=true)
Inheritance with partial specialization due to bug with ref_ptr containers.
A basic particle system that contains all the storages and buffers required for basic operation and a...
Pointer to a entity instance of type Physics.Particle.
Templated vector class.
Definition: agx/Vector.h:53
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
uint64_t UInt
Definition: Integer.h:27
double Real
Definition: Real.h:41
UInt32 Index
Definition: Integer.h:44