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

Small cleaning of Magnum GUI #47

Merged
merged 7 commits into from
May 13, 2020
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
11 changes: 6 additions & 5 deletions src/examples/cameras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

class MyApp : public robot_dart::gui::magnum::GlfwApplication {
public:
explicit MyApp(int argc, char** argv, const dart::simulation::WorldPtr& world,
size_t width, size_t height, const std::string& title = "DART",
bool shadowed = true, bool transparent_shadows = true)
: GlfwApplication(argc, argv, world, width, height, title, shadowed, transparent_shadows) {}
explicit MyApp(int argc, char** argv, const dart::simulation::WorldPtr& world, const robot_dart::gui::magnum::GraphicsConfiguration& configuration = robot_dart::gui::magnum::GraphicsConfiguration())
: GlfwApplication(argc, argv, world, configuration) {}

protected:
void keyPressEvent(KeyEvent& event) override
Expand Down Expand Up @@ -43,7 +41,10 @@ int main()
robot_dart::RobotDARTSimu simu(0.001);

// Magnum graphics
auto graphics = std::make_shared<robot_dart::gui::magnum::Graphics<MyApp>>(simu.world(), 1024, 768);
robot_dart::gui::magnum::GraphicsConfiguration configuration;
configuration.width = 1024;
configuration.height = 768;
auto graphics = std::make_shared<robot_dart::gui::magnum::Graphics<MyApp>>(simu.world(), configuration);
simu.set_graphics(graphics);
graphics->look_at({0., 3.5, 2.}, {0., 0., 0.25});

Expand Down
5 changes: 4 additions & 1 deletion src/examples/magnum_contexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ int main()
std::static_pointer_cast<robot_dart::control::PDControl>(g_robot->controllers()[0])->set_pd(300., 50.);

// Magnum graphics
auto graphics = std::make_shared<robot_dart::gui::magnum::Graphics<robot_dart::gui::magnum::WindowlessGLApplication>>(simu.world(), 1024, 768);
robot_dart::gui::magnum::GraphicsConfiguration configuration;
configuration.width = 1024;
configuration.height = 768;
auto graphics = std::make_shared<robot_dart::gui::magnum::Graphics<robot_dart::gui::magnum::WindowlessGLApplication>>(simu.world(), configuration);
simu.set_graphics(graphics);
// Position the camera differently for each thread to visualize the difference
graphics->look_at({0.4 * index, 3.5 - index * 0.1, 2.}, {0., 0., 0.25});
Expand Down
6 changes: 3 additions & 3 deletions src/python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def clone(self):
simu = rd.RobotDARTSimu(0.001)

# Create graphics
graphics = rd.gui.Graphics(simu.world(), 640, 480, True, False, "DART")
graphics = rd.gui.Graphics(simu.world(), rd.gui.GraphicsConfiguration())
# graphics.clear_lights()
# mat = rd.gui.Material(magnum.Color4(0, 0, 0, 1), magnum.Color4(1, 1, 1, 1), magnum.Color4(1, 1, 1, 1), 80.)
# graphics.add_light(rd.gui.createPointLight(magnum.Vector3(-1., 1., 2.), mat, 2., magnum.Vector3(0., 0., 1.)))
# graphics.add_light(rd.gui.createPointLight(magnum.Vector3(1., -1., 2.), mat, 2., magnum.Vector3(0., 0., 1.)))
# graphics.add_light(rd.gui.create_point_light(magnum.Vector3(-1., 1., 2.), mat, 2., magnum.Vector3(0., 0., 1.)))
# graphics.add_light(rd.gui.create_point_light(magnum.Vector3(1., -1., 2.), mat, 2., magnum.Vector3(0., 0., 1.)))
simu.set_graphics(graphics)

# Add robot and floor to the simulation
Expand Down
2 changes: 1 addition & 1 deletion src/python/example_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test():
simu = rd.RobotDARTSimu(0.001)

# set the graphics
graphics = rd.gui.WindowlessGraphics(simu.world(), 640, 480, True, False, "DART")
graphics = rd.gui.WindowlessGraphics(simu.world(), rd.gui.GraphicsConfiguration())
graphics.look_at([0.4 * ii, 3.5 - ii * 0.1, 2.], [0., 0., 0.25], [0., 0., 1.])
simu.set_graphics(graphics)

Expand Down
37 changes: 30 additions & 7 deletions src/python/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace robot_dart {
// Helper definitions and classes
using BaseGraphics = gui::magnum::Graphics<gui::magnum::GlfwApplication>;
using BaseWindowlessGraphics = gui::magnum::Graphics<gui::magnum::WindowlessGLApplication>;
using GraphicsConfiguration = gui::magnum::GraphicsConfiguration;

class Graphics : public BaseGraphics {
public:
Expand All @@ -35,14 +36,34 @@ namespace robot_dart {
using BaseWindowlessGraphics::BaseWindowlessGraphics;
};

py::class_<GraphicsConfiguration>(sm, "GraphicsConfiguration")
.def(py::init<size_t, size_t, const std::string&, bool, bool, size_t, size_t>(),
py::arg("width") = 640,
py::arg("height") = 480,
py::arg("title") = "DART",
py::arg("shadowed") = true,
py::arg("transparent_shadows") = true,
py::arg("shadow_map_size") = 512,
py::arg("max_lights") = 3)

.def_readwrite("width", &GraphicsConfiguration::width)
.def_readwrite("height", &GraphicsConfiguration::height)
.def_readwrite("title", &GraphicsConfiguration::title)

.def_readwrite("shadowed", &GraphicsConfiguration::shadowed)
.def_readwrite("transparent_shadows", &GraphicsConfiguration::transparent_shadows)
.def_readwrite("shadow_map_size", &GraphicsConfiguration::shadow_map_size)

.def_readwrite("max_lights", &GraphicsConfiguration::max_lights);

py::class_<gui::Base, std::shared_ptr<gui::Base>>(sm, "Base");
py::class_<BaseGraphics, gui::Base, std::shared_ptr<BaseGraphics>>(sm, "BaseGraphics");
py::class_<BaseWindowlessGraphics, gui::Base, std::shared_ptr<BaseWindowlessGraphics>>(sm, "BaseWindowlessGraphics");
py::class_<gui::magnum::BaseApplication>(sm, "BaseApplication");

// Graphics class
py::class_<Graphics, BaseGraphics, std::shared_ptr<Graphics>>(sm, "Graphics")
.def(py::init<const dart::simulation::WorldPtr&, unsigned int, unsigned int, bool, bool, const std::string&>())
.def(py::init<const dart::simulation::WorldPtr&, const GraphicsConfiguration&>())

.def("done", &Graphics::done)
.def("refresh", &Graphics::refresh)
Expand All @@ -61,7 +82,8 @@ namespace robot_dart {
.def("recording", &Graphics::recording)
.def("recording_depth", &Graphics::recording_depth)

.def("is_shadowed", &Graphics::is_shadowed)
.def("shadowed", &Graphics::shadowed)
.def("transparent_shadows", &Graphics::transparent_shadows)
.def("enable_shadows", &Graphics::enable_shadows)

// Magnum::Image2D* magnum_image()
Expand All @@ -84,7 +106,7 @@ namespace robot_dart {

// WindowlessGraphics class
py::class_<WindowlessGraphics, BaseWindowlessGraphics, std::shared_ptr<WindowlessGraphics>>(sm, "WindowlessGraphics")
.def(py::init<const dart::simulation::WorldPtr&, unsigned int, unsigned int, bool, bool, const std::string&>())
.def(py::init<const dart::simulation::WorldPtr&, const GraphicsConfiguration&>())

.def("done", &WindowlessGraphics::done)
.def("refresh", &WindowlessGraphics::refresh)
Expand All @@ -103,7 +125,8 @@ namespace robot_dart {
.def("recording", &WindowlessGraphics::recording)
.def("recording_depth", &WindowlessGraphics::recording_depth)

.def("is_shadowed", &WindowlessGraphics::is_shadowed)
.def("shadowed", &WindowlessGraphics::shadowed)
.def("transparent_shadows", &WindowlessGraphics::transparent_shadows)
.def("enable_shadows", &WindowlessGraphics::enable_shadows)

// Magnum::Image2D* magnum_image()
Expand Down Expand Up @@ -190,9 +213,9 @@ namespace robot_dart {
.def(py::init<const Magnum::Vector4&, const Material&, const Magnum::Vector3&, Magnum::Float, Magnum::Float, const Magnum::Vector4&>());
// TO-DO: Add more functions

sm.def("createPointLight", &gui::magnum::gs::createPointLight);
sm.def("createSpotLight", &gui::magnum::gs::createSpotLight);
sm.def("createDirectionalLight", &gui::magnum::gs::createDirectionalLight);
sm.def("create_point_light", &gui::magnum::gs::create_point_light);
sm.def("create_spot_light", &gui::magnum::gs::create_spot_light);
sm.def("create_directional_light", &gui::magnum::gs::create_directional_light);
}
#endif
} // namespace python
Expand Down
5 changes: 1 addition & 4 deletions src/robot_dart/gui/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ namespace robot_dart {

virtual ~Base() {}

virtual bool done() const
{
return false;
}
virtual bool done() const { return false; }

virtual void refresh() {}

Expand Down
Loading