MRPT  1.9.9
CGridPlaneXY.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 
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 
20 using namespace std;
21 
23 
24 /** Constructor */
26  float xMin, float xMax, float yMin, float yMax, float z, float frequency,
27  float lineWidth, bool antiAliasing)
28  : m_xMin(xMin),
29  m_xMax(xMax),
30  m_yMin(yMin),
31  m_yMax(yMax),
32  m_plane_z(z),
33  m_frequency(frequency),
34  m_lineWidth(lineWidth),
35  m_antiAliasing(antiAliasing)
36 {
37 }
38 
39 /*---------------------------------------------------------------
40  render_dl
41  ---------------------------------------------------------------*/
43 {
44 #if MRPT_HAS_OPENGL_GLUT
45  ASSERT_(m_frequency >= 0);
46 
47  // Enable antialiasing:
48  if (m_antiAliasing)
49  {
54  }
55  glLineWidth(m_lineWidth);
56 
57  glDisable(GL_LIGHTING); // Disable lights when drawing lines
59 
60  for (float y = m_yMin; y <= m_yMax; y += m_frequency)
61  {
62  glVertex3f(m_xMin, y, m_plane_z);
63  glVertex3f(m_xMax, y, m_plane_z);
64  }
65 
66  for (float x = m_xMin; x <= m_xMax; x += m_frequency)
67  {
68  glVertex3f(x, m_yMin, m_plane_z);
69  glVertex3f(x, m_yMax, m_plane_z);
70  }
71 
72  glEnd();
74 
75  // End antialiasing:
76  if (m_antiAliasing)
77  {
78  glPopAttrib();
80  }
81 #endif
82 }
83 
84 uint8_t CGridPlaneXY::serializeGetVersion() const { return 1; }
86 {
87  writeToStreamRender(out);
88  out << m_xMin << m_xMax;
89  out << m_yMin << m_yMax << m_plane_z;
90  out << m_frequency;
91  out << m_lineWidth << m_antiAliasing; // v1
92 }
93 
95  mrpt::serialization::CArchive& in, uint8_t version)
96 {
97  switch (version)
98  {
99  case 0:
100  case 1:
101  {
102  readFromStreamRender(in);
103  in >> m_xMin >> m_xMax;
104  in >> m_yMin >> m_yMax >> m_plane_z;
105  in >> m_frequency;
106  if (version >= 1)
107  in >> m_lineWidth >> m_antiAliasing;
108  else
109  {
110  m_lineWidth = 1.0f;
111  m_antiAliasing = true;
112  }
113  }
114  break;
115  default:
117  };
119 }
120 
123 {
124  bb_min.x = m_xMin;
125  bb_min.y = m_yMin;
126  bb_min.z = 0;
127 
128  bb_max.x = m_xMax;
129  bb_max.y = m_yMax;
130  bb_max.z = 0;
131 
132  // Convert to coordinates of my parent:
133  m_pose.composePoint(bb_min, bb_min);
134  m_pose.composePoint(bb_max, bb_max);
135 }
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
GLdouble GLdouble z
Definition: glext.h:3879
A grid of lines over the XY plane.
Definition: CGridPlaneXY.h:29
GLAPI void GLAPIENTRY glEnable(GLenum cap)
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void render_dl() const override
Render.
STL namespace.
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:288
GLAPI void GLAPIENTRY glPopAttrib(void)
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...
#define GL_LIGHTING
Definition: glew.h:386
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
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 ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
#define GL_COLOR_BUFFER_BIT
Definition: glew.h:266
#define GL_LINE_SMOOTH
Definition: glew.h:368
GLAPI void GLAPIENTRY glBegin(GLenum mode)
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
#define GL_BLEND
Definition: glew.h:433
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
#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
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
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)
GLenum GLint GLint y
Definition: glext.h:3542
const auto bb_min
#define GL_LINES
Definition: glew.h:274
GLenum GLint x
Definition: glext.h:3542
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