AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Grid.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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
40namespace agxTerrain
41{
42 // Container struct for containing data regarding removed volume
50
51 typedef std::tuple<const agxCollide::Mesh*, agx::AffineMatrix4x4, agxCollide::BoundingAABB> MeshIntersectionTestData;
52 typedef std::tuple<const agxCollide::Shape*, agx::AffineMatrix4x4, agxCollide::BoundingAABB> ShapeIntersectionTestData;
55
56
59
72 {
73 public:
74
76
78
79 using GridFunction = std::function<void(GridCoord, float)>;
80
81
82 public:
86 virtual agx::Vec3 getElementSize() const = 0;
87
91 virtual size_t getMemoryUsage() const = 0;
92
96 virtual bool empty() = 0;
97
101 virtual void clearGrid() = 0;
102
106 virtual void setFloatValue(const GridCoord& ijk, float value) = 0;
107
111 virtual float getFloatValue(const GridCoord& ijk) const = 0;
112
116 virtual bool isActiveVoxel(const GridCoord& /*ijk*/) const = 0;
117
121 virtual size_t getNumActiveVoxels() const = 0;
122
126 virtual agx::Real getTotal() const = 0;
127
128 virtual std::tuple<float, float> getTotalAndLargest() const = 0;
129
131
135 virtual void sizeHint( size_t /*hint*/ ) {}
136
137 /*
138 \return true if the implementation supports iterateVoxels
139 */
140 virtual bool hasIterateSupport() const { return false; }
141
142 /*
143 Implementation dependent method that iterates over all voxels in some order
144 and calls func( voxel_ijk, voxel_value) for each voxel.
145
146 It is not valid to have the function change the grid while iterating.
147 */
148 virtual void iterateVoxels( GridFunction /*func*/ ) const {}
149
150
155 const agxCollide::Geometry* geometry,
156 agx::Real voxelSize,
157 bool onlyOccupiedVoxels = true ) const = 0;
158
159
160
162 void store( agxStream::OutputArchive& out ) const override = 0;
163 void restore( agxStream::InputArchive& in ) override = 0;
164
165 };
166
167
173 {
174
175 public:
176
177
178
180
181
183 const agxCollide::HeightField* heightField,
184 agx::Real voxelSize,
185 int lowestAllowedVoxelIndex,
186 BasicGrid* compactionGrid) = 0;
187
188
190 const agxCollide::Convex* convex,
191 agx::Real voxelSize) = 0;
192
193
194 virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
195 const agxCollide::Mesh* mesh,
196 agx::Real voxelSize,
197 agx::Vec3iVector& result) = 0;
198
199
200
202 const TriangleVector& triangles,
203 agx::Real voxelSize,
204 agx::Real margin) = 0;
205
206
207
209 const ActiveZoneShapes& activeZoneShapes,
210 const MeshIntersectionTestData& innerShape,
211 const agx::Plane& innerShapeBoundary,
212 const agx::Bound3& activeZoneGeometryBound,
213 const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
214 std::function<float(const agx::Vec3i&)> getCompression,
215 std::function<bool(const agx::Vec2i&)> canRemoveIndex,
216 agx::Real voxelSize,
217 agx::Real minOccupancyRemoval,
218 agx::Real minAllowedHeight,
219 bool useParticleFreeDeformers) = 0;
220
221
222
224 const ShapeIntersectionTestData& shape,
225 std::function<float( const agx::Vec3i& )> getCompression,
226 std::function<bool( const agx::Vec2i& )> canRemoveIndex,
227 std::function<bool( const agx::Vec3&, const agx::Vec3i& )> isWithinBoundry,
228 agx::Real voxelSize,
229 agx::Real minOccupancyRemoval,
230 agx::Real minAllowedHeight) = 0;
231
232 virtual agx::Vec3iVector findVoxelsInLine( const agx::Line& gridLine ) const = 0;
233
234 virtual void findVoxelSurfaceFromIndex( const agx::Vec3i& index, agx::Vec3i& result ) = 0;
235
237 };
238
239
240
241}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXTERRAIN_EXPORT
Axis aligned bounding box implementation.
A convex class for geometric intersection tests.
Definition Convex.h:37
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.
Class for writing serialized data in binary format to a stream.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Pure virtual interface class for the data storage grid classes we have.
Definition Grid.h:72
void store(agxStream::OutputArchive &out) const override=0
virtual bool hasIterateSupport() const
Definition Grid.h:140
virtual void iterateVoxels(GridFunction) const
Definition Grid.h:148
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 size_t getNumActiveVoxels() const =0
Return number of active voxels in the data structure.
virtual agx::Real getTotal() const =0
Returns the sum of all voxel values.
virtual GridCoordVector getActiveVoxelIndices() const =0
virtual agx::HashSet< agx::Vec3i > findGeometryVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Geometry *geometry, agx::Real voxelSize, bool onlyOccupiedVoxels=true) const =0
Find which voxels that overlap with a geometry.
std::function< void(GridCoord, float)> GridFunction
Definition Grid.h:79
virtual void sizeHint(size_t)
Provide the implementation with a hint about the estimated number of voxels that are needed.
Definition Grid.h:135
Extended pure virtual interface for Grid storage classes.
Definition Grid.h:173
virtual agx::Vec3iVector findVoxelsInLine(const agx::Line &gridLine) const =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, agx::Real minAllowedHeight)=0
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)=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.
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:54
std::tuple< const agxCollide::Mesh *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > MeshIntersectionTestData
Definition Grid.h:51
std::tuple< const agxCollide::Shape *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > ShapeIntersectionTestData
Definition Grid.h:52
agx::Vector< MeshIntersectionTestData > ActiveZoneShapes
Definition Grid.h:53
Vec3T< Int > Vec3i
Definition agx/Vec3.h:43
double Real
Definition Real.h:42
agx::Vec3iVector removedIndices
Definition Grid.h:46
agx::Real32Vector removedOccupancy
Definition Grid.h:47