AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TerrainPager.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
23 #include <agxTerrain/export.h>
24 
26 
29 
31 
32 namespace agxTerrain
33 {
34 
35  class TerrainCache;
36  class TerrainDataSource;
37 
38 
39 
98  {
99  public:
100 
103 
107 
108 
109 
110 
135  TerrainPager(size_t tileResolution, size_t tileOverlap, agx::Real tileElementSize, agx::Real maximumDepth,
136  agx::Vec3 refPoint, agx::Quat refRotation,
137  agxTerrain::Terrain* templateTerrain );
138 
139 
146  //void setTerrainPlaneLocation( agx::Vec3 referencePoint, agx::Quat referenceRotation );
147 
152  const TileSpecification& getTileSpecification() const;
153 
154 
158  bool setFileCacheDirectory( agx::String dir );
159 
163  agx::String getFileCacheDirectory() const;
164 
171  void setShouldStoreCompaction(bool shouldStoreCompaction, size_t maximumCompactionDepth);
172 
176  bool getShouldStoreCompaction() const;
177 
182  void setEmbedCacheFilesInArchive( bool embed );
183 
188  bool getEmbedCacheFilesInArhive() const;
189 
194  void setShouldStoreDeltas(bool shouldStoreDeltas);
195 
199  bool getShouldStoreDeltas();
200 
201 
202 
208  bool add( agx::RigidBody* body, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
209 
215  bool add( agxTerrain::Shovel* shovel, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
216 
217 
223  bool remove( agx::RigidBody* body );
224 
230  bool remove( agxTerrain::Shovel* shovel );
231 
239  agxTerrain::Terrain* getTemplateTerrain();
240 
246  void applyChangesToTemplateTerrain();
247 
248 
249 
255  bool setTileLoadRadiuses( agx::RigidBody* body, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
256 
261  agx::RealPair getTileLoadRadius( agx::RigidBody* body );
262 
266  TerrainDataSource* getTerrainDataSource();
267 
272  void setTerrainDataSource( TerrainDataSource* tds );
273 
274 
275 
279  virtual void addNotification() override;
280 
284  virtual void removeNotification() override;
285 
286 
287 
291  virtual void preCollide( const agx::TimeStamp& time ) override;
292 
293 
299  virtual void last( const agx::TimeStamp& time ) override;
300 
301 
306 
307  RAYCAST_NO_RESULT, // No hit
308  RAYCAST_HIT_ACTIVE_TERRAIN_TILE, // Hit active paged in tile
309  RAYCAST_RESULT_FROM_DATASOURCE // Hit via TerrainDataSource
310  };
311 
325  TerrainRaycastResult raycast( agx::Vec3 start, agx::Vec3 end, agx::Vec3& result );
326 
327 
328  using StepEventListener::store;
329 
330  using StepEventListener::restore;
331 
335  void store(/*agxStream::StorageStream& str*/agxTerrain::TileModificationVector& storeData);
336 
337 
341  void restore(/*agxStream::StorageStream& str*/ const agxTerrain::TileModificationVector& restoreData);
342 
343 
349 
355 
364  agx::Real getTotalTerrainMass();
365 
369 
370  protected:
374  TerrainPager();
375 
376  virtual ~TerrainPager();
377 
378  void updateActiveTiles();
379 
380  void unloadUnusedTiles( bool partOfRemoveNotification );
381 
382  void handleNewTerrainTile( agxTerrain::TerrainTile );
383 
384  void unloadAllTiles();
385 
386  void prepareSimulation(bool fromRestore);
387 
388  agx::Real getOverlappingAreaSolidMass(agxTerrain::TileId, agxTerrain::TileId);
389 
390  private:
391  mutable TerrainCache m_cache;
392 
393  TileSpecification m_tileSpec;
394 
395  bool m_shouldStoreDeltas;
396 
397  bool m_justRestored;
398 
399  struct BodyAttachments {
400  //agx::RigidBodyRef m_body;
401  agx::Real m_requiredRadius;
402  agx::Real m_preloadRadius;
403  agxTerrain::ShovelRef m_shovel;
404  };
405 
406  struct TileAttachments {
407  agx::Real m_lowestPoint;
408  agx::Real m_highestPoint;
409  agx::Real m_zOffset;
410  agxTerrain::TerrainRef m_terrainTile;
411 
412  agx::UInt32 m_unusedCount;
413  };
414 
415  typedef std::pair<TileId, agx::Vec2i> GlobalTerrainIndex;
416 
417  // Bodies this TerrainPager keeps track of
419 
420  // Tiles this TerrainPager keeps track of
422 
423  // Stores heightfield changes since the last call to the store method
425  //agx::HashTable< TileId, TerrainIndexHeight > m_heightFieldDelta;
426 
428 
429  agx::Vector<agxTerrain::TileId> m_missingRequiredTiles;
430  agx::HashSet<agxTerrain::TileId> m_pendingRequests;
431 
432 
433 
434  void fillTileAttachment( agxTerrain::TerrainTile tile, agxTerrain::TerrainPager::TileAttachments& ta );
435 
436  void getCompactionFromNeighbourTiles(agxTerrain::TerrainTile tile);
437 
438  void fillHeightDelta(const GlobalTerrainIndex& gtid, agx::Real height);
439 
440  };
441 
442 
443  inline void TerrainPager::fillHeightDelta(const GlobalTerrainIndex& gtid, agx::Real height)
444  {
445  m_heightFieldDelta[gtid] = height;
446  }
447 
448 
450  {
451  m_cache.setEmbedCacheFilesInArchive( embed );
452  }
453 
454 
456  {
457  return m_cache.getEmbedCacheFilesInArhive();
458  }
459 
460 
461 }
462 
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:305
A TileSpecification determines where in the world a 2D TileId is located and contains utility methods...
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
Definition: TerrainPager.h:455
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:665
TileLoadEvent tileLoadEvent
An event that the TerrainPager will trigger after a new tile as been loaded and added to the simulati...
Definition: TerrainPager.h:348
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:354
A pager that will dynamically handle terrain tiles in a agxSDK::Simulation.
Definition: TerrainPager.h:97
agx::Real TimeStamp
Definition: TimeStamp.h:26
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * > TileLoadEvent
Event types.
Definition: TerrainPager.h:105
Templated vector class.
Definition: Vector.h:52
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:449
agx::Callback2< agxTerrain::TileId, agxTerrain::Terrain * > TileCallback
Callback type.
Definition: TerrainPager.h:102
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:395
#define AGXTERRAIN_EXPORT
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
Templated callback with two arguments.
Definition: Callback.h:139
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:206
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * > TileUnloadEvent
Definition: TerrainPager.h:106
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
Definition: TerrainCache.h:400
double Real
Definition: Real.h:42
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:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100