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-2018, 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 
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  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 
88 {
90 
91  out << m_xMin << m_xMax;
92  out << m_yMin << m_yMax;
93 
95 }
96 
99 {
100  switch (version)
101  {
102  case 0:
103  {
106  in >> m_xMin >> m_xMax;
107  in >> m_yMin >> m_yMax;
108 
110  }
111  break;
112  case 1:
113  case 2:
114  {
116 
117  in >> m_xMin >> m_xMax;
118  in >> m_yMin >> m_yMax;
119 
120  if (version >= 2)
121  {
123  }
124  else
125  { // Old version.
129  {
131  assignImage(
134  }
135  else
137  }
138  }
139  break;
140  default:
142  };
144 }
145 
146 bool CTexturedPlane::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
147 {
148  if (!polygonUpToDate) updatePoly();
149  return math::traceRay(tmpPoly, (o - this->m_pose).asTPose(), dist);
150 }
151 
153 {
154  TPolygon3D poly(4);
155  poly[0].x = poly[1].x = m_xMin;
156  poly[2].x = poly[3].x = m_xMax;
157  poly[0].y = poly[3].y = m_yMin;
158  poly[1].y = poly[2].y = m_yMax;
159  for (size_t i = 0; i < 4; i++) poly[i].z = 0;
160  tmpPoly.resize(1);
161  tmpPoly[0] = poly;
162  polygonUpToDate = true;
163 }
164 
166  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
167 {
168  bb_min.x = std::min(m_xMin, m_xMax);
169  bb_min.y = std::min(m_yMin, m_yMax);
170  bb_min.z = 0;
171 
172  bb_max.x = std::max(m_xMin, m_xMax);
173  bb_max.y = std::max(m_yMin, m_yMax);
174  bb_max.z = 0;
175 
176  // Convert to coordinates of my parent:
177  m_pose.composePoint(bb_min, bb_min);
178  m_pose.composePoint(bb_max, bb_max);
179 }
glBegin
GLAPI void GLAPIENTRY glBegin(GLenum mode)
mrpt::opengl::CTexturedObject::m_enableTransparency
bool m_enableTransparency
Of the texture using "m_textureImageAlpha".
Definition: CTexturedObject.h:35
mrpt::opengl::CTexturedPlane::render_texturedobj
void render_texturedobj() const override
Must be implemented by derived classes.
Definition: CTexturedPlane.cpp:53
mrpt::opengl::CTexturedPlane::m_tex_y_max
float m_tex_y_max
Definition: CTexturedPlane.h:27
mrpt::opengl::CTexturedPlane::m_tex_y_min
float m_tex_y_min
Definition: CTexturedPlane.h:27
mrpt::opengl::CTexturedObject::m_textureImage
mrpt::img::CImage m_textureImage
Definition: CTexturedObject.h:32
mrpt::opengl::CTexturedPlane::m_tex_x_min
float m_tex_x_min
Definition: CTexturedPlane.h:26
mrpt::opengl::CTexturedObject::m_pad_x_right
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.
Definition: CTexturedObject.h:40
mrpt::opengl::CTexturedPlane::Ptr
std::shared_ptr< CTexturedPlane > Ptr
Definition: CTexturedPlane.h:24
mrpt::opengl::CTexturedPlane::traceRay
virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CTexturedPlane.cpp:146
mrpt::opengl::CTexturedObject::readFromStreamTexturedObject
void readFromStreamTexturedObject(mrpt::serialization::CArchive &in)
Definition: CTexturedObject.cpp:549
mrpt::math::TPoint3D::z
double z
Definition: lightweight_geom_data.h:385
mrpt::opengl::CTexturedPlane::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CTexturedPlane.cpp:97
GL_QUADS
#define GL_QUADS
Definition: glew.h:279
glDisable
GLAPI void GLAPIENTRY glDisable(GLenum cap)
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
mrpt::opengl::CTexturedObject::assignImage
void assignImage(const mrpt::img::CImage &img, const mrpt::img::CImage &imgAlpha)
Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M...
Definition: CTexturedObject.cpp:58
CSetOfTriangles.h
mrpt::opengl::CRenderizable::Ptr
std::shared_ptr< CRenderizable > Ptr
Definition: CRenderizable.h:45
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::opengl::CTexturedPlane
A 2D plane in the XY plane with a texture image.
Definition: CTexturedPlane.h:22
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::opengl::CTexturedObject::r_height
int r_height
Definition: CTexturedObject.h:37
mrpt::opengl::CTexturedPlane::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CTexturedPlane.cpp:87
glVertex3f
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::opengl::CTexturedPlane::m_yMax
float m_yMax
Definition: CTexturedPlane.h:30
mrpt::math::traceRay
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::math::TPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
Definition: geometry.cpp:2590
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
glEnd
GLAPI void GLAPIENTRY glEnd(void)
mrpt::opengl::CTexturedObject::m_textureImageAlpha
mrpt::img::CImage m_textureImageAlpha
Definition: CTexturedObject.h:33
mrpt::opengl::CTexturedPlane::~CTexturedPlane
virtual ~CTexturedPlane()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CTexturedPlane.cpp:49
mrpt::opengl::CTexturedPlane::m_tex_x_max
float m_tex_x_max
Definition: CTexturedPlane.h:26
mrpt::opengl::CTexturedPlane::tmpPoly
std::vector< mrpt::math::TPolygonWithPlane > tmpPoly
Used for ray-tracing.
Definition: CTexturedPlane.h:34
mrpt::opengl::CRenderizable::m_pose
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:57
mrpt::opengl::CRenderizable::checkOpenGLError
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: CRenderizable.cpp:301
mrpt::opengl::CTexturedObject::r_width
int r_width
Size of the texture image, rounded up to next power of 2.
Definition: CTexturedObject.h:37
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::opengl::CTexturedObject::m_pad_y_bottom
int m_pad_y_bottom
Definition: CTexturedObject.h:40
mrpt::opengl::CTexturedPlane::m_xMax
float m_xMax
Definition: CTexturedPlane.h:29
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::math::TPoint3D::x
double x
X,Y,Z coordinates.
Definition: lightweight_geom_data.h:385
mrpt::opengl::CTexturedObject
A base class for all OpenGL objects with loadable textures.
Definition: CTexturedObject.h:25
mrpt::opengl::CTexturedPlane::updatePoly
void updatePoly() const
Definition: CTexturedPlane.cpp:152
mrpt::opengl::CTexturedPlane::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CTexturedPlane.cpp:86
mrpt::math::TPolygon3D
3D polygon, inheriting from std::vector<TPoint3D>
Definition: lightweight_geom_data.h:1458
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
opengl-precomp.h
mrpt::math::TPoint3D::y
double y
Definition: lightweight_geom_data.h:385
mrpt::poses::CPose3D::composePoint
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:379
min
#define min(a, b)
Definition: rplidar_driver.cpp:42
mrpt::opengl::CTexturedPlane::CTexturedPlane
CTexturedPlane(float x_min=-1, float x_max=1, float y_min=-1, float y_max=1)
Constructor.
Definition: CTexturedPlane.cpp:35
glTexCoord2d
GLAPI void GLAPIENTRY glTexCoord2d(GLdouble s, GLdouble t)
opengl_internals.h
mrpt::opengl::CTexturedPlane::polygonUpToDate
bool polygonUpToDate
Definition: CTexturedPlane.h:32
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::opengl::CTexturedObject::writeToStreamTexturedObject
void writeToStreamTexturedObject(mrpt::serialization::CArchive &out) const
Definition: CTexturedObject.cpp:474
z
GLdouble GLdouble z
Definition: glext.h:3872
GL_CULL_FACE
#define GL_CULL_FACE
Definition: glew.h:382
in
GLuint in
Definition: glext.h:7274
mrpt::opengl::CTexturedPlane::m_yMin
float m_yMin
Definition: CTexturedPlane.h:30
CArchive.h
mrpt::opengl::CTexturedPlane::m_xMin
float m_xMin
Definition: CTexturedPlane.h:29
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::opengl::CRenderizable::writeToStreamRender
void writeToStreamRender(mrpt::serialization::CArchive &out) const
Definition: CRenderizable.cpp:110
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::opengl::CRenderizableDisplayList::readFromStreamRender
void readFromStreamRender(mrpt::serialization::CArchive &in)
Definition: CRenderizableDisplayList.h:65
mrpt::opengl::CTexturedPlane::getBoundingBox
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...
Definition: CTexturedPlane.cpp:165
CTexturedPlane.h



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST