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
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
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 the 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
static MLint dim()
Returns the dimension the ML calculates with.
bool iterate(const TImageVector< ComponentType > &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
TImageVector(const TImageVector< T2IntType > &v2)
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
TImageVector(const Vector6 &v6)
TVector< TVector6DBase< intT > > ParentClass
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)
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)
ComponentType c
Color component of the vector.
ComponentType t
Time component of the vector.
ComponentType array[NumberOfDimensions]
ComponentType u
Unit/Modality/User component of the vector.
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.
void set(const ComponentType v=0)
Sets all components to v or - if v is not specified - to 0.
TVectorBase::ComponentType ComponentType
Integer type used by this vector.
MLint64 MLint
Definition mlTypeDefs.h:489
Tvec3< MLdouble > Vector3
A vector with three components of type double.
Definition mlVector3.h:286
Tvec6< MLdouble > Vector6
A vector with six components of type double.
Definition mlVector6.h:194
@ MLMaxImageDimension
TImageVector< MLint > ImageVector
Defines the standard ImageVector type that is used by the ML for indexing and coordinates.