AGX Dynamics 2.42.3.0
Loading...
Searching...
No Matches
agxTerrain::TerrainMassOccupancyController Class Reference

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

#include <TerrainMassOccupancyController.h>

+ Inheritance diagram for agxTerrain::TerrainMassOccupancyController:

Public Member Functions

 TerrainMassOccupancyController ()
 
 TerrainMassOccupancyController (Terrain *terrain)
 Construct given terrain instance.
 
float addFluidOccupancy (const agx::Vec3i &voxelIndex, float fluidMass)
 Add fluid mass in a voxel and return the rest mass if the voxel was filled.
 
float addFluidOccupancyToColumn (const agx::Vec2i &terrainIndex, float mass)
 Add fluid mass column wise on the surface of the terrain.
 
float addSolidMassKgToColumn (const agx::Vec2i &terrainIndex, float massKg, float compaction)
 Add solid mass (in kg) column wise on the surface of the terrain using the specified compaction.
 
float addSolidOccupancy (const agx::Vec3i &voxelIndex, float solidOccupancy, 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.
 
float addSolidOccupancyToColumn (const agx::Vec2i &terrainIndex, float occupancy, 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.
 
float addSolidOccupancyToColumn (const agx::Vec3i &surfaceVoxelIndex, float occupancy, 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.
 
float convertCompactedSolidOccupancyToNominal (const agx::Vec3i &voxelIndex, float compactedOccupancy) const
 Converts compacted mass to regular non-compacted mass given the specified voxel compaction.
 
bool dilateOccupancyInColumn (const agx::Vec3i &bottomVoxel, agx::Vec3i &newSurfaceVoxel)
 Dilate material in a column from a bottom index up to surface.
 
float getCompactedSolidOccupancy (const agx::Vec3i &voxelIndex) const
 Get the compacted mass in a voxel.
 
float getCompaction (const agx::Vec3i &voxelIndex) const
 Get compaction in a voxel.
 
float getFluidOccupancy (const agx::Vec3i &voxelIndex) const
 Get fluid mass in a voxel given an index.
 
agx::Real getOccupancyInTerrain (TerrainDataAtlas::MassType massType) const
 Get the total mass in the terrain of a specific mass type.
 
float getOccupancyModifier (agx::Vec3i voxelIndex) const
 
float getParticleOccupancy (const agx::Vec3i &voxelIndex) const
 Get particle mass in a voxel.
 
float getSolidOccupancy (const agx::Vec3i &voxelIndex) const
 Get the solid mass from a voxel.
 
int getSurfaceHeightIndex (const agx::Vec2i terrainIndex) const
 Get Z value of the surface voxel in the voxel grid structure.
 
GridElement getVoxelZAndOccupancyFromLocalHeight (agx::Real height)
 
bool isTotalOccupancyOverNominalThreshold (const agx::Vec3i &voxelIndex) const
 Checks if the total mass in the specified voxel exceeds the allowed nominal threshold.
 
float removeFluidOccupancy (const agx::Vec3i &voxelIndex, float fluidMass)
 Add fluid mass in a voxel and return the rest mass if the voxel was filled.
 
float removeFluidOccupancyFromColumn (const agx::Vec2i &terrainIndex, float mass)
 Remove fluid mass column wise from the surface of the terrain.
 
float removeOccupancyFromColumn (const agx::Vec2i &terrainIndex, float occupancy)
 Remove solid mass (in kg) column wise from the surface of the terrain.
 
float removeSolidOccupancy (const agx::Vec3i &voxelIndex, float solidOccupancy)
 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.
 
float removeSolidOccupancyFromColumn (const agx::Vec2i &terrainIndex, float mass)
 Remove solid mass column wise from surface of the terrain and return the amount of mass that was successfully added.
 
float removeSolidOccupancyFromColumn (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.
 
void setCompaction (const agx::Vec3i &voxelIndex, float compaction, bool scaleMass=false)
 Set compaction on a voxel.
 
void setFluidOccupancy (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.
 
void setOccupancyInSurfaceVoxel (const agx::Vec2i terrainIndex, float occupancy)
 Set occupancy in surface voxel.
 
void setParticleOccupancy (const agx::Vec3i &voxelIndex, float particleMass)
 Set particle mass in a voxel.
 
bool verifyOccupancyColumnIntegrity (const agx::Vec2i &terrainIndex) const
 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.
 
- 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.
 

Protected Member Functions

virtual ~TerrainMassOccupancyController ()
 
TerrainDataAtlas * getData () const
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor.
 
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.
 
- 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 TerrainMassOccupancyController.h.

Constructor & Destructor Documentation

◆ TerrainMassOccupancyController() [1/2]

agxTerrain::TerrainMassOccupancyController::TerrainMassOccupancyController ( Terrain *  terrain)

Construct given terrain instance.

◆ TerrainMassOccupancyController() [2/2]

agxTerrain::TerrainMassOccupancyController::TerrainMassOccupancyController ( )

◆ ~TerrainMassOccupancyController()

virtual agxTerrain::TerrainMassOccupancyController::~TerrainMassOccupancyController ( )
protectedvirtual

Member Function Documentation

◆ addFluidOccupancy()

float agxTerrain::TerrainMassOccupancyController::addFluidOccupancy ( 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

◆ addFluidOccupancyToColumn()

float agxTerrain::TerrainMassOccupancyController::addFluidOccupancyToColumn ( const agx::Vec2i &  terrainIndex,
float  mass 
)

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

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

◆ addSolidMassKgToColumn()

float agxTerrain::TerrainMassOccupancyController::addSolidMassKgToColumn ( const agx::Vec2i &  terrainIndex,
float  massKg,
float  compaction 
)

Add solid mass (in kg) column wise on the surface of the terrain using the specified compaction.

Parameters
terrainIndex- The specified 2D voxel index
massKg- The mass in kg to add
compaction- The compaction state to deposit mass at
Returns
The mass in kg that was successfully added

◆ addSolidOccupancy()

float agxTerrain::TerrainMassOccupancyController::addSolidOccupancy ( const agx::Vec3i &  voxelIndex,
float  solidOccupancy,
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
solidOccupancy- The specified solid mass occupancy 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

◆ addSolidOccupancyToColumn() [1/2]

float agxTerrain::TerrainMassOccupancyController::addSolidOccupancyToColumn ( const agx::Vec2i &  terrainIndex,
float  occupancy,
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
terrainIndex- The specified 2D voxel index
occupancy- the solid mass occupancy to add
compaction- the compaction of the mass
Returns
the amount of mass that was successfully added.

◆ addSolidOccupancyToColumn() [2/2]

float agxTerrain::TerrainMassOccupancyController::addSolidOccupancyToColumn ( const agx::Vec3i &  surfaceVoxelIndex,
float  occupancy,
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
occupancy- the solid mass occupancy to add
compaction- the compaction of the mass
Returns
the amount of mass that was successfully added.

◆ convertCompactedSolidOccupancyToNominal()

float agxTerrain::TerrainMassOccupancyController::convertCompactedSolidOccupancyToNominal ( 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

◆ dilateOccupancyInColumn()

bool agxTerrain::TerrainMassOccupancyController::dilateOccupancyInColumn ( 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

◆ getCompactedSolidOccupancy()

float agxTerrain::TerrainMassOccupancyController::getCompactedSolidOccupancy ( 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::TerrainMassOccupancyController::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::TerrainMassOccupancyController::getData ( ) const
protected

◆ getFluidOccupancy()

float agxTerrain::TerrainMassOccupancyController::getFluidOccupancy ( 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

◆ getOccupancyInTerrain()

agx::Real agxTerrain::TerrainMassOccupancyController::getOccupancyInTerrain ( TerrainDataAtlas::MassType  massType) const

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::TerrainMassOccupancyController::getOccupancyModifier ( agx::Vec3i  voxelIndex) const

◆ getParticleOccupancy()

float agxTerrain::TerrainMassOccupancyController::getParticleOccupancy ( const agx::Vec3i &  voxelIndex) const

Get particle mass in a voxel.

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

◆ getSolidOccupancy()

float agxTerrain::TerrainMassOccupancyController::getSolidOccupancy ( 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::TerrainMassOccupancyController::getSurfaceHeightIndex ( const agx::Vec2i  terrainIndex) const

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.

◆ getVoxelZAndOccupancyFromLocalHeight()

GridElement agxTerrain::TerrainMassOccupancyController::getVoxelZAndOccupancyFromLocalHeight ( agx::Real  height)

◆ isTotalOccupancyOverNominalThreshold()

bool agxTerrain::TerrainMassOccupancyController::isTotalOccupancyOverNominalThreshold ( const agx::Vec3i &  voxelIndex) const

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

◆ removeFluidOccupancy()

float agxTerrain::TerrainMassOccupancyController::removeFluidOccupancy ( 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.

◆ removeFluidOccupancyFromColumn()

float agxTerrain::TerrainMassOccupancyController::removeFluidOccupancyFromColumn ( const agx::Vec2i &  terrainIndex,
float  mass 
)

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

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

◆ removeOccupancyFromColumn()

float agxTerrain::TerrainMassOccupancyController::removeOccupancyFromColumn ( const agx::Vec2i &  terrainIndex,
float  occupancy 
)

Remove solid mass (in kg) column wise from the surface of the terrain.

The removed mass is accumulated per-voxel using actual voxel density, so multi-voxel removals are computed correctly.

Parameters
terrainIndex- The specified 2D voxel index
occupancy- The solid occupancy to remove
Returns
The mass in kg that was actually removed

◆ removeSolidOccupancy()

float agxTerrain::TerrainMassOccupancyController::removeSolidOccupancy ( const agx::Vec3i &  voxelIndex,
float  solidOccupancy 
)

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
solidOccupancy- The specified solid occupancy to remove from a voxel
Returns
The rest mass that could not be removed from the voxel before it was emptied

◆ removeSolidOccupancyFromColumn() [1/2]

float agxTerrain::TerrainMassOccupancyController::removeSolidOccupancyFromColumn ( const agx::Vec2i &  terrainIndex,
float  mass 
)

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

Parameters
terrainIndex- The specified 2D voxel index
mass- the solid mass to remove
Returns
the amount of mass that was successfully removed

◆ removeSolidOccupancyFromColumn() [2/2]

float agxTerrain::TerrainMassOccupancyController::removeSolidOccupancyFromColumn ( 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::TerrainMassOccupancyController::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.

◆ setFluidOccupancy()

void agxTerrain::TerrainMassOccupancyController::setFluidOccupancy ( const agx::Vec3i &  voxelIndex,
float  fluidMass 
)

◆ setGridColumnOccupancy()

void agxTerrain::TerrainMassOccupancyController::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::TerrainMassOccupancyController::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.

◆ setParticleOccupancy()

void agxTerrain::TerrainMassOccupancyController::setParticleOccupancy ( const agx::Vec3i &  voxelIndex,
float  particleMass 
)

Set particle mass in a voxel.

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

◆ verifyOccupancyColumnIntegrity()

bool agxTerrain::TerrainMassOccupancyController::verifyOccupancyColumnIntegrity ( const agx::Vec2i &  terrainIndex) const

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
terrainIndex- 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: