MRPT  2.0.4
CPolygon.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 "math-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/CPolygon.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::math;
17 using namespace std;
18 
19 // This must be added to any CSerializable class implementation file.
21 
22 uint8_t CPolygon::serializeGetVersion() const { return 2; }
24 {
25  // The number of vertexs:
26  const auto n = (uint32_t)TPolygon2D::size();
27 
28  // Size:
29  out << n;
30 
31  // Vertices:
32  if (n)
33  out.WriteBufferFixEndianness<double>(
34  (double*)&TPolygon2D::operator[](0), 2 * n);
35 }
36 
38 {
39  switch (version)
40  {
41  case 0: // floats
42  {
43  // The number of vertexs:
44  uint32_t i, n;
45  float f;
46 
47  // All elemental typed variables:
48  in >> n;
49  in >> f; // max_x=f;
50  in >> f; // max_y=f;
51  in >> f; // min_x=f;
52  in >> f; // min_y=f;
53  in >> f; // cx=f;
54  in >> f; // cy=f;
55 
57 
58  // The vertexs arrays:
59  for (i = 0; i < n; i++)
60  {
61  in >> f;
62  TPolygon2D::operator[](i).x = f;
63  }
64  for (i = 0; i < n; i++)
65  {
66  in >> f;
67  TPolygon2D::operator[](i).y = f;
68  }
69  }
70  break;
71 
72  case 1:
73  {
74  // The number of vertexs:
75  uint32_t n;
76  double dumm;
77 
78  // All elemental typed variables:
79  in >> n >> dumm >> dumm >> dumm >> dumm >> dumm >> dumm;
80  // max_x >> max_y >> min_x >> min_y >> cx >> cy;
81 
83 
84  // The vertexs arrays:
85  for (size_t i = 0; i < n; i++)
86  {
87  in >> dumm;
88  TPolygon2D::operator[](i).x = dumm;
89  }
90  for (size_t i = 0; i < n; i++)
91  {
92  in >> dumm;
93  TPolygon2D::operator[](i).y = dumm;
94  }
95  }
96  break;
97  case 2:
98  {
99  // The number of vertexs:
100  uint32_t n;
101 
102  // All elemental typed variables:
103  in >> n;
104 
106 
107  // The vertexs arrays:
108  if (n > 0)
109  in.ReadBufferFixEndianness<double>(
110  (double*)&TPolygon2D::operator[](0), 2 * n);
111  }
112  break;
113  default:
115  };
116 }
117 
118 /*---------------------------------------------------------------
119  Set all vertices at once, not to be used normally.
120  ---------------------------------------------------------------*/
122  const std::vector<double>& x, const std::vector<double>& y)
123 {
124  ASSERT_(x.size() == y.size() && !x.empty());
125  setAllVertices(x.size(), &x[0], &y[0]);
126 }
127 
128 /*---------------------------------------------------------------
129  Set all vertices at once, not to be used normally.
130  ---------------------------------------------------------------*/
132  size_t nVertices, const double* xs, const double* ys)
133 {
134  // Resize:
135  TPolygon2D::resize(nVertices);
136  for (size_t i = 0; i < nVertices; i++)
137  {
138  TPolygon2D::operator[](i).x = xs[i];
139  TPolygon2D::operator[](i).y = ys[i];
140  }
141 }
142 
143 /*---------------------------------------------------------------
144  Set all vertices at once, not to be used normally.
145  ---------------------------------------------------------------*/
147  size_t nVertices, const float* xs, const float* ys)
148 {
149  // Resize:
150  TPolygon2D::resize(nVertices);
151  for (size_t i = 0; i < nVertices; i++)
152  {
153  TPolygon2D::operator[](i).x = xs[i];
154  TPolygon2D::operator[](i).y = ys[i];
155  }
156 }
157 
159  std::vector<double>& x, std::vector<double>& y) const
160 {
161  // Resize:
162  const size_t n = TPolygon2D::size();
163  x.resize(n);
164  y.resize(n);
165  for (size_t i = 0; i < n; i++)
166  {
167  x[i] = TPolygon2D::operator[](i).x;
168  y[i] = TPolygon2D::operator[](i).y;
169  }
170 }
size_t size(const MATRIXLIKE &m, const int dim)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void setAllVertices(const std::vector< double > &x, const std::vector< double > &y)
Set all vertices at once.
Definition: CPolygon.cpp:121
A wrapper of a TPolygon2D class, implementing CSerializable.
Definition: CPolygon.h:19
STL namespace.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CPolygon.cpp:37
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn&#39;t exist already.
Definition: ts_hash_map.h:216
void getAllVertices(std::vector< double > &x, std::vector< double > &y) const
Get all vertices at once.
Definition: CPolygon.cpp:158
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
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.
Definition: CPolygon.cpp:23
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
mrpt::vision::TStereoCalibResults out
size_t ReadBufferFixEndianness(T *ptr, size_t ElementCount)
Reads a sequence of elemental datatypes, taking care of reordering their bytes from the MRPT stream s...
Definition: CArchive.h:94
images resize(NUM_IMGS)



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020