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  // Copy data:
31  m_xMin = x_min;
32  m_xMax = x_max;
33  m_yMin = y_min;
34  m_yMax = y_max;
35 }
36 
38 
40 {
41 #if MRPT_HAS_OPENGL_GLUT
43 
44  // Compute the exact texture coordinates:
45  m_tex_x_min = 0;
46  m_tex_x_max = 1.0f - ((float)m_pad_x_right) / r_width;
47  m_tex_y_min = 0;
48  m_tex_y_max = 1.0f - ((float)m_pad_y_bottom) / r_height;
49 
50  glDisable(GL_CULL_FACE);
51  glBegin(GL_QUADS);
52 
53  glTexCoord2d(m_tex_x_min, m_tex_y_min);
54  glVertex3f(m_xMin, m_yMin, 0);
55 
56  glTexCoord2d(m_tex_x_max, m_tex_y_min);
57  glVertex3f(m_xMax, m_yMin, 0);
58 
59  glTexCoord2d(m_tex_x_max, m_tex_y_max);
60  glVertex3f(m_xMax, m_yMax, 0);
61 
62  glTexCoord2d(m_tex_x_min, m_tex_y_max);
63  glVertex3f(m_xMin, m_yMax, 0);
64 
65  glEnd();
67 
68  MRPT_END
69 #endif
70 }
71 
72 uint8_t CTexturedPlane::serializeGetVersion() const { return 2; }
74 {
75  writeToStreamRender(out);
76 
77  out << m_xMin << m_xMax;
78  out << m_yMin << m_yMax;
79 
80  writeToStreamTexturedObject(out);
81 }
82 
84  mrpt::serialization::CArchive& in, uint8_t version)
85 {
86  switch (version)
87  {
88  case 0:
89  {
90  readFromStreamRender(in);
91  in >> m_textureImage >> m_textureImageAlpha;
92  in >> m_xMin >> m_xMax;
93  in >> m_yMin >> m_yMax;
94 
95  assignImage(m_textureImage, m_textureImageAlpha);
96  }
97  break;
98  case 1:
99  case 2:
100  {
101  readFromStreamRender(in);
102 
103  in >> m_xMin >> m_xMax;
104  in >> m_yMin >> m_yMax;
105 
106  if (version >= 2)
107  {
108  readFromStreamTexturedObject(in);
109  }
110  else
111  { // Old version.
115  {
117  assignImage(
120  }
121  else
122  assignImage(CTexturedObject::m_textureImage);
123  }
124  }
125  break;
126  default:
128  };
130 }
131 
132 bool CTexturedPlane::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
133 {
134  if (!polygonUpToDate) updatePoly();
135  return math::traceRay(tmpPoly, (o - this->m_pose).asTPose(), dist);
136 }
137 
139 {
140  TPolygon3D poly(4);
141  poly[0].x = poly[1].x = m_xMin;
142  poly[2].x = poly[3].x = m_xMax;
143  poly[0].y = poly[3].y = m_yMin;
144  poly[1].y = poly[2].y = m_yMax;
145  for (size_t i = 0; i < 4; i++) poly[i].z = 0;
146  tmpPoly.resize(1);
147  tmpPoly[0] = poly;
148  polygonUpToDate = true;
149 }
150 
153 {
154  bb_min.x = std::min(m_xMin, m_xMax);
155  bb_min.y = std::min(m_yMin, m_yMax);
156  bb_min.z = 0;
157 
158  bb_max.x = std::max(m_xMin, m_xMax);
159  bb_max.y = std::max(m_yMin, m_yMax);
160  bb_max.z = 0;
161 
162  // Convert to coordinates of my parent:
163  m_pose.composePoint(bb_min, bb_min);
164  m_pose.composePoint(bb_max, bb_max);
165 }
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
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:2565
#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...
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.
#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".
~CTexturedPlane() override
Private, virtual destructor: only can be deleted from smart pointers.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
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:54
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:85
mrpt::vision::TStereoCalibResults out
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
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
mrpt::img::CImage m_textureImageAlpha
const auto bb_min
Lightweight 3D point.
Definition: TPoint3D.h:90
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: 7e629e01a Sat Dec 14 00:05:55 2019 +0100 at sáb dic 14 00:15:10 CET 2019