17#ifndef AGXCOLLIDE_HEIGHTFIELD_H
18#define AGXCOLLIDE_HEIGHTFIELD_H
27#include <GIMPACT/AabbTree.h>
147 size_t minVertexX,
size_t maxVertexX,
148 size_t minVertexY,
size_t maxVertexY);
176 agx::Real getHeight(
size_t x,
size_t y)
const;
179 size_t getResolutionX()
const;
182 size_t getResolutionY()
const;
213 agx::Vec3 getVertexFromGrid(
size_t xIndex,
size_t yIndex)
const;
225 void setMinAllowedHeight(
agx::Real minAllowedHeight);
237 void setDynamic(
bool dynamic);
243 bool getDynamic()
const;
293 void calculateVertexCoordinates(
295 size_t& vertexIndexX,
size_t& vertexIndexY)
const;
303 size_t getTriangleIndex(
304 size_t indexX,
size_t indexY,
305 uint_fast8_t upper)
const;
351 virtual
void updateBvhTree() override;
359 void updateTriangle(
size_t triangleIndex,
bool shouldUpdateBvhNode = true);
361 void addQuadrantVolume(
int xIndex,
int yIndex,
agx::Real factor);
363 void addTriangleVolume(const
agx::Vec3& v0, const
agx::Vec3& v1,
364 const
agx::Vec3& v2,
agx::Real factor);
380 void finalize(
bool updateMassProperties, const
agx::RealVector& heights,
bool flipY = false);
388 void setHeights(
bool shouldUpdateMassProperties, const
agx::RealVector& heights,
bool flipY = false);
412 return m_localBound.min().z() + m_collisionMeshData->m_bottomMargin;
418 return m_localBound.max().z();
424 return m_heightFieldData->m_resolutionX;
430 return m_heightFieldData->m_resolutionY;
436 return m_collisionMeshData->m_vertices[x + y * m_heightFieldData->m_resolutionX][2];
442 return m_heightFieldData->m_size;
448 return m_heightFieldData->m_scale;
453 size_t& vertexIndexX,
size_t& vertexIndexY)
const
455 vertexIndexX = vertexIndex % m_heightFieldData->m_resolutionX;
456 vertexIndexY = vertexIndex / m_heightFieldData->m_resolutionX;
460 AGX_FORCE_INLINE size_t HeightField::getTriangleIndex(
size_t indexX,
size_t indexY, uint_fast8_t upper)
const
462 return 2 * (indexX + indexY * (m_heightFieldData->m_resolutionX - 1)) + upper;
469 return getVertex(yIndex * m_heightFieldData->m_resolutionX + xIndex);
475 m_heightFieldData->m_minAllowedHeight = minAllowedHeight;
476 if (m_heightFieldData->m_dynamic)
477 calculateMassProperties();
483 return m_heightFieldData->m_minAllowedHeight;
489 return m_heightFieldData->m_dynamic;
495 m_heightFieldData->m_dynamic = dynamic;
496 calculateMassProperties();
502 return m_heightFieldData;
509 const agx::Vec2 pointInGrid(projectedPoint[0] * m_heightFieldData->m_invScale[0], projectedPoint[1] * m_heightFieldData->m_invScale[1]);
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
Axis aligned bounding box implementation.
Class for data sharing only to be used by HeightField.
A HeightField is a collision shape that can be created from a grid structure, like an image.
bool calculateVertexIndicesTouchedByAABB(const BoundingAABB &volume, const agx::AffineMatrix4x4 &meshToWorld, const agx::AffineMatrix4x4 &volumeToWorld, agx::Vec2i &gridMin, agx::Vec2i &gridMax) const
Calculates the minimum and maximum vertex indices of the square that a bounding box resides in.
bool setHeights(const agx::RealVector &heights, size_t minVertexX, size_t maxVertexX, size_t minVertexY, size_t maxVertexY)
Set height values of all grid nodes within a rectangle.
HeightField * shallowCopy() const
Creates a new HeightField which shares data with this one.
void setHeightsFromList(const agx::Vec2uVector &indices, const agx::RealVector &heights)
Set height values given a list of terrain indices and corresponding heights.
virtual void calculatePossibleTriangleOverlapsAlongLineSegment(const agx::Vec3 &segmentStartLocal, const agx::Vec3 &segmentEndLocal, agxData::LocalVector< agx::UInt32 > &triangleIndices) const override
Calculates an array of triangle indices of the triangles whose bounding volumes get intersected by a ...
HeightField(size_t resolutionX, size_t resolutionY, agx::Real sizeX, agx::Real sizeY, agx::Real bottomMargin=agx::Real(1))
Constructor for the HeightField class.
virtual void calculatePossibleTriangleOverlapsAlongLineSegment(const agx::Vec3 &segmentStartLocal, const agx::Vec3 &segmentEndLocal, agx::UInt32Vector &triangleIndices) const override
Calculates an array of triangle indices of the triangles whose bounding volumes get intersected by a ...
void setHeights(const agx::RealVector &heights, bool flipY=false)
Set height values of all sampled points.
virtual Shape * clone() const override
Create a clone.
static agxCollide::HeightField * createFromFile(const agx::String &filename, agx::Real sizeX, agx::Real sizeY, agx::Real low, agx::Real high, agx::Real bottomMargin=agx::Real(1))
static agxCollide::HeightField * createFromImage(agxIO::Image *image, agx::Real sizeX, agx::Real sizeY, agx::Real low, agx::Real high, agx::Real bottomMargin=agx::Real(1))
void calculateMassProperties()
Calculates "mass properties" such as volume, unscaled inertia tensor and center.
Mesh::Triangle getTriangleFromPoint(const agx::Vec3 &point) const
Returns a triangle given the 2D-projection of a point on the xy-plane in the grid.
void setHeight(size_t xIndex, size_t yIndex, agx::Real height)
Sets the height at a specific grid node.
HeightField(size_t resolutionX, size_t resolutionY, agx::Real sizeX, agx::Real sizeY, const agx::RealVector &heights, bool flipY=false, agx::Real bottomMargin=agx::Real(1))
Constructor for the HeightField class.
HeightField * deepCopy() const
Creates a new HeightField which copies data from this one.
Class for more intuitive access to the Mesh's mesh data.
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
Class to represent Images.
Pointer to a entity instance of type Physics.Geometry.HeightField.
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxIO namespace contains classes for reading, writing and finding files.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec2T< Real > Vec2
The object holding 2 dimensional vectors and providing basic arithmetic.