AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
SoilParticleAggregate.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
21#include <agx/RigidBody.h>
22#include <agx/LockJoint.h>
23#include <agx/Plane.h>
24
25namespace agxTerrain
26{
27 class Shovel;
28 class TerrainToolCollection;
29 class ActiveZone;
30 class TerrainMaterial;
31
35
38
40 {
41 public:
45 SoilParticleAggregate( agx::RigidBody* connectedBody = nullptr );
46
54
63
73 agx::RigidBodyPtrVector getWedgeBodies(bool onlyEnabled=true) const;
74
84 agx::ConstraintPtrVector getWedgeLockJoints(bool onlyEnabled=true) const;
85
93
101
110
116 void setMaterial( agx::Material* material );
117
122
127
132
137
142
147
150
153
154 public:
160 void addNotification( agxSDK::Simulation* simulation, Terrain* terrain );
161
167 void removeNotification( agxSDK::Simulation* simulation, Terrain* terrain );
168
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
212
218
219 protected:
224
229
234
235 protected:
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
316
323 const SoilParticlePtrVector& soilParticles );
324
331 VoxelHashSet& voxels );
332
339
345 agx::RigidBody* partitionBody,
346 agx::Real totalMass,
347 const agx::Matrix3x3& invWorldInertiaTensor );
348
354
359
364
365 void clearParticles( size_t reserve );
366
368
370
376
382
386 bool isWedgePartitionBody( const agx::RigidBody* body ) const;
387
391 const WedgePartitionData& getPartitionData( const agx::RigidBody* partitionBody ) const;
392
394
396
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}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#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:92
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Class that handles and creates a lumped element approximation of the soil wedge aggregate.
void setMaterial(agx::Material *material)
Set the material of each of the geometries in the lumped element structure.
void synchronizeLockJoints(TerrainToolCollection *collection)
Update the lumped element lock joints according to partition data.
const WedgePartitionData & getPartitionData(const agx::RigidBody *partitionBody) const
void splitWedgeParticles(const TerrainToolCollection *collection, const SoilParticlePtrVector &soilParticles)
Split the wedge particles into different partition elements of the wedge aggregate.
void updateCachedWedgeMomentum()
Updates the cached momentum in each partition for the wedge bodies.
void removeNotification(agxSDK::Simulation *simulation, Terrain *terrain)
void init(agx::RigidBody *innerBody)
Initializes the lumped element structure of the wedge aggregate.
void addNotification(agxSDK::Simulation *simulation, Terrain *terrain)
void splitWedgeVoxels(const TerrainToolCollection *collection, VoxelHashSet &voxels)
Split the wedge voxels into different partition elements of the wedge aggregate.
void calculatePartitionPlaneData(TerrainToolCollection *collection)
Calculates all the normals used to defined the internal partition splitting of the wedge volume.
bool isWedgePartitionBody(const agx::RigidBody *body) const
const agx::RigidBody * getContactingWedgeBody() const
This function returns the outermost enabled body in the lumped-element approximation of the wedge agg...
void setSinglePartitionMode()
Set single partition body mode when no splitting is occuring.
void computeLockViolations()
Computes lock violations of the lock joints in the lumped structure.
void updatePartitionBodyMomentum(agx::RigidBody *partitionBody, agx::Real totalMass, const agx::Matrix3x3 &invWorldInertiaTensor)
Update the a specific partition body velocity and angular velocity from updated inertia and cached mo...
agxCollide::Geometry * _getWedgeGeometry() const
Internal mutable geometry accessor.
void onPre(TerrainToolCollection *collection, ActiveZone *activeZone)
const agx::LockJoint * getInnerWedgeLockJoint() const
agx::Vec3 getInnerMomentum() const
void onPost(TerrainToolCollection *collection)
const SoilParticlePtrVector & getWedgeBodyParticles() const
void addNotification(agxSDK::Simulation *simulation, Terrain *terrain)
agx::Vec3 getInnerAngularMomentum() const
void setMaterial(agx::Material *material)
Assign material used for the contact between the shovel and this soil particle aggregate (the soil pa...
bool isConnectedAggregate() const
Return true if this soil aggregate contains a connected rigid body, false otherwise.
const agx::RigidBody * getContactingWedgeBody() const
const agxCollide::Geometry * getInnerGeometry() const
void onPreCollide(TerrainToolCollection *collection)
void removeNotification(agxSDK::Simulation *simulation, Terrain *terrain)
agx::Real getTotalAggregateMass() const
virtual ~SoilParticleAggregate()
Reference counted object - protected destructor.
agx::Real getTotalWedgeBodyMass() const
SoilParticleAggregate(agx::RigidBody *connectedBody=nullptr)
Construct given shovel.
agx::RigidBody * getInnerBody() const
agx::ConstraintPtrVector getWedgeLockJoints(bool onlyEnabled=true) const
Return the wedge lock joints of the wedge part of the soil aggregate.
const agxCollide::Geometry * getContactingWedgeGeometry() const
static agx::Plane transformPlaneToWorld(const agx::Frame *localFrame, const agx::Plane &localPlane)
void setConnectedInnerBody(agx::RigidBody *connectedInnerBody)
Set a connected inner body to the soil aggregate.
agx::Vec3 getInnerParticleAngularMomentum() const
agx::Vec3 getInnerParticleMomentum() const
agxCollide::Geometry * _getInnerGeometry() const
Internal mutable geometry accessor.
agx::Material * getMaterial() const
const SoilParticlePtrVector & getInnerBodyParticles() const
agx::RigidBodyPtrVector getWedgeBodies(bool onlyEnabled=true) const
Return the wedge partition bodies of the wedge part of the soil aggregate.
agx::RigidBody * getInnerOrConnectedBody() const
Set a connected inner body to the soil aggregate.
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...
Definition Terrain.h:86
The object defining a frame of reference and providing transformations operations.
Definition agx/Frame.h:68
Inheritance with partial specialization due to bug with ref_ptr containers.
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition LockJoint.h:31
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition Material.h:376
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:120
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
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:59
agx::Physics::GranularBodyPtrVector SoilParticlePtrVector
agx::HashSet< agx::Vec3i > VoxelHashSet
agx::Physics::GranularBodyPtr SoilParticlePtr
double Real
Definition Real.h:42
Pure data class used to hold information about a single partition in the wedge aggregate.