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  const mrpt::poses::CPose3D& o, double& dist) const
79 {
81  MRPT_UNUSED_PARAM(dist);
82  throw std::runtime_error(
83  "TODO: TraceRay not implemented in CSetOfTexturedTriangles");
84 }
85 
86 void CSetOfTexturedTriangles::getBoundingBox(
88 {
90  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
91  std::numeric_limits<double>::max());
93  -std::numeric_limits<double>::max(),
94  -std::numeric_limits<double>::max(),
95  -std::numeric_limits<double>::max());
96 
97  for (const auto& t : m_triangles)
98  {
99  for (size_t i = 0; i < 3; i++)
100  {
101  keep_min(bb_min.x, t.x(i));
102  keep_max(bb_max.x, t.x(i));
103 
104  keep_min(bb_min.y, t.y(i));
105  keep_max(bb_max.y, t.y(i));
106 
107  keep_min(bb_min.z, t.z(i));
108  keep_max(bb_max.z, t.z(i));
109  }
110  }
111 
112  // Convert to coordinates of my parent:
113  m_pose.composePoint(bb_min, bb_min);
114  m_pose.composePoint(bb_max, bb_max);
115 }
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:2551
#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
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 3a26b90fd Wed Mar 25 20:17:03 2020 +0100 at miƩ mar 25 23:05:41 CET 2020