Main MRPT website > C++ reference for MRPT 1.9.9
CPolygon.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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:
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 
56  TPolygon2D::resize(n);
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 
82  TPolygon2D::resize(n);
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 
105  TPolygon2D::resize(n);
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 }
n
GLenum GLsizei n
Definition: glext.h:5074
mrpt::containers::operator[]
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn't exist already.
Definition: ts_hash_map.h:199
mrpt::math::CPolygon::serializeFrom
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
mrpt::math::CPolygon::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CPolygon.cpp:23
math-precomp.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
mrpt::math::CPolygon::setAllVertices
void setAllVertices(const std::vector< double > &x, const std::vector< double > &y)
Set all vertices at once.
Definition: CPolygon.cpp:121
CPolygon.h
mrpt::math::CPolygon
A wrapper of a TPolygon2D class, implementing CSerializable.
Definition: CPolygon.h:21
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
in
GLuint in
Definition: glext.h:7274
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::serialization::CArchive::WriteBufferFixEndianness
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
Definition: CArchive.h:123
mrpt::math::CPolygon::getAllVertices
void getAllVertices(std::vector< double > &x, std::vector< double > &y) const
Get all vertices at once.
Definition: CPolygon.cpp:158
size
GLsizeiptr size
Definition: glext.h:3923
y
GLenum GLint GLint y
Definition: glext.h:3538
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
x
GLenum GLint x
Definition: glext.h:3538



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST