AGX Dynamics  2.37.2.0
SoilParticleSimulation.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 #ifndef AGXMODEL_SOIL_PARTICLE_MERGER_H
18 #define AGXMODEL_SOIL_PARTICLE_MERGER_H
19 
20 #define USE_SOIL_PARTICLE_SIMULATION 0
21 
22 #if defined(USE_SOIL_PARTICLE_SIMULATION) && USE_SOIL_PARTICLE_SIMULATION == 1
23 
24 #include <agxModel/export.h>
26 
27 namespace agxModel
28 {
29 
30  typedef agx::HashTable <SoilParticle*,SoilParticlePtrVector> SoilParticlePtrSoilParticlePtrVectorTable;
31 
32  typedef agx::HashTable< agxCollide::Geometry*, agxCollide::GeometryRef > GeometryPtrGeometryRefTable;
33 
34  class AGXMODEL_EXPORT SoilParticleSimulation : public agxSDK::Simulation
35  {
36  public:
37 
38  SoilParticleSimulation();
39 
40  void addSeed(agx::RigidBody *seed);
41 
42  void addSeed(agxCollide::Geometry *seed);
43 
44  void notifyContact( agxCollide::GeometryContact* geometryContact );
45 
46  void prePrepare();
47 
48  void prepareForStepForward( agxSDK::Simulation* originalSimulation );
49 
50  void updatePositionsAfterOrdinarySolve();
51 
52  void postCleanUp( agxSDK::Simulation* originalSimulation );
53 
54  bool isActive( ) { return !m_geometriesToStaticGeometriesTable.empty(); }
55 
56  void updateTransforms( )
57  {
58  GeometryPtrGeometryRefTable::iterator it = m_geometriesToStaticGeometriesTable.begin();
59 
60  while ( it != m_geometriesToStaticGeometriesTable.end() )
61  {
62  updateTransform((*it).first);
63  ++it;
64  }
65  }
66 
67  protected:
68  friend class SoilParticle;
69 
70  private:
71 
72  void addChild( SoilParticle* parent, SoilParticle* child );
73 
74  void mergeParentToParent( SoilParticle* parent1, SoilParticle* parent2, SoilParticlePtrVector& parentVector );
75 
76  void mergeToParent( SoilParticle* parent, SoilParticle* child );
77 
78  void updateTransform( agxCollide::Geometry* geometry );
79 
80  void restoreParticles();
81 
82  agx::RigidBody* replaceParticle( SoilParticle* particle );
83 
84  AGX_FORCE_INLINE void updateTransform( GeometryPtrGeometryRefTable::iterator it )
85  {
86  if ( it == m_geometriesToStaticGeometriesTable.end() )
87  return;
88 
89  (*it).second->setTransform( (*it).first->getTransform() );
90  }
91 
92  AGX_FORCE_INLINE void insertInTable( SoilParticlePtrVector& children, SoilParticle* child )
93  {
94 #if TERRAIN_USE_PARTICLE_SYSTEM == 0
95  agxAssert(!children.contains(child));
96  children.push_back(child);
97 #endif
98  }
99 
101  GeometryPtrGeometryRefTable m_geometriesToStaticGeometriesTable;
102  agxCollide::GeometryRefVector m_geometryReferences;
103  SoilParticlePtrSoilParticlePtrVectorTable m_parents;
104  SoilParticlePtrSoilParticlePtrVectorTable m_seedParents;
105  agx::RigidBodyRefVector m_createdBodies;
106  agx::RigidBodyRefVector m_particlePool;
107  agx::RigidBodyRefVector m_usedParticles;
108  agx::RigidBodyRefVector m_disabledParticles;
109  agxCollide::GeometryPtrVector m_particleGeometries;
110  };
111 
112  typedef agx::ref_ptr<SoilParticleSimulation> SoilParticleSimulationRef;
113 
114 }
115 
116 #endif //USE_SOIL_PARTICLE_SIMULATION
117 
118 #endif
agx::Vector< SoilParticle * > SoilParticlePtrVector
A contact between two geometries.
Definition: Contacts.h:270
#define AGX_FORCE_INLINE
Definition: Object.h:59
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Templated vector class.
Definition: Vector.h:52
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
#define agxAssert(expr)
Definition: debug.h:143
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
#define AGXMODEL_EXPORT
Inheritance with partial specialization due to bug with ref_ptr containers.