fcl/include/moveit/collision_detection_fcl/collision_common.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #pragma once
38 
44 
45 #if (MOVEIT_FCL_VERSION >= FCL_VERSION_CHECK(0, 6, 0))
49 #else
50 #include <fcl/broadphase/broadphase.h>
51 #include <fcl/collision.h>
52 #include <fcl/distance.h>
53 #endif
54 
55 #include <memory>
56 #include <set>
57 
58 namespace collision_detection
59 {
60 MOVEIT_STRUCT_FORWARD(CollisionGeometryData);
61 
63 struct CollisionGeometryData
64 {
67  : type(BodyTypes::ROBOT_LINK), shape_index(index)
68  {
69  ptr.link = link;
70  }
71 
74  : type(BodyTypes::ROBOT_ATTACHED), shape_index(index)
75  {
76  ptr.ab = ab;
77  }
78 
80  CollisionGeometryData(const World::Object* obj, int index) : type(BodyTypes::WORLD_OBJECT), shape_index(index)
81  {
82  ptr.obj = obj;
83  }
84 
86  const std::string& getID() const
87  {
88  switch (type)
89  {
91  return ptr.link->getName();
93  return ptr.ab->getName();
94  default:
95  break;
96  }
97  return ptr.obj->id_;
98  }
99 
101  std::string getTypeString() const
102  {
103  switch (type)
104  {
106  return "Robot link";
108  return "Robot attached";
109  default:
110  break;
111  }
112  return "Object";
113  }
114 
116  bool sameObject(const CollisionGeometryData& other) const
117  {
118  return type == other.type && ptr.raw == other.ptr.raw;
119  }
120 
122  BodyType type;
123 
128  int shape_index;
129 
131  union
132  {
135  const World::Object* obj;
136  const void* raw;
137  } ptr;
138 };
139 
141 struct CollisionData
142 {
143  CollisionData() : req_(nullptr), active_components_only_(nullptr), res_(nullptr), acm_(nullptr), done_(false)
144  {
145  }
146 
147  CollisionData(const CollisionRequest* req, CollisionResult* res, const AllowedCollisionMatrix* acm)
148  : req_(req), active_components_only_(nullptr), res_(res), acm_(acm), done_(false)
149  {
150  }
151 
153  {
154  }
155 
157  void enableGroup(const moveit::core::RobotModelConstPtr& robot_model);
158 
161 
166  const std::set<const moveit::core::LinkModel*>* active_components_only_;
167 
170 
173 
175  bool done_;
176 };
177 
180 {
182  {
183  }
185  {
186  }
187 
189  const DistanceRequest* req;
190 
193 
195  bool done;
196 };
197 
199 
202 {
203  FCLGeometry()
204  {
205  }
206 
208  FCLGeometry(fcl::CollisionGeometryd* collision_geometry, const moveit::core::LinkModel* link, int shape_index)
209  : collision_geometry_(collision_geometry), collision_geometry_data_(new CollisionGeometryData(link, shape_index))
210  {
212  }
213 
215  FCLGeometry(fcl::CollisionGeometryd* collision_geometry, const moveit::core::AttachedBody* ab, int shape_index)
216  : collision_geometry_(collision_geometry), collision_geometry_data_(new CollisionGeometryData(ab, shape_index))
217  {
218  collision_geometry_->setUserData(collision_geometry_data_.get());
219  }
220 
222  FCLGeometry(fcl::CollisionGeometryd* collision_geometry, const World::Object* obj, int shape_index)
223  : collision_geometry_(collision_geometry), collision_geometry_data_(new CollisionGeometryData(obj, shape_index))
224  {
225  collision_geometry_->setUserData(collision_geometry_data_.get());
226  }
227 
230  template <typename T>
231  void updateCollisionGeometryData(const T* data, int shape_index, bool newType)
232  {
233  if (!newType && collision_geometry_data_)
234  if (collision_geometry_data_->ptr.raw == reinterpret_cast<const void*>(data))
235  return;
236  collision_geometry_data_ = std::make_shared<CollisionGeometryData>(data, shape_index);
237  collision_geometry_->setUserData(collision_geometry_data_.get());
238  }
239 
241  std::shared_ptr<fcl::CollisionGeometryd> collision_geometry_;
242 
244  CollisionGeometryDataPtr collision_geometry_data_;
245 };
246 
247 typedef std::shared_ptr<fcl::CollisionObjectd> FCLCollisionObjectPtr;
248 typedef std::shared_ptr<const fcl::CollisionObjectd> FCLCollisionObjectConstPtr;
249 
252 struct FCLObject
253 {
256  void clear();
257 
258  std::vector<FCLCollisionObjectPtr> collision_objects_;
259 
261  std::vector<FCLGeometryConstPtr> collision_geometry_;
262 };
263 
265 struct FCLManager
266 {
268  std::shared_ptr<fcl::BroadPhaseCollisionManagerd> manager_;
269 };
270 
279 
287 bool distanceCallback(fcl::CollisionObjectd* o1, fcl::CollisionObjectd* o2, void* data, double& min_dist);
288 
290 FCLGeometryConstPtr createCollisionGeometry(const shapes::ShapeConstPtr& shape, const moveit::core::LinkModel* link,
291  int shape_index);
292 
294 FCLGeometryConstPtr createCollisionGeometry(const shapes::ShapeConstPtr& shape, const moveit::core::AttachedBody* ab,
295  int shape_index);
296 
300 FCLGeometryConstPtr createCollisionGeometry(const shapes::ShapeConstPtr& shape, const World::Object* obj);
301 
303 FCLGeometryConstPtr createCollisionGeometry(const shapes::ShapeConstPtr& shape, double scale, double padding,
304  const moveit::core::LinkModel* link, int shape_index);
305 
307 FCLGeometryConstPtr createCollisionGeometry(const shapes::ShapeConstPtr& shape, double scale, double padding,
308  const moveit::core::AttachedBody* ab, int shape_index);
309 
311 FCLGeometryConstPtr createCollisionGeometry(const shapes::ShapeConstPtr& shape, double scale, double padding,
312  const World::Object* obj);
313 
316 
318 inline void transform2fcl(const Eigen::Isometry3d& b, fcl::Transform3d& f)
319 {
320  ASSERT_ISOMETRY(b);
321 #if (MOVEIT_FCL_VERSION >= FCL_VERSION_CHECK(0, 6, 0))
322  f = b.matrix();
323 #else
324  Eigen::Quaterniond q(b.linear());
325  f.setTranslation(fcl::Vector3d(b.translation().x(), b.translation().y(), b.translation().z()));
326  f.setQuatRotation(fcl::Quaternion3f(q.w(), q.x(), q.y(), q.z()));
327 #endif
328 }
329 
331 inline fcl::Transform3d transform2fcl(const Eigen::Isometry3d& b)
332 {
334  transform2fcl(b, t);
335  return t;
336 }
337 
339 inline void fcl2contact(const fcl::Contactd& fc, Contact& c)
340 {
341  c.pos = Eigen::Vector3d(fc.pos[0], fc.pos[1], fc.pos[2]);
342  c.normal = Eigen::Vector3d(fc.normal[0], fc.normal[1], fc.normal[2]);
343  c.depth = fc.penetration_depth;
344  const CollisionGeometryData* cgd1 = static_cast<const CollisionGeometryData*>(fc.o1->getUserData());
345  c.body_name_1 = cgd1->getID();
346  c.body_type_1 = cgd1->type;
347  const CollisionGeometryData* cgd2 = static_cast<const CollisionGeometryData*>(fc.o2->getUserData());
348  c.body_name_2 = cgd2->getID();
349  c.body_type_2 = cgd2->type;
350 }
351 
353 inline void fcl2costsource(const fcl::CostSourced& fcs, CostSource& cs)
354 {
355  cs.aabb_min[0] = fcs.aabb_min[0];
356  cs.aabb_min[1] = fcs.aabb_min[1];
357  cs.aabb_min[2] = fcs.aabb_min[2];
358 
359  cs.aabb_max[0] = fcs.aabb_max[0];
360  cs.aabb_max[1] = fcs.aabb_max[1];
361  cs.aabb_max[2] = fcs.aabb_max[2];
362 
363  cs.cost = fcs.cost_density;
364 }
365 } // namespace collision_detection
moveit::core::LinkModel
A link from the robot. Contains the constant transform applied to the link and its geometry.
Definition: link_model.h:71
moveit::core
Core components of MoveIt.
Definition: kinematics_base.h:83
collision_detection::DistanceData::~DistanceData
~DistanceData()
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:216
collision_detection::FCLCollisionObjectConstPtr
std::shared_ptr< const fcl::CollisionObjectd > FCLCollisionObjectConstPtr
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:280
collision_detection::CollisionData::res_
CollisionResult * res_
The user-specified response location.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:201
collision_detection::CollisionData::active_components_only_
const std::set< const moveit::core::LinkModel * > * active_components_only_
If the collision request includes a group name, this set contains the pointers to the link models tha...
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:198
collision_detection::FCLManager::object_
FCLObject object_
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:299
collision_detection::DistanceData::res
DistanceResult * res
Distance query results information.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:224
collision_detection::BodyTypes::WORLD_OBJECT
@ WORLD_OBJECT
A body in the environment.
Definition: include/moveit/collision_detection/collision_common.h:97
collision_detection::CollisionData::req_
const CollisionRequest * req_
The collision request passed by the user.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:192
fcl::CostSource::aabb_max
Vector3< S > aabb_max
collision_detection::FCLGeometry::updateCollisionGeometryData
void updateCollisionGeometryData(const T *data, int shape_index, bool newType)
Updates the collision_geometry_data_ with new data while also setting the collision_geometry_ to the ...
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:263
collision_detection::DistanceData::req
const DistanceRequest * req
Distance query request information.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:221
check_isometry.h
world.h
fcl::Contact
collision_detection::FCLGeometry
Bundles the CollisionGeometryData and FCL collision geometry representation into a single class.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:233
collision_detection::FCLGeometry::collision_geometry_data_
CollisionGeometryDataPtr collision_geometry_data_
Pointer to the user-defined geometry data.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:276
fcl::CostSource
collision_detection::FCLManager::manager_
std::shared_ptr< fcl::BroadPhaseCollisionManagerd > manager_
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:300
broadphase_collision_manager.h
fcl::Transform3d
Transform3< double > Transform3d
fcl::Contact::normal
Vector3< S > normal
collision_detection::CollisionGeometryData::type
BodyType type
Indicates the body type of the object.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:154
class_forward.h
collision_detection::collisionCallback
bool collisionCallback(fcl::CollisionObjectd *o1, fcl::CollisionObjectd *o2, void *data)
Callback function used by the FCLManager used for each pair of collision objects to calculate object ...
Definition: fcl/src/collision_common.cpp:88
collision_detection::CollisionGeometryData::CollisionGeometryData
CollisionGeometryData(const moveit::core::LinkModel *link, int index)
Constructor for a robot link collision geometry object.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:98
collision_detection::fcl2costsource
void fcl2costsource(const fcl::CostSourced &fcs, CostSource &cs)
Transforms the FCL internal representation to the MoveIt CostSource data structure.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:385
collision_detection::CollisionGeometryData::getID
const std::string & getID() const
Returns the name which is saved in the member pointed to in ptr.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:118
collision_detection::CollisionGeometryData::shape_index
int shape_index
Multiple CollisionGeometryData objects construct a collision object. The collision object refers to a...
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:160
obj
CollisionObject< S > * obj
collision_detection::CollisionRequest
Representation of a collision checking request.
Definition: include/moveit/collision_detection/collision_common.h:179
collision_detection::CollisionData::done_
bool done_
Flag indicating whether collision checking is complete.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:207
collision_detection::CollisionGeometryData::raw
const void * raw
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:168
f
f
fcl::CostSource::aabb_min
Vector3< S > aabb_min
distance.h
collision_detection::FCLObject::collision_objects_
std::vector< FCLCollisionObjectPtr > collision_objects_
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:290
fcl::Vector3d
Vector3< double > Vector3d
collision_detection::cleanCollisionGeometryCache
void cleanCollisionGeometryCache()
Increases the counter of the caches which can trigger the cleaning of expired entries from them.
Definition: fcl/src/collision_common.cpp:958
moveit::core::AttachedBody
Object defining bodies that can be attached to robot links.
Definition: attached_body.h:121
collision_detection::CollisionGeometryData::ab
const moveit::core::AttachedBody * ab
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:166
collision_detection::AllowedCollisionMatrix
Definition of a structure for the allowed collision matrix.
Definition: collision_matrix.h:112
collision_detection::transform2fcl
void transform2fcl(const Eigen::Isometry3d &b, fcl::Transform3d &f)
Transforms an Eigen Isometry3d to FCL coordinate transformation.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:350
collision_detection::distanceCallback
bool distanceCallback(fcl::CollisionObjectd *o1, fcl::CollisionObjectd *o2, void *data, double &min_dist)
Callback function used by the FCLManager used for each pair of collision objects to calculate collisi...
Definition: fcl/src/collision_common.cpp:443
fcl::CollisionGeometry
collision_detection::CollisionGeometryData::ptr
union collision_detection::CollisionGeometryData::@0 ptr
Points to the type of body which contains the geometry.
collision_detection::CollisionResult
Representation of a collision checking result.
Definition: include/moveit/collision_detection/collision_common.h:382
collision_detection::CollisionData::acm_
const AllowedCollisionMatrix * acm_
The user-specified collision matrix (may be NULL).
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:204
collision_env.h
ASSERT_ISOMETRY
#define ASSERT_ISOMETRY(transform)
collision_detection::FCLObject::clear
void clear()
Definition: fcl/src/collision_common.cpp:993
fcl::Contact::pos
Vector3< S > pos
collision_detection::FCLCollisionObjectPtr
std::shared_ptr< fcl::CollisionObjectd > FCLCollisionObjectPtr
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:279
collision_detection::CollisionGeometryData
Wrapper around world, link and attached objects' geometry data.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:95
collision_detection::FCLGeometry::collision_geometry_
std::shared_ptr< fcl::CollisionGeometryd > collision_geometry_
Pointer to FCL collision geometry.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:273
collision_detection::BodyTypes::ROBOT_ATTACHED
@ ROBOT_ATTACHED
A body attached to a robot link.
Definition: include/moveit/collision_detection/collision_common.h:94
fcl::Contact::o2
const CollisionGeometry< S > * o2
fcl::Contact::o1
const CollisionGeometry< S > * o1
fcl::CostSource::cost_density
S cost_density
collision_detection::BodyTypes::ROBOT_LINK
@ ROBOT_LINK
A link on the robot.
Definition: include/moveit/collision_detection/collision_common.h:91
collision_detection::World::Object
A representation of an object.
Definition: world.h:79
collision_detection::FCLObject::unregisterFrom
void unregisterFrom(fcl::BroadPhaseCollisionManagerd *manager)
Definition: fcl/src/collision_common.cpp:987
collision_detection::CollisionGeometryData::obj
const World::Object * obj
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:167
collision_detection::FCLManager
Bundles an FCLObject and a broadphase FCL collision manager.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:297
collision_detection::BodyTypes::Type
Type
The types of bodies that are considered for collision.
Definition: include/moveit/collision_detection/collision_common.h:88
collision_detection::CollisionData::enableGroup
void enableGroup(const moveit::core::RobotModelConstPtr &robot_model)
Compute active_components_only_ based on the joint group specified in req_.
Definition: fcl/src/collision_common.cpp:970
collision_detection::CollisionData::~CollisionData
~CollisionData()
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:184
collision_detection::CollisionGeometryData::link
const moveit::core::LinkModel * link
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:165
collision_detection::DistanceData::DistanceData
DistanceData(const DistanceRequest *req, DistanceResult *res)
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:213
collision_detection::createCollisionGeometry
FCLGeometryConstPtr createCollisionGeometry(const shapes::ShapeConstPtr &shape, const moveit::core::LinkModel *link, int shape_index)
Create new FCLGeometry object out of robot link model.
Definition: fcl/src/collision_common.cpp:906
collision_detection::DistanceResult
Result of a distance request.
Definition: include/moveit/collision_detection/collision_common.h:357
fcl_compat.h
fcl::Contact::penetration_depth
S penetration_depth
collision_detection::FCLObject
A general high-level object which consists of multiple FCLCollisionObjects. It is the top level data ...
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:284
index
unsigned int index
collision_detection::CollisionGeometryData::sameObject
bool sameObject(const CollisionGeometryData &other) const
Check if two CollisionGeometryData objects point to the same source object.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:148
collision_detection::FCLGeometry::FCLGeometry
FCLGeometry()
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:235
shapes::ShapeConstPtr
std::shared_ptr< const Shape > ShapeConstPtr
collision_detection::FCLObject::registerTo
void registerTo(fcl::BroadPhaseCollisionManagerd *manager)
Definition: fcl/src/collision_common.cpp:978
collision_detection::DistanceData
Data structure which is passed to the distance callback function of the collision manager.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:211
collision_detection::FCLObject::collision_geometry_
std::vector< FCLGeometryConstPtr > collision_geometry_
Geometry data corresponding to collision_objects_.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:293
collision.h
fcl::CollisionGeometry::getUserData
void * getUserData() const
collision_detection::fcl2contact
void fcl2contact(const fcl::Contactd &fc, Contact &c)
Transforms an FCL contact into a MoveIt contact point.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:371
collision_detection::DistanceRequest
Representation of a distance-reporting request.
Definition: include/moveit/collision_detection/collision_common.h:241
fcl::CollisionObject
collision_detection::CollisionData::CollisionData
CollisionData()
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:175
t
geometry_msgs::TransformStamped t
collision_detection::CollisionGeometryData::getTypeString
std::string getTypeString() const
Returns a string of the corresponding type.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:133
collision_detection::MOVEIT_STRUCT_FORWARD
MOVEIT_STRUCT_FORWARD(CollisionGeometryData)
fcl::Vector3d
Vec3fX< details::Vec3Data< double > > Vector3d
Definition: fcl_compat.h:89
fcl::BroadPhaseCollisionManager
collision_detection
Definition: collision_detector_allocator_allvalid.h:42
collision_detection::DistanceData::done
bool done
Indicates if distance query is finished.
Definition: fcl/include/moveit/collision_detection_fcl/collision_common.h:227


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Thu Apr 18 2024 02:23:40