AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
Grid.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 <tuple>
20
21#include <agxTerrain/export.h>
22#include <agxCollide/Mesh.h>
24
25#include <mutex>
26
27#include <agxTerrain/export.h>
28
29#include <agx/AffineMatrix4x4.h>
30#include <agx/Plane.h>
31#include <agx/Line.h>
32
35#include <agxCollide/Convex.h>
36
39
41
42namespace agxTerrain
43{
44 // Container for defining a height in terms of which voxel level and how filled the voxel is.
46 {
47 int z = 0;
48 float occupancy = 0.0f;
49 };
50
51 // Container struct for containing data regarding removed volume
53 {
58 };
59
60 typedef std::tuple<const agxCollide::Mesh*, agx::AffineMatrix4x4, agxCollide::BoundingAABB> MeshIntersectionTestData;
61 typedef std::tuple<const agxCollide::Shape*, agx::AffineMatrix4x4, agxCollide::BoundingAABB> ShapeIntersectionTestData;
64
65
68
81 {
82 public:
83
85
87
88 using GridFunction = std::function<void(GridCoord, float)>;
89
90
91 public:
95 virtual agx::Vec3 getElementSize() const = 0;
96
100 virtual size_t getMemoryUsage() const = 0;
101
105 virtual bool empty() = 0;
106
110 virtual void clearGrid() = 0;
111
115 virtual void setFloatValue(const GridCoord& ijk, float value) = 0;
116
120 virtual float getFloatValue(const GridCoord& ijk) const = 0;
121
125 virtual bool isActiveVoxel(const GridCoord& /*ijk*/) const = 0;
126
130 virtual size_t getNumActiveVoxels() const = 0;
131
135 virtual agx::Real getTotal() const = 0;
136
137 virtual std::tuple<float, float> getTotalAndLargest() const = 0;
138
140
144 virtual void sizeHint( size_t /*hint*/ ) {}
145
146 /*
147 \return true if the implementation supports iterateVoxels
148 */
149 virtual bool hasIterateSupport() const { return false; }
150
151 /*
152 Implementation dependent method that iterates over all voxels in some order
153 and calls func( voxel_ijk, voxel_value) for each voxel.
154
155 It is not valid to have the function change the grid while iterating.
156 */
157 virtual void iterateVoxels( GridFunction /*func*/ ) const {}
158
159
164 const agxCollide::Geometry* geometry,
165 agx::Real voxelSize,
166 bool onlyOccupiedVoxels = true,
167 bool onlyMidPoint = false ) const = 0;
168
169
170
172 void store( agxStream::OutputArchive& out ) const override = 0;
173 void restore( agxStream::InputArchive& in ) override = 0;
174
175
176 protected:
177 /*
178 Get the center position of the specified voxel in voxel space coordinates.
179 \param voxelIndex - agx::Vec3i with x and y >= 0.
180 */
181 inline agx::Vec3 getGridPositionFromVoxelIndex(const agx::Vec3i& voxelIndex) const
182 {
183 return VoxelGridUtils::getGridPositionFromVoxelIndex(voxelIndex, getElementSize().x());
184 }
185
186 /*
187 Get the voxel index from a voxel space position in the grid.
188 \param position - voxel space position
189 */
191 {
192 return VoxelGridUtils::getVoxelIndexFromGridPosition(position, getElementSize().x());
193 }
194 };
195
196
202 {
203
204 public:
205
206
207
209
210
212 const agxCollide::HeightField* heightField,
213 agx::Real voxelSize,
214 int lowestAllowedVoxelIndex,
215 BasicGrid* compactionGrid) = 0;
216
217
219 const agxCollide::Convex* convex,
220 agx::Real voxelSize) = 0;
221
222
223 virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
224 const agxCollide::Mesh* mesh,
225 agx::Real voxelSize,
226 agx::Vec3iVector& result) = 0;
227
228
229
231 const agx::AffineMatrix4x4& gridTransform,
232 const TriangleVector& triangles,
233 agx::Real voxelSize,
234 agx::Real margin) = 0;
235
236
237
239 const agx::AffineMatrix4x4& gridTransformation,
240 const ActiveZoneShapes& activeZoneShapes,
241 const ActiveZoneShapes& innerShape,
242 const agx::Plane& innerShapeBoundary,
243 const agx::Bound3& activeZoneGeometryBound,
244 const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
245 std::function<float(const agx::Vec3i&)> getCompression,
246 std::function<bool(const agx::Vec2i&)> canRemoveIndex,
247 agx::Real voxelSize,
248 agx::Real minOccupancyRemoval,
249 std::function<agx::Real(const agx::Vec2i&)> getMinAllowedHeight,
250 bool useParticleFreeDeformers) = 0;
251
252
253
255 const ShapeIntersectionTestData& shape,
256 std::function<float( const agx::Vec3i& )> getCompression,
257 std::function<bool( const agx::Vec2i& )> canRemoveIndex,
258 std::function<bool( const agx::Vec3&, const agx::Vec3i& )> isWithinBoundry,
259 agx::Real voxelSize,
260 agx::Real minOccupancyRemoval,
261 std::function<agx::Real(const agx::Vec2i&)> getMinAllowedHeight) = 0;
262
263 virtual agx::Vec3iVector findVoxelsInLine( const agx::Line& gridLine ) const = 0;
264
265 virtual void findVoxelSurfaceFromIndex( const agx::Vec3i& index, agx::Vec3i& result ) = 0;
266
268 };
269
270
271
272}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#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
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:81
void store(agxStream::OutputArchive &out) const override=0
virtual bool hasIterateSupport() const
Definition: Grid.h:149
virtual void iterateVoxels(GridFunction) const
Definition: Grid.h:157
void restore(agxStream::InputArchive &in) override=0
virtual agx::Vec3 getElementSize() const =0
Get the element size used for the voxel grid.
virtual std::tuple< float, float > getTotalAndLargest() const =0
virtual bool isActiveVoxel(const GridCoord &) const =0
Test if voxel ijk is active.
virtual bool empty()=0
Test if the trid is empty.
virtual float getFloatValue(const GridCoord &ijk) const =0
Return value for voxel ijk.
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(agxTerrain::BasicGrid)
virtual size_t getMemoryUsage() const =0
Get the memory usage.
virtual void clearGrid()=0
Clear the grid.
virtual void setFloatValue(const GridCoord &ijk, float value)=0
Set value for voxel ijk.
virtual agx::HashSet< agx::Vec3i > findGeometryVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Geometry *geometry, agx::Real voxelSize, bool onlyOccupiedVoxels=true, bool onlyMidPoint=false) const =0
Find which voxels that overlap with a geometry.
virtual size_t getNumActiveVoxels() const =0
Return number of active voxels in the data structure.
agx::Vec3 getGridPositionFromVoxelIndex(const agx::Vec3i &voxelIndex) const
Definition: Grid.h:181
virtual agx::Real getTotal() const =0
Returns the sum of all voxel values.
virtual GridCoordVector getActiveVoxelIndices() const =0
agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 position) const
Definition: Grid.h:190
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:88
virtual void sizeHint(size_t)
Provide the implementation with a hint about the estimated number of voxels that are needed.
Definition: Grid.h:144
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:202
virtual agx::Vec3iVector findVoxelsInLine(const agx::Line &gridLine) const =0
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)=0
virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Mesh *mesh, agx::Real voxelSize, agx::Vec3iVector &result)=0
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(agxTerrain::Grid)
virtual void findVoxelSurfaceFromIndex(const agx::Vec3i &index, agx::Vec3i &result)=0
virtual agx::HashSet< agx::Vec3i > findConvexVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Convex *convex, agx::Real voxelSize)=0
virtual agxCollide::BoundingAABB getBoundingBox() const =0
virtual agx::HashSet< agx::Vec3i > findVoxelsAboveTriangles(const agx::AffineMatrix4x4 &gridTransform, const TriangleVector &triangles, agx::Real voxelSize, agx::Real margin)=0
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)=0
virtual void setValuesBelowHeightField(const agxCollide::HeightField *heightField, agx::Real voxelSize, int lowestAllowedVoxelIndex, BasicGrid *compactionGrid)=0
A BoundT represents a range defined by a minimum and a maximum value.
Definition: Bound.h:37
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
Base class providing referencing counted objects.
Definition: Referenced.h:120
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:59
agx::Vector< std::array< agx::Vec3, 3 > > TriangleVector
Definition: Grid.h:63
std::tuple< const agxCollide::Mesh *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > MeshIntersectionTestData
Definition: Grid.h:60
std::tuple< const agxCollide::Shape *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > ShapeIntersectionTestData
Definition: Grid.h:61
agx::Vector< MeshIntersectionTestData > ActiveZoneShapes
Definition: Grid.h:62
Vec3T< Int > Vec3i
Definition: agx/Vec3.h:43
double Real
Definition: Real.h:41
agx::Vec3iVector removedIndices
Definition: Grid.h:55
agx::Real32Vector removedOccupancy
Definition: Grid.h:56