Main MRPT website > C++ reference for MRPT 1.5.7
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 
24 
25 #define COMPILE_TIME_ASSERT(N,expr) \
26  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 COpenGLStandardObjectPtr COpenGLStandardObject::Create(_GLENUM t,const std::vector<TPoint3D> &v,uint32_t cs,const std::vector<_GLENUM> &en)
33 {
34  if (cs!=0&&v.size()%cs!=0) throw std::logic_error("Vertices vector does not match chunk size");
35  return COpenGLStandardObjectPtr(new COpenGLStandardObject(t,v,cs,en));
36 }
37 
38 /*---------------------------------------------------------------
39  render
40  ---------------------------------------------------------------*/
42 #if MRPT_HAS_OPENGL_GLUT
43  glVertex3f(p.x,p.y,p.z);
44 #else
46 #endif
47 }
48 
50 #if MRPT_HAS_OPENGL_GLUT
51  for_each(enabled.begin(),enabled.end(),glEnable);
53  //This line won't take any effect if GL_BLEND is not enabled, so it's safe to always execute it.
55  glColor4ub(m_color.R,m_color.G,m_color.B,m_color.A);
56  if (normal[0]||normal[1]||normal[2]) glNormal3f(normal[0],normal[1],normal[2]);
57  if (chunkSize==0) {
58  glBegin(type);
59  for_each(vertices.begin(),vertices.end(),renderFunc);
60  glEnd();
61  } else {
62  std::vector<TPoint3D>::const_iterator it=vertices.begin();
63  do {
64  glBegin(type);
65  for_each(it,it+chunkSize,renderFunc);
66  it+=chunkSize;
67  glEnd();
68  } while (it!=vertices.end());
69  }
70  for_each(enabled.begin(),enabled.end(),glDisable);
71 #endif
72 }
73 /*---------------------------------------------------------------
74  Implements the writing to a CStream capability of
75  CSerializable objects
76  ---------------------------------------------------------------*/
78  if (version) *version=1;
79  else {
80  writeToStreamRender(out);
81  out<< type <<vertices<<chunkSize<<enabled;
82  }
83 }
84 
85 /*---------------------------------------------------------------
86  Implements the reading from a CStream capability of
87  CSerializable objects
88  ---------------------------------------------------------------*/
90  switch (version) {
91  case 1: {
92  readFromStreamRender(in);
93  in>>type>>vertices>>chunkSize>>enabled;
94  }
95  break;
96  default:
98  };
100 }
101 
102 bool COpenGLStandardObject::traceRay(const mrpt::poses::CPose3D &o,double &dist) const {
104  //This object isn't intended to hold geometric properties. No trace ray should be performed on it.
105  return false;
106 }
107 
108 
110 {
111  bb_min.x = 0;
112  bb_min.y = 0;
113  bb_min.z = 0;
114 
115  bb_max.x = 0;
116  bb_max.y = 0;
117  bb_max.z = 0;
118 
119  // Convert to coordinates of my parent:
120  m_pose.composePoint(bb_min, bb_min);
121  m_pose.composePoint(bb_max, bb_max);
122 }
123 
124 
126 {
127  std::vector<_GLENUM>::iterator it = enabled.begin();
128  while (it!=enabled.end())
129  {
130  if (*it==flag)
131  it = enabled.erase(it);
132  else ++it;
133  }
135 }
void renderFunc(TPoint3D p)
#define COMPILE_TIME_ASSERT(N, expr)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Objects of this class represent a generic openGL object without specific geometric properties.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const MRPT_OVERRIDE
Ray Tracing.
void disable(_GLENUM flag)
Disable some openGL flag.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
virtual void render_dl() const MRPT_OVERRIDE
Render.
static COpenGLStandardObjectPtr Create()
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:73
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:39
Scalar * iterator
Definition: eigen_plugins.h:23
const Scalar * const_iterator
Definition: eigen_plugins.h:24
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define GL_SRC_ALPHA
Definition: glew.h:282
#define GL_SMOOTH
Definition: glew.h:631
unsigned int GLenum
Definition: glew.h:202
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:283
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)
GLdouble GLdouble t
Definition: glext.h:3610
const GLdouble * v
Definition: glext.h:3603
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3512
GLuint in
Definition: glext.h:6301
GLfloat GLfloat p
Definition: glext.h:5587
int version
Definition: mrpt_jpeglib.h:898
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: mrpt_macros.h:217
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Definition: mrpt_macros.h:307
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:20
The namespace for 3D scene representation and rendering.
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,...
Definition: zip.h:16
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int32 uint32_t
Definition: rptypes.h:49
Lightweight 3D point.
double z
X,Y,Z coordinates.



Page generated by Doxygen 1.9.1 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at mar 26 may 2026 13:12:03 CEST