AGX Dynamics  2.37.3.2
Grid.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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;
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 
130  virtual GridCoordVector getActiveVoxelIndices() const = 0;
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 
154  virtual agx::HashSet<agx::Vec3i> findGeometryVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
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 
179  virtual agxCollide::BoundingAABB getBoundingBox() const = 0;
180 
181 
182  virtual void setValuesBelowHeightField(
183  const agxCollide::HeightField* heightField,
184  agx::Real voxelSize,
185  int lowestAllowedVoxelIndex,
186  BasicGrid* compactionGrid) = 0;
187 
188 
189  virtual agx::HashSet<agx::Vec3i> findConvexVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
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 
201  virtual agx::HashSet<agx::Vec3i> findVoxelsAboveTriangles(const agx::AffineMatrix4x4& gridTransform,
202  const TriangleVector& triangles,
203  agx::Real voxelSize,
204  agx::Real margin) = 0;
205 
206 
207 
208  virtual ActiveZoneIntersectionData removeVolumeInActiveZone(const agx::AffineMatrix4x4& gridTransformation,
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 
223  virtual ActiveZoneIntersectionData removeVolumeInShape( const agx::AffineMatrix4x4& gridTransformation,
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 }
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
A BoundT represents a range defined by a minimum and a maximum value.
Definition: Bound.h:36
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
Definition: Mesh.h:69
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...
std::tuple< const agxCollide::Mesh *, agx::AffineMatrix4x4, agxCollide::BoundingAABB > MeshIntersectionTestData
Definition: Grid.h:51
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:71
virtual void sizeHint(size_t)
Provide the implementation with a hint about the estimated number of voxels that are needed...
Definition: Grid.h:135
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
agx::Real32Vector removedOccupancy
Definition: Grid.h:47
A convex class for geometric intersection tests.
Definition: Convex.h:36
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
virtual bool hasIterateSupport() const
Definition: Grid.h:140
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
Extended pure virtual interface for Grid storage classes.
Definition: Grid.h:172
virtual void iterateVoxels(GridFunction) const
Definition: Grid.h:148
agx::Vec3iVector removedIndices
Definition: Grid.h:46
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Templated vector class.
Definition: Vector.h:52
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
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: Vec3.h:43
#define AGXTERRAIN_EXPORT
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
std::function< void(GridCoord, float)> GridFunction
Definition: Grid.h:79
agx::Vector< std::array< agx::Vec3, 3 > > TriangleVector
Definition: Grid.h:54
#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
double Real
Definition: Real.h:42
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
A HeightField is a collision shape that can be created from a grid structure, like an image...