MRPT  1.9.9
CSetOfTexturedTriangles.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 
15 #include <mrpt/opengl/opengl_api.h>
16 
17 using namespace std;
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 using namespace mrpt::math;
21 
23 
24 void CSetOfTexturedTriangles::onUpdateBuffers_TexturedTriangles()
25 {
26  // Nothing else to do: all data is already in m_triangles in my base class.
27 }
28 
29 uint8_t CSetOfTexturedTriangles::serializeGetVersion() const { return 2; }
30 void CSetOfTexturedTriangles::serializeTo(
32 {
33  uint32_t n;
34 
35  writeToStreamRender(out);
36  writeToStreamTexturedObject(out);
37 
38  n = (uint32_t)m_triangles.size();
39 
40  out << n;
41 
42  for (uint32_t i = 0; i < n; i++) m_triangles[i].writeTo(out);
43 }
44 
45 void CSetOfTexturedTriangles::serializeFrom(
46  mrpt::serialization::CArchive& in, uint8_t version)
47 {
48  switch (version)
49  {
50  case 0:
51  case 1:
52  case 2:
53  {
54  readFromStreamRender(in);
55  if (version >= 2)
56  {
57  readFromStreamTexturedObject(in);
58  }
59  else
60  { // Old version.
61  THROW_EXCEPTION("deserializing old version not supported.");
62  }
63 
64  uint32_t n;
65  in >> n;
66  m_triangles.resize(n);
67 
68  for (uint32_t i = 0; i < n; i++) m_triangles[i].readFrom(in);
69  }
70  break;
71  default:
73  };
74  CRenderizable::notifyChange();
75 }
76 
78  [[maybe_unused]] const mrpt::poses::CPose3D& o,
79  [[maybe_unused]] double& dist) const
80 {
81  throw std::runtime_error(
82  "TODO: TraceRay not implemented in CSetOfTexturedTriangles");
83 }
84 
85 void CSetOfTexturedTriangles::getBoundingBox(
87 {
89  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
90  std::numeric_limits<double>::max());
92  -std::numeric_limits<double>::max(),
93  -std::numeric_limits<double>::max(),
94  -std::numeric_limits<double>::max());
95 
96  for (const auto& t : m_triangles)
97  {
98  for (size_t i = 0; i < 3; i++)
99  {
100  keep_min(bb_min.x, t.x(i));
101  keep_max(bb_max.x, t.x(i));
102 
103  keep_min(bb_min.y, t.y(i));
104  keep_max(bb_max.y, t.y(i));
105 
106  keep_min(bb_min.z, t.z(i));
107  keep_max(bb_max.z, t.z(i));
108  }
109  }
110 
111  // Convert to coordinates of my parent:
112  m_pose.composePoint(bb_min, bb_min);
113  m_pose.composePoint(bb_max, bb_max);
114 }
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...
#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.
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
STL namespace.
#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.
TPoint3D_< double > TPoint3D
Lightweight 3D point.
Definition: TPoint3D.h:268
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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
const auto bb_min



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020