MRPT  2.0.4
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-2020, 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 using namespace mrpt;
17 using namespace mrpt::opengl;
18 using namespace mrpt::poses;
19 using namespace mrpt::math;
20 using namespace std;
21 
23 
25  float x_min, float x_max, float y_min, float y_max)
26 {
27  // Copy data:
28  m_xMin = x_min;
29  m_xMax = x_max;
30  m_yMin = y_min;
31  m_yMax = y_max;
32 }
33 
35 {
37  using P2f = mrpt::math::TPoint2Df;
38  using P3f = mrpt::math::TPoint3Df;
39 
40  // Note: if we are rendering and the user assigned us no texture image,
41  // let's create a dummy one with the uniform CRenderizable's color:
42  if (!textureImageHasBeenAssigned())
43  {
45  im_a(4, 4, mrpt::img::CH_GRAY);
46  im_rgb.filledRectangle(0, 0, 3, 3, m_color);
47  im_a.filledRectangle(
48  0, 0, 3, 3,
49  mrpt::img::TColor(m_color.A, m_color.A, m_color.A, m_color.A));
50  this->assignImage(std::move(im_rgb), std::move(im_a));
51  }
52 
54  tris.clear();
55 
56  {
57  TTriangle t;
58  t.vertices[0].xyzrgba.pt = P3f(m_xMin, m_yMin, 0);
59  t.vertices[1].xyzrgba.pt = P3f(m_xMax, m_yMin, 0);
60  t.vertices[2].xyzrgba.pt = P3f(m_xMax, m_yMax, 0);
61 
62  t.vertices[0].uv = P2f(0, 0);
63  t.vertices[1].uv = P2f(1, 0);
64  t.vertices[2].uv = P2f(1, 1);
65 
66  tris.emplace_back(t);
67  }
68  {
69  TTriangle t;
70  t.vertices[0].xyzrgba.pt = P3f(m_xMin, m_yMin, 0);
71  t.vertices[1].xyzrgba.pt = P3f(m_xMax, m_yMax, 0);
72  t.vertices[2].xyzrgba.pt = P3f(m_xMin, m_yMax, 0);
73 
74  t.vertices[0].uv = P2f(0, 0);
75  t.vertices[1].uv = P2f(1, 1);
76  t.vertices[2].uv = P2f(0, 1);
77 
78  tris.emplace_back(t);
79  }
80 
81  MRPT_END
82 }
83 
84 uint8_t CTexturedPlane::serializeGetVersion() const { return 2; }
86 {
87  writeToStreamRender(out);
88 
89  out << m_xMin << m_xMax;
90  out << m_yMin << m_yMax;
91 
92  writeToStreamTexturedObject(out);
93 }
94 
96  mrpt::serialization::CArchive& in, uint8_t version)
97 {
98  switch (version)
99  {
100  case 0:
101  case 1:
102  THROW_EXCEPTION("Deserialization of old formats not supported.");
103  break;
104  case 2:
105  {
106  readFromStreamRender(in);
107  in >> m_xMin >> m_xMax;
108  in >> m_yMin >> m_yMax;
109  readFromStreamTexturedObject(in);
110  }
111  break;
112  default:
114  };
116 }
117 
118 bool CTexturedPlane::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
119 {
120  if (!polygonUpToDate) updatePoly();
121  return math::traceRay(tmpPoly, (o - this->m_pose).asTPose(), dist);
122 }
123 
125 {
126  TPolygon3D poly(4);
127  poly[0].x = poly[1].x = m_xMin;
128  poly[2].x = poly[3].x = m_xMax;
129  poly[0].y = poly[3].y = m_yMin;
130  poly[1].y = poly[2].y = m_yMax;
131  for (size_t i = 0; i < 4; i++) poly[i].z = 0;
132  tmpPoly.resize(1);
133  tmpPoly[0] = poly;
134  polygonUpToDate = true;
135 }
136 
139 {
140  bb_min.x = std::min(m_xMin, m_xMax);
141  bb_min.y = std::min(m_yMin, m_yMax);
142  bb_min.z = 0;
143 
144  bb_max.x = std::max(m_xMin, m_xMax);
145  bb_max.y = std::max(m_yMin, m_yMax);
146  bb_max.z = 0;
147 
148  // Convert to coordinates of my parent:
149  m_pose.composePoint(bb_min, bb_min);
150  m_pose.composePoint(bb_max, bb_max);
151 }
mrpt::opengl::CTexturedPlane::onUpdateBuffers_TexturedTriangles
virtual void onUpdateBuffers_TexturedTriangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CTexturedPlane.cpp:34
mrpt::opengl::CRenderizable::notifyChange
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
Definition: CRenderizable.h:315
mrpt::math::TPoint3D_< double >
mrpt::opengl::CRenderizable
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
mrpt::opengl::CTexturedPlane::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CTexturedPlane.cpp:118
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:95
CSetOfTriangles.h
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
mrpt::math::TPoint3Df
TPoint3D_< float > TPoint3Df
Definition: TPoint3D.h:269
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::opengl::CTexturedPlane
A 2D plane in the XY plane with a texture image.
Definition: CTexturedPlane.h:20
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:85
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:22
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:2484
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::math::TPoint2Df
TPoint2D_< float > TPoint2Df
Definition: TPoint2D.h:214
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
MRPT_START
#define MRPT_START
Definition: exceptions.h:241
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::img::CH_GRAY
@ CH_GRAY
Definition: img/CImage.h:61
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::img::CH_RGB
@ CH_RGB
Definition: img/CImage.h:62
mrpt::opengl::CTexturedPlane::updatePoly
void updatePoly() const
Definition: CTexturedPlane.cpp:124
mrpt::opengl::CTexturedPlane::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CTexturedPlane.cpp:84
mrpt::math::TPolygon3D
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20
mrpt::opengl::CRenderizableShaderTexturedTriangles::m_triangles
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
Definition: CRenderizableShaderTexturedTriangles.h:105
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
Definition: CSerializable.h:166
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
mrpt::opengl::TTriangle
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex.
Definition: TTriangle.h:35
opengl-precomp.h
mrpt::opengl::TTriangle::vertices
std::array< Vertex, 3 > vertices
Definition: TTriangle.h:88
tmpPoly
static math::TPolygon3D tmpPoly(3)
MRPT_END
#define MRPT_END
Definition: exceptions.h:245
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::opengl::CTexturedPlane::getBoundingBox
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:137
CTexturedPlane.h
mrpt::img::CCanvas::filledRectangle
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
Definition: CCanvas.cpp:205



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020