Debian Codegraph @

python/dartpy/dynamics/Shape.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 #include <pybind11/stl.h>
36
37 #include "eigen_geometry_pybind.h"
38 #include "eigen_pybind.h"
39
40 namespace py = pybind11;
41
42 namespace dart {
43 namespace python {
44
45 void Shape(py::module& m)
46 {
47 auto shape
48 = ::py::class_<
49 dart::dynamics::Shape,
50 dart::common::Subject,
51 std::shared_ptr<dart::dynamics::Shape>>(m, "Shape")
52 .def(
53 "getType",
54 +[](const dart::dynamics::Shape* self) -> const std::string& {
55 return self->getType();
56 },
57 ::py::return_value_policy::reference_internal)
58 .def(
59 "getBoundingBox",
60 +[](const dart::dynamics::Shape* self)
61 -> const dart::math::BoundingBox& {
62 return self->getBoundingBox();
63 },
64 ::py::return_value_policy::reference_internal)
65 .def(
66 "computeInertia",
67 +[](const dart::dynamics::Shape* self, double mass)
68 -> Eigen::Matrix3d { return self->computeInertia(mass); },
69 ::py::arg("mass"))
70 .def(
71 "computeInertiaFromDensity",
72 +[](const dart::dynamics::Shape* self,
73 double density) -> Eigen::Matrix3d {
74 return self->computeInertiaFromDensity(density);
75 },
76 ::py::arg("density"))
77 .def(
78 "computeInertiaFromMass",
79 +[](const dart::dynamics::Shape* self,
80 double mass) -> Eigen::Matrix3d {
81 return self->computeInertiaFromMass(mass);
82 },
83 ::py::arg("mass"))
84 .def(
85 "getVolume",
86 +[](const dart::dynamics::Shape* self) -> double {
87 return self->getVolume();
88 })
89 .def(
90 "getID",
91 +[](const dart::dynamics::Shape* self) -> std::size_t {
92 return self->getID();
93 })
94 .def(
95 "setDataVariance",
96 +[](dart::dynamics::Shape* self, unsigned int _variance) {
97 self->setDataVariance(_variance);
98 },
99 ::py::arg("variance"))
100 .def(
101 "addDataVariance",
102 +[](dart::dynamics::Shape* self, unsigned int _variance) {
103 self->addDataVariance(_variance);
104 },
105 ::py::arg("variance"))
106 .def(
107 "removeDataVariance",
108 +[](dart::dynamics::Shape* self, unsigned int _variance) {
109 self->removeDataVariance(_variance);
110 },
111 ::py::arg("variance"))
112 .def(
113 "getDataVariance",
114 +[](const dart::dynamics::Shape* self) -> unsigned int {
115 return self->getDataVariance();
116 })
117 .def(
118 "checkDataVariance",
119 +[](const dart::dynamics::Shape* self,
120 dart::dynamics::Shape::DataVariance type) -> bool {
121 return self->checkDataVariance(type);
122 },
123 ::py::arg("type"))
124 .def(
125 "refreshData",
126 +[](dart::dynamics::Shape* self) { self->refreshData(); })
127 .def(
128 "notifyAlphaUpdated",
129 +[](dart::dynamics::Shape* self, double alpha) {
130 self->notifyAlphaUpdated(alpha);
131 },
132 ::py::arg("alpha"))
133 .def(
134 "notifyColorUpdated",
135 +[](dart::dynamics::Shape* self, const Eigen::Vector4d& color) {
136 self->notifyColorUpdated(color);
137 },
138 ::py::arg("color"))
139 .def(
140 "incrementVersion",
141 +[](dart::dynamics::Shape* self) -> std::size_t {
142 return self->incrementVersion();
143 })
144 .def_readonly(
145 "onVersionChanged", &dart::dynamics::Shape::onVersionChanged);
146
147 #define DARTPY_DEFINE_SHAPE_TYPE(val) \
148 .value(#val, dart::dynamics::Shape::ShapeType::val)
149
150 // clang-format off
151 ::py::enum_<dart::dynamics::Shape::ShapeType>(shape, "ShapeType")
152 DARTPY_DEFINE_SHAPE_TYPE(SPHERE)
153 DARTPY_DEFINE_SHAPE_TYPE(BOX)
154 DARTPY_DEFINE_SHAPE_TYPE(ELLIPSOID)
155 DARTPY_DEFINE_SHAPE_TYPE(CYLINDER)
156 DARTPY_DEFINE_SHAPE_TYPE(CAPSULE)
157 DARTPY_DEFINE_SHAPE_TYPE(CONE)
158 DARTPY_DEFINE_SHAPE_TYPE(PLANE)
159 DARTPY_DEFINE_SHAPE_TYPE(MULTISPHERE)
160 DARTPY_DEFINE_SHAPE_TYPE(MESH)
161 DARTPY_DEFINE_SHAPE_TYPE(SOFT_MESH)
162 DARTPY_DEFINE_SHAPE_TYPE(LINE_SEGMENT)
163 DARTPY_DEFINE_SHAPE_TYPE(HEIGHTMAP)
164 DARTPY_DEFINE_SHAPE_TYPE(UNSUPPORTED)
165 .export_values();
166 // clang-format on
167
168 #define DARTPY_DEFINE_DATA_VARIANCE(val) \
169 .value(#val, dart::dynamics::Shape::DataVariance::val)
170
171 // clang-format off
172 ::py::enum_<dart::dynamics::Shape::DataVariance>(shape, "DataVariance")
173 DARTPY_DEFINE_DATA_VARIANCE(STATIC )
174 DARTPY_DEFINE_DATA_VARIANCE(DYNAMIC_TRANSFORM)
175 DARTPY_DEFINE_DATA_VARIANCE(DYNAMIC_PRIMITIVE)
176 DARTPY_DEFINE_DATA_VARIANCE(DYNAMIC_COLOR )
177 DARTPY_DEFINE_DATA_VARIANCE(DYNAMIC_VERTICES )
178 DARTPY_DEFINE_DATA_VARIANCE(DYNAMIC_ELEMENTS )
179 DARTPY_DEFINE_DATA_VARIANCE(DYNAMIC )
180 .export_values();
181 // clang-format on
182
183 ::py::class_<
184 dart::dynamics::BoxShape,
185 dart::dynamics::Shape,
186 std::shared_ptr<dart::dynamics::BoxShape>>(m, "BoxShape")
187 .def(::py::init<const Eigen::Vector3d&>(), ::py::arg("size"))
188 .def(
189 "getType",
190 +[](const dart::dynamics::BoxShape* self) -> const std::string& {
191 return self->getType();
192 },
193 ::py::return_value_policy::reference_internal)
194 .def(
195 "setSize",
196 +[](dart::dynamics::BoxShape* self, const Eigen::Vector3d& _size) {
197 self->setSize(_size);
198 },
199 ::py::arg("size"))
200 .def(
201 "getSize",
202 +[](const dart::dynamics::BoxShape* self) -> const Eigen::Vector3d& {
203 return self->getSize();
204 },
205 ::py::return_value_policy::reference_internal)
206 .def(
207 "computeInertia",
208 +[](const dart::dynamics::BoxShape* self, double mass)
209 -> Eigen::Matrix3d { return self->computeInertia(mass); },
210 ::py::arg("mass"))
211 .def_static(
212 "getStaticType",
213 +[]() -> const std::string& {
214 return dart::dynamics::BoxShape::getStaticType();
215 },
216 ::py::return_value_policy::reference_internal)
217 .def_static(
218 "computeVolume",
219 +[](const Eigen::Vector3d& size) -> double {
220 return dart::dynamics::BoxShape::computeVolume(size);
221 },
222 ::py::arg("size"))
223 .def_static(
224 "computeInertiaOf",
225 +[](const Eigen::Vector3d& size, double mass) -> Eigen::Matrix3d {
226 return dart::dynamics::BoxShape::computeInertia(size, mass);
227 },
228 ::py::arg("size"),
229 ::py::arg("mass"));
230
231 ::py::class_<
232 dart::dynamics::ConeShape,
233 dart::dynamics::Shape,
234 std::shared_ptr<dart::dynamics::ConeShape>>(m, "ConeShape")
235 .def(
236 ::py::init<double, double>(),
237 ::py::arg("radius"),
238 ::py::arg("height"))
239 .def(
240 "getType",
241 +[](const dart::dynamics::ConeShape* self) -> const std::string& {
242 return self->getType();
243 },
244 ::py::return_value_policy::reference_internal)
245 .def(
246 "getRadius",
247 +[](const dart::dynamics::ConeShape* self) -> double {
248 return self->getRadius();
249 })
250 .def(
251 "setRadius",
252 +[](dart::dynamics::ConeShape* self, double radius) {
253 self->setRadius(radius);
254 },
255 ::py::arg("radius"))
256 .def(
257 "getHeight",
258 +[](const dart::dynamics::ConeShape* self) -> double {
259 return self->getHeight();
260 })
261 .def(
262 "setHeight",
263 +[](dart::dynamics::ConeShape* self, double height) {
264 self->setHeight(height);
265 },
266 ::py::arg("height"))
267 .def(
268 "computeInertia",
269 +[](const dart::dynamics::ConeShape* self, double mass)
270 -> Eigen::Matrix3d { return self->computeInertia(mass); },
271 ::py::arg("mass"))
272 .def_static(
273 "getStaticType",
274 +[]() -> const std::string& {
275 return dart::dynamics::ConeShape::getStaticType();
276 },
277 ::py::return_value_policy::reference_internal)
278 .def_static(
279 "computeVolume",
280 +[](double radius, double height) -> double {
281 return dart::dynamics::ConeShape::computeVolume(radius, height);
282 },
283 ::py::arg("radius"),
284 ::py::arg("height"))
285 .def_static(
286 "computeInertiaOf",
287 +[](double radius, double height, double mass) -> Eigen::Matrix3d {
288 return dart::dynamics::ConeShape::computeInertia(
289 radius, height, mass);
290 },
291 ::py::arg("radius"),
292 ::py::arg("height"),
293 ::py::arg("mass"));
294
295 ::py::class_<
296 dart::dynamics::MeshShape,
297 dart::dynamics::Shape,
298 std::shared_ptr<dart::dynamics::MeshShape>>(m, "MeshShape")
299 .def(
300 ::py::init<const Eigen::Vector3d&, const aiScene*>(),
301 ::py::arg("scale"),
302 ::py::arg("mesh"))
303 .def(
304 ::py::init<
305 const Eigen::Vector3d&,
306 const aiScene*,
307 const dart::common::Uri&>(),
308 ::py::arg("scale"),
309 ::py::arg("mesh"),
310 ::py::arg("uri"))
311 .def(
312 ::py::init<
313 const Eigen::Vector3d&,
314 const aiScene*,
315 const dart::common::Uri&,
316 dart::common::ResourceRetrieverPtr>(),
317 ::py::arg("scale"),
318 ::py::arg("mesh"),
319 ::py::arg("uri"),
320 ::py::arg("resourceRetriever"))
321 .def(
322 "getType",
323 +[](const dart::dynamics::MeshShape* self) -> const std::string& {
324 return self->getType();
325 },
326 ::py::return_value_policy::reference_internal)
327 .def(
328 "update", +[](dart::dynamics::MeshShape* self) { self->update(); })
329 .def(
330 "notifyAlphaUpdated",
331 +[](dart::dynamics::MeshShape* self, double alpha) {
332 self->notifyAlphaUpdated(alpha);
333 },
334 ::py::arg("alpha"))
335 .def(
336 "setMesh",
337 +[](dart::dynamics::MeshShape* self, const aiScene* mesh) {
338 self->setMesh(mesh);
339 },
340 ::py::arg("mesh"))
341 .def(
342 "setMesh",
343 +[](dart::dynamics::MeshShape* self,
344 const aiScene* mesh,
345 const std::string& path) { self->setMesh(mesh, path); },
346 ::py::arg("mesh"),
347 ::py::arg("path"))
348 .def(
349 "setMesh",
350 +[](dart::dynamics::MeshShape* self,
351 const aiScene* mesh,
352 const std::string& path,
353 dart::common::ResourceRetrieverPtr resourceRetriever) {
354 self->setMesh(mesh, path, resourceRetriever);
355 },
356 ::py::arg("mesh"),
357 ::py::arg("path"),
358 ::py::arg("resourceRetriever"))
359 .def(
360 "setMesh",
361 +[](dart::dynamics::MeshShape* self,
362 const aiScene* mesh,
363 const dart::common::Uri& path) { self->setMesh(mesh, path); },
364 ::py::arg("mesh"),
365 ::py::arg("path"))
366 .def(
367 "setMesh",
368 +[](dart::dynamics::MeshShape* self,
369 const aiScene* mesh,
370 const dart::common::Uri& path,
371 dart::common::ResourceRetrieverPtr resourceRetriever) {
372 self->setMesh(mesh, path, resourceRetriever);
373 },
374 ::py::arg("mesh"),
375 ::py::arg("path"),
376 ::py::arg("resourceRetriever"))
377 .def(
378 "getMeshUri",
379 +[](const dart::dynamics::MeshShape* self) -> std::string {
380 return self->getMeshUri();
381 })
382 .def(
383 "getMeshUri2",
384 +[](const dart::dynamics::MeshShape* self)
385 -> const dart::common::Uri& { return self->getMeshUri2(); },
386 ::py::return_value_policy::reference_internal)
387 .def(
388 "getMeshPath",
389 +[](const dart::dynamics::MeshShape* self) -> const std::string& {
390 return self->getMeshPath();
391 },
392 ::py::return_value_policy::reference_internal)
393 .def(
394 "getResourceRetriever",
395 +[](dart::dynamics::MeshShape* self)
396 -> dart::common::ResourceRetrieverPtr {
397 return self->getResourceRetriever();
398 })
399 .def(
400 "setScale",
401 +[](dart::dynamics::MeshShape* self, const Eigen::Vector3d& scale) {
402 self->setScale(scale);
403 },
404 ::py::arg("scale"))
405 .def(
406 "getScale",
407 +[](const dart::dynamics::MeshShape* self) -> const Eigen::Vector3d& {
408 return self->getScale();
409 },
410 ::py::return_value_policy::reference_internal)
411 .def(
412 "setColorMode",
413 +[](dart::dynamics::MeshShape* self,
414 dart::dynamics::MeshShape::ColorMode mode) {
415 self->setColorMode(mode);
416 },
417 ::py::arg("mode"))
418 .def(
419 "getColorMode",
420 +[](const dart::dynamics::MeshShape* self)
421 -> dart::dynamics::MeshShape::ColorMode {
422 return self->getColorMode();
423 })
424 .def(
425 "setColorIndex",
426 +[](dart::dynamics::MeshShape* self, int index) {
427 self->setColorIndex(index);
428 },
429 ::py::arg("index"))
430 .def(
431 "getColorIndex",
432 +[](const dart::dynamics::MeshShape* self) -> int {
433 return self->getColorIndex();
434 })
435 .def(
436 "getDisplayList",
437 +[](const dart::dynamics::MeshShape* self) -> int {
438 return self->getDisplayList();
439 })
440 .def(
441 "setDisplayList",
442 +[](dart::dynamics::MeshShape* self, int index) {
443 self->setDisplayList(index);
444 },
445 ::py::arg("index"))
446 .def(
447 "computeInertia",
448 +[](const dart::dynamics::MeshShape* self, double mass)
449 -> Eigen::Matrix3d { return self->computeInertia(mass); },
450 ::py::arg("mass"))
451 .def_static(
452 "getStaticType",
453 +[]() -> const std::string& {
454 return dart::dynamics::MeshShape::getStaticType();
455 },
456 ::py::return_value_policy::reference_internal);
457
458 auto attr = m.attr("MeshShape");
459
460 ::py::enum_<dart::dynamics::MeshShape::ColorMode>(attr, "ColorMode")
461 .value(
462 "MATERIAL_COLOR",
463 dart::dynamics::MeshShape::ColorMode::MATERIAL_COLOR)
464 .value("COLOR_INDEX", dart::dynamics::MeshShape::ColorMode::COLOR_INDEX)
465 .value("SHAPE_COLOR", dart::dynamics::MeshShape::ColorMode::SHAPE_COLOR)
466 .export_values();
467
468 ::py::class_<
469 dart::dynamics::ArrowShape,
470 dart::dynamics::MeshShape,
471 std::shared_ptr<dart::dynamics::ArrowShape>>(m, "ArrowShape")
472 .def(
473 ::py::init<const Eigen::Vector3d&, const Eigen::Vector3d&>(),
474 ::py::arg("tail"),
475 ::py::arg("head"))
476 .def(
477 ::py::init<
478 const Eigen::Vector3d&,
479 const Eigen::Vector3d&,
480 const dart::dynamics::ArrowShape::Properties&>(),
481 ::py::arg("tail"),
482 ::py::arg("head"),
483 ::py::arg("properties"))
484 .def(
485 ::py::init<
486 const Eigen::Vector3d&,
487 const Eigen::Vector3d&,
488 const dart::dynamics::ArrowShape::Properties&,
489 const Eigen::Vector4d&>(),
490 ::py::arg("tail"),
491 ::py::arg("head"),
492 ::py::arg("properties"),
493 ::py::arg("color"))
494 .def(
495 ::py::init<
496 const Eigen::Vector3d&,
497 const Eigen::Vector3d&,
498 const dart::dynamics::ArrowShape::Properties&,
499 const Eigen::Vector4d&,
500 std::size_t>(),
501 ::py::arg("tail"),
502 ::py::arg("head"),
503 ::py::arg("properties"),
504 ::py::arg("color"),
505 ::py::arg("resolution"))
506 .def(
507 "setPositions",
508 +[](dart::dynamics::ArrowShape* self,
509 const Eigen::Vector3d& _tail,
510 const Eigen::Vector3d& _head) {
511 self->setPositions(_tail, _head);
512 },
513 ::py::arg("tail"),
514 ::py::arg("head"))
515 .def(
516 "getTail",
517 +[](const dart::dynamics::ArrowShape* self)
518 -> const Eigen::Vector3d& { return self->getTail(); },
519 ::py::return_value_policy::reference_internal)
520 .def(
521 "getHead",
522 +[](const dart::dynamics::ArrowShape* self)
523 -> const Eigen::Vector3d& { return self->getHead(); },
524 ::py::return_value_policy::reference_internal)
525 .def(
526 "setProperties",
527 +[](dart::dynamics::ArrowShape* self,
528 const dart::dynamics::ArrowShape::Properties& _properties) {
529 self->setProperties(_properties);
530 },
531 ::py::arg("properties"))
532 .def(
533 "notifyColorUpdated",
534 +[](dart::dynamics::ArrowShape* self, const Eigen::Vector4d& _color) {
535 self->notifyColorUpdated(_color);
536 },
537 ::py::arg("color"))
538 .def(
539 "getProperties",
540 +[](const dart::dynamics::ArrowShape* self)
541 -> const dart::dynamics::ArrowShape::Properties& {
542 return self->getProperties();
543 },
544 ::py::return_value_policy::reference_internal)
545 .def(
546 "configureArrow",
547 +[](dart::dynamics::ArrowShape* self,
548 const Eigen::Vector3d& _tail,
549 const Eigen::Vector3d& _head,
550 const dart::dynamics::ArrowShape::Properties& _properties) {
551 self->configureArrow(_tail, _head, _properties);
552 },
553 ::py::arg("tail"),
554 ::py::arg("head"),
555 ::py::arg("properties"));
556
557 ::py::class_<dart::dynamics::ArrowShape::Properties>(
558 m, "ArrowShapeProperties")
559 .def(::py::init<>())
560 .def(::py::init<double>(), ::py::arg("radius"))
561 .def(
562 ::py::init<double, double>(),
563 ::py::arg("radius"),
564 ::py::arg("headRadiusScale"))
565 .def(
566 ::py::init<double, double, double>(),
567 ::py::arg("radius"),
568 ::py::arg("headRadiusScale"),
569 ::py::arg("headLengthScale"))
570 .def(
571 ::py::init<double, double, double, double>(),
572 ::py::arg("radius"),
573 ::py::arg("headRadiusScale"),
574 ::py::arg("headLengthScale"),
575 ::py::arg("minHeadLength"))
576 .def(
577 ::py::init<double, double, double, double, double>(),
578 ::py::arg("radius"),
579 ::py::arg("headRadiusScale"),
580 ::py::arg("headLengthScale"),
581 ::py::arg("minHeadLength"),
582 ::py::arg("maxHeadLength"))
583 .def(
584 ::py::init<double, double, double, double, double, bool>(),
585 ::py::arg("radius"),
586 ::py::arg("headRadiusScale"),
587 ::py::arg("headLengthScale"),
588 ::py::arg("minHeadLength"),
589 ::py::arg("maxHeadLength"),
590 ::py::arg("doubleArrow"))
591 .def_readwrite(
592 "mRadius", &dart::dynamics::ArrowShape::Properties::mRadius)
593 .def_readwrite(
594 "mHeadRadiusScale",
595 &dart::dynamics::ArrowShape::Properties::mHeadRadiusScale)
596 .def_readwrite(
597 "mHeadLengthScale",
598 &dart::dynamics::ArrowShape::Properties::mHeadLengthScale)
599 .def_readwrite(
600 "mMinHeadLength",
601 &dart::dynamics::ArrowShape::Properties::mMinHeadLength)
602 .def_readwrite(
603 "mMaxHeadLength",
604 &dart::dynamics::ArrowShape::Properties::mMaxHeadLength)
605 .def_readwrite(
606 "mDoubleArrow",
607 &dart::dynamics::ArrowShape::Properties::mDoubleArrow);
608
609 ::py::class_<
610 dart::dynamics::PlaneShape,
611 dart::dynamics::Shape,
612 std::shared_ptr<dart::dynamics::PlaneShape>>(m, "PlaneShape")
613 .def(
614 ::py::init<const Eigen::Vector3d&, double>(),
615 ::py::arg("normal"),
616 ::py::arg("offset"))
617 .def(
618 ::py::init<const Eigen::Vector3d&, const Eigen::Vector3d&>(),
619 ::py::arg("normal"),
620 ::py::arg("point"))
621 .def(
622 "getType",
623 +[](const dart::dynamics::PlaneShape* self) -> const std::string& {
624 return self->getType();
625 },
626 ::py::return_value_policy::reference_internal)
627 .def(
628 "computeInertia",
629 +[](const dart::dynamics::PlaneShape* self, double mass)
630 -> Eigen::Matrix3d { return self->computeInertia(mass); },
631 ::py::arg("mass"))
632 .def(
633 "setNormal",
634 +[](dart::dynamics::PlaneShape* self,
635 const Eigen::Vector3d& _normal) { self->setNormal(_normal); },
636 ::py::arg("normal"))
637 .def(
638 "getNormal",
639 +[](const dart::dynamics::PlaneShape* self)
640 -> const Eigen::Vector3d& { return self->getNormal(); },
641 ::py::return_value_policy::reference_internal)
642 .def(
643 "setOffset",
644 +[](dart::dynamics::PlaneShape* self, double _offset) {
645 self->setOffset(_offset);
646 },
647 ::py::arg("offset"))
648 .def(
649 "getOffset",
650 +[](const dart::dynamics::PlaneShape* self) -> double {
651 return self->getOffset();
652 })
653 .def(
654 "setNormalAndOffset",
655 +[](dart::dynamics::PlaneShape* self,
656 const Eigen::Vector3d& _normal,
657 double _offset) { self->setNormalAndOffset(_normal, _offset); },
658 ::py::arg("normal"),
659 ::py::arg("offset"))
660 .def(
661 "setNormalAndPoint",
662 +[](dart::dynamics::PlaneShape* self,
663 const Eigen::Vector3d& _normal,
664 const Eigen::Vector3d& _point) {
665 self->setNormalAndPoint(_normal, _point);
666 },
667 ::py::arg("normal"),
668 ::py::arg("point"))
669 .def(
670 "computeDistance",
671 +[](const dart::dynamics::PlaneShape* self,
672 const Eigen::Vector3d& _point) -> double {
673 return self->computeDistance(_point);
674 },
675 ::py::arg("point"))
676 .def(
677 "computeSignedDistance",
678 +[](const dart::dynamics::PlaneShape* self,
679 const Eigen::Vector3d& _point) -> double {
680 return self->computeSignedDistance(_point);
681 },
682 ::py::arg("point"))
683 .def_static(
684 "getStaticType",
685 +[]() -> const std::string& {
686 return dart::dynamics::PlaneShape::getStaticType();
687 },
688 ::py::return_value_policy::reference_internal);
689 ::py::class_<
690 dart::dynamics::PointCloudShape,
691 dart::dynamics::Shape,
692 std::shared_ptr<dart::dynamics::PointCloudShape>>
693 pointCloudShape(m, "PointCloudShape");
694
695 pointCloudShape.def(::py::init<double>(), ::py::arg("visualSize") = 0.01)
696 .def(
697 "getType",
698 +[](const dart::dynamics::PointCloudShape* self)
699 -> const std::string& { return self->getType(); },
700 ::py::return_value_policy::reference_internal)
701 .def(
702 "computeInertia",
703 +[](const dart::dynamics::PointCloudShape* self, double mass)
704 -> Eigen::Matrix3d { return self->computeInertia(mass); },
705 ::py::arg("mass"))
706 .def(
707 "reserve",
708 +[](dart::dynamics::PointCloudShape* self, std::size_t size) -> void {
709 return self->reserve(size);
710 },
711 ::py::arg("size"))
712 .def(
713 "addPoint",
714 +[](dart::dynamics::PointCloudShape* self,
715 const Eigen::Vector3d& point) -> void {
716 return self->addPoint(point);
717 },
718 ::py::arg("point"))
719 .def(
720 "addPoint",
721 +[](dart::dynamics::PointCloudShape* self,
722 const std::vector<Eigen::Vector3d>& points) -> void {
723 return self->addPoint(points);
724 },
725 ::py::arg("points"))
726 .def(
727 "setPoint",
728 +[](dart::dynamics::PointCloudShape* self,
729 const std::vector<Eigen::Vector3d>& points) -> void {
730 return self->setPoint(points);
731 },
732 ::py::arg("points"))
733 .def(
734 "getPoints",
735 +[](const dart::dynamics::PointCloudShape* self)
736 -> const std::vector<Eigen::Vector3d>& {
737 return self->getPoints();
738 },
739 ::py::return_value_policy::reference_internal)
740 .def(
741 "getNumPoints",
742 +[](const dart::dynamics::PointCloudShape* self) -> std::size_t {
743 return self->getNumPoints();
744 })
745 .def(
746 "removeAllPoints",
747 +[](dart::dynamics::PointCloudShape* self) -> void {
748 return self->removeAllPoints();
749 })
750 .def(
751 "setPointShapeType",
752 +[](dart::dynamics::PointCloudShape* self,
753 dart::dynamics::PointCloudShape::PointShapeType type) -> void {
754 return self->setPointShapeType(type);
755 },
756 ::py::arg("type"))
757 .def(
758 "getPointShapeType",
759 +[](const dart::dynamics::PointCloudShape* self)
760 -> dart::dynamics::PointCloudShape::PointShapeType {
761 return self->getPointShapeType();
762 })
763 .def(
764 "setColorMode",
765 +[](dart::dynamics::PointCloudShape* self,
766 dart::dynamics::PointCloudShape::ColorMode mode) -> void {
767 return self->setColorMode(mode);
768 },
769 ::py::arg("mode"))
770 .def(
771 "getColorMode",
772 +[](const dart::dynamics::PointCloudShape* self)
773 -> dart::dynamics::PointCloudShape::ColorMode {
774 return self->getColorMode();
775 })
776 .def(
777 "setOverallColor",
778 +[](dart::dynamics::PointCloudShape* self,
779 const Eigen::Vector4d& color) -> void {
780 return self->setOverallColor(color);
781 },
782 ::py::arg("color"))
783 .def(
784 "getOverallColor",
785 +[](const dart::dynamics::PointCloudShape* self) -> Eigen::Vector4d {
786 return self->getOverallColor();
787 })
788 .def(
789 "setColors",
790 +[](dart::dynamics::PointCloudShape* self,
791 const std::vector<
792 Eigen::Vector4d,
793 Eigen::aligned_allocator<Eigen::Vector4d>>& colors) -> void {
794 return self->setColors(colors);
795 },
796 ::py::arg("colors"))
797 .def(
798 "getColors",
799 +[](const dart::dynamics::PointCloudShape* self)
800 -> const std::vector<
801 Eigen::Vector4d,
802 Eigen::aligned_allocator<Eigen::Vector4d>>& {
803 return self->getColors();
804 })
805 .def(
806 "setVisualSize",
807 +[](dart::dynamics::PointCloudShape* self, double size) -> void {
808 return self->setVisualSize(size);
809 },
810 ::py::arg("size"))
811 .def(
812 "getVisualSize",
813 +[](const dart::dynamics::PointCloudShape* self) -> double {
814 return self->getVisualSize();
815 })
816 .def(
817 "notifyColorUpdated",
818 +[](dart::dynamics::PointCloudShape* self,
819 const Eigen::Vector4d& color) {
820 self->notifyColorUpdated(color);
821 },
822 ::py::arg("color"));
823
824 ::py::enum_<dart::dynamics::PointCloudShape::ColorMode>(
825 pointCloudShape, "ColorMode")
826 .value(
827 "USE_SHAPE_COLOR",
828 dart::dynamics::PointCloudShape::ColorMode::USE_SHAPE_COLOR)
829 .value(
830 "BIND_OVERALL",
831 dart::dynamics::PointCloudShape::ColorMode::BIND_OVERALL)
832 .value(
833 "BIND_PER_POINT",
834 dart::dynamics::PointCloudShape::ColorMode::BIND_PER_POINT)
835 .export_values();
836
837 ::py::enum_<dart::dynamics::PointCloudShape::PointShapeType>(
838 pointCloudShape, "PointShapeType")
839 .value("BOX", dart::dynamics::PointCloudShape::PointShapeType::BOX)
840 .value(
841 "BILLBOARD_SQUARE",
842 dart::dynamics::PointCloudShape::PointShapeType::BILLBOARD_SQUARE)
843 .value(
844 "BILLBOARD_CIRCLE",
845 dart::dynamics::PointCloudShape::PointShapeType::BILLBOARD_CIRCLE)
846 .export_values();
847
848 ::py::class_<
849 dart::dynamics::SphereShape,
850 dart::dynamics::Shape,
851 std::shared_ptr<dart::dynamics::SphereShape>>(m, "SphereShape")
852 .def(::py::init<double>(), ::py::arg("radius"))
853 .def(
854 "getType",
855 +[](const dart::dynamics::SphereShape* self) -> const std::string& {
856 return self->getType();
857 },
858 ::py::return_value_policy::reference_internal)
859 .def(
860 "setRadius",
861 +[](dart::dynamics::SphereShape* self, double radius) {
862 self->setRadius(radius);
863 },
864 ::py::arg("radius"))
865 .def(
866 "getRadius",
867 +[](const dart::dynamics::SphereShape* self) -> double {
868 return self->getRadius();
869 })
870 .def(
871 "computeInertia",
872 +[](const dart::dynamics::SphereShape* self, double mass)
873 -> Eigen::Matrix3d { return self->computeInertia(mass); },
874 ::py::arg("mass"))
875 .def_static(
876 "getStaticType",
877 +[]() -> const std::string& {
878 return dart::dynamics::SphereShape::getStaticType();
879 },
880 ::py::return_value_policy::reference_internal)
881 .def_static(
882 "computeVolumeOf",
883 +[](double radius) -> double {
884 return dart::dynamics::SphereShape::computeVolume(radius);
885 },
886 ::py::arg("radius"))
887 .def_static(
888 "computeInertiaOf",
889 +[](double radius, double mass) -> Eigen::Matrix3d {
890 return dart::dynamics::SphereShape::computeInertia(radius, mass);
891 },
892 ::py::arg("radius"),
893 ::py::arg("mass"));
894
895 ::py::class_<
896 dart::dynamics::CapsuleShape,
897 dart::dynamics::Shape,
898 std::shared_ptr<dart::dynamics::CapsuleShape>>(m, "CapsuleShape")
899 .def(
900 ::py::init<double, double>(),
901 ::py::arg("radius"),
902 ::py::arg("height"))
903 .def(
904 "getType",
905 +[](const dart::dynamics::CapsuleShape* self) -> const std::string& {
906 return self->getType();
907 },
908 ::py::return_value_policy::reference_internal)
909 .def(
910 "getRadius",
911 +[](const dart::dynamics::CapsuleShape* self) -> double {
912 return self->getRadius();
913 })
914 .def(
915 "setRadius",
916 +[](dart::dynamics::CapsuleShape* self, double radius) {
917 self->setRadius(radius);
918 },
919 ::py::arg("radius"))
920 .def(
921 "getHeight",
922 +[](const dart::dynamics::CapsuleShape* self) -> double {
923 return self->getHeight();
924 })
925 .def(
926 "setHeight",
927 +[](dart::dynamics::CapsuleShape* self, double height) {
928 self->setHeight(height);
929 },
930 ::py::arg("height"))
931 .def(
932 "computeInertia",
933 +[](const dart::dynamics::CapsuleShape* self, double mass)
934 -> Eigen::Matrix3d { return self->computeInertia(mass); },
935 ::py::arg("mass"))
936 .def_static(
937 "getStaticType",
938 +[]() -> const std::string& {
939 return dart::dynamics::CapsuleShape::getStaticType();
940 },
941 ::py::return_value_policy::reference_internal)
942 .def_static(
943 "computeVolumeOf",
944 +[](double radius, double height) -> double {
945 return dart::dynamics::CapsuleShape::computeVolume(radius, height);
946 },
947 ::py::arg("radius"),
948 ::py::arg("height"))
949 .def_static(
950 "computeInertiaOf",
951 +[](double radius, double height, double mass) -> Eigen::Matrix3d {
952 return dart::dynamics::CapsuleShape::computeInertia(
953 radius, height, mass);
954 },
955 ::py::arg("radius"),
956 ::py::arg("height"),
957 ::py::arg("mass"));
958
959 ::py::class_<
960 dart::dynamics::CylinderShape,
961 dart::dynamics::Shape,
962 std::shared_ptr<dart::dynamics::CylinderShape>>(m, "CylinderShape")
963 .def(
964 ::py::init<double, double>(),
965 ::py::arg("radius"),
966 ::py::arg("height"))
967 .def(
968 "getType",
969 +[](const dart::dynamics::CylinderShape* self) -> const std::string& {
970 return self->getType();
971 },
972 ::py::return_value_policy::reference_internal)
973 .def(
974 "getRadius",
975 +[](const dart::dynamics::CylinderShape* self) -> double {
976 return self->getRadius();
977 })
978 .def(
979 "setRadius",
980 +[](dart::dynamics::CylinderShape* self, double _radius) {
981 self->setRadius(_radius);
982 },
983 ::py::arg("radius"))
984 .def(
985 "getHeight",
986 +[](const dart::dynamics::CylinderShape* self) -> double {
987 return self->getHeight();
988 })
989 .def(
990 "setHeight",
991 +[](dart::dynamics::CylinderShape* self, double _height) {
992 self->setHeight(_height);
993 },
994 ::py::arg("height"))
995 .def(
996 "computeInertia",
997 +[](const dart::dynamics::CylinderShape* self, double mass)
998 -> Eigen::Matrix3d { return self->computeInertia(mass); },
999 ::py::arg("mass"))
1000 .def_static(
1001 "getStaticType",
1002 +[]() -> const std::string& {
1003 return dart::dynamics::CylinderShape::getStaticType();
1004 },
1005 ::py::return_value_policy::reference_internal)
1006 .def_static(
1007 "computeVolumeOf",
1008 +[](double radius, double height) -> double {
1009 return dart::dynamics::CylinderShape::computeVolume(radius, height);
1010 },
1011 ::py::arg("radius"),
1012 ::py::arg("height"))
1013 .def_static(
1014 "computeInertiaOf",
1015 +[](double radius, double height, double mass) -> Eigen::Matrix3d {
1016 return dart::dynamics::CylinderShape::computeInertia(
1017 radius, height, mass);
1018 },
1019 ::py::arg("radius"),
1020 ::py::arg("height"),
1021 ::py::arg("mass"));
1022
1023 ::py::class_<
1024 dart::dynamics::SoftMeshShape,
1025 dart::dynamics::Shape,
1026 std::shared_ptr<dart::dynamics::SoftMeshShape>>(m, "SoftMeshShape")
1027 .def(
1028 ::py::init<dart::dynamics::SoftBodyNode*>(),
1029 ::py::arg("softBodyNode"))
1030 .def(
1031 "getType",
1032 +[](const dart::dynamics::SoftMeshShape* self) -> const std::string& {
1033 return self->getType();
1034 },
1035 ::py::return_value_policy::reference_internal)
1036 .def(
1037 "update",
1038 +[](dart::dynamics::SoftMeshShape* self) { self->update(); })
1039 .def(
1040 "computeInertia",
1041 +[](const dart::dynamics::SoftMeshShape* self, double mass)
1042 -> Eigen::Matrix3d { return self->computeInertia(mass); },
1043 ::py::arg("mass"))
1044 .def_static(
1045 "getStaticType",
1046 +[]() -> const std::string& {
1047 return dart::dynamics::SoftMeshShape::getStaticType();
1048 },
1049 ::py::return_value_policy::reference_internal);
1050
1051 ::py::class_<
1052 dart::dynamics::EllipsoidShape,
1053 dart::dynamics::Shape,
1054 std::shared_ptr<dart::dynamics::EllipsoidShape>>(m, "EllipsoidShape")
1055 .def(::py::init<const Eigen::Vector3d&>(), ::py::arg("diameters"))
1056 .def(
1057 "getType",
1058 +[](const dart::dynamics::EllipsoidShape* self)
1059 -> const std::string& { return self->getType(); },
1060 ::py::return_value_policy::reference_internal)
1061 .def(
1062 "setDiameters",
1063 +[](dart::dynamics::EllipsoidShape* self,
1064 const Eigen::Vector3d& diameters) {
1065 self->setDiameters(diameters);
1066 },
1067 ::py::arg("diameters"))
1068 .def(
1069 "getDiameters",
1070 +[](const dart::dynamics::EllipsoidShape* self)
1071 -> const Eigen::Vector3d& { return self->getDiameters(); },
1072 ::py::return_value_policy::reference_internal)
1073 .def(
1074 "setRadii",
1075 +[](dart::dynamics::EllipsoidShape* self,
1076 const Eigen::Vector3d& radii) { self->setRadii(radii); },
1077 ::py::arg("radii"))
1078 .def(
1079 "getRadii",
1080 +[](const dart::dynamics::EllipsoidShape* self)
1081 -> const Eigen::Vector3d { return self->getRadii(); })
1082 .def(
1083 "computeInertia",
1084 +[](const dart::dynamics::EllipsoidShape* self, double mass)
1085 -> Eigen::Matrix3d { return self->computeInertia(mass); },
1086 ::py::arg("mass"))
1087 .def(
1088 "isSphere",
1089 +[](const dart::dynamics::EllipsoidShape* self) -> bool {
1090 return self->isSphere();
1091 })
1092 .def_static(
1093 "getStaticType",
1094 +[]() -> const std::string& {
1095 return dart::dynamics::EllipsoidShape::getStaticType();
1096 },
1097 ::py::return_value_policy::reference_internal)
1098 .def_static(
1099 "computeVolumeOf",
1100 +[](const Eigen::Vector3d& diameters) -> double {
1101 return dart::dynamics::EllipsoidShape::computeVolume(diameters);
1102 },
1103 ::py::arg("diameters"))
1104 .def_static(
1105 "computeInertiaOf",
1106 +[](const Eigen::Vector3d& diameters,
1107 double mass) -> Eigen::Matrix3d {
1108 return dart::dynamics::EllipsoidShape::computeInertia(
1109 diameters, mass);
1110 },
1111 ::py::arg("diameters"),
1112 ::py::arg("mass"));
1113
1114 ::py::class_<
1115 dart::dynamics::LineSegmentShape,
1116 dart::dynamics::Shape,
1117 std::shared_ptr<dart::dynamics::LineSegmentShape>>(m, "LineSegmentShape")
1118 .def(::py::init<>())
1119 .def(::py::init<float>(), ::py::arg("thickness"))
1120 .def(
1121 ::py::init<const Eigen::Vector3d&, const Eigen::Vector3d&>(),
1122 ::py::arg("v1"),
1123 ::py::arg("v2"))
1124 .def(
1125 ::py::init<const Eigen::Vector3d&, const Eigen::Vector3d&, float>(),
1126 ::py::arg("v1"),
1127 ::py::arg("v2"),
1128 ::py::arg("thickness"))
1129 .def(
1130 "getType",
1131 +[](const dart::dynamics::LineSegmentShape* self)
1132 -> const std::string& { return self->getType(); },
1133 ::py::return_value_policy::reference_internal)
1134 .def(
1135 "setThickness",
1136 +[](dart::dynamics::LineSegmentShape* self, float _thickness) {
1137 self->setThickness(_thickness);
1138 },
1139 ::py::arg("thickness"))
1140 .def(
1141 "getThickness",
1142 +[](const dart::dynamics::LineSegmentShape* self) -> float {
1143 return self->getThickness();
1144 })
1145 .def(
1146 "addVertex",
1147 +[](dart::dynamics::LineSegmentShape* self, const Eigen::Vector3d& _v)
1148 -> std::size_t { return self->addVertex(_v); },
1149 ::py::arg("v"))
1150 .def(
1151 "addVertex",
1152 +[](dart::dynamics::LineSegmentShape* self,
1153 const Eigen::Vector3d& _v,
1154 std::size_t _parent) -> std::size_t {
1155 return self->addVertex(_v, _parent);
1156 },
1157 ::py::arg("v"),
1158 ::py::arg("parent"))
1159 .def(
1160 "removeVertex",
1161 +[](dart::dynamics::LineSegmentShape* self, std::size_t _idx) {
1162 self->removeVertex(_idx);
1163 },
1164 ::py::arg("idx"))
1165 .def(
1166 "setVertex",
1167 +[](dart::dynamics::LineSegmentShape* self,
1168 std::size_t _idx,
1169 const Eigen::Vector3d& _v) { self->setVertex(_idx, _v); },
1170 ::py::arg("idx"),
1171 ::py::arg("v"))
1172 .def(
1173 "getVertex",
1174 +[](const dart::dynamics::LineSegmentShape* self, std::size_t _idx)
1175 -> const Eigen::Vector3d& { return self->getVertex(_idx); },
1176 ::py::return_value_policy::reference_internal,
1177 ::py::arg("idx"))
1178 .def(
1179 "addConnection",
1180 +[](dart::dynamics::LineSegmentShape* self,
1181 std::size_t _idx1,
1182 std::size_t _idx2) { self->addConnection(_idx1, _idx2); },
1183 ::py::arg("idx1"),
1184 ::py::arg("idx2"))
1185 .def(
1186 "removeConnection",
1187 +[](dart::dynamics::LineSegmentShape* self,
1188 std::size_t _vertexIdx1,
1189 std::size_t _vertexIdx2) {
1190 self->removeConnection(_vertexIdx1, _vertexIdx2);
1191 },
1192 ::py::arg("vertexIdx1"),
1193 ::py::arg("vertexIdx2"))
1194 .def(
1195 "removeConnection",
1196 +[](dart::dynamics::LineSegmentShape* self,
1197 std::size_t _connectionIdx) {
1198 self->removeConnection(_connectionIdx);
1199 },
1200 ::py::arg("connectionIdx"))
1201 .def(
1202 "computeInertia",
1203 +[](const dart::dynamics::LineSegmentShape* self, double mass)
1204 -> Eigen::Matrix3d { return self->computeInertia(mass); },
1205 ::py::arg("mass"))
1206 .def_static(
1207 "getStaticType",
1208 +[]() -> const std::string& {
1209 return dart::dynamics::LineSegmentShape::getStaticType();
1210 },
1211 ::py::return_value_policy::reference_internal);
1212
1213 ::py::class_<
1214 dart::dynamics::MultiSphereConvexHullShape,
1215 dart::dynamics::Shape,
1216 std::shared_ptr<dart::dynamics::MultiSphereConvexHullShape>>(
1217 m, "MultiSphereConvexHullShape")
1218 .def(
1219 ::py::init<
1220 const dart::dynamics::MultiSphereConvexHullShape::Spheres&>(),
1221 ::py::arg("spheres"))
1222 .def(
1223 "getType",
1224 +[](const dart::dynamics::MultiSphereConvexHullShape* self)
1225 -> const std::string& { return self->getType(); },
1226 ::py::return_value_policy::reference_internal)
1227 .def(
1228 "addSpheres",
1229 +[](dart::dynamics::MultiSphereConvexHullShape* self,
1230 const dart::dynamics::MultiSphereConvexHullShape::Spheres&
1231 spheres) { self->addSpheres(spheres); },
1232 ::py::arg("spheres"))
1233 .def(
1234 "addSphere",
1235 +[](dart::dynamics::MultiSphereConvexHullShape* self,
1236 const dart::dynamics::MultiSphereConvexHullShape::Sphere&
1237 sphere) { self->addSphere(sphere); },
1238 ::py::arg("sphere"))
1239 .def(
1240 "addSphere",
1241 +[](dart::dynamics::MultiSphereConvexHullShape* self,
1242 double radius,
1243 const Eigen::Vector3d& position) {
1244 self->addSphere(radius, position);
1245 },
1246 ::py::arg("radius"),
1247 ::py::arg("position"))
1248 .def(
1249 "removeAllSpheres",
1250 +[](dart::dynamics::MultiSphereConvexHullShape* self) {
1251 self->removeAllSpheres();
1252 })
1253 .def(
1254 "getNumSpheres",
1255 +[](const dart::dynamics::MultiSphereConvexHullShape* self)
1256 -> std::size_t { return self->getNumSpheres(); })
1257 .def(
1258 "computeInertia",
1259 +[](const dart::dynamics::MultiSphereConvexHullShape* self,
1260 double mass) -> Eigen::Matrix3d {
1261 return self->computeInertia(mass);
1262 },
1263 ::py::arg("mass"))
1264 .def_static(
1265 "getStaticType",
1266 +[]() -> const std::string& {
1267 return dart::dynamics::MultiSphereConvexHullShape::getStaticType();
1268 },
1269 ::py::return_value_policy::reference_internal);
1270 }
1271
1272 } // namespace python
1273 } // namespace dart