Debian Codegraph @

python/dartpy/constraint/ConstraintSolver.cpp

raw
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
36 namespace py = pybind11;
37
38 namespace dart {
39 namespace python {
40
41 void ConstraintSolver(py::module& m)
42 {
43 ::py::class_<
44 dart::constraint::ConstraintSolver,
45 std::shared_ptr<dart::constraint::ConstraintSolver>>(
46 m, "ConstraintSolver")
47 .def(
48 "addSkeleton",
49 +[](dart::constraint::ConstraintSolver* self,
50 const dart::dynamics::SkeletonPtr& skeleton) {
51 self->addSkeleton(skeleton);
52 },
53 ::py::arg("skeleton"))
54 .def(
55 "addSkeletons",
56 +[](dart::constraint::ConstraintSolver* self,
57 const std::vector<dart::dynamics::SkeletonPtr>& skeletons) {
58 self->addSkeletons(skeletons);
59 },
60 ::py::arg("skeletons"))
61 .def(
62 "removeSkeleton",
63 +[](dart::constraint::ConstraintSolver* self,
64 const dart::dynamics::SkeletonPtr& skeleton) {
65 self->removeSkeleton(skeleton);
66 },
67 ::py::arg("skeleton"))
68 .def(
69 "removeSkeletons",
70 +[](dart::constraint::ConstraintSolver* self,
71 const std::vector<dart::dynamics::SkeletonPtr>& skeletons) {
72 self->removeSkeletons(skeletons);
73 },
74 ::py::arg("skeletons"))
75 .def(
76 "removeAllSkeletons",
77 +[](dart::constraint::ConstraintSolver* self) {
78 self->removeAllSkeletons();
79 })
80 .def(
81 "addConstraint",
82 +[](dart::constraint::ConstraintSolver* self,
83 const dart::constraint::ConstraintBasePtr& constraint) {
84 self->addConstraint(constraint);
85 },
86 ::py::arg("constraint"))
87 .def(
88 "removeConstraint",
89 +[](dart::constraint::ConstraintSolver* self,
90 const dart::constraint::ConstraintBasePtr& constraint) {
91 self->removeConstraint(constraint);
92 },
93 ::py::arg("constraint"))
94 .def(
95 "removeAllConstraints",
96 +[](dart::constraint::ConstraintSolver* self) {
97 self->removeAllConstraints();
98 })
99 .def(
100 "getNumConstraints",
101 +[](const dart::constraint::ConstraintSolver* self) -> bool {
102 return self->getNumConstraints();
103 })
104 .def(
105 "getConstraint",
106 +[](dart::constraint::ConstraintSolver* self,
107 std::size_t index) -> constraint::ConstraintBasePtr {
108 return self->getConstraint(index);
109 },
110 ::py::arg("index"))
111 .def(
112 "getNumConstraints",
113 +[](const dart::constraint::ConstraintSolver* self) -> bool {
114 return self->getNumConstraints();
115 })
116 .def(
117 "getConstraint",
118 +[](dart::constraint::ConstraintSolver* self,
119 std::size_t index) -> constraint::ConstraintBasePtr {
120 return self->getConstraint(index);
121 },
122 ::py::arg("index"))
123 .def(
124 "clearLastCollisionResult",
125 +[](dart::constraint::ConstraintSolver* self) {
126 self->clearLastCollisionResult();
127 })
128 .def(
129 "setTimeStep",
130 +[](dart::constraint::ConstraintSolver* self, double _timeStep) {
131 self->setTimeStep(_timeStep);
132 },
133 ::py::arg("timeStep"))
134 .def(
135 "getTimeStep",
136 +[](const dart::constraint::ConstraintSolver* self) -> double {
137 return self->getTimeStep();
138 })
139 .def(
140 "setCollisionDetector",
141 +[](dart::constraint::ConstraintSolver* self,
142 const std::shared_ptr<dart::collision::CollisionDetector>&
143 collisionDetector) {
144 self->setCollisionDetector(collisionDetector);
145 },
146 ::py::arg("collisionDetector"))
147 .def(
148 "getCollisionDetector",
149 +[](dart::constraint::ConstraintSolver* self)
150 -> dart::collision::CollisionDetectorPtr {
151 return self->getCollisionDetector();
152 })
153 .def(
154 "getCollisionDetector",
155 +[](const dart::constraint::ConstraintSolver* self)
156 -> dart::collision::ConstCollisionDetectorPtr {
157 return self->getCollisionDetector();
158 })
159 .def(
160 "getCollisionGroup",
161 +[](dart::constraint::ConstraintSolver* self)
162 -> dart::collision::CollisionGroupPtr {
163 return self->getCollisionGroup();
164 })
165 .def(
166 "getCollisionGroup",
167 +[](const dart::constraint::ConstraintSolver* self)
168 -> dart::collision::ConstCollisionGroupPtr {
169 return self->getCollisionGroup();
170 })
171 .def(
172 "getCollisionOption",
173 +[](dart::constraint::ConstraintSolver* self)
174 -> dart::collision::CollisionOption& {
175 return self->getCollisionOption();
176 },
177 "Returns collision option that is used for collision checkings in "
178 "this ConstraintSolver to generate contact constraints.")
179 .def(
180 "getCollisionOption",
181 +[](const dart::constraint::ConstraintSolver* self)
182 -> const dart::collision::CollisionOption& {
183 return self->getCollisionOption();
184 },
185 "Returns collision option that is used for collision checkings in "
186 "this ConstraintSolver to generate contact constraints.")
187 .def(
188 "solve",
189 +[](dart::constraint::ConstraintSolver* self) { self->solve(); });
190 }
191
192 } // namespace python
193 } // namespace dart