Main MRPT website > C++ reference for MRPT 1.9.9
COpenGLStandardObject.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 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::math;
20 using namespace mrpt::poses;
21 using namespace mrpt::utils;
22 
25 
26 #define COMPILE_TIME_ASSERT(N, expr) char dummy_constraint##N[expr]
27 
28 #if MRPT_HAS_OPENGL_GLUT
29 COMPILE_TIME_ASSERT(GLENUM, sizeof(GLenum) == sizeof(_GLENUM));
30 #endif
31 
32 /*---------------------------------------------------------------
33  render
34  ---------------------------------------------------------------*/
35 void renderFunc(TPoint3D p)
36 {
37 #if MRPT_HAS_OPENGL_GLUT
38  glVertex3f(p.x, p.y, p.z);
39 #else
41 #endif
42 }
43 
45 {
46 #if MRPT_HAS_OPENGL_GLUT
47  for_each(enabled.begin(), enabled.end(), glEnable);
49  // This line won't take any effect if GL_BLEND is not enabled, so it's safe
50  // to always execute it.
52  glColor4ub(m_color.R, m_color.G, m_color.B, m_color.A);
53  if (normal[0] || normal[1] || normal[2])
54  glNormal3f(normal[0], normal[1], normal[2]);
55  if (chunkSize == 0)
56  {
57  glBegin(type);
58  for_each(vertices.begin(), vertices.end(), renderFunc);
59  glEnd();
60  }
61  else
62  {
63  std::vector<TPoint3D>::const_iterator it = vertices.begin();
64  do
65  {
66  glBegin(type);
67  for_each(it, it + chunkSize, renderFunc);
68  it += chunkSize;
69  glEnd();
70  } while (it != vertices.end());
71  }
72  for_each(enabled.begin(), enabled.end(), glDisable);
73 #endif
74 }
75 /*---------------------------------------------------------------
76  Implements the writing to a CStream capability of
77  CSerializable objects
78  ---------------------------------------------------------------*/
80  mrpt::utils::CStream& out, int* version) const
81 {
82  if (version)
83  *version = 1;
84  else
85  {
86  writeToStreamRender(out);
87  out << type << vertices << chunkSize << enabled;
88  }
89 }
90 
91 /*---------------------------------------------------------------
92  Implements the reading from a CStream capability of
93  CSerializable objects
94  ---------------------------------------------------------------*/
96  mrpt::utils::CStream& in, int version)
97 {
98  switch (version)
99  {
100  case 1:
101  {
102  readFromStreamRender(in);
103  in >> type >> vertices >> chunkSize >> enabled;
104  }
105  break;
106  default:
108  };
110 }
111 
113  const mrpt::poses::CPose3D& o, double& dist) const
114 {
116  MRPT_UNUSED_PARAM(dist);
117  // This object isn't intended to hold geometric properties. No trace ray
118  // should be performed on it.
119  return false;
120 }
121 
123  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
124 {
125  bb_min.x = 0;
126  bb_min.y = 0;
127  bb_min.z = 0;
128 
129  bb_max.x = 0;
130  bb_max.y = 0;
131  bb_max.z = 0;
132 
133  // Convert to coordinates of my parent:
134  m_pose.composePoint(bb_min, bb_min);
135  m_pose.composePoint(bb_max, bb_max);
136 }
137 
139 {
140  std::vector<_GLENUM>::iterator it = enabled.begin();
141  while (it != enabled.end())
142  {
143  if (*it == flag)
144  it = enabled.erase(it);
145  else
146  ++it;
147  }
149 }
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define COMPILE_TIME_ASSERT(N, expr)
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
Scalar * iterator
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
#define GL_SMOOTH
Definition: glew.h:635
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
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 glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
double x
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glBegin(GLenum mode)
IMPLEMENTS_SERIALIZABLE(COpenGLStandardObject, CRenderizableDisplayList, mrpt::opengl) void renderFunc(TPoint3D p)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
void disable(_GLENUM flag)
Disable some openGL flag.
unsigned int GLenum
Definition: glew.h:206
#define GL_SRC_ALPHA
Definition: glew.h:286
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
GLAPI void GLAPIENTRY glEnd(void)
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
Objects of this class represent a generic openGL object without specific geometric properties...
Lightweight 3D point.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray Tracing.
GLfloat GLfloat p
Definition: glext.h:6305
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3528
virtual void render_dl() const override
Render.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019