AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Emitter.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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
18#pragma once
19
23#include <agx/Task.h>
24#include <agxCollide/Geometry.h>
25#include <agxCollide/Space.h>
26#include <agx/Random.h>
27#include <agx/SetVector.h>
28#include <agx/BitState.h>
29
30namespace agxSDK {
31 class Simulation;
32}
33
34namespace agx
35{
39
40
45 {
46 public:
48 {
51 QUANTITY_MASS
52 };
53
54 AGX_DECLARE_POINTER_TYPES(DistributionModel);
55 AGX_DECLARE_VECTOR_TYPES(DistributionModel);
56 AGX_DECLARE_POINTER_TYPES(DistributionTable);
58
59 public:
60
64 Emitter(Quantity quantity = QUANTITY_COUNT);
65
70 agxCollide::Geometry* getGeometry();
71
72
79 void setQuantity(Quantity quantity);
80
85
92 void setRate(Real rate);
93
97 Real getRate() const;
98
103 void setVelocity(const Vec3& velocity);
104
108 const Vec3& getVelocity() const;
109
113 void setSeed(const agx::UInt32 seed);
114
118 void setDistributionTable(DistributionTable *table);
119
126 void setUseFixedPosition(bool enable);
127
132
139 void setUseFixedRotation( bool enable );
140
145
153 void setFixedPositionOffset( const agx::Vec3& fixedPositionOffset );
154
161 void setFixedRotationOffset( const agx::Quat& fixedRotationOffset );
162
167
172
176 DistributionTable *getDistributionTable();
177 const DistributionTable *getDistributionTable() const;
178
183
191
196
201
211 void addCollisionGroup(const agx::Name& name);
212
219
226 bool hasCollisionGroup(agx::UInt32 id) const;
227 bool hasCollisionGroup(agx::Name id) const;
228
232 agx::Physics::CollisionGroupSetPtr getCollisionGroupSet() const;
233
240
245
255
261
265 void setName(const agx::String& name);
266
268
270
271 Physics::EmitterPtr getEntity() const;
272
273 virtual void transfer(agxSDK::Simulation *simulation);
274 void setSpace(agxCollide::Space* space);
275
277 static agxStream::Serializable* create() { return nullptr; }
278 static agxStream::Serializable* create(agxStream::InputArchive&) { return nullptr; }
279
281
282 protected:
283 virtual void run() override;
284
286 virtual ~Emitter();
287
288 virtual void emitBody(const Vec3& position,
289 const Quat& rotation,
290 const Vec3& velocity,
291 Emitter::DistributionModel *model) = 0;
292 virtual bool preEmit() = 0;
293 virtual void postEmit() = 0;
294 virtual Real getDefaultElementQuantity(Quantity quantity);
295
296 virtual void store( agxStream::OutputArchive& out ) const override;
297 virtual void restore( agxStream::InputArchive& in ) override;
298
299 void setEmittedQuantity(agx::Real quantity);
300 void setEmittedCount(agx::UInt emittedCount);
301
302 // Generates a random number from the generator in the emitter
303 agx::Real generateRandomNumber();
304
305 // State flags for emitter
307 {
308 OVERRIDE_RENDER_SETTINGS = 1 << 0,
309 SHOULD_RENDER_EMITTED_OBJECTS = 1 << 1,
310 FIXED_POSITION = 1 << 2,
311 FIXED_ROTATION = 1 << 3
312 };
313 using Flags = agx::BitState<StateFlags, agx::UInt32>;
314
315 private:
316 // Creates and initializes the parameters.
317 void init();
318
319 // Few helper functions for randomly selecting points in space.
320 Vec3 randomPointInBox(const agxCollide::BoundingAABB* bound);
321 Vec3 randomPointInSphere(agx::Real maxRadius);
322 Vec3 randomPointInGeometry(agxCollide::Geometry* geometry, agxCollide::Geometry* proxySphere);
323
324 void setCollisionGroupSet(agx::Physics::CollisionGroupSetPtr set);
325
326 protected:
328
334
335 // Random number generator for body emitter
337
340
344 };
345
346
347 class AGXPHYSICS_EXPORT Emitter::DistributionModel : public Referenced, public virtual agxStream::Serializable
348 {
349 public:
351 DistributionModel(agx::Real probabilityWeight);
352
357
362
363
368
371
373
375 static agxStream::Serializable* create() { return nullptr; }
376 static agxStream::Serializable* create(agxStream::InputArchive&) { return nullptr; }
377
379
380 protected:
381 virtual ~DistributionModel();
382 virtual agx::Real calculateVolume() = 0;
383 virtual agx::Real calculateMass() = 0;
384 virtual void store( agxStream::OutputArchive& out ) const override;
385 virtual void restore( agxStream::InputArchive& in ) override;
386
387 private:
388 friend class DistributionTable;
389 void setDistribution(DistributionTable *distribution);
390
391 static bool rangeCompare(DistributionModel *model, agx::Real value);
392
393 protected:
394 DistributionTable *m_distribution;
395 agx::Real m_probabilityWeight;
396 agx::UInt m_activationCount;
397 agx::RangeReal m_range;
398 agx::Real m_volume;
399 agx::Real m_mass;
400 };
401
402 class AGXPHYSICS_EXPORT Emitter::DistributionTable : public Referenced, public virtual agxStream::Serializable
403 {
404 public:
405 DistributionTable(Quantity quantity = QUANTITY_COUNT);
406
410 void addModel(DistributionModel *model);
411
416
420 DistributionModel *getRandomModel();
421
426
431
436
441
443
444 AGXSTREAM_DECLARE_SERIALIZABLE(agx::Emitter::DistributionTable);
445
447
448 protected:
449 virtual ~DistributionTable();
450
451 private:
452 friend class DistributionModel;
453 void rebuildProbabilityTable();
454
455 agx::Real getQuantifiedProbabilityWeight(DistributionModel *model) const;
456 agx::Real calculateTotalQuantifiedWeight() const;
457
458
459 private:
460 Quantity m_quantity;
462 UniformRealGenerator m_randomGenerator;
463 agx::UInt32 m_seed;
464 bool m_needRebuild;
465 };
466
467 /* Implementation */
468 AGX_FORCE_INLINE agxCollide::Geometry* agx::Emitter::getGeometry() { return m_geometry; }
469
470 inline agx::Physics::CollisionGroupSetPtr agx::Emitter::getCollisionGroupSet() const { return m_entity.collisionGroupSet(); }
471
473 {
474 return agxCollide::CollisionGroupManager::hasGroup(getCollisionGroupSet(), id);
475 }
476
478 {
479 return agxCollide::CollisionGroupManager::hasGroup(getCollisionGroupSet(), id);
480 }
481
482 AGX_FORCE_INLINE void agx::Emitter::setCollisionGroupSet(agx::Physics::CollisionGroupSetPtr set)
483 {
484 m_entity.collisionGroupSet() = set;
485 }
486}
487
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
Axis aligned bounding box implementation.
static bool hasGroup(agx::Physics::CollisionGroupSetPtr set, agx::UInt32 groupId)
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
Class for reading a binary stream of serialized data.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Spawns new bodys inside a given volume.
Definition Emitter.h:45
void setFixedPositionOffset(const agx::Vec3 &fixedPositionOffset)
Set the fixed position offset of the objects created from the emitter.
void addModel(DistributionModel *model)
Add a particle model.
agx::UInt getActivationCount() const
void setSeed(const agx::UInt32 seed)
Set the seed for the random number generator of the emitter.
bool getEnableOverrideRenderSettings() const
bool getUseFixedPosition() const
void setGeometry(agxCollide::Geometry *geometry)
Set the volume that bodies will be spawned inside.
void addCollisionGroup(agx::UInt32 id)
Add the specified id to a vector of group id, this will make a bodies emitted from this emitter part ...
DistributionTable * getDistributionTable()
agx::Physics::CollisionGroupSetPtr getCollisionGroupSet() const
Definition Emitter.h:470
agx::Real getVolume() const
agx::Real calculateTotalWeight() const
agx::Real getMaximumEmittedQuantity() const
Get the maximum amount of quantity that this emitter is allowed to emit.
Quantity getQuantity() const
ScalarParameterRef m_timestep
Definition Emitter.h:333
void setMaximumEmittedQuantity(const agx::Real max)
Sets the maximum amount of objects that this emitter is allowed to emit.
void setUseFixedRotation(bool enable)
Set if a fixed rotation should be used on objects created from this emitter.
void setRate(Real rate)
Set the rate in which the emitter emits objects, measured in the specified quantity QUANTITY_COUNT - ...
Real m_rest
Definition Emitter.h:342
@ QUANTITY_COUNT
Definition Emitter.h:49
@ QUANTITY_VOLUME
Definition Emitter.h:50
agxCollide::GeometryRef m_proxySphere
Definition Emitter.h:331
agxCollide::GeometryRef m_geometry
Definition Emitter.h:330
void setVelocity(const Vec3 &velocity)
Set the initial velocity for the bodys when spawned, in local geometry coordinates.
const DistributionModelRefVector & getModels() const
void removeCollisionGroup(const agx::Name &name)
Quantity m_quantity
Definition Emitter.h:341
agx::Real getEmittedQuantity() const
Returns the quantity amount that this emitter has emitted.
agx::UInt getNumEmitted() const
void setProbabilityWeight(agx::Real weight)
Set the random probability weight.
agx::Quat m_fixedRotationOffset
Definition Emitter.h:339
void setUseFixedPosition(bool enable)
Set if fixed position should be used on objects created from this emitter.
bool getUseFixedRotation() const
const DistributionTable * getDistributionTable() const
void removeCollisionGroup(agx::UInt32 id)
Remove a group id from the vector of group ids.
void setSeed(agx::UInt32 seed)
Set the seed of the random number generator in the distribution table.
Physics::EmitterPtr m_entity
Definition Emitter.h:327
agx::Quat getFixedRotationOffset() const
agx::Real getMass() const
Emitter(Quantity quantity=QUANTITY_COUNT)
Create an emitter.
void setEnableOverrideRenderSettings(bool enable)
Sets whenever the render settings of emitted objects should be overriden.
void setProbabilityQuantity(Quantity quantity)
Set The probability quantity.
const Vec3 & getVelocity() const
void addCollisionGroup(const agx::Name &name)
void setQuantity(Quantity quantity)
Set the emitting quantity QUANTITY_COUNT - number of emitted objects QUANTITY_VOLUME - volume of emit...
void setDistributionTable(DistributionTable *table)
Set a distribution table to be used for body attributes.
bool hasCollisionGroup(agx::UInt32 id) const
This is performing a linear search among the group id for this Emitter.
Definition Emitter.h:472
UniformRealGenerator m_generator
Definition Emitter.h:336
DistributionModel * getRandomModel()
bool getEnableRenderEmittedObjects() const
DistributionTable(Quantity quantity=QUANTITY_COUNT)
agx::Vec3 m_fixedPositionOffset
Definition Emitter.h:338
agx::Real getProbabilityWeight() const
void setFixedRotationOffset(const agx::Quat &fixedRotationOffset)
Set the fixed rotation offset of the objects created from the emitter.
void setEnableRenderEmittedObjects(bool enable)
Sets whenever the emitted objects should be rendered or not, if possible.
agxCollide::SpaceRef m_space
Definition Emitter.h:332
Real getRate() const
void setName(const agx::String &name)
Set emitter name.
DistributionModel(agx::Real probabilityWeight)
agx::Vec3 getFixedPositionOffset() const
agx::BitState< StateFlags, agx::UInt32 > Flags
Definition Emitter.h:313
DistributionTableRef m_distributionTable
Definition Emitter.h:329
Quantity getProbabilityQuantity() const
agx::String getName() const
Flags m_state
Definition Emitter.h:343
Representation of a name string.
Definition Name.h:33
Pointer to a entity instance of type Physics.CollisionGroupSet.
Pointer to a entity instance of type Physics.Emitter.
Base class providing referencing counted objects.
Definition Referenced.h:120
SerialTask.
Definition Task.h:470
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition SetVector.h:38
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define CALLABLE
Definition macros.h:72
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
#define AGX_FORCE_INLINE
Definition macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
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...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition Integer.h:32
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
agx::SetVector< ref_ptr< Emitter > > EmitterRefSetVector
Definition Emitter.h:38