MRPT  1.9.9
COpenGLStandardObject.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 
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 
24 
25 #define COMPILE_TIME_ASSERT(N, expr) char dummy_constraint##N[expr]
26 
27 #if MRPT_HAS_OPENGL_GLUT
28 COMPILE_TIME_ASSERT(GLENUM, sizeof(GLenum) == sizeof(_GLENUM));
29 #endif
30 
31 /*---------------------------------------------------------------
32  render
33  ---------------------------------------------------------------*/
34 void renderFunc(TPoint3D p)
35 {
36 #if MRPT_HAS_OPENGL_GLUT
37  glVertex3f(p.x, p.y, p.z);
38 #else
40 #endif
41 }
42 
44 {
45 #if MRPT_HAS_OPENGL_GLUT
46  for_each(enabled.begin(), enabled.end(), glEnable);
48  // This line won't take any effect if GL_BLEND is not enabled, so it's safe
49  // to always execute it.
51  glColor4ub(m_color.R, m_color.G, m_color.B, m_color.A);
52  if (normal[0] || normal[1] || normal[2])
53  glNormal3f(normal[0], normal[1], normal[2]);
54  if (chunkSize == 0)
55  {
56  glBegin(type);
57  for_each(vertices.begin(), vertices.end(), renderFunc);
58  glEnd();
59  }
60  else
61  {
62  auto it = vertices.begin();
63  do
64  {
65  glBegin(type);
66  for_each(it, it + chunkSize, renderFunc);
67  it += chunkSize;
68  glEnd();
69  } while (it != vertices.end());
70  }
71  for_each(enabled.begin(), enabled.end(), glDisable);
72 #endif
73 }
74 
78 {
79  writeToStreamRender(out);
80  out << type << vertices << chunkSize << enabled;
81 }
82 
85 {
86  switch (version)
87  {
88  case 1:
89  {
90  readFromStreamRender(in);
91  in >> type >> vertices >> chunkSize >> enabled;
92  }
93  break;
94  default:
96  };
98 }
99 
101  const mrpt::poses::CPose3D& o, double& dist) const
102 {
104  MRPT_UNUSED_PARAM(dist);
105  // This object isn't intended to hold geometric properties. No trace ray
106  // should be performed on it.
107  return false;
108 }
109 
112 {
113  bb_min.x = 0;
114  bb_min.y = 0;
115  bb_min.z = 0;
116 
117  bb_max.x = 0;
118  bb_max.y = 0;
119  bb_max.z = 0;
120 
121  // Convert to coordinates of my parent:
122  m_pose.composePoint(bb_min, bb_min);
123  m_pose.composePoint(bb_max, bb_max);
124 }
125 
127 {
128  auto it = enabled.begin();
129  while (it != enabled.end())
130  {
131  if (*it == flag)
132  it = enabled.erase(it);
133  else
134  ++it;
135  }
137 }
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)
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
#define COMPILE_TIME_ASSERT(N, expr)
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:288
#define GL_SMOOTH
Definition: glew.h:636
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)
unsigned char uint8_t
Definition: rptypes.h:44
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
This base provides a set of functions for maths stuff.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
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...
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:207
#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:53
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
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
Objects of this class represent a generic openGL object without specific geometric properties...
Lightweight 3D point.
Definition: TPoint3D.h:90
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:6398
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3532
void render_dl() const override
Render.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019