AGX Dynamics  2.38.0.2
ColumnHeightGrid.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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/Grid.h>
21 
22 namespace agxTerrain
23 {
24 
29  {
30 
31  public:
32 
33  ColumnHeightGrid( const float defaultValue,
34  const size_t resolutionX,
35  const size_t resolutionY,
36  const agx::Int depth,
37  agx::Real voxelSize );
38 
40 
41  virtual agx::Vec3 getElementSize() const override;
42 
43  virtual size_t getMemoryUsage() const override;
44 
45  virtual bool empty() override;
46 
47  virtual void clearGrid() override;
48 
49  virtual void setFloatValue(const GridCoord& ijk, float value) override;
50 
51  virtual float getFloatValue(const GridCoord& ijk) const override;
52 
53  virtual bool isActiveVoxel(const GridCoord& /*ijk*/) const override;
54 
55  virtual size_t getNumActiveVoxels() const override;
56 
57  virtual agx::Real getTotal() const override;
58 
59  virtual std::tuple<float, float> getTotalAndLargest() const override;
60 
61  virtual GridCoordVector getActiveVoxelIndices() const override;
62 
63  virtual void sizeHint(size_t /*hint*/) override;
64 
65  virtual bool hasIterateSupport() const override;
66 
67  virtual void iterateVoxels(GridFunction func) const override;
68 
69  virtual agx::HashSet<agx::Vec3i> findGeometryVoxelIntersections(
70  const agx::AffineMatrix4x4& gridTransform,
71  const agxCollide::Geometry* geometry,
72  agx::Real voxelSize,
73  bool /*onlyOccupiedVoxels*/ = true) const override;
74 
75  agxCollide::BoundingAABB getBoundingBox() const override;
76 
77  virtual void setValuesBelowHeightField(
78  const agxCollide::HeightField* heightField,
79  agx::Real voxelSize,
80  int lowestAllowedVoxelIndex,
81  BasicGrid* compactionGrid) override;
82 
83  virtual agx::HashSet<agx::Vec3i> findConvexVoxelIntersections(
84  const agx::AffineMatrix4x4& gridTransform,
85  const agxCollide::Convex* convex,
86  agx::Real voxelSize) override;
87 
88  virtual bool findMeshVoxelIntersections(
89  const agx::AffineMatrix4x4& gridTransform,
90  const agxCollide::Mesh* mesh,
91  agx::Real voxelSize,
92  agx::Vec3iVector& result) override;
93 
94  virtual agx::HashSet<agx::Vec3i> findVoxelsAboveTriangles(
95  const agx::AffineMatrix4x4& gridTransform,
96  const TriangleVector& triangles,
97  agx::Real voxelSize,
98  agx::Real margin) override;
99 
100  virtual ActiveZoneIntersectionData removeVolumeInActiveZone( const agx::AffineMatrix4x4& gridTransformation,
101  const ActiveZoneShapes& activeZoneShapes,
102  const MeshIntersectionTestData& innerShape,
103  const agx::Plane& innerShapeBoundary,
104  const agx::Bound3& activeZoneGeometryBound,
105  const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
106  std::function<float(const agx::Vec3i&)> getCompression,
107  std::function<bool(const agx::Vec2i&)> canRemoveIndex,
108  agx::Real voxelSize,
109  agx::Real minOccupancyRemoval,
110  agx::Real minAllowedHeight,
111  bool useParticleFreeDeformers) override;
112 
113  virtual ActiveZoneIntersectionData removeVolumeInShape( const agx::AffineMatrix4x4& gridTransformation,
114  const ShapeIntersectionTestData& shape,
115  std::function<float( const agx::Vec3i& )> getCompression,
116  std::function<bool( const agx::Vec2i& )> canRemoveIndex,
117  std::function<bool( const agx::Vec3&, const agx::Vec3i& )> isWithinBoundry,
118  agx::Real voxelSize,
119  agx::Real minOccupancyRemoval,
120  agx::Real minAllowedHeight ) override;
121 
122  virtual agx::Vec3iVector findVoxelsInLine( const agx::Line& gridLine ) const override;
123 
124  virtual void findVoxelSurfaceFromIndex( const agx::Vec3i& index,
125  agx::Vec3i& result ) override;
126 
127  agx::Vec2i getResolution();
128 
129  int getSurfaceHeightIndex(const agx::Vec2i terrainIndex);
130 
131  std::pair<int, float> getVoxelZAndOccupancyFromLocalHeight(agx::Real height, agx::Real voxelSize);
132 
133  void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy);
134 
135  void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy);
136 
140  int getDepth() const;
141 
143 
144  protected:
145 
146  inline agx::Vec3 getGridPositionFromVoxelIndex(const agx::Vec3i& voxelIndex) const
147  {
148  return VoxelGridUtils::getGridPositionFromVoxelIndex(voxelIndex, m_voxelSize);
149  }
150 
152  {
153  return VoxelGridUtils::getVoxelIndexFromGridPosition(position, m_voxelSize);
154  }
155 
157 
158  void allocateMassArray();
159 
160  private:
161 
162  struct VoxelElement
163  {
164  int z = 0;
165  float occupancy = 0.0;
166  };
167 
168  using GridData = agx::Vector<agx::Vector<VoxelElement>>;
169 
170  GridData m_solidMassArray;
171  float m_default;
172  size_t m_resolutionX;
173  size_t m_resolutionY;
174  agx::Int m_depth;
175  agx::Real m_voxelSize;
176  };
177  }
178 
agxCollide::Mesh
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
Definition: Mesh.h:69
agx::Real
double Real
Definition: Real.h:42
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:58
agxTerrain::Grid
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:172
agx::AffineMatrix4x4T< Real >
agxCollide::HeightField
A HeightField is a collision shape that can be created from a grid structure, like an image.
Definition: agxCollide/HeightField.h:51
VoxelGridUtils.h
agxCollide::BoundingAABB
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
AGXSTREAM_DECLARE_SERIALIZABLE
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
Grid.h
agxTerrain::VoxelGridUtils::getVoxelIndexFromGridPosition
static agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 gridPosition, agx::Real voxelSize)
Definition: VoxelGridUtils.h:38
agx::BoundT< Vec3 >
agx::PlaneT
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
agxTerrain::ColumnHeightGrid::getVoxelIndexFromGridPosition
agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 position) const
Definition: ColumnHeightGrid.h:151
agx::Int
int64_t Int
Definition: Integer.h:28
agxTerrain::ColumnHeightGrid::getGridPositionFromVoxelIndex
agx::Vec3 getGridPositionFromVoxelIndex(const agx::Vec3i &voxelIndex) const
Definition: ColumnHeightGrid.h:146
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
agx::LineT
Definition: Line.h:25
agx::Vec2T
Definition: Vec2Template.h:30
agxTerrain::BasicGrid
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:71
agxTerrain::ActiveZoneIntersectionData
Definition: Grid.h:43
agx::HashSet< agx::Vec3i >
agxTerrain::MeshIntersectionTestData
std::tuple< const agxCollide::Mesh *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > MeshIntersectionTestData
Definition: Grid.h:51
AGXTERRAIN_EXPORT
#define AGXTERRAIN_EXPORT
Definition: agxTerrain/export.h:41
agxCollide::Convex
A convex class for geometric intersection tests.
Definition: Convex.h:36
agxTerrain::ColumnHeightGrid
Class implementing the BasicGrid interface.
Definition: ColumnHeightGrid.h:28
agxTerrain::ShapeIntersectionTestData
std::tuple< const agxCollide::Shape *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > ShapeIntersectionTestData
Definition: Grid.h:52
agx::Vec3T< Real >
agxTerrain::BasicGrid::GridFunction
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:79
agxTerrain::VoxelGridUtils::getGridPositionFromVoxelIndex
static agx::Vec3 getGridPositionFromVoxelIndex(agx::Vec3i voxelIndex, agx::Real voxelSize)
Definition: VoxelGridUtils.h:51