MRPT  2.0.1
CSetOfTriangles.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 
14 #include <mrpt/opengl/opengl_api.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::poses;
20 using namespace mrpt::math;
21 using namespace std;
22 
25 
27 {
28  // Nothing else to do, data is directly kept up-to-date in base class
29  // buffers.
30 }
31 
32 uint8_t CSetOfTriangles::serializeGetVersion() const { return 0; }
34 {
35  writeToStreamRender(out);
36  auto n = (uint32_t)m_triangles.size();
37  out << n;
38  for (size_t i = 0; i < n; i++) m_triangles[i].writeTo(out);
39 }
41  mrpt::serialization::CArchive& in, uint8_t version)
42 {
43  switch (version)
44  {
45  case 0:
46  {
47  readFromStreamRender(in);
48  uint32_t n;
49  in >> n;
50  m_triangles.assign(n, TTriangle());
51  for (size_t i = 0; i < n; i++) m_triangles[i].readFrom(in);
52  }
53  break;
54  default:
56  };
57  polygonsUpToDate = false;
59 }
60 
62  const mrpt::poses::CPose3D& o, double& dist) const
63 {
64  if (!polygonsUpToDate) updatePolygons();
65  return mrpt::math::traceRay(m_polygons, (o - this->m_pose).asTPose(), dist);
66 }
68 {
70  m_color = c;
71  for (auto& t : m_triangles) t.setColor(c);
72  return *this;
73 }
74 
76 {
78  m_color.R = r;
79  for (auto& t : m_triangles) t.setColor(m_color);
80  return *this;
81 }
82 
84 {
86  m_color.G = g;
87  for (auto& t : m_triangles) t.setColor(m_color);
88  return *this;
89 }
90 
92 {
94  m_color.B = b;
95  for (auto& t : m_triangles) t.setColor(m_color);
96  return *this;
97 }
98 
100 {
102  m_color.A = a;
103  for (auto& t : m_triangles) t.setColor(m_color);
104  return *this;
105 }
106 
108  std::vector<mrpt::math::TPolygon3D>& polys) const
109 {
110  if (!polygonsUpToDate) updatePolygons();
111  size_t N = m_polygons.size();
112  for (size_t i = 0; i < N; i++) polys[i] = m_polygons[i].poly;
113 }
114 
116 {
117  TPolygon3D tmp(3);
118  size_t N = m_triangles.size();
119  m_polygons.resize(N);
120  for (size_t i = 0; i < N; i++)
121  for (size_t j = 0; j < 3; j++)
122  {
123  const TTriangle& t = m_triangles[i];
124  tmp[j].x = t.x(j);
125  tmp[j].y = t.y(j);
126  tmp[j].z = t.z(j);
127  m_polygons[i] = tmp;
128  }
129  polygonsUpToDate = true;
131 }
132 
135 {
137  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
138  std::numeric_limits<double>::max());
140  -std::numeric_limits<double>::max(),
141  -std::numeric_limits<double>::max(),
142  -std::numeric_limits<double>::max());
143 
144  for (const auto& t : m_triangles)
145  {
146  keep_min(bb_min.x, t.x(0));
147  keep_max(bb_max.x, t.x(0));
148  keep_min(bb_min.y, t.y(0));
149  keep_max(bb_max.y, t.y(0));
150  keep_min(bb_min.z, t.z(0));
151  keep_max(bb_max.z, t.z(0));
152 
153  keep_min(bb_min.x, t.x(1));
154  keep_max(bb_max.x, t.x(1));
155  keep_min(bb_min.y, t.y(1));
156  keep_max(bb_max.y, t.y(1));
157  keep_min(bb_min.z, t.z(1));
158  keep_max(bb_max.z, t.z(1));
159 
160  keep_min(bb_min.x, t.x(2));
161  keep_max(bb_max.x, t.x(2));
162  keep_min(bb_min.y, t.y(2));
163  keep_max(bb_max.y, t.y(2));
164  keep_min(bb_min.z, t.z(2));
165  keep_max(bb_max.z, t.z(2));
166  }
167 
168  // Convert to coordinates of my parent:
169  m_pose.composePoint(bb_min, bb_min);
170  m_pose.composePoint(bb_max, bb_max);
171 }
172 
174 {
175  reserve(m_triangles.size() + p->m_triangles.size());
176  m_triangles.insert(
177  m_triangles.end(), p->m_triangles.begin(), p->m_triangles.end());
178  polygonsUpToDate = false;
180 }
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
CRenderizable & setColorG_u8(const uint8_t g) override
Overwrite all triangles colors with the one provided.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
void getPolygons(std::vector< mrpt::math::TPolygon3D > &polys) const
Gets the polygon cache.
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
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
const float & x(size_t i) const
Definition: TTriangle.h:90
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex...
Definition: TTriangle.h:35
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
STL namespace.
Renderizable generic renderer for objects using the triangles shader.
CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Overwrite all triangles colors with the one provided.
CRenderizable & setColorR_u8(const uint8_t r) override
Overwrite all triangles colors with the one provided.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
This base provides a set of functions for maths stuff.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
IMPLEMENTS_SERIALIZABLE(CSetOfTriangles, CRenderizableShaderTriangles, mrpt::opengl) void CSetOfTriangles
TPoint3D_< double > TPoint3D
Lightweight 3D point.
Definition: TPoint3D.h:268
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...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
void updatePolygons() const
Explicitly updates the internal polygon cache, with all triangles as polygons.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
const float & y(size_t i) const
Definition: TTriangle.h:91
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
const float & z(size_t i) const
Definition: TTriangle.h:92
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
A set of colored triangles, able to draw any solid, arbitrarily complex object without textures...
const auto bb_min
A RGB color - 8bit.
Definition: TColor.h:25
CRenderizable & setColorB_u8(const uint8_t b) override
Overwrite all triangles colors with the one provided.
CRenderizable & setColorA_u8(const uint8_t a) override
Overwrite all triangles colors with the one provided.
void insertTriangles(const InputIterator &begin, const InputIterator &end)
Inserts a set of triangles, bounded by iterators, into this set.
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020