MRPT  1.9.9
CSimpleLine.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
14 #include "opengl_internals.h"
15 
16 using namespace mrpt;
17 using namespace mrpt::opengl;
18 
19 using namespace mrpt::math;
20 using namespace std;
21 
23 
25  float x0, float y0, float z0, float x1, float y1, float z1, float lineWidth,
26  bool antiAliasing)
27  : m_x0(x0),
28  m_y0(y0),
29  m_z0(z0),
30  m_x1(x1),
31  m_y1(y1),
32  m_z1(z1),
33  m_lineWidth(lineWidth),
34  m_antiAliasing(antiAliasing)
35 {
36 }
37 
38 /*---------------------------------------------------------------
39  render_dl
40  ---------------------------------------------------------------*/
42 {
43 #if MRPT_HAS_OPENGL_GLUT
44  // Enable antialiasing:
45  if (m_antiAliasing)
46  {
51  }
52  glLineWidth(m_lineWidth);
53 
54  glDisable(GL_LIGHTING); // Disable lights when drawing lines
56 
57  glColor4ub(m_color.R, m_color.G, m_color.B, m_color.A);
58  glVertex3f(m_x0, m_y0, m_z0);
59  glVertex3f(m_x1, m_y1, m_z1);
60 
61  glEnd();
63  glEnable(GL_LIGHTING); // Disable lights when drawing lines
64 
65  // End antialiasing:
66  if (m_antiAliasing)
67  {
68  glPopAttrib();
70  }
71 #endif
72 }
73 
74 uint8_t CSimpleLine::serializeGetVersion() const { return 1; }
76 {
77  writeToStreamRender(out);
78  out << m_x0 << m_y0 << m_z0;
79  out << m_x1 << m_y1 << m_z1 << m_lineWidth;
80  out << m_antiAliasing; // Added in v1
81 }
82 
84  mrpt::serialization::CArchive& in, uint8_t version)
85 {
86  switch (version)
87  {
88  case 1:
89  {
90  readFromStreamRender(in);
91  in >> m_x0 >> m_y0 >> m_z0;
92  in >> m_x1 >> m_y1 >> m_z1 >> m_lineWidth;
93  if (version >= 1)
94  in >> m_antiAliasing;
95  else
96  m_antiAliasing = true;
97  }
98  break;
99  default:
101  };
103 }
104 
107 {
108  bb_min.x = std::min(m_x0, m_x1);
109  bb_min.y = std::min(m_y0, m_y1);
110  bb_min.z = std::min(m_z0, m_z1);
111 
112  bb_max.x = std::max(m_x0, m_x1);
113  bb_max.y = std::max(m_y0, m_y1);
114  bb_max.z = std::max(m_z0, m_z1);
115 
116  // Convert to coordinates of my parent:
117  m_pose.composePoint(bb_min, bb_min);
118  m_pose.composePoint(bb_max, bb_max);
119 }
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CSimpleLine.cpp:75
STL namespace.
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:288
GLAPI void GLAPIENTRY glPopAttrib(void)
#define GL_LIGHTING
Definition: glew.h:386
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
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:97
#define GL_COLOR_BUFFER_BIT
Definition: glew.h:266
This base provides a set of functions for maths stuff.
#define GL_LINE_SMOOTH
Definition: glew.h:368
void render_dl() const override
Render.
Definition: CSimpleLine.cpp:41
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:433
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...
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
#define GL_SRC_ALPHA
Definition: glew.h:287
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
A line segment.
Definition: CSimpleLine.h:19
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CSimpleLine.cpp:83
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:155
GLuint in
Definition: glext.h:7391
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
GLAPI void GLAPIENTRY glEnd(void)
const auto bb_min
#define GL_LINES
Definition: glew.h:274
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CSimpleLine.cpp:74
Lightweight 3D point.
Definition: TPoint3D.h:90
GLAPI void GLAPIENTRY glDisable(GLenum cap)
#define GL_LINE_BIT
Definition: glew.h:254



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: abb8b1a1e Fri Oct 18 14:19:12 2019 +0200 at vie oct 18 14:20:13 CEST 2019