MRPT  2.0.4
CMesh.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 
12 #include <mrpt/img/color_maps.h>
14 #include <mrpt/opengl/CMesh.h>
16 #include <mrpt/opengl/opengl_api.h>
17 #include <mrpt/poses/CPose3D.h>
19 #include <Eigen/Dense>
20 
21 using namespace mrpt;
22 using namespace mrpt::opengl;
23 using namespace mrpt::poses;
24 using namespace mrpt::math;
25 using namespace std;
26 using mrpt::img::CImage;
27 
29 
31  bool enableTransparency, float m_xMin_p, float m_xMax_p, float m_yMin_p,
32  float m_yMax_p)
33  : m_enableTransparency(enableTransparency),
34  Z(0, 0),
35  mask(0, 0),
36  C(0, 0),
37  C_r(0, 0),
38  C_g(0, 0),
39  C_b(0, 0),
40  m_xMin(m_xMin_p),
41  m_xMax(m_xMax_p),
42  m_yMin(m_yMin_p),
43  m_yMax(m_yMax_p)
44 {
45  enableTextureLinearInterpolation(true);
46  enableLight(true);
47 
48  m_color.A = 255;
49  m_color.R = 0;
50  m_color.G = 0;
51  m_color.B = 150;
52 }
53 
54 CMesh::~CMesh() = default;
55 
57 {
58  using mrpt::img::colormap;
59 
61 
62  // Remember:
63  /** List of triangles in the mesh */
64  // mutable
65  // std::vector<std::pair<mrpt::opengl::TTriangle,TTriangleVertexIndices>
66  // > actualMesh;
67 
68  /** The accumulated normals & counts for each vertex, so normals can be
69  * averaged. */
70  // mutable std::vector<std::pair<mrpt::math::TPoint3D,size_t> >
71  // vertex_normals;
72 
73  const auto cols = Z.cols();
74  const auto rows = Z.rows();
75 
76  actualMesh.clear();
77  if (cols == 0 && rows == 0) return; // empty mesh
78 
79  ASSERT_(cols > 0 && rows > 0);
80  ASSERT_ABOVE_(m_xMax, m_xMin);
81  ASSERT_ABOVE_(m_yMax, m_yMin);
82 
83  // we have 1 more row & col of vertices than of triangles:
84  vertex_normals.assign(
85  (1 + cols) * (1 + rows),
86  std::pair<TPoint3D, size_t>(TPoint3D(0, 0, 0), 0));
87 
88  if (m_colorFromZ || m_isImage) updateColorsMatrix();
89 
90  bool useMask = false;
91  if (mask.cols() != 0 && mask.rows() != 0)
92  {
93  ASSERT_(mask.cols() == cols && mask.rows() == rows);
94  useMask = true;
95  }
96  const float sCellX = (m_xMax - m_xMin) / (rows - 1);
97  const float sCellY = (m_yMax - m_yMin) / (cols - 1);
98 
100 
101  for (int iX = 0; iX < rows - 1; iX++)
102  for (int iY = 0; iY < cols - 1; iY++)
103  {
104  if (useMask && (!mask(iX, iY) || !mask(iX + 1, iY + 1))) continue;
105  tri.x(0) = m_xMin + iX * sCellX;
106  tri.y(0) = m_yMin + iY * sCellY;
107  tri.z(0) = Z(iX, iY);
108  tri.x(2) = tri.x(0) + sCellX;
109  tri.y(2) = tri.y(0) + sCellY;
110  tri.z(2) = Z(iX + 1, iY + 1);
111 
112  // Vertex indices:
114  tvi.vind[0] = iX + rows * iY;
115  tvi.vind[2] = (iX + 1) + rows * (iY + 1);
116 
117  // Each quadrangle has up to 2 triangles:
118  // [0]
119  // |
120  // |
121  // [1]--[2]
122  // Order: 0,1,2
123  if (!useMask || mask(iX + 1, iY))
124  {
125  tri.x(1) = tri.x(2);
126  tri.y(1) = tri.y(0);
127  tri.z(1) = Z(iX + 1, iY);
128  // Assign alpha channel
129  for (int i = 0; i < 3; i++) tri.a(i) = m_color.A;
130 
131  if (m_colorFromZ)
132  {
133  mrpt::img::TColorf col(0, 0, 0, 1);
134  colormap(m_colorMap, C(iX, iY), col.R, col.G, col.B);
135  tri.r(0) = f2u8(col.R);
136  tri.g(0) = f2u8(col.G);
137  tri.b(0) = f2u8(col.B);
138  colormap(m_colorMap, C(iX + 1, iY), col.R, col.G, col.B);
139  tri.r(1) = f2u8(col.R);
140  tri.g(1) = f2u8(col.G);
141  tri.b(1) = f2u8(col.B);
142  colormap(
143  m_colorMap, C(iX + 1, iY + 1), col.R, col.G, col.B);
144  tri.r(2) = f2u8(col.R);
145  tri.g(2) = f2u8(col.G);
146  tri.b(2) = f2u8(col.B);
147  }
148  else if (m_isImage)
149  {
150  if (getTextureImage().isColor())
151  {
152  tri.r(0) = tri.r(1) = tri.r(2) = C_r(iX, iY);
153  tri.g(0) = tri.g(1) = tri.g(2) = C_g(iX, iY);
154  tri.b(0) = tri.b(1) = tri.b(2) = C_b(iX, iY);
155  }
156  else
157  {
158  tri.r(0) = tri.r(1) = tri.r(2) = C(iX, iY);
159  tri.g(0) = tri.g(1) = tri.g(2) = C(iX, iY);
160  tri.b(0) = tri.b(1) = tri.b(2) = C(iX, iY);
161  }
162  }
163  else
164  {
165  tri.r(0) = tri.r(1) = tri.r(2) = m_color.R / 255.f;
166  tri.g(0) = tri.g(1) = tri.g(2) = m_color.G / 255.f;
167  tri.b(0) = tri.b(1) = tri.b(2) = m_color.B / 255.f;
168  }
169 
170  // Compute normal of this triangle, and add it up to the 3
171  // neighboring vertices:
172  // A = P1 - P0, B = P2 - P0
173  float ax = tri.x(1) - tri.x(0);
174  float bx = tri.x(2) - tri.x(0);
175  float ay = tri.y(1) - tri.y(0);
176  float by = tri.y(2) - tri.y(0);
177  float az = tri.z(1) - tri.z(0);
178  float bz = tri.z(2) - tri.z(0);
179  const TPoint3D this_normal(
180  ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx);
181 
182  // Vertex indices:
183  tvi.vind[1] = iX + 1 + rows * iY;
184 
185  // Add triangle:
186  actualMesh.emplace_back(tri, tvi);
187 
188  // For averaging normals:
189  for (unsigned long k : tvi.vind)
190  {
191  vertex_normals[k].first += this_normal;
192  vertex_normals[k].second++;
193  }
194  }
195  // 2:
196  // [0]--[1->2]
197  // \ |
198  // \|
199  // [2->1]
200  // Order: 0,2,1
201  if (!useMask || mask(iX, iY + 1))
202  {
203  tri.x(1) = tri.x(2);
204  tri.y(1) = tri.y(2);
205  tri.z(1) = tri.z(2);
206 
207  tri.x(2) = tri.x(0);
208  // tri.y(2)=tri.y(1);
209  tri.z(2) = Z(iX, iY + 1);
210  if (m_colorFromZ)
211  {
212  mrpt::img::TColorf col(0, 0, 0, 1);
213 
214  colormap(m_colorMap, C(iX, iY), col.R, col.G, col.B);
215  tri.r(0) = f2u8(col.R);
216  tri.g(0) = f2u8(col.G);
217  tri.b(0) = f2u8(col.B);
218  colormap(
219  m_colorMap, C(iX + 1, iY + 1), col.R, col.G, col.B);
220  tri.r(1) = f2u8(col.R);
221  tri.g(1) = f2u8(col.G);
222  tri.b(1) = f2u8(col.B);
223  colormap(m_colorMap, C(iX, iY + 1), col.R, col.G, col.B);
224  tri.r(2) = f2u8(col.R);
225  tri.g(2) = f2u8(col.G);
226  tri.b(2) = f2u8(col.B);
227  }
228  else if (m_isImage)
229  {
230  if (getTextureImage().isColor())
231  {
232  tri.r(0) = tri.r(1) = tri.r(2) = C_r(iX, iY);
233  tri.g(0) = tri.g(1) = tri.g(2) = C_g(iX, iY);
234  tri.b(0) = tri.b(1) = tri.b(2) = C_b(iX, iY);
235  }
236  else
237  {
238  tri.r(0) = tri.r(1) = tri.r(2) = C(iX, iY);
239  tri.g(0) = tri.g(1) = tri.g(2) = C(iX, iY);
240  tri.b(0) = tri.b(1) = tri.b(2) = C(iX, iY);
241  }
242  }
243  else
244  {
245  tri.r(0) = tri.r(1) = tri.r(2) = m_color.R / 255.f;
246  tri.g(0) = tri.g(1) = tri.g(2) = m_color.G / 255.f;
247  tri.b(0) = tri.b(1) = tri.b(2) = m_color.B / 255.f;
248  }
249 
250  // Compute normal of this triangle, and add it up to the 3
251  // neighboring vertices:
252  // A = P1 - P0, B = P2 - P0
253  float ax = tri.x(1) - tri.x(0);
254  float bx = tri.x(2) - tri.x(0);
255  float ay = tri.y(1) - tri.y(0);
256  float by = tri.y(2) - tri.y(0);
257  float az = tri.z(1) - tri.z(0);
258  float bz = tri.z(2) - tri.z(0);
259  const TPoint3D this_normal(
260  ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx);
261 
262  // Vertex indices:
263  tvi.vind[1] = tvi.vind[2];
264  tvi.vind[2] = iX + rows * (iY + 1);
265 
266  // Add triangle:
267  actualMesh.emplace_back(tri, tvi);
268 
269  // For averaging normals:
270  for (unsigned long k : tvi.vind)
271  {
272  vertex_normals[k].first += this_normal;
273  vertex_normals[k].second++;
274  }
275  }
276  }
277 
278  // Average normals:
279  for (auto& vertex_normal : vertex_normals)
280  {
281  const size_t N = vertex_normal.second;
282  if (N > 0)
283  {
284  vertex_normal.first *= 1.0 / N;
285  vertex_normal.first = vertex_normal.first.unitarize();
286  }
287  }
288 
289  m_trianglesUpToDate = true;
290  m_polygonsUpToDate = false;
291 }
292 
293 void CMesh::render(const RenderContext& rc) const
294 {
295  switch (rc.shader_id)
296  {
298  if (!m_isWireFrame)
300  break;
302  if (m_isWireFrame) CRenderizableShaderWireFrame::render(rc);
303  break;
304  };
305 }
307 {
308  if (!m_trianglesUpToDate) updateTriangles();
309 
312 }
313 
315 {
318  vbd.clear();
319  cbd.clear();
320 
321  for (auto& i : actualMesh)
322  {
323  const mrpt::opengl::TTriangle& t = i.first;
324 
325  for (int kk = 0; kk <= 3; kk++)
326  {
327  int k = kk % 3;
328  int k1 = (kk + 1) % 3;
329 
330  vbd.emplace_back(t.x(k), t.y(k), t.z(k));
331  cbd.emplace_back(t.r(k), t.g(k), t.b(k), t.a(k));
332 
333  vbd.emplace_back(t.x(k1), t.y(k1), t.z(k1));
334  cbd.emplace_back(t.r(k1), t.g(k1), t.b(k1), t.a(k1));
335  }
336  }
337 }
338 
340 {
342  tris.clear();
343 
344  for (auto& i : actualMesh)
345  {
346  const mrpt::opengl::TTriangle& t = i.first;
347  const TTriangleVertexIndices& tvi = i.second;
348 
349  const auto& n0 = vertex_normals.at(tvi.vind[0]).first;
350  const auto& n1 = vertex_normals.at(tvi.vind[1]).first;
351  const auto& n2 = vertex_normals.at(tvi.vind[2]).first;
352 
353  auto tri = t;
354 
355  tri.vertices[0].normal = n0;
356  tri.vertices[1].normal = n1;
357  tri.vertices[2].normal = n2;
358 
359  for (int k = 0; k < 3; k++)
360  {
361  tri.vertices[k].uv.x =
362  (tri.vertices[k].xyzrgba.pt.x - m_xMin) / (m_xMax - m_xMin);
363  tri.vertices[k].uv.y =
364  (tri.vertices[k].xyzrgba.pt.y - m_yMin) / (m_yMax - m_yMin);
365  }
366 
367  tris.emplace_back(std::move(tri));
368  }
369 }
370 
371 /*---------------------------------------------------------------
372  assignImage
373  ---------------------------------------------------------------*/
374 void CMesh::assignImage(const CImage& img)
375 {
376  MRPT_START
377 
378  // Make a copy:
380 
381  // Delete content in Z
382  Z.setZero(img.getHeight(), img.getWidth());
383 
384  m_modified_Image = true;
385  m_enableTransparency = false;
386  m_colorFromZ = false;
387  m_isImage = true;
388  m_trianglesUpToDate = false;
389 
391 
392  MRPT_END
393 }
394 
396  const CImage& img, const mrpt::math::CMatrixDynamic<float>& in_Z)
397 {
398  MRPT_START
399 
400  ASSERT_(
401  (img.getWidth() == static_cast<size_t>(in_Z.cols())) &&
402  (img.getHeight() == static_cast<size_t>(in_Z.rows())));
403 
404  Z = in_Z;
405 
406  // Load the texture:
408 
409  m_modified_Image = true;
410  m_enableTransparency = false;
411  m_colorFromZ = false;
412  m_isImage = true;
413  m_trianglesUpToDate = false;
414 
416 
417  MRPT_END
418 }
419 
420 uint8_t CMesh::serializeGetVersion() const { return 1; }
422 {
423  writeToStreamRender(out);
424  writeToStreamTexturedObject(out);
425 
426  // Version 0:
427  out << m_xMin << m_xMax << m_yMin << m_yMax;
428  out << Z << mask; // We don't need to serialize C, it's computed
429  out << m_enableTransparency;
430  out << m_colorFromZ;
431  // new in v1
432  out << m_isWireFrame;
433  out << int16_t(m_colorMap);
434 }
435 
437 {
438  switch (version)
439  {
440  case 0:
441  case 1:
442  {
443  readFromStreamRender(in);
444  readFromStreamTexturedObject(in);
445 
446  in >> m_xMin;
447  in >> m_xMax;
448  in >> m_yMin;
449  in >> m_yMax;
450 
451  in >> Z >> mask;
452  in >> m_enableTransparency;
453  in >> m_colorFromZ;
454 
455  if (version >= 1)
456  {
457  in >> m_isWireFrame;
458  int16_t i;
459  in >> i;
460  m_colorMap = mrpt::img::TColormap(i);
461  }
462  else
463  m_isWireFrame = false;
464 
465  m_modified_Z = true;
466  }
467  m_trianglesUpToDate = false;
468  break;
469  default:
471  };
472  m_trianglesUpToDate = false;
474 }
475 
477 {
478  if ((!m_modified_Z) && (!m_modified_Image)) return;
479 
481 
482  if (m_isImage)
483  {
484  const int cols = getTextureImage().getWidth();
485  const int rows = getTextureImage().getHeight();
486 
487  if ((cols != Z.cols()) || (rows != Z.rows()))
488  printf("\nTexture Image and Z sizes have to be equal");
489 
490  else if (getTextureImage().isColor())
491  {
492  C_r.setSize(rows, cols);
493  C_g.setSize(rows, cols);
494  C_b.setSize(rows, cols);
495  getTextureImage().getAsRGBMatrices(C_r, C_g, C_b);
496  }
497  else
498  {
499  C.setSize(rows, cols);
500  getTextureImage().getAsMatrix(C);
501  }
502  }
503  else
504  {
505  const size_t cols = Z.cols();
506  const size_t rows = Z.rows();
507  C.setSize(rows, cols);
508 
509  // Color is proportional to height:
510  C = Z;
511 
512  // If mask is empty -> Normalize the whole mesh
513  if (mask.empty()) mrpt::math::normalize(C, 0.01f, 0.99f);
514 
515  // Else -> Normalize color ignoring masked-out cells:
516  else
517  {
518  float val_max = -std::numeric_limits<float>::max(),
519  val_min = std::numeric_limits<float>::max();
520  bool any_valid = false;
521 
522  for (size_t c = 0; c < cols; c++)
523  for (size_t r = 0; r < rows; r++)
524  {
525  if (!mask(r, c)) continue;
526  any_valid = true;
527  const float val = C(r, c);
528  mrpt::keep_max(val_max, val);
529  mrpt::keep_min(val_min, val);
530  }
531 
532  if (any_valid)
533  {
534  float minMaxDelta = val_max - val_min;
535  if (minMaxDelta == 0) minMaxDelta = 1;
536  const float minMaxDelta_ = 1.0f / minMaxDelta;
537  C.array() = (C.array() - val_min) * minMaxDelta_;
538  }
539  }
540  }
541 
542  m_modified_Image = false;
543  m_modified_Z = false;
544  m_trianglesUpToDate = false;
545 }
546 
548 {
549  Z = in_Z;
550  m_modified_Z = true;
551  m_trianglesUpToDate = false;
552 
553  // Delete previously loaded images
554  m_isImage = false;
555 
557 }
558 
560 {
561  mask = in_mask;
562  m_trianglesUpToDate = false;
564 }
565 
566 bool CMesh::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
567 {
568  if (!m_trianglesUpToDate || !m_polygonsUpToDate) updatePolygons();
569  return mrpt::math::traceRay(tmpPolys, (o - this->m_pose).asTPose(), dist);
570 }
571 
572 static math::TPolygon3D tmpPoly(3);
574  const std::pair<mrpt::opengl::TTriangle, CMesh::TTriangleVertexIndices>& p)
575 {
576  const mrpt::opengl::TTriangle& t = p.first;
577  for (size_t i = 0; i < 3; i++) tmpPoly[i] = t.vertex(i);
579 }
580 
582 {
583  if (!m_trianglesUpToDate) updateTriangles();
584  size_t N = actualMesh.size();
585  tmpPolys.resize(N);
586  transform(
587  actualMesh.begin(), actualMesh.end(), tmpPolys.begin(),
589  m_polygonsUpToDate = true;
591 }
592 
595 {
596  bb_min.x = m_xMin;
597  bb_min.y = m_yMin;
598  bb_min.z = Z.minCoeff();
599 
600  bb_max.x = m_xMax;
601  bb_max.y = m_yMax;
602  bb_max.z = Z.maxCoeff();
603 
604  // Convert to coordinates of my parent:
605  m_pose.composePoint(bb_min, bb_min);
606  m_pose.composePoint(bb_max, bb_max);
607 }
608 
610 {
611  ASSERT_(m_isImage);
612  const float ycenter = 0.5f * (m_yMin + m_yMax);
613  const float xwidth = m_xMax - m_xMin;
614  const float newratio = float(getTextureImage().getWidth()) /
615  float(getTextureImage().getHeight());
616  m_yMax = ycenter + 0.5f * newratio * xwidth;
617  m_yMin = ycenter - 0.5f * newratio * xwidth;
619 }
virtual ~CMesh() override
mrpt::math::TPoint3Df & vertex(size_t i)
Definition: TTriangle.h:109
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...
void colormap(const TColormap &color_map, const float color_index, float &r, float &g, float &b)
Transform a float number in the range [0,1] into RGB components.
Definition: color_maps.cpp:114
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:30
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
#define MRPT_START
Definition: exceptions.h:241
const uint8_t & b(size_t i) const
Definition: TTriangle.h:95
void assignImageAndZ(const mrpt::img::CImage &img, const mrpt::math::CMatrixDynamic< float > &in_Z)
Assigns a texture image and Z simultaneously, and disable transparency.
Definition: CMesh.cpp:395
static constexpr shader_id_t TEXTURED_TRIANGLES
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CMesh.cpp:420
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.
const uint8_t & r(size_t i) const
Definition: TTriangle.h:93
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
Slightly heavyweight type to speed-up calculations with polygons in 3D.
This file implements several operations that operate element-wise on individual or pairs of container...
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CMesh.cpp:436
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
const uint8_t & g(size_t i) const
Definition: TTriangle.h:94
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:849
STL namespace.
void setMask(const mrpt::math::CMatrixDynamic< float > &in_mask)
This method sets the boolean mask of valid heights for each position (cell) in the mesh grid...
Definition: CMesh.cpp:559
Context for calls to render()
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
void assignImage(const mrpt::img::CImage &img)
Assigns a texture image.
Definition: CMesh.cpp:374
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
const uint8_t & a(size_t i) const
Definition: TTriangle.h:96
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CMesh.cpp:421
std::array< Vertex, 3 > vertices
Definition: TTriangle.h:88
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
mrpt::img::CImage CImage
Definition: utils/CImage.h:5
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:818
void normalize(CONTAINER &c, Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
static constexpr shader_id_t WIREFRAME
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Trace ray.
Definition: CMesh.cpp:566
int val
Definition: mrpt_jpeglib.h:957
TPoint3D_< double > TPoint3D
Lightweight 3D point.
Definition: TPoint3D.h:268
void updatePolygons() const
Definition: CMesh.cpp:581
mrpt::math::TPolygonWithPlane createPolygonFromTriangle(const std::pair< mrpt::opengl::TTriangle, CMesh::TTriangleVertexIndices > &p)
Definition: CMesh.cpp:573
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CMesh.cpp:293
void setZ(const mrpt::math::CMatrixDynamic< float > &in_Z)
This method sets the matrix of heights for each position (cell) in the mesh grid. ...
Definition: CMesh.cpp:547
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...
TPoint3D_< T > unitarize() const
Returns this vector with unit length: v/norm(v)
Definition: TPoint3D.h:153
std::vector< mrpt::img::TColor > m_color_buffer_data
uint8_t f2u8(const float f)
converts a float [0,1] into an uint8_t [0,255] (without checking for out of bounds) ...
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
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: CMesh.cpp:593
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CMesh.cpp:314
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
#define ASSERT_ABOVE_(__A, __B)
Definition: exceptions.h:155
#define MRPT_END
Definition: exceptions.h:245
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
void updateColorsMatrix() const
Called internally to assure C is updated.
Definition: CMesh.cpp:476
const auto bb_max
void adjustGridToImageAR()
Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the ...
Definition: CMesh.cpp:609
const auto bb_min
void onUpdateBuffers_TexturedTriangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CMesh.cpp:339
A planar (XY) grid where each cell has an associated height and, optionally, a texture map...
Definition: CMesh.h:37
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
double getHeight(const TPolygon3D &p, const TPoint3D &c)
This template class provides the basic functionality for a general 2D any-size, resizable container o...
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
static math::TPolygon3D tmpPoly(3)
void updateTriangles() const
Called internally to assure the triangle list is updated.
Definition: CMesh.cpp:56
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...
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Definition: CMesh.cpp:306
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 7b5ddf9de Fri May 29 14:02:56 2020 +0200 at vie may 29 14:15:09 CEST 2020