AGX Dynamics  2.38.0.2
TerrainPager.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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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/HashSet.h>
20 #include <agx/HashTable.h>
21 
22 #include <agx/config/AGX_USE_AGXTERRAIN.h>
23 #include <agxTerrain/export.h>
24 
26 
29 
31 
32 namespace agxTerrain
33 {
34 
35  class TerrainCache;
36  class TerrainDataSource;
37 
40 
99  {
100  public:
101 
104 
108 
114 
116  };
117 
119 
144  TerrainPager(size_t tileResolution, size_t tileOverlap, agx::Real tileElementSize, agx::Real maximumDepth,
145  agx::Vec3 refPoint, agx::Quat refRotation,
146  agxTerrain::Terrain* templateTerrain );
147 
148 
155  //void setTerrainPlaneLocation( agx::Vec3 referencePoint, agx::Quat referenceRotation );
156 
161  const TileSpecification& getTileSpecification() const;
162 
163 
167  bool setFileCacheDirectory( agx::String dir );
168 
172  agx::String getFileCacheDirectory() const;
173 
180  void setShouldStoreCompaction(bool shouldStoreCompaction, size_t maximumCompactionDepth);
181 
185  bool getShouldStoreCompaction() const;
186 
195  void setShouldSynchronizeOverlapCompaction( bool shouldSynchronizeCompaction );
196 
200  bool getShouldSynchronizeOverlapCompaction();
201 
208  void setDeformable( bool deformable );
209 
215  inline bool getDeformable() const;
216 
221  void setEmbedCacheFilesInArchive( bool embed );
222 
227  bool getEmbedCacheFilesInArhive() const;
228 
233  void setShouldStoreDeltas(bool shouldStoreDeltas);
234 
238  bool getShouldStoreDeltas();
239 
243  TileAttachmentPtrVector getActiveTileAttachments();
244 
248  SoilSimulationInterface* getSoilSimulationInterface();
249 
255  bool add( agx::RigidBody* body, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
256 
262  bool add( agxTerrain::Shovel* shovel, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
263 
264 
270  bool remove( agx::RigidBody* body );
271 
277  bool remove( agxTerrain::Shovel* shovel );
278 
286  agxTerrain::Terrain* getTemplateTerrain();
287 
293  void applyChangesToTemplateTerrain();
294 
295 
296 
302  bool setTileLoadRadiuses( agx::RigidBody* body, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
303 
308  agx::RealPair getTileLoadRadius( agx::RigidBody* body );
309 
313  TerrainDataSource* getTerrainDataSource();
314 
319  void setTerrainDataSource( TerrainDataSource* tds );
320 
321 
322 
326  virtual void addNotification() override;
327 
331  virtual void removeNotification() override;
332 
333 
334 
338  virtual void preCollide( const agx::TimeStamp& time ) override;
339 
340 
346  virtual void last( const agx::TimeStamp& time ) override;
347 
348 
353 
354  RAYCAST_NO_RESULT, // No hit
355  RAYCAST_HIT_ACTIVE_TERRAIN_TILE, // Hit active paged in tile
356  RAYCAST_RESULT_FROM_DATASOURCE // Hit via TerrainDataSource
357  };
358 
372  TerrainRaycastResult raycast( agx::Vec3 start, agx::Vec3 end, agx::Vec3& result );
373 
374 
375  using StepEventListener::store;
376 
377  using StepEventListener::restore;
378 
382  void store(/*agxStream::StorageStream& str*/agxTerrain::TileModificationVector& storeData);
383 
384 
388  void restore(/*agxStream::StorageStream& str*/ const agxTerrain::TileModificationVector& restoreData);
389 
390 
396 
402 
411  agx::Real getTotalTerrainMass();
412 
416 
417  protected:
421  TerrainPager();
422 
423  virtual ~TerrainPager();
424 
425  void updateActiveTiles();
426 
427  void unloadUnusedTiles( bool partOfRemoveNotification );
428 
429  void handleNewTerrainTile( agxTerrain::TerrainTile );
430 
431  void unloadAllTiles();
432 
433  void prepareSimulation(bool fromRestore);
434 
435  agx::Real getOverlappingAreaSolidMass(agxTerrain::TileId, agxTerrain::TileId);
436 
437  agx::Real getSolidMassBeneathSurfaceCoord(const size_t& x, const size_t& y, agxTerrain::TerrainRef& terrainTile);
438 
439  private:
440  mutable TerrainCache m_cache;
441 
442  TileSpecification m_tileSpec;
443 
444  bool m_shouldStoreDeltas;
445 
446  bool m_justRestored;
447 
448  bool m_shouldSynchronizeCompaction;
449 
450  struct BodyAttachments {
451  agx::RigidBodyObserver m_bodyObserver;
452  agx::Real m_requiredRadius;
453  agx::Real m_preloadRadius;
454  agxTerrain::ShovelRefVector m_shovels;
455  };
456 
457  typedef std::pair<TileId, agx::Vec2i> GlobalTerrainIndex;
458 
459  // Bodies this TerrainPager keeps track of
461 
462  // Tiles this TerrainPager keeps track of
464 
465  // Stores heightfield changes since the last call to the store method
467  //agx::HashTable< TileId, TerrainIndexHeight > m_heightFieldDelta;
468 
470 
471  agx::Vector<agxTerrain::TileId> m_missingRequiredTiles;
472  agx::HashSet<agxTerrain::TileId> m_pendingRequests;
473 
474 
475 
476  void fillTileAttachment( agxTerrain::TerrainTile tile, agxTerrain::TerrainPager::TileAttachments& ta );
477 
478  void getCompactionFromNeighbourTiles(agxTerrain::TerrainTile tile);
479 
480  void fillHeightDelta(const GlobalTerrainIndex& gtid, agx::Real height);
481 
482  };
483 
484 
485  inline void TerrainPager::fillHeightDelta(const GlobalTerrainIndex& gtid, agx::Real height)
486  {
487  m_heightFieldDelta[gtid] = height;
488  }
489 
490 
492  {
493  m_cache.setEmbedCacheFilesInArchive( embed );
494  }
495 
496 
498  {
499  return m_cache.getEmbedCacheFilesInArhive();
500  }
501 
502  inline bool TerrainPager::getDeformable() const
503  {
504  return m_cache.getTemplateTerrain()->getDeformable();
505  }
506 }
507 
agx::end
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
Definition: LinearProbingHashSet.h:593
agxTerrain::Terrain
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:85
agx::Real
double Real
Definition: Real.h:42
agxTerrain::TerrainPager::tileUnloadEvent
TileUnloadEvent tileUnloadEvent
An event that the TerrainPager will trigger just before it removes a tile from the simulation.
Definition: TerrainPager.h:401
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
agxTerrain::TerrainCache
The TerrainCache is used internally by the TerrainPager to provide requested terrain tiles.
Definition: TerrainCache.h:53
agxTerrain::TerrainPager::TileAttachments::m_zOffset
agx::Real m_zOffset
Definition: TerrainPager.h:112
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxTerrain::TerrainPager::TileAttachments::m_unusedCount
agx::UInt32 m_unusedCount
Definition: TerrainPager.h:115
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:58
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
agxTerrain::TileSpecification
A TileSpecification determines where in the world a 2D TileId is located and contains utility methods...
Definition: TileSpecification.h:69
TileSpecification.h
agxTerrain::TerrainPager::TileAttachments
Definition: TerrainPager.h:109
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
HashTable.h
agxTerrain::TerrainCache::getTemplateTerrain
agxTerrain::TerrainRef getTemplateTerrain()
Returns the template terrain used for properties of new terrain tiles.
Definition: TerrainCache.h:384
agx::RealPair
std::pair< Real, Real > RealPair
Definition: ConstraintImplementation.h:68
agxTerrain::Shovel
Definition: Shovel.h:50
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxTerrain::TerrainTile
Struct with data to describe a terrain tile.
Definition: TerrainCache.h:38
agxTerrain::TerrainPager::TileCallback
agx::Callback2< agxTerrain::TileId, agxTerrain::Terrain * > TileCallback
Callback type.
Definition: TerrainPager.h:103
agxTerrain::TerrainPager::TileAttachments::m_terrainTile
agxTerrain::TerrainRef m_terrainTile
Definition: TerrainPager.h:113
StepEventListener.h
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx::VectorPOD< TileModification >
export.h
agx::observer_ptr< RigidBody >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agxTerrain::TerrainPager::TerrainRaycastResult
TerrainRaycastResult
Enum with different types of result from the raycast method.
Definition: TerrainPager.h:352
agxTerrain::TerrainPager::RAYCAST_HIT_ACTIVE_TERRAIN_TILE
@ RAYCAST_HIT_ACTIVE_TERRAIN_TILE
Definition: TerrainPager.h:355
agxTerrain::TerrainPager::TileAttachmentPtrVector
agx::Vector< TerrainPager::TileAttachments * > TileAttachmentPtrVector
Definition: TerrainPager.h:118
agxTerrain::TerrainCache::setEmbedCacheFilesInArchive
void setEmbedCacheFilesInArchive(bool embed)
Sets if cached files written out to disk should be embeded in AGX Archives when store is called.
Definition: TerrainCache.h:401
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agxTerrain::TerrainDataSource
Abstract interface for requesting height data for a Terrain tile.
Definition: TerrainDataSource.h:39
agx::ref_ptr< Terrain >
agxTerrain::TerrainPager::RAYCAST_NO_RESULT
@ RAYCAST_NO_RESULT
Definition: TerrainPager.h:354
agxTerrain::TerrainCache::getEmbedCacheFilesInArhive
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
Definition: TerrainCache.h:406
agxTerrain::TerrainPager::getDeformable
bool getDeformable() const
Gets whether or not deformations are enabled for the tiles managed by this pager.
Definition: TerrainPager.h:502
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:926
agxTerrain::TerrainPager::TileLoadEvent
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * > TileLoadEvent
Event types.
Definition: TerrainPager.h:106
agx::Vec2T
Definition: Vec2Template.h:30
agxTerrain::SoilSimulationInterface
Interface class for accessing data and functions for the internal soil particle simulation used in ag...
Definition: SoilSimulationInterface.h:36
agx::HashSet
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
agx::QuatT< Real >
agxTerrain::TerrainPager::TileAttachments::m_highestPoint
agx::Real m_highestPoint
Definition: TerrainPager.h:111
HashSet.h
TerrainCache.h
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
AGXTERRAIN_EXPORT
#define AGXTERRAIN_EXPORT
Definition: agxTerrain/export.h:41
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
agxTerrain::TerrainPager::TileUnloadEvent
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * > TileUnloadEvent
Definition: TerrainPager.h:107
agxTerrain::TerrainPager::TileAttachments::m_lowestPoint
agx::Real m_lowestPoint
Definition: TerrainPager.h:110
agxTerrain::TerrainPager
A pager that will dynamically handle terrain tiles in a agxSDK::Simulation.
Definition: TerrainPager.h:98
agx::AgXString< std::string >
agxTerrain::TerrainPager::tileLoadEvent
TileLoadEvent tileLoadEvent
An event that the TerrainPager will trigger after a new tile as been loaded and added to the simulati...
Definition: TerrainPager.h:395
agx::Vec3T< Real >
agx::Callback2
Templated callback with two arguments.
Definition: Callback.h:139
agx::UInt32
uint32_t UInt32
Definition: Integer.h:32
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * >
StorageStream.h
agxTerrain::TerrainPager::getEmbedCacheFilesInArhive
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
Definition: TerrainPager.h:497
agxTerrain::TerrainPager::setEmbedCacheFilesInArchive
void setEmbedCacheFilesInArchive(bool embed)
Sets if cached files written out to disk should be embeded in AGX Archives when store is called.
Definition: TerrainPager.h:491