AGX Dynamics 2.42.2.1
Loading...
Searching...
No Matches
ColumnHeightGrid.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or
9having been advised so by Algoryx Simulation AB for a time limited evaluation,
10or having purchased a valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agxTerrain/Grid.h>
20
21namespace agxTerrain
22{
27 {
28 public:
29
30 ColumnHeightGrid( const float defaultValue,
31 const size_t resolutionX,
32 const size_t resolutionY,
33 const agx::Real lowestMinimumHeight,
34 const agx::Real voxelSize,
35 const agx::RealVector& minimumHeights = agx::RealVector());
36
38
39 const GridElement& getGridElement(const agx::Vec2i& ij) const;
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
70 const agx::AffineMatrix4x4& gridTransform,
71 const agxCollide::Geometry* geometry,
72 agx::Real voxelSize,
73 bool /*onlyOccupiedVoxels*/ = true,
74 bool onlyMidPoint =false ) const override;
75
77 const agx::AffineMatrix4x4& gridTransform, const agxCollide::Geometry* geometry, agx::Real voxelSize,
78 agx::Real radius, agx::Real width, bool onlyOccupiedVoxels = true, bool onlyMidPoint = false) const;
79
81 const agx::AffineMatrix4x4& gridTransform, const agxCollide::Geometry* geometry, agx::Real voxelSize,
82 agx::Real radius, agx::Real width,
83 bool onlyOccupiedVoxels = true, bool onlyMidPoint = false) const;
84
86
88 const agxCollide::HeightField* heightField,
89 agx::Real voxelSize,
90 int lowestAllowedVoxelIndex,
91 BasicGrid* compactionGrid) override;
92
94 const agx::AffineMatrix4x4& gridTransform,
95 const agxCollide::Convex* convex,
96 agx::Real voxelSize) override;
97
99 const agx::AffineMatrix4x4& gridTransform,
100 const agxCollide::Mesh* mesh,
101 agx::Real voxelSize,
102 agx::Vec3iVector& result) override;
103
105 const agx::AffineMatrix4x4& gridTransform,
106 const TriangleVector& triangles,
107 agx::Real voxelSize,
108 agx::Real margin) override;
109
111 const ActiveZoneShapes& activeZoneShapes,
112 const ActiveZoneShapes& innerShape,
113 const agx::Plane& innerShapeBoundary,
114 const agx::Bound3& activeZoneGeometryBound,
115 const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
116 std::function<float(const agx::Vec3i&)> getCompression,
117 std::function<bool(const agx::Vec2i&)> canRemoveIndex,
118 agx::Real voxelSize,
119 agx::Real minOccupancyRemoval,
120 std::function<agx::Real(const agx::Vec2i&)> getMinAllowedHeight,
121 bool useParticleFreeDeformers) override;
122
124 const ShapeIntersectionTestData& shape,
125 std::function<float( const agx::Vec3i& )> getCompression,
126 std::function<bool( const agx::Vec2i& )> canRemoveIndex,
127 std::function<bool( const agx::Vec3&, const agx::Vec3i& )> isWithinBoundry,
128 agx::Real voxelSize,
129 agx::Real minOccupancyRemoval,
130 std::function<agx::Real(const agx::Vec2i&)> getMinAllowedHeight ) override;
131
132 virtual agx::Vec3iVector findVoxelsInLine( const agx::Line& gridLine ) const override;
133
134 virtual void findVoxelSurfaceFromIndex( const agx::Vec3i& index,
135 agx::Vec3i& result ) override;
136
138
140
142
143
144 agx::Real getHeightFromVoxelZAndOccupancy(int voxelZ, float occupancy);
145
146 int getSurfaceHeightIndex(const agx::Vec2i terrainIndex) const;
147
149
150 void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy);
151
152 void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy);
153
155
156 /* Minimum height functionality */
158
160
162
164
165 bool setMinimumHeight(agx::Vec2i terrainIndex, agx::Real minimumHeight);
166
168
170
172
173 /*
174 Set the minimum heights in the grid.
175 \param minimumHeights - row major array of size (resX * resY).
176 \note If getEnableMinimumHeights() == false, this method will print a warning and then enable minimum heights, and continue as usual.
177 */
178 void setMinimumHeights(const agx::RealVector& minimumHeights);
179
181
182 /*
183 Enable minimum heights grid. If disabled, getLowestMinimumHeight() will be used as the lowest point in all coordinates.
184 */
185 void setEnableMinimumHeights(bool enable);
186
187
189
190 protected:
191
193
195
197
199
200 private:
201
203
204 GridData m_solidMassArray;
205 float m_default;
206 size_t m_resolutionX;
207 size_t m_resolutionY;
208 agx::Real m_voxelSize;
209
210 // Minimum height grid data
212
213 HeightData m_minimumHeigths;
214 bool m_enableMinHeights;
215 agx::Real m_lowestMinimumHeight;
216 };
217 }
218
#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:36
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
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:81
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:88
Class implementing the BasicGrid interface.
bool setMinimumHeight(agx::Vec2i terrainIndex, agx::Real minimumHeight)
agx::Vec3iVector findCylinderGeometryVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Geometry *geometry, agx::Real voxelSize, agx::Real radius, agx::Real width, bool onlyOccupiedVoxels=true, bool onlyMidPoint=false) const
bool getEnableMinimumHeights() const
GridElement getVoxelZAndOccupancyFromLocalHeight(agx::Real height)
virtual bool empty() override
Test if the trid is empty.
const GridElement & getGridElement(const agx::Vec2i &ij) const
virtual bool hasIterateSupport() const override
virtual agx::Real getTotal() const override
Returns the sum of all voxel values.
GridElement getVoxelAndOccupancy(const agx::Vec2i &terrainIndex)
virtual std::tuple< float, float > getTotalAndLargest() const override
virtual agx::Vec3iVector findVoxelsInLine(const agx::Line &gridLine) const override
agx::Real getMinimumHeight(agx::Vec2i terrainIndex) const
agxCollide::BoundingAABB getBoundingBox() const override
virtual float getFloatValue(const GridCoord &ijk) const override
Return value for voxel ijk.
virtual void iterateVoxels(GridFunction func) const 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.
virtual void setValuesBelowHeightField(const agxCollide::HeightField *heightField, agx::Real voxelSize, int lowestAllowedVoxelIndex, BasicGrid *compactionGrid) override
virtual agx::HashSet< agx::Vec3i > findGeometryVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Geometry *geometry, agx::Real voxelSize, bool=true, bool onlyMidPoint=false) const override
Find which voxels that overlap with a geometry.
virtual size_t getMemoryUsage() const override
Get the memory usage.
agx::Int getLowestAllowableVoxelIndexZ() const
virtual void setFloatValue(const GridCoord &ijk, float value) override
Set value for voxel ijk.
virtual void clearGrid() override
Clear the grid.
agx::Int getVoxelZFromHeight(agx::Real height) const
agx::Real getHeightFromVoxelZAndOccupancy(int voxelZ, float occupancy)
agx::RealVector getMinimumHeights() const
bool isIndexOutsideBounds(agx::Vec2i index) const
agx::Int getMinimumHeightIndexZ(agx::Vec2i terrainIndex) const
agx::Real getLowestMinimumHeight() const
void setLowestMinimumHeight(agx::Real minimumHeight)
virtual ActiveZoneIntersectionData removeVolumeInShape(const agx::AffineMatrix4x4 &gridTransformation, const ShapeIntersectionTestData &shape, std::function< float(const agx::Vec3i &)> getCompression, std::function< bool(const agx::Vec2i &)> canRemoveIndex, std::function< bool(const agx::Vec3 &, const agx::Vec3i &)> isWithinBoundry, agx::Real voxelSize, agx::Real minOccupancyRemoval, std::function< agx::Real(const agx::Vec2i &)> getMinAllowedHeight) override
ColumnHeightGrid(const float defaultValue, const size_t resolutionX, const size_t resolutionY, const agx::Real lowestMinimumHeight, const agx::Real voxelSize, const agx::RealVector &minimumHeights=agx::RealVector())
virtual bool isActiveVoxel(const GridCoord &) const override
Test if voxel ijk is active.
void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy)
void setMinimumHeights(const agx::RealVector &minimumHeights)
virtual ActiveZoneIntersectionData removeVolumeInActiveZone(const agx::AffineMatrix4x4 &gridTransformation, const ActiveZoneShapes &activeZoneShapes, const ActiveZoneShapes &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, std::function< agx::Real(const agx::Vec2i &)> getMinAllowedHeight, bool useParticleFreeDeformers) override
void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy)
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.
void setEnableMinimumHeights(bool enable)
agx::Vec3iVector cylinderVoxelAABBIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Geometry *geometry, agx::Real voxelSize, agx::Real radius, agx::Real width, bool onlyOccupiedVoxels=true, bool onlyMidPoint=false) const
virtual agx::HashSet< agx::Vec3i > findConvexVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Convex *convex, agx::Real voxelSize) override
int getSurfaceHeightIndex(const agx::Vec2i terrainIndex) const
virtual agx::HashSet< agx::Vec3i > findVoxelsAboveTriangles(const agx::AffineMatrix4x4 &gridTransform, const TriangleVector &triangles, agx::Real voxelSize, agx::Real margin) override
virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Mesh *mesh, agx::Real voxelSize, agx::Vec3iVector &result) override
agx::Real getLocalHeight(const agx::Vec2i terrainIndex)
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:202
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:670
Class representing the mathematical concept of a plane, also called a half- space.
Definition: agx/Plane.h:32
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:59
std::tuple< const agxCollide::Shape *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > ShapeIntersectionTestData
Definition: Grid.h:61
double Real
Definition: Real.h:41
int64_t Int
Definition: Integer.h:28