Main MRPT website > C++ reference for MRPT 1.9.9
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 
13 #include <mrpt/utils/CStream.h>
14 
15 #if MRPT_HAS_OPENGL_GLUT
16 #ifdef MRPT_OS_WINDOWS
17 // Windows:
18 #include <windows.h>
19 #endif
20 
21 #ifdef MRPT_OS_APPLE
22 #include <OpenGL/gl.h>
23 #else
24 #include <GL/gl.h>
25 #endif
26 #endif
27 
28 // Include libraries in linking:
29 #if MRPT_HAS_OPENGL_GLUT && defined(MRPT_OS_WINDOWS)
30 // WINDOWS:
31 #if defined(_MSC_VER) || defined(__BORLANDC__)
32 #pragma comment(lib, "opengl32.lib")
33 #pragma comment(lib, "GlU32.lib")
34 #endif
35 #endif // MRPT_HAS_OPENGL_GLUT
36 
37 using namespace mrpt;
38 using namespace mrpt::opengl;
39 using namespace mrpt::utils;
40 using namespace mrpt::math;
41 using namespace std;
42 
45 
46 /*---------------------------------------------------------------
47  Constructor
48  ---------------------------------------------------------------*/
50  : m_scan(),
51  m_cache_points(),
52  m_cache_valid(false),
53  m_line_width(1),
54  m_line_R(1.f),
55  m_line_G(0.f),
56  m_line_B(0.f),
57  m_line_A(0.5f),
58  m_points_width(3),
59  m_points_R(1.0f),
60  m_points_G(0.0f),
61  m_points_B(0.0f),
62  m_points_A(1.0f),
63  m_plane_R(0.01f),
64  m_plane_G(0.01f),
65  m_plane_B(0.6f),
66  m_plane_A(0.6f),
67  m_enable_points(true),
68  m_enable_line(true),
69  m_enable_surface(true)
70 {
71 }
72 
73 /*---------------------------------------------------------------
74  clear
75  ---------------------------------------------------------------*/
77 {
79  m_scan.resizeScan(0);
80 }
81 
82 /*---------------------------------------------------------------
83  render
84  ---------------------------------------------------------------*/
86 {
87 #if MRPT_HAS_OPENGL_GLUT
89 
90  // Load into cache:
91  if (!m_cache_valid)
92  {
93  m_cache_valid = true;
97 
99  }
100 
101  size_t i, n;
102  const float *x, *y, *z;
103 
105  if (!n || !x) return;
106 
109 
110  // LINES
111  // ----------------------------
112  if (n > 1 && m_enable_line)
113  {
116 
117  glBegin(GL_LINES);
119 
120  for (i = 0; i < n - 1; i++)
121  {
122  glVertex3f(x[i], y[i], z[i]);
123  glVertex3f(x[i + 1], y[i + 1], z[i + 1]);
124  }
125  glEnd();
127  }
128 
129  // POINTS
130  // ----------------------------
131  if (n > 0 && m_enable_points)
132  {
135 
138 
139  for (i = 0; i < n; i++)
140  {
141  glVertex3f(x[i], y[i], z[i]);
142  }
143  glEnd();
145  }
146 
147  // SURFACE:
148  // ------------------------------
149  if (n > 1 && m_enable_surface)
150  {
152 
154 
155  for (i = 0; i < n - 1; i++)
156  {
157  glVertex3f(
159  m_scan.sensorPose.z());
160  glVertex3f(x[i], y[i], z[i]);
161  glVertex3f(x[i + 1], y[i + 1], z[i + 1]);
162  }
163  glEnd();
165  }
166 
168 
169 #endif
170 }
171 
172 /*---------------------------------------------------------------
173  Implements the writing to a CStream capability of
174  CSerializable objects
175  ---------------------------------------------------------------*/
177  mrpt::utils::CStream& out, int* version) const
178 {
179  if (version)
180  *version = 1;
181  else
182  {
183  writeToStreamRender(out);
184  out << m_scan;
185  out << m_line_width << m_line_R << m_line_G << m_line_B << m_line_A
189  << m_enable_surface; // new in v1
190  }
191 }
192 
193 /*---------------------------------------------------------------
194  Implements the reading from a CStream capability of
195  CSerializable objects
196  ---------------------------------------------------------------*/
198 {
199  switch (version)
200  {
201  case 0:
202  case 1:
203  {
205  in >> m_scan;
206  in >> m_line_width >> m_line_R >> m_line_G >> m_line_B >>
209  m_plane_B >> m_plane_A;
210 
211  if (version >= 1)
212  {
214  m_enable_surface; // new in v1
215  }
216  else
217  {
219  }
220  }
221  break;
222  default:
224  };
225 }
226 
228  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
229 {
230  // Load into cache:
231  if (!m_cache_valid)
232  {
233  m_cache_valid = true;
237 
239  }
240 
241  size_t n;
242  const float *x, *y, *z;
243 
245  if (!n || !x) return;
246 
247  bb_min = mrpt::math::TPoint3D(
248  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
249  std::numeric_limits<double>::max());
250  bb_max = mrpt::math::TPoint3D(
251  -std::numeric_limits<double>::max(),
252  -std::numeric_limits<double>::max(),
253  -std::numeric_limits<double>::max());
254 
255  for (size_t i = 0; i < n; i++)
256  {
257  keep_min(bb_min.x, x[i]);
258  keep_max(bb_max.x, x[i]);
259  keep_min(bb_min.y, y[i]);
260  keep_max(bb_max.y, y[i]);
261  keep_min(bb_min.z, z[i]);
262  keep_max(bb_max.z, z[i]);
263  }
264 
265  // Convert to coordinates of my parent:
266  m_pose.composePoint(bb_min, bb_min);
267  m_pose.composePoint(bb_max, bb_max);
268 }
void clear()
Erase all the contents of the map.
Definition: CMetricMap.cpp:31
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
bool isPlanarMap
If set to true, only HORIZONTAL (in the XY plane) measurements will be inserted in the map (Default v...
Definition: CPointsMap.h:236
void writeToStreamRender(utils::CStream &out) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLdouble GLdouble z
Definition: glext.h:3872
GLAPI void GLAPIENTRY glEnable(GLenum cap)
mrpt::maps::CSimplePointsMap m_cache_points
GLAPI void GLAPIENTRY glPointSize(GLfloat size)
GLenum GLsizei n
Definition: glext.h:5074
#define GL_TRIANGLES
Definition: glew.h:276
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:287
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:57
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:189
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
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.
void render_dl() const override
Render.
void readFromStreamRender(mrpt::utils::CStream &in)
mrpt::utils::ContainerReadOnlyProxyAccessor< std::vector< char > > validRange
It&#39;s false (=0) on no reflected rays, referenced to elements in scan.
This object renders a 2D laser scan by means of three elements: the points, the line along end-points...
double x
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:432
#define GL_POINTS
Definition: glew.h:272
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:227
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
mrpt::obs::CObservation2DRangeScan m_scan
#define GL_SRC_ALPHA
Definition: glew.h:286
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void getPointsBuffer(size_t &outPointsCount, const float *&xs, const float *&ys, const float *&zs) const
Provides a direct access to points buffer, or nullptr if there is no points in the map...
Definition: CPointsMap.cpp:259
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:220
void resizeScan(const size_t len)
Resizes all data vectors to allocate a given number of scan rays.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
Definition: CPose3D.cpp:453
IMPLEMENTS_SERIALIZABLE(CPlanarLaserScan, CRenderizableDisplayList, mrpt::opengl) CPlanarLaserScan
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
#define ASSERT_(f)
GLAPI void GLAPIENTRY glEnd(void)
GLenum GLint GLint y
Definition: glext.h:3538
TInsertionOptions insertionOptions
The options used when inserting observations in the map.
Definition: CPointsMap.h:256
#define GL_LINES
Definition: glew.h:273
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
GLenum GLint x
Definition: glext.h:3538
mrpt::utils::ContainerReadOnlyProxyAccessor< std::vector< float > > scan
The range values of the scan, in meters.
Lightweight 3D point.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
bool insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=NULL)
Insert the observation information into this map.
Definition: CMetricMap.cpp:95
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
float minDistBetweenLaserPoints
The minimum distance between points (in 3D): If two points are too close, one of them is not inserted...
Definition: CPointsMap.h:217



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019