ML Reference
MeVis/Foundation/Sources/MLLinearAlgebra/mlVector4.h
Go to the documentation of this file.
00001 // **InsertLicense** code 
00002 //=====================================================================================
00004 
00009 //=====================================================================================
00010 
00011 #ifndef __mlVector4_H
00012 #define __mlVector4_H
00013 
00014 // Include system independency file and project settings.
00015 #ifndef __mlLinearAlgebraSystem_H
00016 #include "mlLinearAlgebraSystem.h"
00017 #endif
00018 #ifndef __mlLinearAlgebraDefs_H
00019 #include "mlLinearAlgebraDefs.h"
00020 #endif
00021 #ifndef __mlFloatingPointVector_H
00022 #include "mlFloatingPointVector.h"
00023 #endif
00024 #ifndef __mlVector2_H
00025 #include "mlVector2.h"
00026 #endif
00027 #ifndef __mlVector3_H
00028 #include "mlVector3.h"
00029 #endif
00030 #ifndef __mlMatrix3_H
00031 #include "mlMatrix3.h"
00032 #endif
00033 #ifndef __mlMatrix4_H
00034 #include "mlMatrix4.h"
00035 #endif
00036 
00037 // All declarations of this header will be in the ML_LA_NAMESPACE namespace.
00038 ML_LA_START_NAMESPACE
00039 
00040 //--------------------------------------------------------------------
00042 // This is necessary because we do not known whether vector or 
00043 // matrix header is included first and we cannot move template
00044 // code into C++ file.
00045 //--------------------------------------------------------------------
00046 template <class DT> class Tvec2;
00047 template <class DT> class Tvec3;
00048 template <class DT> class Tmat3;
00049 template <class DT> class Tmat4;
00051 
00052 //--------------------------------------------------------------------
00054 //--------------------------------------------------------------------
00055 template <class DT>
00056 class Tvec4 : public FloatingPointVector<DT,4> {
00057 public:
00058   
00060   typedef FloatingPointVector<DT,4> Superclass;
00061 
00063   typedef DT ComponentType;
00064   
00065   //--------------------------------------------------------------------
00067 
00068   //--------------------------------------------------------------------
00070   inline explicit Tvec4(const DT value=0) : Superclass(value)
00071   {
00072     ML_TRACE_IN_TIME_CRITICAL("Tvec4::Tvec4(const DT value=0)");
00073   }
00074   
00078   inline Tvec4(const Superclass &v): Superclass(v)
00079   {
00080     ML_TRACE_IN_TIME_CRITICAL("Tvec4::Tvec4(const FloatingPointVector<DT,4>& v)");
00081   }
00082   
00085   inline Tvec4(const DT x, const DT y, const DT z, const DT w)
00086   {
00087     ML_TRACE_IN_TIME_CRITICAL("Tvec4::Tvec4(const DT x, const DT y, const DT z, const DT w)");
00088     
00089     Superclass::_buffer[0] = x;  
00090     Superclass::_buffer[1] = y;  
00091     Superclass::_buffer[2] = z;  
00092     Superclass::_buffer[3] = w;
00093   }
00094   
00096   inline Tvec4(const Tvec2<DT>& v, const DT z, const DT w)
00097   {
00098     ML_TRACE_IN_TIME_CRITICAL("Tvec4::Tvec4(const Tvec2<DT>& v, const DT z, const DT w)");
00099     
00100     Superclass::_buffer[0] = v[0];  
00101     Superclass::_buffer[1] = v[1];  
00102     Superclass::_buffer[2] = z;  
00103     Superclass::_buffer[3] = w;
00104   }
00105   
00107   inline Tvec4(const Tvec3<DT>& v, const DT w)
00108   {
00109     ML_TRACE_IN_TIME_CRITICAL("Tvec4::Tvec4(const Tvec3<DT>& v, const DT w)");
00110     
00111     Superclass::_buffer[0] = v[0];  
00112     Superclass::_buffer[1] = v[1];
00113     Superclass::_buffer[2] = v[2];  
00114     Superclass::_buffer[3] = w;
00115   }
00116   
00118   inline void assign(const DT x, const DT y, const DT z, const DT c)
00119   {
00120     ML_TRACE_IN_TIME_CRITICAL("Tvec4::assign(const DT x, const DT y, const DT z, const DT c)");
00121     
00122     Superclass::_buffer[0] = x;
00123     Superclass::_buffer[1] = y;
00124     Superclass::_buffer[2] = z;
00125     Superclass::_buffer[3] = c;
00126   }
00127   
00132   inline Tvec4<DT> divideByLastComp() const
00133   {
00134     ML_TRACE_IN( "divideByLastComp() const( )" );
00135     
00136     Tvec4<DT> retVal;
00137     ML_TRY
00138     {
00139       const DT lastComp = Superclass::_buffer[3];
00140       
00141       ML_CHECK_FLOAT_THROW(lastComp);
00142       const DT div = static_cast<DT>(1) / lastComp;
00143       retVal = Tvec4<DT>(Superclass::_buffer[0] * div, 
00144                          Superclass::_buffer[1] * div, 
00145                          Superclass::_buffer[2] * div, 1);
00146     }
00147     ML_CATCH_RETHROW;
00148     return retVal;
00149   }
00151 };
00152 
00154 #define _ML_VEC4_RC(i) a[i][0]*v[0] + a[i][1]*v[1] + a[i][2]*v[2] + a[i][3]*v[3]
00155 //-----------------------------------------------------------------------------------
00157 //-----------------------------------------------------------------------------------
00158 template <class DT>
00159 inline Tvec4<DT> operator*(const Tmat4<DT>& a, const Tvec4<DT>& v)
00160 {
00161   ML_TRACE_IN_TIME_CRITICAL("mlVector4.h: operator*(const Tmat4<DT>& a, const Tvec4<DT>& v)");
00162   
00163   return Tvec4<DT>(_ML_VEC4_RC(0), _ML_VEC4_RC(1), _ML_VEC4_RC(2), _ML_VEC4_RC(3));
00164 }
00165 #undef _ML_VEC4_RC
00166 
00167 //-----------------------------------------------------------------------------------
00169 //-----------------------------------------------------------------------------------
00170 template <class DT>
00171 inline Tvec4<DT> operator*(const Tvec4<DT>& v, const Tmat4<DT>& a)
00172 {
00173   ML_TRACE_IN_TIME_CRITICAL("mlVector4.h: operator*(const Tvec4<DT>& v, const Tmat4<DT>& a)");
00174   
00175   return a.transpose() * v;
00176 }
00177 
00178 
00179 //-----------------------------------------------------------------------------------
00181 
00182 //-----------------------------------------------------------------------------------
00184 typedef Tvec4<MLfloat>   Vector4f;
00186 typedef Tvec4<MLdouble>  Vector4d;
00188 typedef Tvec4<MLldouble> Vector4ld;
00190 typedef Tvec4<MLdouble>  Vector4;
00192 
00193 
00194 #ifdef ML_DEPRECATED
00195 
00196 
00197 
00198 
00199 ML_DEPRECATED typedef Tvec4<MLfloat>   vecf4;
00202 ML_DEPRECATED typedef Tvec4<MLdouble>  vecd4;
00205 ML_DEPRECATED typedef Tvec4<MLldouble> vecld4;
00208 ML_DEPRECATED typedef Tvec4<MLdouble> vec4;
00210 
00211 #endif // ML_DEPRECATED
00212 
00213 
00214 ML_LA_END_NAMESPACE
00215 
00216 #endif //of __mlVector4_H
00217 
00218 
00219