Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
collision_large_dataset_unit.hpp
Go to the documentation of this file.
1#ifndef TESSERACT_COLLISION_COLLISION_LARGE_DATASET_UNIT_HPP
2#define TESSERACT_COLLISION_COLLISION_LARGE_DATASET_UNIT_HPP
3
6#include <console_bridge/console.h>
7#include <chrono>
9
14
16{
17inline void runTest(DiscreteContactManager& checker, bool use_convex_mesh = false, int num_interations = 10)
18{
19 // Add Meshed Sphere to checker
21
22 if (use_convex_mesh)
23 {
24 auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
25 auto mesh_faces = std::make_shared<Eigen::VectorXi>();
27 std::string(TESSERACT_SUPPORT_DIR) + "/meshes/sphere_p25m.ply", *mesh_vertices, *mesh_faces, true),
28 0);
29
30 auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
32 }
33 else
34 {
35 sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
36 }
37
38 double delta = 0.55;
39
40 std::size_t t = 5; // Because of unit test runtime this was reduced from 10 to 5.
41 std::vector<std::string> link_names;
43 for (std::size_t x = 0; x < t; ++x)
44 {
45 for (std::size_t y = 0; y < t; ++y)
46 {
47 for (std::size_t z = 0; z < t; ++z)
48 {
49 CollisionShapesConst obj3_shapes;
51 Eigen::Isometry3d sphere_pose;
52 sphere_pose.setIdentity();
53
54 obj3_shapes.push_back(CollisionShapePtr(sphere->clone()));
55 obj3_poses.push_back(sphere_pose);
56
57 link_names.push_back("sphere_link_" + std::to_string(x) + std::to_string(y) + std::to_string(z));
58
59 location[link_names.back()] = sphere_pose;
60 location[link_names.back()].translation() = Eigen::Vector3d(
61 static_cast<double>(x) * delta, static_cast<double>(y) * delta, static_cast<double>(z) * delta);
62 checker.addCollisionObject(link_names.back(), 0, obj3_shapes, obj3_poses);
63 }
64 }
65 }
66
67 // Check if they are in collision
69 std::vector<std::string> check_active_links = checker.getActiveCollisionObjects();
71
72 EXPECT_TRUE(checker.getIsContactAllowedFn() == nullptr);
73
76 checker.setCollisionObjectsTransform(location);
77
78 ContactResultMap result;
80
81 auto start_time = std::chrono::high_resolution_clock::now();
82 num_interations = 1;
83 for (auto i = 0; i < num_interations; ++i)
84 {
85 result.clear();
86 result_vector.clear();
89
90 if (result_vector.size() != 300)
91 for (const auto& result : result_vector)
92 std::cout << result.link_names[0] << "," << result.link_names[1] << "," << result.distance << std::endl;
93
94 EXPECT_EQ(result_vector.size(), 300);
95 }
96 auto end_time = std::chrono::high_resolution_clock::now();
97
98 CONSOLE_BRIDGE_logInform("DT: %f ms", std::chrono::duration<double, std::milli>(end_time - start_time).count());
99}
100} // namespace tesseract_collision::test_suite
101#endif // TESSERACT_COLLISION_COLLISION_LARGE_DATASET_UNIT_HPP
This structure hold contact results for link pairs.
Definition: types.h:154
void clear()
This is a consurvative clear.
Definition: types.cpp:183
void flattenMoveResults(ContactResultVector &v)
Definition: types.cpp:215
Definition: discrete_contact_manager.h:41
virtual void setActiveCollisionObjects(const std::vector< std::string > &names)=0
Set which collision objects can move.
virtual void contactTest(ContactResultMap &collisions, const ContactRequest &request)=0
Perform a contact test for all objects based.
virtual void setCollisionObjectsTransform(const std::string &name, const Eigen::Isometry3d &pose)=0
Set a single collision object's transforms.
virtual bool addCollisionObject(const std::string &name, const int &mask_id, const CollisionShapesConst &shapes, const tesseract_common::VectorIsometry3d &shape_poses, bool enabled=true)=0
Add a object to the checker.
virtual const std::vector< std::string > & getActiveCollisionObjects() const =0
Get which collision objects can move.
virtual const CollisionMarginData & getCollisionMarginData() const =0
Get the contact distance threshold.
virtual void setCollisionMarginData(CollisionMarginData collision_margin_data, CollisionMarginOverrideType override_type=CollisionMarginOverrideType::REPLACE)=0
Set the contact distance thresholds for which collision should be considered on a per pair basis.
virtual IsContactAllowedFn getIsContactAllowedFn() const =0
Get the active function for determining if two links are allowed to be in collision.
double getMaxCollisionMargin() const
Get the largest collision margin.
Definition: collision_margin_data.h:165
EXPECT_NEAR(config.contact_manager_config.margin_data.getDefaultCollisionMargin(), 5, 1e-6)
tesseract_collision::ContactResultVector result_vector
Definition: collision_core_unit.cpp:410
results link_names[0]
Definition: collision_core_unit.cpp:146
EXPECT_EQ(results.distance, std::numeric_limits< double >::max())
EXPECT_TRUE(tesseract_common::isIdentical< tesseract_collision::ObjectPairKey >(pairs, check_pairs, false))
This is a collection of common methods.
This is a collection of common methods.
This is the discrete contact manager base class.
Tesseract Geometries.
EXPECT_GT(m.m.condition, 1e+20)
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: large_dataset_benchmarks.hpp:17
void runTest(ContinuousContactManager &checker)
Definition: collision_box_box_cast_unit.hpp:111
tesseract_common::CollisionMarginData CollisionMarginData
Definition: types.h:50
tesseract_geometry::Geometry::Ptr CollisionShapePtr
Definition: types.h:49
std::vector< tesseract_geometry::Geometry::ConstPtr > CollisionShapesConst
Definition: types.h:47
tesseract_common::AlignedVector< ContactResult > ContactResultVector
Definition: types.h:134
int loadSimplePlyFile(const std::string &path, tesseract_common::VectorVector3d &vertices, Eigen::VectorXi &faces, bool triangles_only=false)
Loads a simple ply file given a path.
Definition: common.cpp:285
tesseract_geometry::ConvexMesh::Ptr makeConvexMesh(const tesseract_geometry::Mesh &mesh)
Definition: convex_hull_utils.cpp:114
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
Definition: types.h:66
template bool isIdentical< std::string >(const std::vector< std::string > &, const std::vector< std::string > &, bool, const std::function< bool(const std::string &, const std::string &)> &, const std::function< bool(const std::string &, const std::string &)> &)
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
Definition: types.h:62
The ContactRequest struct.
Definition: types.h:294
auto sphere
Definition: tesseract_geometry_unit.cpp:23
auto mesh
Definition: tesseract_geometry_unit.cpp:25