AGX Dynamics  2.35.0.1
SoilParticleAggregate.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 #pragma once
18 
21 #include <agx/RigidBody.h>
22 #include <agx/LockJoint.h>
23 #include <agx/Plane.h>
24 
25 namespace agxTerrain
26 {
27  class Shovel;
28  class TerrainToolCollection;
29  class ActiveZone;
30  class TerrainMaterial;
31 
34 
37 
39  {
40  public:
45 
52  const agx::RigidBody* getInnerBody() const;
53 
60  const agx::RigidBody* getWedgeBody() const;
61 
69 
77 
85  const agx::LockJoint* getLockJoint() const;
86 
92  void setMaterial( agx::Material* material );
93 
98 
103 
108 
113 
119 
125 
130 
131  public:
137  void addNotification( agxSDK::Simulation* simulation, Terrain* terrain );
138 
144  void removeNotification( agxSDK::Simulation* simulation, Terrain* terrain );
145 
151  void onPreCollide( TerrainToolCollection* collection );
152 
158  void onPre( TerrainToolCollection* collection, ActiveZone* activeZone );
159 
165  void onPost( TerrainToolCollection* collection );
166 
172  void onEnableChange( bool enable );
173 
174  static agx::Plane transformPlaneToWorld(const agx::Frame* localFrame, const agx::Plane& localPlane);
175 
176  protected:
181 
186 
191 
192  private:
193  agx::HashSet<agx::Vec3i> calculateWedgeVoxels(TerrainToolCollection* collection, ActiveZone* activeZone);
194 
195  agx::HashSet<agx::Vec3i> filterWedgeVoxelsSplittingPlane(TerrainToolCollection* collection,
196  ActiveZone* activeZone,
197  const agx::HashSet<agx::Vec3i>& wedgeVoxels);
198 
199  void updateDynamicProperties(const SoilParticlePtrVector& soilParticles,
200  agx::RigidBody* rb,
201  agx::HashSet<agx::Vec3i>& voxels,
202  TerrainToolCollection* collection);
203 
204  void synchronizeLockJoint(TerrainToolCollection* collection);
205 
206  void computePointsInsideActiveZone(TerrainToolCollection* collection, ActiveZone* activeZone);
207 
208  void sortParticlesBySeparatingPlane(Terrain* terrain,
209  ActiveZone* activeZone,
210  SoilParticlePtrVector& innerParticles,
211  SoilParticlePtrVector& wedgeParticles);
212 
213  void computeParticlesInInnerShape(PrimaryActiveZone* activeZone, SoilParticlePtrVector& innerParticles);
214 
215  SoilParticlePtrVector computeParticlesInWedgeShape(ActiveZone* activeZone, SoilParticlePtrVector& wedgeParticleCandidates);
216 
217  void computeParticlesAboveShovel(TerrainToolCollection* collection, agx::Vec3 up, SoilParticlePtrVector& wedgeParticles);
218 
219  bool isPointAbovePlane(const agx::Plane& plane, const agx::Vec3& point) const;
220 
221  bool isSphereIntersectingPlane(const agx::Plane& plane, const agx::Vec3& point, agx::Real radius) const;
222 
223  void updateLockJointComplianceFromBulkMaterial(const TerrainToolCollection* collection,
224  agx::LockJoint* lockJoint);
225 
226  private:
227  agx::RigidBodyRef m_innerBody;
228  agx::RigidBodyRef m_wedgeBody;
229  agx::Vec3 m_innerBodyMomentum;
230  agx::Vec3 m_wedgeBodyMomentum;
231  agx::Vec3 m_innerBodyAngularMomentum;
232  agx::Vec3 m_wedgeBodyAngularMomentum;
233 
234  SoilParticlePtrVector m_innerParticles;
235  SoilParticlePtrVector m_wedgeParticles;
236 
237  agx::LockJointRef m_lock;
238  };
239 
240 
241 
242  inline bool SoilParticleAggregate::isPointAbovePlane(const agx::Plane& plane, const agx::Vec3& point) const
243  {
244  return plane.signedDistanceToPoint(point) > 0;
245  }
246 
247 
248 
249  inline bool SoilParticleAggregate::isSphereIntersectingPlane(const agx::Plane& plane, const agx::Vec3& point, agx::Real radius) const
250  {
251  return std::abs(plane.signedDistanceToPoint(point)) < radius;
252  }
253 
254 
255 
256 
257 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXTERRAIN_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
agxCollide::Geometry * _getWedgeGeometry() const
Internal mutable geometry accessor.
const agx::RigidBody * getInnerBody() const
void onPre(TerrainToolCollection *collection, ActiveZone *activeZone)
void onPost(TerrainToolCollection *collection)
void addNotification(agxSDK::Simulation *simulation, Terrain *terrain)
agx::Real getRigidBodyMassSum() const
agx::Material * getMaterial() const
void setMaterial(agx::Material *material)
Assign material used for the contact between the shovel and this soil particle aggregate (the soil pa...
const agxCollide::Geometry * getWedgeGeometry() const
const SoilParticlePtrVector & getInnerBodyParticles() const
const SoilParticlePtrVector & getWedgeBodyParticles() const
void setLockRotationalCompliance(agx::Real compliance)
Set the compliance of the lock joint in the soil aggregate in rotational degrees of freedom.
void onPreCollide(TerrainToolCollection *collection)
void removeNotification(agxSDK::Simulation *simulation, Terrain *terrain)
virtual ~SoilParticleAggregate()
Reference counted object - protected destructor.
const agxCollide::Geometry * getInnerGeometry() const
const agx::LockJoint * getLockJoint() const
SoilParticleAggregate()
Construct given shovel.
static agx::Plane transformPlaneToWorld(const agx::Frame *localFrame, const agx::Plane &localPlane)
const agx::RigidBody * getWedgeBody() const
agxCollide::Geometry * _getInnerGeometry() const
Internal mutable geometry accessor.
void setLockTranslationalCompliance(agx::Real compliance)
Set the compliance of the lock joint in the soil aggregate in translational degrees of freedom.
Collection of terrain tool (currently Shovel) related objects which are terrain instance specific.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition: LockJoint.h:29
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:388
Pointer to a entity instance of type Physics.GranularBody.
Class representing the mathematical concept of a plane, also called a half- space.
Definition: agx/Plane.h:32
T signedDistanceToPoint(const agx::Vec3T< T > &point) const
Calculates the distance from the plane to a point.
Definition: agx/Plane.h:209
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Vector containing 'raw' data.
Definition: agx/Vector.h:246
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:60
agx::Physics::GranularBodyPtrVector SoilParticlePtrVector
agx::Physics::GranularBodyPtr SoilParticlePtr
double Real
Definition: Real.h:42