38 #include <gtest/gtest.h> 40 #include "fcl/config.h" 53 #include "fcl_resources/config.h" 59 void octomap_cost_test(S env_scale, std::size_t env_size, std::size_t num_max_cost_sources,
bool use_mesh,
bool use_mesh_octomap,
double resolution = 0.1);
65 octomap_cost_test<S>(200, 100, 10,
false,
false);
66 octomap_cost_test<S>(200, 1000, 10,
false,
false);
68 octomap_cost_test<S>(200, 10, 10,
false,
false, 0.1);
69 octomap_cost_test<S>(200, 100, 10,
false,
false, 0.1);
76 test_octomap_cost<double>();
83 octomap_cost_test<S>(200, 100, 10,
true,
false);
84 octomap_cost_test<S>(200, 1000, 10,
true,
false);
86 octomap_cost_test<S>(200, 2, 4,
true,
false, 1.0);
87 octomap_cost_test<S>(200, 5, 4,
true,
false, 1.0);
94 test_octomap_cost_mesh<double>();
98 void octomap_cost_test(S env_scale, std::size_t env_size, std::size_t num_max_cost_sources,
bool use_mesh,
bool use_mesh_octomap,
double resolution)
100 std::vector<CollisionObject<S>*> env;
106 OcTree<S>* tree =
new OcTree<S>(std::shared_ptr<const octomap::OcTree>(test::generateOcTree(resolution)));
114 cdata.
request.enable_cost =
true;
115 cdata.
request.num_max_cost_sources = num_max_cost_sources;
127 cdata3.
request.enable_cost =
true;
128 cdata3.
request.num_max_cost_sources = num_max_cost_sources;
142 std::vector<CollisionObject<S>*> boxes;
144 test::generateBoxesFromOctomapMesh(boxes, *tree);
146 test::generateBoxesFromOctomap(boxes, *tree);
158 cdata2.
request.enable_cost =
true;
159 cdata3.
request.num_max_cost_sources = num_max_cost_sources;
166 std::cout << cdata.
result.numContacts() <<
" " << cdata3.
result.numContacts() <<
" " << cdata2.
result.numContacts() << std::endl;
167 std::cout << cdata.
result.numCostSources() <<
" " << cdata3.
result.numCostSources() <<
" " << cdata2.
result.numCostSources() << std::endl;
170 std::vector<CostSource<S>> cost_sources;
171 cdata.
result.getCostSources(cost_sources);
172 for(std::size_t i = 0; i < cost_sources.size(); ++i)
174 std::cout << cost_sources[i].aabb_min.transpose() <<
" " << cost_sources[i].aabb_max.transpose() <<
" " << cost_sources[i].cost_density << std::endl;
177 std::cout << std::endl;
179 cdata3.
result.getCostSources(cost_sources);
180 for(std::size_t i = 0; i < cost_sources.size(); ++i)
182 std::cout << cost_sources[i].aabb_min.transpose() <<
" " << cost_sources[i].aabb_max.transpose() <<
" " << cost_sources[i].cost_density << std::endl;
185 std::cout << std::endl;
187 cdata2.
result.getCostSources(cost_sources);
188 for(std::size_t i = 0; i < cost_sources.size(); ++i)
190 std::cout << cost_sources[i].aabb_min.transpose() <<
" " << cost_sources[i].aabb_max.transpose() <<
" " << cost_sources[i].cost_density << std::endl;
193 std::cout << std::endl;
202 for(std::size_t i = 0; i < boxes.size(); ++i)
205 std::cout <<
"collision cost" << std::endl;
206 std::cout <<
"1) octomap overall time: " << t1.
overall_time << std::endl;
207 std::cout <<
"1') octomap overall time (as geometry): " << t3.
overall_time << std::endl;
208 std::cout <<
"2) boxes overall time: " << t2.
overall_time << std::endl;
209 std::cout <<
" a) to boxes: " << t2.
records[0] << std::endl;
210 std::cout <<
" b) structure init: " << t2.
records[1] << std::endl;
211 std::cout <<
" c) collision: " << t2.
records[2] << std::endl;
212 std::cout <<
"Note: octomap may need more collides when using mesh, because octomap collision uses box primitive inside" << std::endl;
216 int main(
int argc,
char* argv[])
218 ::testing::InitGoogleTest(&argc, argv);
219 return RUN_ALL_TESTS();
void generateEnvironmentsMesh(std::vector< CollisionObject< S > *> &env, S env_scale, std::size_t n)
Generate environment with 3 * n objects, but all in meshes.
bool octree_as_geometry_collide
double getElapsedTime()
get elapsed time in milli-second
CollisionRequest< S > request
std::vector< double > records
void stop()
stop the timer
GTEST_TEST(FCL_OCTOMAP, test_octomap_cost)
int main(int argc, char *argv[])
void octomap_cost_test(S env_scale, std::size_t env_size, std::size_t num_max_cost_sources, bool use_mesh, bool use_mesh_octomap, double resolution=0.1)
Octomap collision with an environment with 3 * env_size objects, compute cost.
bool octree_as_geometry_distance
The geometry for the object for collision or distance computation.
void collide(CollisionObject< S > *obj, void *cdata, CollisionCallBack< S > callback) const
perform collision test between one object and all the objects belonging to the manager ...
void setup()
initialize the manager, related with the specific type of manager
void generateEnvironments(std::vector< CollisionObject< S > *> &env, S env_scale, std::size_t n)
Generate environment with 3 * n objects: n boxes, n spheres and n cylinders.
CollisionResult< S > result
the object for collision or distance computation, contains the geometry and the transform information...
Collision data for use with the DefaultCollisionFunction. It stores the collision request and the res...
bool DefaultCollisionFunction(CollisionObject< S > *o1, CollisionObject< S > *o2, void *data)
Provides a simple callback for the collision query in the BroadPhaseCollisionManager. It assumes the data parameter is non-null and points to an instance of DefaultCollisionData. It simply invokes the collide() method on the culled pair of geometries and stores the results in the data's CollisionResult instance.
#define EXPECT_TRUE(args)
void registerObjects(const std::vector< CollisionObject< S > *> &other_objs)
add objects to the manager
void test_octomap_cost_mesh()