| 1 |
/* |
| 2 |
* Copyright (c) 2011-2022, 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/pybind11.h> |
| 35 |
#include <pybind11/stl.h> |
| 36 |
|
| 37 |
namespace py = pybind11; |
| 38 |
|
| 39 |
namespace dart { |
| 40 |
namespace python { |
| 41 |
|
| 42 |
void CollisionResult(py::module& m) |
| 43 |
{ |
| 44 |
::py::class_<dart::collision::CollisionResult>(m, "CollisionResult") |
| 45 |
.def(::py::init<>()) |
| 46 |
.def( |
| 47 |
"addContact", |
| 48 |
+[](dart::collision::CollisionResult* self, |
| 49 |
const dart::collision::Contact& contact) { |
| 50 |
self->addContact(contact); |
| 51 |
}, |
| 52 |
::py::arg("contact"), |
| 53 |
"Add one contact.") |
| 54 |
.def( |
| 55 |
"getNumContacts", |
| 56 |
+[](const dart::collision::CollisionResult* self) -> std::size_t { |
| 57 |
return self->getNumContacts(); |
| 58 |
}, |
| 59 |
"Return number of contacts.") |
| 60 |
.def( |
| 61 |
"getContact", |
| 62 |
+[](dart::collision::CollisionResult* self, std::size_t index) |
| 63 |
-> dart::collision::Contact& { return self->getContact(index); }, |
| 64 |
::py::arg("index"), |
| 65 |
::py::return_value_policy::reference, |
| 66 |
"Return the index-th contact.") |
| 67 |
.def( |
| 68 |
"getContact", |
| 69 |
+[](const dart::collision::CollisionResult* self, |
| 70 |
std::size_t index) -> const dart::collision::Contact& { |
| 71 |
return self->getContact(index); |
| 72 |
}, |
| 73 |
::py::arg("index"), |
| 74 |
::py::return_value_policy::reference, |
| 75 |
"Return (const) the index-th contact.") |
| 76 |
.def( |
| 77 |
"getContacts", |
| 78 |
+[](const dart::collision::CollisionResult* self) |
| 79 |
-> const std::vector<dart::collision::Contact>& { |
| 80 |
return self->getContacts(); |
| 81 |
}, |
| 82 |
::py::return_value_policy::reference, |
| 83 |
"Return contacts.") |
| 84 |
.def( |
| 85 |
"getCollidingBodyNodes", |
| 86 |
+[](const dart::collision::CollisionResult* self) |
| 87 |
-> const std::unordered_set<const dynamics::BodyNode*>& { |
| 88 |
return self->getCollidingBodyNodes(); |
| 89 |
}, |
| 90 |
::py::return_value_policy::reference, |
| 91 |
"Return the set of BodyNodes that are in collision.") |
| 92 |
.def( |
| 93 |
"getCollidingShapeFrames", |
| 94 |
+[](const dart::collision::CollisionResult* self) |
| 95 |
-> const std::unordered_set<const dynamics::ShapeFrame*>& { |
| 96 |
return self->getCollidingShapeFrames(); |
| 97 |
}, |
| 98 |
::py::return_value_policy::reference, |
| 99 |
"Return the set of ShapeFrames that are in collision.") |
| 100 |
.def( |
| 101 |
"inCollision", |
| 102 |
+[](const dart::collision::CollisionResult* self, |
| 103 |
const dart::dynamics::BodyNode* bn) -> bool { |
| 104 |
return self->inCollision(bn); |
| 105 |
}, |
| 106 |
::py::arg("bn"), |
| 107 |
"Returns true if the given BodyNode is in collision.") |
| 108 |
.def( |
| 109 |
"inCollision", |
| 110 |
+[](const dart::collision::CollisionResult* self, |
| 111 |
const dart::dynamics::ShapeFrame* frame) -> bool { |
| 112 |
return self->inCollision(frame); |
| 113 |
}, |
| 114 |
::py::arg("frame"), |
| 115 |
"Returns true if the given ShapeFrame is in collision.") |
| 116 |
.def( |
| 117 |
"isCollision", |
| 118 |
+[](const dart::collision::CollisionResult* self) -> bool { |
| 119 |
return self->isCollision(); |
| 120 |
}, |
| 121 |
"Return binary collision result.") |
| 122 |
.def( |
| 123 |
"clear", |
| 124 |
+[](dart::collision::CollisionResult* self) { self->clear(); }, |
| 125 |
"Clear all the contacts."); |
| 126 |
} |
| 127 |
|
| 128 |
} // namespace python |
| 129 |
} // namespace dart |