AGXDynamics  2.31.1.0
RigidBodyEmitter.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 {
34 
37 
42  {
43  private:
44  struct RigidBodyEmitterInternalData : public agx::ICloneable
45  {
46  enum EState
47  {
48  CREATED_BY_RIGIDBODYEMITTER = 1 << 0
49  };
50  typedef agx::BitState< EState, agx::Int32 > State;
51 
52  RigidBodyEmitterInternalData() : state() {}
53 
54  State state;
55  protected:
56  virtual ~RigidBodyEmitterInternalData() {}
57 
58  private:
59  virtual agx::ICloneableRef clone(agx::ICloneable* child) override
60  {
61  if (child == nullptr)
62  child = new RigidBodyEmitterInternalData();
63 
64  child->as<RigidBodyEmitterInternalData>()->state = this->state;
65 
66  return agx::ICloneableRef(child);
67  }
68  };
69  public:
70 
72  Event emitEvent;
73 
74  AGX_DECLARE_POINTER_TYPES(DistributionModel);
75 
76  public:
77 
81  RigidBodyEmitter(Quantity quantity = QUANTITY_COUNT);
82 
83  static agx::RigidBodyRefVector spawnBodiesInBound(const agx::Bound3& bound, agx::Emitter::DistributionTable* sourceTable, const agx::Vec3& spacing, agx::Real jitterfactor = agx::Real(0));
84 
85  static bool rigidBodyIsEmitted(const agx::RigidBody * body);
86 
87  static void setRigidBodyIsEmitted(agx::RigidBody * body, bool isEmitted);
88 
90 
91  static void storePersistentData(const agx::RigidBody* rb, agxStream::OutputArchive& out);
92 
93  static void restorePersistentData(agx::RigidBody* rb, agxStream::InputArchive& in);
94 
96 
97  private:
98  static RigidBodyEmitterInternalData* getRigidBodyEmitterData(const agx::RigidBody* obj);
99 
100  static RigidBodyEmitterInternalData* getOrCreateRigidBodyEmitterData(agx::RigidBody* obj);
101 
103 
104  protected:
105 
107  virtual ~RigidBodyEmitter();
108 
109  virtual void emitBody(const Vec3& position, const Vec3& velocity, Emitter::DistributionModel *model) override;
110  virtual bool preEmit() override;
111  virtual void postEmit() override;
112 
113 
114  private:
115  // Creates and initializes the parameters.
116  void init();
117 
118 
119 
120  private:
121  agxSDK::Simulation *m_simulation;
122  };
123 
124  class AGXPHYSICS_EXPORT RigidBodyEmitter::DistributionModel : public Emitter::DistributionModel
125  {
126  public:
127  DistributionModel();
128  DistributionModel(agx::RigidBody *bodyTemplate, agx::Real probabilityWeight);
129 
133  // void setBodyTemplate(agx::RigidBody *bodyTemplate);
134 
138  agx::RigidBody *getBodyTemplate();
139 
141 
142  AGXSTREAM_DECLARE_SERIALIZABLE(agx::RigidBodyEmitter::DistributionModel);
143 
145 
146  protected:
147  virtual ~DistributionModel();
148  virtual agx::Real calculateVolume() override;
149  virtual agx::Real calculateMass() override;
150 
151  private:
152  agx::RigidBodyRef m_bodyTemplate;
153  };
154 }
155 
156 #endif
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
void AGXPHYSICS_EXPORT init()
Initialize agx.
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...
friend class DistributionTable
Definition: Emitter.h:278
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agx::ref_ptr< ICloneable > ICloneableRef
Definition: ICloneable.h:24
Event2< RigidBodyEmitter *, agx::RigidBody * > Event
AGX_DECLARE_VECTOR_TYPES(CollisionGroupFilter)
Spawns new bodys inside a given volume.
Definition: Emitter.h:37
T * as()
Subclass casting.
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
#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:206
Interface class for a cloneable reference counted object.
Definition: ICloneable.h:29
Spawns new bodys inside a given volume.
double Real
Definition: Real.h:42
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:102
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:101