Skip to content

Commit

Permalink
[dartpy] Allow WorldNode classes to overload virtual functions (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored May 18, 2019
1 parent c91f974 commit 10ad8e2
Show file tree
Hide file tree
Showing 13 changed files with 664 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* Switched to pybind11: [#1307](https://github.com/dartsim/dart/pull/1307)
* Added grid visual: [#1318](https://github.com/dartsim/dart/pull/1318)
* Added ReferentialSkeleton, Linkage, and Chain: [#1321](https://github.com/dartsim/dart/pull/1321)
* Enabled WorldNode classes to overload virtual functions in Python: [#1322](https://github.com/dartsim/dart/pull/1322)

### [DART 6.8.4 (2019-05-03)](https://github.com/dartsim/dart/milestone/56?closed=1)

Expand Down
3 changes: 0 additions & 3 deletions dart/gui/osg/RealTimeWorldNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ class RealTimeWorldNode : public WorldNode
/// Get the highest real time factor that has been hit during the simulation.
double getHighestRealTimeFactor() const;

/// Turn the text displaying the real time factor on or off
void setRealTimeFactorDisplay(bool on);

// Documentation inherited
void refresh() override;

Expand Down
4 changes: 2 additions & 2 deletions dart/gui/osg/WorldNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ class WorldNode : public ::osg::Group
/// the default ShadowTechnique is ShadowMap
static ::osg::ref_ptr<osgShadow::ShadowTechnique> createDefaultShadowTechnique(const Viewer* viewer);

protected:

/// Destructor
virtual ~WorldNode();

protected:

/// Called when this world gets added to an dart::gui::osg::Viewer. Override
/// this function to customize the way your WorldNode starts up in an
/// dart::gui::osg::Viewer. Default behavior does nothing.
Expand Down
4 changes: 2 additions & 2 deletions data/urdf/KR5/ground.urdf
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<box size="2.0 0.05 2.0" />
</geometry>
</visual>
<!--collision group="default">
<collision group="default">
<origin xyz="0 -0.525 0" rpy="0 -0 0" />
<geometry>
<box size="2.0 0.05 2.0" />
</geometry>
</collision-->
</collision>
</link>
<joint name="ground_joint" type="fixed">
<origin xyz="0 0 0" rpy="0 0 0" />
Expand Down
2 changes: 1 addition & 1 deletion python/dartpy/dynamics/Chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void Chain(pybind11::module& m)
::pybind11::enum_<dart::dynamics::Chain::IncludeUpstreamParentJointTag>(
attr, "IncludeUpstreamParentJointTag")
.value(
"IncludeBoth",
"IncludeUpstreamParentJoint",
dart::dynamics::Chain::IncludeUpstreamParentJointTag::
IncludeUpstreamParentJoint)
.export_values();
Expand Down
2 changes: 1 addition & 1 deletion python/dartpy/dynamics/Skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/

#include <dart/dart.hpp>
#include <pybind11/stl.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "eigen_geometry_pybind.h"
#include "eigen_pybind.h"

Expand Down
1 change: 1 addition & 0 deletions python/dartpy/gui/osg/GridVisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void GridVisual(pybind11::module& m)
{
::pybind11::class_<
dart::gui::osg::GridVisual,
dart::gui::osg::ViewerAttachment,
::osg::ref_ptr<dart::gui::osg::GridVisual>>(m, "GridVisual")
.def(py::init<>())
.def(
Expand Down
127 changes: 125 additions & 2 deletions python/dartpy/gui/osg/RealTimeWorldNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,138 @@ namespace py = pybind11;
namespace dart {
namespace python {

class PyPyRealTimeWorldNodeNode : public dart::gui::osg::RealTimeWorldNode
{
public:
// Inherit the constructors
using RealTimeWorldNode::RealTimeWorldNode;

// Trampoline for virtual function
void refresh() override
{
PYBIND11_OVERLOAD(
void, // Return type
RealTimeWorldNode, // Parent class
refresh, // Name of function in C++ (must match Python name)
);
}

// Trampoline for virtual function
void customPreRefresh() override
{
PYBIND11_OVERLOAD(
void, // Return type
RealTimeWorldNode, // Parent class
customPreRefresh, // Name of function in C++ (must match Python name)
);
}

// Trampoline for virtual function
void customPostRefresh() override
{
PYBIND11_OVERLOAD(
void, // Return type
RealTimeWorldNode, // Parent class
customPostRefresh, // Name of function in C++ (must match Python name)
);
}

// Trampoline for virtual function
void customPreStep() override
{
PYBIND11_OVERLOAD(
void, // Return type
RealTimeWorldNode, // Parent class
customPreStep, // Name of function in C++ (must match Python name)
);
}

// Trampoline for virtual function
void customPostStep() override
{
PYBIND11_OVERLOAD(
void, // Return type
RealTimeWorldNode, // Parent class
customPostStep, // Name of function in C++ (must match Python name)
);
}
};

void RealTimeWorldNode(pybind11::module& m)
{
::pybind11::class_<
dart::gui::osg::RealTimeWorldNode,
dart::gui::osg::WorldNode,
PyPyRealTimeWorldNodeNode,
::osg::ref_ptr<dart::gui::osg::RealTimeWorldNode>>(m, "RealTimeWorldNode")
.def(py::init<>())
.def(::pybind11::init<>())
.def(
::pybind11::init<const std::shared_ptr<dart::simulation::World>&>(),
::pybind11::arg("world"));
::pybind11::arg("world"))
.def(
::pybind11::init<
const std::shared_ptr<dart::simulation::World>&,
const osg::ref_ptr<osgShadow::ShadowTechnique>&>(),
::pybind11::arg("world"),
::pybind11::arg("shadower"))
.def(
::pybind11::init<
const std::shared_ptr<dart::simulation::World>&,
const osg::ref_ptr<osgShadow::ShadowTechnique>&,
double>(),
::pybind11::arg("world"),
::pybind11::arg("shadower"),
::pybind11::arg("targetFrequency"))
.def(
::pybind11::init<
const std::shared_ptr<dart::simulation::World>&,
const osg::ref_ptr<osgShadow::ShadowTechnique>&,
double,
double>(),
::pybind11::arg("world"),
::pybind11::arg("shadower"),
::pybind11::arg("targetFrequency"),
::pybind11::arg("targetRealTimeFactor"))
.def(
"setTargetFrequency",
+[](dart::gui::osg::RealTimeWorldNode* self, double targetFrequency) {
self->setTargetFrequency(targetFrequency);
},
::pybind11::arg("targetFrequency"))
.def(
"getTargetFrequency",
+[](const dart::gui::osg::RealTimeWorldNode* self) -> double {
return self->getTargetFrequency();
})
.def(
"setTargetRealTimeFactor",
+[](dart::gui::osg::RealTimeWorldNode* self, double targetRTF) {
self->setTargetRealTimeFactor(targetRTF);
},
::pybind11::arg("targetRTF"))
.def(
"getTargetRealTimeFactor",
+[](const dart::gui::osg::RealTimeWorldNode* self) -> double {
return self->getTargetRealTimeFactor();
})
.def(
"getLastRealTimeFactor",
+[](const dart::gui::osg::RealTimeWorldNode* self) -> double {
return self->getLastRealTimeFactor();
})
.def(
"getLowestRealTimeFactor",
+[](const dart::gui::osg::RealTimeWorldNode* self) -> double {
return self->getLowestRealTimeFactor();
})
.def(
"getHighestRealTimeFactor",
+[](const dart::gui::osg::RealTimeWorldNode* self) -> double {
return self->getHighestRealTimeFactor();
})
.def("refresh", +[](dart::gui::osg::RealTimeWorldNode* self) {
self->refresh();
});
}

} // namespace python
Expand Down
Loading

0 comments on commit 10ad8e2

Please sign in to comment.