AGX Dynamics  2.37.2.0
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 
193  void setDeformable( bool deformable );
194 
200  inline bool getDeformable() const;
201 
206  void setEmbedCacheFilesInArchive( bool embed );
207 
212  bool getEmbedCacheFilesInArhive() const;
213 
218  void setShouldStoreDeltas(bool shouldStoreDeltas);
219 
223  bool getShouldStoreDeltas();
224 
228  TileAttachmentPtrVector getActiveTileAttachments();
229 
233  SoilSimulationInterface* getSoilSimulationInterface();
234 
240  bool add( agx::RigidBody* body, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
241 
247  bool add( agxTerrain::Shovel* shovel, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
248 
249 
255  bool remove( agx::RigidBody* body );
256 
262  bool remove( agxTerrain::Shovel* shovel );
263 
271  agxTerrain::Terrain* getTemplateTerrain();
272 
278  void applyChangesToTemplateTerrain();
279 
280 
281 
287  bool setTileLoadRadiuses( agx::RigidBody* body, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
288 
293  agx::RealPair getTileLoadRadius( agx::RigidBody* body );
294 
298  TerrainDataSource* getTerrainDataSource();
299 
304  void setTerrainDataSource( TerrainDataSource* tds );
305 
306 
307 
311  virtual void addNotification() override;
312 
316  virtual void removeNotification() override;
317 
318 
319 
323  virtual void preCollide( const agx::TimeStamp& time ) override;
324 
325 
331  virtual void last( const agx::TimeStamp& time ) override;
332 
333 
338 
339  RAYCAST_NO_RESULT, // No hit
340  RAYCAST_HIT_ACTIVE_TERRAIN_TILE, // Hit active paged in tile
341  RAYCAST_RESULT_FROM_DATASOURCE // Hit via TerrainDataSource
342  };
343 
357  TerrainRaycastResult raycast( agx::Vec3 start, agx::Vec3 end, agx::Vec3& result );
358 
359 
360  using StepEventListener::store;
361 
362  using StepEventListener::restore;
363 
367  void store(/*agxStream::StorageStream& str*/agxTerrain::TileModificationVector& storeData);
368 
369 
373  void restore(/*agxStream::StorageStream& str*/ const agxTerrain::TileModificationVector& restoreData);
374 
375 
380  TileLoadEvent tileLoadEvent;
381 
386  TileUnloadEvent tileUnloadEvent;
387 
396  agx::Real getTotalTerrainMass();
397 
401 
402  protected:
406  TerrainPager();
407 
408  virtual ~TerrainPager();
409 
410  void updateActiveTiles();
411 
412  void unloadUnusedTiles( bool partOfRemoveNotification );
413 
414  void handleNewTerrainTile( agxTerrain::TerrainTile );
415 
416  void unloadAllTiles();
417 
418  void prepareSimulation(bool fromRestore);
419 
420  agx::Real getOverlappingAreaSolidMass(agxTerrain::TileId, agxTerrain::TileId);
421 
422  agx::Real getSolidMassBeneathSurfaceCoord(const size_t& x, const size_t& y, agxTerrain::TerrainRef& terrainTile);
423 
424  private:
425  mutable TerrainCache m_cache;
426 
427  TileSpecification m_tileSpec;
428 
429  bool m_shouldStoreDeltas;
430 
431  bool m_justRestored;
432 
433  struct BodyAttachments {
434  //agx::RigidBodyRef m_body;
435  agx::Real m_requiredRadius;
436  agx::Real m_preloadRadius;
437  agxTerrain::ShovelRef m_shovel;
438  };
439 
440  typedef std::pair<TileId, agx::Vec2i> GlobalTerrainIndex;
441 
442  // Bodies this TerrainPager keeps track of
444 
445  // Tiles this TerrainPager keeps track of
447 
448  // Stores heightfield changes since the last call to the store method
450  //agx::HashTable< TileId, TerrainIndexHeight > m_heightFieldDelta;
451 
453 
454  agx::Vector<agxTerrain::TileId> m_missingRequiredTiles;
455  agx::HashSet<agxTerrain::TileId> m_pendingRequests;
456 
457 
458 
459  void fillTileAttachment( agxTerrain::TerrainTile tile, agxTerrain::TerrainPager::TileAttachments& ta );
460 
461  void getCompactionFromNeighbourTiles(agxTerrain::TerrainTile tile);
462 
463  void fillHeightDelta(const GlobalTerrainIndex& gtid, agx::Real height);
464 
465  };
466 
467 
468  inline void TerrainPager::fillHeightDelta(const GlobalTerrainIndex& gtid, agx::Real height)
469  {
470  m_heightFieldDelta[gtid] = height;
471  }
472 
473 
475  {
476  m_cache.setEmbedCacheFilesInArchive( embed );
477  }
478 
479 
481  {
482  return m_cache.getEmbedCacheFilesInArhive();
483  }
484 
485  inline bool TerrainPager::getDeformable() const
486  {
487  return m_cache.getTemplateTerrain()->getDeformable();
488  }
489 }
490 
std::pair< Real, Real > RealPair
Struct with data to describe a terrain tile.
Definition: TerrainCache.h:38
TerrainRaycastResult
Enum with different types of result from the raycast method.
Definition: TerrainPager.h:337
A TileSpecification determines where in the world a 2D TileId is located and contains utility methods...
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
TileLoadEvent tileLoadEvent
An event that the TerrainPager will trigger after a new tile as been loaded and added to the simulati...
Definition: TerrainPager.h:380
Derive from this class to implement a listener for simulation step events.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
TileUnloadEvent tileUnloadEvent
An event that the TerrainPager will trigger just before it removes a tile from the simulation...
Definition: TerrainPager.h:386
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
A pager that will dynamically handle terrain tiles in a agxSDK::Simulation.
Definition: TerrainPager.h:98
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::Real TimeStamp
Definition: TimeStamp.h:26
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
Definition: TerrainPager.h:480
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain *> TileLoadEvent
Event types.
Definition: TerrainPager.h:106
Templated vector class.
Definition: Vector.h:52
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
The TerrainCache is used internally by the TerrainPager to provide requested terrain tiles...
Definition: TerrainCache.h:53
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:474
agx::Callback2< agxTerrain::TileId, agxTerrain::Terrain *> TileCallback
Callback type.
Definition: TerrainPager.h:103
#define AGXTERRAIN_EXPORT
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Templated callback with two arguments.
Definition: Callback.h:139
Interface class for accessing data and functions for the internal soil particle simulation used in ag...
Abstract interface for requesting height data for a Terrain tile.
#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
bool getDeformable() const
Gets whether or not deformations are enabled for the tiles managed by this pager. ...
Definition: TerrainPager.h:485
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain *> TileUnloadEvent
Definition: TerrainPager.h:107
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agx::Vector< TerrainPager::TileAttachments * > TileAttachmentPtrVector
Definition: TerrainPager.h:118
Inheritance with partial specialization due to bug with ref_ptr containers.
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97