gjk.cc
Go to the documentation of this file.
1 //
2 // Software License Agreement (BSD License)
3 //
4 // Copyright (c) 2020 CNRS-LAAS
5 // Author: Joseph Mirabel
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following
16 // disclaimer in the documentation and/or other materials provided
17 // with the distribution.
18 // * Neither the name of CNRS-LAAS. nor the names of its
19 // contributors may be used to endorse or promote products derived
20 // from this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 // POSSIBILITY OF SUCH DAMAGE.
34 
35 #include <eigenpy/eigenpy.hpp>
36 
37 #include "coal.hh"
38 
39 #include "coal/fwd.hh"
40 #include "coal/narrowphase/gjk.h"
41 
42 #ifdef COAL_HAS_DOXYGEN_AUTODOC
43 #include "doxygen_autodoc/functions.h"
44 #include "doxygen_autodoc/coal/narrowphase/gjk.h"
45 #endif
46 
47 using namespace boost::python;
48 using namespace coal;
49 using coal::details::EPA;
50 using coal::details::GJK;
53 
55  static void support0(MinkowskiDiff& self, const Vec3s& dir, int& hint,
56  bool compute_swept_sphere_support = false) {
57  if (compute_swept_sphere_support) {
58  self.support0<SupportOptions::WithSweptSphere>(dir, hint);
59  } else {
60  self.support0<SupportOptions::NoSweptSphere>(dir, hint);
61  }
62  }
63 
64  static void support1(MinkowskiDiff& self, const Vec3s& dir, int& hint,
65  bool compute_swept_sphere_support = false) {
66  if (compute_swept_sphere_support) {
67  self.support1<SupportOptions::WithSweptSphere>(dir, hint);
68  } else {
69  self.support1<SupportOptions::NoSweptSphere>(dir, hint);
70  }
71  }
72 
73  static void set(MinkowskiDiff& self, const ShapeBase* shape0,
74  const ShapeBase* shape1,
75  bool compute_swept_sphere_support = false) {
76  if (compute_swept_sphere_support) {
77  self.set<SupportOptions::WithSweptSphere>(shape0, shape1);
78  } else {
79  self.set<SupportOptions::NoSweptSphere>(shape0, shape1);
80  }
81  }
82 
83  static void set(MinkowskiDiff& self, const ShapeBase* shape0,
84  const ShapeBase* shape1, const Transform3s& tf0,
85  const Transform3s& tf1,
86  bool compute_swept_sphere_supports = false) {
87  if (compute_swept_sphere_supports) {
88  self.set<SupportOptions::WithSweptSphere>(shape0, shape1, tf0, tf1);
89  } else {
90  self.set<SupportOptions::NoSweptSphere>(shape0, shape1, tf0, tf1);
91  }
92  }
93 };
94 
95 void exposeGJK() {
96  if (!eigenpy::register_symbolic_link_to_registered_type<GJK::Status>()) {
97  enum_<GJK::Status>("GJKStatus")
98  .value("Failed", GJK::Status::Failed)
99  .value("DidNotRun", GJK::Status::DidNotRun)
100  .value("NoCollision", GJK::Status::NoCollision)
101  .value("NoCollisionEarlyStopped", GJK::Status::NoCollisionEarlyStopped)
102  .value("CollisionWithPenetrationInformation",
103  GJK::Status::CollisionWithPenetrationInformation)
104  .value("Collision", GJK::Status::Collision)
105  .export_values();
106  }
107 
108  if (!eigenpy::register_symbolic_link_to_registered_type<MinkowskiDiff>()) {
109  class_<MinkowskiDiff>("MinkowskiDiff", doxygen::class_doc<MinkowskiDiff>(),
110  no_init)
111  .def(doxygen::visitor::init<MinkowskiDiff>())
112  .def("set",
113  static_cast<void (*)(MinkowskiDiff&, const ShapeBase*,
114  const ShapeBase*, bool)>(
116  doxygen::member_func_doc(static_cast<void (MinkowskiDiff::*)(
117  const ShapeBase*, const ShapeBase*)>(
118  &MinkowskiDiff::set<SupportOptions::NoSweptSphere>)))
119 
120  .def("set",
121  static_cast<void (*)(MinkowskiDiff&, const ShapeBase*,
122  const ShapeBase*, const Transform3s&,
123  const Transform3s&, bool)>(
126  static_cast<void (MinkowskiDiff::*)(
127  const ShapeBase*, const ShapeBase*, const Transform3s&,
128  const Transform3s&)>(
129  &MinkowskiDiff::set<SupportOptions::NoSweptSphere>)))
130 
131  .def("support0", &MinkowskiDiffWrapper::support0,
133  &MinkowskiDiff::support0<SupportOptions::NoSweptSphere>))
134 
135  .def("support1", &MinkowskiDiffWrapper::support1,
137  &MinkowskiDiff::support1<SupportOptions::NoSweptSphere>))
138 
139  .def("support", &MinkowskiDiff::support,
140  doxygen::member_func_doc(&MinkowskiDiff::support))
141 
142  .DEF_RW_CLASS_ATTRIB(MinkowskiDiff, swept_sphere_radius)
143  .DEF_RW_CLASS_ATTRIB(MinkowskiDiff, normalize_support_direction);
144  }
145 
146  if (!eigenpy::register_symbolic_link_to_registered_type<GJKVariant>()) {
147  enum_<GJKVariant>("GJKVariant")
148  .value("DefaultGJK", GJKVariant::DefaultGJK)
149  .value("PolyakAcceleration", GJKVariant::PolyakAcceleration)
150  .value("NesterovAcceleration", GJKVariant::NesterovAcceleration)
151  .export_values();
152  }
153 
154  if (!eigenpy::register_symbolic_link_to_registered_type<GJKInitialGuess>()) {
155  enum_<GJKInitialGuess>("GJKInitialGuess")
156  .value("DefaultGuess", GJKInitialGuess::DefaultGuess)
157  .value("CachedGuess", GJKInitialGuess::CachedGuess)
158  .value("BoundingVolumeGuess", GJKInitialGuess::BoundingVolumeGuess)
159  .export_values();
160  }
161 
164  enum_<GJKConvergenceCriterion>("GJKConvergenceCriterion")
165  .value("Default", GJKConvergenceCriterion::Default)
166  .value("DualityGap", GJKConvergenceCriterion::DualityGap)
167  .value("Hybrid", GJKConvergenceCriterion::Hybrid)
168  .export_values();
169  }
170 
173  enum_<GJKConvergenceCriterionType>("GJKConvergenceCriterionType")
174  .value("Absolute", GJKConvergenceCriterionType::Absolute)
175  .value("Relative", GJKConvergenceCriterionType::Relative)
176  .export_values();
177  }
178 
179  if (!eigenpy::register_symbolic_link_to_registered_type<GJK>()) {
180  class_<GJK>("GJK", doxygen::class_doc<GJK>(), no_init)
181  .def(doxygen::visitor::init<GJK, unsigned int, CoalScalar>())
182  .DEF_RW_CLASS_ATTRIB(GJK, distance)
183  .DEF_RW_CLASS_ATTRIB(GJK, ray)
184  .DEF_RW_CLASS_ATTRIB(GJK, support_hint)
185  .DEF_RW_CLASS_ATTRIB(GJK, gjk_variant)
186  .DEF_RW_CLASS_ATTRIB(GJK, convergence_criterion)
187  .DEF_RW_CLASS_ATTRIB(GJK, convergence_criterion_type)
188  .DEF_CLASS_FUNC(GJK, reset)
189  .DEF_CLASS_FUNC(GJK, evaluate)
190  .DEF_CLASS_FUNC(GJK, getTolerance)
191  .DEF_CLASS_FUNC(GJK, getNumMaxIterations)
192  .DEF_CLASS_FUNC(GJK, getNumIterations)
193  .DEF_CLASS_FUNC(GJK, getNumIterationsMomentumStopped)
194  .DEF_CLASS_FUNC(GJK, hasClosestPoints)
195  .DEF_CLASS_FUNC(GJK, getWitnessPointsAndNormal)
196  .DEF_CLASS_FUNC(GJK, setDistanceEarlyBreak)
197  .DEF_CLASS_FUNC(GJK, getGuessFromSimplex);
198  }
199 }
coal::GJKConvergenceCriterion
GJKConvergenceCriterion
Which convergence criterion is used to stop the algorithm (when the shapes are not in collision)....
Definition: coal/data_types.h:104
MinkowskiDiffWrapper::support0
static void support0(MinkowskiDiff &self, const Vec3s &dir, int &hint, bool compute_swept_sphere_support=false)
Definition: gjk.cc:55
boost::python
exposeGJK
void exposeGJK()
Definition: gjk.cc:95
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal::Hybrid
@ Hybrid
Definition: coal/data_types.h:104
coal.hh
eigenpy.hpp
coal::details::MinkowskiDiff
Minkowski difference class of two shapes.
Definition: coal/narrowphase/minkowski_difference.h:53
coal::GJKConvergenceCriterionType
GJKConvergenceCriterionType
Wether the convergence criterion is scaled on the norm of the solution or not.
Definition: coal/data_types.h:108
coal::DefaultGuess
@ DefaultGuess
Definition: coal/data_types.h:95
eigenpy::register_symbolic_link_to_registered_type
bool register_symbolic_link_to_registered_type()
coal::details::EPA
class for EPA algorithm
Definition: coal/narrowphase/gjk.h:258
gjk.tf1
tuple tf1
Definition: test/scripts/gjk.py:27
coal::Relative
@ Relative
Definition: coal/data_types.h:108
distance
double distance(const std::vector< Transform3s > &tf, const BVHModel< BV > &m1, const BVHModel< BV > &m2, bool verbose)
Definition: benchmark.cpp:93
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
MinkowskiDiffWrapper::set
static void set(MinkowskiDiff &self, const ShapeBase *shape0, const ShapeBase *shape1, bool compute_swept_sphere_support=false)
Definition: gjk.cc:73
MinkowskiDiffWrapper::support1
static void support1(MinkowskiDiff &self, const Vec3s &dir, int &hint, bool compute_swept_sphere_support=false)
Definition: gjk.cc:64
coal::details::NoSweptSphere
@ NoSweptSphere
Definition: coal/narrowphase/support_functions.h:59
coal::CachedGuess
@ CachedGuess
Definition: coal/data_types.h:95
MinkowskiDiffWrapper::set
static void set(MinkowskiDiff &self, const ShapeBase *shape0, const ShapeBase *shape1, const Transform3s &tf0, const Transform3s &tf1, bool compute_swept_sphere_supports=false)
Definition: gjk.cc:83
coal::Default
@ Default
Definition: coal/data_types.h:104
coal::DefaultGJK
@ DefaultGJK
Definition: coal/data_types.h:98
coal::details::WithSweptSphere
@ WithSweptSphere
Definition: coal/narrowphase/support_functions.h:60
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
coal::NesterovAcceleration
@ NesterovAcceleration
Definition: coal/data_types.h:98
fwd.hh
coal::ShapeBase
Base class for all basic geometric shapes.
Definition: coal/shape/geometric_shapes.h:58
coal::PolyakAcceleration
@ PolyakAcceleration
Definition: coal/data_types.h:98
coal::BoundingVolumeGuess
@ BoundingVolumeGuess
Definition: coal/data_types.h:95
MinkowskiDiffWrapper
Definition: gjk.cc:54
coal::DualityGap
@ DualityGap
Definition: coal/data_types.h:104
coal::details::GJK
class for GJK algorithm
Definition: coal/narrowphase/gjk.h:53
gjk.h
coal::details::SupportOptions
SupportOptions
Options for the computation of support points. NoSweptSphere option is used when the support function...
Definition: coal/narrowphase/support_functions.h:58
doxygen::member_func_doc
const char * member_func_doc(FuncPtr)
Definition: doxygen.hh:33
coal::Absolute
@ Absolute
Definition: coal/data_types.h:108


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58