39 #ifndef HPP_FCL_BVH_MODEL_H 40 #define HPP_FCL_BVH_MODEL_H 56 template <
typename BV>
58 template <
typename BV>
88 if (num_tris && num_vertices)
90 else if (num_vertices)
105 delete[] tri_indices;
106 delete[] prev_vertices;
113 void computeLocalAABB();
116 int beginModel(
unsigned int num_tris = 0,
unsigned int num_vertices = 0);
119 int addVertex(
const Vec3f& p);
122 int addVertices(
const Matrixx3f& points);
125 int addTriangles(
const Matrixx3i& triangles);
131 int addSubModel(
const std::vector<Vec3f>& ps,
132 const std::vector<Triangle>& ts);
135 int addSubModel(
const std::vector<Vec3f>& ps);
143 int beginReplaceModel();
146 int replaceVertex(
const Vec3f& p);
149 int replaceTriangle(
const Vec3f& p1,
const Vec3f& p2,
const Vec3f& p3);
152 int replaceSubModel(
const std::vector<Vec3f>& ps);
156 int endReplaceModel(
bool refit =
true,
bool bottomup =
true);
161 int beginUpdateModel();
164 int updateVertex(
const Vec3f& p);
170 int updateSubModel(
const std::vector<Vec3f>& ps);
174 int endUpdateModel(
bool refit =
true,
bool bottomup =
true);
180 void buildConvexRepresentation(
bool share_memory);
193 bool buildConvexHull(
bool keepTriangle,
const char* qhullCommand = NULL);
195 virtual int memUsage(
const bool msg =
false)
const = 0;
201 virtual void makeParentRelative() = 0;
206 for (
unsigned int i = 0; i < num_tris; ++i) {
207 const Triangle& tri = tri_indices[i];
209 (vertices[tri[0]].cross(vertices[tri[1]])).dot(vertices[tri[2]]);
212 (vertices[tri[0]] + vertices[tri[1]] + vertices[tri[2]]) * d_six_vol;
215 return com / (vol * 4);
220 for (
unsigned int i = 0; i < num_tris; ++i) {
221 const Triangle& tri = tri_indices[i];
223 (vertices[tri[0]].cross(vertices[tri[1]])).dot(vertices[tri[2]]);
234 C_canonical << 1 / 60.0, 1 / 120.0, 1 / 120.0, 1 / 120.0, 1 / 60.0,
235 1 / 120.0, 1 / 120.0, 1 / 120.0, 1 / 60.0;
237 for (
unsigned int i = 0; i < num_tris; ++i) {
238 const Triangle& tri = tri_indices[i];
239 const Vec3f& v1 = vertices[tri[0]];
240 const Vec3f& v2 = vertices[tri[1]];
241 const Vec3f& v3 = vertices[tri[2]];
243 A << v1.transpose(), v2.transpose(), v3.transpose();
244 C += A.derived().transpose() * C_canonical * A * (v1.cross(v2)).dot(v3);
247 return C.trace() * Matrix3f::Identity() - C;
251 virtual void deleteBVs() = 0;
252 virtual bool allocateBVs() = 0;
255 virtual int buildTree() = 0;
258 virtual int refitTree(
bool bottomup) = 0;
272 template <
typename BV>
298 delete[] primitive_indices;
323 int memUsage(
const bool msg)
const;
331 makeParentRelativeRecurse(0, I,
Vec3f());
351 int refitTree(
bool bottomup);
355 int refitTree_topdown();
359 int refitTree_bottomup();
362 int recursiveBuildTree(
int bv_id,
unsigned int first_primitive,
363 unsigned int num_primitives);
366 int recursiveRefitTree_bottomup(
int bv_id);
372 const Vec3f& parent_c) {
373 if (!bvs[bv_id].isLeaf()) {
374 makeParentRelativeRecurse(bvs[bv_id].first_child, parent_axes,
375 bvs[bv_id].getCenter());
377 makeParentRelativeRecurse(bvs[bv_id].first_child + 1, parent_axes,
378 bvs[bv_id].getCenter());
381 bvs[bv_id].
bv =
translate(bvs[bv_id].bv, -parent_c);
387 if (other_ptr ==
nullptr)
return false;
391 if (!res)
return false;
436 if (num_bvs != other.
num_bvs)
return false;
438 for (
unsigned int k = 0; k < num_bvs; ++k) {
439 if (bvs[k] != other.
bvs[k])
return false;
450 const Vec3f& parent_c);
454 const Vec3f& parent_c);
459 const Vec3f& parent_c);
Vec3f * prev_vertices
Geometry point data in previous frame.
shared_ptr< ConvexBase > convex
Convex<Triangle> representation of this object.
unsigned int getNumBVs() const
Get the number of bv in the BVH.
unsigned int num_vertex_updated
FCL_REAL computeVolume() const
compute the volume
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
BV bv
bounding volume storing the geometry
BVNode< BV > & getBV(unsigned int i)
Access the bv giving the its index.
shared_ptr< BVFitter< BV > > bv_fitter
Fitting rule to fit a BV node to a set of geometry primitives.
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
virtual BVHModel< BV > * clone() const
Clone *this into a new BVHModel.
A base class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewe...
unsigned int num_vertices
Number of points.
unsigned int num_vertices_allocated
Vec3f computeCOM() const
compute center of mass
OBJECT_TYPE getObjectType() const
Get the object type: it is a BVH.
void makeParentRelativeRecurse(int bv_id, Matrix3f &parent_axes, const Vec3f &parent_c)
unsigned int * primitive_indices
Triangle * tri_indices
Geometry triangle index data, will be NULL for point clouds.
BVHBuildState
States for BVH construction empty->begun->processed ->replace_begun->processed -> ...
Vec3f * vertices
Geometry point data.
unsigned int num_tris
Number of triangles.
Eigen::Matrix< Eigen::DenseIndex, Eigen::Dynamic, 3 > Matrixx3i
virtual bool isEqual(const CollisionGeometry &_other) const
for ccd vertex update
BVHModelType getModelType() const
Model type described by the instance.
unsigned int num_tris_allocated
Eigen::Matrix< FCL_REAL, Eigen::Dynamic, 3 > Matrixx3f
BVHModelType
BVH model type.
unsigned int num_bvs
Number of BV nodes in bounding volume hierarchy.
A class describing a bounding volume node. It includes the tree structure providing in BVNodeBase and...
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
void makeParentRelative()
This is a special acceleration: BVH_model default stores the BV's transform in world coordinate...
static AABB translate(const AABB &aabb, const Vec3f &t)
translate the center of AABB by t
~BVHModel()
deconstruction, delete mesh data related.
Triangle with 3 indices for points.
const BVNode< BV > & getBV(unsigned int i) const
We provide getBV() and getNumBVs() because BVH may be compressed (in future), so we must provide some...
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18, kDOP24), basic shape (box, sphere, ellipsoid, capsule, cone, cylinder, convex, plane, triangle), and octree
NODE_TYPE getNodeType() const
Get the BV type: default is unknown.
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
BVHBuildState build_state
The state of BVH building process.
BVNode< BV > * bvs
Bounding volume hierarchy.
unsigned int num_bvs_allocated
shared_ptr< BVSplitter< BV > > bv_splitter
Split rule to split one BV node into two children.
The class for the default algorithm fitting a bounding volume to a set of points. ...
A class describing the split rule that splits each BV node.
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
The geometry for the object for collision or distance computation.
virtual ~BVHModelBase()
deconstruction, delete mesh data related.
bool isEqual(const Eigen::MatrixBase< Derived > &lhs, const Eigen::MatrixBase< OtherDerived > &rhs, const FCL_REAL tol=std::numeric_limits< FCL_REAL >::epsilon() *100)