Main MRPT website > C++ reference for MRPT 1.5.7
CPlanarLaserScan.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #include "maps-precomp.h" // Precomp header
11 
12 
14 #include <mrpt/utils/CStream.h>
15 
16 
17 #if MRPT_HAS_OPENGL_GLUT
18  #ifdef MRPT_OS_WINDOWS
19  // Windows:
20  #include <windows.h>
21  #endif
22 
23  #ifdef MRPT_OS_APPLE
24  #include <OpenGL/gl.h>
25  #else
26  #include <GL/gl.h>
27  #endif
28 #endif
29 
30 // Include libraries in linking:
31 #if MRPT_HAS_OPENGL_GLUT && defined(MRPT_OS_WINDOWS)
32  // WINDOWS:
33  #if defined(_MSC_VER) || defined(__BORLANDC__)
34  #pragma comment (lib,"opengl32.lib")
35  #pragma comment (lib,"GlU32.lib")
36  #endif
37 #endif // MRPT_HAS_OPENGL_GLUT
38 
39 
40 using namespace mrpt;
41 using namespace mrpt::opengl;
42 using namespace mrpt::utils;
43 using namespace mrpt::math;
44 using namespace std;
45 
47 
48 
49 /*---------------------------------------------------------------
50  Constructor
51  ---------------------------------------------------------------*/
53  m_scan(),
54  m_cache_points(),
55  m_cache_valid(false),
56  m_line_width(1),
57  m_line_R(1.f),m_line_G(0.f),m_line_B(0.f),m_line_A(0.5f),
58  m_points_width(3),
59  m_points_R(1.0f),m_points_G(0.0f),m_points_B(0.0f),m_points_A(1.0f),
60  m_plane_R(0.01f),m_plane_G(0.01f),m_plane_B(0.6f),m_plane_A(0.6f),
61  m_enable_points(true), m_enable_line(true), m_enable_surface(true)
62 {
63 }
64 
65 /*---------------------------------------------------------------
66  clear
67  ---------------------------------------------------------------*/
69 {
71  m_scan.resizeScan(0);
72 }
73 
74 
75 /*---------------------------------------------------------------
76  render
77  ---------------------------------------------------------------*/
79 {
80 #if MRPT_HAS_OPENGL_GLUT
81  ASSERT_(m_scan.scan.size()==m_scan.validRange.size());
82 
83  // Load into cache:
84  if (!m_cache_valid)
85  {
86  m_cache_valid=true;
87  m_cache_points.clear();
88  m_cache_points.insertionOptions.minDistBetweenLaserPoints = 0;
89  m_cache_points.insertionOptions.isPlanarMap=false;
90 
91  m_cache_points.insertObservation( &m_scan );
92  }
93 
94  size_t i,n;
95  const float *x,*y,*z;
96 
97  m_cache_points.getPointsBuffer(n,x,y,z);
98  if (!n || !x) return;
99 
102 
103  // LINES
104  // ----------------------------
105  if (n>1 && m_enable_line)
106  {
107  glLineWidth(m_line_width); checkOpenGLError();
108 
109  glBegin( GL_LINES );
110  glColor4f( m_line_R,m_line_G,m_line_B,m_line_A );
111 
112  for (i=0;i<n-1;i++)
113  {
114  glVertex3f( x[i],y[i],z[i] );
115  glVertex3f( x[i+1],y[i+1],z[i+1] );
116  }
117  glEnd();
119  }
120 
121  // POINTS
122  // ----------------------------
123  if (n>0 && m_enable_points)
124  {
125  glPointSize(m_points_width);
127 
128  glBegin( GL_POINTS );
129  glColor4f( m_points_R,m_points_G,m_points_B,m_points_A );
130 
131  for (i=0;i<n;i++)
132  {
133  glVertex3f( x[i],y[i],z[i] );
134  }
135  glEnd();
137  }
138 
139  // SURFACE:
140  // ------------------------------
141  if (n>1 && m_enable_surface)
142  {
144 
145  glColor4f(m_plane_R,m_plane_G,m_plane_B,m_plane_A);
146 
147  for (i=0;i<n-1;i++)
148  {
149  glVertex3f( m_scan.sensorPose.x(), m_scan.sensorPose.y(), m_scan.sensorPose.z() );
150  glVertex3f( x[i],y[i],z[i] );
151  glVertex3f( x[i+1],y[i+1],z[i+1] );
152  }
153  glEnd();
155  }
156 
158 
159 #endif
160 }
161 
162 /*---------------------------------------------------------------
163  Implements the writing to a CStream capability of
164  CSerializable objects
165  ---------------------------------------------------------------*/
167 {
168 
169  if (version)
170  *version = 1;
171  else
172  {
173  writeToStreamRender(out);
174  out << m_scan;
175  out << m_line_width
176  << m_line_R << m_line_G << m_line_B << m_line_A
177  << m_points_width
178  << m_points_R << m_points_G << m_points_B << m_points_A
179  << m_plane_R << m_plane_G << m_plane_B << m_plane_A
180  << m_enable_points << m_enable_line << m_enable_surface; // new in v1
181  }
182 }
183 
184 /*---------------------------------------------------------------
185  Implements the reading from a CStream capability of
186  CSerializable objects
187  ---------------------------------------------------------------*/
189 {
190  switch(version)
191  {
192  case 0:
193  case 1:
194  {
195  readFromStreamRender(in);
196  in >> m_scan;
197  in >> m_line_width
198  >> m_line_R >> m_line_G >> m_line_B >> m_line_A
199  >> m_points_width
200  >> m_points_R >> m_points_G >> m_points_B >> m_points_A
201  >> m_plane_R >> m_plane_G >> m_plane_B >> m_plane_A;
202 
203  if (version>=1)
204  {
205  in >> m_enable_points >> m_enable_line >> m_enable_surface; // new in v1
206  }
207  else
208  {
209  m_enable_points = m_enable_line = m_enable_surface = true;
210  }
211  } break;
212  default:
214 
215  };
216 }
217 
218 
220 {
221  // Load into cache:
222  if (!m_cache_valid)
223  {
224  m_cache_valid=true;
225  m_cache_points.clear();
226  m_cache_points.insertionOptions.minDistBetweenLaserPoints = 0;
227  m_cache_points.insertionOptions.isPlanarMap=false;
228 
229  m_cache_points.insertObservation( &m_scan );
230  }
231 
232  size_t n;
233  const float *x,*y,*z;
234 
235  m_cache_points.getPointsBuffer(n,x,y,z);
236  if (!n || !x) return;
237 
238  bb_min = mrpt::math::TPoint3D(std::numeric_limits<double>::max(),std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
239  bb_max = mrpt::math::TPoint3D(-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max());
240 
241  for (size_t i=0;i<n;i++)
242  {
243  keep_min(bb_min.x, x[i]); keep_max(bb_max.x, x[i]);
244  keep_min(bb_min.y, y[i]); keep_max(bb_max.y, y[i]);
245  keep_min(bb_min.z, z[i]); keep_max(bb_max.z, z[i]);
246  }
247 
248  // Convert to coordinates of my parent:
249  m_pose.composePoint(bb_min, bb_min);
250  m_pose.composePoint(bb_max, bb_max);
251 }
252 
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
GLdouble GLdouble z
Definition: glext.h:3734
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glPointSize(GLfloat size)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLenum GLsizei n
Definition: glext.h:4618
#define GL_TRIANGLES
Definition: glew.h:272
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
STL namespace.
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:283
double z
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This object renders a 2D laser scan by means of three elements: the points, the line along end-points...
int version
Definition: mrpt_jpeglib.h:898
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:428
#define GL_POINTS
Definition: glew.h:268
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
Definition: bits.h:176
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
#define GL_SRC_ALPHA
Definition: glew.h:282
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
Definition: bits.h:171
void OPENGL_IMPEXP checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:134
GLuint in
Definition: glext.h:6301
The namespace for 3D scene representation and rendering.
#define ASSERT_(f)
GLAPI void GLAPIENTRY glEnd(void)
void render_dl() const MRPT_OVERRIDE
Render.
GLenum GLint GLint y
Definition: glext.h:3516
#define GL_LINES
Definition: glew.h:269
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
GLenum GLint x
Definition: glext.h:3516
Lightweight 3D point.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
void clear()
< Clear the scan
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019