AGX Dynamics  2.35.0.1
ColumnHeightGrid.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
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>
20 
21 namespace agxTerrain
22 {
23 
28  {
29 
30  public:
31 
33 
34  ColumnHeightGrid(const float defaultValue, const size_t resolutionX, const size_t resolutionY, const agx::Int depth, agx::Real voxelSize);
36 
37  virtual agx::Vec3 getElementSize() const override;
38 
39  virtual size_t getMemoryUsage() const override;
40 
41  virtual bool empty() override;
42 
43  virtual void clearGrid() override;
44 
45  virtual void setFloatValue(const GridCoord& ijk, float value) override;
46 
47  virtual float getFloatValue(const GridCoord& ijk) const override;
48 
49  virtual bool isActiveVoxel(const GridCoord& /*ijk*/) const override;
50 
51  virtual size_t getNumActiveVoxels() const override;
52 
53  virtual agx::Real getTotal() const override;
54 
55  virtual std::tuple<float, float> getTotalAndLargest() const override;
56 
57  virtual GridCoordVector getActiveVoxelIndices() const override;
58 
59  virtual void sizeHint(size_t /*hint*/) override;
60 
61  virtual bool hasIterateSupport() const override;
62 
63  virtual void iterateVoxels(GridFunction /*func*/) const override;
64 
66  const agxCollide::Geometry* geometry,
67  agx::Real voxelSize,
68  bool /*onlyOccupiedVoxels*/ = true) const override;
69 
71 
73  const agxCollide::HeightField* heightField,
74  agx::Real voxelSize,
75  int lowestAllowedVoxelIndex,
76  BasicGrid* compactionGrid) override;
77 
78 
80  const agxCollide::Convex* convex,
81  agx::Real voxelSize) override;
82 
83 
84  virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
85  const agxCollide::Mesh* mesh,
86  agx::Real voxelSize,
87  agx::Vec3iVector& result) override;
88 
89 
91  const TriangleVector& triangles,
92  agx::Real voxelSize,
93  agx::Real margin) override;
94 
95 
97  const ActiveZoneShapes& activeZoneShapes,
98  const MeshIntersectionTestData& innerShape,
99  const agx::Plane& innerShapeBoundary,
100  const agx::Bound3& activeZoneGeometryBound,
101  const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
102  std::function<float(const agx::Vec3i&)> getCompression,
103  std::function<bool(const agx::Vec2i&)> canRemoveIndex,
104  agx::Real voxelSize,
105  agx::Real minOccupancyRemoval,
106  agx::Real minAllowedHeight,
107  bool useParticleFreeDeformers) override;
108 
110  const MeshIntersectionTestData& shape,
111  const agx::Plane& innerShapeBoundary,
112  const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
113  std::function<float(const agx::Vec3i&)> getCompression,
114  std::function<bool(const agx::Vec2i&)> canRemoveIndex,
115  agx::Real voxelSize,
116  agx::Real minOccupancyRemoval,
117  agx::Real minAllowedHeight,
118  bool useParticleFreeDeformers) override;
119 
120  virtual agx::Vec3iVector findVoxelsInLineIntersection(const agx::Line& line) const override;
121 
122  virtual void findVoxelSurfaceFromIndex(const agx::Vec3i& index, agx::Vec3i& result) override;
123 
125 
126  int getSurfaceHeightIndex(const agx::Vec2i terrainIndex);
127 
128  std::pair<int, float> getVoxelZAndOccupancyFromLocalHeight(agx::Real height, agx::Real voxelSize);
129 
130  void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy);
131 
132  void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy);
133 
137  int getDepth() const;
138 
140 
141  protected:
142 
143  agx::Vec3 getLocalPositionFromVoxelIndex(const agx::Vec3i& voxelIndex, agx::Real voxelSize) const;
144 
146 
147 
148  protected:
150 
152 
153  private:
154 
155  GridData m_solidMassArray;
156  float m_default;
157  size_t m_resolutionX;
158  size_t m_resolutionY;
159  agx::Int m_depth;
160  agx::Real m_voxelSize;
161  };
162  }
163 
#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
#define AGXTERRAIN_EXPORT
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
A convex class for geometric intersection tests.
Definition: Convex.h:38
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
A HeightField is a collision shape that can be created from a grid structure, like an image.
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
Definition: Mesh.h:70
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:71
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:78
Class implementing the BasicGrid interface.
virtual bool empty() override
Test if the trid is empty.
virtual bool hasIterateSupport() const override
virtual void iterateVoxels(GridFunction) const override
virtual agx::Real getTotal() const override
Returns the sum of all voxel values.
virtual agx::HashSet< agx::Vec3i > findConvexVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Convex *convex, agx::Real voxelSize) override
agxCollide::BoundingAABB getBoundingBox() const override
virtual float getFloatValue(const GridCoord &ijk) const override
Return value for voxel ijk.
virtual ActiveZoneIntersectionData removeVolumeInActiveZone(const agx::AffineMatrix4x4 &gridTransformation, const ActiveZoneShapes &activeZoneShapes, const MeshIntersectionTestData &innerShape, const agx::Plane &innerShapeBoundary, const agx::Bound3 &activeZoneGeometryBound, const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep, std::function< float(const agx::Vec3i &)> getCompression, std::function< bool(const agx::Vec2i &)> canRemoveIndex, agx::Real voxelSize, agx::Real minOccupancyRemoval, agx::Real minAllowedHeight, bool useParticleFreeDeformers) override
virtual void sizeHint(size_t) override
Provide the implementation with a hint about the estimated number of voxels that are needed.
virtual GridCoordVector getActiveVoxelIndices() const override
virtual agx::Vec3 getElementSize() const override
Get the element size used for the voxel grid.
ColumnHeightGrid(const float defaultValue, const size_t resolutionX, const size_t resolutionY, const agx::Int depth, agx::Real voxelSize)
virtual void setValuesBelowHeightField(const agxCollide::HeightField *heightField, agx::Real voxelSize, int lowestAllowedVoxelIndex, BasicGrid *compactionGrid) override
virtual size_t getMemoryUsage() const override
Get the memory usage.
virtual void setFloatValue(const GridCoord &ijk, float value) override
Set value for voxel ijk.
virtual void clearGrid() override
Clear the grid.
virtual ActiveZoneIntersectionData removeVolumeInConvex(const agx::AffineMatrix4x4 &gridTransformation, const MeshIntersectionTestData &shape, const agx::Plane &innerShapeBoundary, const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep, std::function< float(const agx::Vec3i &)> getCompression, std::function< bool(const agx::Vec2i &)> canRemoveIndex, agx::Real voxelSize, agx::Real minOccupancyRemoval, agx::Real minAllowedHeight, bool useParticleFreeDeformers) override
virtual agx::HashSet< agx::Vec3i > findVoxelsAboveTriangles(const agx::AffineMatrix4x4 &gridTransform, const TriangleVector &triangles, agx::Real voxelSize, agx::Real margin) override
std::pair< int, float > getVoxelZAndOccupancyFromLocalHeight(agx::Real height, agx::Real voxelSize)
virtual bool isActiveVoxel(const GridCoord &) const override
Test if voxel ijk is active.
void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy)
virtual agx::Vec3iVector findVoxelsInLineIntersection(const agx::Line &line) const override
agx::Vec3 getLocalPositionFromVoxelIndex(const agx::Vec3i &voxelIndex, agx::Real voxelSize) const
void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy)
virtual agx::HashSet< agx::Vec3i > findGeometryVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Geometry *geometry, agx::Real voxelSize, bool=true) const override
Find which voxels that overlap with a geometry.
virtual void findVoxelSurfaceFromIndex(const agx::Vec3i &index, agx::Vec3i &result) override
virtual size_t getNumActiveVoxels() const override
Return number of active voxels in the data structure.
int getSurfaceHeightIndex(const agx::Vec2i terrainIndex)
agx::Vec3i getVoxelIndexFromLocalPosition(agx::Vec3 position, agx::Real voxelSize) const
virtual std::tuple< float, float > getTotalAndLargest() const override
virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Mesh *mesh, agx::Real voxelSize, agx::Vec3iVector &result) override
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:172
Class representing the mathematical concept of a plane, also called a half- space.
Definition: agx/Plane.h:32
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Templated vector class.
Definition: agx/Vector.h:53
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:60
std::tuple< const agxCollide::Mesh *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > MeshIntersectionTestData
Definition: Grid.h:51
int32_t Int
Definition: Integer.h:35
double Real
Definition: Real.h:42