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 }
#define COMPILE_TIME_ASSERT(N, expr)
IMPLEMENTS_SERIALIZABLE(COpenGLStandardObject, CRenderizableDisplayList, mrpt::opengl) void renderFunc(TPoint3D p)
Objects of this class represent a generic openGL object without specific geometric properties.
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...
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...
void disable(_GLENUM flag)
Disable some openGL flag.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
virtual void render_dl() const override
Render.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray Tracing.
A renderizable object suitable for rendering with OpenGL's display lists.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:89
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:42
Scalar * iterator
Definition: eigen_plugins.h:26
const Scalar * const_iterator
Definition: eigen_plugins.h:27
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define GL_SRC_ALPHA
Definition: glew.h:286
#define GL_SMOOTH
Definition: glew.h:635
unsigned int GLenum
Definition: glew.h:206
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
GLAPI void GLAPIENTRY glEnd(void)
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3528
GLuint in
Definition: glext.h:7274
GLfloat GLfloat p
Definition: glext.h:6305
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: mrpt_macros.h:181
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Definition: mrpt_macros.h:365
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:20
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:16
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:18
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Lightweight 3D point.
double x
X,Y,Z coordinates.



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST