AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
SoilParticleAggregate.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. 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 ActiveZone;
29 class TerrainMaterial;
30 class AggregateContactGenerator;
31 class ExternalDeformer;
32
36
39
41 {
42 public:
46 SoilParticleAggregate( agx::RigidBody* connectedBody = nullptr,
47 bool isDeformerAggregate = false,
48 const agx::Name& tag = "" );
49
57
66
76 agx::RigidBodyPtrVector getWedgeBodies(bool onlyEnabled=true) const;
77
87 agx::ConstraintPtrVector getWedgeLockJoints(bool onlyEnabled=true) const;
88
96
104
113
119 void setMaterial( agx::Material* material );
120
125
130
135
140
145
150
155
166 agx::Real getTotalSoilBulkVolume(agx::Real packingFraction=0.67) const;
167
172
177
182
185
188
189 public:
191
192
197 void addNotification( agxSDK::Simulation* simulation );
198
204 void removeNotification( agxSDK::Simulation* simulation );
205
211 void onPreCollide( Terrain* terrain,
212 Shovel* shovel,
213 bool enableBodies );
214
220 void onPre( Terrain* terrain, Shovel* shovel, ActiveZone* activeZone);
221
227 void onDeformerPre(Terrain* terrain, ActiveZone* activeZone);
228
234 void onPost();
235
241 void onEnableChange( bool enable );
242
243 static agx::Plane transformPlaneToWorld(const agx::Frame* localFrame, const agx::Plane& localPlane);
244
245 static agx::Vector<agx::Plane> transformPlanesToWorld( const agx::Frame* localFrame, const agx::Vector<agx::Plane>& localPlanes );
246
252 void setConnectedInnerBody(agx::RigidBody* connectedInnerBody);
253
259 agx::RigidBody* getInnerOrConnectedBody() const;
260
265 bool isConnectedAggregate() const;
266
270 void updateAggregateCacheData( agxTerrain::Shovel* shovel );
271
272 void clearAggregateData();
273
274 void disableWedgeAggregates();
275
276 void renderWegePositions( const agx::Vec3& origin,
277 const agxRender::Color& color );
278
279 void renderWedgeVelocityNormals( agx::Real normalLength = agx::Real( 1.0 ) );
280
281 public:
286 struct AGXTERRAIN_EXPORT WedgePartitionData
287 {
288 agx::RigidBodyRef wedgeBody;
290
291 agx::Vec3 lockFramePosition;
292 agx::Vec3 lockPlaneNormal;
293
294 SoilParticlePtrVector splitWedgeParticles;
295 VoxelHashSet voxels;
296
297 agx::Vec3 wedgeBodyMomentum;
298 agx::Vec3 wedgeBodyAngularMomentum;
299
300 using RealArray = std::array<agx::Real, 6>;
301 RealArray violations;
302 };
303
316 class AGXTERRAIN_EXPORT SoilWedgeContainer
317 {
318 public:
322 SoilWedgeContainer( size_t numWedges );
323
329 void init( agx::RigidBody* innerBody,
330 const agx::Name& tag );
331
337 void addNotification( agxSDK::Simulation* simulation );
338
344 void removeNotification( agxSDK::Simulation* simulation );
345
351 void onEnableChange(bool enable);
352
356 void setMaterial( agx::Material* material );
357
362 void calculatePartitionPlaneData( Shovel* shovel );
363
369 void splitWedgeParticles( const Shovel* shovel,
370 const SoilParticlePtrVector& soilParticles );
371
377 void splitWedgeVoxels( const Terrain* terrain,
378 const Shovel* shovel,
379 VoxelHashSet& voxels );
380
386 const agx::RigidBody* getContactingWedgeBody() const;
387
392 void updatePartitionBodyMomentum(
393 agx::RigidBody* partitionBody,
394 agx::Real totalMass,
395 const agx::Matrix3x3& invWorldInertiaTensor );
396
401 void updateCachedWedgeMomentum();
402
406 void computeLockViolations();
407
411 void synchronizeLockJoints(Terrain* terrain, Shovel* shovel);
412
413 void clearParticles( size_t reserve );
414
415 void clearVoxelsAndParticles();
416
417 agx::Real getTotalWedgeMass() const;
418
423 void setSinglePartitionMode();
424
429 void setDeformerWedgeMode();
430
434 bool isWedgePartitionBody( const agx::RigidBody* body ) const;
435
439 const WedgePartitionData& getPartitionData( const agx::RigidBody* partitionBody ) const;
440
441 const agx::Vec3& getCuttingVectorFlat() const;
442
443 const agx::Vec3& getCutTopVector() const;
444
445 const agx::Vec3& getForwardDiggingPlane() const;
446
447 inline const WedgePartitionData& operator[] ( size_t index ) const {
448 return m_wedgePartitions[ index ];
449 }
450
451 inline WedgePartitionData& operator[] ( size_t index ) {
452 return m_wedgePartitions[ index ];
453 }
454
455 size_t size() const noexcept
456 {
457 return m_wedgePartitions.size();
458 }
459
460 protected:
461 agx::Vec3 m_cuttingVectorFlat;
462 agx::Vec3 m_topCutVector;
463 agx::Vec3 m_forwardDiggingPlane;
464
465 std::vector<WedgePartitionData> m_wedgePartitions;
466 };
467
468 SoilWedgeContainer* getSoilWedgeContainer();
469
471
472 protected:
477
481 agxCollide::Geometry* _getInnerGeometry() const;
482
486 agxCollide::Geometry* _getWedgeGeometry() const;
487
488 private:
489 void calculateWedgeVoxels(Terrain* terrain, ActiveZone* activeZone);
490
491 VoxelHashSet filterWedgeVoxelsSplittingPlane( Terrain* terrain,
492 ActiveZone* activeZone,
493 const VoxelHashSet& wedgeVoxels );
494
495 void updateDynamicProperties( const SoilParticlePtrVector& soilParticles,
496 agx::RigidBody* rb,
497 VoxelHashSet& voxels,
498 Terrain* terrain,
499 Shovel* shovel );
500
501 void computeParticlesInActiveZone( Shovel* shovel,
502 ActiveZone* activeZone);
503
504 void sortParticlesBySeparatingPlane( agx::ParticleSystem* soilParticleSystem,
505 ActiveZone* activeZone,
506 SoilParticlePtrVector& innerParticles,
507 SoilParticlePtrVector& wedgeParticles,
508 bool onlyMidpoint=false);
509
510 void computeParticlesInInnerShape( Shovel* shovel,
511 PrimaryActiveZone* activeZone,
512 SoilParticlePtrVector& innerParticles,
513 agx::Real radiusMultiplier);
514
515 SoilParticlePtrVector computeParticlesInWedgeShape( ActiveZone* activeZone,
516 SoilParticlePtrVector& wedgeParticleCandidates );
517
518 void computeParticlesAboveShovel( Shovel* shovel,
519 SoilParticlePtrVector& wedgeParticles);
520
521 bool isPointAbovePlane( const agx::Plane& plane,
522 const agx::Vec3& point,
523 agx::Real threshold = 0.0 ) const;
524
525 bool isSphereIntersectingPlane( const agx::Plane& plane,
526 const agx::Vec3& point,
527 agx::Real radius ) const;
528
529 bool shouldSplitWedgeAggregate( const Shovel* shovel );
530
531 void clearParticles( size_t particleStorageSize );
532
533 void debugRenderParticles( agxTerrain::Shovel* shovel,
534 bool shouldSplit );
535
536 void debugRenderVoxels( agxTerrain::Shovel* shovel,
537 agxTerrain::Terrain* terrain,
538 bool shouldSplit );
539
540 private:
541 agx::RigidBodyRef m_innerBody;
542
543 agx::Vec3 m_innerBodyCachedMomentum;
544 agx::Vec3 m_innerBodyCachedAngularMomentum;
545
546 agx::Vec3 m_innerParticleMomentum;
547 agx::Vec3 m_innerParticleAngularMomentum;
548
549 SoilParticlePtrVector m_innerParticles;
550 SoilParticlePtrVector m_wedgeParticles;
551 VoxelHashSet m_wedgeVoxels;
552 agx::Real m_wedgeVoxelsVolume;
553
554 SoilWedgeContainer m_soilWedgeContainer;
555 agx::RigidBodyObserver m_connectedInnerBody;
556 };
557
558
559
560 inline bool SoilParticleAggregate::isPointAbovePlane( const agx::Plane& plane,
561 const agx::Vec3& point,
562 agx::Real threshold ) const
563 {
564 return plane.signedDistanceToPoint(point) > threshold;
565 }
566
567
568
569 inline bool SoilParticleAggregate::isSphereIntersectingPlane( const agx::Plane& plane,
570 const agx::Vec3& point,
571 agx::Real radius ) const
572 {
573 return std::abs(plane.signedDistanceToPoint(point)) < radius;
574 }
575
576
577
578
579}
#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:131
Shovel object used to interact with a terrain via an active zone that converts solid terrain to dynam...
Definition: Shovel.h:63
const agx::LockJoint * getInnerWedgeLockJoint() const
SoilParticleAggregate(agx::RigidBody *connectedBody=nullptr, bool isDeformerAggregate=false, const agx::Name &tag="")
Construct a soil particle aggregate.
const SoilParticlePtrVector & getWedgeBodyParticles() const
void setMaterial(agx::Material *material)
Assign material used for the contact between the shovel and this soil particle aggregate (the soil pa...
agx::Real getTotalParticleVolume() const
agx::Real getWedgeParticleVolume() const
const agx::RigidBody * getContactingWedgeBody() const
const agxCollide::Geometry * getInnerGeometry() const
agx::Real getTotalAggregateMass() const
agx::Real getTotalSoilBulkVolume(agx::Real packingFraction=0.67) const
Return the estimated total soil bulk volume of all particles and voxels of fluid and solid mass (both...
agx::Real getTotalWedgeBodyMass() const
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
agx::Vec3iVector getWedgeBodyVoxels() const
agx::Vec3 getInnerCachedAngularMomentum() const
agx::Vec3 getInnerParticleAngularMomentum() const
agx::Vec3 getInnerParticleMomentum() const
agx::Real getInnerParticleVolume() const
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::Vec3 getInnerCachedMomentum() const
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:92
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:670
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:378
Representation of a name string.
Definition: Name.h:33
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:49
Vector containing 'raw' data.
Definition: agx/Vector.h:246
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Namespace containing classes for handling debug rendering of collision geometries,...
Definition: Constraint.h:36
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
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
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real
Definition: Real.h:41