AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ColumnHeightGrid.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 <agxTerrain/Grid.h>
21
22namespace agxTerrain
23{
24
29 {
30
31 public:
32
33 ColumnHeightGrid( const float defaultValue,
34 const size_t resolutionX,
35 const size_t resolutionY,
36 const agx::Int depth,
37 agx::Real voxelSize );
38
40
41 virtual agx::Vec3 getElementSize() const override;
42
43 virtual size_t getMemoryUsage() const override;
44
45 virtual bool empty() override;
46
47 virtual void clearGrid() override;
48
49 virtual void setFloatValue(const GridCoord& ijk, float value) override;
50
51 virtual float getFloatValue(const GridCoord& ijk) const override;
52
53 virtual bool isActiveVoxel(const GridCoord& /*ijk*/) const override;
54
55 virtual size_t getNumActiveVoxels() const override;
56
57 virtual agx::Real getTotal() const override;
58
59 virtual std::tuple<float, float> getTotalAndLargest() const override;
60
61 virtual GridCoordVector getActiveVoxelIndices() const override;
62
63 virtual void sizeHint(size_t /*hint*/) override;
64
65 virtual bool hasIterateSupport() const override;
66
67 virtual void iterateVoxels(GridFunction func) const override;
68
70 const agx::AffineMatrix4x4& gridTransform,
71 const agxCollide::Geometry* geometry,
72 agx::Real voxelSize,
73 bool /*onlyOccupiedVoxels*/ = true) const override;
74
76
78 const agxCollide::HeightField* heightField,
79 agx::Real voxelSize,
80 int lowestAllowedVoxelIndex,
81 BasicGrid* compactionGrid) override;
82
84 const agx::AffineMatrix4x4& gridTransform,
85 const agxCollide::Convex* convex,
86 agx::Real voxelSize) override;
87
89 const agx::AffineMatrix4x4& gridTransform,
90 const agxCollide::Mesh* mesh,
91 agx::Real voxelSize,
92 agx::Vec3iVector& result) override;
93
95 const agx::AffineMatrix4x4& gridTransform,
96 const TriangleVector& triangles,
97 agx::Real voxelSize,
98 agx::Real margin) override;
99
101 const ActiveZoneShapes& activeZoneShapes,
102 const MeshIntersectionTestData& innerShape,
103 const agx::Plane& innerShapeBoundary,
104 const agx::Bound3& activeZoneGeometryBound,
105 const agx::Vec3iVector voxelsInPrimaryActiveZoneLastTimeStep,
106 std::function<float(const agx::Vec3i&)> getCompression,
107 std::function<bool(const agx::Vec2i&)> canRemoveIndex,
108 agx::Real voxelSize,
109 agx::Real minOccupancyRemoval,
110 agx::Real minAllowedHeight,
111 bool useParticleFreeDeformers) override;
112
114 const ShapeIntersectionTestData& shape,
115 std::function<float( const agx::Vec3i& )> getCompression,
116 std::function<bool( const agx::Vec2i& )> canRemoveIndex,
117 std::function<bool( const agx::Vec3&, const agx::Vec3i& )> isWithinBoundry,
118 agx::Real voxelSize,
119 agx::Real minOccupancyRemoval,
120 agx::Real minAllowedHeight ) override;
121
122 virtual agx::Vec3iVector findVoxelsInLine( const agx::Line& gridLine ) const override;
123
124 virtual void findVoxelSurfaceFromIndex( const agx::Vec3i& index,
125 agx::Vec3i& result ) override;
126
128
129 int getSurfaceHeightIndex(const agx::Vec2i terrainIndex);
130
131 std::pair<int, float> getVoxelZAndOccupancyFromLocalHeight(agx::Real height, agx::Real voxelSize);
132
133 void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy);
134
135 void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy);
136
140 int getDepth() const;
141
143
144 protected:
145
146 inline agx::Vec3 getGridPositionFromVoxelIndex(const agx::Vec3i& voxelIndex) const
147 {
148 return VoxelGridUtils::getGridPositionFromVoxelIndex(voxelIndex, m_voxelSize);
149 }
150
152 {
153 return VoxelGridUtils::getVoxelIndexFromGridPosition(position, m_voxelSize);
154 }
155
157
159
160 private:
161
162 struct VoxelElement
163 {
164 int z = 0;
165 float occupancy = 0.0;
166 };
167
169
170 GridData m_solidMassArray;
171 float m_default;
172 size_t m_resolutionX;
173 size_t m_resolutionY;
174 agx::Int m_depth;
175 agx::Real m_voxelSize;
176 };
177 }
178
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#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
Pure virtual interface class for the data storage grid classes we have.
Definition Grid.h:72
std::function< void(GridCoord, float)> GridFunction
Definition Grid.h:79
Class implementing the BasicGrid interface.
virtual bool empty() override
Test if the trid is empty.
virtual bool hasIterateSupport() const override
virtual agx::Real getTotal() const override
Returns the sum of all voxel values.
virtual std::tuple< float, float > getTotalAndLargest() const override
virtual agx::Vec3iVector findVoxelsInLine(const agx::Line &gridLine) const override
agxCollide::BoundingAABB getBoundingBox() const override
agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 position) const
virtual float getFloatValue(const GridCoord &ijk) const override
Return value for voxel ijk.
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) override
virtual void iterateVoxels(GridFunction func) const override
virtual void sizeHint(size_t) override
Provide the implementation with a hint about the estimated number of voxels that are needed.
virtual GridCoordVector getActiveVoxelIndices() const override
virtual agx::Vec3 getElementSize() const override
Get the element size used for the voxel grid.
ColumnHeightGrid(const float defaultValue, const size_t resolutionX, const size_t resolutionY, const agx::Int depth, agx::Real voxelSize)
virtual void setValuesBelowHeightField(const agxCollide::HeightField *heightField, agx::Real voxelSize, int lowestAllowedVoxelIndex, BasicGrid *compactionGrid) override
virtual size_t getMemoryUsage() const override
Get the memory usage.
virtual void setFloatValue(const GridCoord &ijk, float value) override
Set value for voxel ijk.
virtual void clearGrid() override
Clear the grid.
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) override
agx::Vec3 getGridPositionFromVoxelIndex(const agx::Vec3i &voxelIndex) const
virtual bool isActiveVoxel(const GridCoord &) const override
Test if voxel ijk is active.
void setOccupancyInSurfaceVoxel(const agx::Vec2i terrainIndex, float occupancy)
void setGridColumnOccupancy(const agx::Vec2i terrainIndex, int voxelZ, float occupancy)
virtual void findVoxelSurfaceFromIndex(const agx::Vec3i &index, agx::Vec3i &result) override
virtual size_t getNumActiveVoxels() const override
Return number of active voxels in the data structure.
virtual agx::HashSet< agx::Vec3i > findGeometryVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Geometry *geometry, agx::Real voxelSize, bool=true) const override
Find which voxels that overlap with a geometry.
std::pair< int, float > getVoxelZAndOccupancyFromLocalHeight(agx::Real height, agx::Real voxelSize)
int getSurfaceHeightIndex(const agx::Vec2i terrainIndex)
virtual agx::HashSet< agx::Vec3i > findConvexVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Convex *convex, agx::Real voxelSize) override
virtual agx::HashSet< agx::Vec3i > findVoxelsAboveTriangles(const agx::AffineMatrix4x4 &gridTransform, const TriangleVector &triangles, agx::Real voxelSize, agx::Real margin) override
virtual bool findMeshVoxelIntersections(const agx::AffineMatrix4x4 &gridTransform, const agxCollide::Mesh *mesh, agx::Real voxelSize, agx::Vec3iVector &result) override
Extended pure virtual interface for Grid storage classes.
Definition Grid.h:173
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
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
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
double Real
Definition Real.h:42
int64_t Int
Definition Integer.h:28