Main MRPT website > C++ reference for MRPT 1.5.7
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 
12 
14 #include <mrpt/utils/CStream.h>
16 
17 #include "opengl_internals.h"
18 
19 using namespace mrpt;
20 using namespace mrpt::opengl;
21 using namespace mrpt::poses;
22 using namespace mrpt::utils;
23 using namespace mrpt::math;
24 using namespace std;
25 
27 
28 CTexturedPlanePtr CTexturedPlane::Create(
29  float x_min,
30  float x_max,
31  float y_min,
32  float y_max)
33 {
34  return CTexturedPlanePtr( new CTexturedPlane(x_min, x_max, y_min, y_max) );
35 }
36 /*---------------------------------------------------------------
37  CTexturedPlane
38  ---------------------------------------------------------------*/
40  float x_min,
41  float x_max,
42  float y_min,
43  float y_max
44  ) :
45  polygonUpToDate(false)
46 {
47  // Copy data:
48  m_xMin = x_min;
49  m_xMax = x_max;
50  m_yMin = y_min;
51  m_yMax = y_max;
52 }
53 
54 
55 /*---------------------------------------------------------------
56  ~CTexturedPlane
57  ---------------------------------------------------------------*/
59 {
60 }
61 
62 /*---------------------------------------------------------------
63  render
64  ---------------------------------------------------------------*/
66 {
67 #if MRPT_HAS_OPENGL_GLUT
69 
70  // Compute the exact texture coordinates:
71  m_tex_x_min = 0;
72  m_tex_x_max = 1.0f-((float)m_pad_x_right) / r_width;
73  m_tex_y_min = 0;
74  m_tex_y_max = 1.0f-((float)m_pad_y_bottom) / r_height;
75 
78 
80  glVertex3f( m_xMin, m_yMin,0 );
81 
83  glVertex3f( m_xMax, m_yMin,0 );
84 
86  glVertex3f( m_xMax, m_yMax,0 );
87 
89  glVertex3f( m_xMin, m_yMax,0 );
90 
91  glEnd();
93 
94  MRPT_END
95 #endif
96 }
97 
98 /*---------------------------------------------------------------
99  Implements the writing to a CStream capability of
100  CSerializable objects
101  ---------------------------------------------------------------*/
103 {
104  if (version)
105  *version = 2;
106  else
107  {
108  writeToStreamRender(out);
109 
110  out << m_xMin << m_xMax;
111  out << m_yMin << m_yMax;
112 
114  }
115 }
116 
117 /*---------------------------------------------------------------
118  Implements the reading from a CStream capability of
119  CSerializable objects
120  ---------------------------------------------------------------*/
122 {
123  switch(version)
124  {
125  case 0:
126  {
129  in >> m_xMin >> m_xMax;
130  in >> m_yMin >> m_yMax;
131 
133 
134  } break;
135  case 1:
136  case 2:
137  {
139 
140  in >> m_xMin >> m_xMax;
141  in >> m_yMin >> m_yMax;
142 
143  if (version>=2)
144  {
146  }
147  else
148  { // Old version.
152  {
155  }
156  else
158  }
159 
160  } break;
161  default:
163 
164  };
166 }
167 
168 bool CTexturedPlane::traceRay(const mrpt::poses::CPose3D &o,double &dist) const {
169  if (!polygonUpToDate) updatePoly();
170  return math::traceRay(tmpPoly,o-this->m_pose,dist);
171 }
172 
174  TPolygon3D poly(4);
175  poly[0].x=poly[1].x=m_xMin;
176  poly[2].x=poly[3].x=m_xMax;
177  poly[0].y=poly[3].y=m_yMin;
178  poly[1].y=poly[2].y=m_yMax;
179  for (size_t i=0;i<4;i++) poly[i].z=0;
180  tmpPoly.resize(1);
181  tmpPoly[0]=poly;
182  polygonUpToDate=true;
183 }
184 
185 
187 {
188  bb_min.x = std::min(m_xMin, m_xMax);
189  bb_min.y = std::min(m_yMin, m_yMax);
190  bb_min.z = 0;
191 
192  bb_max.x = std::max(m_xMin, m_xMax);
193  bb_max.y = std::max(m_yMin, m_yMax);
194  bb_max.z = 0;
195 
196  // Convert to coordinates of my parent:
197  m_pose.composePoint(bb_min, bb_min);
198  m_pose.composePoint(bb_max, bb_max);
199 }
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
3D polygon, inheriting from std::vector<TPoint3D>
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
void readFromStreamRender(mrpt::utils::CStream &in)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference. This class automatically holds the cached 3x3 rotation m...
Definition: CRenderizable.h:55
void writeToStreamRender(utils::CStream &out) const
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
A base class for all OpenGL objects with loadable textures.
void readFromStreamTexturedObject(mrpt::utils::CStream &in)
mrpt::utils::CImage m_textureImage
void writeToStreamTexturedObject(mrpt::utils::CStream &out) const
int m_pad_y_bottom
The size of the fill in pixels in the textured image, w.r.t the image passed by the user.
int r_height
Size of the texture image, rounded up to next power of 2.
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...
mrpt::utils::CImage m_textureImageAlpha
bool m_enableTransparency
Of the texture using "m_textureImageAlpha".
A 2D plane in the XY plane with a texture image.
CTexturedPlane(float x_min=-1, float x_max=1, float y_min=-1, float y_max=1)
Constructor.
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...
std::vector< mrpt::math::TPolygonWithPlane > tmpPoly
Used for ray-tracing.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
virtual ~CTexturedPlane()
Private, virtual destructor: only can be deleted from smart pointers.
virtual 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...
virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const MRPT_OVERRIDE
Simulation of ray-trace, given a pose.
void render_texturedobj() const MRPT_OVERRIDE
Must be implemented by derived classes.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:73
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, 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:427
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:39
#define GL_QUADS
Definition: glew.h:275
#define GL_CULL_FACE
Definition: glew.h:378
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glTexCoord2d(GLdouble s, GLdouble t)
GLAPI void GLAPIENTRY glEnd(void)
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLuint in
Definition: glext.h:6301
GLdouble GLdouble z
Definition: glext.h:3734
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
Definition: geometry.cpp:1989
int version
Definition: mrpt_jpeglib.h:898
#define MRPT_START
Definition: mrpt_macros.h:366
#define MRPT_END
Definition: mrpt_macros.h:370
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: mrpt_macros.h:217
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.
#define min(a, b)
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