AGX Dynamics  2.35.0.1
Shovel.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
19 #include <agx/BitState.h>
23 
24 #include <agxStream/Serializable.h>
25 
26 namespace agxCollide
27 {
28  class Geometry;
29  class Shape;
30 }
31 
32 namespace agxTerrain
33 {
34  class Terrain;
35  class TerrainMaterial;
36  class TerrainToolCollection;
37 
51  {
52  public:
53  class ExcavationSettings;
54 
55 
67  Shovel(agx::RigidBody* shovelBody,
68  const agx::Line& topEdge,
69  const agx::Line& cuttingEdge,
70  const agx::Vec3& cuttingDirection);
71 
87  {
88  PRIMARY = 0,
89  DEFORM_BACK = 1,
90  DEFORM_RIGHT = 2,
91  DEFORM_LEFT = 3
92  };
93 
98 
103 
108 
113 
118 
123 
128 
133 
138 
143 
148 
153 
158 
175  void setExcavationSettings( ExcavationMode mode, ExcavationSettings excavationSettings );
176 
181  void setTopEdge(agx::Line topEdge);
182 
187  void setCuttingEdge(agx::Line cuttingEdge);
188 
192  void setCuttingDirection(agx::Vec3 cuttingDirection);
193 
197  void setToothLength(agx::Real length);
198 
203 
208 
213 
217  void setNoMergeExtensionDistance(agx::Real extensionDistance);
218 
222  void setMinimumSubmergedContactLengthFraction(agx::Real minimumSubmergedContactLengthFraction);
223 
228 
233 
238 
243  void setVerticalBladeSoilMergeDistance(agx::Real verticalSoilBladeMergeDistance);
244 
250  void setSecondarySeparationDeadloadLimit( agx::Real secondarySeparationLimit );
251 
257 
270 
281 
294 
305 
310  void setPenetrationForceScaling(agx::Real penetrationForceScaling);
311 
316 
324 
329 
334  void setAlwaysRemoveShovelContacts(bool enable);
335 
340 
345  void setMaxPenetrationForce(agx::Real maxPenetrationForce);
346 
352 
358 
363 
368 
375 
383 
391  void setBottomContactThreshold( agx::Real bottomContactThreshold );
392 
398 
406 
413 
419  void setEnable(bool enable);
420 
425  bool getEnable() const;
426 
427  public:
428 
433  {
434  public:
439 
445 
450  void setEnable(bool enable);
451 
456  void setEnableCreateDynamicMass(bool enable);
457 
462  void setEnableForceFeedback(bool enable);
463 
467  bool getEnable() const;
468 
473 
478 
483 
484  void store( agxStream::OutputArchive& out ) const { m_settings.store( out ); }
485  void restore( agxStream::InputArchive& in ) { m_settings.restore( in ); }
486 
487  private:
488  enum StateFlags : agx::UInt32
489  {
490  ENABLED = 1 << 0,
491  ENABLE_CREATE_DYNAMIC_MASS = 1 << 1,
492  ENABLE_FORCE_FEEDBACK = 1 << 2,
493  };
494  using Flags = agx::BitState<StateFlags, agx::UInt32>;
495  Flags m_settings;
496  };
497 
498  public:
499 
505  agx::Bool initializeCollection( TerrainToolCollection* collection, agxSDK::Simulation* simulation );
506 
511  void uninitializeCollection( TerrainToolCollection* collection, agxSDK::Simulation* simulation );
512 
517  void onPre( TerrainToolCollection* collection );
518 
523  void onPost( TerrainToolCollection* collection );
524 
525  bool getShovelPlanes(TerrainToolCollection* collection,
526  agx::Plane& bottomPlane,
527  agx::Plane& backPlane,
528  agx::Plane& leftPlane,
529  agx::Plane& rightPlane);
530 
531  void removeTerrainShovelContacts(TerrainToolCollection* collection);
532 
533  void removeTerrainShovelContactsDeformer(TerrainToolCollection* collection);
534 
535  bool isEdgeSubmerged(const agx::Line& edge, const Terrain* terrain) const;
536 
537  bool isEdgeSubmergedInSolid(const agx::Line& edge, const Terrain* terrain) const;
538 
539  bool isEdgeSubmergedInHeightfield(const agx::Line& edge, const agxCollide::HeightField* heightfield, const Terrain* terrain) const;
540 
541  agx::Real getSubmergedEdgeLength(const agx::Line& edge, const Terrain* terrain) const;
542 
543  agx::Vec3 getCuttingEdgeVelocity();
544 
545  void correctShovelVectors();
546 
547  void calculateDeadLoadFraction( const Terrain* terrain,
548  const ActiveZone* activeZone,
549  const agx::Physics::GranularBodyPtrVector& innerParticles );
550 
551  void setInnerContactArea( agx::Real contactArea );
552 
553  void setSettingsAreDirty(bool enable);
554 
555  bool getSettingsAreDirty() const;
556 
557  agx::Real computeDefaultBottomContactThreshold() const;
558 
561 
562  protected:
567 
571  virtual ~Shovel();
572 
573  agxCollide::GeometryRefVector createVoxelCollisionGeometries( agx::Real tessellationLevel ) const;
574 
575  protected:
577  {
581  };
582 
584  {
585  ENABLED = 1 << 0,
586  REMOVE_SHOVEL_CONTACTS = 1 << 1,
587 
588  INNER_SHAPE_CREATE_DYNAMIC_MASS = 1 << 2,
589 
590  ENABLE_PARTICLE_FREE_DEFORMATION = 1 << 3,
591 
592  };
593  using Flags = agx::BitState<StateFlags, agx::UInt32>;
594 
609 
610  std::array< ExcavationSettings, 4 > m_excavationSettings;
611 
613 
614  // Caching of dead load
616  // Caching of inner contact area
618 
619  // Geometries used to find shovel-voxel collisions
622  };
623 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXTERRAIN_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:52
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Class containing the settings for the different ExcavationModes for a shovel.
Definition: Shovel.h:433
ExcavationSettings()
Default constructor.
void setEnable(bool enable)
Set whether the excavation mode should be enabled, creating dynamic mass and generating force feedbac...
ExcavationSettings(agx::UInt32 state)
Constructor taking an internal state variable from another excavation setting object.
void store(agxStream::OutputArchive &out) const
Definition: Shovel.h:484
void setEnableForceFeedback(bool enable)
Set true/false if the excavation mode should generate force feedback from created aggregates.
void restore(agxStream::InputArchive &in)
Definition: Shovel.h:485
void setEnableCreateDynamicMass(bool enable)
Set true/false if the excavation mode should create dynamic mass.
bool getEnableParticleFreeDeformers() const
agx::Real m_toothLength
Definition: Shovel.h:599
void setToothMinimumRadius(agx::Real radius)
void setMinimumSubmergedContactLengthFraction(agx::Real minimumSubmergedContactLengthFraction)
Set the minimum submerged cutting edge length fraction (0-1) that generates submerged cutting.
agx::Real getNoMergeExtensionDistance() const
Get the margin outside the shovel bonding box where soil particle merging is forbidden.
agx::Line getCuttingEdge() const
agx::UInt m_nTeeth
Definition: Shovel.h:602
agx::Plane getCurrentSeparationPlane(Terrain *terrain, ExcavationMode mode) const
agx::Real getMaxPenetrationForce() const
Set the maximum limit on penetration force (N) that the terrain will generate on this shovel.
agx::RigidBodyObserver m_shovelBody
Definition: Shovel.h:595
agx::Line m_topEdge
Definition: Shovel.h:597
agx::Real getVerticalBladeSoilMergeDistance() const
Get the vertical distance under the blade cutting edge that the soil is allowed to instantly merge up...
void setCuttingDirection(agx::Vec3 cuttingDirection)
agx::Real getToothLength() const
agx::Real m_contactThreshold
Definition: Shovel.h:612
agx::Real getPenetrationDepthThreshold() const
Get the vertical penetration depth threshold for when the shovel tooth for penetration resistance sho...
bool getAlwaysRemoveShovelContacts() const
agx::Vec3 m_cuttingDirection
Definition: Shovel.h:598
agx::UInt getNumberOfTeeth() const
void setToothMaximumRadius(agx::Real radius)
agx::Real m_noMergeExtensionDistance
Definition: Shovel.h:603
void setNumberOfTeeth(agx::UInt count)
agx::Real m_deadLoadFraction
Definition: Shovel.h:615
bool setSoilPenetrationModel(agxTerrain::SoilPenetrationResistance::PenetrationModel model, agxTerrain::Terrain *terrain)
Set the soil penetration model used for the specified shovel in the given terrain.
bool m_settingsAreDirty
Definition: Shovel.h:621
void setToothLength(agx::Real length)
void setEnableParticleFreeDeformers(bool enable)
Set true/false if the shovel deformers should make particle free deformations.
void setBottomContactThreshold(agx::Real bottomContactThreshold)
Set the distance threshold from the shovel planes where regular geometry contacts between the shovel ...
void setTopEdge(agx::Line topEdge)
Set the top edge in local space.
void setMaxPenetrationForce(agx::Real maxPenetrationForce)
Set a maximum limit on penetration force (N) that the terrain will generate on this shovel.
agx::Real m_toothMaxRadius
Definition: Shovel.h:601
agx::Real m_minimumSubmergedContactLengthFraction
Definition: Shovel.h:605
agx::BitState< StateFlags, agx::UInt32 > Flags
Definition: Shovel.h:593
bool getEnable() const
Access the state enable flag.
agx::Vec3 getCuttingDirectionWorld() const
agxCollide::GeometryRefVector m_voxelCollisionGeometries
Definition: Shovel.h:620
agx::Real getDeadLoadFraction() const
Get the last computed dead load fraction of the shovel, i.e how much of it's inner volume that is fil...
Shovel(agx::RigidBody *shovelBody, const agx::Line &topEdge, const agx::Line &cuttingEdge, const agx::Vec3 &cuttingDirection)
Basic constructor.
void setNoMergeExtensionDistance(agx::Real extensionDistance)
Set the extension outside the shovel bounding box where soil particle merging is forbidden.
agx::Vec3 getCuttingDirection() const
agx::Real getMinimumSubmergedContactLengthFraction() const
Get the minimum submerged cutting edge length fraction (0-1) that generates submerged cutting.
agx::Real m_verticalSoilBladeMergeDistance
Definition: Shovel.h:604
void setEnableInnerShapeCreateDynamicMass(bool enable)
Set if inner shape alone should always create dynamic mass.
agx::Real getSecondarySeparationDeadloadLimit() const
agx::Line getTopEdgeWorld() const
std::array< ExcavationSettings, 4 > m_excavationSettings
Definition: Shovel.h:610
bool getEnableInnerShapeCreateDynamicMass() const
Get if inner shape alone should always create dynamic mass.
void setEnable(bool enable)
Change state enable of this shovel Default: true.
bool getSoilPenetrationModel(agxTerrain::Terrain *terrain, agxTerrain::SoilPenetrationResistance::PenetrationModel &model) const
Get the soil penetration model used for the specified shovel in the given terrain.
agx::Real getSecondarySeparationAngle(Terrain *terrain) const
agx::Line getCuttingEdgeWorld() const
agx::Real getToothMinimumRadius() const
void setSecondarySeparationDeadloadLimit(agx::Real secondarySeparationLimit)
Sets the dead-load limit where secondary separation will start to activate where the forward directio...
void setExcavationSettings(ExcavationMode mode, ExcavationSettings excavationSettings)
Set a settings object for an ExcavationMode of the shovel.
agx::Real getBottomContactThreshold() const
Get the distance threshold from the shovel planes where regular geometry contacts between the shovel ...
void setPenetrationForceScaling(agx::Real penetrationForceScaling)
Set the linear scaling coefficient for the penetration force (Default: 1.0)
agx::Real getInnerContactArea() const
Get the last computed inner contact area of the shovel, i.e the estimated cross-section area of the i...
void setPenetrationDepthThreshold(agx::Real depthThreshold)
Set the vertical penetration depth threshold for when the shovel tooth for penetration resistance sho...
agx::Real getToothMaximumRadius() const
agx::Real m_secondarySeparationDeadLoadLimit
Definition: Shovel.h:606
agx::Vec3 getSecondaryCuttingDirection(Terrain *terrain) const
void setAlwaysRemoveShovelContacts(bool enable)
Set to true/false if shovel <-> terrain contacts should always be removed param enable - set to true/...
agx::RigidBody * getRigidBody() const
agx::Line m_cuttingEdge
Definition: Shovel.h:596
void setVerticalBladeSoilMergeDistance(agx::Real verticalSoilBladeMergeDistance)
Sets the vertical distance under the blade cutting edge that the soil is allowed to instantly merge u...
agx::Real getPenetrationForceScaling() const
SoilPenetrationParameters m_soilPenetrationParameters
Definition: Shovel.h:608
agx::Real m_innerContactArea
Definition: Shovel.h:617
ExcavationMode
Enum for describing the different excavation modes of a shovel: PRIMARY - The primary mode of excavat...
Definition: Shovel.h:87
void setCuttingEdge(agx::Line cuttingEdge)
Set the cutting edge in local space.
agx::Real computeCuttingEdgeLength() const
ExcavationSettings & getExcavationSettings(ExcavationMode mode)
agx::Real m_toothMinRadius
Definition: Shovel.h:600
agx::Line getTopEdge() const
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Class representing the mathematical concept of a plane, also called a half- space.
Definition: agx/Plane.h:32
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::Vector< agx::ref_ptr< Geometry > > GeometryRefVector
Flags
Flags for specifying what is enabled in the debug rendering system.
Definition: RenderManager.h:58
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:60
agx::VectorPOD< GranularBodyPtr > GranularBodyPtrVector
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:40
PlaneT< agx::Real > Plane
Definition: agx/Plane.h:121
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
bool Bool
Definition: Integer.h:48
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42
LineT< Vec3 > Line
Definition: agx/Line.h:39