AGXDynamics
2.35.0.3
TerrainPager.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
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
25
#include <
agxSDK/StepEventListener.h
>
26
27
#include <
agxTerrain/TileSpecification.h
>
28
#include <
agxTerrain/TerrainCache.h
>
29
30
#include <
agxStream/StorageStream.h
>
31
32
namespace
agxTerrain
33
{
34
35
class
TerrainCache;
36
class
TerrainDataSource;
37
38
39
97
class
AGXTERRAIN_EXPORT
TerrainPager
:
public
agxSDK::StepEventListener
98
{
99
public
:
100
102
typedef
agx::Callback2< agxTerrain::TileId, agxTerrain::Terrain* >
TileCallback
;
103
105
typedef
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain* >
TileLoadEvent
;
106
typedef
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain* >
TileUnloadEvent
;
107
108
struct
TileAttachments
{
109
agx::Real
m_lowestPoint
;
110
agx::Real
m_highestPoint
;
111
agx::Real
m_zOffset
;
112
agxTerrain::TerrainRef
m_terrainTile
;
113
114
agx::UInt32
m_unusedCount
;
115
};
116
117
typedef
agx::Vector<TerrainPager::TileAttachments*>
TileAttachmentPtrVector
;
118
143
TerrainPager
(
size_t
tileResolution,
size_t
tileOverlap,
agx::Real
tileElementSize,
agx::Real
maximumDepth,
144
agx::Vec3
refPoint,
agx::Quat
refRotation,
145
agxTerrain::Terrain
* templateTerrain );
146
147
154
//void setTerrainPlaneLocation( agx::Vec3 referencePoint, agx::Quat referenceRotation );
155
160
const
TileSpecification
& getTileSpecification()
const
;
161
162
166
bool
setFileCacheDirectory(
agx::String
dir );
167
171
agx::String
getFileCacheDirectory()
const
;
172
179
void
setShouldStoreCompaction(
bool
shouldStoreCompaction,
size_t
maximumCompactionDepth);
180
184
bool
getShouldStoreCompaction()
const
;
185
192
void
setDeformable(
bool
deformable );
193
199
inline
bool
getDeformable()
const
;
200
205
void
setEmbedCacheFilesInArchive(
bool
embed );
206
211
bool
getEmbedCacheFilesInArhive()
const
;
212
217
void
setShouldStoreDeltas(
bool
shouldStoreDeltas);
218
222
bool
getShouldStoreDeltas();
223
227
TileAttachmentPtrVector
getActiveTileAttachments();
228
232
SoilSimulationInterface
* getSoilSimulationInterface();
233
239
bool
add(
agx::RigidBody
* body,
agx::Real
requiredTileRadius,
agx::Real
preloadTileRadius );
240
246
bool
add(
agxTerrain::Shovel
* shovel,
agx::Real
requiredTileRadius,
agx::Real
preloadTileRadius );
247
248
254
bool
remove(
agx::RigidBody
* body );
255
261
bool
remove(
agxTerrain::Shovel
* shovel );
262
270
agxTerrain::Terrain
* getTemplateTerrain();
271
277
void
applyChangesToTemplateTerrain();
278
279
280
286
bool
setTileLoadRadiuses(
agx::RigidBody
* body,
agx::Real
requiredTileRadius,
agx::Real
preloadTileRadius );
287
292
agx::RealPair
getTileLoadRadius(
agx::RigidBody
* body );
293
297
TerrainDataSource
* getTerrainDataSource();
298
303
void
setTerrainDataSource(
TerrainDataSource
* tds );
304
305
306
310
virtual
void
addNotification()
override
;
311
315
virtual
void
removeNotification()
override
;
316
317
318
322
virtual
void
preCollide(
const
agx::TimeStamp
& time )
override
;
323
324
330
virtual
void
last(
const
agx::TimeStamp
& time )
override
;
331
332
336
enum
TerrainRaycastResult
{
337
338
RAYCAST_NO_RESULT
,
// No hit
339
RAYCAST_HIT_ACTIVE_TERRAIN_TILE
,
// Hit active paged in tile
340
RAYCAST_RESULT_FROM_DATASOURCE
// Hit via TerrainDataSource
341
};
342
356
TerrainRaycastResult raycast(
agx::Vec3
start,
agx::Vec3
end
,
agx::Vec3
& result );
357
358
359
using
StepEventListener::store;
360
361
using
StepEventListener::restore;
362
366
void
store(
/*agxStream::StorageStream& str*/
agxTerrain::TileModificationVector
& storeData);
367
368
372
void
restore(
/*agxStream::StorageStream& str*/
const
agxTerrain::TileModificationVector
& restoreData);
373
374
379
TileLoadEvent
tileLoadEvent
;
380
385
TileUnloadEvent
tileUnloadEvent
;
386
395
agx::Real
getTotalTerrainMass();
396
397
DOXYGEN_START_INTERNAL_BLOCK
()
398
AGXSTREAM_DECLARE_SERIALIZABLE
(
agxTerrain
::
TerrainPager
);
399
DOXYGEN_END_INTERNAL_BLOCK
()
400
401
protected:
405
TerrainPager
();
406
407
virtual ~
TerrainPager
();
408
409
void
updateActiveTiles();
410
411
void
unloadUnusedTiles(
bool
partOfRemoveNotification );
412
413
void
handleNewTerrainTile(
agxTerrain
::
TerrainTile
);
414
415
void
unloadAllTiles();
416
417
void
prepareSimulation(
bool
fromRestore);
418
419
agx
::
Real
getOverlappingAreaSolidMass(
agxTerrain
::
TileId
,
agxTerrain
::
TileId
);
420
421
private:
422
mutable
TerrainCache
m_cache;
423
424
TileSpecification
m_tileSpec;
425
426
bool
m_shouldStoreDeltas;
427
428
bool
m_justRestored;
429
430
struct BodyAttachments {
431
//agx::RigidBodyRef m_body;
432
agx::Real
m_requiredRadius;
433
agx::Real
m_preloadRadius;
434
agxTerrain::ShovelRef
m_shovel;
435
};
436
437
typedef
std::pair<TileId, agx::Vec2i> GlobalTerrainIndex;
438
439
// Bodies this TerrainPager keeps track of
440
agx::HashTable< agx::RigidBody*, BodyAttachments >
m_bodies;
441
442
// Tiles this TerrainPager keeps track of
443
agx::HashTable< TileId, TileAttachments >
m_terrainTiles;
444
445
// Stores heightfield changes since the last call to the store method
446
agx::HashTable< GlobalTerrainIndex, agx::Real >
m_heightFieldDelta;
447
//agx::HashTable< TileId, TerrainIndexHeight > m_heightFieldDelta;
448
449
agx::Physics::GranularBodySystemRef
m_gbs;
450
451
agx::Vector<agxTerrain::TileId>
m_missingRequiredTiles;
452
agx::HashSet<agxTerrain::TileId>
m_pendingRequests;
453
454
455
456
void
fillTileAttachment(
agxTerrain::TerrainTile
tile,
agxTerrain::TerrainPager::TileAttachments
& ta );
457
458
void
getCompactionFromNeighbourTiles(
agxTerrain::TerrainTile
tile);
459
460
void
fillHeightDelta(
const
GlobalTerrainIndex& gtid,
agx::Real
height);
461
462
};
463
464
465
inline
void
TerrainPager::fillHeightDelta(
const
GlobalTerrainIndex& gtid,
agx::Real
height)
466
{
467
m_heightFieldDelta[gtid] = height;
468
}
469
470
471
inline
void
TerrainPager::setEmbedCacheFilesInArchive
(
bool
embed )
472
{
473
m_cache.
setEmbedCacheFilesInArchive
( embed );
474
}
475
476
477
inline
bool
TerrainPager::getEmbedCacheFilesInArhive
()
const
478
{
479
return
m_cache.
getEmbedCacheFilesInArhive
();
480
}
481
482
inline
bool
TerrainPager::getDeformable
()
const
483
{
484
return
m_cache.
getTemplateTerrain
()->getDeformable();
485
}
486
}
487
agx::end
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
Definition:
LinearProbingHashSet.h:612
agxTerrain::Terrain
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition:
agxTerrain/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:385
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:111
agx::Vector
Templated vector class.
Definition:
Vector.h:52
agxTerrain::TerrainPager::TileAttachments::m_unusedCount
agx::UInt32 m_unusedCount
Definition:
TerrainPager.h:114
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition:
Geometry.h:59
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition:
RigidBody.h:54
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:108
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:378
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:102
agxTerrain::TerrainPager::TileAttachments::m_terrainTile
agxTerrain::TerrainRef m_terrainTile
Definition:
TerrainPager.h:112
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
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:336
agxTerrain::TerrainPager::RAYCAST_HIT_ACTIVE_TERRAIN_TILE
@ RAYCAST_HIT_ACTIVE_TERRAIN_TILE
Definition:
TerrainPager.h:339
agxTerrain::TerrainPager::TileAttachmentPtrVector
agx::Vector< TerrainPager::TileAttachments * > TileAttachmentPtrVector
Definition:
TerrainPager.h:117
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:395
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:338
agxTerrain::TerrainCache::getEmbedCacheFilesInArhive
bool getEmbedCacheFilesInArhive() const
Returns if cached files should be embedded in AGX Archives used for serialization.
Definition:
TerrainCache.h:400
agxTerrain::TerrainPager::getDeformable
bool getDeformable() const
Gets whether or not deformations are enabled for the tiles managed by this pager.
Definition:
TerrainPager.h:482
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition:
LinearProbingHashTable.h:871
agxTerrain::TerrainPager::TileLoadEvent
agx::Event2< agxTerrain::TileId, agxTerrain::Terrain * > TileLoadEvent
Event types.
Definition:
TerrainPager.h:105
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:665
agx::QuatT< Real >
agxTerrain::TerrainPager::TileAttachments::m_highestPoint
agx::Real m_highestPoint
Definition:
TerrainPager.h:110
HashSet.h
TerrainCache.h
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:106
agxTerrain::TerrainPager::TileAttachments::m_lowestPoint
agx::Real m_lowestPoint
Definition:
TerrainPager.h:109
agxTerrain::TerrainPager
A pager that will dynamically handle terrain tiles in a agxSDK::Simulation.
Definition:
TerrainPager.h:97
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:379
agx::Vec3T< Real >
agx::Callback2
Templated callback with two arguments.
Definition:
Callback.h:139
agx::UInt32
uint32_t UInt32
Definition:
Integer.h:40
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:477
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:471
include
agxTerrain
TerrainPager.h
Generated on Fri Feb 10 2023 14:06:19 for AGXDynamics by
1.8.17