AGX Dynamics  2.35.0.1
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;
42  class TerrainToolCollection;
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 
73 
75 
77 
78  agx::Bool overlapsVoxel(const agx::Vec3i& index) const;
79 
81 
83 
85 
87 
89 
90  bool isSoilWedgeEnabled(agx::UInt index) const;
91 
92  bool isAnySoilWedgeEnabled() const;
93 
98 
100 
102 
104 
106 
108 
110 
116  void onEnableChange( bool enable );
117 
119 
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 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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:93
bool soilWedgeCreationFailed() const
agx::Line getWedgeCuttingEdge() const
agx::Real getToolInclination() const
agx::Real getTotalSoilWedgeVolume(const agx::Vec3 &upVector) const
agx::Bound3i getVoxelOverlapBound() const
agx::Real getTerrainInclination() const
agx::Plane getSplittingPlane() const
virtual void onPost(Terrain *terrain, const agx::Line &cuttingEdge, const agx::Line &topEdge, const agx::Vec3 &forwardVector)=0
agx::Real getFailureAngleToTerrainPlane(const agx::Vec3 &upVector) const
void onEnableChange(bool enable)
bool isAnySoilWedgeEnabled() const
agx::UInt m_soilWedgesSize
Definition: ActiveZone.h:140
WedgePlaneVector getSoilWedgePlanes() const
agx::Vector< SoilWedge > m_soilWedges
Definition: ActiveZone.h:142
virtual void onPreCollide(Terrain *terrain, const agx::Line &cuttingEdge, const agx::Line &topEdge, const agx::Vec3 &forwardVector)=0
agx::Line getWedgeFailureEdge() const
agx::String getActiveZoneTypeName() const
agx::Vec3 projectVectorToTerrainPlane(const agx::Vec3 &vec, const agx::Vec3 &upVector) const
const agxCollide::Geometry * getGeometry() const
agx::Bound3i m_voxelOverlapBound
Definition: ActiveZone.h:137
agxCollide::Geometry * getGeometry()
agx::Bool overlapsVoxel(const agx::Vec3i &index) const
const agx::Vector< agxCollide::ConvexRef > & getWedgeShapes() const
agx::Frame * m_parentFrame
Definition: ActiveZone.h:136
virtual void onPre(Terrain *terrain, const agx::Line &cuttingEdge, const agx::Line &topEdge, const agx::Vec3 &forwardVector)=0
agx::Plane m_splittingPlane
Definition: ActiveZone.h:146
void createSoilWedges(const Terrain *terrain, const agx::Line &cuttingEdge, const agx::Line &topEdge, const agx::Vec3 &forwardVector, const agx::Vec3 &flatForwardVector)
virtual ActiveZone::Type getType() const =0
agx::Real getFailureAngle() const
agx::Vector< agxCollide::ConvexRef > m_soilWedgeMeshses
Definition: ActiveZone.h:144
ActiveZone(agx::Frame *parentFrame)
bool isSoilWedgeEnabled(agx::UInt index) const
agx::Line getWedgeTopEdge() const
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
A BoundT represents a range defined by a minimum and a maximum value.
Definition: Bound.h:37
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
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
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Templated vector class.
Definition: agx/Vector.h:53
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:60
std::pair< agxCollide::MeshRef, agx::AffineMatrix4x4 > MeshTransformPair
Definition: ActiveZone.h:42
agx::Vector< MeshTransformPair > MeshTransformPairVector
Definition: ActiveZone.h:45
bool Bool
Definition: Integer.h:48
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42