ML Reference
MeVis/Foundation/Sources/MLLinearAlgebra/mlImageVector.h
Go to the documentation of this file.
00001 // **InsertLicense** code 
00002 //-------------------------------------------------------------------------
00006 
00011 //-------------------------------------------------------------------------
00012 #ifndef __mlImageVector_H
00013 #define __mlImageVector_H
00014 
00015 // ML-includes
00016 #ifndef __mlIntegerVector_H
00017 #include "mlIntegerVector.h"
00018 #endif
00019 
00020 
00021 ML_START_NAMESPACE
00022 
00023   //-------------------------------------------------------------------------
00025   //-------------------------------------------------------------------------
00026   enum { MLMaxImageDimension = 6 };
00027 
00028   //-------------------------------------------------------------------------
00034   //-------------------------------------------------------------------------
00035   template <typename CompIntType> 
00036   class TVector6DBase 
00037   {
00038     public:
00039 
00041     typedef CompIntType ComponentType;
00042 
00044     enum { NumberOfDimensions = MLMaxImageDimension };
00045 
00046     // We use a union to make the vector members accessible
00047     // either with .x, ... .z or with .array[0..MLMaxImageDimension-1].
00048     // Below we also provide indexing operators [] on the array.
00049     union {
00050       //------------------------------------------------------
00052 
00053       //------------------------------------------------------
00054       struct {
00056         ComponentType x;
00058         ComponentType y;
00060         ComponentType z;
00062         ComponentType c;
00064         ComponentType t;
00066         ComponentType u;
00067       };
00069       
00072       ComponentType array[NumberOfDimensions];
00073     };
00074 
00075     protected:
00076     
00080     TVector6DBase(){};
00081 
00082   };
00083 
00084 
00085   //-------------------------------------------------------------------------
00090 
00130   //-------------------------------------------------------------------------
00131   template <typename CompIntType=MLint> 
00132   class TImageVector : public TVector<TVector6DBase<CompIntType> > {
00133     public:
00134 
00136     typedef TVector<TVector6DBase<CompIntType> > ParentClass;
00137 
00139     typedef typename ParentClass::ComponentType  ComponentType;
00140 
00141     //------------------------------------------------------
00143 
00144     //------------------------------------------------------
00146     inline static MLint dim(){ return MLMaxImageDimension; }
00148 
00149     // Propagate constructors and set shadowed methods from base class.
00151     inline TImageVector() : ParentClass(){ }
00152   
00155     inline TImageVector(const ParentClass& v) : ParentClass(v){ }
00156   
00158     inline explicit TImageVector(const ComponentType i) : ParentClass(i){ }
00159   
00162     template <typename T2IntType>
00163     inline explicit TImageVector(const TImageVector<T2IntType> &v2) : ParentClass(v2){}
00164     
00166     inline TImageVector(const ComponentType xp, const TImageVector<ComponentType> &p) : ParentClass(xp, p){ }
00167 
00169     inline void set(const ComponentType v=0){ ParentClass::set(v); }
00170 
00172     inline void set(const ParentClass &v){ ParentClass::set(v); }
00173 
00177     inline TImageVector(const MLint num, const ComponentType* const arr, const ComponentType deflt) : ParentClass(num, arr, deflt){}
00178     
00179 
00180     // Add specialized constructors and functionality.
00182     inline TImageVector(const ComponentType xp, const ComponentType yp, const ComponentType zp, 
00183                         const ComponentType cp, const ComponentType tp, const ComponentType up)
00184     {
00185       ML_TRACE_IN_TIME_CRITICAL( "TImageVector(6 args)" );
00186       ParentClass::x = xp; 
00187       ParentClass::y = yp; 
00188       ParentClass::z = zp;
00189       ParentClass::c = cp; 
00190       ParentClass::t = tp; 
00191       ParentClass::u = up; 
00192     }
00193 
00196     inline explicit TImageVector(const Vector6 &v6)
00197     {
00198       ML_TRACE_IN_TIME_CRITICAL( "TImageVector(const Vector6 &v6)" );
00199       ParentClass::x = static_cast<ComponentType>(v6[0]); 
00200       ParentClass::y = static_cast<ComponentType>(v6[1]); 
00201       ParentClass::z = static_cast<ComponentType>(v6[2]);
00202       ParentClass::c = static_cast<ComponentType>(v6[3]); 
00203       ParentClass::t = static_cast<ComponentType>(v6[4]); 
00204       ParentClass::u = static_cast<ComponentType>(v6[5]); 
00205     }
00206 
00208     inline void set(const ComponentType vx  , const ComponentType vy  , const ComponentType vz=0, 
00209                     const ComponentType vc=0, const ComponentType vt=0, const ComponentType vu=0) 
00210     { 
00211       ML_TRACE_IN_TIME_CRITICAL( "TImageVector::set(6 args)" );
00212       ParentClass::x = vx; 
00213       ParentClass::y = vy; 
00214       ParentClass::z = vz; 
00215       ParentClass::c = vc; 
00216       ParentClass::t = vt; 
00217       ParentClass::u = vu;
00218     }
00219 
00221     inline void get(ComponentType * const xp=NULL, ComponentType * const yp=NULL, ComponentType * const zp=NULL, 
00222                     ComponentType * const cp=NULL, ComponentType * const tp=NULL, ComponentType * const up=NULL) const
00223     {
00224       ML_TRACE_IN_TIME_CRITICAL("TImageVector::get(...)");
00225       ML_TRY
00226       {
00227         if (xp){ *xp = ParentClass::x; }
00228         if (yp){ *yp = ParentClass::y; }
00229         if (zp){ *zp = ParentClass::z; }
00230         if (cp){ *cp = ParentClass::c; } 
00231         if (tp){ *tp = ParentClass::t; }
00232         if (up){ *up = ParentClass::u; }
00233       }
00234       ML_CATCH_RETHROW;
00235     }
00236 
00244     inline bool iterate(const TImageVector<ComponentType> &ext)
00245     {
00246       ML_TRACE_IN_TIME_CRITICAL("TImageVector::iterate(const TImageVector<ComponentType> &ext)");
00247       ParentClass::x++;
00248       if (ParentClass::x >= ext.x){
00249         ParentClass::x = 0; ParentClass::y++; 
00250         if (ParentClass::y >= ext.y){
00251           ParentClass::y = 0; ParentClass::z++; 
00252           if (ParentClass::z >= ext.z){
00253             ParentClass::z = 0; ParentClass::c++; 
00254             if (ParentClass::c >= ext.c){
00255               ParentClass::c = 0; ParentClass::t++; 
00256               if (ParentClass::t >= ext.t){
00257                 ParentClass::t = 0; ParentClass::u++; 
00258                 if (ParentClass::u >= ext.u){ 
00259                   ParentClass::u = 0; return true; 
00260                 }
00261               }
00262             }
00263           }
00264         }
00265       }
00266       return false;
00267     }
00268   
00270     inline Vector6 toVector6() const 
00271     { 
00272       ML_TRACE_IN_TIME_CRITICAL("TImageVector::toVector6()");
00273       return Vector6(ParentClass::x,
00274                      ParentClass::y,
00275                      ParentClass::z,
00276                      ParentClass::c,
00277                      ParentClass::t,
00278                      ParentClass::u);
00279     }
00280 
00281 #ifdef ML_DEPRECATED
00282 
00284 
00285 
00286 
00287   inline ML_DEPRECATED Vector6 getVec6() const
00288   { 
00289     ML_TRACE_IN_TIME_CRITICAL("TImageVector::getVec6()");
00290     return toVector6(); 
00291   }
00293 
00294 #endif // ML_DEPRECATED
00295 
00296 
00297   };
00298 
00300   ML_LINEAR_ALGEBRA_EXPORT typedef TImageVector<MLint> ImageVector;
00301 
00302 
00303 #ifdef ML_DEPRECATED
00304 
00306 
00307 
00308 
00309   ML_LINEAR_ALGEBRA_EXPORT ML_DEPRECATED typedef ImageVector Vector;
00311 
00312 #endif // ML_DEPRECATED
00313 
00314 ML_END_NAMESPACE
00315 
00316 #endif //of __mlImageVector_H
00317