AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
agxTerrain::TerrainDataSource Class Referenceabstract

Abstract interface for requesting height data for a Terrain tile. More...

#include <TerrainDataSource.h>

+ Inheritance diagram for agxTerrain::TerrainDataSource:

Public Types

typedef agx::RealVector TerrainHeightType
 Datatype used for returning height values.
 
typedef std::pair< agxCollide::Geometry *, agxTerrain::TerrainMaterial * > TerrainMaterialDomain
 
typedef agx::Vector< TerrainMaterialDomain > TerrainMaterialDomainVector
 

Public Member Functions

bool addTerrainMaterial (agxTerrain::TerrainMaterial *terrainMaterial)
 Add a TerrainMaterial to the TerrainDataSource, without designating where it is.
 
bool addTerrainMaterial (agxTerrain::TerrainMaterial *terrainMaterial, agxCollide::Geometry *geometry)
 Add a source geometry for the given TerrainMaterial.
 
 AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE (agxTerrain::TerrainDataSource)
 
bool exchangeTerrainMaterial (agxTerrain::TerrainMaterial *oldTerrainMaterial, agxTerrain::TerrainMaterial *newTerrainMaterial)
 Swap out an already added TerrainMaterial for another.
 
virtual TerrainMaterialDomainVector fetchTerrainMaterials (const TileSpecification &ts, agxTerrain::TileId id, agx::Real maxHeight)
 Return assigned terrain material patches in the requested tile.
 
virtual TerrainHeightType fetchTerrainTile (const TileSpecification &ts, agxTerrain::TileId id)=0
 Return height data for requested tile according to the TileSpecification.
 
agx::Material * getAssociatedMaterial (agxTerrain::TerrainMaterial *terrainMaterial)
 
agx::Vector< agx::Material * > getAssociatedMaterials ()
 
const agxCollide::GeometryRefVector & getSourceGeometries ()
 
const agx::HashTable< agxCollide::Geometry *, agxTerrain::TerrainMaterial * > & getTerrainMaterialLookup ()
 
MaterialPairVector getTerrainMaterialPairs ()
 
agx::Vector< agxTerrain::TerrainMaterial * > getTerrainMaterials ()
 
bool isDirty () const
 
virtual void onReset ()
 Let the external dataSource know we're doing a reset of the terrain so it can reset as well.
 
virtual bool raycast (agx::Vec3 start, agx::Vec3 end, agx::Vec3 &raycastResult)
 Perform raycasting against the terrain.
 
bool removeTerrainMaterial (agxTerrain::TerrainMaterial *terrainMaterial)
 Remove the specified TerrainMaterial from the TerrainDataSource.
 
virtual void restore (agxStream::InputArchive &in) override
 
bool setAssociatedMaterial (agx::Material *associatedMaterial, agxTerrain::TerrainMaterial *terrainMaterial)
 Set the associated Material to a given TerrainMaterial.
 
void setDefaultTerrainMaterial (agxTerrain::TerrainMaterial *terrainMaterial)
 Set the default terrain material for the terrain data source.
 
void setDirty (bool dirty)
 
virtual void store (agxStream::OutputArchive &out) const override
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor.
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting.
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match.
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test.
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object.
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 
- Public Member Functions inherited from agxStream::Serializable
virtual ~Serializable ()
 Destructor for normal C++ use but hidden from SWIG bindings.
 
virtual const char * getClassName () const
 
bool getEnableSerialization () const
 
bool getEnableUuidGeneration ()
 
agx::UInt32 getIndex () const
 This index is given at creation of this object.
 
virtual StorageAgent * getStorageAgent () const =0
 
agx::Uuid getUuid () const
 
bool isFinished () const
 
void setEnableSerialization (bool flag)
 Set to false to disable serialization of this object.
 
void setFinished ()
 Tells this class that it is restored correctly and should not be deleted during destruction of an Archive.
 
void setUuid (const agx::Uuid &uuid)
 Explicitly set a Uuid on a serializable object.
 

Protected Attributes

bool m_dirty = false
 
TerrainMaterialLookup m_lookupTerrainMaterial
 
agx::ReaderWriterLock m_rwLock
 
agxCollide::GeometryRefVector m_terrainMaterialGeometries
 
agxTerrain::MaterialPairVector m_terrainMaterialsAndAssociatedMaterials
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Additional Inherited Members

- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- Static Public Member Functions inherited from agxStream::Serializable
static void setEnableUuidGeneration (bool flag)
 Specify if there should be UUID:s generated for each new Serializable object. By default it is enabled.
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor.
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
- Protected Member Functions inherited from agxStream::Serializable
 Serializable ()
 Default constructor.
 
 Serializable (const Serializable &other)
 Copy constructor.
 
void generateUuid ()
 
- Static Protected Member Functions inherited from agx::Referenced
static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.
 

Detailed Description

Abstract interface for requesting height data for a Terrain tile.

Definition at line 44 of file TerrainDataSource.h.

Member Typedef Documentation

◆ TerrainHeightType

Datatype used for returning height values.

Definition at line 52 of file TerrainDataSource.h.

◆ TerrainMaterialDomain

◆ TerrainMaterialDomainVector

Member Function Documentation

◆ addTerrainMaterial() [1/2]

bool agxTerrain::TerrainDataSource::addTerrainMaterial ( agxTerrain::TerrainMaterial *  terrainMaterial)

Add a TerrainMaterial to the TerrainDataSource, without designating where it is.

This is necessary for the TerrainPager to be able to set

Parameters
terrainMaterial- the TerrainMaterial that should be added to the TerrainDataSource.
Returns
true if the terrainMaterial could be added to the TerrainDataSource. False otherwise (the terrainMaterial was nullptr or already added).

◆ addTerrainMaterial() [2/2]

bool agxTerrain::TerrainDataSource::addTerrainMaterial ( agxTerrain::TerrainMaterial *  terrainMaterial,
agxCollide::Geometry *  geometry 
)

Add a source geometry for the given TerrainMaterial.

If the TerrainMaterial isn't in the TerrainDataSource, it will be added (see addTerrainMaterial). New tiles will load the specified terrain material if they overlap with the geometry.

Returns
true if the terrain material could be set, false if either terrainMaterial or geometry were nullptr or if geometry was already used to assign another domain.

◆ AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE()

agxTerrain::TerrainDataSource::AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE ( agxTerrain::TerrainDataSource  )

◆ exchangeTerrainMaterial()

bool agxTerrain::TerrainDataSource::exchangeTerrainMaterial ( agxTerrain::TerrainMaterial *  oldTerrainMaterial,
agxTerrain::TerrainMaterial *  newTerrainMaterial 
)

Swap out an already added TerrainMaterial for another.

The new terrain material will keep the old terrain materials associated material.

Returns
true if the oldTerrainMaterial could be swapped for the newTerrainMaterial. False otherwise.

◆ fetchTerrainMaterials()

virtual TerrainMaterialDomainVector agxTerrain::TerrainDataSource::fetchTerrainMaterials ( const TileSpecification &  ts,
agxTerrain::TileId  id,
agx::Real  maxHeight 
)
virtual

Return assigned terrain material patches in the requested tile.

The assignment of the TerrainMaterial It is possible to override this method in a custom implementation of a TerrainDataSource, just make sure that any returned TerrainMaterial* in the TerrainMaterialDomain has been added to the TerrainDataSource (via either of the addTerrainMaterial methods) before the fetchTerrainMaterials returns the TerrainMaterialDomainVector.

Parameters
ts- The specification of how new tiles are created by the data source
id- The id or position of the tile relative to other paged terrain tiles
maxHeight- The maximum sampling height of the tile. terrain materials beneath this value will not be added to the simulation.

◆ fetchTerrainTile()

virtual TerrainHeightType agxTerrain::TerrainDataSource::fetchTerrainTile ( const TileSpecification &  ts,
agxTerrain::TileId  id 
)
pure virtual

Return height data for requested tile according to the TileSpecification.

The returned vector should have ts.getTileResolution squared number of height values. If the TerrainDataSource is not able to provide data, an empty vector can be returned.

Upon no data returned, the TerrainCache will reply to the TerrainPager with the requested TileId id but having no terrain instance signaling that the request was processed but could not be fullfilled. In this scenario, there will be an empty tile where it should have been a terrain instance and the same tile will be requested again on the next stepForward.

Parameters
ts- The specification of how new tiles are created by the data source
id- The id or position of the tile relative to other paged terrain tiles
Returns
A vector containing the height data for the new tile

Implemented in agxTerrain::TerrainRasterizer, and agxTerrain::ExternalTerrainDataSource.

◆ getAssociatedMaterial()

agx::Material * agxTerrain::TerrainDataSource::getAssociatedMaterial ( agxTerrain::TerrainMaterial *  terrainMaterial)
Returns
the associated Material to a specific TerrainMaterial. Will return nullptr if there is no associated material or the terrain material is not added.

◆ getAssociatedMaterials()

agx::Vector< agx::Material * > agxTerrain::TerrainDataSource::getAssociatedMaterials ( )
Returns
the associated materials to the terrain materials added to this TerrainDataSource.

◆ getSourceGeometries()

const agxCollide::GeometryRefVector & agxTerrain::TerrainDataSource::getSourceGeometries ( )

◆ getTerrainMaterialLookup()

const agx::HashTable< agxCollide::Geometry *, agxTerrain::TerrainMaterial * > & agxTerrain::TerrainDataSource::getTerrainMaterialLookup ( )

◆ getTerrainMaterialPairs()

MaterialPairVector agxTerrain::TerrainDataSource::getTerrainMaterialPairs ( )

◆ getTerrainMaterials()

agx::Vector< agxTerrain::TerrainMaterial * > agxTerrain::TerrainDataSource::getTerrainMaterials ( )
Returns
the terrain materials added to this TerrainDataSource.

◆ isDirty()

bool agxTerrain::TerrainDataSource::isDirty ( ) const

◆ onReset()

virtual void agxTerrain::TerrainDataSource::onReset ( )
virtual

Let the external dataSource know we're doing a reset of the terrain so it can reset as well.

Reimplemented in agxTerrain::ExternalTerrainDataSource.

◆ raycast()

virtual bool agxTerrain::TerrainDataSource::raycast ( agx::Vec3  start,
agx::Vec3  end,
agx::Vec3 &  raycastResult 
)
virtual

Perform raycasting against the terrain.

This can be called by the TerrainPager when TerrainPager::raycast is used and no active tile is hit.

Default implementation returns false. Classes inheriting from TerrainDataSource can overload this method and add support if possible.

Parameters
start- The start position of the raycast
end- The end position of the raycast
raycastResult- A reference to a Vec3 in which to store the point where the raycast hits the data source,
Returns
true if terrain is hit and raycastResult is then updated with position for the hit.

Reimplemented in agxTerrain::TerrainRasterizer, and agxTerrain::ExternalTerrainDataSource.

◆ removeTerrainMaterial()

bool agxTerrain::TerrainDataSource::removeTerrainMaterial ( agxTerrain::TerrainMaterial *  terrainMaterial)

Remove the specified TerrainMaterial from the TerrainDataSource.

This will also remove the associated material to the terrain material from the TerrainDataSource, and any added geometries that assigned the given terrain material from the TerrainDataSource. WARNING: Doing this during simulation runtime, may result in undefined behavior and possibly, crashes.

Parameters
terrainMaterial- the TerrainMaterial which will be removed from the TerrainDataSource.

◆ restore()

virtual void agxTerrain::TerrainDataSource::restore ( agxStream::InputArchive &  in)
overridevirtual

◆ setAssociatedMaterial()

bool agxTerrain::TerrainDataSource::setAssociatedMaterial ( agx::Material *  associatedMaterial,
agxTerrain::TerrainMaterial *  terrainMaterial 
)

Set the associated Material to a given TerrainMaterial.

This can replace the current associated material.

Returns
bool - true if the associated material could be set, or false if not. If false, probably because the TerrainMaterial was not added to the TerrainDataSource before this method was called.

◆ setDefaultTerrainMaterial()

void agxTerrain::TerrainDataSource::setDefaultTerrainMaterial ( agxTerrain::TerrainMaterial *  terrainMaterial)

Set the default terrain material for the terrain data source.

The default terrain material is used in all TerrainPager tiles, except where a TerrainMaterial has been added with the addTerrainMaterial method. If not specified on the TerrainDataSource, TerrainPager tiles will use the default terrain material from the given template terrain instead (if not changed, this is the dirt_1 preset).

Parameters
terrainMaterial- the new default TerrainMaterial.

◆ setDirty()

void agxTerrain::TerrainDataSource::setDirty ( bool  dirty)

◆ store()

virtual void agxTerrain::TerrainDataSource::store ( agxStream::OutputArchive &  out) const
overridevirtual

Member Data Documentation

◆ m_dirty

bool agxTerrain::TerrainDataSource::m_dirty = false
protected

Definition at line 217 of file TerrainDataSource.h.

◆ m_lookupTerrainMaterial

TerrainMaterialLookup agxTerrain::TerrainDataSource::m_lookupTerrainMaterial
protected

Definition at line 211 of file TerrainDataSource.h.

◆ m_rwLock

agx::ReaderWriterLock agxTerrain::TerrainDataSource::m_rwLock
protected

Definition at line 216 of file TerrainDataSource.h.

◆ m_terrainMaterialGeometries

agxCollide::GeometryRefVector agxTerrain::TerrainDataSource::m_terrainMaterialGeometries
protected

Definition at line 209 of file TerrainDataSource.h.

◆ m_terrainMaterialsAndAssociatedMaterials

agxTerrain::MaterialPairVector agxTerrain::TerrainDataSource::m_terrainMaterialsAndAssociatedMaterials
protected

Definition at line 213 of file TerrainDataSource.h.


The documentation for this class was generated from the following file: