Main MRPT website > C++ reference for MRPT 1.9.9
CTexturedPlane.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 
16 #include "opengl_internals.h"
17 
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 using namespace mrpt::poses;
21 using namespace mrpt::utils;
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  return CTexturedPlane::Ptr(new CTexturedPlane(x_min, x_max, y_min, y_max));
31 }
32 /*---------------------------------------------------------------
33  CTexturedPlane
34  ---------------------------------------------------------------*/
36  float x_min, float x_max, float y_min, float y_max)
37  : polygonUpToDate(false)
38 {
39  // Copy data:
40  m_xMin = x_min;
41  m_xMax = x_max;
42  m_yMin = y_min;
43  m_yMax = y_max;
44 }
45 
46 /*---------------------------------------------------------------
47  ~CTexturedPlane
48  ---------------------------------------------------------------*/
50 /*---------------------------------------------------------------
51  render
52  ---------------------------------------------------------------*/
54 {
55 #if MRPT_HAS_OPENGL_GLUT
57 
58  // Compute the exact texture coordinates:
59  m_tex_x_min = 0;
60  m_tex_x_max = 1.0f - ((float)m_pad_x_right) / r_width;
61  m_tex_y_min = 0;
62  m_tex_y_max = 1.0f - ((float)m_pad_y_bottom) / r_height;
63 
66 
69 
72 
75 
78 
79  glEnd();
81 
82  MRPT_END
83 #endif
84 }
85 
86 /*---------------------------------------------------------------
87  Implements the writing to a CStream capability of
88  CSerializable objects
89  ---------------------------------------------------------------*/
91  mrpt::utils::CStream& out, int* version) const
92 {
93  if (version)
94  *version = 2;
95  else
96  {
98 
99  out << m_xMin << m_xMax;
100  out << m_yMin << m_yMax;
101 
103  }
104 }
105 
106 /*---------------------------------------------------------------
107  Implements the reading from a CStream capability of
108  CSerializable objects
109  ---------------------------------------------------------------*/
111 {
112  switch (version)
113  {
114  case 0:
115  {
118  in >> m_xMin >> m_xMax;
119  in >> m_yMin >> m_yMax;
120 
122  }
123  break;
124  case 1:
125  case 2:
126  {
128 
129  in >> m_xMin >> m_xMax;
130  in >> m_yMin >> m_yMax;
131 
132  if (version >= 2)
133  {
135  }
136  else
137  { // Old version.
141  {
143  assignImage(
146  }
147  else
149  }
150  }
151  break;
152  default:
154  };
156 }
157 
158 bool CTexturedPlane::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
159 {
160  if (!polygonUpToDate) updatePoly();
161  return math::traceRay(tmpPoly, o - this->m_pose, dist);
162 }
163 
165 {
166  TPolygon3D poly(4);
167  poly[0].x = poly[1].x = m_xMin;
168  poly[2].x = poly[3].x = m_xMax;
169  poly[0].y = poly[3].y = m_yMin;
170  poly[1].y = poly[2].y = m_yMax;
171  for (size_t i = 0; i < 4; i++) poly[i].z = 0;
172  tmpPoly.resize(1);
173  tmpPoly[0] = poly;
174  polygonUpToDate = true;
175 }
176 
178  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
179 {
180  bb_min.x = std::min(m_xMin, m_xMax);
181  bb_min.y = std::min(m_yMin, m_yMax);
182  bb_min.z = 0;
183 
184  bb_max.x = std::max(m_xMin, m_xMax);
185  bb_max.y = std::max(m_yMin, m_yMax);
186  bb_max.z = 0;
187 
188  // Convert to coordinates of my parent:
189  m_pose.composePoint(bb_min, bb_min);
190  m_pose.composePoint(bb_max, bb_max);
191 }
void assignImage(const mrpt::utils::CImage &img, const mrpt::utils::CImage &imgAlpha)
Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M...
void writeToStreamRender(utils::CStream &out) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLdouble GLdouble z
Definition: glext.h:3872
#define min(a, b)
A base class for all OpenGL objects with loadable textures.
std::shared_ptr< CTexturedPlane > Ptr
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons&#39; properties.
Definition: geometry.cpp:2582
virtual 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...
virtual ~CTexturedPlane()
Private, virtual destructor: only can be deleted from smart pointers.
#define GL_CULL_FACE
Definition: glew.h:382
int m_pad_x_right
The size of the fill in pixels in the textured image, w.r.t the image passed by the user...
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
STL namespace.
int r_width
Size of the texture image, rounded up to next power of 2.
std::shared_ptr< CObject > Ptr
Definition: CObject.h:154
virtual 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.
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:57
void render_texturedobj() const override
Must be implemented by derived classes.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_END
bool m_enableTransparency
Of the texture using "m_textureImageAlpha".
#define GL_QUADS
Definition: glew.h:279
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void readFromStreamRender(mrpt::utils::CStream &in)
double x
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glBegin(GLenum mode)
void writeToStreamTexturedObject(mrpt::utils::CStream &out) const
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
std::vector< mrpt::math::TPolygonWithPlane > tmpPoly
Used for ray-tracing.
#define MRPT_START
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::utils::CImage m_textureImage
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
Definition: CPose3D.cpp:453
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
GLAPI void GLAPIENTRY glEnd(void)
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...
GLAPI void GLAPIENTRY glTexCoord2d(GLdouble s, GLdouble t)
CTexturedPlane(float x_min=-1, float x_max=1, float y_min=-1, float y_max=1)
Constructor.
Lightweight 3D point.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
3D polygon, inheriting from std::vector<TPoint3D>
mrpt::utils::CImage m_textureImageAlpha
void readFromStreamTexturedObject(mrpt::utils::CStream &in)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019