AGX Dynamics  2.35.0.1
TerrainDataInterface.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 #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 
56 
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 
173 
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 
204 
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 
240 
245  void setDepthForMaxCompression( agx::Real depthForMaxCompression );
246 
251 
259  void setInverseFrictionMultiplier( agx::Real inverseFrictionMultiplier );
260 
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 
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 
377 
379 
380  size_t getAvalancheHeatMapValue( const size_t index );
381 
387  virtual agx::MaterialRef createParticleMaterial( const agx::Material* material, const agx::Real particleAdhesion );
388 
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 
394 
396 
397  void disableDynamicHeightFieldParticles( size_t numberOfUsedParticles );
398 
399  bool hasParticles();
400 
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 
426  ConstContactMaterialVector& contactMaterials, agx::ContactMaterial& newCM, const agx::Real totalYoungsModulus);
427 
437  virtual agx::Real scaleDeformation( agx::Real lastDeformation, agx::Real deformability ) const;
438 
443 
448  void createContactMaterials( agxSDK::Simulation* simulation, agx::Real adhesiveOverlap, agx::Real particleYoungsMultiplier );
449 
455 
459  bool getMaterialsAreDirty() const;
460 
465 
471  static agx::Real compressionMultiplier( agx::Real deformability, agx::Real compression );
472 
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 
486 
491 
493 
495 
498 
501 
503 
505 
507 
509 
511 
513 
516 
519  };
521 
522 }
523 
524 #endif //AGXMODEL_TERRAIN_DATA_INTERFACE_H
#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
#define AGXMODEL_EXPORT
A contact point in a contact data.
Definition: Contacts.h:56
A HeightField is a collision shape that can be created from a grid structure, like an image.
agxCollide::ContactPoint * contactPoint
size_t getLocalVertexIndexWithLargestInfluence() const
This class implements an interface for how the terrain accesses the data it needs to access data item...
size_t getMaterialIndex(const size_t x, const size_t y) const
void remove(const agx::Material *material)
Removes a material from the terrain.
void updateCompression(size_t x, size_t y, agx::Real deltaDiggingHeightShrink, agx::Real compressionFromOverlap)
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))
Adds a material to the terrain.
virtual agx::Real calculateYoungsModulus(size_t x, size_t y, agx::Real defaultYoungsModulus, agx::Real deformability, agx::Real localDepth=agx::Real(0)) const
Calculate the YoungsModulus value for a given grid point.
agx::Real calculateSurfaceViscosity(agx::Real frictionCoefficient)
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)
TerrainDataInterface(const agxCollide::HeightField *heightField, const agx::Material *defaultTerrainMaterial=nullptr)
agx::RigidBody * getParticle()
void setMaxCompressionMultiplier(agx::Real maxCompressionMultiplier)
Set how much harder than default Young's modulus the ground can get by being compressed?
SizeTConstMaterialRefPairTable::const_iterator getMaterialIndexEndIterator() const
Returns end iterator to the materials on this terrain.
bool getData(const agxModel::Terrain *terrain, const agxCollide::ContactPoint &cp, ImpactVolumeData &ivd) const
bool getData(const agxModel::Terrain *terrain, const agx::Vec3 pos, ImpactVolumeData &ivd) const
virtual agx::MaterialRef createParticleMaterial(const agx::Material *material, const agx::Real particleAdhesion)
void createContactMaterials(agxSDK::Simulation *simulation, agx::Real adhesiveOverlap, agx::Real particleYoungsMultiplier)
Create contact materials for everything interacting with particles (including particle-particle conta...
size_t getNumberOfVertices() const
agx::RealVector m_materialIndexToTanOfAngleOfRepose
agx::Real getInverseFrictionMultiplier() const
returns the inverse friction multiplier.
const agx::Material * getParticleMaterial(const size_t materialIndex) const
const agx::Material * getParticleMaterial(const size_t x, const size_t y) const
void updateAvalanceHeatMap(const size_t x, const size_t y, const size_t value)
void disableDynamicHeightFieldParticles(size_t numberOfUsedParticles)
void tickDownAvalancheHeatMap()
integrate heat map
agx::Real getShovelGroundCuttingForce() const
agx::RigidBodyRefVector & getDynamicHeightFieldParticles()
void clearImpactVolumeData()
Resets the number of impactVolumeDatas used.
SizeTConstMaterialRefPairTable::const_iterator getMaterialIndexBeginIterator() const
Returns begin iterator to the materials on this terrain.
ConstMaterialRefVector m_externalMaterialsInteractingWithParticles
void setMaxYoungsChangePerTimestep(agx::Real maxScaleOfYoungsOneTimestep)
Due to high velocities we may have deep Terrain penetrations.
void removeExistingParticleParticleContactMaterials(agxSDK::Simulation *simulation)
Clear existing contact materials created for particles.
virtual agx::Real getCompression(size_t x, size_t y) const
void addExternalMaterial(agx::Material *material, agx::Real surfaceViscosity=agx::Real(1E-3))
Add an external material to the terrain.
ImpactVolumeData * getImpactVolumeData(agxCollide::ContactPoint *cp, const Terrain *terrain)
Calculates ImpactVolumeData from a given contact point.
virtual const agx::FrictionModel * calculateContactMaterialProperties(ConstContactMaterialVector &contactMaterials, agx::ContactMaterial &newCM, const agx::Real totalYoungsModulus)
Uses all found contactMaterials for a geometry contact, and creates a temporary contact material.
void setMaterialMapping(const size_t x, const size_t y, const size_t materialIndex)
Maps materials to grid points.
agx::Real getDepthForMaxCompression() const
const agx::Material * getMaterial(const size_t materialIndex) const
agx::Real getPossibleCompression(agx::Real deformability, agx::Real oldCompression, agx::Real maxYoungsMultiplier)
void allocateDynamicHeightFieldParticles(Terrain *terrain)
void setShovelGroundCuttingForce(agx::Real force)
When a shovel is cutting through the terrain, the user has the ability to set a minimum force that is...
size_t getVectorIndex(size_t x, size_t y) const
const agx::Material * getMaterial(const size_t x, const size_t y) const
static agx::Real compressionMultiplier(agx::Real deformability, agx::Real compression)
Calculate a multiplier for how much harder the ground gets given a compression and its deformability.
size_t getAvalancheHeatMapValue(const size_t index)
ImpactVolumeDataRefVector m_impactVolumeDataStorage
void setDepthForMaxCompression(agx::Real depthForMaxCompression)
Set the depth for maximum compression.
agx::RigidBodyRefVector m_dynamicHeightFieldParticles
void updateAvalanceHeatMap(const size_t vectorIndex, const size_t value)
Set the number of time steps left for avalanches at a vertex.
virtual void setCompression(size_t x, size_t y, const agx::Real val)
Set the compression at a specified grid point (x,y)
bool getMaterialsAreDirty() const
returns true if DEFORMABILITY or YOUNGS_SCALER has been set
void setInverseFrictionMultiplier(agx::Real inverseFrictionMultiplier)
Set the inverse friction multiplier.
void regretParticleFromBack(size_t indexFromBack)
virtual void setMaterialMapping(const std::string &filePath)
Maps materials to grid points.
void getCoordinates(size_t i, int &x, int &y) const
Get the x,y coordinate of the i:th point in the grid (starting from 0,0)
void setParticleFrictionSolveType(agx::FrictionModel::SolveType solveType)
Set the solve type of the particles when they interact with each other.
agx::RealVector m_externalMaterialSurfaceViscosity
virtual agx::Real scaleDeformation(agx::Real lastDeformation, agx::Real deformability) const
2^( 1 + lastDeformation * deformability ) = newYoungs / lastYoungs we have set maxvalue of RHS
bool getTriangleIndexPoints(const Terrain *terrain, const agx::Vec3 point, ImpactVolumeData &ivd) const
SizeTConstMaterialRefPairTable m_indexToMaterial
bool collectNearbyVertices(const Terrain *terrain, ImpactVolumeData &ivd) const
agx::Real getMaxCompressionMultiplier() const
agx::Real getDeformability(const size_t x, const size_t y) const
agx::Real getTanOfTheAngleOfRepose(const size_t x, const size_t y) const
void getCoordinates(size_t i, size_t &x, size_t &y) const
Get the x,y coordinate of the i:th point in the grid (starting from 0,0)
agx::FrictionModel::SolveType getParticleFrictionSolveType() const
void setCompression(agx::Real val)
Set the deformation at all grid points.
agx::FrictionModel::SolveType m_particleFrictionSolveType
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
This class store the combine material properties between two agx::Material's.
Definition: Material.h:528
Base class for all friction models with interface and some utility/necessary methods implemented.
Definition: FrictionModel.h:51
@ SPLIT
First Normal equation is calculated in the DIRECT solver, then in a second pass the normal and the fr...
Definition: FrictionModel.h:60
Inheritance with partial specialization due to bug with ref_ptr containers.
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:388
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:37
agx::ref_ptr< TerrainDataInterface > TerrainDataInterfaceRef
agx::Vector< const agx::ContactMaterial * > ConstContactMaterialVector
agx::ref_ptr< ImpactVolumeData > ImpactVolumeDataRef
std::pair< agx::ref_ptr< const agx::Material >, agx::ref_ptr< const agx::Material > > ConstMaterialRefPair
agx::Vector< size_t > SizeTVector
agx::HashTable< size_t, ConstMaterialRefPair > SizeTConstMaterialRefPairTable
agx::Vector< ImpactVolumeDataRef > ImpactVolumeDataRefVector
agx::Vector< agx::ref_ptr< const agx::Material > > ConstMaterialRefVector
agx::Vector< ImpactVolumeData * > ImpactVolumeDataPtrVector
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
double Real
Definition: Real.h:42