39 #ifndef HPP_FCL_COLLISION_DATA_H
40 #define HPP_FCL_COLLISION_DATA_H
109 static const int NONE = -1;
112 Contact() : o1(NULL), o2(NULL), b1(NONE), b2(NONE) {
113 penetration_depth = (std::numeric_limits<FCL_REAL>::max)();
114 nearest_points[0] = nearest_points[1] = normal = pos =
115 Vec3f::Constant(std::numeric_limits<FCL_REAL>::quiet_NaN());
120 : o1(o1_), o2(o2_), b1(b1_), b2(b2_) {
121 penetration_depth = (std::numeric_limits<FCL_REAL>::max)();
122 nearest_points[0] = nearest_points[1] = normal = pos =
123 Vec3f::Constant(std::numeric_limits<FCL_REAL>::quiet_NaN());
133 nearest_points{pos_ - (depth_ * normal_ / 2),
134 pos_ + (depth_ * normal_ / 2)},
136 penetration_depth(depth_) {}
146 nearest_points{p1, p2},
148 penetration_depth(depth_) {}
151 if (b1 == other.
b1)
return b2 < other.
b2;
152 return b1 < other.
b1;
156 return o1 == other.
o1 && o2 == other.
o2 && b1 == other.
b1 &&
157 b2 == other.
b2 && normal == other.
normal && pos == other.
pos &&
178 bool enable_cached_gjk_guess;
187 size_t gjk_max_iterations;
205 size_t epa_max_iterations;
225 enable_cached_gjk_guess(false),
226 cached_gjk_guess(1, 0, 0),
235 enable_timings(false),
236 collision_distance_threshold(
237 Eigen::NumTraits<
FCL_REAL>::dummy_precision()) {}
261 gjk_convergence_criterion_type ==
287 : cached_gjk_guess(
Vec3f::Zero()),
322 bool enable_distance_lower_bound;
351 : num_max_contacts(num_max_contacts_),
352 enable_contact(flag &
CONTACT),
355 break_distance(1e-3),
356 distance_upper_bound((std::numeric_limits<
FCL_REAL>::max)()) {}
360 : num_max_contacts(1),
361 enable_contact(true),
362 enable_distance_lower_bound(false),
364 break_distance(1e-3),
365 distance_upper_bound((std::numeric_limits<
FCL_REAL>::max)()) {}
394 std::vector<Contact> contacts;
419 : distance_lower_bound((std::numeric_limits<
FCL_REAL>::max)()) {
420 nearest_points[0] = nearest_points[1] = normal =
421 Vec3f::Constant(std::numeric_limits<FCL_REAL>::quiet_NaN());
426 if (distance_lower_bound_ < distance_lower_bound)
427 distance_lower_bound = distance_lower_bound_;
435 return contacts == other.contacts &&
450 if (contacts.size() == 0)
452 "The number of contacts is zero. No Contact can be returned.",
453 std::invalid_argument);
455 if (i < contacts.size())
458 return contacts.back();
463 if (contacts.size() == 0)
465 "The number of contacts is zero. No Contact can be returned.",
466 std::invalid_argument);
468 if (i < contacts.size())
476 contacts_.resize(contacts.size());
477 std::copy(contacts.begin(), contacts.end(), contacts_.begin());
480 const std::vector<Contact>&
getContacts()
const {
return contacts; }
484 distance_lower_bound = (std::numeric_limits<FCL_REAL>::max)();
487 nearest_points[0] = nearest_points[1] = normal =
488 Vec3f::Constant(std::numeric_limits<FCL_REAL>::quiet_NaN());
549 static constexpr
size_t default_preallocated_size = 12;
561 explicit ContactPatch(
size_t preallocated_size = default_preallocated_size)
564 penetration_depth(0) {
565 this->m_points.reserve(preallocated_size);
570 if (this->direction == PatchDirection::INVERTED) {
577 size_t size()
const {
return this->m_points.size(); }
586 this->m_points.emplace_back(point.template head<2>());
591 Vec3f point(0, 0, 0);
592 point.head<2>() = this->point(i);
601 Vec3f point = this->getPoint(i);
602 point -= (this->penetration_depth / 2) * this->getNormal();
610 Vec3f point = this->getPoint(i);
611 point += (this->penetration_depth / 2) * this->getNormal();
625 if (i < this->m_points.size()) {
626 return this->m_points[i];
628 return this->m_points.back();
635 if (i < this->m_points.size()) {
636 return this->m_points[i];
638 return this->m_points.back();
643 this->m_points.clear();
645 this->penetration_depth = 0;
653 return this->tf == other.
tf && this->direction == other.
direction &&
655 this->points() == other.
points();
662 Eigen::NumTraits<FCL_REAL>::dummy_precision())
const {
666 if (!this->getNormal().isApprox(other.
getNormal(), tol)) {
674 if (this->direction != other.
direction) {
678 if (this->size() != other.
size()) {
683 for (
size_t i = 0; i < this->size(); ++i) {
685 const Vec3f pi = this->getPoint(i);
686 for (
size_t j = 0; j < other.
size(); ++j) {
688 if (pi.isApprox(other_pj, tol)) {
712 contact_patch.
direction = ContactPatch::PatchDirection::DEFAULT;
764 size_t num_samples_curved_shapes =
767 : max_num_patch(max_num_patch) {
768 this->setNumSamplesCurvedShapes(num_samples_curved_shapes);
769 this->setPatchTolerance(patch_tolerance);
774 size_t num_samples_curved_shapes =
777 : max_num_patch(collision_request.num_max_contacts) {
778 this->setNumSamplesCurvedShapes(num_samples_curved_shapes);
779 this->setPatchTolerance(patch_tolerance);
784 if (num_samples_curved_shapes < 3) {
786 "`num_samples_curved_shapes` cannot be lower than 3. Setting it to "
787 "3 to prevent bugs.");
788 this->m_num_samples_curved_shapes = 3;
790 this->m_num_samples_curved_shapes = num_samples_curved_shapes;
796 return this->m_num_samples_curved_shapes;
801 if (patch_tolerance < 0) {
803 "`patch_tolerance` cannot be negative. Setting it to 0 to prevent "
805 this->m_patch_tolerance = Eigen::NumTraits<FCL_REAL>::dummy_precision();
807 this->m_patch_tolerance = patch_tolerance;
817 this->getNumSamplesCurvedShapes() ==
849 const size_t max_num_patch = 1;
856 : m_id_available_patch(0) {
865 if (this->m_id_available_patch >= this->m_contact_patches_data.size()) {
867 "Trying to get an unused contact patch but all contact patches are "
868 "used. Increasing size of contact patches vector, at the cost of a "
869 "copy. You should increase `max_num_patch` in the "
870 "`ContactPatchRequest`.");
871 this->m_contact_patches_data.emplace_back(
872 this->m_contact_patches_data.back());
873 this->m_contact_patches_data.back().clear();
876 this->m_contact_patches_data[this->m_id_available_patch];
877 contact_patch.
clear();
878 this->m_contact_patches.emplace_back(contact_patch);
879 ++(this->m_id_available_patch);
880 return this->m_contact_patches.back();
885 if (this->m_contact_patches.empty()) {
887 "The number of contact patches is zero. No ContactPatch can be "
889 std::invalid_argument);
891 if (i < this->m_contact_patches.size()) {
892 return this->m_contact_patches[i];
894 return this->m_contact_patches.back();
899 if (this->m_contact_patches.empty()) {
901 "The number of contact patches is zero. No ContactPatch can be "
903 std::invalid_argument);
905 if (i < this->m_contact_patches.size()) {
906 return this->m_contact_patches[i];
908 return this->m_contact_patches.back();
913 this->m_contact_patches.clear();
914 this->m_id_available_patch = 0;
915 for (
ContactPatch& patch : this->m_contact_patches_data) {
922 if (this->m_contact_patches_data.size() < request.
max_num_patch) {
925 for (
ContactPatch& patch : this->m_contact_patches_data) {
934 assert(this->m_contact_patches_data.size() >= request.
max_num_patch);
935 if (this->m_contact_patches_data.size() < request.
max_num_patch) {
939 for (
const ContactPatch& patch : this->m_contact_patches_data) {
941 assert(patch.points().capacity() >=
955 for (
size_t i = 0; i < this->numContactPatches(); ++i) {
958 if (!(patch == other_patch)) {
972 for (
size_t i = 0; i < this->numContactPatches(); ++i) {
977 for (
size_t j = 0; j < patch.
size(); ++j) {
978 patch.
point(i)(0) *= -1.0;
984 struct DistanceResult;
992 Nearest points are always computed : they are the points of the shapes
995 .\n Use `enable_signed_distance`
if you want to compute a
signed
996 minimum
distance(and thus its corresponding nearest points)
998 bool enable_nearest_points;
1012 bool enable_signed_distance;
1025 bool enable_signed_distance_ = true,
FCL_REAL rel_err_ = 0.0,
1027 : enable_nearest_points(enable_nearest_points_),
1028 enable_signed_distance(enable_signed_distance_),
1030 abs_err(abs_err_) {}
1088 static const int NONE = -1;
1091 FCL_REAL min_distance_ = (std::numeric_limits<FCL_REAL>::max)())
1092 : min_distance(min_distance_), o1(NULL), o2(NULL), b1(NONE), b2(NONE) {
1094 Vec3f::Constant(std::numeric_limits<FCL_REAL>::quiet_NaN()));
1095 nearest_points[0] = nearest_points[1] = normal = nan;
1120 nearest_points[0] = p1;
1121 nearest_points[1] = p2;
1130 o1 = other_result.
o1;
1131 o2 = other_result.
o2;
1132 b1 = other_result.
b1;
1133 b2 = other_result.
b2;
1136 normal = other_result.
normal;
1143 Vec3f::Constant(std::numeric_limits<FCL_REAL>::quiet_NaN()));
1144 min_distance = (std::numeric_limits<FCL_REAL>::max)();
1149 nearest_points[0] = nearest_points[1] = normal = nan;
1158 normal == other.
normal && o1 == other.
o1 && o2 == other.
o2 &&
1159 b1 == other.
b1 && b2 == other.
b2;
1162 if ((o1 != NULL) ^ (other.
o1 != NULL))
return false;
1163 is_same &= (o1 == other.
o1);
1167 if ((o2 != NULL) ^ (other.
o2 != NULL))
return false;
1168 is_same &= (o2 == other.
o2);
1176 namespace internal {
1179 const FCL_REAL sqrDistLowerBound) {
1182 FCL_REAL new_dlb = std::sqrt(sqrDistLowerBound);
1190 const Vec3f& normal) {
1207 static_cast<int>(b));
1213 static_cast<int>(b));
1219 static_cast<int>(b));
The geometry for the object for collision or distance computation.
Definition: collision_object.h:95
#define HPP_FCL_DLLAPI
Definition: config.hh:88
#define HPP_FCL_DEPRECATED_MESSAGE(message)
Definition: deprecated.hh:38
#define HPP_FCL_ASSERT(check, message, exception)
Definition: fwd.hh:82
#define HPP_FCL_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
Definition: fwd.hh:122
#define HPP_FCL_COMPILER_DIAGNOSTIC_PUSH
Definition: fwd.hh:120
#define HPP_FCL_COMPILER_DIAGNOSTIC_POP
Definition: fwd.hh:121
#define HPP_FCL_THROW_PRETTY(message, exception)
Definition: fwd.hh:64
FCL_REAL distance(const Matrix3f &R0, const Vec3f &T0, const kIOS &b1, const kIOS &b2, Vec3f *P=NULL, Vec3f *Q=NULL)
Approximate distance between two kIOS bounding volumes.
#define HPP_FCL_LOG_WARNING(message)
Definition: logging.h:50
void updateDistanceLowerBoundFromLeaf(const CollisionRequest &, CollisionResult &res, const FCL_REAL &distance, const Vec3f &p0, const Vec3f &p1, const Vec3f &normal)
Definition: collision_data.h:1186
void updateDistanceLowerBoundFromBV(const CollisionRequest &, CollisionResult &res, const FCL_REAL sqrDistLowerBound)
Definition: collision_data.h:1177
CollisionRequestFlag operator&(CollisionRequestFlag a, CollisionRequestFlag b)
Definition: collision_data.h:1210
Matrix3f constructOrthonormalBasisFromVector(const Vec3f &vec)
Construct othonormal basis from vector. The z-axis is the normalized input vector.
Definition: transform.h:261
CollisionRequestFlag & operator^=(CollisionRequestFlag &a, CollisionRequestFlag b)
Definition: collision_data.h:1232
GJKVariant
Variant to use for the GJK algorithm.
Definition: data_types.h:88
@ DefaultGJK
Definition: data_types.h:88
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
CollisionRequestFlag & operator&=(CollisionRequestFlag &a, CollisionRequestFlag b)
Definition: collision_data.h:1227
CollisionRequestFlag operator~(CollisionRequestFlag a)
Definition: collision_data.h:1200
GJKConvergenceCriterionType
Wether the convergence criterion is scaled on the norm of the solution or not.
Definition: data_types.h:98
@ Relative
Definition: data_types.h:98
CollisionRequestFlag
flag declaration for specifying required params in CollisionResult
Definition: collision_data.h:305
@ NO_REQUEST
Definition: collision_data.h:308
@ DISTANCE_LOWER_BOUND
Definition: collision_data.h:307
@ CONTACT
Definition: collision_data.h:306
Eigen::Matrix< FCL_REAL, 2, 1 > Vec2f
Definition: data_types.h:68
void constructContactPatchFrameFromContact(const Contact &contact, ContactPatch &contact_patch)
Construct a frame from a Contact's position and normal. Because both Contact's position and normal ar...
Definition: collision_data.h:706
GJKConvergenceCriterion
Which convergence criterion is used to stop the algorithm (when the shapes are not in collision)....
Definition: data_types.h:94
@ Default
Definition: data_types.h:94
CollisionRequestFlag operator^(CollisionRequestFlag a, CollisionRequestFlag b)
Definition: collision_data.h:1216
GJKInitialGuess
Initial guess to use for the GJK algorithm DefaultGuess: Vec3f(1, 0, 0) CachedGuess: previous vector ...
Definition: data_types.h:85
@ CachedGuess
Definition: data_types.h:85
@ DefaultGuess
Definition: data_types.h:85
constexpr size_t GJK_DEFAULT_MAX_ITERATIONS
GJK.
Definition: narrowphase_defaults.h:47
constexpr size_t EPA_DEFAULT_MAX_ITERATIONS
Definition: narrowphase_defaults.h:60
constexpr FCL_REAL EPA_DEFAULT_TOLERANCE
Definition: narrowphase_defaults.h:61
constexpr FCL_REAL GJK_DEFAULT_TOLERANCE
Definition: narrowphase_defaults.h:48
CollisionRequestFlag operator|(CollisionRequestFlag a, CollisionRequestFlag b)
Definition: collision_data.h:1204
double FCL_REAL
Definition: data_types.h:66
Eigen::Vector2i support_func_guess_t
Definition: data_types.h:77
CollisionRequestFlag & operator|=(CollisionRequestFlag &a, CollisionRequestFlag b)
Definition: collision_data.h:1222
Main namespace.
Definition: broadphase_bruteforce.h:44
request to the collision algorithm
Definition: collision_data.h:312
size_t num_max_contacts
The maximum number of contacts that can be returned.
Definition: collision_data.h:314
bool enable_distance_lower_bound
Whether a lower bound on distance is returned when objects are disjoint.
Definition: collision_data.h:322
FCL_REAL distance_upper_bound
Distance above which GJK solver makes an early stopping. GJK stops searching for the closest points w...
Definition: collision_data.h:341
FCL_REAL security_margin
Distance below which objects are considered in collision. See Collision.
Definition: collision_data.h:329
bool enable_contact
whether the contact information (normal, penetration depth and contact position) will return.
Definition: collision_data.h:318
bool isSatisfied(const CollisionResult &result) const
bool operator==(const CollisionRequest &other) const
whether two CollisionRequest are the same or not
Definition: collision_data.h:371
CollisionRequest()
Default constructor.
Definition: collision_data.h:359
FCL_REAL break_distance
Distance below which bounding volumes are broken down. See Collision.
Definition: collision_data.h:333
collision result
Definition: collision_data.h:391
std::array< Vec3f, 2 > nearest_points
nearest points. A CollisionResult can have multiple contacts. The nearest points in CollisionResults ...
Definition: collision_data.h:415
void clear()
clear the results obtained
Definition: collision_data.h:483
void updateDistanceLowerBound(const FCL_REAL &distance_lower_bound_)
Update the lower bound only if the distance is inferior.
Definition: collision_data.h:425
void addContact(const Contact &c)
add one contact into result structure
Definition: collision_data.h:431
const Contact & getContact(size_t i) const
get the i-th contact calculated
Definition: collision_data.h:449
bool isCollision() const
return binary collision result
Definition: collision_data.h:443
const std::vector< Contact > & getContacts() const
Definition: collision_data.h:480
Vec3f normal
normal associated to nearest_points. Same as CollisionResult::nearest_points but for the normal.
Definition: collision_data.h:406
void getContacts(std::vector< Contact > &contacts_) const
get all the contacts
Definition: collision_data.h:475
FCL_REAL distance_lower_bound
Definition: collision_data.h:402
void setContact(size_t i, const Contact &c)
set the i-th contact calculated
Definition: collision_data.h:462
bool operator==(const CollisionResult &other) const
whether two CollisionResult are the same or not
Definition: collision_data.h:434
CollisionResult()
Definition: collision_data.h:418
size_t numContacts() const
number of contacts found
Definition: collision_data.h:446
void swapObjects()
reposition Contact objects when fcl inverts them during their construction.
request to the distance computation
Definition: collision_data.h:987
bool enable_nearest_points
whether to return the nearest points. Nearest points are always computed and are the points of the sh...
Definition: collision_data.h:998
bool enable_signed_distance
whether to compute the penetration depth when objects are in collision. Turning this off can save com...
Definition: collision_data.h:1012
bool operator==(const DistanceRequest &other) const
whether two DistanceRequest are the same or not
Definition: collision_data.h:1041
FCL_REAL rel_err
error threshold for approximate distance
Definition: collision_data.h:1015
bool isSatisfied(const DistanceResult &result) const
DistanceRequest & operator=(const DistanceRequest &other)=default
FCL_REAL abs_err
Definition: collision_data.h:1016
distance result
Definition: collision_data.h:1053
const CollisionGeometry * o2
collision object 2
Definition: collision_data.h:1073
DistanceResult(FCL_REAL min_distance_=(std::numeric_limits< FCL_REAL >::max)())
Definition: collision_data.h:1090
bool operator==(const DistanceResult &other) const
whether two DistanceResult are the same or not
Definition: collision_data.h:1154
void update(FCL_REAL distance, const CollisionGeometry *o1_, const CollisionGeometry *o2_, int b1_, int b2_)
add distance information into the result
Definition: collision_data.h:1099
void update(const DistanceResult &other_result)
add distance information into the result
Definition: collision_data.h:1127
std::array< Vec3f, 2 > nearest_points
nearest points. See CollisionResult::nearest_points.
Definition: collision_data.h:1067
Vec3f normal
normal.
Definition: collision_data.h:1063
const CollisionGeometry * o1
collision object 1
Definition: collision_data.h:1070
void update(FCL_REAL distance, const CollisionGeometry *o1_, const CollisionGeometry *o2_, int b1_, int b2_, const Vec3f &p1, const Vec3f &p2, const Vec3f &normal_)
add distance information into the result
Definition: collision_data.h:1111
int b2
information about the nearest point in object 2 if object 2 is mesh or point cloud,...
Definition: collision_data.h:1085
int b1
information about the nearest point in object 1 if object 1 is mesh or point cloud,...
Definition: collision_data.h:1079
void clear()
clear the result
Definition: collision_data.h:1141
FCL_REAL min_distance
minimum distance between two objects. If two objects are in collision and DistanceRequest::enable_sig...
Definition: collision_data.h:1060
base class for all query requests
Definition: collision_data.h:171
GJKVariant gjk_variant
whether to enable the Nesterov accleration of GJK
Definition: collision_data.h:196
Vec3f cached_gjk_guess
the gjk initial guess set by user
Definition: collision_data.h:181
bool operator==(const QueryRequest &other) const
whether two QueryRequest are the same or not
Definition: collision_data.h:254
GJKInitialGuess gjk_initial_guess
Definition: collision_data.h:173
GJKConvergenceCriterion gjk_convergence_criterion
convergence criterion used to stop GJK
Definition: collision_data.h:199
size_t gjk_max_iterations
maximum iteration for the GJK algorithm
Definition: collision_data.h:187
support_func_guess_t cached_support_func_guess
the support function initial guess set by user
Definition: collision_data.h:184
FCL_REAL gjk_tolerance
tolerance for the GJK algorithm. Note: This tolerance determines the precision on the estimated dista...
Definition: collision_data.h:193
size_t epa_max_iterations
max number of iterations for EPA
Definition: collision_data.h:205
void updateGuess(const QueryResult &result) const
Updates the guess for the internal GJK algorithm in order to warm-start it when reusing this collisio...
Definition: collision_data.h:291
QueryRequest & operator=(const QueryRequest &other)=default
Copy assignment operator.
bool enable_timings
enable timings when performing collision/distance request
Definition: collision_data.h:215
FCL_REAL epa_tolerance
tolerance for EPA. Note: This tolerance determines the precision on the estimated distance between tw...
Definition: collision_data.h:212
QueryRequest(const QueryRequest &other)=default
Copy constructor.
bool enable_cached_gjk_guess
whether enable gjk initial guess @Deprecated Use gjk_initial_guess instead
Definition: collision_data.h:178
FCL_REAL collision_distance_threshold
threshold below which a collision is considered.
Definition: collision_data.h:218
GJKConvergenceCriterionType gjk_convergence_criterion_type
convergence criterion used to stop GJK
Definition: collision_data.h:202
base class for all query results
Definition: collision_data.h:276
support_func_guess_t cached_support_func_guess
stores the last support function vertex index, when relevant.
Definition: collision_data.h:281
Vec3f cached_gjk_guess
stores the last GJK ray when relevant.
Definition: collision_data.h:278
QueryResult()
Definition: collision_data.h:286
CPUTimes timings
timings for the given request
Definition: collision_data.h:284