AGXDynamics  2.31.1.0
SoilParticleAggregate.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 #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;
31 
34 
37 
39  {
40  public:
45 
52  const agx::RigidBody* getInnerBody() const;
53 
60  const agx::RigidBody* getWedgeBody() const;
61 
68  const agxCollide::Geometry* getInnerGeometry() const;
69 
76  const agxCollide::Geometry* getWedgeGeometry() const;
77 
85  const agx::LockJoint* getLockJoint() const;
86 
92  void setMaterial( agx::Material* material );
93 
97  agx::Material* getMaterial() const;
98 
102  agx::Real getMass() const;
103 
107  const SoilParticlePtrVector& getInnerBodyParticles() const;
108 
112  const SoilParticlePtrVector& getWedgeBodyParticles() const;
113 
118  void setLockTranslationalCompliance(agx::Real compliance);
119 
124  void setLockRotationalCompliance(agx::Real compliance);
125 
129  agx::Real getRigidBodyMassSum() const;
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:
180  virtual ~SoilParticleAggregate();
181 
185  agxCollide::Geometry* _getInnerGeometry() const;
186 
190  agxCollide::Geometry* _getWedgeGeometry() const;
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  Terrain* terrain,
203  agx::Vec3 shovelVelocity);
204 
205  void synchronizeLockJoint(TerrainToolCollection* collection);
206 
207  void computePointsInsideActiveZone(TerrainToolCollection* collection, ActiveZone* activeZone);
208 
209  void sortParticlesBySeparatingPlane(Terrain* terrain,
210  ActiveZone* activeZone,
211  SoilParticlePtrVector& innerParticles,
212  SoilParticlePtrVector& wedgeParticles);
213 
214  void computeParticlesInInnerShape(PrimaryActiveZone* activeZone, SoilParticlePtrVector& innerParticles);
215 
216  SoilParticlePtrVector computeParticlesInWedgeShape(ActiveZone* activeZone, SoilParticlePtrVector& wedgeParticleCandidates);
217 
218  void computeParticlesAboveShovel(TerrainToolCollection* collection, agx::Vec3 up, SoilParticlePtrVector& wedgeParticles);
219 
220  bool isPointAbovePlane(const agx::Plane& plane, const agx::Vec3& point) const;
221 
222  bool isSphereIntersectingPlane(const agx::Plane& plane, const agx::Vec3& point, agx::Real radius) const;
223 
224  void updateLockJointComplianceFromBulkMaterial(const TerrainToolCollection* collection,
225  agx::LockJoint* lockJoint);
226 
227  private:
228  agx::RigidBodyRef m_innerBody;
229  agx::RigidBodyRef m_wedgeBody;
230 
231  SoilParticlePtrVector m_innerParticles;
232  SoilParticlePtrVector m_wedgeParticles;
233 
234  agx::LockJointRef m_lock;
235  };
236 
237 
238 
239  inline bool SoilParticleAggregate::isPointAbovePlane(const agx::Plane& plane, const agx::Vec3& point) const
240  {
241  return plane.signedDistanceToPoint(point) > 0;
242  }
243 
244 
245 
246  inline bool SoilParticleAggregate::isSphereIntersectingPlane(const agx::Plane& plane, const agx::Vec3& point, agx::Real radius) const
247  {
248  return std::abs(plane.signedDistanceToPoint(point)) < radius;
249  }
250 
251 
252 
253 
254 }
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Pointer to a entity instance of type Physics.GranularBody.
Copyright 2007 - 2018.
Definition: Geometry.h:56
agx::Physics::GranularBodyPtrVector SoilParticlePtrVector
Collection of terrain tool (currently Shovel) related objects which are terrain instance specific...
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
This class is used to describe the general material properties of the Terrain.
agx::Physics::GranularBodyPtr SoilParticlePtr
Base class providing referencing counted objects.
Definition: Referenced.h:113
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition: LockJoint.h:28
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
#define AGXTERRAIN_EXPORT
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:384
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
AGX_DECLARE_VECTOR_TYPES(ActiveZone)
double Real
Definition: Real.h:42
T signedDistanceToPoint(const agx::Vec3T< T > &point) const
Calculates the distance from the plane to a point.
Definition: Plane.h:209