MRPT  2.0.4
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/core/exceptions.h>
11 #include <mrpt/core/lock_helper.h>
15 
16 #include <iostream>
17 
18 #if MRPT_HAS_NANOGUI
19 void TestGUI()
20 {
21  nanogui::init();
22 
23  {
24  // Create main window:
26  // cp.fullscreen = true;
27 
29  "CDisplayWindowGUI demo", 800, 600, cp);
30 
31  nanogui::FormHelper* fh = new nanogui::FormHelper(&win);
32 
33  // Add subwindow:
34  nanogui::ref<nanogui::Window> subWin2 =
35  fh->addWindow({300, 400}, "Test");
36  subWin2->setLayout(new nanogui::GroupLayout());
37 
39  subWin2->add<mrpt::gui::MRPT2NanoguiGLCanvas>();
40  subWin2->setPosition({10, 300});
41 
42  {
45 
46  glControl->camera().setZoomDistance(5.0f);
47 
48  auto lck = mrpt::lockHelper(glControl->scene_mtx);
49  glControl->scene = std::move(scene);
50  }
51 
52  // Add subwindow:
53  nanogui::ref<nanogui::Window> subWin =
54  fh->addWindow({300, 400}, "Test");
55  bool show_corner = true;
56 
57  fh->addGroup("Visualization");
58  fh->addVariable("Show XYZ corner", show_corner)
59  ->setCallback([&](const bool& c) { subWin2->setVisible(c); });
60 
61  fh->addButton("Quit", [&]() { win.setVisible(false); });
62 
63  subWin->setPosition({10, 10});
64 
65  // add a background scene:
66  {
68  scene->insert(mrpt::opengl::CGridPlaneXY::Create());
69 
70  std::lock_guard<std::mutex> lck(win.background_scene_mtx);
71  win.background_scene = std::move(scene);
72  }
73 
74  win.performLayout();
75 
76  win.camera().setZoomDistance(10.0f);
77 
78  // Update view and process events:
79  win.drawAll();
80  win.setVisible(true);
81  nanogui::mainloop();
82  }
83 
84  nanogui::shutdown();
85 }
86 #endif
87 
88 int main()
89 {
90  try
91  {
92 #if MRPT_HAS_NANOGUI
93  TestGUI();
94 #else
95  std::cerr << "This example requires MRPT built with NANOGUI.\n";
96 #endif
97  return 0;
98  }
99  catch (const std::exception& e)
100  {
101  std::cerr << mrpt::exception_to_str(e) << std::endl;
102  return -1;
103  }
104 }
exceptions.h
mrpt::gui::MRPT2NanoguiGLCanvas::scene_mtx
std::mutex scene_mtx
Definition: MRPT2NanoguiGLCanvas.h:44
TestGUI
void TestGUI()
Definition: vision_stereo_rectify/test.cpp:19
stock_objects.h
mrpt::opengl::stock_objects::CornerXYZSimple
CSetOfObjects::Ptr CornerXYZSimple(float scale=1.0, float lineWidth=1.0)
Returns three arrows representing a X,Y,Z 3D corner (just thick lines instead of complex arrows for f...
Definition: StockObjects.cpp:343
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::gui::MRPT2NanoguiGLCanvas
An extension of nanogui::GLCanvas to render MRPT OpenGL scenes.
Definition: MRPT2NanoguiGLCanvas.h:32
mrpt::opengl::CGridPlaneXY::Create
static Ptr Create(Args &&... args)
Definition: CGridPlaneXY.h:31
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::gui::CDisplayWindowGUI
A window with powerful GUI capabilities, via the nanogui library.
Definition: CDisplayWindowGUI.h:71
mrpt::gui::MRPT2NanoguiGLCanvas::scene
mrpt::opengl::COpenGLScene::Ptr scene
The scene to render in this control.
Definition: MRPT2NanoguiGLCanvas.h:43
lock_helper.h
mrpt::gui::MRPT2NanoguiGLCanvas::camera
CGlCanvasBase & camera()
Definition: MRPT2NanoguiGLCanvas.h:46
mrpt::opengl::COpenGLScene::Create
static Ptr Create(Args &&... args)
Definition: COpenGLScene.h:58
mrpt::lockHelper
LockHelper< T > lockHelper(T &t)
Syntactic sugar to easily create a locker to any kind of std::mutex.
Definition: lock_helper.h:50
mrpt::gui::CDisplayWindowGUI_Params
Additional parameters to change the window behavior and OpenGL context.
Definition: CDisplayWindowGUI.h:28
mrpt::exception_to_str
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
CDisplayWindowGUI.h
CGridPlaneXY.h
mrpt::gui::CGlCanvasBase::setZoomDistance
virtual void setZoomDistance(float zoom)
Saves camera zooming See also getZoomDistance()
Definition: CGlCanvasBase.cpp:186



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020