AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Grid.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 <agxTerrain/export.h>
20 #include <agx/Plane.h>
21 #include <agx/Line.h>
22 #include <agx/AffineMatrix4x4.h>
23 #include <tuple>
24 #include <agxCollide/HeightField.h>
26 
27 namespace agxTerrain
28 {
29  // Container struct for containing data regarding removed volume
31  {
36  };
37 
38  typedef std::tuple<const agxCollide::Mesh*, agx::AffineMatrix4x4, agxCollide::BoundingAABB> MeshIntersectionTestData;
41 
43 
56  {
57  public:
59  struct GridCoord
60  {
62  :i(0), j(0), k(0) {}
64  :i(i), j(j), k(k) {}
66  :i(v.x()), j(v.y()), k(v.z()){}
67 
68  const GridCoord operator+(const GridCoord& rhs) const
69  {
70  return GridCoord{ i + rhs.i, j + rhs.j, k + rhs.k };
71  }
72 
73  agx::Int i=0, j=0, k=0;
74  };
75 
77 
78  public:
79 
80  using Factory = GridRef(*)( float defaultValue, agx::Real voxelSize );
81  static GridRef createGrid( float defaultValue, agx::Real voxelSize );
82 
83  virtual agx::Vec3 getElementSize() const = 0;
84 
85  virtual size_t getMemoryUsage() const = 0;
86 
87  virtual size_t getNumActiveVoxels() const = 0;
88 
89  virtual agxCollide::BoundingAABB getBoundingBox() const = 0;
90 
91  virtual void setValuesBelowPlane(const agx::Plane& plane, const agx::Vec3u& numCells, agx::Real voxelSize) = 0;
92 
93  virtual void setValuesBelowHeightField(
94  const agxCollide::HeightField* heightField,
95  agx::Real voxelSize,
96  int lowestAllowedVoxelIndex,
97  Grid* compactionGrid ) = 0;
98 
99  virtual agx::Vec3iVector removeVolumeInSphere(
100  agx::Real radius, const agx::Vec3& center, agx::Real voxelSize, float emptyValue) = 0;
101 
102  virtual agx::Vec3iVector removeVolumeInGeometry(const agx::AffineMatrix4x4& gridTransform,
103  const agxCollide::Geometry* geometry,
104  agx::Real voxelSize,
105  float emptyValue) = 0;
106 
107  virtual agx::HashSet<agx::Vec3i> findGeometryVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
108  const agxCollide::Geometry* geometry,
109  agx::Real voxelSize,
110  bool onlyOccupiedVoxels = true ) const = 0;
111 
112  virtual agx::HashSet<agx::Vec3i> findShapeVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
113  const agxCollide::Shape* shape,
114  agx::Real voxelSize) = 0;
115 
116  virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
117  const agxCollide::Mesh* mesh,
118  agx::Real voxelSize,
119  agx::Vec3iVector& result) = 0;
120 
121 
122  virtual agx::HashSet<agx::Vec3i> findTriangleListVoxelIntersections(const agx::AffineMatrix4x4& gridTransform,
123  const TriangleVector& triangles,
124  agx::Real voxelSize) = 0;
125 
126  virtual agx::HashSet<agx::Vec3i> findVoxelsAboveTriangles(const agx::AffineMatrix4x4& gridTransform,
127  const TriangleVector& triangles,
128  agx::Real voxelSize,
129  agx::Real margin) = 0;
130 
131  virtual bool findTriangleListVoxelIntersectionsParallel(const agx::AffineMatrix4x4& gridTransform,
132  const agx::Vector<std::array<agx::Vec3, 3>>& triangles,
133  agx::Real voxelSize,
134  agx::Vec3iVector& result) = 0;
135 
136  virtual agx::Vec3iVector removeVolumeInMesh(const agx::AffineMatrix4x4& gridTransform,
137  const agxCollide::Mesh* mesh,
138  const agx::Vec3& up,
139  agx::Real voxelSize ) = 0;
140 
141  virtual ActiveZoneIntersectionData removeVolumeInActiveZone(const agx::AffineMatrix4x4& gridTransform,
142  const ActiveZoneShapes& activeZoneShapes,
143  const MeshIntersectionTestData& innerShapeInfo,
144  const agx::Plane& innerShapeBoundary,
145  const agx::Vec3& up,
146  const agx::Bound3& bound,
147  const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
148  std::function<float(const agx::Vec3i&)> getCompression,
149  std::function<bool(const agx::Vec2i&)> canRemoveIndex,
150  agx::Real voxelSize,
151  agx::Real minOccupancyRemoval,
152  agx::Real minAllowedHeight,
153  bool useParticleFreeDeformers) = 0;
154 
155  virtual agx::Vec3iVector findVoxelsInLineIntersection(const agx::Line& line) const = 0;
156 
157  virtual void setFloatValue(const GridCoord& ijk, float value) = 0;
158 
159  virtual float getFloatValue(const GridCoord& ijk) const = 0;
160 
161  virtual bool isActiveVoxel(const GridCoord& ijk) const = 0;
162 
163  virtual float getTotal() const = 0;
164 
165  virtual agx::Real getTotalReal() const = 0;
166 
167  virtual std::tuple<float, float> getTotalAndLargest() const = 0;
168 
169  virtual void deepCopyGrid(const Grid& grid) = 0;
170 
171  virtual GridRef clone() const = 0;
172 
173  virtual void combine2(const Grid* other1, const Grid* other2) = 0;
174 
175  virtual void combine(const Grid* other1) = 0;
176 
177  virtual bool findVoxelSurfaceFromIndex(const agx::Vec3i& index, agx::Vec3i& result, bool globalSearch = false) =0;
178 
179  virtual void clearGrid() = 0;
180 
181  virtual bool empty() = 0;
182 
183  virtual agx::Vec3iVector getActiveVoxelIndices() = 0;
184 
185  virtual void store( std::ostream& out ) const = 0;
186  virtual void restore( std::istream& in ) = 0;
187  };
188 }
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:68
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:38
Base class for a shape.
Definition: Shape.h:53
agx::Real32Vector removedOccupancy
Definition: Grid.h:34
int32_t Int
Definition: Integer.h:35
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:55
agx::Vec3iVector removedIndices
Definition: Grid.h:33
const GridCoord operator+(const GridCoord &rhs) const
Definition: Grid.h:68
#define AGXTERRAIN_PLUGIN_EXPORT
Base class providing referencing counted objects.
Definition: Referenced.h:113
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
Templated vector class.
Definition: Vector.h:52
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
GridCoord(agx::Int i, agx::Int j, agx::Int k)
Definition: Grid.h:63
agx::Vector< MeshIntersectionTestData > ActiveZoneShapes
Definition: Grid.h:39
Container for holding a grid coordinate.
Definition: Grid.h:59
agx::VectorPOD< Grid::GridCoord > GridCoordVector
Definition: Grid.h:76
GridRef(*)(float defaultValue, agx::Real voxelSize) Factory
Definition: Grid.h:80
GridCoord(const agx::Vec3i &v)
Definition: Grid.h:65
agx::ref_ptr< Grid > GridRef
Definition: Grid.h:42
agx::Vector< std::array< agx::Vec3, 3 > > TriangleVector
Definition: Grid.h:40
double Real
Definition: Real.h:42
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
AGXOSG_EXPORT osg::Geometry * createGrid(unsigned int resU, unsigned int resV, const osg::Vec3 &origin, const osg::Vec3 &endPointX, const osg::Vec3 &endPointY, bool wireFrameMode=false)
Create a uniform grid.
A HeightField is a collision shape that can be created from a grid structure, like an image...