AGX Dynamics  2.37.3.2
ActiveZone.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 
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  agx::Vec3iVector getFailurePlaneVoxels( const Terrain* terrain ) const;
123 
124  protected:
125 
126  virtual ~ActiveZone();
127 
128  void createSoilWedges(const Terrain* terrain,
129  const agx::Line& cuttingEdge,
130  const agx::Line& topEdge,
131  const agx::Vec3& forwardVector,
132  const agx::Vec3& flatForwardVector);
133 
134  agx::Vec3 projectVectorToTerrainPlane(const agx::Vec3& vec, const agx::Vec3& upVector) const;
135 
136  protected:
137  // Parent frame following shovel body model frame.
140 
141  // Soil wedge meshes
143 
145 
147 
149 
150  private:
151  void initializeGeometry();
152 
153  SoilWedge createSoilWedge(const Terrain* terrain,
154  const agx::UInt wedgeCount,
155  const agx::Line& cuttingEdge,
156  const agx::Line& topEdge,
157  const agx::Vec3& forwardVector,
158  const agx::Vec3& flatForwardVector);
159 
160  bool calculateFailurePlaneIntersection(const Terrain* terrain,
161  SoilWedge& soilWedge,
162  const agx::Line& cuttingEdge,
163  const agx::Line& topEdge,
164  const agx::Vec3& forwardVector,
165  const agx::Vec3& flatForwardVector);
166 
167  void createSoilWedgeConvex(const SoilWedge& soilWedge);
168 
169  void createSoilWedgePlanes(SoilWedge& soilWedge);
170 
171  bool isSoilWedgeSubmerged( const Terrain* terrain, const SoilWedge& soilWedge );
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,
204  const agx::Line& cuttingEdge) const;
205 
206  private:
207  // Active zone geometry and inner-shape
208  agxCollide::GeometryRef m_geometry;
209 
210  bool m_convexCreationFailed;
211  };
212 }
AGXCORE_EXPORT Type * getType(const agx::String &name)
A BoundT represents a range defined by a minimum and a maximum value.
Definition: Bound.h:36
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
bool Bool
Definition: Integer.h:48
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
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
agx::Vector< MeshTransformPair > MeshTransformPairVector
Definition: ActiveZone.h:45
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Templated vector class.
Definition: Vector.h:52
agx::Vector< agxCollide::ConvexRef > m_soilWedgeMeshses
Definition: ActiveZone.h:146
uint32_t UInt
Definition: Integer.h:34
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
T * iterator
Definition: Vector.h:255
agx::Plane m_splittingPlane
Definition: ActiveZone.h:148
std::pair< agxCollide::MeshRef, agx::AffineMatrix4x4 > MeshTransformPair
Definition: ActiveZone.h:42
agx::Bound3i m_voxelOverlapBound
Definition: ActiveZone.h:139
#define AGXTERRAIN_EXPORT
agx::Vector< SoilWedge > m_soilWedges
Definition: ActiveZone.h:144
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agx::Frame * m_parentFrame
Definition: ActiveZone.h:138
agx::UInt m_soilWedgesSize
Definition: ActiveZone.h:142
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34