Main MRPT website > C++ reference for MRPT 1.9.9
CSetOfLines.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 "opengl-precomp.h" // Precompiled header
11 
13 #include <mrpt/utils/CStream.h>
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::utils;
20 using namespace mrpt::math;
21 using namespace std;
22 
24 
25 /** Constructor */
27  : mSegments(),
28  mLineWidth(1.0),
29  m_antiAliasing(true),
30  m_verticesPointSize(.0f)
31 {
32 }
33 
34 /** Constructor with a initial set of lines. */
35 CSetOfLines::CSetOfLines(const std::vector<TSegment3D>& sgms, bool antiAliasing)
36  : mSegments(sgms),
37  mLineWidth(1.0),
38  m_antiAliasing(antiAliasing),
39  m_verticesPointSize(.0f)
40 {
41 }
42 
43 /*---------------------------------------------------------------
44  setLineByIndex
45  ---------------------------------------------------------------*/
47  size_t index, const mrpt::math::TSegment3D& segm)
48 {
50  if (index >= mSegments.size()) THROW_EXCEPTION("Index out of bounds");
52  mSegments[index] = segm;
53  MRPT_END
54 }
55 
57 void CSetOfLines::setVerticesPointSize(const float size_points)
58 {
59  m_verticesPointSize = size_points;
61 }
62 
63 /*---------------------------------------------------------------
64  render
65  ---------------------------------------------------------------*/
67 {
68 #if MRPT_HAS_OPENGL_GLUT
69 
70  // Enable antialiasing:
72  if (m_antiAliasing || m_color.A != 255)
73  {
76  }
80 
81  glDisable(GL_LIGHTING); // Disable lights when drawing lines
85  it != mSegments.end(); ++it)
86  {
87  glVertex3d(it->point1.x, it->point1.y, it->point1.z);
88  glVertex3d(it->point2.x, it->point2.y, it->point2.z);
89  }
90  glEnd();
92 
93  // Draw vertices?
94  if (m_verticesPointSize > 0)
95  {
97  if (m_antiAliasing)
99  else
101 
104  bool first = true;
105  for (const auto& seg : mSegments)
106  {
107  if (first)
108  {
109  glVertex3d(seg.point1.x, seg.point1.y, seg.point1.z);
110  first = false;
111  }
112  glVertex3d(seg.point2.x, seg.point2.y, seg.point2.z);
113  }
114 
115  glEnd();
116  }
117 
118  glEnable(GL_LIGHTING); // Disable lights when drawing lines
119 
120  // End of antialiasing:
121  glPopAttrib();
122 
123 #endif
124 }
125 
126 /*---------------------------------------------------------------
127  Implements the writing to a CStream capability of
128  CSerializable objects
129  ---------------------------------------------------------------*/
130 void CSetOfLines::writeToStream(mrpt::utils::CStream& out, int* version) const
131 {
132  if (version)
133  *version = 4;
134  else
135  {
136  writeToStreamRender(out);
137  out << mSegments << mLineWidth;
138  out << m_antiAliasing; // Added in v3
139  out << m_verticesPointSize; // v4
140  }
141 }
142 
143 /*---------------------------------------------------------------
144  Implements the reading from a CStream capability of
145  CSerializable objects
146  ---------------------------------------------------------------*/
148 {
149  switch (version)
150  {
151  case 0:
152  case 1:
153  {
155  CVectorFloat x0, y0, z0, x1, y1, z1;
156  in >> x0 >> y0 >> z0 >> x1 >> y1 >> z1;
157  if (version >= 1)
158  in >> mLineWidth;
159  else
160  mLineWidth = 1;
161  size_t N = x0.size();
162  mSegments.resize(N);
163  for (size_t i = 0; i < N; i++)
164  {
165  mSegments[i][0][0] = x0[i];
166  mSegments[i][0][1] = y0[i];
167  mSegments[i][0][2] = z0[i];
168  mSegments[i][1][0] = x1[i];
169  mSegments[i][1][1] = y1[i];
170  mSegments[i][1][2] = z1[i];
171  }
172  }
173  break;
174  case 2:
175  case 3:
176  case 4:
177  {
179  in >> mSegments;
180  in >> mLineWidth;
181  if (version >= 3)
182  in >> m_antiAliasing;
183  else
184  m_antiAliasing = true;
185  if (version >= 4)
187  else
188  m_verticesPointSize = .0f;
189  }
190  break;
191  default:
193  };
195 }
196 
198  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
199 {
200  bb_min = mrpt::math::TPoint3D(
201  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
202  std::numeric_limits<double>::max());
203  bb_max = mrpt::math::TPoint3D(
204  -std::numeric_limits<double>::max(),
205  -std::numeric_limits<double>::max(),
206  -std::numeric_limits<double>::max());
207 
208  for (size_t i = 0; i < mSegments.size(); i++)
209  {
210  const TSegment3D& s = mSegments[i];
211  for (size_t p = 0; p < 2; p++)
212  {
213  const TPoint3D& pt = s[p];
214  for (size_t j = 0; j < 3; j++)
215  {
216  keep_min(bb_min[j], pt[j]);
217  keep_max(bb_max[j], pt[j]);
218  }
219  }
220  }
221 
222  // Convert to coordinates of my parent:
223  m_pose.composePoint(bb_min, bb_min);
224  m_pose.composePoint(bb_max, bb_max);
225 }
226 
228  size_t index, double& x0, double& y0, double& z0, double& x1, double& y1,
229  double& z1) const
230 {
231  ASSERT_(index < mSegments.size())
232  const mrpt::math::TPoint3D& p0 = mSegments[index].point1;
233  const mrpt::math::TPoint3D& p1 = mSegments[index].point2;
234  x0 = p0.x;
235  y0 = p0.y;
236  z0 = p0.z;
237  x1 = p1.x;
238  y1 = p1.y;
239  z1 = p1.z;
240 }
std::vector< mrpt::math::TSegment3D > mSegments
Definition: CSetOfLines.h:39
void writeToStreamRender(utils::CStream &out) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glPointSize(GLfloat size)
void getLineByIndex(size_t index, double &x0, double &y0, double &z0, double &x1, double &y1, double &z1) const
Gets a specific line in the set, given its index.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLint * first
Definition: glext.h:3827
#define THROW_EXCEPTION(msg)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
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.
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...
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:43
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
GLAPI void GLAPIENTRY glPopAttrib(void)
GLdouble s
Definition: glext.h:3676
#define GL_LIGHTING
Definition: glew.h:385
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:57
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define GL_COLOR_BUFFER_BIT
Definition: glew.h:265
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
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:56
3D segment, consisting of two points.
#define MRPT_END
#define GL_LINE_SMOOTH
Definition: glew.h:367
GLuint index
Definition: glext.h:4054
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void readFromStreamRender(mrpt::utils::CStream &in)
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...
mrpt::utils::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
void setVerticesPointSize(const float size_points)
Enable showing vertices as dots if size_points>0.
Definition: CSetOfLines.cpp:57
#define GL_POINT_SMOOTH
Definition: glew.h:363
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
void render_dl() const override
Render.
Definition: CSetOfLines.cpp:66
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
#define MRPT_START
#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.
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:26
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
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 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
GLuint in
Definition: glext.h:7274
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
#define ASSERT_(f)
GLAPI void GLAPIENTRY glEnd(void)
#define GL_LINES
Definition: glew.h:273
Lightweight 3D point.
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:35
GLAPI void GLAPIENTRY glDisable(GLenum cap)
INT32 z1
Definition: jidctint.cpp:130
GLfloat GLfloat p
Definition: glext.h:6305
#define GL_LINE_BIT
Definition: glew.h:253
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:46



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