AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
TerrainPager.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or
9having been advised so by Algoryx Simulation AB for a time limited evaluation,
10or having purchased a valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
32namespace agxTerrain
33{
34
35 class TerrainCache;
36 class TerrainDataSource;
37
40
99 {
100 public:
101
104
108
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
162
163
168
173
180 void setShouldStoreCompaction(bool shouldStoreCompaction, size_t maximumCompactionDepth);
181
186
195 void setShouldSynchronizeOverlapCompaction( bool shouldSynchronizeCompaction );
196
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
239
244
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
287
294
295
296
302 bool setTileLoadRadiuses( agx::RigidBody* body, agx::Real requiredTileRadius, agx::Real preloadTileRadius );
303
309
314
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
355 RAYCAST_HIT_ACTIVE_TERRAIN_TILE, // Hit active paged in tile
356 RAYCAST_RESULT_FROM_DATASOURCE // Hit via TerrainDataSource
357 };
358
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
412
416
417 protected:
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;
455 };
456
457 typedef std::pair<TileId, agx::Vec2i> GlobalTerrainIndex;
458
459 // Bodies this TerrainPager keeps track of
460 agx::HashTable < agx::RigidBody *, BodyAttachments > m_bodies;
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXTERRAIN_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
Derive from this class to implement a listener for simulation step events.
Interface class for accessing data and functions for the internal soil particle simulation used in ag...
The TerrainCache is used internally by the TerrainPager to provide requested terrain tiles.
void setEmbedCacheFilesInArchive(bool embed)
Sets if cached files written out to disk should be embeded in AGX Archives when store is called.
agxTerrain::TerrainRef getTemplateTerrain()
Returns the template terrain used for properties of new terrain tiles.
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
Abstract interface for requesting height data for a Terrain tile.
A pager that will dynamically handle terrain tiles in a agxSDK::Simulation.
TileUnloadEvent tileUnloadEvent
An event that the TerrainPager will trigger just before it removes a tile from the simulation.
TerrainDataSource * getTerrainDataSource()
Returns the data source the pager uses for fetching height data for tiles.
bool add(agx::RigidBody *body, agx::Real requiredTileRadius, agx::Real preloadTileRadius)
Adds a RigidBody to the terrain pager.
TerrainPager(size_t tileResolution, size_t tileOverlap, agx::Real tileElementSize, agx::Real maximumDepth, agx::Vec3 refPoint, agx::Quat refRotation, agxTerrain::Terrain *templateTerrain)
Constructor.
agx::String getFileCacheDirectory() const
Return the location for where files should be temporary cached when not needed in memory.
const TileSpecification & getTileSpecification() const
Specifies a new reference point for the terrain grid tiles.
agx::Callback2< agxTerrain::TileId, agxTerrain::Terrain * > TileCallback
Callback type.
bool remove(agxTerrain::Shovel *shovel)
Removes a shovel object from the terrain pager, if it exists.
TerrainRaycastResult raycast(agx::Vec3 start, agx::Vec3 end, agx::Vec3 &result)
Perform raycasting against the paged terrain.
agxTerrain::Terrain * getTemplateTerrain()
Fetches the template terrain.
virtual void removeNotification() override
Performs cleanup when removed from the simulation.
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * > TileUnloadEvent
virtual void preCollide(const agx::TimeStamp &time) override
Callback from Simulation.
TileAttachmentPtrVector getActiveTileAttachments()
Returns a vector of the terrains currently tracked by this pager.
void setTerrainDataSource(TerrainDataSource *tds)
Sets the data source that the pager needs to fetch terrain tile data.
void restore(const agxTerrain::TileModificationVector &restoreData)
Restores internal data from stream.
bool setTileLoadRadiuses(agx::RigidBody *body, agx::Real requiredTileRadius, agx::Real preloadTileRadius)
Set tile radiuses for a already added RigidBody.
agx::Real getTotalTerrainMass()
Calculates the total mass of all currently paged in terrain tiles.
bool getDeformable() const
Gets whether or not deformations are enabled for the tiles managed by this pager.
bool getShouldStoreCompaction() const
Returns whether the terrain pager should store compaction data for tiles that are paged out.
bool getShouldSynchronizeOverlapCompaction()
Return whether the terrain pager should synchronize compaction between tiles if shouldStoreCompaction...
agx::Vector< TerrainPager::TileAttachments * > TileAttachmentPtrVector
void setShouldSynchronizeOverlapCompaction(bool shouldSynchronizeCompaction)
Specify whether the terrain pager should synchronize compaction changes in tile overlaps even if shou...
TerrainRaycastResult
Enum with different types of result from the raycast method.
void applyChangesToTemplateTerrain()
Signals to the TerrainPager that the template terrain has been updated and that any changes to the te...
bool add(agxTerrain::Shovel *shovel, agx::Real requiredTileRadius, agx::Real preloadTileRadius)
Adds a Shovel and its RigidBody to the terrain pager.
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
void setShouldStoreDeltas(bool shouldStoreDeltas)
Specify whether the terrain pager should store changes to the terrain every time step.
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * > TileLoadEvent
Event types.
void store(agxTerrain::TileModificationVector &storeData)
Stores internal data into stream.
TileLoadEvent tileLoadEvent
An event that the TerrainPager will trigger after a new tile as been loaded and added to the simulati...
bool remove(agx::RigidBody *body)
Remove body so that the terrain pager no longer uses the body when determining which terrain tiles th...
void setShouldStoreCompaction(bool shouldStoreCompaction, size_t maximumCompactionDepth)
Sets if the terrain pager should store compaction data for tiles that are paged out.
SoilSimulationInterface * getSoilSimulationInterface()
Returns the soil simulation interface used by the terrains tracked by this pager or nullptr if there ...
agx::RealPair getTileLoadRadius(agx::RigidBody *body)
Get the tile readiuses for a body.
bool setFileCacheDirectory(agx::String dir)
Specify the location for there terrain tiles should be stored when cached to disk.
virtual void addNotification() override
Notification to the TerrainPager when being added to a Simulation.
bool getShouldStoreDeltas()
Return whether the terrain pager should store changes to the terrain every time step.
virtual void last(const agx::TimeStamp &time) override
Callback from Simulation.
void setEmbedCacheFilesInArchive(bool embed)
Sets if cached files written out to disk should be embeded in AGX Archives when store is called.
void setDeformable(bool deformable)
Sets if deformation should be enabled for terrains managed by this pager.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition Terrain.h:86
A TileSpecification determines where in the world a 2D TileId is located and contains utility methods...
Templated callback with two arguments.
Definition Callback.h:140
An event with two arguments.
Definition Event.h:122
Inheritance with partial specialization due to bug with ref_ptr containers.
Inheritance with partial specialization due to bug with ref_ptr containers.
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
Templated vector class.
Definition agx/Vector.h:53
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition Geometry.h:59
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition Integer.h:32
double Real
Definition Real.h:42
std::pair< Real, Real > RealPair
agx::Real TimeStamp
Definition TimeStamp.h:26
Struct with data to describe a terrain tile.