AGXDynamics  2.35.0.2
ActiveZone.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/config/AGX_USE_AGXTERRAIN.h>
20 
21 #include <agx/agx.h>
22 #include <agx/Line.h>
23 #include <agx/RigidBody.h>
25 
26 #include <agxCollide/Geometry.h>
28 #include <agxCollide/Convex.h>
29 
31 
32 #include <agxSDK/Simulation.h>
34 
35 #include <agxTerrain/export.h>
36 #include <agxTerrain/Grid.h>
37 #include <agxTerrain/SoilWedge.h>
38 
39 namespace agxTerrain
40 {
41  class Terrain;
43 
44  typedef std::pair<agxCollide::MeshRef, agx::AffineMatrix4x4> MeshTransformPair;
46 
48 
51 
53  {
54  public:
55 
56  enum class Type
57  {
58  PRIMARY_ACTIVE_ZONE,
59  DEFORMER_ACTIVE_ZONE
60  };
61 
62  ActiveZone(agx::Frame* parentFrame);
63 
64  virtual void onPreCollide(Terrain* terrain, const agx::Line& cuttingEdge, const agx::Line& topEdge, const agx::Vec3& forwardVector) = 0;
65 
66  virtual void onPre(Terrain* terrain, const agx::Line& cuttingEdge, const agx::Line& topEdge, const agx::Vec3& forwardVector) = 0;
67 
68  virtual void onPost(Terrain* terrain, const agx::Line& cuttingEdge, const agx::Line& topEdge, const agx::Vec3& forwardVector) = 0;
69 
70  virtual ActiveZone::Type getType() const = 0;
71 
72  agx::Line getWedgeFailureEdge() const;
73 
74  agx::Line getWedgeCuttingEdge() const;
75 
76  agx::Line getWedgeTopEdge() const;
77 
78  agx::Bool overlapsVoxel(const agx::Vec3i& index) const;
79 
80  agx::Bound3i getVoxelOverlapBound() const;
81 
82  agxCollide::Geometry* getGeometry();
83 
84  const agxCollide::Geometry* getGeometry() const;
85 
86  const agx::Vector<agxCollide::ConvexRef>& getWedgeShapes() const;
87 
88  WedgePlaneVector getSoilWedgePlanes() const;
89 
90  bool isSoilWedgeEnabled(agx::UInt index) const;
91 
92  bool isAnySoilWedgeEnabled() const;
93 
97  bool soilWedgeCreationFailed() const;
98 
99  agx::Plane getSplittingPlane() const;
100 
101  agx::Real getTotalSoilWedgeVolume(const agx::Vec3& upVector) const;
102 
103  agx::Real getFailureAngle() const;
104 
105  agx::Real getTerrainInclination() const;
106 
107  agx::Real getToolInclination() const;
108 
109  agx::Real getFailureAngleToTerrainPlane(const agx::Vec3& upVector) const;
110 
116  void onEnableChange( bool enable );
117 
118  void removeWedgeShapes();
119 
120  agx::String getActiveZoneTypeName() const;
121 
122  protected:
123 
124  virtual ~ActiveZone();
125 
126  void createSoilWedges(const Terrain* terrain,
127  const agx::Line& cuttingEdge,
128  const agx::Line& topEdge,
129  const agx::Vec3& forwardVector,
130  const agx::Vec3& flatForwardVector);
131 
132  agx::Vec3 projectVectorToTerrainPlane(const agx::Vec3& vec, const agx::Vec3& upVector) const;
133 
134  protected:
135  // Parent frame following shovel body model frame.
138 
139  // Soil wedge meshes
141 
143 
145 
147 
148  private:
149  void initializeGeometry();
150 
151  SoilWedge createSoilWedge(const Terrain* terrain,
152  const agx::UInt wedgeCount,
153  const agx::Line& cuttingEdge,
154  const agx::Line& topEdge,
155  const agx::Vec3& forwardVector,
156  const agx::Vec3& flatForwardVector);
157 
158  bool calculateFailurePlaneIntersection(const Terrain* terrain,
159  SoilWedge& soilWedge,
160  const agx::Line& cuttingEdge,
161  const agx::Line& topEdge,
162  const agx::Vec3& forwardVector,
163  const agx::Vec3& flatForwardVector);
164 
165  void createSoilWedgeConvex(const SoilWedge& soilWedge);
166 
167  void createSoilWedgePlanes(SoilWedge& soilWedge);
168 
169  bool isSoilWedgeSubmerged( const Terrain* terrain, const SoilWedge& soilWedge );
170 
171  bool isPointSubmerged( const Terrain* terrain, const agx::Vec3& point );
172 
173  bool doTerrainToolIntersectionTest(const Terrain* terrain,
174  const agx::AffineMatrix4x4& worldToHeightField,
175  const SoilWedge& soilWedge,
176  const agx::Vec3& upVector,
177  const agx::Vec3& flatForwardVector,
178  const agx::Vec3& forwardVector,
179  agx::Real forwardAngle,
180  agx::Real maxWedgeLength,
181  agx::Vec3& intersectionPoint) const;
182 
183  bool handleMissedIntersection( const Terrain* terrain,
184  const agx::Vec3& upVector,
185  const agx::Vec3& flatForwardVector,
186  const agx::Line& flatForwardLine,
187  agx::Vec3iVector::iterator& voxelIterator,
188  const agx::Vec3iVector& voxels,
189  agx::Vec3& intersectionPoint ) const;
190 
191  bool isIntersectionAboveTerrainMesh( const Terrain* terrain,
192  const SoilWedge& soilWedge,
193  const agx::AffineMatrix4x4& worldToHeightField,
194  const agx::Vec3& upVector ) const;
195 
196  void updateSoilWedgeInclinations(const Terrain* terrain,
197  SoilWedge& soilWedge,
198  const agx::Vec2i terrainIndex,
199  const agx::Vec3i voxelIndex,
200  const agx::Real cuttingEdgeHeight,
201  const agx::Vec3& upVector,
202  const agx::Vec3& forwardVector,
203  const agx::Vec3& flatForwardVector) const;
204 
205  private:
206  // Active zone geometry and inner-shape
207  agxCollide::GeometryRef m_geometry;
208 
209  bool m_convexCreationFailed;
210  };
211 }
agxTerrain::Terrain
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: agxTerrain/Terrain.h:85
agx::Real
double Real
Definition: Real.h:42
agxTerrain::SoilWedge
Definition: SoilWedge.h:28
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:59
Simulation.h
agxData::getType
AGXCORE_EXPORT Type * getType(const agx::String &name)
Geometry.h
agx::AffineMatrix4x4T< Real >
agx::VectorPOD::iterator
T * iterator
Definition: Vector.h:255
agxTerrain::ActiveZone
Definition: ActiveZone.h:52
StepEventListener.h
agxTerrain::ActiveZone::m_soilWedgeMeshses
agx::Vector< agxCollide::ConvexRef > m_soilWedgeMeshses
Definition: ActiveZone.h:144
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
Grid.h
export.h
ShapePrimitives.h
agxTerrain::MeshTransformPair
std::pair< agxCollide::MeshRef, agx::AffineMatrix4x4 > MeshTransformPair
Definition: ActiveZone.h:42
agx::BoundT
A BoundT represents a range defined by a minimum and a maximum value.
Definition: Bound.h:36
agxTerrain::ActiveZone::m_splittingPlane
agx::Plane m_splittingPlane
Definition: ActiveZone.h:146
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< Geometry >
agxTerrain::ActiveZone::m_voxelOverlapBound
agx::Bound3i m_voxelOverlapBound
Definition: ActiveZone.h:137
Line.h
agxTerrain::ActiveZone::m_soilWedges
agx::Vector< SoilWedge > m_soilWedges
Definition: ActiveZone.h:142
Convex.h
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::LineT
Definition: Line.h:25
agx::Vec2T
Definition: Vec2Template.h:30
agx.h
RigidBody.h
agxTerrain::ActiveZone::Type
Type
Definition: ActiveZone.h:56
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
AGXTERRAIN_EXPORT
#define AGXTERRAIN_EXPORT
Definition: agxTerrain/export.h:41
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agx::Bool
bool Bool
Definition: Integer.h:48
RenderSingleton.h
agxTerrain::TerrainToolCollection
Collection of terrain tool (currently Shovel) related objects which are terrain instance specific.
Definition: TerrainToolCollection.h:35
agx::AgXString< std::string >
agx::Vec3T< Real >
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agxTerrain::MeshTransformPairVector
agx::Vector< MeshTransformPair > MeshTransformPairVector
Definition: ActiveZone.h:45
GranularBodySystem.h
agxTerrain::ActiveZone::m_parentFrame
agx::Frame * m_parentFrame
Definition: ActiveZone.h:136
SoilWedge.h
agxTerrain::ActiveZone::m_soilWedgesSize
agx::UInt m_soilWedgesSize
Definition: ActiveZone.h:140