37#ifndef COAL_HEIGHT_FIELD_H 38#define COAL_HEIGHT_FIELD_H 54 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
127template <
typename BV>
129 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
138 return Base::operator==(other) &&
bv == other.
bv;
149 return bv.overlap(other.
bv, request, sqrDistLowerBound);
155 Vec3s* P2 = NULL)
const {
156 return bv.distance(other.
bv, P1, P2);
164 return Matrix3s::Identity();
172template <
typename BV>
175 AABB bv_aabb(pointA, pointB);
178 convertBV(bv_aabb, bv);
185 AABB bv_aabb(pointA, pointB);
186 convertBV(bv_aabb, bv);
201template <
typename BV>
204 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
209 typedef std::vector<Node, Eigen::aligned_allocator<Node>>
BVS;
282 const AABB aabb_(A, B);
291 if (new_heights.rows() !=
heights.rows() ||
292 new_heights.cols() !=
heights.cols())
294 "The matrix containing the new heights values does not have the same " 295 "matrix size as the original one.\n" 296 "\tinput values - rows: " 297 << new_heights.rows() <<
" - cols: " << new_heights.cols() <<
"\n" 298 <<
"\texpected values - rows: " <<
heights.rows()
299 <<
" - cols: " <<
heights.cols() <<
"\n",
300 std::invalid_argument);
317 assert(NX >= 2 &&
"The number of columns is too small.");
318 assert(NY >= 2 &&
"The number of rows is too small.");
324 const size_t num_tot_bvs =
325 (size_t)(NX * NY) - 1 + (size_t)((NX - 1) * (NY - 1));
326 bvs.resize(num_tot_bvs);
367 "the maximal height is not correct");
384 max_height = (std::max)(max_left_height, max_right_height);
399 const Eigen::DenseIndex x_id,
400 const Eigen::DenseIndex x_size,
401 const Eigen::DenseIndex y_id,
402 const Eigen::DenseIndex y_size) {
403 assert(x_id <
heights.cols() &&
"x_id is out of bounds");
404 assert(y_id <
heights.rows() &&
"y_id is out of bounds");
405 assert(x_size >= 0 && y_size >= 0 &&
406 "x_size or y_size are not of correct value");
407 assert(bv_id <
bvs.size() &&
"bv_id exceeds the vector dimension");
420 if (x_size >= y_size)
422 Eigen::DenseIndex x_size_half = x_size / 2;
423 if (x_size == 1) x_size_half = 1;
425 x_size_half, y_id, y_size);
429 x_size - x_size_half, y_id, y_size);
432 Eigen::DenseIndex y_size_half = y_size / 2;
433 if (y_size == 1) y_size_half = 1;
439 y_id + y_size_half, y_size - y_size_half);
442 max_height = (std::max)(max_left_height, max_right_height);
449 assert(x_id + x_size <
x_grid.size());
450 assert(y_id + y_size <
y_grid.size());
465 if (bv_node.
x_id == 0)
468 if (bv_node.
y_id == 0)
502 if (other_ptr ==
nullptr)
return false;
505 return x_dim == other.
x_dim && y_dim == other.
y_dim &&
508 y_grid == other.
y_grid && bvs == other.
bvs &&
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition AABB.h:55
The geometry for the object for collision or distance computation.
Definition collision_object.h:94
Data structure depicting a height field given by the base grid dimensions and the elevation along the...
Definition hfield.h:202
HeightField(const HeightField &other)
Copy contructor from another HeightField.
Definition hfield.h:239
CoalScalar max_height
Definition hfield.h:351
OBJECT_TYPE getObjectType() const
Get the object type: it is a HFIELD.
Definition hfield.h:334
VecXs y_grid
Definition hfield.h:355
const BVS & getNodes() const
Definition hfield.h:271
const VecXs & getXGrid() const
Returns a const reference of the grid along the X direction.
Definition hfield.h:252
CoalScalar computeVolume() const
compute the volume
Definition hfield.h:338
CoalScalar getXDim() const
Returns the dimension of the Height Field along the X direction.
Definition hfield.h:260
virtual ~HeightField()
deconstruction, delete mesh data related.
Definition hfield.h:274
CoalScalar y_dim
Definition hfield.h:344
CoalScalar recursiveUpdateHeight(const size_t bv_id)
Definition hfield.h:374
std::vector< Node, Eigen::aligned_allocator< Node > > BVS
Definition hfield.h:209
HFNode< BV > Node
Definition hfield.h:208
VecXs x_grid
Grids along the X and Y directions. Useful for plotting or other related things.
Definition hfield.h:355
CoalScalar recursiveBuildTree(const size_t bv_id, const Eigen::DenseIndex x_id, const Eigen::DenseIndex x_size, const Eigen::DenseIndex y_id, const Eigen::DenseIndex y_size)
Definition hfield.h:398
HFNode< BV > & getBV(unsigned int i)
Access the bv giving the its index.
Definition hfield.h:490
const MatrixXs & getHeights() const
Returns a const reference of the heights.
Definition hfield.h:257
HeightField()
Constructing an empty HeightField.
Definition hfield.h:212
unsigned int num_bvs
Definition hfield.h:359
MatrixXs heights
Elevation values in meters of the Height Field.
Definition hfield.h:347
int buildTree()
Build the bounding volume hierarchy.
Definition hfield.h:362
HeightField(const CoalScalar x_dim, const CoalScalar y_dim, const MatrixXs &heights, const CoalScalar min_height=(CoalScalar) 0)
Constructing an HeightField from its base dimensions and the set of heights points....
Definition hfield.h:228
const VecXs & getYGrid() const
Returns a const reference of the grid along the Y direction.
Definition hfield.h:254
CoalScalar x_dim
Dimensions in meters along X and Y directions.
Definition hfield.h:344
Vec3s computeCOM() const
compute center of mass
Definition hfield.h:336
NODE_TYPE getNodeType() const
Get the BV type: default is unknown.
Definition hfield.h:497
virtual HeightField< BV > * clone() const
Clone *this into a new CollisionGeometry.
Definition hfield.h:269
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef CollisionGeometry Base
Definition hfield.h:206
void computeLocalAABB()
Compute the AABB for the HeightField, used for broad-phase collision.
Definition hfield.h:278
void init(const CoalScalar x_dim, const CoalScalar y_dim, const MatrixXs &heights, const CoalScalar min_height)
Definition hfield.h:308
CoalScalar getYDim() const
Returns the dimension of the Height Field along the Y direction.
Definition hfield.h:262
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition hfield.h:340
const HFNode< BV > & getBV(unsigned int i) const
Access the bv giving the its index.
Definition hfield.h:483
CoalScalar getMinHeight() const
Returns the minimal height value of the Height Field.
Definition hfield.h:265
CoalScalar getMaxHeight() const
Returns the maximal height value of the Height Field.
Definition hfield.h:267
void updateHeights(const MatrixXs &new_heights)
Update Height Field height.
Definition hfield.h:290
BVS bvs
Bounding volume hierarchy.
Definition hfield.h:358
CoalScalar min_height
Minimal height of the Height Field: all values bellow min_height will be discarded.
Definition hfield.h:351
#define COAL_UNUSED_VARIABLE(var)
Definition fwd.hh:56
#define COAL_THROW_PRETTY(message, exception)
Definition fwd.hh:64
Vec3s center() const
Center of the AABB.
Definition AABB.h:164
AABB aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
Definition collision_object.h:158
@ BV_UNKNOWN
Definition collision_object.h:65
@ OT_HFIELD
Definition collision_object.h:57
Vec3s aabb_center
AABB center in local coordinate.
Definition collision_object.h:151
CollisionGeometry()
Definition collision_object.h:96
CoalScalar aabb_radius
AABB radius.
Definition collision_object.h:154
Main namespace.
Definition broadphase_bruteforce.h:44
Eigen::Matrix< CoalScalar, 3, 3 > Matrix3s
Definition data_types.h:81
Eigen::Matrix< CoalScalar, Eigen::Dynamic, 1 > VecXs
Definition data_types.h:80
bool isEqual(const Eigen::MatrixBase< Derived > &lhs, const Eigen::MatrixBase< OtherDerived > &rhs, const CoalScalar tol=std::numeric_limits< CoalScalar >::epsilon() *100)
Definition tools.h:204
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition collision_object.h:64
CollisionRequestFlag operator&(CollisionRequestFlag a, CollisionRequestFlag b)
Definition collision_data.h:1208
Eigen::Matrix< CoalScalar, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition data_types.h:86
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition collision_object.h:52
@ BVH_OK
Definition BVH_internal.h:64
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition data_types.h:77
double CoalScalar
Definition data_types.h:76
request to the collision algorithm
Definition collision_data.h:311
Eigen::DenseIndex y_size
Definition hfield.h:72
size_t rightChild() const
Return the index of the second child. The index is referred to the bounding volume array (i....
Definition hfield.h:108
Eigen::DenseIndex x_size
Definition hfield.h:71
int contact_active_faces
Definition hfield.h:75
Eigen::Vector2i rightChildIndexes() const
Definition hfield.h:113
bool isLeaf() const
Whether current node is a leaf node (i.e. contains a primitive index)
Definition hfield.h:100
bool operator==(const HFNodeBase &other) const
Comparison operator.
Definition hfield.h:88
size_t first_child
An index for first child node or primitive If the value is positive, it is the index of the first chi...
Definition hfield.h:69
HFNodeBase()
Default constructor.
Definition hfield.h:78
Eigen::DenseIndex y_id
Definition hfield.h:72
bool operator!=(const HFNodeBase &other) const
Difference operator.
Definition hfield.h:96
CoalScalar max_height
Definition hfield.h:74
Eigen::DenseIndex x_id
Definition hfield.h:71
FaceOrientation
Definition hfield.h:56
@ BOTTOM
Definition hfield.h:58
@ NORTH
Definition hfield.h:59
@ EAST
Definition hfield.h:60
@ TOP
Definition hfield.h:57
@ WEST
Definition hfield.h:62
@ SOUTH
Definition hfield.h:61
size_t leftChild() const
Return the index of the first child. The index is referred to the bounding volume array (i....
Definition hfield.h:104
Eigen::Vector2i leftChildIndexes() const
Definition hfield.h:110
bool overlap(const HFNode &other) const
Check whether two BVNode collide.
Definition hfield.h:145
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef HFNodeBase Base
Definition hfield.h:131
CoalScalar distance(const HFNode &other, Vec3s *P1=NULL, Vec3s *P2=NULL) const
Compute the distance between two BVNode. P1 and P2, if not NULL and the underlying BV supports distan...
Definition hfield.h:154
bool operator!=(const HFNode &other) const
Difference operator.
Definition hfield.h:142
bool overlap(const HFNode &other, const CollisionRequest &request, CoalScalar &sqrDistLowerBound) const
Check whether two BVNode collide.
Definition hfield.h:147
bool operator==(const HFNode &other) const
Equality operator.
Definition hfield.h:137
virtual ~HFNode()
Definition hfield.h:167
coal::Matrix3s::IdentityReturnType getOrientation() const
Access to the orientation of the BV.
Definition hfield.h:163
Vec3s getCenter() const
Access to the center of the BV.
Definition hfield.h:160
BV bv
bounding volume storing the geometry
Definition hfield.h:134
static void run(const Vec3s &pointA, const Vec3s &pointB, AABB &bv)
Definition hfield.h:184
static void run(const Vec3s &pointA, const Vec3s &pointB, BV &bv)
Definition hfield.h:174