MRPT  1.9.9
CTexturedPlane.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 
16 #include "opengl_internals.h"
17 
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 using namespace mrpt::poses;
21 
22 using namespace mrpt::math;
23 using namespace std;
24 
26 
28  float x_min, float x_max, float y_min, float y_max)
29 
30 {
31  // Copy data:
32  m_xMin = x_min;
33  m_xMax = x_max;
34  m_yMin = y_min;
35  m_yMax = y_max;
36 }
37 
38 /*---------------------------------------------------------------
39  ~CTexturedPlane
40  ---------------------------------------------------------------*/
42 /*---------------------------------------------------------------
43  render
44  ---------------------------------------------------------------*/
46 {
47 #if MRPT_HAS_OPENGL_GLUT
49 
50  // Compute the exact texture coordinates:
51  m_tex_x_min = 0;
52  m_tex_x_max = 1.0f - ((float)m_pad_x_right) / r_width;
53  m_tex_y_min = 0;
54  m_tex_y_max = 1.0f - ((float)m_pad_y_bottom) / r_height;
55 
58 
59  glTexCoord2d(m_tex_x_min, m_tex_y_min);
60  glVertex3f(m_xMin, m_yMin, 0);
61 
62  glTexCoord2d(m_tex_x_max, m_tex_y_min);
63  glVertex3f(m_xMax, m_yMin, 0);
64 
65  glTexCoord2d(m_tex_x_max, m_tex_y_max);
66  glVertex3f(m_xMax, m_yMax, 0);
67 
68  glTexCoord2d(m_tex_x_min, m_tex_y_max);
69  glVertex3f(m_xMin, m_yMax, 0);
70 
71  glEnd();
73 
74  MRPT_END
75 #endif
76 }
77 
80 {
81  writeToStreamRender(out);
82 
83  out << m_xMin << m_xMax;
84  out << m_yMin << m_yMax;
85 
86  writeToStreamTexturedObject(out);
87 }
88 
91 {
92  switch (version)
93  {
94  case 0:
95  {
96  readFromStreamRender(in);
97  in >> m_textureImage >> m_textureImageAlpha;
98  in >> m_xMin >> m_xMax;
99  in >> m_yMin >> m_yMax;
100 
101  assignImage(m_textureImage, m_textureImageAlpha);
102  }
103  break;
104  case 1:
105  case 2:
106  {
107  readFromStreamRender(in);
108 
109  in >> m_xMin >> m_xMax;
110  in >> m_yMin >> m_yMax;
111 
112  if (version >= 2)
113  {
114  readFromStreamTexturedObject(in);
115  }
116  else
117  { // Old version.
121  {
123  assignImage(
126  }
127  else
128  assignImage(CTexturedObject::m_textureImage);
129  }
130  }
131  break;
132  default:
134  };
136 }
137 
138 bool CTexturedPlane::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
139 {
140  if (!polygonUpToDate) updatePoly();
141  return math::traceRay(tmpPoly, (o - this->m_pose).asTPose(), dist);
142 }
143 
145 {
146  TPolygon3D poly(4);
147  poly[0].x = poly[1].x = m_xMin;
148  poly[2].x = poly[3].x = m_xMax;
149  poly[0].y = poly[3].y = m_yMin;
150  poly[1].y = poly[2].y = m_yMax;
151  for (size_t i = 0; i < 4; i++) poly[i].z = 0;
152  tmpPoly.resize(1);
153  tmpPoly[0] = poly;
154  polygonUpToDate = true;
155 }
156 
159 {
160  bb_min.x = std::min(m_xMin, m_xMax);
161  bb_min.y = std::min(m_yMin, m_yMax);
162  bb_min.z = 0;
163 
164  bb_max.x = std::max(m_xMin, m_xMax);
165  bb_max.y = std::max(m_yMin, m_yMax);
166  bb_max.z = 0;
167 
168  // Convert to coordinates of my parent:
169  m_pose.composePoint(bb_min, bb_min);
170  m_pose.composePoint(bb_max, bb_max);
171 }
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
#define MRPT_START
Definition: exceptions.h:241
GLdouble GLdouble z
Definition: glext.h:3879
#define min(a, b)
A base class for all OpenGL objects with loadable textures.
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::math::TPose3D &pose, double &dist)
Fast ray tracing method using polygons&#39; properties.
Definition: geometry.cpp:2567
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
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_CULL_FACE
Definition: glew.h:383
STL namespace.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
A 2D plane in the XY plane with a texture image.
void render_texturedobj() const override
Must be implemented by derived classes.
unsigned char uint8_t
Definition: rptypes.h:44
#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.
bool m_enableTransparency
Of the texture using "m_textureImageAlpha".
#define GL_QUADS
Definition: glew.h:280
~CTexturedPlane() override
Private, virtual destructor: only can be deleted from smart pointers.
GLAPI void GLAPIENTRY glBegin(GLenum mode)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
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
mrpt::img::CImage m_textureImage
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:155
#define MRPT_END
Definition: exceptions.h:245
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)
mrpt::img::CImage m_textureImageAlpha
GLAPI void GLAPIENTRY glTexCoord2d(GLdouble s, GLdouble t)
const auto bb_min
Lightweight 3D point.
Definition: TPoint3D.h:90
GLAPI void GLAPIENTRY glDisable(GLenum cap)
static math::TPolygon3D tmpPoly(3)
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:18



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