17 #include <boost/filesystem.hpp> 21 #include "../src/collision_node.h" 25 #include "fcl_resources/config.h" 27 #define RUN_CASE(BV, tf, models, split) \ 28 run<BV>(tf, models, split, #BV " - " #split ":\t") 35 template <
typename BV>
36 void makeModel(
const std::vector<Vec3f>& vertices,
37 const std::vector<Triangle>& triangles,
40 template <
typename BV,
typename TraversalNode>
44 template <
typename BV,
typename TraversalNode>
48 template <
typename BV>
49 double run(
const std::vector<Transform3f>& tf,
53 template <
typename BV>
80 template <
typename BV>
82 const std::vector<Triangle>& triangles,
92 template <
typename BV,
typename TraversalNode>
101 node.enable_statistics =
verbose;
106 for (std::size_t i = 0; i < tf.size(); ++i) {
107 if (!
initialize(node, m1, tf[i], m2, pose2, request, local_result))
108 std::cout <<
"initialize error" << std::endl;
116 template <
typename BV,
typename TraversalNode>
123 TraversalNode node(request);
125 node.enable_statistics =
verbose;
130 for (std::size_t i = 0; i < tf.size(); ++i) {
131 bool success(
initialize(node, m1, tf[i], m2, pose2, local_result));
136 collide(&node, request, result);
143 template <
typename BV>
144 double run(
const std::vector<Transform3f>& tf,
146 const char* prefix) {
147 double col = collide<BV, typename traits<BV>::CollisionTraversalNode>(
148 tf, models[0][split_method], models[1][split_method],
verbose);
149 double dist = distance<BV, typename traits<BV>::DistanceTraversalNode>(
150 tf, models[0][split_method], models[1][split_method],
verbose);
152 std::cout << prefix <<
" (" << col <<
", " << dist <<
")\n";
157 double run<OBB>(
const std::vector<Transform3f>& tf,
159 const char* prefix) {
160 double col = collide<OBB, traits<OBB>::CollisionTraversalNode>(
161 tf, models[0][split_method], models[1][split_method],
verbose);
164 std::cout << prefix <<
" (\t" << col <<
", \tNaN)\n";
169 std::vector<Vec3f>
p1, p2;
170 std::vector<Triangle> t1, t2;
172 loadOBJFile((path /
"env.obj").
string().c_str(), p1, t1);
173 loadOBJFile((path /
"rob.obj").
string().c_str(), p2, t2);
180 makeModel(p2, t2, SPLIT_METHOD_MEAN, ms_rss[1][SPLIT_METHOD_MEAN]);
181 makeModel(p2, t2, SPLIT_METHOD_BV_CENTER, ms_rss[1][SPLIT_METHOD_BV_CENTER]);
182 makeModel(p2, t2, SPLIT_METHOD_MEDIAN, ms_rss[1][SPLIT_METHOD_MEDIAN]);
185 makeModel(p1, t1, SPLIT_METHOD_MEAN, ms_kios[0][SPLIT_METHOD_MEAN]);
186 makeModel(p1, t1, SPLIT_METHOD_BV_CENTER, ms_kios[0][SPLIT_METHOD_BV_CENTER]);
187 makeModel(p1, t1, SPLIT_METHOD_MEDIAN, ms_kios[0][SPLIT_METHOD_MEDIAN]);
188 makeModel(p2, t2, SPLIT_METHOD_MEAN, ms_kios[1][SPLIT_METHOD_MEAN]);
189 makeModel(p2, t2, SPLIT_METHOD_BV_CENTER, ms_kios[1][SPLIT_METHOD_BV_CENTER]);
190 makeModel(p2, t2, SPLIT_METHOD_MEDIAN, ms_kios[1][SPLIT_METHOD_MEDIAN]);
193 makeModel(p1, t1, SPLIT_METHOD_MEAN, ms_obb[0][SPLIT_METHOD_MEAN]);
194 makeModel(p1, t1, SPLIT_METHOD_BV_CENTER, ms_obb[0][SPLIT_METHOD_BV_CENTER]);
195 makeModel(p1, t1, SPLIT_METHOD_MEDIAN, ms_obb[0][SPLIT_METHOD_MEDIAN]);
196 makeModel(p2, t2, SPLIT_METHOD_MEAN, ms_obb[1][SPLIT_METHOD_MEAN]);
197 makeModel(p2, t2, SPLIT_METHOD_BV_CENTER, ms_obb[1][SPLIT_METHOD_BV_CENTER]);
198 makeModel(p2, t2, SPLIT_METHOD_MEDIAN, ms_obb[1][SPLIT_METHOD_MEDIAN]);
201 makeModel(p1, t1, SPLIT_METHOD_MEAN, ms_obbrss[0][SPLIT_METHOD_MEAN]);
202 makeModel(p1, t1, SPLIT_METHOD_BV_CENTER,
203 ms_obbrss[0][SPLIT_METHOD_BV_CENTER]);
204 makeModel(p1, t1, SPLIT_METHOD_MEDIAN, ms_obbrss[0][SPLIT_METHOD_MEDIAN]);
205 makeModel(p2, t2, SPLIT_METHOD_MEAN, ms_obbrss[1][SPLIT_METHOD_MEAN]);
206 makeModel(p2, t2, SPLIT_METHOD_BV_CENTER,
207 ms_obbrss[1][SPLIT_METHOD_BV_CENTER]);
208 makeModel(p2, t2, SPLIT_METHOD_MEDIAN, ms_obbrss[1][SPLIT_METHOD_MEDIAN]);
210 std::vector<Transform3f> transforms;
212 std::size_t n = 10000;
215 double total_time = 0;
217 total_time +=
RUN_CASE(
RSS, transforms, ms_rss, SPLIT_METHOD_MEAN);
218 total_time +=
RUN_CASE(
RSS, transforms, ms_rss, SPLIT_METHOD_BV_CENTER);
219 total_time +=
RUN_CASE(
RSS, transforms, ms_rss, SPLIT_METHOD_MEDIAN);
221 total_time +=
RUN_CASE(
kIOS, transforms, ms_kios, SPLIT_METHOD_MEAN);
222 total_time +=
RUN_CASE(
kIOS, transforms, ms_kios, SPLIT_METHOD_BV_CENTER);
223 total_time +=
RUN_CASE(
kIOS, transforms, ms_kios, SPLIT_METHOD_MEDIAN);
225 total_time +=
RUN_CASE(
OBB, transforms, ms_obb, SPLIT_METHOD_MEAN);
226 total_time +=
RUN_CASE(
OBB, transforms, ms_obb, SPLIT_METHOD_BV_CENTER);
227 total_time +=
RUN_CASE(
OBB, transforms, ms_obb, SPLIT_METHOD_MEDIAN);
229 total_time +=
RUN_CASE(
OBBRSS, transforms, ms_obbrss, SPLIT_METHOD_MEAN);
230 total_time +=
RUN_CASE(
OBBRSS, transforms, ms_obbrss, SPLIT_METHOD_BV_CENTER);
231 total_time +=
RUN_CASE(
OBBRSS, transforms, ms_obbrss, SPLIT_METHOD_MEDIAN);
233 std::cout <<
"\n\nTotal time: " << total_time << std::endl;
request to the distance computation
void loadOBJFile(const char *filename, std::vector< Vec3f > &points, std::vector< Triangle > &triangles)
Load an obj mesh file.
bool initialize(MeshCollisionTraversalNode< BV, RelativeTransformationIsIdentity > &node, BVHModel< BV > &model1, Transform3f &tf1, BVHModel< BV > &model2, Transform3f &tf2, CollisionResult &result, bool use_refit=false, bool refit_bottomup=false)
Initialize traversal node for collision between two meshes, given the current transforms.
int addSubModel(const std::vector< Vec3f > &ps, const std::vector< Triangle > &ts)
Add a set of triangles in the new BVH model.
void stop()
stop the timer
void generateRandomTransforms(FCL_REAL extents[6], std::vector< Transform3f > &transforms, std::size_t n)
Generate n random transforms whose translations are constrained by extents.
MeshDistanceTraversalNodekIOS DistanceTraversalNode
A class describing the kIOS collision structure, which is a set of spheres.
request to the collision algorithm
HPP_FCL_DLLAPI FCL_REAL distance(const Matrix3f &R0, const Vec3f &T0, const kIOS &b1, const kIOS &b2, Vec3f *P=NULL, Vec3f *Q=NULL)
Approximate distance between two kIOS bounding volumes.
int beginModel(unsigned int num_tris=0, unsigned int num_vertices=0)
Begin a new BVH model.
double run(const std::vector< Transform3f > &tf, const BVHModel< BV >(&models)[2][3], int split_method, const char *sm_name)
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
MeshCollisionTraversalNodeOBB CollisionTraversalNode
SplitMethodType
Three types of split algorithms are provided in FCL as default.
HPP_FCL_DLLAPI std::size_t collide(const CollisionObject *o1, const CollisionObject *o2, const CollisionRequest &request, CollisionResult &result)
Main collision interface: given two collision objects, and the requirements for contacts, including num of max contacts, whether perform exhaustive collision (i.e., returning returning all the contact points), whether return detailed contact information (i.e., normal, contact point, depth; otherwise only contact primitive id is returned), this function performs the collision between them. Return value is the number of contacts generated between the two objects.
double getElapsedTimeInMicroSec()
get elapsed time in micro-second
shared_ptr< BVSplitter< BV > > bv_splitter
Split rule to split one BV node into two children.
#define RUN_CASE(BV, tf, models, split)
A class describing the split rule that splits each BV node.
MeshCollisionTraversalNodekIOS CollisionTraversalNode
int endModel()
End BVH model construction, will build the bounding volume hierarchy.
void makeModel(const std::vector< Vec3f > &vertices, const std::vector< Triangle > &triangles, SplitMethodType split_method, BVHModel< BV > &model)
double run< OBB >(const std::vector< Transform3f > &tf, const BVHModel< OBB >(&models)[2][3], int split_method, const char *prefix)
Oriented bounding box class.