AGX Dynamics  2.37.3.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:
46 
53  const 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 
199  protected:
203  virtual ~SoilParticleAggregate();
204 
208  agxCollide::Geometry* _getInnerGeometry() const;
209 
213  agxCollide::Geometry* _getWedgeGeometry() const;
214 
215  protected:
221  {
224 
227 
228  SoilParticlePtrVector splitWedgeParticles;
229  VoxelHashSet voxels;
230 
233 
234  using RealArray = std::array<agx::Real, 6>;
236  };
237 
251  {
252  public:
256  SoilWedgeContainer( size_t numWedges );
257 
263  void init(agx::RigidBody* innerBody);
264 
270  void addNotification( agxSDK::Simulation* simulation, Terrain* terrain );
271 
277  void removeNotification( agxSDK::Simulation* simulation, Terrain* terrain );
278 
284  void onEnableChange(bool enable);
285 
289  void setMaterial( agx::Material* material );
290 
295  void calculatePartitionPlaneData( TerrainToolCollection* collection );
296 
302  void splitWedgeParticles( const TerrainToolCollection* collection,
303  const SoilParticlePtrVector& soilParticles );
304 
310  void splitWedgeVoxels( const TerrainToolCollection* collection,
311  VoxelHashSet& voxels );
312 
318  const agx::RigidBody* getContactingWedgeBody() const;
319 
324  void updatePartitionBodyMomentum(
325  agx::RigidBody* partitionBody,
326  agx::Real totalMass,
327  const agx::Matrix3x3& invWorldInertiaTensor );
328 
333  void updateCachedWedgeMomentum();
334 
338  void computeLockViolations();
339 
343  void synchronizeLockJoints( TerrainToolCollection* collection );
344 
345  void clearParticles( size_t reserve );
346 
347  void clearVoxelsAndParticles();
348 
349  agx::Real getTotalWedgeMass() const;
350 
355  void setSinglePartitionMode();
356 
361  void setDeformerWedgeMode();
362 
366  bool isWedgePartitionBody( const agx::RigidBody* body ) const;
367 
371  const WedgePartitionData& getPartitionData( const agx::RigidBody* partitionBody ) const;
372 
373  const agx::Vec3& getCuttingVectorFlat() const;
374 
375  const agx::Vec3& getCutTopVector() const;
376 
377  const agx::Vec3& getForwardDiggingPlane() const;
378 
379  inline const WedgePartitionData& operator[] ( size_t index ) const {
380  return m_wedgePartitions[ index ];
381  }
382 
383  inline WedgePartitionData& operator[] ( size_t index ) {
384  return m_wedgePartitions[ index ];
385  }
386 
387  size_t size() const noexcept
388  {
389  return m_wedgePartitions.size();
390  }
391 
392  protected:
396 
397  std::vector<WedgePartitionData> m_wedgePartitions;
398  };
399 
400  private:
401  VoxelHashSet calculateWedgeVoxels(TerrainToolCollection* collection, ActiveZone* activeZone);
402 
403  VoxelHashSet filterWedgeVoxelsSplittingPlane(TerrainToolCollection* collection,
404  ActiveZone* activeZone,
405  const VoxelHashSet& wedgeVoxels);
406 
407  void updateDynamicProperties(const SoilParticlePtrVector& soilParticles,
408  agx::RigidBody* rb,
409  VoxelHashSet& voxels,
410  TerrainToolCollection* collection);
411 
412  void computeParticlesInActiveZone(TerrainToolCollection* collection,
413  ActiveZone* activeZone);
414 
415  void sortParticlesBySeparatingPlane( Terrain* terrain,
416  ActiveZone* activeZone,
417  SoilParticlePtrVector& innerParticles,
418  SoilParticlePtrVector& wedgeParticles );
419 
420  void computeParticlesInInnerShape( PrimaryActiveZone* activeZone,
421  SoilParticlePtrVector& innerParticles,
422  agx::Real radiusMultiplier);
423 
424  SoilParticlePtrVector computeParticlesInWedgeShape( ActiveZone* activeZone,
425  SoilParticlePtrVector& wedgeParticleCandidates );
426 
427  void computeParticlesAboveShovel( TerrainToolCollection* collection,
428  const agx::Vec3& up,
429  SoilParticlePtrVector& wedgeParticles,
430  agx::Real radiusMultiplier );
431 
432  bool isPointAbovePlane( const agx::Plane& plane,
433  const agx::Vec3& point,
434  agx::Real threshold = 0.0 ) const;
435 
436  bool isSphereIntersectingPlane( const agx::Plane& plane,
437  const agx::Vec3& point,
438  agx::Real radius ) const;
439 
440  bool shouldSplitWedgeAggregate( const TerrainToolCollection* collection );
441 
442  void clearParticles( TerrainToolCollection* collection );
443 
444  void debugRenderParticles( TerrainToolCollection* collection, bool shouldSplit);
445 
446  private:
447  agx::RigidBodyRef m_innerBody;
448 
449  agx::Vec3 m_innerBodyMomentum;
450  agx::Vec3 m_innerBodyAngularMomentum;
451 
452  agx::Vec3 m_innerParticleMomentum;
453  agx::Vec3 m_innerParticleAngularMomentum;
454 
455  agx::Vec3 m_innerCachedMomentum;
456  agx::Vec3 m_innerCachedAngularMomentum;
457 
458  SoilParticlePtrVector m_innerParticles;
459  SoilParticlePtrVector m_wedgeParticles;
460 
461  SoilWedgeContainer m_soilWedgeContainer;
462  };
463 
464 
465 
466  inline bool SoilParticleAggregate::isPointAbovePlane( const agx::Plane& plane,
467  const agx::Vec3& point,
468  agx::Real threshold ) const
469  {
470  return plane.signedDistanceToPoint(point) > threshold;
471  }
472 
473 
474 
475  inline bool SoilParticleAggregate::isSphereIntersectingPlane( const agx::Plane& plane,
476  const agx::Vec3& point,
477  agx::Real radius ) const
478  {
479  return std::abs(plane.signedDistanceToPoint(point)) < radius;
480  }
481 
482 
483 
484 
485 }
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
Pure data class used to hold information about a single partition in the wedge aggregate.
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.
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
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:254
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:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition: LockJoint.h:28
Class that handles and creates a lumped element approximation of the soil wedge aggregate.
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:54
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
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:126
agx::HashSet< agx::Vec3i > VoxelHashSet
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
T signedDistanceToPoint(const agx::Vec3T< T > &point) const
Calculates the distance from the plane to a point.
Definition: Plane.h:209