IOLink  IOL_v1.6.1_release
Region.h
1 #pragma once
2 
3 #include <iolink/RegionX.h>
4 #include <iolink/Vector.h>
5 
6 namespace iolink
7 {
38 template <typename T, size_t N>
39 class Region final
40 {
41 public:
42  using VectorType = Vector<T, N>;
43  using SizeType = Vector<T, N>;
44 
48  Region();
49 
55  Region(const VectorType& origin, const SizeType& size);
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 
107  VectorType max() const;
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 
180 private:
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 
193 extern template class IOLINK_API_IMPORT Region<uint64_t, 2>;
194 
195 extern template class IOLINK_API_IMPORT Region<uint64_t, 3>;
196 
197 extern template class IOLINK_API_IMPORT Region<uint64_t, 4>;
198 
199 // ================= //
200 // Alias definitions //
201 // ================= //
202 
203 template <typename T>
204 using Region2 = Region<T, 2>;
205 template <typename T>
206 using Region3 = Region<T, 3>;
207 template <typename T>
208 using Region4 = Region<T, 4>;
209 
213 
214 } // end namespace iolink