IOLink IOL_v1.8.0_release
Loading...
Searching...
No Matches
Region.h
1#pragma once
2
3#include <iolink/RegionX.h>
4#include <iolink/Vector.h>
5
6namespace iolink
7{
38template <typename T, size_t N>
39class Region final
40{
41public:
43 using SizeType = Vector<T, N>;
44
49
56
67 template <typename U, size_t P>
68 explicit Region(const Region<U, P>& other)
69 : m_origin(other.min(), 0)
70 , m_size(other.size(), 1)
71 {
72 }
73
77 inline size_t dimensionCount() const { return N; }
78
82 inline const VectorType& origin() const { return m_origin; }
83
88 inline const SizeType& size() const { return m_size; }
89
95 size_t elementCount() const;
96
101 inline VectorType min() const { return m_origin; }
102
108
113 bool isEmpty() const;
114
120 bool contains(const Region& other) const;
121
127 bool contains(const VectorType& position) const;
128
134 bool intersect(const Region& other) const;
135
141 Region intersection(const Region& other) const;
142
161 Region extractSliceFromAxis(size_t dimension, T origin) const;
162
169 bool operator==(const Region& other) const;
170
171 Region(const RegionX<T>& other);
172
173 operator RegionX<T>() const;
174
178 std::string toString() const;
179
180private:
181 VectorType m_origin;
182
183 // size computation depends on given indexer type T.
184 // For integer indexers, size is equal to max()- min() + 1
185 // For float indexers, size is equal to max()- min()
186 SizeType m_size;
187};
188
189// ============================ //
190// Extern template declarations //
191// ============================ //
192
193extern template class IOLINK_API_IMPORT Region<uint64_t, 2>;
194
195extern template class IOLINK_API_IMPORT Region<uint64_t, 3>;
196
197extern template class IOLINK_API_IMPORT Region<uint64_t, 4>;
198
199// ================= //
200// Alias definitions //
201// ================= //
202
203template <typename T>
204using Region2 = Region<T, 2>;
205template <typename T>
206using Region3 = Region<T, 3>;
207template <typename T>
208using Region4 = Region<T, 4>;
209
213
214} // end namespace iolink