MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlImageVector.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2010, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_IMAGE_VECTOR_H
14#define ML_IMAGE_VECTOR_H
15
19
20// ML-includes
21#include "mlIntegerVector.h"
22
23
25
26//-------------------------------------------------------------------------
28//-------------------------------------------------------------------------
29enum {
31};
32
33//-------------------------------------------------------------------------
39//-------------------------------------------------------------------------
40template <typename CompIntType> class TVector6DBase
41{
42public:
45
47 enum {
48 NumberOfDimensions = MLMaxImageDimension
49 };
50
51 // We use a union to make the vector members accessible
52 // either with .x, ... .z or with .array[0..MLMaxImageDimension-1].
53 // Below, we also provide indexing operators [] on the array.
54 union
55 {
56 //------------------------------------------------------
59 //------------------------------------------------------
60 struct
61 {
74 };
76
79 ComponentType array[NumberOfDimensions];
80 };
81
82protected:
87};
88
89
90//-------------------------------------------------------------------------
95
135//-------------------------------------------------------------------------
136template <typename CompIntType = MLint> class TImageVector : public TVector<TVector6DBase<CompIntType>>
137{
138public:
141
144
145 //------------------------------------------------------
148 //------------------------------------------------------
150 inline static MLint dim()
151 {
152 return MLMaxImageDimension;
153 }
155
156 // Propagates constructors and sets shadowed methods from the base class.
159 : ParentClass()
160 {}
161
164 inline TImageVector(const ParentClass& v)
165 : ParentClass(v)
166 {}
167
169 inline explicit TImageVector(const ComponentType i)
170 : ParentClass(i)
171 {}
172
175 template <typename T2IntType> inline explicit TImageVector(const TImageVector<T2IntType>& v2)
176 : ParentClass(v2)
177 {}
178
181 : ParentClass(xp, p)
182 {}
183
185 inline void set(const ComponentType v = 0)
186 {
187 ParentClass::set(v);
188 }
189
191 inline void set(const ParentClass& v)
192 {
193 ParentClass::set(v);
194 }
195
199 inline TImageVector(const MLint num, const ComponentType* const arr, const ComponentType deflt)
200 : ParentClass(num, arr, deflt)
201 {}
202
203
204 // Adds specialized constructors and functionality.
207 const ComponentType tp, const ComponentType up)
208 {
209 ParentClass::x = xp;
210 ParentClass::y = yp;
211 ParentClass::z = zp;
212 ParentClass::c = cp;
213 ParentClass::t = tp;
214 ParentClass::u = up;
215 }
216
219 inline explicit TImageVector(const Vector6& v6)
220 {
221 ParentClass::x = static_cast<ComponentType>(v6[0]);
222 ParentClass::y = static_cast<ComponentType>(v6[1]);
223 ParentClass::z = static_cast<ComponentType>(v6[2]);
224 ParentClass::c = static_cast<ComponentType>(v6[3]);
225 ParentClass::t = static_cast<ComponentType>(v6[4]);
226 ParentClass::u = static_cast<ComponentType>(v6[5]);
227 }
228
230 inline void set(const ComponentType vx, const ComponentType vy, const ComponentType vz = 0,
231 const ComponentType vc = 0, const ComponentType vt = 0, const ComponentType vu = 0)
232 {
233 ParentClass::x = vx;
234 ParentClass::y = vy;
235 ParentClass::z = vz;
236 ParentClass::c = vc;
237 ParentClass::t = vt;
238 ParentClass::u = vu;
239 }
240
242 inline void get(ComponentType* const xp = nullptr, ComponentType* const yp = nullptr,
243 ComponentType* const zp = nullptr, ComponentType* const cp = nullptr,
244 ComponentType* const tp = nullptr, ComponentType* const up = nullptr) const
245 {
246 if (xp) {
247 *xp = ParentClass::x;
248 }
249 if (yp) {
250 *yp = ParentClass::y;
251 }
252 if (zp) {
253 *zp = ParentClass::z;
254 }
255 if (cp) {
256 *cp = ParentClass::c;
257 }
258 if (tp) {
259 *tp = ParentClass::t;
260 }
261 if (up) {
262 *up = ParentClass::u;
263 }
264 }
265
274 {
275 ParentClass::x++;
276 if (ParentClass::x >= ext.x) {
277 ParentClass::x = 0;
278 ParentClass::y++;
279 if (ParentClass::y >= ext.y) {
280 ParentClass::y = 0;
281 ParentClass::z++;
282 if (ParentClass::z >= ext.z) {
283 ParentClass::z = 0;
284 ParentClass::c++;
285 if (ParentClass::c >= ext.c) {
286 ParentClass::c = 0;
287 ParentClass::t++;
288 if (ParentClass::t >= ext.t) {
289 ParentClass::t = 0;
290 ParentClass::u++;
291 if (ParentClass::u >= ext.u) {
292 ParentClass::u = 0;
293 return true;
294 }
295 }
296 }
297 }
298 }
299 }
300 return false;
301 }
302
304 inline Vector6 toVector6() const
305 {
306 return Vector6(static_cast<double>(ParentClass::x), static_cast<double>(ParentClass::y),
307 static_cast<double>(ParentClass::z), static_cast<double>(ParentClass::c),
308 static_cast<double>(ParentClass::t), static_cast<double>(ParentClass::u));
309 }
310
312 inline Vector3 toVector3() const
313 {
314 return Vector3(static_cast<double>(ParentClass::x), static_cast<double>(ParentClass::y),
315 static_cast<double>(ParentClass::z));
316 }
317};
318
321
323
324#endif
ImageVector is the 6D TVector specialization used by the ML for all image indexing.
static MLint dim()
Returns the dimension the ML calculates with.
bool iterate(const TImageVector< ComponentType > &ext)
Coordinate incrementation/iterator function inside ext.
TImageVector(const ComponentType xp, const ComponentType yp, const ComponentType zp, const ComponentType cp, const ComponentType tp, const ComponentType up)
Constructor that initializes all components with the values x, y, z, c, t and u.
void set(const ParentClass &v)
Like assignment operator.
ParentClass::ComponentType ComponentType
Integer type used by this vector.
TImageVector(const TImageVector< T2IntType > &v2)
Copy constructor from another TVector of same or other integer type, values are cast.
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
TImageVector(const Vector6 &v6)
Copies the six double components of v6 into x, ..., u, respectively.
TVector< TVector6DBase< CompIntType > > ParentClass
Parent class of this class.
TImageVector(const ComponentType i)
Constructor that initializes all components to i.
TImageVector()
Constructor. All components are initialized to 0.
Vector3 toVector3() const
Returns the x, y, z components as Vector3.
void get(ComponentType *const xp=nullptr, ComponentType *const yp=nullptr, ComponentType *const zp=nullptr, ComponentType *const cp=nullptr, ComponentType *const tp=nullptr, ComponentType *const up=nullptr) const
Returns the subset of those Vector components whose corresponding pointers are not NULL.
void set(const ComponentType vx, const ComponentType vy, const ComponentType vz=0, const ComponentType vc=0, const ComponentType vt=0, const ComponentType vu=0)
Sets vector to (vx, vy, vz, vc, vt, vu). Components not passed are set to 0.
TImageVector(const ParentClass &v)
Copy constructor from the base class.
TImageVector(const ComponentType xp, const TImageVector< ComponentType > &p)
Constructor that assigns X to x and copies other elements from p.
Vector6 toVector6() const
Returns the vector contents as Vector6.
TImageVector(const MLint num, const ComponentType *const arr, const ComponentType deflt)
Constructor that initializes the vector components by copying them from arr[0] ,.....
TVector6DBase is the data container class for TVector providing specialized 6D container functionalit...
ComponentType c
Color component of the vector.
ComponentType t
Time component of the vector.
ComponentType u
Unit/Modality/User component of the vector.
TVector6DBase()
Do not allow a direct creation of this class as object, as this container does not initialize itself;...
ComponentType z
Z component of the vector.
ComponentType x
X component of the vector.
CompIntType ComponentType
Integer type used by this vector.
ComponentType y
Y component of the vector.
ML integer image vector class to be specialized for different purposes.
TVectorBase::ComponentType ComponentType
Integer type used by this vector.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489
@ MLMaxImageDimension