polygon_3d.hpp
1 #pragma once
2 
3 #include <vector>
4 
5 #include "global.hpp"
6 
7 #include "point_3d.hpp"
8 #include "point_3d_h.hpp"
9 
10 namespace Cvb
11 {
12 
13 CVB_BEGIN_INLINE_NS
14 
15 template <class T>
16 using IsPolygonPoint =
20 
21 template <class T>
22 using EnablePolygonPoint = std::enable_if<IsPolygonPoint<T>::value>;
23 
25 
27 template<class T, class ENABLE = void>
28 class Polygon3D final
29 {
30 
31 #ifndef CVB_DOXYGEN
32  static_assert (IsPolygonPoint<T>::value, "CVB: Polygon type must be Point3D or Point3DH with floating point type");
33 };
34 
35 
36 template <class T>
37 class Polygon3D<T,
38  typename EnablePolygonPoint<T>::type> final
39 {
40 
41 #endif
42 
43  public:
44 
45 
46  Polygon3D() = default;
47 
48  Polygon3D(const Polygon3D&) = default;
49 
50  Polygon3D& operator=(const Polygon3D&) = default;
51 
53 
58  : points_(std::move(points))
59  {
60  }
61 
62  Polygon3D(Polygon3D&&) = default;
63  Polygon3D& operator=(Polygon3D&&) = default;
64 
66 
70  explicit Polygon3D(const std::vector<T>& points) noexcept
71  : points_(points)
72  {
73  }
74 
76 
80  template<std::size_t N>
81  Polygon3D(const T(&list)[N]) noexcept
82  {
83  static_assert(N >= 3, "CVB: Poligon3D must have at least three points");
84  points_ = std::vector<T>(list, list + N);
85  }
86 
88 
93  const T& operator[](std::size_t index) const noexcept
94  {
95  return points_[index];
96  }
97 
99 
104  const T& At(std::size_t index) const
105  {
106  return points_.at(index);
107  }
108 
110 
114  std::size_t NumPoints() const noexcept
115  {
116  return points_.size();
117  }
118 
120 
124  auto CBegin() const noexcept
125  {
126  return points_.cbegin();
127  }
128 
130 
134  auto Begin() const noexcept
135  {
136  return CBegin();
137  }
138 
140 
144  auto cbegin() const noexcept
145  {
146  return CBegin();
147  }
148 
150 
154  auto begin() const noexcept
155  {
156  return CBegin();
157  }
158 
160 
164  auto CEnd() const noexcept
165  {
166  return points_.cend();
167  }
168 
170 
174  auto End() const noexcept
175  {
176  return CEnd();
177  }
178 
180 
184  auto cend() const noexcept
185  {
186  return CEnd();
187  }
188 
190 
194  auto end() const noexcept
195  {
196  return cend();
197  }
198 
200 
204  auto CRBegin() const noexcept
205  {
206  return points_.crbegin();
207  }
208 
210 
214  auto RBegin() const noexcept
215  {
216  return CRBegin();
217  }
218 
220 
224  auto crbegin() const noexcept
225  {
226  return CRBegin();
227  }
228 
230 
234  auto rbegin() const noexcept
235  {
236  return crbegin();
237  }
238 
240 
244  auto CREnd() const noexcept
245  {
246  return points_.crend();
247  }
248 
250 
254  auto REnd() const noexcept
255  {
256  return CREnd();
257  }
258 
260 
264  auto crend() const noexcept
265  {
266  return CREnd();
267  }
268 
270 
274  auto rend() const noexcept
275  {
276  return crend();
277  }
278 
280 
285  bool operator==(const Polygon3D<T>& polygon) const noexcept
286  {
287  return points_ == polygon.points_;
288  }
289 
290 
292 
297  bool operator!=(const Polygon3D<T>& polygon) const noexcept
298  {
299  return !(*this == polygon);
300  }
301 
303  template <class C>
304  explicit operator Polygon3D<C>() const noexcept
305  {
306  std::vector<C> points;
307  points.reserve(points_.size());
308  for (const auto& point : points_)
309  points.emplace_back(static_cast<C>(point));
310  return Polygon3D<C>(std::move(points));
311  }
312 
313  private:
314 
315  std::vector<T> points_;
316 
317 
318 
319 };
320 
321 CVB_END_INLINE_NS
322 
323 
324 }
auto cbegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:144
const T & At(std::size_t index) const
Gets the point ata given index.
Definition: polygon_3d.hpp:104
Polygon3D(const T(&list)[N]) noexcept
Construct a polygon with an initializer list.
Definition: polygon_3d.hpp:81
auto crbegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:224
auto rbegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:234
auto CBegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:124
auto End() const noexcept
Iterator access.
Definition: polygon_3d.hpp:174
auto crend() const noexcept
Iterator access.
Definition: polygon_3d.hpp:264
auto Begin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:134
auto CEnd() const noexcept
Iterator access.
Definition: polygon_3d.hpp:164
auto cend() const noexcept
Iterator access.
Definition: polygon_3d.hpp:184
Root namespace for the Image Manager interface.
Definition: version.hpp:11
std::size_t NumPoints() const noexcept
Gets the number of points in this polygon.
Definition: polygon_3d.hpp:114
A polygon in 3D space.
Definition: polygon_3d.hpp:28
auto end() const noexcept
Iterator access.
Definition: polygon_3d.hpp:194
bool operator==(const Polygon3D< T > &polygon) const noexcept
Compares to an other polygon.
Definition: polygon_3d.hpp:285
bool operator!=(const Polygon3D< T > &polygon) const noexcept
Compares to an other polygon.
Definition: polygon_3d.hpp:297
auto RBegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:214
STL class.
auto rend() const noexcept
Iterator access.
Definition: polygon_3d.hpp:274
const T & operator[](std::size_t index) const noexcept
Gets the point at a given index.
Definition: polygon_3d.hpp:93
Polygon3D(std::vector< T > &&points)
Construct a polygon from a vector.
Definition: polygon_3d.hpp:57
Polygon3D(const std::vector< T > &points) noexcept
Construct a polygon from a vector.
Definition: polygon_3d.hpp:70
auto CRBegin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:204
auto REnd() const noexcept
Iterator access.
Definition: polygon_3d.hpp:254
auto begin() const noexcept
Iterator access.
Definition: polygon_3d.hpp:154
auto CREnd() const noexcept
Iterator access.
Definition: polygon_3d.hpp:244