Go to the documentation of this file.
37 #ifndef COAL_HEIGHT_FIELD_H
38 #define COAL_HEIGHT_FIELD_H
54 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
84 max_height(std::numeric_limits<
CoalScalar>::lowest()),
85 contact_active_faces(0) {}
90 x_size == other.
x_size && y_id == other.
y_id &&
100 inline bool isLeaf()
const {
return x_size == 1 && y_size == 1; }
111 return Eigen::Vector2i(x_id, y_id);
114 return Eigen::Vector2i(x_id + x_size / 2, y_id + y_size / 2);
127 template <
typename BV>
129 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
138 return Base::operator==(other) && bv == other.
bv;
149 return bv.overlap(other.
bv, request, sqrDistLowerBound);
156 return bv.distance(other.
bv,
P1,
P2);
164 return Matrix3s::Identity();
172 template <
typename BV>
175 AABB bv_aabb(pointA, pointB);
185 AABB bv_aabb(pointA, pointB);
201 template <
typename BV>
204 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
209 typedef std::vector<Node, Eigen::aligned_allocator<Node>>
BVS;
214 min_height((std::numeric_limits<
CoalScalar>::min)()),
215 max_height((std::numeric_limits<
CoalScalar>::max)()) {}
232 init(x_dim, y_dim, heights, min_height);
243 heights(other.heights),
244 min_height(other.min_height),
245 max_height(other.max_height),
246 x_grid(other.x_grid),
247 y_grid(other.y_grid),
249 num_bvs(other.num_bvs) {}
279 const Vec3s A(x_grid[0], y_grid[0], min_height);
280 const Vec3s B(x_grid[x_grid.size() - 1], y_grid[y_grid.size() - 1],
284 aabb_radius = (
A -
B).norm() / 2.;
286 aabb_center = aabb_.
center();
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);
302 heights = new_heights.cwiseMax(min_height);
303 this->max_height = recursiveUpdateHeight(0);
304 assert(this->max_height == heights.maxCoeff());
312 this->heights = heights.cwiseMax(min_height);
313 this->min_height = min_height;
314 this->max_height = heights.maxCoeff();
316 const Eigen::DenseIndex NX = heights.cols(), NY = heights.rows();
317 assert(NX >= 2 &&
"The number of columns is too small.");
318 assert(NY >= 2 &&
"The number of rows is too small.");
320 x_grid = VecXs::LinSpaced(NX, -0.5 * x_dim, 0.5 * x_dim);
321 y_grid = VecXs::LinSpaced(NY, 0.5 * y_dim, -0.5 * y_dim);
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);
365 recursiveBuildTree(0, 0, heights.cols() - 1, 0, heights.rows() - 1);
366 assert(max_recursive_height == max_height &&
367 "the maximal height is not correct");
379 max_height = heights.block<2, 2>(bv_node.
y_id, bv_node.
x_id).maxCoeff();
382 max_right_height = recursiveUpdateHeight(bv_node.
rightChild());
384 max_height = (std::max)(max_left_height, max_right_height);
389 const Vec3s pointA(x_grid[bv_node.
x_id], y_grid[bv_node.
y_id], min_height);
391 y_grid[bv_node.
y_id + bv_node.
y_size], max_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");
414 max_height = heights.block<2, 2>(y_id, x_id).maxCoeff();
419 CoalScalar max_left_height = min_height, max_right_height = min_height;
420 if (x_size >= y_size)
422 Eigen::DenseIndex x_size_half = x_size / 2;
423 if (x_size == 1) x_size_half = 1;
424 max_left_height = recursiveBuildTree(bv_node.
leftChild(), x_id,
425 x_size_half, y_id, y_size);
428 recursiveBuildTree(bv_node.
rightChild(), x_id + x_size_half,
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;
434 max_left_height = recursiveBuildTree(bv_node.
leftChild(), x_id, x_size,
438 recursiveBuildTree(bv_node.
rightChild(), x_id, x_size,
439 y_id + y_size_half, y_size - y_size_half);
442 max_height = (std::max)(max_left_height, max_right_height);
448 const Vec3s pointA(x_grid[x_id], y_grid[y_id], min_height);
449 assert(x_id + x_size < x_grid.size());
450 assert(y_id + y_size < y_grid.size());
451 const Vec3s pointB(x_grid[x_id + x_size], y_grid[y_id + y_size],
465 if (bv_node.
x_id == 0)
468 if (bv_node.
y_id == 0)
471 if (bv_node.
x_id + 1 == heights.cols() - 1)
474 if (bv_node.
y_id + 1 == heights.rows() - 1)
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 &&
531 NODE_TYPE HeightField<KDOP<16>>::getNodeType()
const;
534 NODE_TYPE HeightField<KDOP<18>>::getNodeType()
const;
537 NODE_TYPE HeightField<KDOP<24>>::getNodeType()
const;
const VecXs & getXGrid() const
Returns a const reference of the grid along the X direction.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef HFNodeBase Base
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....
const MatrixXs & getHeights() const
Returns a const reference of the heights.
Vec3s computeCOM() const
compute center of mass
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
HeightField(const HeightField &other)
Copy contructor from another HeightField.
virtual ~HeightField()
deconstruction, delete mesh data related.
Eigen::Vector2i leftChildIndexes() const
HFNodeBase()
Default constructor.
void init(const CoalScalar x_dim, const CoalScalar y_dim, const MatrixXs &heights, const CoalScalar min_height)
NODE_TYPE getNodeType() const
Get the BV type: default is unknown.
Eigen::Vector2i rightChildIndexes() const
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
CollisionRequestFlag operator&(CollisionRequestFlag a, CollisionRequestFlag b)
CoalScalar recursiveUpdateHeight(const size_t bv_id)
CoalScalar getYDim() const
Returns the dimension of the Height Field along the Y direction.
HeightField()
Constructing an empty HeightField.
The geometry for the object for collision or distance computation.
void updateHeights(const MatrixXs &new_heights)
Update Height Field height.
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
void computeLocalAABB()
Compute the AABB for the HeightField, used for broad-phase collision.
bool isLeaf() const
Whether current node is a leaf node (i.e. contains a primitive index)
bool operator==(const HFNode &other) const
Equality operator.
bool operator!=(const HFNodeBase &other) const
Difference operator.
virtual HeightField< BV > * clone() const
Clone *this into a new CollisionGeometry.
#define COAL_UNUSED_VARIABLE(var)
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)
Eigen::Matrix< CoalScalar, Eigen::Dynamic, 1 > VecXs
std::vector< Node, Eigen::aligned_allocator< Node > > BVS
CoalScalar getMinHeight() const
Returns the minimal height value of the Height Field.
virtual bool isEqual(const CollisionGeometry &_other) const
equal operator with another object of derived type.
#define COAL_THROW_PRETTY(message, exception)
const BVS & getNodes() const
coal::Matrix3s::IdentityReturnType getOrientation() const
Access to the orientation of the BV.
int buildTree()
Build the bounding volume hierarchy.
static void run(const Vec3s &pointA, const Vec3s &pointB, AABB &bv)
request to the collision algorithm
Vec3s getCenter() const
Access to the center of the BV.
CoalScalar getMaxHeight() const
Returns the maximal height value of the Height Field.
CoalScalar computeVolume() const
compute the volume
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...
CoalScalar getXDim() const
Returns the dimension of the Height Field along the X direction.
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
const HFNode< BV > & getBV(unsigned int i) const
Access the bv giving the its index.
BVS bvs
Bounding volume hierarchy.
OBJECT_TYPE getObjectType() const
Get the object type: it is a HFIELD.
Data structure depicting a height field given by the base grid dimensions and the elevation along the...
Vec3s center() const
Center of the AABB.
size_t rightChild() const
Return the index of the second child. The index is referred to the bounding volume array (i....
CoalScalar x_dim
Dimensions in meters along X and Y directions.
Eigen::Matrix< CoalScalar, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
bool operator!=(const HFNode &other) const
Difference operator.
BV bv
bounding volume storing the geometry
const VecXs & getYGrid() const
Returns a const reference of the grid along the Y direction.
Eigen::Matrix< CoalScalar, 3, 3 > Matrix3s
bool overlap(const HFNode &other, const CollisionRequest &request, CoalScalar &sqrDistLowerBound) const
Check whether two BVNode collide.
MatrixXs heights
Elevation values in meters of the Height Field.
bool operator==(const HFNodeBase &other) const
Comparison operator.
HFNode< BV > & getBV(unsigned int i)
Access the bv giving the its index.
static void convertBV(const BV1 &bv1, const Transform3s &tf1, BV2 &bv2)
Convert a bounding volume of type BV1 in configuration tf1 to bounding volume of type BV2 in identity...
VecXs x_grid
Grids along the X and Y directions. Useful for plotting or other related things.
static void run(const Vec3s &pointA, const Vec3s &pointB, BV &bv)
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...
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef CollisionGeometry Base
size_t leftChild() const
Return the index of the first child. The index is referred to the bounding volume array (i....
bool overlap(const HFNode &other) const
Check whether two BVNode collide.
CoalScalar min_height
Minimal height of the Height Field: all values bellow min_height will be discarded.
hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58