Main MRPT website > C++ reference for MRPT 1.5.7
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 
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 using namespace mrpt::utils;
21 using namespace mrpt::math;
22 using namespace std;
23 
25 
26 CSetOfLinesPtr CSetOfLines::Create(const std::vector<TSegment3D> &sgms, const bool antiAliasing)
27 {
28  return CSetOfLinesPtr(new CSetOfLines(sgms,antiAliasing));
29 }
30 /** Constructor */
32  : mSegments(),mLineWidth(1.0),m_antiAliasing(true), m_verticesPointSize(.0f)
33 {
34 }
35 
36 /** Constructor with a initial set of lines. */
37 CSetOfLines::CSetOfLines(const std::vector<TSegment3D> &sgms,bool antiAliasing)
38  : mSegments(sgms),mLineWidth(1.0),m_antiAliasing(antiAliasing), m_verticesPointSize(.0f)
39 {
40 }
41 
42 /*---------------------------------------------------------------
43  setLineByIndex
44  ---------------------------------------------------------------*/
47  if (index>=mSegments.size()) THROW_EXCEPTION("Index out of bounds");
49  mSegments[index]=segm;
50  MRPT_END
51 }
52 
54 {
55  return m_verticesPointSize;
56 }
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  }
77  if (m_antiAliasing)
81 
82  glDisable(GL_LIGHTING); // Disable lights when drawing lines
85  for (std::vector<TSegment3D>::const_iterator it=mSegments.begin();it!=mSegments.end();++it) {
86  glVertex3d(it->point1.x,it->point1.y,it->point1.z);
87  glVertex3d(it->point2.x,it->point2.y,it->point2.z);
88  }
89  glEnd();
91 
92  // Draw vertices?
93  if (m_verticesPointSize > 0)
94  {
96  if (m_antiAliasing)
99 
102  bool first = true;
103  for (const auto &seg : mSegments)
104  {
105  if (first) {
106  glVertex3d(seg.point1.x, seg.point1.y, seg.point1.z);
107  first = false;
108  }
109  glVertex3d(seg.point2.x, seg.point2.y, seg.point2.z);
110  }
111 
112  glEnd();
113  }
114 
115  glEnable(GL_LIGHTING); // Disable lights when drawing lines
116 
117  // End of antialiasing:
118  glPopAttrib();
119 
120 #endif
121 }
122 
123 /*---------------------------------------------------------------
124  Implements the writing to a CStream capability of
125  CSerializable objects
126  ---------------------------------------------------------------*/
128 {
129  if (version) *version=4;
130  else {
131  writeToStreamRender(out);
132  out<<mSegments<<mLineWidth;
133  out << m_antiAliasing; // Added in v3
134  out << m_verticesPointSize; // v4
135  }
136 }
137 
138 /*---------------------------------------------------------------
139  Implements the reading from a CStream capability of
140  CSerializable objects
141  ---------------------------------------------------------------*/
143 {
144  switch(version)
145  {
146  case 0:
147  case 1:
148  {
150  CVectorFloat x0,y0,z0,x1,y1,z1;
151  in>>x0>>y0>>z0>>x1>>y1>>z1;
152  if (version>=1) in>>mLineWidth;
153  else mLineWidth=1;
154  size_t N=x0.size();
155  mSegments.resize(N);
156  for (size_t i=0;i<N;i++) {
157  mSegments[i][0][0]=x0[i];
158  mSegments[i][0][1]=y0[i];
159  mSegments[i][0][2]=z0[i];
160  mSegments[i][1][0]=x1[i];
161  mSegments[i][1][1]=y1[i];
162  mSegments[i][1][2]=z1[i];
163  }
164  } break;
165  case 2:
166  case 3:
167  case 4:
168  {
170  in>>mSegments;
171  in>>mLineWidth;
172  if (version>=3)
173  in >> m_antiAliasing;
174  else m_antiAliasing = true;
175  if (version >= 4)
177  else m_verticesPointSize = .0f;
178  }
179  break;
180  default:
182 
183  };
185 }
186 
188 {
189  bb_min = mrpt::math::TPoint3D(std::numeric_limits<double>::max(),std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
190  bb_max = mrpt::math::TPoint3D(-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max());
191 
192  for (size_t i=0;i<mSegments.size();i++)
193  {
194  const TSegment3D &s=mSegments[i];
195  for (size_t p=0;p<2;p++)
196  {
197  const TPoint3D &pt = s[p];
198  for (size_t j=0;j<3;j++)
199  {
200  keep_min(bb_min[j], pt[j]);
201  keep_max(bb_max[j], pt[j]);
202  }
203  }
204  }
205 
206  // Convert to coordinates of my parent:
207  m_pose.composePoint(bb_min, bb_min);
208  m_pose.composePoint(bb_max, bb_max);
209 }
210 
211 
212 void CSetOfLines::getLineByIndex(size_t index,double &x0,double &y0,double &z0,double &x1,double &y1,double &z1) const
213 {
214  ASSERT_(index<mSegments.size())
215  const mrpt::math::TPoint3D &p0 = mSegments[index].point1;
216  const mrpt::math::TPoint3D &p1 = mSegments[index].point2;
217  x0 = p0.x;
218  y0 = p0.y;
219  z0 = p0.z;
220  x1 = p1.x;
221  y1 = p1.y;
222  z1 = p1.z;
223 }
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.
Definition: zip.h:16
void render_dl() const MRPT_OVERRIDE
Render.
Definition: CSetOfLines.cpp:66
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:3703
#define THROW_EXCEPTION(msg)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:35
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.
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:42
const Scalar * const_iterator
Definition: eigen_plugins.h:24
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:283
GLAPI void GLAPIENTRY glPopAttrib(void)
GLdouble s
Definition: glext.h:3602
#define GL_LIGHTING
Definition: glew.h:381
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
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...
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference. This class automatically holds the cached 3x3 rotation m...
Definition: CRenderizable.h:55
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
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:261
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, 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:427
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
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:53
3D segment, consisting of two points.
#define MRPT_END
#define GL_LINE_SMOOTH
Definition: glew.h:363
GLuint index
Definition: glext.h:3891
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void readFromStreamRender(mrpt::utils::CStream &in)
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:359
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 glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
#define MRPT_START
#define GL_SRC_ALPHA
Definition: glew.h:282
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:31
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:171
GLuint in
Definition: glext.h:6301
The namespace for 3D scene representation and rendering.
#define ASSERT_(f)
GLAPI void GLAPIENTRY glEnd(void)
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...
#define GL_LINES
Definition: glew.h:269
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)
GLfloat GLfloat p
Definition: glext.h:5587
#define GL_LINE_BIT
Definition: glew.h:249
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:45



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