|
hpp-fcl
1.6.0
HPP fork of FCL -- The Flexible Collision Library
|
Go to the documentation of this file.
38 #ifndef HPP_FCL_BVH_MODEL_H
39 #define HPP_FCL_BVH_MODEL_H
45 #include <boost/shared_ptr.hpp>
46 #include <boost/noncopyable.hpp>
58 template <
typename BV>
class BVFitter;
59 template <
typename BV>
class BVSplitter;
84 boost::shared_ptr< ConvexBase >
convex;
89 if(num_tris && num_vertices)
104 num_tris_allocated(0),
105 num_vertices_allocated(0),
106 num_vertex_updated(0)
117 delete [] tri_indices;
118 delete [] prev_vertices;
137 int addSubModel(
const std::vector<Vec3f>& ps,
const std::vector<Triangle>& ts);
205 for(
int i = 0; i < num_tris; ++i)
207 const Triangle& tri = tri_indices[i];
208 FCL_REAL d_six_vol = (vertices[tri[0]].cross(vertices[tri[1]])).dot(vertices[tri[2]]);
210 com += (vertices[tri[0]] + vertices[tri[1]] + vertices[tri[2]]) * d_six_vol;
213 return com / (vol * 4);
219 for(
int i = 0; i < num_tris; ++i)
221 const Triangle& tri = tri_indices[i];
222 FCL_REAL d_six_vol = (vertices[tri[0]].cross(vertices[tri[1]])).dot(vertices[tri[2]]);
234 C_canonical << 1/60.0, 1/120.0, 1/120.0,
235 1/120.0, 1/60.0, 1/120.0,
236 1/120.0, 1/120.0, 1/60.0;
238 for(
int i = 0; i < num_tris; ++i)
240 const Triangle& tri = tri_indices[i];
241 const Vec3f& v1 = vertices[tri[0]];
242 const Vec3f& v2 = vertices[tri[1]];
243 const Vec3f& v3 = vertices[tri[2]];
244 Matrix3f A; A << v1.transpose(), v2.transpose(), v3.transpose();
245 C += A.derived().transpose() * C_canonical * A * (v1.cross(v2)).dot(v3);
248 return C.trace() * Matrix3f::Identity() - C;
268 template<
typename BV>
289 delete [] primitive_indices;
297 assert (
id < num_bvs);
304 assert (
id < num_bvs);
325 makeParentRelativeRecurse(0, I,
Vec3f());
332 int num_bvs_allocated;
333 unsigned int* primitive_indices;
345 int refitTree(
bool bottomup);
348 int refitTree_topdown();
351 int refitTree_bottomup();
354 int recursiveBuildTree(
int bv_id,
int first_primitive,
int num_primitives);
357 int recursiveRefitTree_bottomup(
int bv_id);
361 void makeParentRelativeRecurse(
int bv_id,
Matrix3f& parent_axes,
const Vec3f& parent_c)
363 if(!bvs[bv_id].isLeaf())
365 makeParentRelativeRecurse(bvs[bv_id].first_child, parent_axes, bvs[bv_id].getCenter());
367 makeParentRelativeRecurse(bvs[bv_id].first_child + 1, parent_axes, bvs[bv_id].getCenter());
370 bvs[bv_id].
bv = translate(bvs[bv_id].bv, -parent_c);
377 void BVHModel<OBB>::makeParentRelativeRecurse(
int bv_id,
Matrix3f& parent_axes,
const Vec3f& parent_c);
380 void BVHModel<RSS>::makeParentRelativeRecurse(
int bv_id,
Matrix3f& parent_axes,
const Vec3f& parent_c);
383 void BVHModel<OBBRSS>::makeParentRelativeRecurse(
int bv_id,
Matrix3f& parent_axes,
const Vec3f& parent_c);
int endUpdateModel(bool refit=true, bool bottomup=true)
End BVH model update, will also refit or rebuild the bounding volume hierarchy.
virtual int refitTree(bool bottomup)=0
Refit the bounding volume hierarchy.
virtual int buildTree()=0
Build the bounding volume hierarchy.
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
virtual int memUsage(int msg) const =0
BVHModel()
Constructing an empty BVH.
BVHModelBase(const BVHModelBase &other)
copy from another BVH
int replaceTriangle(const Vec3f &p1, const Vec3f &p2, const Vec3f &p3)
Replace one triangle in the old BVH model.
boost::shared_ptr< BVFitter< BV > > bv_fitter
Fitting rule to fit a BV node to a set of geometry primitives.
Definition: BVH_model.h:277
int updateVertex(const Vec3f &p)
Update one point in the old BVH model.
int getNumBVs() const
Get the number of bv in the BVH.
Definition: BVH_model.h:309
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: BVH_model.h:229
BVHBuildState build_state
The state of BVH building process.
Definition: BVH_model.h:81
int memUsage(int msg) const
Check the number of memory used.
void computeLocalAABB()
Compute the AABB for the BVH, used for broad-phase collision.
@ BVH_MODEL_UNKNOWN
Definition: BVH_internal.h:79
OBJECT_TYPE getObjectType() const
Get the object type: it is a BVH.
Definition: BVH_model.h:122
int endReplaceModel(bool refit=true, bool bottomup=true)
End BVH model replacement, will also refit or rebuild the bounding volume hierarchy.
Vec3f * prev_vertices
Geometry point data in previous frame.
Definition: BVH_model.h:72
int num_vertices
Number of points.
Definition: BVH_model.h:78
int updateTriangle(const Vec3f &p1, const Vec3f &p2, const Vec3f &p3)
Update one triangle in the old BVH model.
virtual void deleteBVs()=0
int replaceVertex(const Vec3f &p)
Replace one point in the old BVH model.
int addSubModel(const std::vector< Vec3f > &ps, const std::vector< Triangle > &ts)
Add a set of triangles in the new BVH model.
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:270
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition: collision_object.h:56
int num_vertex_updated
Definition: BVH_model.h:263
virtual bool allocateBVs()=0
void buildConvexRepresentation(bool share_memory)
Build this Convex<Triangle> representation of this model. The result is stored in attribute convex.
BVHModel(const BVHModel &other)
copy from another BVH
int beginUpdateModel()
Replace the geometry information of current frame (i.e. should have the same mesh topology with the p...
double FCL_REAL
Definition: data_types.h:66
@ BVH_BUILD_STATE_EMPTY
Definition: BVH_internal.h:54
bool buildConvexHull(bool keepTriangle, const char *qhullCommand=NULL)
Build a convex hull and store it in attribute convex.
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition: collision_object.h:53
@ BVH_MODEL_TRIANGLES
unknown model type
Definition: BVH_internal.h:80
NODE_TYPE getNodeType() const
Get the BV type: default is unknown.
Definition: BVH_model.h:315
int addVertex(const Vec3f &p)
Add one point in the new BVH model.
virtual void makeParentRelative()=0
This is a special acceleration: BVH_model default stores the BV's transform in world coordinate....
int num_tris_allocated
Definition: BVH_model.h:261
FCL_REAL computeVolume() const
compute the volume
Definition: BVH_model.h:216
void makeParentRelative()
This is a special acceleration: BVH_model default stores the BV's transform in world coordinate....
Definition: BVH_model.h:322
BVHBuildState
States for BVH construction empty->begun->processed ->replace_begun->processed -> ....
Definition: BVH_internal.h:53
int replaceSubModel(const std::vector< Vec3f > &ps)
Replace a set of points in the old BVH model.
BVHModelType
BVH model type.
Definition: BVH_internal.h:78
int addTriangle(const Vec3f &p1, const Vec3f &p2, const Vec3f &p3)
Add one triangle in the new BVH model.
Main namespace.
Definition: AABB.h:44
~BVHModel()
deconstruction, delete mesh data related.
Definition: BVH_model.h:286
BV bv
bounding volume storing the geometry
Definition: BV_node.h:90
BVHModelType getModelType() const
Model type described by the instance.
Definition: BVH_model.h:87
@ BV_UNKNOWN
Definition: collision_object.h:56
boost::shared_ptr< ConvexBase > convex
Convex<Triangle> representation of this object.
Definition: BVH_model.h:84
BVHModelBase()
Constructing an empty BVH.
Definition: BVH_model.h:98
int updateSubModel(const std::vector< Vec3f > &ps)
Update a set of points in the old BVH model.
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Definition: data_types.h:68
const BVNode< BV > & getBV(int id) const
We provide getBV() and getNumBVs() because BVH may be compressed (in future), so we must provide some...
Definition: BVH_model.h:295
The geometry for the object for collision or distance computation.
Definition: collision_object.h:64
int endModel()
End BVH model construction, will build the bounding volume hierarchy.
A base class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewe...
Definition: BVH_model.h:63
Vec3f * vertices
Geometry point data.
Definition: BVH_model.h:66
int beginReplaceModel()
Replace the geometry information of current frame (i.e. should have the same mesh topology with the p...
Triangle * tri_indices
Geometry triangle index data, will be NULL for point clouds.
Definition: BVH_model.h:69
Triangle with 3 indices for points.
Definition: data_types.h:73
BVNode< BV > & getBV(int id)
Access the bv giving the its index.
Definition: BVH_model.h:302
@ OT_BVH
Definition: collision_object.h:53
Vec3f computeCOM() const
compute center of mass
Definition: BVH_model.h:201
int addSubModel(const std::vector< Vec3f > &ps)
Add a set of points in the new BVH model.
A class describing a bounding volume node. It includes the tree structure providing in BVNodeBase and...
Definition: BV_node.h:88
int num_vertices_allocated
Definition: BVH_model.h:262
@ BVH_MODEL_POINTCLOUD
triangle model
Definition: BVH_internal.h:81
int num_tris
Number of triangles.
Definition: BVH_model.h:75
virtual ~BVHModelBase()
deconstruction, delete mesh data related.
Definition: BVH_model.h:114
boost::shared_ptr< BVSplitter< BV > > bv_splitter
Split rule to split one BV node into two children.
Definition: BVH_model.h:274
int beginModel(int num_tris=0, int num_vertices=0)
Begin a new BVH model.