collision.cc
Go to the documentation of this file.
1 //
2 // Software License Agreement (BSD License)
3 //
4 // Copyright (c) 2019-2021 CNRS-LAAS, INRIA
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/fwd.hh"
40 #include "coal/collision.h"
43 
44 #include "coal.hh"
45 #include "deprecation.hh"
46 #include "serializable.hh"
47 
48 #ifdef COAL_HAS_DOXYGEN_AUTODOC
49 #include "doxygen_autodoc/functions.h"
50 #include "doxygen_autodoc/coal/collision_data.h"
51 #endif
52 
53 #include "../doc/python/doxygen.hh"
54 #include "../doc/python/doxygen-boost.hh"
55 
56 using namespace boost::python;
57 using namespace coal;
58 using namespace coal::python;
59 
60 namespace dv = doxygen::visitor;
61 
62 template <int index>
63 const CollisionGeometry* geto(const Contact& c) {
64  return index == 1 ? c.o1 : c.o2;
65 }
66 
68  static Vec3s getNearestPoint1(const Contact& contact) {
69  return contact.nearest_points[0];
70  }
71  static Vec3s getNearestPoint2(const Contact& contact) {
72  return contact.nearest_points[1];
73  }
74 };
75 
79  enum_<CollisionRequestFlag>("CollisionRequestFlag")
80  .value("CONTACT", CONTACT)
81  .value("DISTANCE_LOWER_BOUND", DISTANCE_LOWER_BOUND)
82  .value("NO_REQUEST", NO_REQUEST)
83  .export_values();
84  }
85 
86  if (!eigenpy::register_symbolic_link_to_registered_type<CPUTimes>()) {
87  class_<CPUTimes>("CPUTimes", no_init)
88  .def_readonly("wall", &CPUTimes::wall,
89  "wall time in micro seconds (us)")
90  .def_readonly("user", &CPUTimes::user,
91  "user time in micro seconds (us)")
92  .def_readonly("system", &CPUTimes::system,
93  "system time in micro seconds (us)")
94  .def("clear", &CPUTimes::clear, arg("self"), "Reset the time values.");
95  }
96 
99  if (!eigenpy::register_symbolic_link_to_registered_type<QueryRequest>()) {
100  class_<QueryRequest>("QueryRequest", doxygen::class_doc<QueryRequest>(),
101  no_init)
102  .DEF_RW_CLASS_ATTRIB(QueryRequest, gjk_tolerance)
103  .DEF_RW_CLASS_ATTRIB(QueryRequest, gjk_max_iterations)
104  .DEF_RW_CLASS_ATTRIB(QueryRequest, gjk_variant)
105  .DEF_RW_CLASS_ATTRIB(QueryRequest, gjk_convergence_criterion)
106  .DEF_RW_CLASS_ATTRIB(QueryRequest, gjk_convergence_criterion_type)
107  .DEF_RW_CLASS_ATTRIB(QueryRequest, gjk_initial_guess)
108  .DEF_RW_CLASS_ATTRIB(QueryRequest, enable_cached_gjk_guess)
109  .add_property(
110  "enable_cached_gjk_guess",
111  bp::make_function(
112  +[](QueryRequest& self) -> bool {
113  return self.enable_cached_gjk_guess;
114  },
116  "enable_cached_gjk_guess has been marked as deprecated and "
117  "will be removed in a future release.\n"
118  "Please use gjk_initial_guess instead.")),
119  bp::make_function(
120  +[](QueryRequest& self, const bool value) -> void {
121  self.enable_cached_gjk_guess = value;
122  },
124  "enable_cached_gjk_guess has been marked as deprecated and "
125  "will be removed in a future release.\n"
126  "Please use gjk_initial_guess instead.")),
127  doxygen::class_attrib_doc<QueryRequest>("enable_cached_gjk_guess"))
128  .DEF_RW_CLASS_ATTRIB(QueryRequest, cached_gjk_guess)
129  .DEF_RW_CLASS_ATTRIB(QueryRequest, cached_support_func_guess)
130  .DEF_RW_CLASS_ATTRIB(QueryRequest, epa_max_iterations)
131  .DEF_RW_CLASS_ATTRIB(QueryRequest, epa_tolerance)
132  .DEF_RW_CLASS_ATTRIB(QueryRequest, enable_timings)
133  .DEF_CLASS_FUNC(QueryRequest, updateGuess);
134  }
136 
139  if (!eigenpy::register_symbolic_link_to_registered_type<CollisionRequest>()) {
140  class_<CollisionRequest, bases<QueryRequest> >(
141  "CollisionRequest", doxygen::class_doc<CollisionRequest>(), no_init)
142  .def(dv::init<CollisionRequest>())
143  .def(dv::init<CollisionRequest, const CollisionRequestFlag, size_t>())
145  .DEF_RW_CLASS_ATTRIB(CollisionRequest, enable_contact)
146  .add_property(
147  "enable_distance_lower_bound",
148  bp::make_function(
149  +[](CollisionRequest& self) -> bool {
150  return self.enable_distance_lower_bound;
151  },
153  "enable_distance_lower_bound has been marked as "
154  "deprecated. "
155  "A lower bound on distance is always computed.\n")),
156  bp::make_function(
157  +[](CollisionRequest& self, const bool value) -> void {
158  self.enable_distance_lower_bound = value;
159  },
161  "enable_distance_lower_bound has been marked as "
162  "deprecated. "
163  "A lower bound on distance is always computed.\n")),
164  doxygen::class_attrib_doc<CollisionRequest>(
165  "enable_distance_lower_bound"))
166  .DEF_RW_CLASS_ATTRIB(CollisionRequest, security_margin)
167  .DEF_RW_CLASS_ATTRIB(CollisionRequest, break_distance)
168  .DEF_RW_CLASS_ATTRIB(CollisionRequest, distance_upper_bound)
170  }
171 
173  std::vector<CollisionRequest> >()) {
174  class_<std::vector<CollisionRequest> >("StdVec_CollisionRequest")
175  .def(vector_indexing_suite<std::vector<CollisionRequest> >());
176  }
178 
179  if (!eigenpy::register_symbolic_link_to_registered_type<Contact>()) {
180  class_<Contact>("Contact", doxygen::class_doc<Contact>(),
181  init<>(arg("self"), "Default constructor"))
182  .def(dv::init<Contact, const CollisionGeometry*,
183  const CollisionGeometry*, int, int>())
184  .def(dv::init<Contact, const CollisionGeometry*,
185  const CollisionGeometry*, int, int, const Vec3s&,
186  const Vec3s&, CoalScalar>())
187  .add_property(
188  "o1",
189  make_function(&geto<1>,
190  return_value_policy<reference_existing_object>()),
191  doxygen::class_attrib_doc<Contact>("o1"))
192  .add_property(
193  "o2",
194  make_function(&geto<2>,
195  return_value_policy<reference_existing_object>()),
196  doxygen::class_attrib_doc<Contact>("o2"))
197  .def("getNearestPoint1", &ContactWrapper::getNearestPoint1,
198  doxygen::class_attrib_doc<Contact>("nearest_points"))
199  .def("getNearestPoint2", &ContactWrapper::getNearestPoint2,
200  doxygen::class_attrib_doc<Contact>("nearest_points"))
201  .DEF_RW_CLASS_ATTRIB(Contact, b1)
202  .DEF_RW_CLASS_ATTRIB(Contact, b2)
203  .DEF_RW_CLASS_ATTRIB(Contact, normal)
204  .DEF_RW_CLASS_ATTRIB(Contact, nearest_points)
205  .DEF_RW_CLASS_ATTRIB(Contact, pos)
206  .DEF_RW_CLASS_ATTRIB(Contact, penetration_depth)
207  .def(self == self)
208  .def(self != self);
209  }
210 
212  std::vector<Contact> >()) {
213  class_<std::vector<Contact> >("StdVec_Contact")
214  .def(vector_indexing_suite<std::vector<Contact> >());
215  }
216 
217  if (!eigenpy::register_symbolic_link_to_registered_type<QueryResult>()) {
218  class_<QueryResult>("QueryResult", doxygen::class_doc<QueryResult>(),
219  no_init)
220  .DEF_RW_CLASS_ATTRIB(QueryResult, cached_gjk_guess)
221  .DEF_RW_CLASS_ATTRIB(QueryResult, cached_support_func_guess)
222  .DEF_RW_CLASS_ATTRIB(QueryResult, timings);
223  }
224 
225  if (!eigenpy::register_symbolic_link_to_registered_type<CollisionResult>()) {
226  class_<CollisionResult, bases<QueryResult> >(
227  "CollisionResult", doxygen::class_doc<CollisionResult>(), no_init)
228  .def(dv::init<CollisionResult>())
229  .DEF_CLASS_FUNC(CollisionResult, isCollision)
230  .DEF_CLASS_FUNC(CollisionResult, numContacts)
231  .DEF_CLASS_FUNC(CollisionResult, addContact)
232  .DEF_CLASS_FUNC(CollisionResult, clear)
233  .DEF_CLASS_FUNC2(CollisionResult, getContact,
234  return_value_policy<copy_const_reference>())
236  "getContacts",
237  static_cast<void (CollisionResult::*)(std::vector<Contact>&) const>(
238  &CollisionResult::getContacts)))
239  .def("getContacts",
240  static_cast<const std::vector<Contact>& (CollisionResult::*)()
241  const>(&CollisionResult::getContacts),
243  static_cast<const std::vector<Contact>& (CollisionResult::*)()
244  const>(&CollisionResult::getContacts)),
245  return_internal_reference<>())
246 
249  }
250 
252  std::vector<CollisionResult> >()) {
253  class_<std::vector<CollisionResult> >("StdVec_CollisionResult")
254  .def(vector_indexing_suite<std::vector<CollisionResult> >());
255  }
256 
257  doxygen::def("collide",
258  static_cast<std::size_t (*)(
259  const CollisionObject*, const CollisionObject*,
261  doxygen::def(
262  "collide",
263  static_cast<std::size_t (*)(const CollisionGeometry*, const Transform3s&,
264  const CollisionGeometry*, const Transform3s&,
266  &collide));
267 
268  class_<ComputeCollision>("ComputeCollision",
269  doxygen::class_doc<ComputeCollision>(), no_init)
270  .def(dv::init<ComputeCollision, const CollisionGeometry*,
271  const CollisionGeometry*>())
272  .def("__call__",
273  static_cast<std::size_t (ComputeCollision::*)(
274  const Transform3s&, const Transform3s&, const CollisionRequest&,
275  CollisionResult&) const>(&ComputeCollision::operator()));
276 }
collision.h
coal::CONTACT
@ CONTACT
Definition: coal/collision_data.h:305
boost::python
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal.hh
eigenpy.hpp
COAL_COMPILER_DIAGNOSTIC_PUSH
#define COAL_COMPILER_DIAGNOSTIC_PUSH
Definition: include/coal/fwd.hh:120
doxygen_xml_parser.index
index
Definition: doxygen_xml_parser.py:889
eigenpy::register_symbolic_link_to_registered_type
bool register_symbolic_link_to_registered_type()
coal::QueryResult
base class for all query results
Definition: coal/collision_data.h:275
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
ContactWrapper
Definition: collision.cc:67
doxygen::visitor
Definition: doxygen-boost.hh:12
doxygen::def
void def(const char *name, Func func)
Definition: doxygen-boost.hh:106
coal::NO_REQUEST
@ NO_REQUEST
Definition: coal/collision_data.h:307
coal::python::SerializableVisitor
Definition: serializable.hh:23
coal::CollisionGeometry
The geometry for the object for collision or distance computation.
Definition: coal/collision_object.h:94
DEF_RW_CLASS_ATTRIB
#define DEF_RW_CLASS_ATTRIB(CLASS, ATTRIB)
Definition: python/fwd.hh:29
coal::DISTANCE_LOWER_BOUND
@ DISTANCE_LOWER_BOUND
Definition: coal/collision_data.h:306
serializable.hh
distance_lower_bound
Definition: distance_lower_bound.py:1
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
exposeCollisionAPI
void exposeCollisionAPI()
Definition: collision.cc:76
DEF_CLASS_FUNC
#define DEF_CLASS_FUNC(CLASS, ATTRIB)
Definition: python/fwd.hh:35
c
c
coal::Contact::nearest_points
std::array< Vec3s, 2 > nearest_points
nearest points associated to this contact.
Definition: coal/collision_data.h:99
coal::python
Definition: python/broadphase/fwd.hh:11
fwd.hh
coal::CollisionResult
collision result
Definition: coal/collision_data.h:390
doxygen::visitor::member_func
member_func_impl< function_type > member_func(const char *name, const function_type &function)
Definition: doxygen-boost.hh:49
deprecation.hh
coal::CollisionRequest
request to the collision algorithm
Definition: coal/collision_data.h:311
value
float value
coal::CollisionObject
the object for collision or distance computation, contains the geometry and the transform information
Definition: coal/collision_object.h:214
octree.pos
pos
Definition: octree.py:7
coal::Contact
Contact information returned by collision.
Definition: coal/collision_data.h:58
coal::QueryRequest
base class for all query requests
Definition: coal/collision_data.h:170
coal::python::deprecated_warning_policy
Definition: deprecation.hh:16
collision_data.h
ContactWrapper::getNearestPoint1
static Vec3s getNearestPoint1(const Contact &contact)
Definition: collision.cc:68
geto
const CollisionGeometry * geto(const Contact &c)
Definition: collision.cc:63
COAL_COMPILER_DIAGNOSTIC_POP
#define COAL_COMPILER_DIAGNOSTIC_POP
Definition: include/coal/fwd.hh:121
COAL_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
#define COAL_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
Definition: include/coal/fwd.hh:122
num_max_contacts
int num_max_contacts
Definition: test/collision.cpp:73
coal::CollisionRequestFlag
CollisionRequestFlag
flag declaration for specifying required params in CollisionResult
Definition: coal/collision_data.h:304
coal::collide
COAL_DLLAPI std::size_t collide(const CollisionObject *o1, const CollisionObject *o2, const CollisionRequest &request, CollisionResult &result)
Main collision interface: given two collision objects, and the requirements for contacts,...
Definition: src/collision.cpp:61
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
ContactWrapper::getNearestPoint2
static Vec3s getNearestPoint2(const Contact &contact)
Definition: collision.cc:71
coal::ComputeCollision
This class reduces the cost of identifying the geometry pair. This is mostly useful for repeated shap...
Definition: coal/collision.h:78
doxygen::member_func_doc
const char * member_func_doc(FuncPtr)
Definition: doxygen.hh:33


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