Debian Codegraph @

python/dartpy/simulation/World.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 <dart/simulation/World.hpp>
35 #include <pybind11/eigen.h>
36 #include <pybind11/pybind11.h>
37
38 namespace py = pybind11;
39
40 namespace dart {
41 namespace python {
42
43 void World(py::module& m)
44 {
45 ::py::class_<
46 dart::simulation::World,
47 std::shared_ptr<dart::simulation::World>>(m, "World")
48 .def(::py::init<>())
49 .def(::py::init<const std::string&>(), ::py::arg("name"))
50 .def(::py::init(+[]() -> dart::simulation::WorldPtr {
51 return dart::simulation::World::create();
52 }))
53 .def(
54 ::py::init(
55 +[](const std::string& name) -> dart::simulation::WorldPtr {
56 return dart::simulation::World::create(name);
57 }),
58 ::py::arg("name"))
59 .def(
60 "clone",
61 +[](const dart::simulation::World* self)
62 -> std::shared_ptr<dart::simulation::World> {
63 return self->clone();
64 })
65 .def(
66 "setName",
67 +[](dart::simulation::World* self, const std::string& _newName)
68 -> const std::string& { return self->setName(_newName); },
69 ::py::return_value_policy::reference_internal,
70 ::py::arg("newName"))
71 .def(
72 "getName",
73 +[](const dart::simulation::World* self) -> const std::string& {
74 return self->getName();
75 },
76 ::py::return_value_policy::reference_internal)
77 .def(
78 "setGravity",
79 ::py::overload_cast<const Eigen::Vector3d&>(
80 &dart::simulation::World::setGravity),
81 ::py::arg("gravity"))
82 .def(
83 "setGravity",
84 ::py::overload_cast<double, double, double>(
85 &dart::simulation::World::setGravity),
86 ::py::arg("x"),
87 ::py::arg("y"),
88 ::py::arg("z"))
89 .def(
90 "getGravity",
91 +[](const dart::simulation::World* self) -> const Eigen::Vector3d& {
92 return self->getGravity();
93 },
94 ::py::return_value_policy::reference_internal)
95 .def(
96 "setTimeStep",
97 +[](dart::simulation::World* self, double _timeStep) -> void {
98 return self->setTimeStep(_timeStep);
99 },
100 ::py::arg("timeStep"))
101 .def(
102 "getTimeStep",
103 +[](const dart::simulation::World* self) -> double {
104 return self->getTimeStep();
105 })
106 .def(
107 "getSkeleton",
108 +[](const dart::simulation::World* self,
109 std::size_t _index) -> dart::dynamics::SkeletonPtr {
110 return self->getSkeleton(_index);
111 },
112 ::py::arg("index"))
113 .def(
114 "getSkeleton",
115 +[](const dart::simulation::World* self,
116 const std::string& _name) -> dart::dynamics::SkeletonPtr {
117 return self->getSkeleton(_name);
118 },
119 ::py::arg("name"))
120 .def(
121 "getNumSkeletons",
122 +[](const dart::simulation::World* self) -> std::size_t {
123 return self->getNumSkeletons();
124 })
125 .def(
126 "addSkeleton",
127 +[](dart::simulation::World* self,
128 const dart::dynamics::SkeletonPtr& _skeleton) -> std::string {
129 return self->addSkeleton(_skeleton);
130 },
131 ::py::arg("skeleton"))
132 .def(
133 "removeSkeleton",
134 +[](dart::simulation::World* self,
135 const dart::dynamics::SkeletonPtr& _skeleton) -> void {
136 return self->removeSkeleton(_skeleton);
137 },
138 ::py::arg("skeleton"))
139 .def(
140 "removeAllSkeletons",
141 +[](dart::simulation::World* self)
142 -> std::set<dart::dynamics::SkeletonPtr> {
143 return self->removeAllSkeletons();
144 })
145 .def(
146 "hasSkeleton",
147 +[](const dart::simulation::World* self,
148 const dart::dynamics::ConstSkeletonPtr& skeleton) -> bool {
149 return self->hasSkeleton(skeleton);
150 },
151 ::py::arg("skeleton"))
152 .def(
153 "getIndex",
154 +[](const dart::simulation::World* self, int _index) -> int {
155 return self->getIndex(_index);
156 },
157 ::py::arg("index"))
158 .def(
159 "getSimpleFrame",
160 +[](const dart::simulation::World* self,
161 std::size_t _index) -> dart::dynamics::SimpleFramePtr {
162 return self->getSimpleFrame(_index);
163 },
164 ::py::arg("index"))
165 .def(
166 "getSimpleFrame",
167 +[](const dart::simulation::World* self,
168 const std::string& _name) -> dart::dynamics::SimpleFramePtr {
169 return self->getSimpleFrame(_name);
170 },
171 ::py::arg("name"))
172 .def(
173 "getNumSimpleFrames",
174 +[](const dart::simulation::World* self) -> std::size_t {
175 return self->getNumSimpleFrames();
176 })
177 .def(
178 "addSimpleFrame",
179 +[](dart::simulation::World* self,
180 const dart::dynamics::SimpleFramePtr& _frame) -> std::string {
181 return self->addSimpleFrame(_frame);
182 },
183 ::py::arg("frame"))
184 .def(
185 "removeSimpleFrame",
186 +[](dart::simulation::World* self,
187 const dart::dynamics::SimpleFramePtr& _frame) -> void {
188 return self->removeSimpleFrame(_frame);
189 },
190 ::py::arg("frame"))
191 .def(
192 "removeAllSimpleFrames",
193 +[](dart::simulation::World* self)
194 -> std::set<dart::dynamics::SimpleFramePtr> {
195 return self->removeAllSimpleFrames();
196 })
197 .def(
198 "checkCollision",
199 +[](dart::simulation::World* self) -> bool {
200 return self->checkCollision();
201 })
202 .def(
203 "checkCollision",
204 +[](dart::simulation::World* self,
205 const dart::collision::CollisionOption& option) -> bool {
206 return self->checkCollision(option);
207 },
208 ::py::arg("option"))
209 .def(
210 "checkCollision",
211 +[](dart::simulation::World* self,
212 const dart::collision::CollisionOption& option,
213 dart::collision::CollisionResult* result) -> bool {
214 return self->checkCollision(option, result);
215 },
216 ::py::arg("option"),
217 ::py::arg("result"))
218 .def(
219 "getLastCollisionResult",
220 +[](dart::simulation::World* self)
221 -> const collision::CollisionResult& {
222 return self->getLastCollisionResult();
223 })
224 .def(
225 "reset",
226 +[](dart::simulation::World* self) -> void { return self->reset(); })
227 .def(
228 "step",
229 +[](dart::simulation::World* self) -> void { return self->step(); })
230 .def(
231 "step",
232 +[](dart::simulation::World* self, bool _resetCommand) -> void {
233 return self->step(_resetCommand);
234 },
235 ::py::arg("resetCommand"))
236 .def(
237 "setTime",
238 +[](dart::simulation::World* self, double _time) -> void {
239 return self->setTime(_time);
240 },
241 ::py::arg("time"))
242 .def(
243 "getTime",
244 +[](const dart::simulation::World* self) -> double {
245 return self->getTime();
246 })
247 .def(
248 "getSimFrames",
249 +[](const dart::simulation::World* self) -> int {
250 return self->getSimFrames();
251 })
252 .def(
253 "getConstraintSolver",
254 +[](dart::simulation::World* self) -> constraint::ConstraintSolver* {
255 return self->getConstraintSolver();
256 },
257 ::py::return_value_policy::reference_internal)
258 .def(
259 "bake",
260 +[](dart::simulation::World* self) -> void { return self->bake(); })
261 .def_readonly("onNameChanged", &dart::simulation::World::onNameChanged);
262 }
263
264 } // namespace python
265 } // namespace dart