AGXDynamics  2.35.0.3
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 
129  virtual GridCoordVector getActiveVoxelIndices() const = 0;
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 
153  virtual agx::HashSet<agx::Vec3i> findGeometryVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
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 
178  virtual agxCollide::BoundingAABB getBoundingBox() const = 0;
179 
180 
181  virtual void setValuesBelowHeightField(
182  const agxCollide::HeightField* heightField,
183  agx::Real voxelSize,
184  int lowestAllowedVoxelIndex,
185  BasicGrid* compactionGrid) = 0;
186 
187 
188  virtual agx::HashSet<agx::Vec3i> findConvexVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
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 
200  virtual agx::HashSet<agx::Vec3i> findVoxelsAboveTriangles(const agx::AffineMatrix4x4& gridTransform,
201  const TriangleVector& triangles,
202  agx::Real voxelSize,
203  agx::Real margin) = 0;
204 
205 
206 
207  virtual ActiveZoneIntersectionData removeVolumeInActiveZone(const agx::AffineMatrix4x4& gridTransformation,
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 
222  virtual ActiveZoneIntersectionData removeVolumeInConvex(const agx::AffineMatrix4x4& gridTransformation,
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 
233  virtual agx::Vec3iVector findVoxelsInLineIntersection(const agx::Line& line) const = 0;
234 
235  virtual void findVoxelSurfaceFromIndex(const agx::Vec3i& index, agx::Vec3i& result) = 0;
236 
238  };
239 
240 
241 
242 }
HeightField.h
BoundingAABB.h
agxTerrain::ActiveZoneShapes
agx::Vector< MeshIntersectionTestData > ActiveZoneShapes
Definition: Grid.h:52
InputArchive.h
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
agxTerrain::TriangleVector
agx::Vector< std::array< agx::Vec3, 3 > > TriangleVector
Definition: Grid.h:53
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxStream::out
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.
Definition: OutputArchive.h:412
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:59
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
agxTerrain::Grid
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:171
agx::Vec3i
Vec3T< Int > Vec3i
Definition: Vec3.h:43
agx::AffineMatrix4x4T< Real >
IndexLambdaKernel.h
agxTerrain::BasicGrid::sizeHint
virtual void sizeHint(size_t)
Provide the implementation with a hint about the estimated number of voxels that are needed.
Definition: Grid.h:134
agxCollide::HeightField
A HeightField is a collision shape that can be created from a grid structure, like an image.
Definition: agxCollide/HeightField.h:51
agxTerrain::ActiveZoneIntersectionData::indicesInActiveZone
agx::Bound3i indicesInActiveZone
Definition: Grid.h:45
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
agxCollide::BoundingAABB
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
Plane.h
export.h
agx::BoundT
A BoundT represents a range defined by a minimum and a maximum value.
Definition: Bound.h:36
agxTerrain::BasicGrid::hasIterateSupport
virtual bool hasIterateSupport() const
Definition: Grid.h:139
agxStream::in
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
AffineMatrix4x4.h
agx::PlaneT
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
agxTerrain::ActiveZoneIntersectionData::removedOccupancy
agx::Real32Vector removedOccupancy
Definition: Grid.h:47
Line.h
agxTerrain::BasicGrid::iterateVoxels
virtual void iterateVoxels(GridFunction) const
Definition: Grid.h:147
agxTerrain::ActiveZoneIntersectionData::removedVolume
agx::Real removedVolume
Definition: Grid.h:48
Convex.h
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
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agxTerrain::ActiveZoneIntersectionData::removedIndices
agx::Vec3iVector removedIndices
Definition: Grid.h:46
agx::HashSet< agx::Vec3i >
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
agxTerrain::MeshIntersectionTestData
std::tuple< const agxCollide::Mesh *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > MeshIntersectionTestData
Definition: Grid.h:51
Mesh.h
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
AGXTERRAIN_EXPORT
#define AGXTERRAIN_EXPORT
Definition: agxTerrain/export.h:41
agxCollide::Convex
A convex class for geometric intersection tests.
Definition: Convex.h:37
OutputArchive.h
agx::Vec3T< Int >
agxTerrain::BasicGrid::GridFunction
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:78