MRPT  2.0.4
CWindowManager.h
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 #pragma once
10 
13 
14 #include "CWindowObserver.h"
15 
16 namespace mrpt::graphslam
17 {
18 /**\brief Class acts as a container for storing pointers to
19  * mrpt::gui::CDisplayWindow3D,
20  * mrpt::graphslam::CWindowObserver instances.
21  *
22  * CWindowManager also provides methods for adding/positioning textMessages
23  * and viewports in the CDisplayWindow in a compact and consistent way.
24  *
25  * \ingroup mrpt_graphslam_grp
26  */
28 {
29  public:
30  /**\brief Default class constructor */
32  /**\brief Class constructor*/
34  {
35  this->initCWindowManager();
36  this->setCDisplayWindow3DPtr(win_in);
37  }
38  /**\brief Class constructor*/
42  {
43  this->initCWindowManager();
44 
45  this->setWindowObserverPtr(observer_in);
46  this->setCDisplayWindow3DPtr(win_in);
47  }
48  /**\brief Class destructor. */
49  ~CWindowManager() override = default;
50  /**\brief Store the CDisplayWindow3D pointer in the CWindowManager
51  * instance.
52  *
53  * \sa setWindowObserverPtr
54  */
56  {
58  win = win_in;
59 
60  MRPT_LOG_DEBUG_STREAM("Fetched the CDisplayWindow3D* successfully");
61  }
62  /**\brief Store the CWindowObserver pointer in the CWindowManager instance.
63  *
64  * \sa setCDisplayWindow3DPtr
65  */
67  {
69  observer = obsever_in;
70 
71  MRPT_LOG_DEBUG_STREAM("Fetched the CWindowObserver* successfully");
72  }
73 
74  /**\brief Assign the next available offset_y and text_index for the
75  * textMessage under construction.
76  *
77  * Used for consistent positioning of textMessages in the
78  * CDisplayWindow3D.
79  *
80  * \sa assignViewPortParameters
81  */
82  void assignTextMessageParameters(double* offset_y, int* text_index)
83  {
84  *offset_y = m_curr_offset_y;
86 
87  *text_index = m_curr_text_index;
89  }
90 
91  /**\brief Wrapper call around the CWindowDisplay3D */
92  bool isOpen()
93  {
94  if (win)
95  {
96  return win->isOpen();
97  }
98  else
99  {
100  return false;
101  }
102  }
103 
104  /**\brief Wrapper around the CDisplayWindow3D::addTextMessage method, so
105  * that the
106  * user does not have to specify the font name and size.
107  *
108  * \note see initCWindowManager method for the default fontName and
109  * fontSize used.
110  */
112  const double x, const double y, const std::string& text,
113  const mrpt::img::TColorf& color = mrpt::img::TColorf(1.0, 1.0, 1.0),
114  const size_t unique_index = 0)
115  {
116  if (!win)
117  {
118  return;
119  }
120 
121  win->addTextMessage(x, y, text, unique_index);
122  }
123 
124  /**\brief Assign position and size values for the placement of the next
125  * viewport
126  *
127  * Used for consistent positioning of the Viewports in the CDisplayWindow3D
128  *
129  * \sa assignTextMessageParameters
130  */
132  double* x, double* y, double* width, double* height)
133  {
134  *x = m_viewp_x;
135  *y = m_viewp_y;
136 
137  *width = m_viewp_width;
138  *height = m_viewp_height;
139 
141  }
142 
143  mrpt::gui::CDisplayWindow3D* win; /**< CDisplayWindow instance */
144  mrpt::graphslam::CWindowObserver* observer; /**< CWindowObserver instance */
145  private:
146  /**\brief Initialization method, to be called from the various Constructors.
147  */
149  {
152  win = nullptr;
153  observer = nullptr;
154 
155  m_offset_y_step = 20.0;
156  m_index_text_step = 1;
157  m_font_name = "sans";
158  m_font_size = 12;
159  m_curr_offset_y = 30;
160  m_curr_text_index = 1;
161 
162  m_viewp_width = 0.2;
163  m_viewp_height = 0.2;
164  m_viewp_x = 0.75;
165  m_viewp_margin = 0.01;
166  m_viewp_y = 0.72;
167 
168  // loger related directives
169  this->setLoggerName("CWindowManager");
170  }
171 
174 
179 
180  std::string m_font_name;
182 
183  // viewports configuration
186  double m_viewp_x;
187  double m_viewp_y; /**< vertical layout of the viewports */
189 };
190 } // namespace mrpt::graphslam
void setCDisplayWindow3DPtr(mrpt::gui::CDisplayWindow3D *win_in)
Store the CDisplayWindow3D pointer in the CWindowManager instance.
CWindowManager(mrpt::gui::CDisplayWindow3D *win_in, mrpt::graphslam::CWindowObserver *observer_in)
Class constructor.
void setWindowObserverPtr(mrpt::graphslam::CWindowObserver *obsever_in)
Store the CWindowObserver pointer in the CWindowManager instance.
double m_viewp_y
vertical layout of the viewports
void assignViewportParameters(double *x, double *y, double *width, double *height)
Assign position and size values for the placement of the next viewport.
bool isOpen()
Wrapper call around the CWindowDisplay3D.
SLAM methods related to graphs of pose constraints.
mrpt::gui::CDisplayWindow3D * win
CDisplayWindow instance.
mrpt::graphslam::CWindowObserver * observer
CWindowObserver instance.
Versatile class for consistent logging and management of output messages.
void setLoggerName(const std::string &name)
Set the name of the COutputLogger instance.
bool isOpen()
Returns false if the user has already closed the window.
CWindowManager()
Default class constructor.
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
Use: MRPT_LOG_DEBUG_STREAM("Var=" << value << " foo=" << foo_var);
void addTextMessage(const double x_frac, const double y_frac, const std::string &text, const size_t unique_index=0, const mrpt::opengl::TFontParams &fontParams=mrpt::opengl::TFontParams())
A shortcut for calling mrpt::opengl::COpenGLViewport::addTextMessage() in the "main" viewport of the ...
Monitor events in the visualization window.
~CWindowManager() override=default
Class destructor.
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
void addTextMessage(const double x, const double y, const std::string &text, const mrpt::img::TColorf &color=mrpt::img::TColorf(1.0, 1.0, 1.0), const size_t unique_index=0)
Wrapper around the CDisplayWindow3D::addTextMessage method, so that the user does not have to specify...
void initCWindowManager()
Initialization method, to be called from the various Constructors.
CWindowManager(mrpt::gui::CDisplayWindow3D *win_in)
Class constructor.
Class acts as a container for storing pointers to mrpt::gui::CDisplayWindow3D, mrpt::graphslam::CWind...
void assignTextMessageParameters(double *offset_y, int *text_index)
Assign the next available offset_y and text_index for the textMessage under construction.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020