MRPT  2.0.0
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 
41  tris.clear();
42 
43  {
44  TTriangle t;
45  t.vertices[0].xyzrgba.pt = P3f(m_xMin, m_yMin, 0);
46  t.vertices[1].xyzrgba.pt = P3f(m_xMax, m_yMin, 0);
47  t.vertices[2].xyzrgba.pt = P3f(m_xMax, m_yMax, 0);
48 
49  t.vertices[0].uv = P2f(0, 0);
50  t.vertices[1].uv = P2f(1, 0);
51  t.vertices[2].uv = P2f(1, 1);
52 
53  tris.emplace_back(t);
54  }
55  {
56  TTriangle t;
57  t.vertices[0].xyzrgba.pt = P3f(m_xMin, m_yMin, 0);
58  t.vertices[1].xyzrgba.pt = P3f(m_xMax, m_yMax, 0);
59  t.vertices[2].xyzrgba.pt = P3f(m_xMin, m_yMax, 0);
60 
61  t.vertices[0].uv = P2f(0, 0);
62  t.vertices[1].uv = P2f(1, 1);
63  t.vertices[2].uv = P2f(0, 1);
64 
65  tris.emplace_back(t);
66  }
67 
68  MRPT_END
69 }
70 
71 uint8_t CTexturedPlane::serializeGetVersion() const { return 2; }
73 {
74  writeToStreamRender(out);
75 
76  out << m_xMin << m_xMax;
77  out << m_yMin << m_yMax;
78 
79  writeToStreamTexturedObject(out);
80 }
81 
83  mrpt::serialization::CArchive& in, uint8_t version)
84 {
85  switch (version)
86  {
87  case 0:
88  case 1:
89  THROW_EXCEPTION("Deserialization of old formats not supported.");
90  break;
91  case 2:
92  {
93  readFromStreamRender(in);
94  in >> m_xMin >> m_xMax;
95  in >> m_yMin >> m_yMax;
96  readFromStreamTexturedObject(in);
97  }
98  break;
99  default:
101  };
103 }
104 
105 bool CTexturedPlane::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
106 {
107  if (!polygonUpToDate) updatePoly();
108  return math::traceRay(tmpPoly, (o - this->m_pose).asTPose(), dist);
109 }
110 
112 {
113  TPolygon3D poly(4);
114  poly[0].x = poly[1].x = m_xMin;
115  poly[2].x = poly[3].x = m_xMax;
116  poly[0].y = poly[3].y = m_yMin;
117  poly[1].y = poly[2].y = m_yMax;
118  for (size_t i = 0; i < 4; i++) poly[i].z = 0;
119  tmpPoly.resize(1);
120  tmpPoly[0] = poly;
121  polygonUpToDate = true;
122 }
123 
126 {
127  bb_min.x = std::min(m_xMin, m_xMax);
128  bb_min.y = std::min(m_yMin, m_yMax);
129  bb_min.z = 0;
130 
131  bb_max.x = std::max(m_xMin, m_xMax);
132  bb_max.y = std::max(m_yMin, m_yMax);
133  bb_max.z = 0;
134 
135  // Convert to coordinates of my parent:
136  m_pose.composePoint(bb_min, bb_min);
137  m_pose.composePoint(bb_max, bb_max);
138 }
#define MRPT_START
Definition: exceptions.h:241
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
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:2484
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex...
Definition: TTriangle.h:35
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...
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
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.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
std::array< Vertex, 3 > vertices
Definition: TTriangle.h:88
This base provides a set of functions for maths stuff.
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 void onUpdateBuffers_TexturedTriangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
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
#define MRPT_END
Definition: exceptions.h:245
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
const auto bb_min
TPoint3D_< float > TPoint3Df
Definition: TPoint3D.h:269
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
static math::TPolygon3D tmpPoly(3)
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20
TPoint2D_< float > TPoint2Df
Definition: TPoint2D.h:214



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020