ML Reference
MeVis/Foundation/Sources/MLLinearAlgebra/mlVector2.h
Go to the documentation of this file.
00001 // **InsertLicense** code 
00002 //=====================================================================================
00004 
00009 //=====================================================================================
00010 #ifndef __mlVector2_H
00011 #define __mlVector2_H
00012 
00013 // Include system independency file and project settings.
00014 #ifndef __mlLinearAlgebraSystem_H
00015 #include "mlLinearAlgebraSystem.h"
00016 #endif
00017 #ifndef __mlLinearAlgebraDefs_H
00018 #include "mlLinearAlgebraDefs.h"
00019 #endif
00020 #ifndef __mlFloatingPointVector_H
00021 #include "mlFloatingPointVector.h"
00022 #endif
00023 
00024 // All declarations of this header will be in the ML_LA_NAMESPACE namespace.
00025 ML_LA_START_NAMESPACE
00026 
00028 template <class DT>
00029 class Vector2DataContainer
00030 {
00031 public:
00032   union {
00033     struct {
00035       DT x; 
00037       DT y;
00038     };
00040     DT _buffer[2];
00041   };
00042 };
00043 
00044 //--------------------------------------------------------------------
00046 // This is necessary because we do not known whether vector or 
00047 // matrix header is included first and we cannot move template
00048 // code into C++ file.
00049 //--------------------------------------------------------------------
00050 template <class DT> class Tvec3;
00052 
00053 //--------------------------------------------------------------------
00055 //--------------------------------------------------------------------
00056 template <class DT>
00057 class Tvec2 : public FloatingPointVector<DT, 2, Vector2DataContainer<DT> > {
00058 public:
00059   
00061   typedef FloatingPointVector<DT, 2, Vector2DataContainer<DT> > Superclass;
00062 
00064   typedef DT ComponentType;
00065   
00066   //--------------------------------------------------------------------
00068 
00069   //--------------------------------------------------------------------
00072   inline explicit Tvec2(const DT value=0) : Superclass(value)
00073   {
00074     ML_TRACE_IN_TIME_CRITICAL("Tvec2::Tvec2(DT value=0)");
00075   }
00076   
00080   inline Tvec2(const Superclass &v): Superclass(v)
00081   {
00082     ML_TRACE_IN_TIME_CRITICAL("Tvec2::Tvec2(const FloatingPointVector<DT, 2, Vector2DataContainer<DT> >& v)");
00083   }
00084   
00086   inline Tvec2(const DT px, const DT py) : Superclass()
00087   {
00088     ML_TRACE_IN_TIME_CRITICAL("Tvec2::Tvec2(DT px, DT py)");
00089     
00090     assign(px,py);
00091   }
00092   
00094   inline void assign(const DT px, const DT py)
00095   {
00096     ML_TRACE_IN_TIME_CRITICAL("Tvec2::assign(const DT x, const DT y)");
00097     
00098     Superclass::_buffer[0] = px;
00099     Superclass::_buffer[1] = py;
00100   }
00101   
00106   inline Tvec2(const Tvec3<DT>& v, const bool normalize) : Superclass()
00107   {
00108     ML_TRACE_IN("Tvec2::Tvec2(const Tvec2<DT>& v, const bool normalize)");
00109     ML_TRY
00110     {
00111       if (normalize){
00112         // Homogeneous cast.
00113         ML_CHECK_FLOAT_THROW(v[2]);
00114         Superclass::_buffer[0] = v[0]/v[2];
00115         Superclass::_buffer[1] = v[1]/v[2];
00116       }
00117       else{
00118         // Normal cast.
00119         Superclass::_buffer[0] = v[0];
00120         Superclass::_buffer[1] = v[1];
00121       }
00122     }
00123     ML_CATCH_RETHROW;
00124   }
00125   
00129   inline Tvec2(const Tvec3<DT>& v, const int axis) : Superclass()
00130   {
00131     ML_TRACE_IN_TIME_CRITICAL("Tvec2::Tvec2(const Tvec3<DT>& v, const int axis)");
00132     
00133     switch (axis) {
00134       case 0:  Superclass::_buffer[0] = v[1];
00135                Superclass::_buffer[1] = v[2]; break;
00136       case 1:  Superclass::_buffer[0] = v[0];
00137                Superclass::_buffer[1] = v[2]; break;
00138       default: Superclass::_buffer[0] = v[0];
00139                Superclass::_buffer[1] = v[1]; break;
00140     }
00141   }
00143   
00146   inline Tvec3<DT> affineVec() const
00147   {
00148     ML_TRACE_IN_TIME_CRITICAL("Tvec2::affineVec() const");
00149     
00150     return Tvec3<DT>(*this, 0);
00151   }
00152   
00155   inline Tvec3<DT> affinePoint() const
00156   {
00157     ML_TRACE_IN_TIME_CRITICAL("Tvec2::affinePoint() const");
00158     
00159     return Tvec3<DT>(*this, 1);
00160   }
00161   
00162 }; // end of class *Tvec2<DT>*
00163 
00164 
00165 //-----------------------------------------------------------------------------------
00167 
00168 //-----------------------------------------------------------------------------------
00170 typedef Tvec2<MLfloat>   Vector2f;
00172 typedef Tvec2<MLdouble>  Vector2d;
00174 typedef Tvec2<MLldouble> Vector2ld;
00176 typedef Tvec2<MLdouble>  Vector2;
00178 
00179 
00180 #ifdef ML_DEPRECATED
00181 
00182 
00183 
00184 
00185 ML_DEPRECATED typedef Tvec2<MLfloat>   vecf2;
00188 ML_DEPRECATED typedef Tvec2<MLdouble>  vecd2;
00191 ML_DEPRECATED typedef Tvec2<MLldouble> vecld2;
00194 ML_DEPRECATED typedef Tvec2<MLdouble> vec2;
00196 
00197 #endif // ML_DEPRECATED
00198 
00199 
00200 ML_LA_END_NAMESPACE
00201 
00202 #endif //of __mlVector2_H
00203 
00204 
00205 
00206