AGX Dynamics  2.35.0.1
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 ()
 
 TerrainMassController (Terrain *terrain)
 Construct given terrain instance. More...
 
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)
 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)
 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 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...
 
agx::Real getMassInTerrain (size_t massType)
 Get the total mass in the terrain of a specific mass type. More...
 
float getOccupancyModifier (agx::Vec3i voxelIndex) const
 
float getParticleMass (const agx::Vec3i &voxelIndex) const
 Get particle mass in a voxel. More...
 
float getSolidMass (const agx::Vec3i &voxelIndex) const
 Get the solid mass from a voxel. More...
 
int getSurfaceHeightIndex (const agx::Vec2i terrainIndex)
 Get Z value of the surface voxel in the voxel grid structure. More...
 
agx::Real getTotalMassInTerrain ()
 Get the total mass in the terrain of a all mass types. More...
 
std::pair< int, float > getVoxelZAndOccupancyFromLocalHeight (agx::Real height, agx::Real voxelSize)
 
bool isTotalMassOverNominalThreshold (const agx::Vec3i &voxelIndex)
 Checks if the total mass in the specified voxel exceeds the allowed nominal threshold. 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)
 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)
 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 setGridColumnOccupancy (const agx::Vec2i terrainIndex, int voxelZ, float occupancy)
 Set the which voxel is the surface voxel and what the occupancy is in that voxel. More...
 
void setOccupancyInSurfaceVoxel (const agx::Vec2i terrainIndex, float occupancy)
 Set occupancy in surface voxel. More...
 
void setParticleMass (const agx::Vec3i &voxelIndex, float particleMass)
 Set particle mass in a voxel. 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...
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor. More...
 
 Referenced (const Referenced &)
 
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
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object. 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...
 
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...
 

Protected Member Functions

virtual ~TerrainMassController ()
 
TerrainDataAtlas * getData () const
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor. More...
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 

Additional Inherited Members

- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- 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. More...
 
- Protected Attributes inherited from agx::Referenced
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 
)

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
Returns
the amount of mass that was successfully added.

◆ addSolidMassToColumn() [2/2]

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

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
Returns
the amount of mass that was successfully added.

◆ 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

◆ 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

◆ 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

◆ getMassInTerrain()

agx::Real agxTerrain::TerrainMassController::getMassInTerrain ( size_t  massType)

Get the total mass in the terrain of a specific mass type.

Parameters
massType- The mass type.
Returns
Total mass of that specific mass type in terrain.

◆ getOccupancyModifier()

float agxTerrain::TerrainMassController::getOccupancyModifier ( agx::Vec3i  voxelIndex) const

◆ 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

◆ 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

◆ getSurfaceHeightIndex()

int agxTerrain::TerrainMassController::getSurfaceHeightIndex ( const agx::Vec2i  terrainIndex)

Get Z value of the surface voxel in the voxel grid structure.

Parameters
terrainIndex- Terrain index of the column.
Returns
Z value of the surface voxel in the voxel grid structure.

◆ getTotalMassInTerrain()

agx::Real agxTerrain::TerrainMassController::getTotalMassInTerrain ( )

Get the total mass in the terrain of a all mass types.

Returns
Total mass of that all mass types in terrain.

◆ getVoxelZAndOccupancyFromLocalHeight()

std::pair<int, float> agxTerrain::TerrainMassController::getVoxelZAndOccupancyFromLocalHeight ( agx::Real  height,
agx::Real  voxelSize 
)

◆ 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

◆ 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 
)

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
Returns
the amount of mass that was successfully removed

◆ removeSolidMassFromColumn() [2/2]

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

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
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.

◆ setFluidMass()

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

◆ setGridColumnOccupancy()

void agxTerrain::TerrainMassController::setGridColumnOccupancy ( const agx::Vec2i  terrainIndex,
int  voxelZ,
float  occupancy 
)

Set the which voxel is the surface voxel and what the occupancy is in that voxel.

Parameters
terrainIndex- Terrain index of the column.
voxelZ- Z value of the surface voxel in the voxel grid structure.
occupancy- Occupancy in the surface voxel.

◆ setOccupancyInSurfaceVoxel()

void agxTerrain::TerrainMassController::setOccupancyInSurfaceVoxel ( const agx::Vec2i  terrainIndex,
float  occupancy 
)

Set occupancy in surface voxel.

Parameters
terrainIndex- Terrain index of the column.
occupancy- Occupancy in the surface voxel.

◆ 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

◆ 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.

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