Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dartpy] Add InteractiveFrame and ImGui APIs #1359

Merged
merged 5 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Added GUI event handler: [#1346](https://github.com/dartsim/dart/pull/1346)
* Added shadow technique: [#1348](https://github.com/dartsim/dart/pull/1348)
* Added findSolution and solveAndApply to InverseKinematics: [#1358](https://github.com/dartsim/dart/pull/1358)
* Added InteractiveFrame and ImGui APIs: [#1359](https://github.com/dartsim/dart/pull/1359)

### [DART 6.9.1 (2019-06-06)](https://github.com/dartsim/dart/milestone/59?closed=1)

Expand Down
1 change: 1 addition & 0 deletions examples/drag_and_drop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ int main()
tf.translation() = Eigen::Vector3d(-4, 4, 0);
SimpleFramePtr draggable(new SimpleFrame(frame.get(), "draggable", tf));
draggable->setShape(std::make_shared<BoxShape>(Eigen::Vector3d(1, 1, 1)));
draggable->getVisualAspect(true)->setColor(Eigen::Vector3d(0.9, 0.0, 0.0));
world->addSimpleFrame(draggable);

tf.translation() = Eigen::Vector3d(8.0, 0.0, 0.0);
Expand Down
2 changes: 1 addition & 1 deletion python/dartpy/collision/CollisionObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace python {

void CollisionObject(py::module& m)
{
::pybind11::class_<dart::collision::CollisionObject>(m, "CollisionObject")
::py::class_<dart::collision::CollisionObject>(m, "CollisionObject")
.def(
"getShape",
+[](const dart::collision::CollisionObject* self)
Expand Down
20 changes: 10 additions & 10 deletions python/dartpy/collision/DistanceOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ namespace python {

void DistanceOption(py::module& m)
{
::pybind11::class_<dart::collision::DistanceOption>(m, "DistanceOption")
.def(::pybind11::init<>())
.def(::pybind11::init<bool>(), ::pybind11::arg("enableNearestPoints"))
::py::class_<dart::collision::DistanceOption>(m, "DistanceOption")
.def(::py::init<>())
.def(::py::init<bool>(), ::py::arg("enableNearestPoints"))
.def(
::pybind11::init<bool, double>(),
::pybind11::arg("enableNearestPoints"),
::pybind11::arg("distanceLowerBound"))
::py::init<bool, double>(),
::py::arg("enableNearestPoints"),
::py::arg("distanceLowerBound"))
.def(
::pybind11::init<
::py::init<
bool,
double,
const std::shared_ptr<dart::collision::DistanceFilter>&>(),
::pybind11::arg("enableNearestPoints"),
::pybind11::arg("distanceLowerBound"),
::pybind11::arg("distanceFilter"))
::py::arg("enableNearestPoints"),
::py::arg("distanceLowerBound"),
::py::arg("distanceFilter"))
.def_readwrite(
"enableNearestPoints",
&dart::collision::DistanceOption::enableNearestPoints)
Expand Down
4 changes: 2 additions & 2 deletions python/dartpy/collision/DistanceResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace python {

void DistanceResult(py::module& m)
{
::pybind11::class_<dart::collision::DistanceResult>(m, "DistanceResult")
.def(::pybind11::init<>())
::py::class_<dart::collision::DistanceResult>(m, "DistanceResult")
.def(::py::init<>())
.def(
"clear",
+[](dart::collision::DistanceResult* self) { self->clear(); })
Expand Down
12 changes: 6 additions & 6 deletions python/dartpy/collision/RaycastOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ namespace python {

void RaycastOption(py::module& m)
{
::pybind11::class_<dart::collision::RaycastOption>(m, "RaycastOption")
.def(::pybind11::init<>())
.def(::pybind11::init<bool>(), ::pybind11::arg("enableAllHits"))
::py::class_<dart::collision::RaycastOption>(m, "RaycastOption")
.def(::py::init<>())
.def(::py::init<bool>(), ::py::arg("enableAllHits"))
.def(
::pybind11::init<bool, bool>(),
::pybind11::arg("enableAllHits"),
::pybind11::arg("sortByClosest"))
::py::init<bool, bool>(),
::py::arg("enableAllHits"),
::py::arg("sortByClosest"))
.def_readwrite(
"mEnableAllHits", &dart::collision::RaycastOption::mEnableAllHits)
.def_readwrite(
Expand Down
8 changes: 4 additions & 4 deletions python/dartpy/collision/RaycastResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ namespace python {

void RaycastResult(py::module& m)
{
::pybind11::class_<dart::collision::RayHit>(m, "RayHit")
.def(::pybind11::init<>())
::py::class_<dart::collision::RayHit>(m, "RayHit")
.def(::py::init<>())
.def_readwrite(
"mCollisionObject", &dart::collision::RayHit::mCollisionObject)
.def_readwrite("mNormal", &dart::collision::RayHit::mNormal)
.def_readwrite("mPoint", &dart::collision::RayHit::mPoint)
.def_readwrite("mFraction", &dart::collision::RayHit::mFraction);

::pybind11::class_<dart::collision::RaycastResult>(m, "RaycastResult")
.def(::pybind11::init<>())
::py::class_<dart::collision::RaycastResult>(m, "RaycastResult")
.def(::py::init<>())
.def(
"clear", +[](dart::collision::RaycastResult* self) { self->clear(); })
.def(
Expand Down
116 changes: 116 additions & 0 deletions python/dartpy/gui/osg/ImGuiHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2011-2019, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/master/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <dart/dart.hpp>
#include <dart/gui/osg/osg.hpp>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>

PYBIND11_DECLARE_HOLDER_TYPE(T, ::osg::ref_ptr<T>, true);

namespace py = pybind11;

namespace dart {
namespace python {

void ImGuiHandler(py::module& m)
{
::pybind11::class_<
dart::gui::osg::ImGuiHandler,
osg::ref_ptr<dart::gui::osg::ImGuiHandler> >(m, "ImGuiHandler")
.def(::pybind11::init<>())
.def(
"newFrame",
+[](dart::gui::osg::ImGuiHandler* self, osg::RenderInfo& renderInfo) {
self->newFrame(renderInfo);
},
::pybind11::arg("renderInfo"))
.def(
"render",
+[](dart::gui::osg::ImGuiHandler* self, osg::RenderInfo& renderInfo) {
self->render(renderInfo);
},
::pybind11::arg("renderInfo"))
.def(
"setCameraCallbacks",
+[](dart::gui::osg::ImGuiHandler* self, osg::Camera* camera) {
self->setCameraCallbacks(camera);
},
::pybind11::arg("camera"))
.def(
"hasWidget",
+[](const dart::gui::osg::ImGuiHandler* self,
const std::shared_ptr<dart::gui::osg::ImGuiWidget>& widget)
-> bool { return self->hasWidget(widget); },
::pybind11::arg("widget"))
.def(
"addWidget",
+[](dart::gui::osg::ImGuiHandler* self,
const std::shared_ptr<dart::gui::osg::ImGuiWidget>& widget) {
self->addWidget(widget);
},
::pybind11::arg("widget"))
.def(
"addWidget",
+[](dart::gui::osg::ImGuiHandler* self,
const std::shared_ptr<dart::gui::osg::ImGuiWidget>& widget,
bool visible) { self->addWidget(widget, visible); },
::pybind11::arg("widget"),
::pybind11::arg("visible"))
.def(
"removeWidget",
+[](dart::gui::osg::ImGuiHandler* self,
const std::shared_ptr<dart::gui::osg::ImGuiWidget>& widget) {
self->removeWidget(widget);
},
::pybind11::arg("widget"))
.def(
"removeAllWidget",
+[](dart::gui::osg::ImGuiHandler* self) { self->removeAllWidget(); })
.def(
"handle",
+[](dart::gui::osg::ImGuiHandler* self,
const osgGA::GUIEventAdapter& eventAdapter,
osgGA::GUIActionAdapter& actionAdapter,
osg::Object* object,
osg::NodeVisitor* nodeVisitor) -> bool {
return self->handle(
eventAdapter, actionAdapter, object, nodeVisitor);
},
::pybind11::arg("eventAdapter"),
::pybind11::arg("actionAdapter"),
::pybind11::arg("object"),
::pybind11::arg("nodeVisitor"));
}

} // namespace python
} // namespace dart
69 changes: 69 additions & 0 deletions python/dartpy/gui/osg/ImGuiViewer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2011-2019, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/master/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <dart/dart.hpp>
#include <dart/gui/osg/osg.hpp>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>

PYBIND11_DECLARE_HOLDER_TYPE(T, ::osg::ref_ptr<T>, true);

namespace py = pybind11;

namespace dart {
namespace python {

void ImGuiViewer(py::module& m)
{
::py::class_<
dart::gui::osg::ImGuiViewer,
dart::gui::osg::Viewer,
osg::ref_ptr<dart::gui::osg::ImGuiViewer>>(m, "ImGuiViewer")
.def(::py::init<>())
.def(::py::init<const osg::Vec4&>(), ::py::arg("clearColor"))
.def(
"getImGuiHandler",
+[](dart::gui::osg::ImGuiViewer* self)
-> dart::gui::osg::ImGuiHandler* {
return self->getImGuiHandler();
},
::py::return_value_policy::reference_internal)
.def(
"showAbout",
+[](dart::gui::osg::ImGuiViewer* self) { self->showAbout(); })
.def("hideAbout", +[](dart::gui::osg::ImGuiViewer* self) {
self->hideAbout();
});
}

} // namespace python
} // namespace dart
66 changes: 66 additions & 0 deletions python/dartpy/gui/osg/ImGuiWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2011-2019, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/master/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <dart/dart.hpp>
#include <dart/gui/osg/osg.hpp>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>

PYBIND11_DECLARE_HOLDER_TYPE(T, ::osg::ref_ptr<T>, true);

namespace py = pybind11;

namespace dart {
namespace python {

void ImGuiWidget(py::module& m)
{
::pybind11::class_<dart::gui::osg::ImGuiWidget>(m, "ImGuiWidget")
.def("render", +[](dart::gui::osg::ImGuiWidget* self) { self->render(); })
.def(
"setVisible",
+[](dart::gui::osg::ImGuiWidget* self, bool visible) {
self->setVisible(visible);
},
::pybind11::arg("visible"))
.def(
"toggleVisible",
+[](dart::gui::osg::ImGuiWidget* self) { self->toggleVisible(); })
.def("show", +[](dart::gui::osg::ImGuiWidget* self) { self->show(); })
.def("hide", +[](dart::gui::osg::ImGuiWidget* self) { self->hide(); })
.def("isVisible", +[](const dart::gui::osg::ImGuiWidget* self) -> bool {
return self->isVisible();
});
}

} // namespace python
} // namespace dart
Loading