AGXDynamics  2.35.0.2
TerrainContactGenerator.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 #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 
97 
102 
103  public:
107 
108  protected:
109 
113  void buildTerrainContacts(agxSDK::Simulation* simulation);
114 
119 
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 
151 
155  const agxCollide::Geometry* getCollider(const agxCollide::GeometryContact* contact) const;
156 
157  protected:
159 
166  {
167  public:
171  ContactReplacer(Terrain* terrain);
172 
178 
183  const agxCollide::ContactPoint* cp,
184  const agx::ContactMaterial* contactMaterial);
185 
186  /*
187  Create a new geometry contact from a contact point in an old geometry contact.
188  */
190  const agx::Vec3& point, const agx::Vec3f& normal, agx::Real depth, agx::Real pointArea, agx::ContactMaterial* cm);
191 
195  agx::ContactMaterial* createContactMaterial(const agx::ContactMaterial* originalCM, const agx::Real& newYoungs);
196 
203  agx::Real getModifiedYoungsModuls(const agx::Vec3& position, const agx::ContactMaterial* existingContactMaterial) const;
204 
209 
210  protected:
214  virtual ~ContactReplacer();
215 
216  private:
217  Terrain* m_terrain;
218  agx::Vector<agx::ContactMaterialRef> m_temporaryContactMaterials;
219  agx::Vector<agx::ContactMaterialRef> m_contactMaterialPool;
220  };
221 
222  protected:
226  virtual ~TerrainContactGenerator();
227 
228  void addNeighborIndex(
229  const agx::Vec2i& index, std::queue<agx::Vec2i>& indicesToCheck, agx::HashSet<agx::Vec2i>& visitedIndices) const;
230  void registerContactingGeometry(const agxCollide::Geometry* geometry, agxSDK::Simulation* simulation);
232  void unRegisterGeometriesNotInContact(const agxCollide::GeometryHashSet& geometriesInContact);
235 
236  private:
238 
239  private:
240  Terrain* m_terrain;
241  ContactReplacerRef m_terrainGeometryContactCreator;
242  agxCollide::GeometryContactPtrVector m_currentContacts;
243  GeometryContactTimeTable m_geometryToContactTime;
244  TerrainContactRefVector m_currentTerrainContacts;
245  };
246 }
AGXTERRAIN_STORE_RESTORE_INTERFACE
#define AGXTERRAIN_STORE_RESTORE_INTERFACE
Definition: agxTerrain/export.h:64
Referenced.h
agxTerrain::TerrainContactGenerator::ContactReplacer::createContactMaterial
agx::ContactMaterial * createContactMaterial(const agx::ContactMaterial *originalCM, const agx::Real &newYoungs)
Generate a new contact material based on a new young's modulus computed from voxel compaction.
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
agxTerrain::TerrainContactGenerator
This class has two main responsibilities:
Definition: TerrainContactGenerator.h:60
agx::Real
double Real
Definition: Real.h:42
agx::Vector< TerrainContactRef >
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:59
agxCollide::LocalGeometryContact
Definition: LocalContactPoint.h:209
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agxTerrain::IndexQueue
std::queue< agx::Vec2i > IndexQueue
Definition: TerrainContactGenerator.h:45
agxTerrain::TerrainContactGenerator::ContactReplacer::clearContactMaterialPool
void clearContactMaterialPool()
Empties the ContactMaterial pool.
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxTerrain::TerrainContactGenerator::findIntersectingIndexInContact
std::tuple< TerrainIndexToDepthTable, agx::Bound3 > findIntersectingIndexInContact(const agxCollide::GeometryContactPtrVector &contacts)
Find the terrain grid indices intersecting with the colliding geometry via ray intersection tests.
agxTerrain::TerrainContactGenerator::raycastTerrainVertexToGeometry
bool raycastTerrainVertexToGeometry(const agxCollide::Geometry *collider, const agx::Vec2i &hfIndex, agx::Real &depth)
Raycast in a terrain index in order to find intersection with a colliding geometry.
agxTerrain::TerrainContactGenerator::ContactReplacer::~ContactReplacer
virtual ~ContactReplacer()
Reference counted object - protected destructor.
agxCollide::ContactPoint
A contact point in a contact data.
Definition: Contacts.h:55
agxTerrain::TerrainContactGenerator::buildTerrainContacts
void buildTerrainContacts(agxSDK::Simulation *simulation)
Build the TerrainContact objects used in compaction calculations.
agx::VectorPOD< GeometryContact * >
agxTerrain::TerrainContactGenerator::~TerrainContactGenerator
virtual ~TerrainContactGenerator()
Reference counted object - protected destructor.
agxTerrain::TerrainContactGenerator::ContactReplacer::ContactReplacer
ContactReplacer(Terrain *terrain)
Default constructor.
export.h
agxTerrain::TerrainContactGenerator::TerrainContactGenerator
TerrainContactGenerator()
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
Vec2.h
agxTerrain::TerrainContact
Class that contains information about a terrain contact between an external object and the terrain ge...
Definition: TerrainContact.h:40
agxTerrain::TerrainContactGenerator::ContactReplacer::generateTerrainGeometryContacts
agxCollide::LocalGeometryContactVector generateTerrainGeometryContacts(const agxCollide::GeometryContactPtrVector &geometryConacts)
Generate new geometry contacts from each contact point in the old geometry contacts.
Vec3.h
agx::ref_ptr< ContactReplacer >
agxTerrain::TerrainContactGenerator::ContactReplacer::getModifiedYoungsModuls
agx::Real getModifiedYoungsModuls(const agx::Vec3 &position, const agx::ContactMaterial *existingContactMaterial) const
Get modified Young's Modulus from depending on the compaction of the voxel of the specified position.
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agxTerrain::TerrainContactGenerator::ContactReplacer::createGeometryContact
agxCollide::LocalGeometryContact createGeometryContact(agxCollide::Geometry *g1, agxCollide::Geometry *g2, const agx::Vec3 &point, const agx::Vec3f &normal, agx::Real depth, agx::Real pointArea, agx::ContactMaterial *cm)
agxTerrain::TerrainContactGenerator::ContactReplacer::createGeometryContactFromPoint
agxCollide::LocalGeometryContact createGeometryContactFromPoint(const agxCollide::GeometryContact *parentGeometryContact, const agxCollide::ContactPoint *cp, const agx::ContactMaterial *contactMaterial)
Create a new geometry contact from a contact point in an old geometry contact.
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Bound.h
agx::Vec2T
Definition: Vec2Template.h:30
agx::ContactMaterial
This class store the combine material properties between two agx::Material's.
Definition: Material.h:527
agxTerrain::TerrainContactGenerator::replaceTerrainGeometryContacts
void replaceTerrainGeometryContacts()
Replaces current geometry contacts with one new for each contact points containing a new Young's Modu...
agxTerrain::TerrainContactGenerator::ContactReplacer
Internal class that is used to create new geometry contacts between the terrain and the colliding obj...
Definition: TerrainContactGenerator.h:165
agxTerrain::TerrainContactGenerator::getTerrainContacts
const TerrainContactRefVector & getTerrainContacts() const
agxTerrain::TerrainContactGenerator::unRegisterContactingGeometry
void unRegisterContactingGeometry(const agxCollide::Geometry *geometry)
agx::HashSet< agx::Vec2i >
HashSet.h
agxTerrain::TerrainContactGenerator::getCurrentContactTime
agx::Real getCurrentContactTime(const agxCollide::Geometry *geometry) const
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::TerrainContactGenerator::updateTerrainContactsWithForceData
void updateTerrainContactsWithForceData()
Update the TerrainContact objects with force data.
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agxTerrain::TerrainContactGenerator::registerContactingGeometry
void registerContactingGeometry(const agxCollide::Geometry *geometry, agxSDK::Simulation *simulation)
agxTerrain::TerrainContactGenerator::onPost
void onPost(agxSDK::Simulation *simulation)
Do post updates for the contact generator.
agxTerrain::TerrainContactGenerator::onRemove
void onRemove(agxSDK::Simulation *simulation)
Do cleanup when removed from the Simulation.
agxCollide::GeometryContact
A contact between two geometries.
Definition: Contacts.h:269
TerrainContact.h
Contacts.h
agxTerrain::TerrainContactGenerator::getCollider
const agxCollide::Geometry * getCollider(const agxCollide::GeometryContact *contact) const
Get the collider geometry in the geometry contact.
agxTerrain::TerrainContactGenerator::collectTerrainContacts
void collectTerrainContacts(agxSDK::Simulation *simulation)
Collect contacts between externally colliding geometries and the terrain (Does not include SoilPartic...
agxTerrain::TerrainContactGenerator::isSoilAggregateContact
bool isSoilAggregateContact(agxCollide::GeometryContact *gc) const
agxTerrain::TerrainContactGenerator::onPre
void onPre(agxSDK::Simulation *simulation)
Do pre updates for the contact generator.
agxTerrain::TerrainContactGenerator::unRegisterGeometriesNotInContact
void unRegisterGeometriesNotInContact(const agxCollide::GeometryHashSet &geometriesInContact)
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agxTerrain::TerrainContactGenerator::generateTerrainContact
TerrainContact * generateTerrainContact(const agxCollide::GeometryContactPtrVector &contacts, agxSDK::Simulation *simulation)
Get the current generated Terrain contacts.
agxTerrain::TerrainContactGenerator::addNeighborIndex
void addNeighborIndex(const agx::Vec2i &index, std::queue< agx::Vec2i > &indicesToCheck, agx::HashSet< agx::Vec2i > &visitedIndices) const
agx::Vec3T< Real >
agx::HashVector< const agxCollide::Geometry *, std::pair< agxCollide::GeometryConstObserver, agx::Real > >
agx_vector_types.h
Material.h