AGX Dynamics  2.37.3.2
TerrainDataInterface.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 #ifndef AGXMODEL_TERRAIN_DATA_INTERFACE_H
18 #define AGXMODEL_TERRAIN_DATA_INTERFACE_H
19 
20 #include <agxModel/export.h>
21 
22 
23 #include <agxCollide/Geometry.h>
24 #include <agxCollide/Contacts.h>
25 #include <agx/Material.h>
26 
27 #include <agx/FrictionModel.h>
28 
29 
30 namespace agxCollide
31 {
32  class HeightField;
33 }
34 
35 namespace agxSDK
36 {
37  class Simulation;
38 }
39 
40 #define MAX_NUMBER_MATERIALS 256
41 
42 namespace agxModel
43 {
44  class Terrain;
45 
51  {
52  public:
54 
55  size_t getLocalVertexIndexWithLargestInfluence() const;
56 
64  agx::Vec2i coordinates[3];
65  agx::Vec2 positions[3];
66 
67  void clear( );
68 
69  };
70 
72 
74 
76 
78 
79  typedef std::pair< agx::ref_ptr<const agx::Material>, agx::ref_ptr<const agx::Material> > ConstMaterialRefPair;
80 
82 
84 
86 
123  {
124  public:
125 
130  TerrainDataInterface( const agxCollide::HeightField* heightField, const agx::Material* defaultTerrainMaterial = nullptr );
131 
140  void add( const agx::Material* material, const size_t materialIndex, const agx::Real particleAdhesion = agx::Real(0), const agx::Real deformability = agx::Real(0), agx::Real angleOfRepose = agx::Real(0) );
141 
145  void remove( const agx::Material* material );
146 
151  virtual void setMaterialMapping( const std::string& filePath );
152 
159  void setMaterialMapping( const size_t x, const size_t y, const size_t materialIndex );
160 
166  void setMaxYoungsChangePerTimestep( agx::Real maxScaleOfYoungsOneTimestep );
167 
172  void setShovelGroundCuttingForce( agx::Real force );
173 
177  agx::Real getShovelGroundCuttingForce() const;
178 
182  SizeTConstMaterialRefPairTable::const_iterator getMaterialIndexBeginIterator() const;
183 
187  SizeTConstMaterialRefPairTable::const_iterator getMaterialIndexEndIterator() const;
188 
196  void addExternalMaterial( agx::Material* material, agx::Real surfaceViscosity = agx::Real(1E-3) );
197 
203  void setParticleFrictionSolveType( agx::FrictionModel::SolveType solveType );
204 
208  agx::FrictionModel::SolveType getParticleFrictionSolveType() const;
209 
213  virtual agx::Real getCompression( size_t x, size_t y ) const;
214 
220  virtual void setCompression( size_t x, size_t y , const agx::Real val );
221 
228  agx::Real getPossibleCompression( agx::Real deformability, agx::Real oldCompression, agx::Real maxYoungsMultiplier );
229 
234  void setMaxCompressionMultiplier( agx::Real maxCompressionMultiplier );
235 
239  agx::Real getMaxCompressionMultiplier() const;
240 
245  void setDepthForMaxCompression( agx::Real depthForMaxCompression );
246 
250  agx::Real getDepthForMaxCompression() const;
251 
259  void setInverseFrictionMultiplier( agx::Real inverseFrictionMultiplier );
260 
264  agx::Real getInverseFrictionMultiplier( ) const;
265 
271  const agx::Material* getParticleMaterial( const size_t x, const size_t y ) const;
272 
277  const agx::Material* getParticleMaterial( const size_t materialIndex ) const;
278 
284  agx::Real getDeformability(const size_t x, const size_t y) const;
285 
291  agx::Real getTanOfTheAngleOfRepose(const size_t x, const size_t y) const;
292 
298  size_t getMaterialIndex(const size_t x, const size_t y) const;
299 
305  const agx::Material* getMaterial(const size_t x, const size_t y) const;
306 
311  const agx::Material* getMaterial(const size_t materialIndex) const;
312 
316  size_t getResolutionX() const;
317 
321  size_t getResolutionY() const;
322 
326  size_t getNumberOfVertices() const;
327 
331  bool isValid() const;
332 
336  size_t getVectorIndex( size_t x, size_t y ) const;
337 
341  void getCoordinates( size_t i, size_t& x, size_t& y ) const;
342 
346  void getCoordinates( size_t i, int& x, int& y ) const;
347 
356  virtual agx::Real calculateYoungsModulus(size_t x, size_t y, agx::Real defaultYoungsModulus, agx::Real deformability, agx::Real localDepth = agx::Real(0)) const;
357 
359 
360  protected:
362 
363  virtual ~TerrainDataInterface();
364 
370  void updateAvalanceHeatMap( const size_t vectorIndex, const size_t value );
371  void updateAvalanceHeatMap( const size_t x, const size_t y, const size_t value );
372 
376  void tickDownAvalancheHeatMap();
377 
378  size_t getAvalancheHeatMapSize();
379 
380  size_t getAvalancheHeatMapValue( const size_t index );
381 
387  virtual agx::MaterialRef createParticleMaterial( const agx::Material* material, const agx::Real particleAdhesion );
388 
389  agx::Real calculateSurfaceViscosity( agx::Real frictionCoefficient );
390 
391  agx::ContactMaterialRef createParticleContactMaterial( agxSDK::Simulation* simulation, const agx::Material* mat1, const agx::Material* mat2, const bool adhesiveForce, agx::Real adhesiveOverlap, agx::Real youngsParticleMultiplier, agx::Real surfaceViscosity = agx::Real(0), agx::FrictionModel::SolveType frictionSolveType = agx::FrictionModel::SPLIT );
392 
393  agx::RigidBodyRefVector& getDynamicHeightFieldParticles();
394 
395  void allocateDynamicHeightFieldParticles( Terrain* terrain);
396 
397  void disableDynamicHeightFieldParticles( size_t numberOfUsedParticles );
398 
399  bool hasParticles();
400 
401  agx::RigidBody* getParticle();
402 
403  void regretParticleFromBack( size_t indexFromBack );
404 
405  //When the height shrinks at a vertex due to digging, the ground below harder, the deltaHeightShrink and the m_depthForMaxCompression parameter
406  //will give a new compression. Also the compression variable tells how much the ground is compressed due to the compressed ground (overlap with geometry)
413  void updateCompression( size_t x, size_t y, agx::Real deltaDiggingHeightShrink, agx::Real compressionFromOverlap );
414 
415  friend class Terrain;
416 
425  virtual const agx::FrictionModel* calculateContactMaterialProperties(
426  ConstContactMaterialVector& contactMaterials, agx::ContactMaterial& newCM, const agx::Real totalYoungsModulus);
427 
437  virtual agx::Real scaleDeformation( agx::Real lastDeformation, agx::Real deformability ) const;
438 
442  void removeExistingParticleParticleContactMaterials( agxSDK::Simulation* simulation );
443 
448  void createContactMaterials( agxSDK::Simulation* simulation, agx::Real adhesiveOverlap, agx::Real particleYoungsMultiplier );
449 
454  void setCompression( agx::Real val);
455 
459  bool getMaterialsAreDirty() const;
460 
464  void clearImpactVolumeData( );
465 
471  static agx::Real compressionMultiplier( agx::Real deformability, agx::Real compression );
472 
476  ImpactVolumeData* getImpactVolumeData( agxCollide::ContactPoint* cp, const Terrain* terrain );
477  bool getData( const agxModel::Terrain* terrain, const agx::Vec3 pos, ImpactVolumeData& ivd ) const;
478  bool getData( const agxModel::Terrain* terrain, const agxCollide::ContactPoint& cp, ImpactVolumeData& ivd ) const;
479  bool getTriangleIndexPoints( const Terrain* terrain, const agx::Vec3 point, ImpactVolumeData& ivd ) const;
480  bool collectNearbyVertices( const Terrain* terrain, ImpactVolumeData& ivd ) const;
481 
482 
483  protected:
484 
485  ImpactVolumeDataRefVector m_impactVolumeDataStorage;
486 
488  SizeTVector m_materialIndexMap;
489  SizeTVector m_avalancheHeatMap;
491 
493 
495 
498 
501 
503 
505 
507 
509 
511 
512  SizeTConstMaterialRefPairTable m_indexToMaterial;
513 
516 
519  };
521 
522 }
523 
524 #endif //AGXMODEL_TERRAIN_DATA_INTERFACE_H
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:515
AGXTERRAIN_EXPORT void clear()
agx::Vector< agx::ref_ptr< const agx::Material > > ConstMaterialRefVector
agx::HashTable< size_t, ConstMaterialRefPair > SizeTConstMaterialRefPairTable
agx::Vector< ImpactVolumeDataRef > ImpactVolumeDataRefVector
ImpactVolumeDataRefVector m_impactVolumeDataStorage
Base class for all friction models with interface and some utility/necessary methods implemented...
Definition: FrictionModel.h:50
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::RealVector m_externalMaterialSurfaceViscosity
agx::RealVector m_materialIndexToTanOfAngleOfRepose
agx::Vector< size_t > SizeTVector
agx::Vector< ImpactVolumeData *> ImpactVolumeDataPtrVector
agx::ref_ptr< TerrainDataInterface > TerrainDataInterfaceRef
Base class providing referencing counted objects.
Definition: Referenced.h:119
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
agx::ref_ptr< ImpactVolumeData > ImpactVolumeDataRef
SizeTConstMaterialRefPairTable m_indexToMaterial
std::pair< agx::ref_ptr< const agx::Material >, agx::ref_ptr< const agx::Material > > ConstMaterialRefPair
agx::Vector< const agx::ContactMaterial *> ConstContactMaterialVector
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxCollide::ContactPoint * contactPoint
ConstMaterialRefVector m_externalMaterialsInteractingWithParticles
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
agx::RigidBodyRefVector m_dynamicHeightFieldParticles
This class implements an interface for how the terrain accesses the data it needs to access data item...
First Normal equation is calculated in the DIRECT solver, then in a second pass the normal and the fr...
Definition: FrictionModel.h:60
agx::FrictionModel::SolveType m_particleFrictionSolveType
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
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
#define AGXMODEL_EXPORT
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
A HeightField is a collision shape that can be created from a grid structure, like an image...