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-2018, 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 
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 
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 
128 {
129  writeToStreamRender(out);
130  out << mSegments << mLineWidth;
131  out << m_antiAliasing; // Added in v3
132  out << m_verticesPointSize; // v4
133 }
134 
137 {
138  switch (version)
139  {
140  case 0:
141  case 1:
142  {
144  CVectorFloat x0, y0, z0, x1, y1, z1;
145  in >> x0 >> y0 >> z0 >> x1 >> y1 >> z1;
146  if (version >= 1)
147  in >> mLineWidth;
148  else
149  mLineWidth = 1;
150  size_t N = x0.size();
151  mSegments.resize(N);
152  for (size_t i = 0; i < N; i++)
153  {
154  mSegments[i][0][0] = x0[i];
155  mSegments[i][0][1] = y0[i];
156  mSegments[i][0][2] = z0[i];
157  mSegments[i][1][0] = x1[i];
158  mSegments[i][1][1] = y1[i];
159  mSegments[i][1][2] = z1[i];
160  }
161  }
162  break;
163  case 2:
164  case 3:
165  case 4:
166  {
168  in >> mSegments;
169  in >> mLineWidth;
170  if (version >= 3)
171  in >> m_antiAliasing;
172  else
173  m_antiAliasing = true;
174  if (version >= 4)
176  else
177  m_verticesPointSize = .0f;
178  }
179  break;
180  default:
182  };
184 }
185 
187  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
188 {
189  bb_min = mrpt::math::TPoint3D(
190  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
191  std::numeric_limits<double>::max());
192  bb_max = mrpt::math::TPoint3D(
193  -std::numeric_limits<double>::max(),
194  -std::numeric_limits<double>::max(),
195  -std::numeric_limits<double>::max());
196 
197  for (size_t i = 0; i < mSegments.size(); i++)
198  {
199  const TSegment3D& s = mSegments[i];
200  for (size_t p = 0; p < 2; p++)
201  {
202  const TPoint3D& pt = s[p];
203  for (size_t j = 0; j < 3; j++)
204  {
205  keep_min(bb_min[j], pt[j]);
206  keep_max(bb_max[j], pt[j]);
207  }
208  }
209  }
210 
211  // Convert to coordinates of my parent:
212  m_pose.composePoint(bb_min, bb_min);
213  m_pose.composePoint(bb_max, bb_max);
214 }
215 
217  size_t index, double& x0, double& y0, double& z0, double& x1, double& y1,
218  double& z1) const
219 {
220  ASSERT_(index < mSegments.size());
221  const mrpt::math::TPoint3D& p0 = mSegments[index].point1;
222  const mrpt::math::TPoint3D& p1 = mSegments[index].point2;
223  x0 = p0.x;
224  y0 = p0.y;
225  z0 = p0.z;
226  x1 = p1.x;
227  y1 = p1.y;
228  z1 = p1.z;
229 }
std::vector< mrpt::math::TSegment3D > mSegments
Definition: CSetOfLines.h:37
#define MRPT_START
Definition: exceptions.h:262
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
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
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:44
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.
uint8_t B
Definition: TColor.h:48
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:41
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
uint8_t G
Definition: TColor.h:48
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...
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
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
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
unsigned char uint8_t
Definition: rptypes.h:41
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
#define GL_COLOR_BUFFER_BIT
Definition: glew.h:265
This base provides a set of functions for maths stuff.
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...
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:56
3D segment, consisting of two points.
void writeToStreamRender(mrpt::serialization::CArchive &out) const
#define GL_LINE_SMOOTH
Definition: glew.h:367
GLuint index
Definition: glext.h:4054
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
X,Y,Z coordinates.
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
uint8_t R
Definition: TColor.h:48
void render_dl() const override
Render.
Definition: CSetOfLines.cpp:66
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
#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
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
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:379
#define MRPT_END
Definition: exceptions.h:266
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
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:33
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLfloat GLfloat p
Definition: glext.h:6305
const Scalar * const_iterator
Definition: eigen_plugins.h:27
void readFromStreamRender(mrpt::serialization::CArchive &in)
#define GL_LINE_BIT
Definition: glew.h:253
uint8_t A
Definition: TColor.h:48
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: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019