1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  *   https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  *   Redistribution and use in source and binary forms, with or
10  *   without modification, are permitted provided that the following
11  *   conditions are met:
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  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  *   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  *   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  *   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  *   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  *   AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  *   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  *   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  *   POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <dart/dart.hpp>
34 #include <pybind11/eigen.h>
35 #include <pybind11/pybind11.h>
36 
37 namespace py = pybind11;
38 
39 namespace dart {
40 namespace python {
41 
CollisionGroup(py::module & m)42 void CollisionGroup(py::module& m)
43 {
44   ::py::class_<
45       dart::collision::CollisionGroup,
46       std::shared_ptr<dart::collision::CollisionGroup> >(m, "CollisionGroup")
47       .def(
48           "getCollisionDetector",
49           +[](dart::collision::CollisionGroup* self)
50               -> dart::collision::CollisionDetectorPtr {
51             return self->getCollisionDetector();
52           })
53       .def(
54           "getCollisionDetector",
55           +[](const dart::collision::CollisionGroup* self)
56               -> dart::collision::ConstCollisionDetectorPtr {
57             return self->getCollisionDetector();
58           })
59       .def(
60           "addShapeFrame",
61           +[](dart::collision::CollisionGroup* self,
62               const dart::dynamics::ShapeFrame* shapeFrame) {
63             self->addShapeFrame(shapeFrame);
64           },
65           ::py::arg("shapeFrame"))
66       .def(
67           "addShapeFrames",
68           +[](dart::collision::CollisionGroup* self,
69               const std::vector<const dart::dynamics::ShapeFrame*>&
70                   shapeFrames) { self->addShapeFrames(shapeFrames); },
71           ::py::arg("shapeFrames"))
72       .def(
73           "addShapeFramesOf",
74           +[](dart::collision::CollisionGroup* self,
75               const dynamics::ShapeFrame* shapeFrame) {
76             self->addShapeFramesOf(shapeFrame);
77           },
78           ::py::arg("shapeFrame"),
79           "Adds a ShapeFrame")
80       .def(
81           "addShapeFramesOf",
82           +[](dart::collision::CollisionGroup* self,
83               const std::vector<const dart::dynamics::ShapeFrame*>&
84                   shapeFrames) { self->addShapeFramesOf(shapeFrames); },
85           ::py::arg("shapeFrames"),
86           "Adds ShapeFrames")
87       .def(
88           "addShapeFramesOf",
89           +[](dart::collision::CollisionGroup* self,
90               const dart::collision::CollisionGroup* otherGroup) {
91             self->addShapeFramesOf(otherGroup);
92           },
93           ::py::arg("otherGroup"),
94           "Adds ShapeFrames of other CollisionGroup")
95       .def(
96           "addShapeFramesOf",
97           +[](dart::collision::CollisionGroup* self,
98               const dart::dynamics::BodyNode* body) {
99             self->addShapeFramesOf(body);
100           },
101           ::py::arg("body"),
102           "Adds ShapeFrames of BodyNode")
103       .def(
104           "addShapeFramesOf",
105           +[](dart::collision::CollisionGroup* self,
106               const dart::dynamics::MetaSkeleton* skeleton) {
107             self->addShapeFramesOf(skeleton);
108           },
109           ::py::arg("skeleton"),
110           "Adds ShapeFrames of MetaSkeleton")
111       .def(
112           "subscribeTo",
113           +[](dart::collision::CollisionGroup* self) { self->subscribeTo(); })
114       .def(
115           "removeShapeFrame",
116           +[](dart::collision::CollisionGroup* self,
117               const dart::dynamics::ShapeFrame* shapeFrame) {
118             self->removeShapeFrame(shapeFrame);
119           },
120           ::py::arg("shapeFrame"))
121       .def(
122           "removeShapeFrames",
123           +[](dart::collision::CollisionGroup* self,
124               const std::vector<const dart::dynamics::ShapeFrame*>&
125                   shapeFrames) { self->removeShapeFrames(shapeFrames); },
126           ::py::arg("shapeFrames"))
127       .def(
128           "removeShapeFramesOf",
129           +[](dart::collision::CollisionGroup* self,
130               const dynamics::ShapeFrame* shapeFrame) {
131             self->removeShapeFramesOf(shapeFrame);
132           },
133           ::py::arg("shapeFrame"),
134           "Removes a ShapeFrame")
135       .def(
136           "removeShapeFramesOf",
137           +[](dart::collision::CollisionGroup* self,
138               const std::vector<const dart::dynamics::ShapeFrame*>&
139                   shapeFrames) { self->removeShapeFramesOf(shapeFrames); },
140           ::py::arg("shapeFrames"),
141           "Removes ShapeFrames")
142       .def(
143           "removeShapeFramesOf",
144           +[](dart::collision::CollisionGroup* self,
145               const dart::collision::CollisionGroup* otherGroup) {
146             self->removeShapeFramesOf(otherGroup);
147           },
148           ::py::arg("otherGroup"),
149           "Removes ShapeFrames of other CollisionGroup")
150       .def(
151           "removeShapeFramesOf",
152           +[](dart::collision::CollisionGroup* self,
153               const dart::dynamics::BodyNode* body) {
154             self->removeShapeFramesOf(body);
155           },
156           ::py::arg("body"),
157           "Removes ShapeFrames of BodyNode")
158       .def(
159           "removeShapeFramesOf",
160           +[](dart::collision::CollisionGroup* self,
161               const dart::dynamics::MetaSkeleton* skeleton) {
162             self->removeShapeFramesOf(skeleton);
163           },
164           ::py::arg("skeleton"),
165           "Removes ShapeFrames of MetaSkeleton")
166       .def(
167           "removeAllShapeFrames",
168           +[](dart::collision::CollisionGroup* self) {
169             self->removeAllShapeFrames();
170           })
171       .def(
172           "hasShapeFrame",
173           +[](const dart::collision::CollisionGroup* self,
174               const dart::dynamics::ShapeFrame* shapeFrame) -> bool {
175             return self->hasShapeFrame(shapeFrame);
176           },
177           ::py::arg("shapeFrame"))
178       .def(
179           "getNumShapeFrames",
180           +[](const dart::collision::CollisionGroup* self) -> std::size_t {
181             return self->getNumShapeFrames();
182           })
183       .def(
184           "collide",
185           +[](dart::collision::CollisionGroup* self,
186               const dart::collision::CollisionOption& option,
187               dart::collision::CollisionResult* result) -> bool {
188             return self->collide(option, result);
189           },
190           ::py::arg("option")
191           = dart::collision::CollisionOption(false, 1u, nullptr),
192           ::py::arg("result") = nullptr,
193           "Performs collision check within this CollisionGroup")
194       .def(
195           "collide",
196           +[](dart::collision::CollisionGroup* self,
197               dart::collision::CollisionGroup* otherGroup,
198               const dart::collision::CollisionOption& option,
199               dart::collision::CollisionResult* result) -> bool {
200             return self->collide(otherGroup, option, result);
201           },
202           ::py::arg("otherGroup"),
203           ::py::arg("option")
204           = dart::collision::CollisionOption(false, 1u, nullptr),
205           ::py::arg("result") = nullptr,
206           "Perform collision check against other CollisionGroup")
207       .def(
208           "distance",
209           +[](dart::collision::CollisionGroup* self,
210               const dart::collision::DistanceOption& option,
211               dart::collision::DistanceResult* result) -> double {
212             return self->distance(option, result);
213           },
214           ::py::arg("option")
215           = dart::collision::DistanceOption(false, 0.0, nullptr),
216           ::py::arg("result") = nullptr)
217       .def(
218           "raycast",
219           +[](dart::collision::CollisionGroup* self,
220               const Eigen::Vector3d& from,
221               const Eigen::Vector3d& to) -> bool {
222             return self->raycast(from, to);
223           },
224           ::py::arg("from"),
225           ::py::arg("to"))
226       .def(
227           "raycast",
228           +[](dart::collision::CollisionGroup* self,
229               const Eigen::Vector3d& from,
230               const Eigen::Vector3d& to,
231               const dart::collision::RaycastOption& option) -> bool {
232             return self->raycast(from, to, option);
233           },
234           ::py::arg("from"),
235           ::py::arg("to"),
236           ::py::arg("option"))
237       .def(
238           "raycast",
239           +[](dart::collision::CollisionGroup* self,
240               const Eigen::Vector3d& from,
241               const Eigen::Vector3d& to,
242               const dart::collision::RaycastOption& option,
243               dart::collision::RaycastResult* result) -> bool {
244             return self->raycast(from, to, option, result);
245           },
246           ::py::arg("from"),
247           ::py::arg("to"),
248           ::py::arg("option"),
249           ::py::arg("result"))
250       .def(
251           "setAutomaticUpdate",
252           +[](dart::collision::CollisionGroup* self) {
253             self->setAutomaticUpdate();
254           })
255       .def(
256           "setAutomaticUpdate",
257           +[](dart::collision::CollisionGroup* self, bool automatic) {
258             self->setAutomaticUpdate(automatic);
259           },
260           ::py::arg("automatic"))
261       .def(
262           "getAutomaticUpdate",
263           +[](const dart::collision::CollisionGroup* self) -> bool {
264             return self->getAutomaticUpdate();
265           })
266       .def(
267           "update",
268           +[](dart::collision::CollisionGroup* self) { self->update(); })
269       .def(
270           "removeDeletedShapeFrames",
271           +[](dart::collision::CollisionGroup* self) {
272             self->removeDeletedShapeFrames();
273           });
274 }
275 
276 } // namespace python
277 } // namespace dart
278