AGXDynamics  2.31.1.0
agxTerrain::TerrainMassController Class Reference

Class that handles and sanity checks the mass logic in the terrain. More...

#include <TerrainMassController.h>

+ Inheritance diagram for agxTerrain::TerrainMassController:

Public Member Functions

 TerrainMassController (Terrain *terrain)
 Construct given terrain instance. More...
 
 TerrainMassController ()
 
float addFluidMass (const agx::Vec3i &voxelIndex, float fluidMass)
 Add fluid mass in a voxel and return the rest mass if the voxel was filled. More...
 
float addFluidMassToColumn (const agx::Vec2i &voxelIndexXY, float mass)
 Add fluid mass column wise on the surface of the terrain. More...
 
float addSolidMass (const agx::Vec3i &voxelIndex, float solidMass, float compaction, float occupancyLimit=1.0)
 Add solid mass with a given compaction to a voxel and return the rest mass that could not fit. More...
 
float addSolidMassToColumn (const agx::Vec2i &voxelIndexXY, float mass, float compaction, agx::Vec3i &newSurfaceVoxel)
 Add solid mass with given compaction column wise on the surface of the terrain and return the amount of mass that was successfully added. More...
 
float addSolidMassToColumn (const agx::Vec3i &surfaceVoxelIndex, float mass, float compaction, agx::Vec3i &newSurfaceVoxel)
 Add solid mass with given compaction column wise on the surface of the terrain and return the amount of mass that was successfully added. More...
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
float convertCompactedSolidMassToNominal (const agx::Vec3i &voxelIndex, float compactedOccupancy) const
 Converts compacted mass to regular non-compacted mass given the specified voxel compaction. More...
 
bool dilateMassInColumn (const agx::Vec3i &bottomVoxel, agx::Vec3i &newSurfaceVoxel)
 Dilate material in a column from a bottom index up to surface. More...
 
float getCompactedSolidMass (const agx::Vec3i &voxelIndex) const
 Get the compacted mass in a voxel. More...
 
float getCompaction (const agx::Vec3i &voxelIndex) const
 Get compaction in a voxel. More...
 
float getFluidMass (const agx::Vec3i &voxelIndex) const
 Get fluid mass in a voxel given an index. More...
 
float getParticleMass (const agx::Vec3i &voxelIndex) const
 Get particle mass in a voxel. More...
 
int getReferenceCount () const
 
float getSolidMass (const agx::Vec3i &voxelIndex) const
 Get the solid mass from a voxel. More...
 
template<typename T >
bool is () const
 Subclass test. More...
 
bool isTotalMassOverNominalThreshold (const agx::Vec3i &voxelIndex)
 Checks if the total mass in the specified voxel exceeds the allowed nominal threshold. More...
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
float removeFluidMass (const agx::Vec3i &voxelIndex, float fluidMass)
 Add fluid mass in a voxel and return the rest mass if the voxel was filled. More...
 
float removeFluidMassFromColumn (const agx::Vec2i &voxelIndexXY, float mass)
 Remove fluid mass column wise from the surface of the terrain. More...
 
float removeSolidMass (const agx::Vec3i &voxelIndex, float solidMass)
 Remove solid mass from a voxel and return the amount of mass that could not be removed, i.e the rest if the voxel was emptied. More...
 
float removeSolidMassFromColumn (const agx::Vec2i &voxelIndexXY, float mass, agx::Vec3i &newSurfaceVoxel)
 Remove solid mass column wise from surface of the terrain and return the amount of mass that was successfully added. More...
 
float removeSolidMassFromColumn (const agx::Vec3i &surfaceVoxelIndex, float mass, agx::Vec3i &newSurfaceVoxel)
 Remove solid mass column wise from surface of the terrain and return the amount of mass that was successfully added. More...
 
void setCompaction (const agx::Vec3i &voxelIndex, float compaction, bool scaleMass=false)
 Set compaction on a voxel. More...
 
void setFluidMass (const agx::Vec3i &voxelIndex, float fluidMass)
 
void setParticleMass (const agx::Vec3i &voxelIndex, float particleMass)
 Set particle mass in a voxel. More...
 
void setSolidMass (const agx::Vec3i &voxelIndex, float solidMass, float compaction)
 Set solid mass with a given compaction to a voxel. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
bool verifyMassColumnIntegrity (const agx::Vec2i &voxelIndexXY)
 Verify that a mass column in the terrain grid is properly filled, i.e that all submerged voxels under the surface holds the maximum allowed mass given by the voxel compaction. More...
 

Static Public Member Functions

template<typename T >
static bool ValidateCast (const Referenced *object)
 

Protected Member Functions

virtual ~TerrainMassController ()
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
TerrainDataAtlas * getData () const
 

Static Protected Member Functions

static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 

Protected Attributes

Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

Class that handles and sanity checks the mass logic in the terrain.

Every mass operation on the terrain grid should go through here.

Definition at line 35 of file TerrainMassController.h.

Constructor & Destructor Documentation

◆ TerrainMassController() [1/2]

agxTerrain::TerrainMassController::TerrainMassController ( Terrain *  terrain)

Construct given terrain instance.

◆ TerrainMassController() [2/2]

agxTerrain::TerrainMassController::TerrainMassController ( )

◆ ~TerrainMassController()

virtual agxTerrain::TerrainMassController::~TerrainMassController ( )
protectedvirtual

Member Function Documentation

◆ addFluidMass()

float agxTerrain::TerrainMassController::addFluidMass ( const agx::Vec3i &  voxelIndex,
float  fluidMass 
)

Add fluid mass in a voxel and return the rest mass if the voxel was filled.

Parameters
voxelIndex- The voxel index
fluidMass- the amount of fluid mass to add
Returns
the rest fluid mass that could not fit in the voxel

◆ addFluidMassToColumn()

float agxTerrain::TerrainMassController::addFluidMassToColumn ( const agx::Vec2i &  voxelIndexXY,
float  mass 
)

Add fluid mass column wise on the surface of the terrain.

Parameters
voxelIndexXY- The specified 2D voxel index
mass- Amount of mass to be added
Returns
the fluid mass that was added to the column.

◆ addSolidMass()

float agxTerrain::TerrainMassController::addSolidMass ( const agx::Vec3i &  voxelIndex,
float  solidMass,
float  compaction,
float  occupancyLimit = 1.0 
)

Add solid mass with a given compaction to a voxel and return the rest mass that could not fit.

Note
- The added solid mass will modify the voxel compaction given it's own compaction.
Parameters
voxelIndex- The specified voxel index
solidMass- The specified solid mass to add to a voxel
compaction- The compaction of the mass to add
occupancyLimit- The nominal occupancy limit in to fill in the voxel. NOTE - cannot be higher than the voxel max nominal occupancy
Returns
The rest mass that could not fit inside the voxel

◆ addSolidMassToColumn() [1/2]

float agxTerrain::TerrainMassController::addSolidMassToColumn ( const agx::Vec2i &  voxelIndexXY,
float  mass,
float  compaction,
agx::Vec3i &  newSurfaceVoxel 
)

Add solid mass with given compaction column wise on the surface of the terrain and return the amount of mass that was successfully added.

Parameters
voxelIndexXY- The specified 2D voxel index
mass- the solid mass to add
compaction- the compaction of the mass
newSurfaceVoxel- Will give the new surface voxel index after all the mass has been added
Returns
the amount of mass that was successfully added.

◆ addSolidMassToColumn() [2/2]

float agxTerrain::TerrainMassController::addSolidMassToColumn ( const agx::Vec3i &  surfaceVoxelIndex,
float  mass,
float  compaction,
agx::Vec3i &  newSurfaceVoxel 
)

Add solid mass with given compaction column wise on the surface of the terrain and return the amount of mass that was successfully added.

Unless needed, prefer to use the addSolidMassToColumn that uses just (x,y) to index the voxel instead of this version that has (x,y,z).

Parameters
surfaceVoxelIndex- Current surface voxel in column
mass- the solid mass to add
compaction- the compaction of the mass
newSurfaceVoxel- Will give the new surface voxel index after all the mass has been added
Returns
the amount of mass that was successfully added.

◆ allocateObserverVector()

void agx::Referenced::allocateObserverVector ( ) const
protectedinherited

◆ as() [1/2]

template<typename T >
T* agx::Referenced::as ( )
inherited

Subclass casting.

Template type must match actual type, dynamic_cast assertion will fail otherwise.

Referenced by agx::InternalData::get(), agxVehicle::Track::getNode(), agx::InternalData::getOrCreate(), and agx::InternalData::hasData().

◆ as() [2/2]

template<typename T >
const T* agx::Referenced::as ( ) const
inherited

◆ asSafe() [1/2]

template<typename T >
T* agx::Referenced::asSafe ( )
inherited

Safe subclass casting, return nullptr if template type does not match.

Referenced by agxUtil::CollectBodiesAndWiresVisitor::visit().

◆ asSafe() [2/2]

template<typename T >
const T* agx::Referenced::asSafe ( ) const
inherited

◆ convertCompactedSolidMassToNominal()

float agxTerrain::TerrainMassController::convertCompactedSolidMassToNominal ( const agx::Vec3i &  voxelIndex,
float  compactedOccupancy 
) const

Converts compacted mass to regular non-compacted mass given the specified voxel compaction.

Parameters
voxelIndex- The voxel index where the compaction value will be used for conversion
compactedOccupancy- The compacted mass to convert
Returns
The converted mass given the specified voxel compaction and compacted occupancy

◆ deleteUsingDeleteHandler()

void agx::Referenced::deleteUsingDeleteHandler ( ) const
protectedinherited

◆ dilateMassInColumn()

bool agxTerrain::TerrainMassController::dilateMassInColumn ( const agx::Vec3i &  bottomVoxel,
agx::Vec3i &  newSurfaceVoxel 
)

Dilate material in a column from a bottom index up to surface.

This is used when the compaction data in the grid has been updated (eg. through compaction) and the compacted mass needs redistributed to account for the changed volume.

Parameters
bottomVoxel- The bottom voxel index where dilation will begin
newSurfaceVoxel- Will give the new surface voxel index after all the mass has been dilated
Returns
true if the dilation was successfully, false otherwise

◆ getCompactedSolidMass()

float agxTerrain::TerrainMassController::getCompactedSolidMass ( const agx::Vec3i &  voxelIndex) const

Get the compacted mass in a voxel.

This is the solid mass divided by the compaction in the specified voxel. This will normalize the solid mass to nominal occupancy, i.e how much space the compacted solid mass takes in the voxel (0.0 - 1.0).

Parameters
voxelIndex- The specified voxel index
Returns
the compacted solid mass in the voxel

◆ getCompaction()

float agxTerrain::TerrainMassController::getCompaction ( const agx::Vec3i &  voxelIndex) const

Get compaction in a voxel.

Parameters
voxelIndex- The specified voxel index
Returns
the compaction in the voxel

◆ getData()

TerrainDataAtlas* agxTerrain::TerrainMassController::getData ( ) const
protected

◆ getDeleteHandler()

static DeleteHandler* agx::Referenced::getDeleteHandler ( )
staticprotectedinherited
Returns
a DeleteHandler.

◆ getFluidMass()

float agxTerrain::TerrainMassController::getFluidMass ( const agx::Vec3i &  voxelIndex) const

Get fluid mass in a voxel given an index.

Parameters
voxelIndex- The specified voxel index
Returns
the fluid mass in the voxel

◆ getParticleMass()

float agxTerrain::TerrainMassController::getParticleMass ( const agx::Vec3i &  voxelIndex) const

Get particle mass in a voxel.

Parameters
voxelIndex- The specified voxel index
Returns
the particle mass in a voxel

◆ getReferenceCount()

int agx::Referenced::getReferenceCount ( ) const
inherited
Returns
the number pointers currently referencing this object.

◆ getSolidMass()

float agxTerrain::TerrainMassController::getSolidMass ( const agx::Vec3i &  voxelIndex) const

Get the solid mass from a voxel.

Parameters
voxelIndex- The specified voxel index
Returns
the solid mass in the voxel

◆ is()

template<typename T >
bool agx::Referenced::is ( ) const
inherited

◆ isTotalMassOverNominalThreshold()

bool agxTerrain::TerrainMassController::isTotalMassOverNominalThreshold ( const agx::Vec3i &  voxelIndex)

Checks if the total mass in the specified voxel exceeds the allowed nominal threshold.

Parameters
voxelIndex- The specified voxel index to check
Returns
True if the mass is over the nominal threshold, false otherwise

◆ reference()

void agx::Referenced::reference ( void *  ptr = nullptr) const
inherited

Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.

This method should be used with care, always balanced with the same number of calls to unreference.

◆ removeFluidMass()

float agxTerrain::TerrainMassController::removeFluidMass ( const agx::Vec3i &  voxelIndex,
float  fluidMass 
)

Add fluid mass in a voxel and return the rest mass if the voxel was filled.

Parameters
voxelIndex- The voxel index.
fluidMass- the amount of fluid mass to remove.
Returns
the rest fluid mass that could not be removed from the voxel.

◆ removeFluidMassFromColumn()

float agxTerrain::TerrainMassController::removeFluidMassFromColumn ( const agx::Vec2i &  voxelIndexXY,
float  mass 
)

Remove fluid mass column wise from the surface of the terrain.

Parameters
voxelIndexXY- The specified 2D voxel index.
mass- Amount of mass to be removed.
Returns
the amount of fluid mass that was removed from the column.

◆ removeSolidMass()

float agxTerrain::TerrainMassController::removeSolidMass ( const agx::Vec3i &  voxelIndex,
float  solidMass 
)

Remove solid mass from a voxel and return the amount of mass that could not be removed, i.e the rest if the voxel was emptied.

Parameters
voxelIndex- The specified voxel index
solidMass- The specified solid mass to remove from a voxel
Returns
The rest mass that could not be removed from the voxel before it was emptied

◆ removeSolidMassFromColumn() [1/2]

float agxTerrain::TerrainMassController::removeSolidMassFromColumn ( const agx::Vec2i &  voxelIndexXY,
float  mass,
agx::Vec3i &  newSurfaceVoxel 
)

Remove solid mass column wise from surface of the terrain and return the amount of mass that was successfully added.

Parameters
voxelIndexXY- The specified 2D voxel index
mass- the solid mass to remove
newSurfaceVoxel- Will give the new surface voxel after all the mass has been removed
Returns
the amount of mass that was successfully removed

◆ removeSolidMassFromColumn() [2/2]

float agxTerrain::TerrainMassController::removeSolidMassFromColumn ( const agx::Vec3i &  surfaceVoxelIndex,
float  mass,
agx::Vec3i &  newSurfaceVoxel 
)

Remove solid mass column wise from surface of the terrain and return the amount of mass that was successfully added.

Unless needed, prefer to use the removeSolidMassFromColumn that uses (x,y) to index the voxel instead of this version with (x,y,z).

Parameters
surfaceVoxelIndex- Current surface voxel index
mass- the solid mass to remove
newSurfaceVoxel- Will give the new surface voxel after all the mass has been removed
Returns
the amount of mass that was successfully removed

◆ setCompaction()

void agxTerrain::TerrainMassController::setCompaction ( const agx::Vec3i &  voxelIndex,
float  compaction,
bool  scaleMass = false 
)

Set compaction on a voxel.

Parameters
voxelIndex- The specified voxel index
compaction-The compaction to set
scaleMass- True if the existing occupancy in the voxel should be scaled so that the compacted solid occupancy is the same as before compaction was set. This will effectively increase the total mass in the terrain.

◆ setDeleteHandler()

static void agx::Referenced::setDeleteHandler ( DeleteHandler *  handler)
staticprotectedinherited

Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.

◆ setFluidMass()

void agxTerrain::TerrainMassController::setFluidMass ( const agx::Vec3i &  voxelIndex,
float  fluidMass 
)

◆ setParticleMass()

void agxTerrain::TerrainMassController::setParticleMass ( const agx::Vec3i &  voxelIndex,
float  particleMass 
)

Set particle mass in a voxel.

Parameters
voxelIndex- The specified voxel index
particleMass- The particle mass to set

◆ setSolidMass()

void agxTerrain::TerrainMassController::setSolidMass ( const agx::Vec3i &  voxelIndex,
float  solidMass,
float  compaction 
)

Set solid mass with a given compaction to a voxel.

Parameters
voxelIndex- The specified voxel index
solidMass- The specified solid mass to set
compaction- The compaction of the solid mass to set

◆ unreference()

void agx::Referenced::unreference ( void *  ptr = nullptr) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.

This method should be used with care, always balanced with the same number of calls to reference.

Referenced by agxData::EntityRef< ContactMaterialPtr >::~EntityRef().

◆ unreference_nodelete()

void agx::Referenced::unreference_nodelete ( ) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.

◆ ValidateCast()

template<typename T >
static bool agx::Referenced::ValidateCast ( const Referenced *  object)
staticinherited

◆ verifyMassColumnIntegrity()

bool agxTerrain::TerrainMassController::verifyMassColumnIntegrity ( const agx::Vec2i &  voxelIndexXY)

Verify that a mass column in the terrain grid is properly filled, i.e that all submerged voxels under the surface holds the maximum allowed mass given by the voxel compaction.

There should not be any "holes" in the terrain.

Note
- If the check fails, it will trigger an agxVerify and crash.
Parameters
voxelIndexXY- The specified voxel index to check.
Returns
true if the terrain solid column satisfies mass integrity conditions, false otherwise.

Member Data Documentation

◆ m_mutex

Mutex agx::Referenced::m_mutex
mutableprotectedinherited

Definition at line 240 of file Referenced.h.

◆ m_observers

ObserverContainer agx::Referenced::m_observers
mutableprotectedinherited

Definition at line 239 of file Referenced.h.

◆ m_refCount

AtomicValue agx::Referenced::m_refCount
mutableprotectedinherited

Definition at line 241 of file Referenced.h.


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