AGX Dynamics  2.35.0.1
RigidBodyEmitter.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, 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 
18 #ifndef AGX_RIGIDBODY_EMITTER_H
19 #define AGX_RIGIDBODY_EMITTER_H
20 
21 #include <agx/Emitter.h>
22 #include <agx/InternalData.h>
23 #include <agx/BitState.h>
24 #include <agx/ICloneable.h>
25 
26 namespace agxSDK
27 {
28  class Simulation;
29 }
30 
31 
32 namespace agx
33 {
36 
43  {
44  private:
49  struct RigidBodyEmitterInternalData : public agx::ICloneable
50  {
51  enum EState
52  {
53  CREATED_BY_RIGIDBODYEMITTER = 1 << 0,
54  CREATED_BY_SNAPSHOT_LOADING = 1 << 1,
55  IS_BODYMODEL_TEMPLATE = 1 << 2
56  };
57  typedef agx::BitState< EState, agx::Int32 > State;
58 
59  RigidBodyEmitterInternalData() : state() {}
60 
61  State state;
62  protected:
63  virtual ~RigidBodyEmitterInternalData() {}
64 
65  private:
66  virtual agx::ICloneableRef clone(agx::ICloneable* child) override
67  {
68  if (child == nullptr)
69  child = new RigidBodyEmitterInternalData();
70 
71  child->as<RigidBodyEmitterInternalData>()->state = this->state;
72 
73  return agx::ICloneableRef(child);
74  }
75  };
76  public:
77 
80 
81  AGX_DECLARE_POINTER_TYPES(DistributionModel);
82 
83  public:
84 
89  RigidBodyEmitter(Quantity quantity = QUANTITY_COUNT);
90 
100  const agx::Vec3& spacing,
101  agx::Real jitterfactor = agx::Real(0));
102 
106  static bool rigidBodyIsEmitted( const agx::RigidBody * body );
107 
111  static bool rigidBodyIsLoaded( const agx::RigidBody * body );
112 
118  static bool rigidBodyIsTemplate(const agx::RigidBody* body);
119 
126  static void setRigidBodyIsEmitted( agx::RigidBody * body, bool isEmitted );
127 
134  static void setRigidBodyIsLoaded( agx::RigidBody * body, bool isLoaded );
135 
146  static void setRigidBodyIsTemplate(agx::RigidBody* body, bool isTemplate);
147 
153 
155 
156  static void storePersistentData(const agx::RigidBody* rb, agxStream::OutputArchive& out);
157 
158  static void restorePersistentData(agx::RigidBody* rb, agxStream::InputArchive& in);
159 
161 
162  private:
163  static RigidBodyEmitterInternalData* getRigidBodyEmitterData(const agx::RigidBody* obj);
164 
165  static RigidBodyEmitterInternalData* getOrCreateRigidBodyEmitterData(agx::RigidBody* obj);
166 
168 
169  protected:
170 
172  virtual ~RigidBodyEmitter();
173 
174  virtual void emitBody(const Vec3& position, const Vec3& velocity, Emitter::DistributionModel *model) override;
175  virtual bool preEmit() override;
176  virtual void postEmit() override;
177 
178  virtual void transfer(agxSDK::Simulation *simulation) override;
179 
180  private:
181  // Creates and initializes the parameters.
182  void init();
183 
184 
185 
186  private:
187  agxSDK::Simulation *m_simulation;
188  };
189 
193  class AGXPHYSICS_EXPORT RigidBodyEmitter::DistributionModel : public Emitter::DistributionModel
194  {
195  public:
200 
210  DistributionModel(agx::RigidBody *bodyTemplate, agx::Real probabilityWeight);
211 
216 
218 
220 
222 
223  protected:
224  virtual ~DistributionModel();
225  virtual agx::Real calculateVolume() override;
226  virtual agx::Real calculateMass() override;
227 
228  private:
229  agx::RigidBodyRef m_bodyTemplate;
230  };
231 }
232 
233 #endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Spawns new bodys inside a given volume.
Definition: Emitter.h:45
friend class DistributionTable
Definition: Emitter.h:324
Interface class for a cloneable reference counted object.
Definition: ICloneable.h:30
T * as()
Subclass casting.
Spawns new Rigid Bodies inside a volume given to the Emitter.
static void setRigidBodyIsLoaded(agx::RigidBody *body, bool isLoaded)
Manually override setting that specifies if a RigidBody was loaded from an snapshot.
static void setRigidBodyIsEmitted(agx::RigidBody *body, bool isEmitted)
Manually override setting that specifies if a RigidBody was created from an Emitter.
static agx::RigidBodyPtrVector getEmittedBodiesInSimulation(agxSDK::Simulation *simulation)
static agx::RigidBodyRefVector spawnBodiesInBound(const agx::Bound3 &bound, agx::Emitter::DistributionTable *sourceTable, const agx::Vec3 &spacing, agx::Real jitterfactor=agx::Real(0))
Spawn Rigid Bodies inside a 3D bound based on a specified distribution table of rigid bodies.
Event2< RigidBodyEmitter *, agx::RigidBody * > Event
agx::RigidBody * getBodyTemplate()
DistributionModel(agx::RigidBody *bodyTemplate, agx::Real probabilityWeight)
Create a Rigid Body Distribution model for usage in the Emitter::DistributionTable class.
static bool rigidBodyIsLoaded(const agx::RigidBody *body)
static bool rigidBodyIsEmitted(const agx::RigidBody *body)
DistributionModel()
Default constructor.
static bool rigidBodyIsTemplate(const agx::RigidBody *body)
RigidBodyEmitter(Quantity quantity=QUANTITY_COUNT)
Default constructor for a RigidBodyEmitter.
static void setRigidBodyIsTemplate(agx::RigidBody *body, bool isTemplate)
Set state bit in the RigidBodyEmitterData for the specifed RigidBody that signals if it is used as a ...
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real
Definition: Real.h:42
void AGXPHYSICS_EXPORT init()
Initialize agx.
agx::ref_ptr< ICloneable > ICloneableRef
Definition: ICloneable.h:24