1 #ifndef TESSERACT_COLLISION_COLLISION_SPHERE_SPHERE_CAST_UNIT_HPP
2 #define TESSERACT_COLLISION_COLLISION_SPHERE_SPHERE_CAST_UNIT_HPP
24 auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
25 auto mesh_faces = std::make_shared<Eigen::VectorXi>();
33 auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
38 sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
41 Eigen::Isometry3d sphere_pose;
42 sphere_pose.setIdentity();
43 sphere_pose.translation()[2] = 0.25;
47 obj1_shapes.push_back(sphere);
48 obj1_poses.push_back(sphere_pose);
58 CollisionShapePtr thin_box = std::make_shared<tesseract_geometry::Box>(0.1, 1, 1);
59 Eigen::Isometry3d thin_box_pose;
60 thin_box_pose.setIdentity();
64 obj2_shapes.push_back(thin_box);
65 obj2_poses.push_back(thin_box_pose);
80 auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
81 auto mesh_faces = std::make_shared<Eigen::VectorXi>();
89 auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
94 sphere1 = std::make_shared<tesseract_geometry::Sphere>(0.25);
97 Eigen::Isometry3d sphere1_pose;
98 sphere1_pose.setIdentity();
99 sphere1_pose.translation()[2] = 0.25;
103 obj3_shapes.push_back(sphere1);
104 obj3_poses.push_back(sphere1_pose);
112 CollisionShapePtr remove_box = std::make_shared<tesseract_geometry::Box>(0.1, 1, 1);
113 Eigen::Isometry3d remove_box_pose;
114 remove_box_pose.setIdentity();
118 obj4_shapes.push_back(remove_box);
119 obj4_poses.push_back(remove_box_pose);
149 std::vector<std::string> active_links{
"sphere_link",
"sphere1_link" };
152 EXPECT_TRUE(tesseract_common::isIdentical<std::string>(active_links, check_active_links,
false));
161 location_start[
"sphere_link"] = Eigen::Isometry3d::Identity();
162 location_start[
"sphere_link"].translation()(0) = -0.2;
163 location_start[
"sphere_link"].translation()(1) = -1.0;
165 location_start[
"sphere1_link"] = Eigen::Isometry3d::Identity();
166 location_start[
"sphere1_link"].translation()(0) = 0.2;
167 location_start[
"sphere1_link"].translation()(2) = -1.0;
171 location_end[
"sphere_link"] = Eigen::Isometry3d::Identity();
172 location_end[
"sphere_link"].translation()(0) = -0.2;
173 location_end[
"sphere_link"].translation()(1) = 1.0;
175 location_end[
"sphere1_link"] = Eigen::Isometry3d::Identity();
176 location_end[
"sphere1_link"].translation()(0) = 0.2;
177 location_end[
"sphere1_link"].translation()(2) = 1.0;
191 std::vector<int> idx = { 0, 1, 1 };
192 if (result_vector[0].link_names[0] !=
"sphere_link")
195 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[0])], 0.5, 0.001);
196 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[1])], 0.5, 0.001);
198 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
200 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
203 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.05, 0.001);
204 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
205 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
207 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.05, 0.001);
208 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
209 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
211 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][0], 0.25, 0.001);
212 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
213 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
214 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][0], -0.25, 0.001);
215 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
216 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
218 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[0])].isApprox(location_start[
"sphere_link"], 0.0001));
219 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[1])].isApprox(location_start[
"sphere1_link"], 0.0001));
220 EXPECT_TRUE(result_vector[0].cc_transform[
static_cast<size_t>(idx[0])].isApprox(location_end[
"sphere_link"], 0.0001));
222 result_vector[0].cc_transform[
static_cast<size_t>(idx[1])].isApprox(location_end[
"sphere1_link"], 0.0001));
224 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
225 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
226 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
233 location_start[
"sphere_link"] = Eigen::Isometry3d::Identity();
234 location_start[
"sphere_link"].translation()(0) = -0.2;
235 location_start[
"sphere_link"].translation()(1) = -0.5;
237 location_start[
"sphere1_link"] = Eigen::Isometry3d::Identity();
238 location_start[
"sphere1_link"].translation()(0) = 0.2;
239 location_start[
"sphere1_link"].translation()(2) = -1.0;
242 location_end[
"sphere_link"] = Eigen::Isometry3d::Identity();
243 location_end[
"sphere_link"].translation()(0) = -0.2;
244 location_end[
"sphere_link"].translation()(1) = 1.0;
246 location_end[
"sphere1_link"] = Eigen::Isometry3d::Identity();
247 location_end[
"sphere1_link"].translation()(0) = 0.2;
248 location_end[
"sphere1_link"].translation()(2) = 1.0;
254 result_vector.clear();
263 if (result_vector[0].link_names[0] !=
"sphere_link")
266 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[0])], 0.3333, 0.001);
267 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[1])], 0.5, 0.001);
269 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
271 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[1]))] ==
274 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.05, 0.001);
275 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
276 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
278 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.05, 0.001);
279 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
280 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
282 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][0], 0.25, 0.001);
283 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
284 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
285 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][0], -0.25, 0.001);
286 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
287 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
289 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[0])].isApprox(location_start[
"sphere_link"], 0.0001));
290 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[1])].isApprox(location_start[
"sphere1_link"], 0.0001));
291 EXPECT_TRUE(result_vector[0].cc_transform[
static_cast<size_t>(idx[0])].isApprox(location_end[
"sphere_link"], 0.0001));
293 result_vector[0].cc_transform[
static_cast<size_t>(idx[1])].isApprox(location_end[
"sphere1_link"], 0.0001));
295 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
296 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
297 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
305 std::vector<std::string> active_links{
"sphere_link",
"sphere1_link" };
308 EXPECT_TRUE(tesseract_common::isIdentical<std::string>(active_links, check_active_links,
false));
317 location_start[
"sphere_link"] = Eigen::Isometry3d::Identity();
318 location_start[
"sphere_link"].translation()(0) = -0.2;
319 location_start[
"sphere_link"].translation()(1) = -1.0;
321 location_start[
"sphere1_link"] = Eigen::Isometry3d::Identity();
322 location_start[
"sphere1_link"].translation()(0) = 0.2;
323 location_start[
"sphere1_link"].translation()(2) = -1.0;
327 location_end[
"sphere_link"] = Eigen::Isometry3d::Identity();
328 location_end[
"sphere_link"].translation()(0) = -0.2;
329 location_end[
"sphere_link"].translation()(1) = 1.0;
331 location_end[
"sphere1_link"] = Eigen::Isometry3d::Identity();
332 location_end[
"sphere1_link"].translation()(0) = 0.2;
333 location_end[
"sphere1_link"].translation()(2) = 1.0;
347 std::vector<int> idx = { 0, 1, 1 };
348 if (result_vector[0].link_names[0] !=
"sphere_link")
351 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[0])], 0.5, 0.001);
352 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[1])], 0.5, 0.001);
354 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
356 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
359 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.0377, 0.001);
360 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
361 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
363 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.0377, 0.001);
364 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
365 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
367 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][0], 0.2377, 0.001);
368 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
369 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
370 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][0], -0.2377, 0.001);
371 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
372 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
374 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[0])].isApprox(location_start[
"sphere_link"], 0.0001));
375 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[1])].isApprox(location_start[
"sphere1_link"], 0.0001));
376 EXPECT_TRUE(result_vector[0].cc_transform[
static_cast<size_t>(idx[0])].isApprox(location_end[
"sphere_link"], 0.0001));
378 result_vector[0].cc_transform[
static_cast<size_t>(idx[1])].isApprox(location_end[
"sphere1_link"], 0.0001));
380 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
381 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
382 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
389 location_start[
"sphere_link"] = Eigen::Isometry3d::Identity();
390 location_start[
"sphere_link"].translation()(0) = -0.2;
391 location_start[
"sphere_link"].translation()(1) = -0.5;
393 location_start[
"sphere1_link"] = Eigen::Isometry3d::Identity();
394 location_start[
"sphere1_link"].translation()(0) = 0.2;
395 location_start[
"sphere1_link"].translation()(2) = -1.0;
398 location_end[
"sphere_link"] = Eigen::Isometry3d::Identity();
399 location_end[
"sphere_link"].translation()(0) = -0.2;
400 location_end[
"sphere_link"].translation()(1) = 1.0;
402 location_end[
"sphere1_link"] = Eigen::Isometry3d::Identity();
403 location_end[
"sphere1_link"].translation()(0) = 0.2;
404 location_end[
"sphere1_link"].translation()(2) = 1.0;
410 result_vector.clear();
419 if (result_vector[0].link_names[0] !=
"sphere_link")
422 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[0])], 0.3848, 0.001);
423 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[1])], 0.5, 0.001);
425 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
427 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[1]))] ==
430 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.0377, 0.001);
431 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0772, 0.001);
432 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
434 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.0377, 0.001);
435 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0772, 0.001);
436 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
438 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][0], 0.2377, 0.001);
439 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
440 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
441 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][0], -0.2377, 0.001);
442 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
443 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
445 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[0])].isApprox(location_start[
"sphere_link"], 0.0001));
446 EXPECT_TRUE(result_vector[0].
transform[
static_cast<size_t>(idx[1])].isApprox(location_start[
"sphere1_link"], 0.0001));
447 EXPECT_TRUE(result_vector[0].cc_transform[
static_cast<size_t>(idx[0])].isApprox(location_end[
"sphere_link"], 0.0001));
449 result_vector[0].cc_transform[
static_cast<size_t>(idx[1])].isApprox(location_end[
"sphere1_link"], 0.0001));
451 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
452 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
453 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
472 #endif // TESSERACT_COLLISION_COLLISION_SPHERE_SPHERE_CAST_UNIT_HPP