MRPT  1.9.9
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>
14 
15 #include <iostream>
16 
17 #if MRPT_HAS_NANOGUI
18 void TestGUI()
19 {
20  nanogui::init();
21 
22  {
23  // Create main window:
25  // cp.fullscreen = true;
26 
28  "CDisplayWindowGUI demo", 800, 600, cp);
29 
30  nanogui::FormHelper* fh = new nanogui::FormHelper(&win);
31 
32  // Add subwindow:
33  nanogui::ref<nanogui::Window> subWin2 =
34  fh->addWindow({300, 400}, "Test");
35  subWin2->setLayout(new nanogui::GroupLayout());
36 
38  subWin2->add<mrpt::gui::MRPT2NanoguiGLCanvas>();
39  subWin2->setPosition({10, 300});
40 
41  {
44 
45  glControl->camera().setZoomDistance(5.0f);
46 
47  std::lock_guard<std::mutex> lck(glControl->scene_mtx);
48  glControl->scene = std::move(scene);
49  }
50 
51  // Add subwindow:
52  nanogui::ref<nanogui::Window> subWin =
53  fh->addWindow({300, 400}, "Test");
54  bool show_corner = true;
55 
56  fh->addGroup("Visualization");
57  fh->addVariable("Show XYZ corner", show_corner)
58  ->setCallback([&](const bool& c) { subWin2->setVisible(c); });
59 
60  fh->addButton("Quit", [&]() { win.setVisible(false); });
61 
62  subWin->setPosition({10, 10});
63 
64  // add a background scene:
65  {
67  scene->insert(mrpt::opengl::CGridPlaneXY::Create());
68 
69  std::lock_guard<std::mutex> lck(win.background_scene_mtx);
70  win.background_scene = std::move(scene);
71  }
72 
73  win.performLayout();
74 
75  win.camera().setZoomDistance(10.0f);
76 
77  // Update view and process events:
78  win.drawAll();
79  win.setVisible(true);
80  nanogui::mainloop();
81  }
82 
83  nanogui::shutdown();
84 }
85 #endif
86 
87 int main()
88 {
89  try
90  {
91 #if MRPT_HAS_NANOGUI
92  TestGUI();
93 #else
94  std::cerr << "This example requires MRPT built with NANOGUI.\n";
95 #endif
96  return 0;
97  }
98  catch (const std::exception& e)
99  {
100  std::cerr << mrpt::exception_to_str(e) << std::endl;
101  return -1;
102  }
103 }
virtual void setZoomDistance(float zoom)
Saves camera zooming See also getZoomDistance()
mrpt::gui::CDisplayWindow3D::Ptr win
An extension of nanogui::GLCanvas to render MRPT OpenGL scenes.
Additional parameters to change the window behavior and OpenGL context.
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...
mrpt::opengl::COpenGLScene::Ptr scene
The scene to render in this control.
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
static Ptr Create(Args &&... args)
Definition: COpenGLScene.h:58
static Ptr Create(Args &&... args)
Definition: CGridPlaneXY.h:31
A window with powerful GUI capabilities, via the nanogui library.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 3a26b90fd Wed Mar 25 20:17:03 2020 +0100 at miƩ mar 25 23:05:41 CET 2020