AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TerrainDataAtlas.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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 <agxTerrain/export.h>
20 #include <agxTerrain/Grid.h>
21 
22 namespace agxTerrain
23 {
25 
27 
28  /*
29  Atlas for holding information about terrain mass in the grid system.
30  Is active in the same index space as the regular grid.
31  */
33  {
34  static constexpr float MAX_MASS = 1.0;
35 
36  public:
37  enum MassType
38  {
41  FLUID
42  };
43  struct MassTypeHash
44  {
46  {
47  return agx::hash((agx::UInt32)key);
48  }
49  };
50 
51  public:
56  TerrainDataAtlas(agx::Real voxelSize);
57 
64  float getMass(const Grid::GridCoord& coord, MassType massType) const;
65 
73  void setMass(const Grid::GridCoord& coord, MassType massType, float value);
74 
83  float addMass(const Grid::GridCoord& coord, MassType massType, float value);
84 
91  void setCompaction(const Grid::GridCoord& coord, float value);
92 
98  float getCompaction(const Grid::GridCoord& coord) const;
99 
107  float getCompactedSolidMass(const Grid::GridCoord& coord) const;
108 
114  float getMaximumAllowedSolidMassInVoxel(const Grid::GridCoord& coord) const;
115 
121  bool isActiveVoxel(const Grid::GridCoord& coord, MassType massType) const;
122 
128  agx::Vec3iVector getIndicesWithMass(MassType massType) const;
129 
130  float getTotalMassInVoxel(const Grid::GridCoord& coord) const;
131 
132  void setVelocity(const Grid::GridCoord& coord, const agx::Vec3f& value);
133  agx::Vec3f getVelocity(const Grid::GridCoord& coord) const;
134  void clearVelocityGrid();
135 
136  // Set mass data according to a grid with occupancy values. Uses the internal voxel size and mass density to calculate resulting mass.
137  void setData(const Grid& grid, MassType massType);
138 
139  Grid* getGridMassData(MassType massType) const;
140  Grid* getCompactionGridData() const;
141 
142  size_t getTotalGridMemoryUsage() const;
143 
144  size_t getTotalActiveVoxels() const;
145 
146  void clearMassGrid(MassType massType);
147 
148  agx::Real getMassInTerrain(MassType massType) const;
149 
150  agx::Real getTotalMassInTerrain() const;
151 
152  VoxelToVelocityTable& getVelocityTable();
153 
154  public:
158 
159  protected:
163  virtual ~TerrainDataAtlas();
164 
165  protected:
166  GridRef m_solidMassGrid;
167  GridRef m_fluidMassGrid;
168  GridRef m_particleMassGrid;
169  GridRef m_compactionGrid;
170 
171  VoxelToVelocityTable m_voxelToVelocityTable;
172 
173  agx::HashTable<MassType, Grid*, MassTypeHash> m_massGridTable;
174  };
175 }
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65
#define AGXTERRAIN_STORE_RESTORE_INTERFACE
agx::UInt32 operator()(TerrainDataAtlas::MassType key) const
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGX_FORCE_INLINE
Definition: Object.h:62
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:55
Base class providing referencing counted objects.
Definition: Referenced.h:113
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
agx::HashTable< agx::Vec3i, agx::Vec3f > VoxelToVelocityTable
Container for holding a grid coordinate.
Definition: Grid.h:59
#define AGXTERRAIN_EXPORT
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
LinearProbingHashTable< KeyT, DataT, HashT, AllocatorT > HashTable
Definition: HashTable.h:24
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100