AGX Dynamics  2.35.0.1
TerrainMassController.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 having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 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/config/AGX_USE_AGXTERRAIN.h>
20 #include <agxTerrain/export.h>
21 #include <agx/Referenced.h>
22 #include <agx/Vec3.h>
23 
24 namespace agxTerrain
25 {
26  class Terrain;
27  class TerrainDataAtlas;
28 
31 
36  {
37  public:
42 
49 
50  /*
51  Set fluid mass in a voxel given an index
52  \param voxelIndex - The specified voxel index
53  \param fluidMass - the amount of fluid mass to set
54  */
55  void setFluidMass(const agx::Vec3i& voxelIndex, float fluidMass);
56 
63  float addFluidMass(const agx::Vec3i& voxelIndex, float fluidMass);
64 
71  float removeFluidMass(const agx::Vec3i& voxelIndex, float fluidMass);
72 
78  float getFluidMass(const agx::Vec3i& voxelIndex) const;
79 
90  float addSolidMass(const agx::Vec3i& voxelIndex, float solidMass, float compaction, float occupancyLimit = 1.0);
91 
99  float removeSolidMass(const agx::Vec3i& voxelIndex, float solidMass);
100 
106  float getSolidMass(const agx::Vec3i& voxelIndex) const;
107 
116  void setCompaction(const agx::Vec3i& voxelIndex, float compaction, bool scaleMass=false);
117 
123  float getCompaction(const agx::Vec3i& voxelIndex) const;
124 
125  float getOccupancyModifier(agx::Vec3i voxelIndex) const;
126 
132  float getParticleMass(const agx::Vec3i& voxelIndex) const;
133 
139  void setParticleMass(const agx::Vec3i& voxelIndex, float particleMass);
140 
147  float getCompactedSolidMass(const agx::Vec3i& voxelIndex) const;
148 
155  float addFluidMassToColumn(const agx::Vec2i& voxelIndexXY, float mass);
156 
163  float removeFluidMassFromColumn(const agx::Vec2i& voxelIndexXY, float mass);
164 
173  float addSolidMassToColumn(const agx::Vec2i& voxelIndexXY, float mass, float compaction);
174 
184  float addSolidMassToColumn(const agx::Vec3i& surfaceVoxelIndex, float mass, float compaction);
185 
193  float removeSolidMassFromColumn(const agx::Vec2i& voxelIndexXY, float mass);
194 
203  float removeSolidMassFromColumn(const agx::Vec3i& surfaceVoxelIndex, float mass);
204 
212  bool dilateMassInColumn(const agx::Vec3i& bottomVoxel, agx::Vec3i& newSurfaceVoxel);
213 
220  float convertCompactedSolidMassToNominal(const agx::Vec3i& voxelIndex, float compactedOccupancy) const;
221 
228 
236  bool verifyMassColumnIntegrity(const agx::Vec2i& voxelIndexXY);
237 
244  void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy);
245 
251  void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy);
252 
258  int getSurfaceHeightIndex(const agx::Vec2i terrainIndex);
259 
265  agx::Real getMassInTerrain(size_t massType);
266 
272 
273  std::pair<int, float> getVoxelZAndOccupancyFromLocalHeight(agx::Real height, agx::Real voxelSize);
274 
275  public:
279 
280  protected:
281 
283 
284  TerrainDataAtlas* getData() const;
285 
286  private:
287  Terrain* m_terrain;
288  agx::HashTable<agx::Vec3i, float> m_occupancyModifiers;
289  };
290 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXTERRAIN_STORE_RESTORE_INTERFACE
#define AGXTERRAIN_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Class that handles and sanity checks the mass logic in the terrain.
void setFluidMass(const agx::Vec3i &voxelIndex, float fluidMass)
float removeFluidMass(const agx::Vec3i &voxelIndex, float fluidMass)
Add fluid mass in a voxel and return the rest mass if the voxel was filled.
float addFluidMass(const agx::Vec3i &voxelIndex, float fluidMass)
Add fluid mass in a voxel and return the rest mass if the voxel was filled.
float getCompactedSolidMass(const agx::Vec3i &voxelIndex) const
Get the compacted mass in a voxel.
float getParticleMass(const agx::Vec3i &voxelIndex) const
Get particle mass in a voxel.
float convertCompactedSolidMassToNominal(const agx::Vec3i &voxelIndex, float compactedOccupancy) const
Converts compacted mass to regular non-compacted mass given the specified voxel compaction.
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 succ...
float getCompaction(const agx::Vec3i &voxelIndex) const
Get compaction in a voxel.
void setParticleMass(const agx::Vec3i &voxelIndex, float particleMass)
Set particle mass in a voxel.
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,...
int getSurfaceHeightIndex(const agx::Vec2i terrainIndex)
Get Z value of the surface voxel in the voxel grid structure.
float getFluidMass(const agx::Vec3i &voxelIndex) const
Get fluid mass in a voxel given an index.
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 succ...
agx::Real getMassInTerrain(size_t massType)
Get the total mass in the terrain of a specific mass type.
float getOccupancyModifier(agx::Vec3i voxelIndex) const
float getSolidMass(const agx::Vec3i &voxelIndex) const
Get the solid mass from a voxel.
void setCompaction(const agx::Vec3i &voxelIndex, float compaction, bool scaleMass=false)
Set compaction on a voxel.
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.
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...
std::pair< int, float > getVoxelZAndOccupancyFromLocalHeight(agx::Real height, agx::Real voxelSize)
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.
agx::Real getTotalMassInTerrain()
Get the total mass in the terrain of a all mass types.
bool dilateMassInColumn(const agx::Vec3i &bottomVoxel, agx::Vec3i &newSurfaceVoxel)
Dilate material in a column from a bottom index up to surface.
TerrainMassController(Terrain *terrain)
Construct given terrain instance.
bool isTotalMassOverNominalThreshold(const agx::Vec3i &voxelIndex)
Checks if the total mass in the specified voxel exceeds the allowed nominal threshold.
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 ...
float removeFluidMassFromColumn(const agx::Vec2i &voxelIndexXY, float mass)
Remove fluid mass column wise from the surface of the terrain.
void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy)
Set occupancy in surface voxel.
float addFluidMassToColumn(const agx::Vec2i &voxelIndexXY, float mass)
Add fluid mass column wise on the surface of the terrain.
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 ...
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Base class providing referencing counted objects.
Definition: Referenced.h:114
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:60
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< Int > Vec3i
Definition: agx/Vec3.h:43
double Real
Definition: Real.h:42
LinearProbingHashTable< KeyT, DataT, HashT, AllocatorT > HashTable
Definition: HashTable.h:24