AGX Dynamics  2.37.3.2
TerrainContactGenerator.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 #include <agxTerrain/export.h>
22 #include <agx/Referenced.h>
23 #include <agx/Vec3.h>
24 #include <agx/Vec2.h>
25 #include <agx/agx_vector_types.h>
26 #include <agx/Material.h>
27 #include <agx/HashSet.h>
28 #include <agx/Material.h>
29 #include <agx/Bound.h>
30 #include <agxCollide/Contacts.h>
31 #include <queue>
32 
33 namespace agxSDK
34 {
35  class Simulation;
36 }
37 
38 namespace agxCollide
39 {
40  class Geometry;
41 }
42 
43 namespace agxTerrain
44 {
45  class Terrain;
46 
47  typedef std::queue<agx::Vec2i> IndexQueue;
48 
51 
61  {
62  public:
67 
74 
80  void onPre(agxSDK::Simulation* simulation);
81 
86  void onPost(agxSDK::Simulation* simulation);
87 
91  void onRemove(agxSDK::Simulation* simulation);
92 
96  const TerrainContactRefVector& getTerrainContacts() const;
97 
101  TerrainContactRefVector& getTerrainContacts();
102 
103  public:
107 
108  protected:
109 
113  void buildTerrainContacts(agxSDK::Simulation* simulation);
114 
118  void updateTerrainContactsWithForceData();
119 
124  void replaceTerrainGeometryContacts();
125 
129  void collectTerrainContacts(agxSDK::Simulation* simulation);
130 
138  bool raycastTerrainVertexToGeometry(const agxCollide::Geometry* collider, const agx::Vec2i& hfIndex, agx::Real& depth);
139 
145  std::tuple<TerrainIndexToDepthTable, agx::Bound3> findIntersectingIndexInContact(const agxCollide::GeometryContactPtrVector& contacts);
146 
150  TerrainContact* generateTerrainContact(const agxCollide::GeometryContactPtrVector& contacts, agxSDK::Simulation* simulation);
151 
155  const agxCollide::Geometry* getCollider(const agxCollide::GeometryContact* contact) const;
156 
157  protected:
159 
166  {
167  public:
171  ContactReplacer(Terrain* terrain);
172 
177  agxCollide::LocalGeometryContactVector generateTerrainGeometryContacts(const agxCollide::GeometryContactPtrVector& geometryContacts);
178 
182  agxCollide::LocalGeometryContact createGeometryContactFromPoint(
183  const agxCollide::GeometryContact* parentGeometryContact,
184  const agxCollide::ContactPoint* cp,
185  const agx::ContactMaterial* contactContactMaterial,
186  const agx::ContactMaterial* voxelContactMaterial);
187 
188  /*
189  Create a new geometry contact from a contact point in an old geometry contact.
190  */
192  const agx::Vec3& point, const agx::Vec3f& normal, agx::Real depth, agx::Real pointArea, agx::ContactMaterial* cm);
193 
197  agx::ContactMaterial* createContactMaterial(const agx::ContactMaterial* originalCM);
198 
205  agx::Real getModifiedYoungsModuls(const agx::Vec3& position, const agx::ContactMaterial* existingContactMaterial) const;
206 
210  void clearContactMaterialPool();
211 
212  protected:
216  virtual ~ContactReplacer();
217 
218  private:
219  Terrain* m_terrain;
220  agx::Vector<agx::ContactMaterialRef> m_temporaryContactMaterials;
221  agx::Vector<agx::ContactMaterialRef> m_contactMaterialPool;
222  };
223 
224  protected:
228  virtual ~TerrainContactGenerator();
229 
230  void addNeighborIndex(
231  const agx::Vec2i& index, std::queue<agx::Vec2i>& indicesToCheck, agx::HashSet<agx::Vec2i>& visitedIndices) const;
232  void registerContactingGeometry(const agxCollide::Geometry* geometry, agxSDK::Simulation* simulation);
233  void unRegisterContactingGeometry(const agxCollide::Geometry* geometry);
234  void unRegisterGeometriesNotInContact(const agxCollide::GeometryHashSet& geometriesInContact);
235  agx::Real getCurrentContactTime(const agxCollide::Geometry* geometry) const;
236  bool isSoilAggregateContact(agxCollide::GeometryContact* gc) const;
237 
238  private:
240 
241  private:
242  Terrain* m_terrain;
243  ContactReplacerRef m_terrainGeometryContactCreator;
244  agxCollide::GeometryContactPtrVector m_currentContacts;
245  GeometryContactTimeTable m_geometryToContactTime;
246  TerrainContactRefVector m_currentTerrainContacts;
247  };
248 }
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:515
#define AGXTERRAIN_STORE_RESTORE_INTERFACE
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
Class that contains information about a terrain contact between an external object and the terrain ge...
A contact between two geometries.
Definition: Contacts.h:270
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
This class has two main responsibilities:
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
A contact point in a contact data.
Definition: Contacts.h:55
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
Internal class that is used to create new geometry contacts between the terrain and the colliding obj...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
std::queue< agx::Vec2i > IndexQueue