AGX Dynamics  2.35.0.1
Grid.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 <tuple>
20 
21 #include <agxTerrain/export.h>
22 #include <agxCollide/Mesh.h>
23 #include <agx/IndexLambdaKernel.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 
33 #include <agxCollide/HeightField.h>
35 #include <agxCollide/Convex.h>
36 
37 #include <agxStream/InputArchive.h>
39 
40 namespace agxTerrain
41 {
42  // Container struct for containing data regarding removed volume
44  {
49  };
50 
51  typedef std::tuple<const agxCollide::Mesh*, agx::AffineMatrix4x4, agxCollide::BoundingAABB> MeshIntersectionTestData;
54 
55 
58 
71  {
72  public:
73 
75 
77 
78  using GridFunction = std::function<void(GridCoord, float)>;
79 
80 
81  public:
85  virtual agx::Vec3 getElementSize() const = 0;
86 
90  virtual size_t getMemoryUsage() const = 0;
91 
95  virtual bool empty() = 0;
96 
100  virtual void clearGrid() = 0;
101 
105  virtual void setFloatValue(const GridCoord& ijk, float value) = 0;
106 
110  virtual float getFloatValue(const GridCoord& ijk) const = 0;
111 
115  virtual bool isActiveVoxel(const GridCoord& /*ijk*/) const = 0;
116 
120  virtual size_t getNumActiveVoxels() const = 0;
121 
125  virtual agx::Real getTotal() const = 0;
126 
127  virtual std::tuple<float, float> getTotalAndLargest() const = 0;
128 
130 
134  virtual void sizeHint( size_t /*hint*/ ) {}
135 
136  /*
137  \return true if the implementation supports iterateVoxels
138  */
139  virtual bool hasIterateSupport() const { return false; }
140 
141  /*
142  Implementation dependent method that iterates over all voxels in some order
143  and calls func( voxel_ijk, voxel_value) for each voxel.
144 
145  It is not valid to have the function change the grid while iterating.
146  */
147  virtual void iterateVoxels( GridFunction /*func*/ ) const {}
148 
149 
154  const agxCollide::Geometry* geometry,
155  agx::Real voxelSize,
156  bool onlyOccupiedVoxels = true ) const = 0;
157 
158 
159 
161  void store( agxStream::OutputArchive& out ) const override = 0;
162  void restore( agxStream::InputArchive& in ) override = 0;
163 
164  };
165 
166 
172  {
173 
174  public:
175 
176 
177 
179 
180 
182  const agxCollide::HeightField* heightField,
183  agx::Real voxelSize,
184  int lowestAllowedVoxelIndex,
185  BasicGrid* compactionGrid) = 0;
186 
187 
189  const agxCollide::Convex* convex,
190  agx::Real voxelSize) = 0;
191 
192 
193  virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
194  const agxCollide::Mesh* mesh,
195  agx::Real voxelSize,
196  agx::Vec3iVector& result) = 0;
197 
198 
199 
201  const TriangleVector& triangles,
202  agx::Real voxelSize,
203  agx::Real margin) = 0;
204 
205 
206 
208  const ActiveZoneShapes& activeZoneShapes,
209  const MeshIntersectionTestData& innerShape,
210  const agx::Plane& innerShapeBoundary,
211  const agx::Bound3& activeZoneGeometryBound,
212  const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
213  std::function<float(const agx::Vec3i&)> getCompression,
214  std::function<bool(const agx::Vec2i&)> canRemoveIndex,
215  agx::Real voxelSize,
216  agx::Real minOccupancyRemoval,
217  agx::Real minAllowedHeight,
218  bool useParticleFreeDeformers) = 0;
219 
220 
221 
223  const MeshIntersectionTestData& shape,
224  const agx::Plane& innerShapeBoundary,
225  const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
226  std::function<float(const agx::Vec3i&)> getCompression,
227  std::function<bool(const agx::Vec2i&)> canRemoveIndex,
228  agx::Real voxelSize,
229  agx::Real minOccupancyRemoval,
230  agx::Real minAllowedHeight,
231  bool useParticleFreeDeformers) = 0;
232 
234 
235  virtual void findVoxelSurfaceFromIndex(const agx::Vec3i& index, agx::Vec3i& result) = 0;
236 
238  };
239 
240 
241 
242 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXTERRAIN_EXPORT
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
A convex class for geometric intersection tests.
Definition: Convex.h:38
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
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:52
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:45
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:71
void store(agxStream::OutputArchive &out) const override=0
virtual bool hasIterateSupport() const
Definition: Grid.h:139
virtual void iterateVoxels(GridFunction) const
Definition: Grid.h:147
void restore(agxStream::InputArchive &in) override=0
virtual agx::Vec3 getElementSize() const =0
Get the element size used for the voxel grid.
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 std::tuple< float, float > getTotalAndLargest() 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.
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
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:78
virtual void sizeHint(size_t)
Provide the implementation with a hint about the estimated number of voxels that are needed.
Definition: Grid.h:134
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:172
virtual agx::HashSet< agx::Vec3i > findConvexVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Convex *convex, agx::Real voxelSize)=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 > findVoxelsAboveTriangles(const agx::AffineMatrix4x4 &gridTransform, const TriangleVector &triangles, agx::Real voxelSize, agx::Real margin)=0
virtual agx::Vec3iVector findVoxelsInLineIntersection(const agx::Line &line) const =0
virtual agxCollide::BoundingAABB getBoundingBox() const =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
virtual ActiveZoneIntersectionData removeVolumeInConvex(const agx::AffineMatrix4x4 &gridTransformation, const MeshIntersectionTestData &shape, const agx::Plane &innerShapeBoundary, 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
A BoundT represents a range defined by a minimum and a maximum value.
Definition: Bound.h:37
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:114
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Templated vector class.
Definition: agx/Vector.h:53
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:60
agx::Vector< std::array< agx::Vec3, 3 > > TriangleVector
Definition: Grid.h:53
std::tuple< const agxCollide::Mesh *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > MeshIntersectionTestData
Definition: Grid.h:51
agx::Vector< MeshIntersectionTestData > ActiveZoneShapes
Definition: Grid.h:52
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