AGXDynamics  2.35.0.3
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 
65  virtual agx::HashSet<agx::Vec3i> findGeometryVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
66  const agxCollide::Geometry* geometry,
67  agx::Real voxelSize,
68  bool /*onlyOccupiedVoxels*/ = true) const override;
69 
70  agxCollide::BoundingAABB getBoundingBox() const override;
71 
72  virtual void setValuesBelowHeightField(
73  const agxCollide::HeightField* heightField,
74  agx::Real voxelSize,
75  int lowestAllowedVoxelIndex,
76  BasicGrid* compactionGrid) override;
77 
78 
79  virtual agx::HashSet<agx::Vec3i> findConvexVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
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 
90  virtual agx::HashSet<agx::Vec3i> findVoxelsAboveTriangles(const agx::AffineMatrix4x4& gridTransform,
91  const TriangleVector& triangles,
92  agx::Real voxelSize,
93  agx::Real margin) override;
94 
95 
96  virtual ActiveZoneIntersectionData removeVolumeInActiveZone(const agx::AffineMatrix4x4& gridTransformation,
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 
109  virtual ActiveZoneIntersectionData removeVolumeInConvex(const agx::AffineMatrix4x4& gridTransformation,
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 
124  agx::Vec2i getResolution();
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 
145  agx::Vec3i getVoxelIndexFromLocalPosition(agx::Vec3 position, agx::Real voxelSize) const;
146 
147 
148  protected:
150 
151  void allocateMassArray();
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 
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:59
agxTerrain::Grid
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:171
agx::AffineMatrix4x4T< Real >
agx::Int
int32_t Int
Definition: Integer.h:35
agxCollide::HeightField
A HeightField is a collision shape that can be created from a grid structure, like an image.
Definition: agxCollide/HeightField.h:51
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
agx::BoundT< Vec3 >
agx::PlaneT
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
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:70
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:37
agxTerrain::ColumnHeightGrid
Class implementing the BasicGrid interface.
Definition: ColumnHeightGrid.h:27
agx::Vec3T< Real >
agxTerrain::BasicGrid::GridFunction
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:78