00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MITKVECTOR_H_HEADER_INCLUDED_C1EBD0AD
00020 #define MITKVECTOR_H_HEADER_INCLUDED_C1EBD0AD
00021
00022 #include <itkPoint.h>
00023 #include <float.h>
00024 #include <itkIndex.h>
00025 #include <itkContinuousIndex.h>
00026 #include <itkVector.h>
00027 #include <itkMatrix.h>
00028 #include <itkTransform.h>
00029 #include <vnl/vnl_quaternion.h>
00030 #include "mitkCommon.h"
00031
00032 #ifndef DOXYGEN_SKIP
00033
00034 namespace mitk {
00035 typedef float ScalarType;
00036
00037 typedef itk::Matrix<ScalarType, 3, 3> Matrix3D;
00038 typedef itk::Matrix<ScalarType,4,4> Matrix4D;
00039 typedef vnl_matrix_fixed<ScalarType, 3, 3> VnlMatrix3D;
00040 typedef itk::Transform<ScalarType, 3, 3> Transform3D;
00041 typedef vnl_vector<ScalarType> VnlVector;
00042 typedef vnl_vector_ref<ScalarType> VnlVectorRef;
00043
00044 typedef itk::Point<ScalarType,2> Point2D;
00045 typedef itk::Point<ScalarType,3> Point3D;
00046 typedef itk::Point<ScalarType,4> Point4D;
00047 typedef itk::Point<int,2> Point2I;
00048 typedef itk::Point<int,3> Point3I;
00049 typedef itk::Point<int,4> Point4I;
00050 typedef itk::Vector<ScalarType,2> Vector2D;
00051 typedef itk::Vector<ScalarType,3> Vector3D;
00052 typedef itk::Index<3> Index3D;
00053 typedef itk::ContinuousIndex<ScalarType, 3> ContinuousIndex3D;
00054 typedef vnl_quaternion<ScalarType> Quaternion;
00055
00056
00057
00058 enum PointSpecificationType
00059 {
00060 PTUNDEFINED = 0,
00061 PTSTART,
00062 PTCORNER,
00063 PTEDGE,
00064 PTEND
00065 };
00066
00067 typedef itk::NumericTraits<mitk::ScalarType> ScalarTypeNumericTraits;
00068 MITK_CORE_EXPORT extern const ScalarType eps;
00069 MITK_CORE_EXPORT extern const ScalarType sqrteps;
00070 MITK_CORE_EXPORT extern const double large;
00071
00072 template <class T> class VectorTraits {
00073 public:
00074 typedef T ValueType;
00075 };
00076
00077 template <> class VectorTraits<VnlVector> {
00078 public:
00079 typedef ScalarType ValueType;
00080 };
00081
00082 template<> class VectorTraits<double[4]> {
00083 public:
00084 typedef double ValueType;
00085 };
00086 template<> class VectorTraits< itk::Index<5> > {
00087 public:
00088 typedef itk::Index<5>::IndexValueType ValueType;
00089 };
00090
00091 template<> class VectorTraits< itk::Index<3> > {
00092 public:
00093 typedef itk::Index<3>::IndexValueType ValueType;
00094 };
00095
00096 template<> class VectorTraits< long int [3]> {
00097 public:
00098 typedef long int ValueType;
00099 };
00100 template<> class VectorTraits< float [3]> {
00101 public:
00102 typedef float ValueType;
00103 };
00104 template<> class VectorTraits< double [3]> {
00105 public:
00106 typedef double ValueType;
00107 };
00108
00109 template<> class VectorTraits< vnl_vector_fixed<ScalarType, 3> > {
00110 public:
00111 typedef ScalarType ValueType;
00112 };
00113
00114 template<> class VectorTraits< long unsigned int[3]> {
00115 public:
00116 typedef long unsigned int ValueType;
00117 };
00118
00119 template<> class VectorTraits< unsigned int *> {
00120 public:
00121 typedef unsigned int ValueType;
00122 };
00123
00124 template<> class VectorTraits< ScalarType[4] > {
00125 public:
00126 typedef ScalarType ValueType;
00127 };
00128
00129 template<> class VectorTraits< itk::Vector<float,3> > {
00130 public:
00131 typedef float ValueType;
00132 };
00133
00134 template<> class VectorTraits< itk::Point<float,3> > {
00135 public:
00136 typedef float ValueType;
00137 };
00138
00139 template<> class VectorTraits< itk::Point<float,4> > {
00140 public:
00141 typedef float ValueType;
00142 };
00143
00144 template<> class VectorTraits< itk::Vector<double,3> > {
00145 public:
00146 typedef double ValueType;
00147 };
00148
00149 template<> class VectorTraits< itk::Point<double,3> > {
00150 public:
00151 typedef double ValueType;
00152 };
00153
00154 template<> class VectorTraits< itk::Vector<int,3> > {
00155 public:
00156 typedef int ValueType;
00157 };
00158
00159 template<> class VectorTraits< itk::Point<int,3> > {
00160 public:
00161 typedef int ValueType;
00162 };
00163
00164 template <class Tin, class Tout>
00165 inline void itk2vtk(const Tin& in, Tout& out)
00166 {
00167 out[0]=(typename VectorTraits<Tout>::ValueType)(in[0]);
00168 out[1]=(typename VectorTraits<Tout>::ValueType)(in[1]);
00169 out[2]=(typename VectorTraits<Tout>::ValueType)(in[2]);
00170 }
00171
00172 template <class Tin, class Tout>
00173 inline void vtk2itk(const Tin& in, Tout& out)
00174 {
00175 out[0]=(typename VectorTraits<Tout>::ValueType)(in[0]);
00176 out[1]=(typename VectorTraits<Tout>::ValueType)(in[1]);
00177 out[2]=(typename VectorTraits<Tout>::ValueType)(in[2]);
00178 }
00179 template <class Tout>
00180 inline void FillVector3D(Tout& out, ScalarType x, ScalarType y, ScalarType z)
00181 {
00182 out[0] = (typename VectorTraits<Tout>::ValueType)x;
00183 out[1] = (typename VectorTraits<Tout>::ValueType)y;
00184 out[2] = (typename VectorTraits<Tout>::ValueType)z;
00185 }
00186 template <class Tout>
00187 inline void FillVector4D(Tout& out, ScalarType x, ScalarType y, ScalarType z, ScalarType t)
00188 {
00189 out[0] = (typename VectorTraits<Tout>::ValueType)x;
00190 out[1] = (typename VectorTraits<Tout>::ValueType)y;
00191 out[2] = (typename VectorTraits<Tout>::ValueType)z;
00192 out[3] = (typename VectorTraits<Tout>::ValueType)t;
00193 }
00194
00195
00196 template <class Tin, class Tout>
00197 inline void vnl2vtk(const vnl_vector<Tin>& in, Tout *out)
00198 {
00199 unsigned int i;
00200 for(i=0; i<in.size();++i)
00201 out[i]=(Tout) (in[i]);
00202 }
00203
00204 template <class Tin, class Tout>
00205 inline void vtk2vnl(const Tin *in, vnl_vector<Tout>& out)
00206 {
00207 unsigned int i;
00208 for(i=0; i<out.size();++i)
00209 out[i]=(Tout) (in[i]);
00210 }
00211
00212 template <class Tin, class Tout>
00213 inline void vtk2vnlref(const Tin *in, vnl_vector_ref<Tout>& out)
00214 {
00215 unsigned int i;
00216 for(i=0; i<out.size();++i)
00217 out[i]=(Tout) (in[i]);
00218 }
00219
00220 template <class Tin, class Tout, unsigned int n>
00221 inline void vnl2vtk(const vnl_vector_fixed<Tin, n>& in, Tout *out)
00222 {
00223 unsigned int i;
00224 for(i=0; i<in.size();++i)
00225 out[i]=(Tout) (in[i]);
00226 }
00227
00228 template <class Tin, class Tout, unsigned int n>
00229 inline void vtk2vnl(const Tin *in, vnl_vector_fixed<Tout, n>& out)
00230 {
00231 unsigned int i;
00232 for(i=0; i<out.size();++i)
00233 out[i]=(Tout) (in[i]);
00234 }
00235
00236 template <class T, unsigned int NVectorDimension>
00237 itk::Vector<T, NVectorDimension> operator+(const itk::Vector<T, NVectorDimension> &vector, const itk::Point<T, NVectorDimension> &point)
00238 {
00239 itk::Vector<T, NVectorDimension> sub;
00240 for( unsigned int i=0; i<NVectorDimension; i++)
00241 {
00242 sub[i] = vector[i]+point[i];
00243 }
00244 return sub;
00245 }
00246
00247 template <class T, unsigned int NVectorDimension>
00248 inline itk::Vector<T, NVectorDimension>& operator+=(itk::Vector<T, NVectorDimension> &vector, const itk::Point<T, NVectorDimension> &point)
00249 {
00250 for( unsigned int i=0; i<NVectorDimension; i++)
00251 {
00252 vector[i] += point[i];
00253 }
00254 return vector;
00255 }
00256
00257 template <class T, unsigned int NVectorDimension>
00258 itk::Vector<T, NVectorDimension> operator-(const itk::Vector<T, NVectorDimension> &vector, const itk::Point<T, NVectorDimension> &point)
00259 {
00260 itk::Vector<T, NVectorDimension> sub;
00261 for( unsigned int i=0; i<NVectorDimension; i++)
00262 {
00263 sub[i] = vector[i]-point[i];
00264 }
00265 return sub;
00266 }
00267
00268 template <class T, unsigned int NVectorDimension>
00269 inline itk::Vector<T, NVectorDimension>& operator-=(itk::Vector<T, NVectorDimension> &vector, const itk::Point<T, NVectorDimension> &point)
00270 {
00271 for( unsigned int i=0; i<NVectorDimension; i++)
00272 {
00273 vector[i] -= point[i];
00274 }
00275 return vector;
00276 }
00277
00278 template <typename TCoordRep, unsigned int NPointDimension>
00279 inline bool Equal(const itk::Vector<TCoordRep, NPointDimension>& vector1, const itk::Vector<TCoordRep, NPointDimension>& vector2)
00280 {
00281 typename itk::Vector<TCoordRep, NPointDimension>::VectorType diff = vector1-vector2;
00282 return diff.GetSquaredNorm() < mitk::eps;
00283 }
00284
00285 template <typename TCoordRep, unsigned int NPointDimension>
00286 inline bool Equal(const itk::Point<TCoordRep, NPointDimension>& vector1, const itk::Point<TCoordRep, NPointDimension>& vector2)
00287 {
00288 typename itk::Point<TCoordRep, NPointDimension>::VectorType diff = vector1-vector2;
00289 return diff.GetSquaredNorm() < mitk::eps;
00290 }
00291
00292 inline bool Equal(const mitk::VnlVector& vector1, const mitk::VnlVector& vector2)
00293 {
00294 mitk::VnlVector diff = vector1-vector2;
00295 return diff.squared_magnitude() < mitk::eps;
00296 }
00297
00298 inline bool Equal(double scalar1, double scalar2)
00299 {
00300 return fabs(scalar1-scalar2) < mitk::eps;
00301 }
00302
00303 template <typename TCoordRep, unsigned int NPointDimension>
00304 inline bool Equal(const vnl_vector_fixed<TCoordRep, NPointDimension> & vector1, const vnl_vector_fixed<TCoordRep, NPointDimension>& vector2)
00305 {
00306 vnl_vector_fixed<TCoordRep, NPointDimension> diff = vector1-vector2;
00307 return diff.squared_magnitude() < mitk::eps;
00308 }
00309
00310 template <typename U, typename V, unsigned int NRows, unsigned int NColumns>
00311 inline void TransferMatrix(const itk::Matrix<U, NRows, NColumns>& in, itk::Matrix<V, NRows, NColumns>& out)
00312 {
00313 for (unsigned int i = 0; i < in.RowDimensions; ++i)
00314 for (unsigned int j = 0; j < in.ColumnDimensions; ++j)
00315 out[i][j] = in[i][j];
00316 }
00317
00318
00319 }
00320
00321 #endif //DOXYGEN_SKIP
00322
00323
00324
00325
00326
00327
00328
00329
00330 #include <itkAffineGeometryFrame.h>
00331
00332 namespace mitk
00333 {
00334 typedef itk::AffineGeometryFrame<ScalarType, 3>::TransformType AffineTransform3D;
00335 }
00336
00337
00338 #define mitkSetConstReferenceMacro(name,type) \
00339 virtual void Set##name (const type & _arg) \
00340 { \
00341 itkDebugMacro("setting " << #name " to " << _arg ); \
00342 if (this->m_##name != _arg) \
00343 { \
00344 this->m_##name = _arg; \
00345 this->Modified(); \
00346 } \
00347 }
00348
00349 #define mitkSetVectorMacro(name,type) \
00350 mitkSetConstReferenceMacro(name,type)
00351
00352 #define mitkGetVectorMacro(name,type) \
00353 itkGetConstReferenceMacro(name,type)
00354
00355 #endif