AGX Dynamics  2.38.0.2
SoilParticleAggregate.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 #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 
35 
38 
40  {
41  public:
45  SoilParticleAggregate( agx::RigidBody* connectedBody = nullptr );
46 
53  agx::RigidBody* getInnerBody() const;
54 
62  const agx::RigidBody* getContactingWedgeBody() const;
63 
73  agx::RigidBodyPtrVector getWedgeBodies(bool onlyEnabled=true) const;
74 
84  agx::ConstraintPtrVector getWedgeLockJoints(bool onlyEnabled=true) const;
85 
92  const agxCollide::Geometry* getInnerGeometry() const;
93 
100  const agxCollide::Geometry* getContactingWedgeGeometry() const;
101 
109  const agx::LockJoint* getInnerWedgeLockJoint() const;
110 
116  void setMaterial( agx::Material* material );
117 
121  agx::Material* getMaterial() const;
122 
126  agx::Real getMass() const;
127 
131  const SoilParticlePtrVector& getInnerBodyParticles() const;
132 
136  const SoilParticlePtrVector& getWedgeBodyParticles() const;
137 
141  agx::Real getTotalWedgeBodyMass() const;
142 
146  agx::Real getTotalAggregateMass() const;
147 
148  agx::Vec3 getInnerParticleMomentum() const;
149  agx::Vec3 getInnerParticleAngularMomentum() const;
150 
151  agx::Vec3 getInnerMomentum() const;
152  agx::Vec3 getInnerAngularMomentum() const;
153 
154  public:
160  void addNotification( agxSDK::Simulation* simulation, Terrain* terrain );
161 
167  void removeNotification( agxSDK::Simulation* simulation, Terrain* terrain );
168 
174  void onPreCollide( TerrainToolCollection* collection );
175 
181  void onPre( TerrainToolCollection* collection, ActiveZone* activeZone );
182 
188  void onPost( TerrainToolCollection* collection );
189 
195  void onEnableChange( bool enable );
196 
197  static agx::Plane transformPlaneToWorld(const agx::Frame* localFrame, const agx::Plane& localPlane);
198 
204  void setConnectedInnerBody(agx::RigidBody* connectedInnerBody);
205 
211  agx::RigidBody* getInnerOrConnectedBody() const;
212 
217  bool isConnectedAggregate() const;
218 
219  protected:
223  virtual ~SoilParticleAggregate();
224 
228  agxCollide::Geometry* _getInnerGeometry() const;
229 
233  agxCollide::Geometry* _getWedgeGeometry() const;
234 
235  protected:
241  {
244 
247 
250 
253 
254  using RealArray = std::array<agx::Real, 6>;
256  };
257 
271  {
272  public:
276  SoilWedgeContainer( size_t numWedges );
277 
283  void init(agx::RigidBody* innerBody);
284 
290  void addNotification( agxSDK::Simulation* simulation, Terrain* terrain );
291 
297  void removeNotification( agxSDK::Simulation* simulation, Terrain* terrain );
298 
304  void onEnableChange(bool enable);
305 
309  void setMaterial( agx::Material* material );
310 
315  void calculatePartitionPlaneData( TerrainToolCollection* collection );
316 
322  void splitWedgeParticles( const TerrainToolCollection* collection,
323  const SoilParticlePtrVector& soilParticles );
324 
330  void splitWedgeVoxels( const TerrainToolCollection* collection,
331  VoxelHashSet& voxels );
332 
338  const agx::RigidBody* getContactingWedgeBody() const;
339 
344  void updatePartitionBodyMomentum(
345  agx::RigidBody* partitionBody,
346  agx::Real totalMass,
347  const agx::Matrix3x3& invWorldInertiaTensor );
348 
353  void updateCachedWedgeMomentum();
354 
358  void computeLockViolations();
359 
363  void synchronizeLockJoints( TerrainToolCollection* collection );
364 
365  void clearParticles( size_t reserve );
366 
367  void clearVoxelsAndParticles();
368 
369  agx::Real getTotalWedgeMass() const;
370 
375  void setSinglePartitionMode();
376 
381  void setDeformerWedgeMode();
382 
386  bool isWedgePartitionBody( const agx::RigidBody* body ) const;
387 
391  const WedgePartitionData& getPartitionData( const agx::RigidBody* partitionBody ) const;
392 
393  const agx::Vec3& getCuttingVectorFlat() const;
394 
395  const agx::Vec3& getCutTopVector() const;
396 
397  const agx::Vec3& getForwardDiggingPlane() const;
398 
399  inline const WedgePartitionData& operator[] ( size_t index ) const {
400  return m_wedgePartitions[ index ];
401  }
402 
403  inline WedgePartitionData& operator[] ( size_t index ) {
404  return m_wedgePartitions[ index ];
405  }
406 
407  size_t size() const noexcept
408  {
409  return m_wedgePartitions.size();
410  }
411 
412  protected:
416 
417  std::vector<WedgePartitionData> m_wedgePartitions;
418  };
419 
420  private:
421  VoxelHashSet calculateWedgeVoxels(TerrainToolCollection* collection, ActiveZone* activeZone);
422 
423  VoxelHashSet filterWedgeVoxelsSplittingPlane(TerrainToolCollection* collection,
424  ActiveZone* activeZone,
425  const VoxelHashSet& wedgeVoxels);
426 
427  void updateDynamicProperties(const SoilParticlePtrVector& soilParticles,
428  agx::RigidBody* rb,
429  VoxelHashSet& voxels,
430  TerrainToolCollection* collection);
431 
432  void computeParticlesInActiveZone(TerrainToolCollection* collection,
433  ActiveZone* activeZone);
434 
435  void sortParticlesBySeparatingPlane( Terrain* terrain,
436  ActiveZone* activeZone,
437  SoilParticlePtrVector& innerParticles,
438  SoilParticlePtrVector& wedgeParticles );
439 
440  void computeParticlesInInnerShape( PrimaryActiveZone* activeZone,
441  SoilParticlePtrVector& innerParticles,
442  agx::Real radiusMultiplier);
443 
444  SoilParticlePtrVector computeParticlesInWedgeShape( ActiveZone* activeZone,
445  SoilParticlePtrVector& wedgeParticleCandidates );
446 
447  void computeParticlesAboveShovel( TerrainToolCollection* collection,
448  const agx::Vec3& up,
449  SoilParticlePtrVector& wedgeParticles,
450  agx::Real radiusMultiplier );
451 
452  bool isPointAbovePlane( const agx::Plane& plane,
453  const agx::Vec3& point,
454  agx::Real threshold = 0.0 ) const;
455 
456  bool isSphereIntersectingPlane( const agx::Plane& plane,
457  const agx::Vec3& point,
458  agx::Real radius ) const;
459 
460  bool shouldSplitWedgeAggregate( const TerrainToolCollection* collection );
461 
462  void clearParticles( TerrainToolCollection* collection );
463 
464  void debugRenderParticles( TerrainToolCollection* collection, bool shouldSplit);
465 
466  private:
467  agx::RigidBodyRef m_innerBody;
468 
469  agx::Vec3 m_innerBodyMomentum;
470  agx::Vec3 m_innerBodyAngularMomentum;
471 
472  agx::Vec3 m_innerParticleMomentum;
473  agx::Vec3 m_innerParticleAngularMomentum;
474 
475  agx::Vec3 m_innerCachedMomentum;
476  agx::Vec3 m_innerCachedAngularMomentum;
477 
478  SoilParticlePtrVector m_innerParticles;
479  SoilParticlePtrVector m_wedgeParticles;
480 
481  SoilWedgeContainer m_soilWedgeContainer;
482  agx::RigidBodyObserver m_connectedInnerBody;
483  };
484 
485 
486 
487  inline bool SoilParticleAggregate::isPointAbovePlane( const agx::Plane& plane,
488  const agx::Vec3& point,
489  agx::Real threshold ) const
490  {
491  return plane.signedDistanceToPoint(point) > threshold;
492  }
493 
494 
495 
496  inline bool SoilParticleAggregate::isSphereIntersectingPlane( const agx::Plane& plane,
497  const agx::Vec3& point,
498  agx::Real radius ) const
499  {
500  return std::abs(plane.signedDistanceToPoint(point)) < radius;
501  }
502 
503 
504 
505 
506 }
agx::Physics::GranularBodyPtr
Pointer to a entity instance of type Physics.GranularBody.
Definition: GranularBodyEntity.h:190
agxTerrain::SoilParticleAggregate::WedgePartitionData::lock
agx::LockJointRef lock
Definition: SoilParticleAggregate.h:243
agxTerrain::SoilParticleAggregate::WedgePartitionData
Pure data class used to hold information about a single partition in the wedge aggregate.
Definition: SoilParticleAggregate.h:240
agxTerrain::SoilParticleAggregate::WedgePartitionData::RealArray
std::array< agx::Real, 6 > RealArray
Definition: SoilParticleAggregate.h:254
agxTerrain::Terrain
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:85
agx::Real
double Real
Definition: Real.h:42
PrimaryActiveZone.h
agxTerrain::SoilParticleAggregate::WedgePartitionData::splitWedgeParticles
SoilParticlePtrVector splitWedgeParticles
Definition: SoilParticleAggregate.h:248
agxTerrain::SoilParticlePtr
agx::Physics::GranularBodyPtr SoilParticlePtr
Definition: SoilParticleAggregate.h:30
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:58
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
agxTerrain::SoilParticleAggregate::SoilWedgeContainer::m_topCutVector
agx::Vec3 m_topCutVector
Definition: SoilParticleAggregate.h:414
agxTerrain::TerrainMaterial
This class is used to describe the general material properties of the Terrain.
Definition: TerrainMaterial.h:53
agxTerrain::SoilParticlePtrVector
agx::Physics::GranularBodyPtrVector SoilParticlePtrVector
Definition: SoilParticleAggregate.h:33
agxTerrain::SoilParticleAggregate::WedgePartitionData::wedgeBodyMomentum
agx::Vec3 wedgeBodyMomentum
Definition: SoilParticleAggregate.h:251
agxTerrain::ActiveZone
Definition: ActiveZone.h:52
agxTerrain::VoxelHashSet
agx::HashSet< agx::Vec3i > VoxelHashSet
Definition: SoilParticleAggregate.h:34
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
Plane.h
agxTerrain::SoilParticleAggregate::WedgePartitionData::violations
RealArray violations
Definition: SoilParticleAggregate.h:255
agx::observer_ptr< RigidBody >
agxTerrain::SoilParticleAggregate::WedgePartitionData::lockPlaneNormal
agx::Vec3 lockPlaneNormal
Definition: SoilParticleAggregate.h:246
agxTerrain::PrimaryActiveZone
Definition: PrimaryActiveZone.h:30
agx::PlaneT
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agx::ref_ptr< RigidBody >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agxTerrain::SoilParticleAggregate::WedgePartitionData::voxels
VoxelHashSet voxels
Definition: SoilParticleAggregate.h:249
SoilSimulationInterface.h
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
agxTerrain::SoilParticleAggregate::WedgePartitionData::wedgeBody
agx::RigidBodyRef wedgeBody
Definition: SoilParticleAggregate.h:242
agxTerrain::SoilParticleAggregate::SoilWedgeContainer
Class that handles and creates a lumped element approximation of the soil wedge aggregate.
Definition: SoilParticleAggregate.h:270
agx::LockJoint
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition: LockJoint.h:30
agxTerrain::SoilParticleAggregate::WedgePartitionData::lockFramePosition
agx::Vec3 lockFramePosition
Definition: SoilParticleAggregate.h:245
LockJoint.h
agxTerrain::SoilParticleAggregate::SoilWedgeContainer::m_wedgePartitions
std::vector< WedgePartitionData > m_wedgePartitions
Definition: SoilParticleAggregate.h:417
agxTerrain::SoilParticleAggregate::SoilWedgeContainer::m_cuttingVectorFlat
agx::Vec3 m_cuttingVectorFlat
Definition: SoilParticleAggregate.h:413
agx::HashSet< agx::Vec3i >
agx::PlaneT::signedDistanceToPoint
T signedDistanceToPoint(const agx::Vec3T< T > &point) const
Calculates the distance from the plane to a point.
Definition: Plane.h:209
agxTerrain::SoilParticleAggregate::SoilWedgeContainer::m_forwardDiggingPlane
agx::Vec3 m_forwardDiggingPlane
Definition: SoilParticleAggregate.h:415
RigidBody.h
agxTerrain::SoilParticleAggregate::SoilWedgeContainer::size
size_t size() const noexcept
Definition: SoilParticleAggregate.h:407
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
AGXTERRAIN_EXPORT
#define AGXTERRAIN_EXPORT
Definition: agxTerrain/export.h:41
agxTerrain::TerrainToolCollection
Collection of terrain tool (currently Shovel) related objects which are terrain instance specific.
Definition: TerrainToolCollection.h:36
agxTerrain::SoilParticleAggregate::WedgePartitionData::wedgeBodyAngularMomentum
agx::Vec3 wedgeBodyAngularMomentum
Definition: SoilParticleAggregate.h:252
agxTerrain::SoilParticleAggregate
Definition: SoilParticleAggregate.h:39
agx::init
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
agx::Material
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
agx::Vec3T< Real >
agx::Matrix3x3T< Real >
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67