CVB++ 15.0
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
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
15 template <class T>
16 using IsPolygonPoint = std::integral_constant<bool, (std::is_same<Point3D<typename T::ValueType>, T>::value
17 || std::is_same<Point3DH<typename T::ValueType>, T>::value)
18 && std::is_floating_point<typename T::ValueType>::value>;
19
20 template <class T>
21 using EnablePolygonPoint = std::enable_if<IsPolygonPoint<T>::value>;
22
24
26 template <class T, class ENABLE = void>
27 class Polygon3D final
28 {
29
30#ifndef CVB_DOXYGEN
31 static_assert(IsPolygonPoint<T>::value, "CVB: Polygon type must be Point3D or Point3DH with floating point type");
32 };
33
34 template <class T>
35 class Polygon3D<T, typename EnablePolygonPoint<T>::type> final
36 {
37
38#endif
39
40 public:
41 Polygon3D() = default;
42
43 Polygon3D(const Polygon3D &) = default;
44
45 Polygon3D &operator=(const Polygon3D &) = default;
46
47 ~Polygon3D() = default;
48
50
54 explicit Polygon3D(std::vector<T> &&points)
55 : points_(std::move(points))
56 {
57 }
58
59 Polygon3D(Polygon3D &&) = default;
60 Polygon3D &operator=(Polygon3D &&) = default;
61
63
67 explicit Polygon3D(const std::vector<T> &points) noexcept
68 : points_(points)
69 {
70 }
71
73
77 template <std::size_t N>
78 Polygon3D(const T (&list)[N]) noexcept // NOLINT
79 {
80 static_assert(N >= 3, "CVB: Poligon3D must have at least three points");
81 points_ = std::vector<T>(list, list + N); // NOLINT(cppcoreguidelines-prefer-member-initializer)
82 }
83
85
90 const T &operator[](std::size_t index) const noexcept
91 {
92 return points_[index];
93 }
94
96
101 const T &At(std::size_t index) const
102 {
103 return points_.at(index);
104 }
105
107
111 std::size_t NumPoints() const noexcept
112 {
113 return points_.size();
114 }
115
117
121 auto CBegin() const noexcept
122 {
123 return points_.cbegin();
124 }
125
127
131 auto Begin() const noexcept
132 {
133 return CBegin();
134 }
135
137
141 auto cbegin() const noexcept
142 {
143 return CBegin();
144 }
145
147
151 auto begin() const noexcept
152 {
153 return CBegin();
154 }
155
157
161 auto CEnd() const noexcept
162 {
163 return points_.cend();
164 }
165
167
171 auto End() const noexcept
172 {
173 return CEnd();
174 }
175
177
181 auto cend() const noexcept
182 {
183 return CEnd();
184 }
185
187
191 auto end() const noexcept
192 {
193 return cend();
194 }
195
197
201 auto CRBegin() const noexcept
202 {
203 return points_.crbegin();
204 }
205
207
211 auto RBegin() const noexcept
212 {
213 return CRBegin();
214 }
215
217
221 auto crbegin() const noexcept
222 {
223 return CRBegin();
224 }
225
227
231 auto rbegin() const noexcept
232 {
233 return crbegin();
234 }
235
237
241 auto CREnd() const noexcept
242 {
243 return points_.crend();
244 }
245
247
251 auto REnd() const noexcept
252 {
253 return CREnd();
254 }
255
257
261 auto crend() const noexcept
262 {
263 return CREnd();
264 }
265
267
271 auto rend() const noexcept
272 {
273 return crend();
274 }
275
277
282 bool operator==(const Polygon3D<T> &polygon) const noexcept
283 {
284 return points_ == polygon.points_;
285 }
286
288
293 bool operator!=(const Polygon3D<T> &polygon) const noexcept
294 {
295 return !(*this == polygon);
296 }
297
299 template <class C>
300 explicit operator Polygon3D<C>() const noexcept
301 {
302 std::vector<C> points;
303 points.reserve(points_.size());
304 for (const auto &point : points_)
305 points.emplace_back(static_cast<C>(point));
306 return Polygon3D<C>(std::move(points));
307 }
308
309 private:
310 std::vector<T> points_;
311 };
312
313 CVB_END_INLINE_NS
314
315} // namespace Cvb
A polygon in 3D space.
Definition polygon_3d.hpp:28
auto Begin() const noexcept
Iterator access.
Definition polygon_3d.hpp:131
auto CREnd() const noexcept
Iterator access.
Definition polygon_3d.hpp:241
auto end() const noexcept
Iterator access.
Definition polygon_3d.hpp:191
Polygon3D(const std::vector< T > &points) noexcept
Construct a polygon from a vector.
Definition polygon_3d.hpp:67
auto rbegin() const noexcept
Iterator access.
Definition polygon_3d.hpp:231
auto REnd() const noexcept
Iterator access.
Definition polygon_3d.hpp:251
auto cend() const noexcept
Iterator access.
Definition polygon_3d.hpp:181
const T & At(std::size_t index) const
Gets the point ata given index.
Definition polygon_3d.hpp:101
auto CRBegin() const noexcept
Iterator access.
Definition polygon_3d.hpp:201
const T & operator[](std::size_t index) const noexcept
Gets the point at a given index.
Definition polygon_3d.hpp:90
auto crend() const noexcept
Iterator access.
Definition polygon_3d.hpp:261
auto crbegin() const noexcept
Iterator access.
Definition polygon_3d.hpp:221
auto begin() const noexcept
Iterator access.
Definition polygon_3d.hpp:151
auto RBegin() const noexcept
Iterator access.
Definition polygon_3d.hpp:211
bool operator!=(const Polygon3D< T > &polygon) const noexcept
Compares to an other polygon.
Definition polygon_3d.hpp:293
Polygon3D(const T(&list)[N]) noexcept
Construct a polygon with an initializer list.
Definition polygon_3d.hpp:78
bool operator==(const Polygon3D< T > &polygon) const noexcept
Compares to an other polygon.
Definition polygon_3d.hpp:282
auto CBegin() const noexcept
Iterator access.
Definition polygon_3d.hpp:121
auto End() const noexcept
Iterator access.
Definition polygon_3d.hpp:171
Polygon3D(std::vector< T > &&points)
Construct a polygon from a vector.
Definition polygon_3d.hpp:54
std::size_t NumPoints() const noexcept
Gets the number of points in this polygon.
Definition polygon_3d.hpp:111
auto rend() const noexcept
Iterator access.
Definition polygon_3d.hpp:271
auto CEnd() const noexcept
Iterator access.
Definition polygon_3d.hpp:161
auto cbegin() const noexcept
Iterator access.
Definition polygon_3d.hpp:141
T move(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17