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 }
CSetOfLines.h
mrpt::keep_min
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: core/include/mrpt/core/bits_math.h:124
glBegin
GLAPI void GLAPIENTRY glBegin(GLenum mode)
mrpt::opengl::CSetOfLines::getBoundingBox
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...
Definition: CSetOfLines.cpp:186
mrpt::opengl::CSetOfLines::m_antiAliasing
bool m_antiAliasing
Definition: CSetOfLines.h:39
mrpt::opengl::CSetOfLines::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CSetOfLines.cpp:126
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
s
GLdouble s
Definition: glext.h:3676
mrpt::opengl::CSetOfLines::render_dl
void render_dl() const override
Render.
Definition: CSetOfLines.cpp:66
GL_SRC_ALPHA
#define GL_SRC_ALPHA
Definition: glew.h:286
mrpt::math::dynamic_vector
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
Definition: eigen_frwds.h:44
mrpt::opengl::CSetOfLines::CSetOfLines
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:26
mrpt::opengl::CSetOfLines::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CSetOfLines.cpp:127
mrpt::opengl::CSetOfLines
A set of independent lines (or segments), one line with its own start and end positions (X,...
Definition: CSetOfLines.h:33
GL_BLEND
#define GL_BLEND
Definition: glew.h:432
glColor4ub
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
GL_LINE_SMOOTH
#define GL_LINE_SMOOTH
Definition: glew.h:367
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::math::TPoint3D::z
double z
Definition: lightweight_geom_data.h:385
glDisable
GLAPI void GLAPIENTRY glDisable(GLenum cap)
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
mrpt::opengl::CSetOfLines::mLineWidth
float mLineWidth
Definition: CSetOfLines.h:38
mrpt::img::TColor::R
uint8_t R
Definition: TColor.h:48
glEnable
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GL_POINT_SMOOTH
#define GL_POINT_SMOOTH
Definition: glew.h:363
stl_serialization.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::opengl::CSetOfLines::getVerticesPointSize
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:56
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::opengl::CSetOfLines::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CSetOfLines.cpp:135
glEnd
GLAPI void GLAPIENTRY glEnd(void)
mrpt::img::TColor::B
uint8_t B
Definition: TColor.h:48
GL_LINE_BIT
#define GL_LINE_BIT
Definition: glew.h:253
mrpt::opengl::CRenderizable::m_pose
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:57
mrpt::opengl::CRenderizable::m_color
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
mrpt::opengl::CRenderizable::checkOpenGLError
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: CRenderizable.cpp:301
GL_LIGHTING
#define GL_LIGHTING
Definition: glew.h:385
glLineWidth
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::opengl::CSetOfLines::m_verticesPointSize
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:41
GL_ONE_MINUS_SRC_ALPHA
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
glPushAttrib
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
mrpt::keep_max
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: core/include/mrpt/core/bits_math.h:131
mrpt::opengl::CSetOfLines::setLineByIndex
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:46
index
GLuint index
Definition: glext.h:4054
mrpt::math::TPoint3D::x
double x
X,Y,Z coordinates.
Definition: lightweight_geom_data.h:385
mrpt::opengl::CSetOfLines::mSegments
std::vector< mrpt::math::TSegment3D > mSegments
Definition: CSetOfLines.h:37
glVertex3d
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
GL_POINTS
#define GL_POINTS
Definition: glew.h:272
glPointSize
GLAPI void GLAPIENTRY glPointSize(GLfloat size)
mrpt::img::TColor::A
uint8_t A
Definition: TColor.h:48
mrpt::math::TSegment3D
3D segment, consisting of two points.
Definition: lightweight_geom_data.h:1044
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
GL_LINES
#define GL_LINES
Definition: glew.h:273
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
opengl-precomp.h
mrpt::math::TPoint3D::y
double y
Definition: lightweight_geom_data.h:385
mrpt::poses::CPose3D::composePoint
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
opengl_internals.h
glPopAttrib
GLAPI void GLAPIENTRY glPopAttrib(void)
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::img::TColor::G
uint8_t G
Definition: TColor.h:48
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
in
GLuint in
Definition: glext.h:7274
mrpt::opengl::CSetOfLines::getLineByIndex
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.
Definition: CSetOfLines.cpp:216
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::opengl::CRenderizable::writeToStreamRender
void writeToStreamRender(mrpt::serialization::CArchive &out) const
Definition: CRenderizable.cpp:110
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::opengl::CRenderizableDisplayList::readFromStreamRender
void readFromStreamRender(mrpt::serialization::CArchive &in)
Definition: CRenderizableDisplayList.h:65
first
GLint * first
Definition: glext.h:3827
mrpt::opengl::CSetOfLines::setVerticesPointSize
void setVerticesPointSize(const float size_points)
Enable showing vertices as dots if size_points>0.
Definition: CSetOfLines.cpp:57
glBlendFunc
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
GL_COLOR_BUFFER_BIT
#define GL_COLOR_BUFFER_BIT
Definition: glew.h:265



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST