| IOLink 1.11.0

Loading...
Searching...
No Matches
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
210 using Region2u64 = Region2<uint64_t>;
211 using Region3u64 = Region3<uint64_t>;
212 using Region4u64 = Region4<uint64_t>;
213
214} // end namespace iolink
iolink::Region
A multi-dimensional region defined by its origin and its size.
Definition Region.h:40
iolink::Region::Region
Region(const Region< U, P > &other)
Build a region from another of different dimension and different type.
Definition Region.h:68
iolink::Region::contains
bool contains(const VectorType &position) const
Returns if the given region contains the given position vector.
iolink::Region::isEmpty
bool isEmpty() const
Indicates if region is empty.
iolink::Region::origin
const VectorType & origin() const
Return region's origin.
Definition Region.h:82
iolink::Region::elementCount
size_t elementCount() const
Return number of elements (pixel, voxel, samples) contained in the region.
iolink::Region::extractSliceFromAxis
Region extractSliceFromAxis(size_t dimension, T origin) const
Returns a region of size one along one axis.
iolink::Region::min
VectorType min() const
return min region coordinates
Definition Region.h:101
iolink::Region::contains
bool contains(const Region &other) const
Returns if the current region contains the given one.
iolink::Region::Region
Region()
Create an empty region.
iolink::Region::Region
Region(const VectorType &origin, const SizeType &size)
Create a region with given origin and size.
iolink::Region::toString
std::string toString() const
Return a string representation.
iolink::Region::size
const SizeType & size() const
return size of region
Definition Region.h:88
iolink::Region::operator==
bool operator==(const Region &other) const
Returns the intersection region between current and given one.
iolink::Region::intersect
bool intersect(const Region &other) const
Returns if the given region intersects the given position vector.
iolink::Region::dimensionCount
size_t dimensionCount() const
Return number of dimension of this region.
Definition Region.h:77
iolink::Region::max
VectorType max() const
return max region coordinates
iolink::Region::intersection
Region intersection(const Region &other) const
Returns the intersection region between current and given one.
iolink::RegionX
A Region using dynamic vectors.
Definition RegionX.h:14
iolink::Vector
An arithmetic vector.
Definition Vector.h:37
iolink
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8