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