Collision Checker
fcl_collision_object.cc
Go to the documentation of this file.
2 #include <math.h>
7 
8 namespace collision {
9 namespace solvers {
10 namespace solverFCL {
13  FCL_PRECISION tolerance) const {
14  SolverEntity_FCL *obj2_entity;
15  FCL_COLLISION_ENTITY_TYPE obj2_entity_type =
16  get_object_fcl_entity_type(&obj2, obj2_entity);
17 
18  if (obj2_entity_type == COLLISION_ENTITY_TYPE_FCL_OBJECT) {
20  *this, *(static_cast<const FCLCollisionObject *>(obj2_entity)),
21  distance, tolerance);
22  return result;
23  } else if (obj2_entity_type == COLLISION_ENTITY_TYPE_FCL_OBJECTGROUP) {
25  *(static_cast<const FCLCollisionObjectGroup *>(obj2_entity)), *this,
26  distance, tolerance);
27  return result;
28  } else
29  return -1;
30 }
31 
33  const CollisionObject &obj2, double &distance,
34  FCL_TOLERANCE_CHECK_TYPE check_type, FCL_PRECISION tolerance) const {
35  SolverEntity_FCL *obj2_entity;
36  FCL_COLLISION_ENTITY_TYPE obj2_entity_type =
37  get_object_fcl_entity_type(&obj2, obj2_entity);
38  if (obj2_entity_type == COLLISION_ENTITY_TYPE_FCL_OBJECT) {
40  *this, *(static_cast<const FCLCollisionObject *>(obj2_entity)),
41  distance, check_type, tolerance);
42 
43  } else if (obj2_entity_type == COLLISION_ENTITY_TYPE_FCL_OBJECTGROUP) {
45  *(static_cast<const FCLCollisionObjectGroup *>(obj2_entity)), *this,
46  distance, check_type, tolerance);
47  } else
48  return -1;
49 }
50 
51 /*
52 int FCLCollisionObject::ToleranceCheck(CollisionObjectConstPtr obj2, bool&
53 result, double& distance, FCL_TOLERANCE_CHECK_TYPE check_type, FCL_PRECISION
54 tolerance) const
55 {
56 SolverEntity_FCL* obj2_entity;
57 FCL_COLLISION_ENTITY_TYPE obj2_entity_type = get_object_fcl_entity_type(obj2,
58 obj2_entity); if (obj2_entity_type == COLLISION_ENTITY_TYPE_FCL_OBJECT)
59 {
60 int tolerance_result = fcl_primitive_queries::FCL_DistanceTolerance(*this,
61 *(static_cast<const FCLCollisionObject*>(obj2_entity)), distance, check_type,
62 tolerance); if (tolerance_result >= 0)
63 {
64 if (distance > -1 * (abs(tolerance)))
65 result = true;
66 else
67 result = false;
68 }
69 return tolerance_result;
70 }
71 else if (obj2_entity_type == COLLISION_ENTITY_TYPE_FCL_OBJECTGROUP)
72 {
73 int tolerance_result =
74 fcl_primitive_queries::FCL_DistanceTolerance(*(static_cast<const
75 FCLCollisionObjectGroup*>(obj2_entity)), *this, distance, check_type,
76 tolerance); if (distance > -1 * (abs(tolerance))) result = true; else result =
77 false; return tolerance_result;
78 }
79 else
80 return -1;
81 }
82 */
85  this->getCollisionObject_fcl().get();
86  fcl::AABB<double> BV_this = fcl_this_obj->getAABB();
87 
88  Eigen::Vector2d min_(BV_this.min_[0], BV_this.min_[1]);
89 
90  Eigen::Vector2d max_(BV_this.max_[0], BV_this.max_[1]);
91 
92  Eigen::Vector2d center = (min_ + max_) / 2;
93 
94  double rx = center[0] - min_[0];
95  double ry = center[1] - min_[1];
96 
98  std::shared_ptr<const RectangleAABB>(
99  new collision::RectangleAABB(rx, ry, center));
100  return raabbcptr;
101 }
102 
104  SolverEntity_FCL *obj2_entity;
105  FCL_COLLISION_ENTITY_TYPE obj2_entity_type =
106  get_object_fcl_entity_type(obj2, obj2_entity);
107 
108  if (obj2_entity_type ==
111  this->getCollisionObject_fcl().get();
113  (static_cast<const FCLCollisionObject *>(obj2_entity))
114  ->getCollisionObject_fcl()
115  .get();
116  fcl::AABB<double> BV_this = fcl_this_obj->getAABB();
117  fcl::AABB<double> BV_2 = fcl_obj2->getAABB();
118  return BV_this.overlap(BV_2);
119  }
120  return true;
121 }
122 
123 std::shared_ptr<fcl::CollisionObject<FCL_PRECISION>>
125  if (!object_cached)
126 
127  {
128  fcl_geometry = std::shared_ptr<fcl::CollisionGeometry<FCL_PRECISION>>(
129  m_parent_fcl_interface->createFCLCollisionGeometry());
130 
131  fcl_col_obj = std::shared_ptr<fcl::CollisionObject<FCL_PRECISION>>(
132  m_parent_fcl_interface->createFCLCollisionObject(fcl_geometry));
133 
134  // TODO: alloc errors check
135 
136  fcl::CollisionObject<FCL_PRECISION> *fcl_obj = fcl_col_obj.get();
137 
138  fcl_obj->setUserData((void *)m_parent);
139 
140  object_cached = true;
141  }
142  return (fcl_col_obj);
143 }
144 
145 } // namespace solverFCL
146 } // namespace solvers
147 
148 } // namespace collision
virtual bool BVCheck(CollisionObjectConstPtr obj2) const
int FCL_CalculateDistance(const FCLCollisionObject &obj1, const FCLCollisionObject &obj2, FCL_PRECISION &distance, double distance_tolerance=1e-6)
int FCL_DistanceTolerance(const FCLCollisionObjectGroup &group1, const FCLCollisionObject &obj2, FCL_PRECISION &distance, FCL_TOLERANCE_CHECK_TYPE check_type=TOLERANCE_CHECK_NARROWPHASE, double distance_tolerance=1e-6)
int calculateDistance(const CollisionObject &obj2, FCL_PRECISION &distance, FCL_PRECISION tolerance=1e-6) const
std::shared_ptr< const RectangleAABB > RectangleAABBConstPtr
std::size_t distance(const CollisionObject &obj1, const CollisionObject &obj2, DistanceResult &res, const DistanceRequest &req)
std::shared_ptr< const CollisionObject > CollisionObjectConstPtr
FCL_COLLISION_ENTITY_TYPE get_object_fcl_entity_type(const CollisionObject *obj2)
Definition: fcl_helpers.h:11
std::shared_ptr< fcl::CollisionObject< FCL_PRECISION > > getCollisionObject_fcl(void) const
virtual collision::RectangleAABBConstPtr getAABB(void) const
Axis-aligned rectangle.
virtual fcl::CollisionObject< FCL_PRECISION > * createFCLCollisionObject(const std::shared_ptr< fcl::CollisionGeometry< FCL_PRECISION >> &) const =0
int calculateDistanceNegTolerance(const CollisionObject &obj2, double &distance, FCL_TOLERANCE_CHECK_TYPE check_type=TOLERANCE_CHECK_NARROWPHASE, FCL_PRECISION tolerance=1e-6) const
virtual fcl::CollisionGeometry< FCL_PRECISION > * createFCLCollisionGeometry(void) const =0
Base class for CollisionObjects and some of their groups.