ML Reference
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
24ML_START_NAMESPACE
25
26 //-------------------------------------------------------------------------
28 //-------------------------------------------------------------------------
29 enum { MLMaxImageDimension = 6 };
30
31 //-------------------------------------------------------------------------
37 //-------------------------------------------------------------------------
38 template <typename CompIntType>
40 {
41 public:
42
44 typedef CompIntType ComponentType;
45
47 enum { NumberOfDimensions = MLMaxImageDimension };
48
49 // We use a union to make the vector members accessible
50 // either with .x, ... .z or with .array[0..MLMaxImageDimension-1].
51 // Below we also provide indexing operators [] on the array.
52 union {
53 //------------------------------------------------------
56 //------------------------------------------------------
57 struct {
70 };
72
75 ComponentType array[NumberOfDimensions];
76 };
77
78 protected:
79
84
85 };
86
87
88 //-------------------------------------------------------------------------
93
133 //-------------------------------------------------------------------------
134 template <typename CompIntType=MLint>
135 class TImageVector : public TVector<TVector6DBase<CompIntType> > {
136 public:
137
140
143
144 //------------------------------------------------------
147 //------------------------------------------------------
149 inline static MLint dim(){ return MLMaxImageDimension; }
151
152 // Propagates constructors and sets shadowed methods from base class.
154 inline TImageVector() : ParentClass(){ }
155
158 inline TImageVector(const ParentClass& v) : ParentClass(v){ }
159
161 inline explicit TImageVector(const ComponentType i) : ParentClass(i){ }
162
165 template <typename T2IntType>
166 inline explicit TImageVector(const TImageVector<T2IntType> &v2) : ParentClass(v2){}
167
170
172 inline void set(const ComponentType v=0){ ParentClass::set(v); }
173
175 inline void set(const ParentClass &v){ ParentClass::set(v); }
176
180 inline TImageVector(const MLint num, const ComponentType* const arr, const ComponentType deflt) : ParentClass(num, arr, deflt){}
181
182
183 // Adds specialized constructors and functionality.
185 inline TImageVector(const ComponentType xp, const ComponentType yp, const ComponentType zp,
186 const ComponentType cp, const ComponentType tp, const ComponentType up)
187 {
188 ParentClass::x = xp;
189 ParentClass::y = yp;
190 ParentClass::z = zp;
191 ParentClass::c = cp;
192 ParentClass::t = tp;
193 ParentClass::u = up;
194 }
195
198 inline explicit TImageVector(const Vector6 &v6)
199 {
200 ParentClass::x = static_cast<ComponentType>(v6[0]);
201 ParentClass::y = static_cast<ComponentType>(v6[1]);
202 ParentClass::z = static_cast<ComponentType>(v6[2]);
203 ParentClass::c = static_cast<ComponentType>(v6[3]);
204 ParentClass::t = static_cast<ComponentType>(v6[4]);
205 ParentClass::u = static_cast<ComponentType>(v6[5]);
206 }
207
209 inline void set(const ComponentType vx , const ComponentType vy , const ComponentType vz=0,
210 const ComponentType vc=0, const ComponentType vt=0, const ComponentType vu=0)
211 {
212 ParentClass::x = vx;
213 ParentClass::y = vy;
214 ParentClass::z = vz;
215 ParentClass::c = vc;
216 ParentClass::t = vt;
217 ParentClass::u = vu;
218 }
219
221 inline void get(ComponentType * const xp= nullptr, ComponentType * const yp= nullptr, ComponentType * const zp= nullptr,
222 ComponentType * const cp= nullptr, ComponentType * const tp= nullptr, ComponentType * const up= nullptr) const
223 {
224 if (xp){ *xp = ParentClass::x; }
225 if (yp){ *yp = ParentClass::y; }
226 if (zp){ *zp = ParentClass::z; }
227 if (cp){ *cp = ParentClass::c; }
228 if (tp){ *tp = ParentClass::t; }
229 if (up){ *up = ParentClass::u; }
230 }
231
239 inline bool iterate(const TImageVector<ComponentType> &ext)
240 {
241 ParentClass::x++;
242 if (ParentClass::x >= ext.x){
243 ParentClass::x = 0; ParentClass::y++;
244 if (ParentClass::y >= ext.y){
245 ParentClass::y = 0; ParentClass::z++;
246 if (ParentClass::z >= ext.z){
247 ParentClass::z = 0; ParentClass::c++;
248 if (ParentClass::c >= ext.c){
249 ParentClass::c = 0; ParentClass::t++;
250 if (ParentClass::t >= ext.t){
251 ParentClass::t = 0; ParentClass::u++;
252 if (ParentClass::u >= ext.u){
253 ParentClass::u = 0; return true;
254 }
255 }
256 }
257 }
258 }
259 }
260 return false;
261 }
262
264 inline Vector6 toVector6() const
265 {
266 return Vector6(static_cast<double>(ParentClass::x),
267 static_cast<double>(ParentClass::y),
268 static_cast<double>(ParentClass::z),
269 static_cast<double>(ParentClass::c),
270 static_cast<double>(ParentClass::t),
271 static_cast<double>(ParentClass::u));
272 }
273
275 inline Vector3 toVector3() const
276 {
277 return Vector3(static_cast<double>(ParentClass::x),
278 static_cast<double>(ParentClass::y),
279 static_cast<double>(ParentClass::z));
280 }
281
282 };
283
286
287ML_END_NAMESPACE
288
289#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 which 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 which 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). Not passed components are set to 0.
TImageVector(const ParentClass &v)
Copy constructor from Base class.
TImageVector(const ComponentType xp, const TImageVector< ComponentType > &p)
Constructor which 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 which 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, because this container does not initialize it...
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.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:490
@ MLMaxImageDimension