00001 /* 00002 Copyright (C) 2010 - 2014 Fabian Killus, Christoph Haenisch 00003 00004 Chair of Medical Engineering (mediTEC) 00005 RWTH Aachen University 00006 Pauwelsstr. 20 00007 52074 Aachen 00008 Germany 00009 00010 Version 0.2.0 (2012-03-29) 00011 */ 00012 00018 #ifndef FIT_2D_HPP_9582945877 00019 #define FIT_2D_HPP_9582945877 00020 00021 00022 #include <cmath> 00023 #include <vector> 00024 00025 #include <Eigen/Core> 00026 #include <Eigen/StdVector> 00027 00028 #include "Coordinate.hpp" 00029 #include "ErrorObj.hpp" 00030 #include "Transform3D.hpp" 00031 #include "Fit.hpp" 00032 00033 namespace TRTK 00034 { 00035 00036 00052 template <class T> 00053 class Fit2D : public Fit<T> 00054 { 00055 private: 00056 00057 typedef Fit<T> super; 00058 00059 public: 00060 00061 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00062 00063 typedef T value_type; 00064 00065 typedef typename super::MatrixXT MatrixXT; 00066 typedef typename super::Matrix2T Matrix2T; 00067 typedef typename super::VectorXT VectorXT; 00068 typedef typename super::Vector2T Vector2T; 00069 typedef typename super::Vector3T Vector3T; 00070 00071 using super::DATA_POINTS_TOO_SIMILAR; 00072 using super::INFINITY_NOT_AVAILABLE; 00073 using super::NAN_NOT_AVAILABLE; 00074 using super::NOT_ENOUGH_POINTS; 00075 using super::UNKNOWN_ERROR; 00076 using super::WRONG_POINT_SIZE; 00077 00078 Fit2D(); 00079 virtual ~Fit2D(); 00080 00081 void compute() = 0; 00082 00083 T getDistanceTo(const Coordinate<T> & point) const = 0; 00084 T getRMS() const = 0; 00085 unsigned getNumberPointsRequired() const = 0; 00086 00087 void setPoints(const std::vector<Coordinate<T> > &); 00088 void setPoints(const std::vector<Vector2T, Eigen::aligned_allocator<Vector2T> > &); 00089 void setPoints(const std::vector<Vector3T> &); 00090 00091 protected: 00092 MatrixXT m_points; 00093 }; 00094 00095 00101 template <class T> 00102 Fit2D<T>::Fit2D() 00103 { 00104 } 00105 00106 00112 template <class T> 00113 Fit2D<T>::~Fit2D() 00114 { 00115 } 00116 00117 00131 template <class T> 00132 void Fit2D<T>::setPoints(const std::vector<Coordinate<T> > & points) 00133 { 00134 const int m = 2; 00135 const int n = points.size(); 00136 00137 m_points.resize(m, n); 00138 00139 for (int i = 0; i < n; ++i) 00140 { 00141 00142 if (!(points[i].size() == 2 || points[i].size() == 3)) 00143 { 00144 ErrorObj error; 00145 error.setClassName("Fit3D<T>"); 00146 error.setFunctionName("setPoints"); 00147 error.setErrorMessage("One or more source points are of wrong size."); 00148 error.setErrorCode(WRONG_POINT_SIZE); 00149 throw error; 00150 } 00151 00152 m_points.col(i) = points[i].toArray().head(2); 00153 } 00154 } 00155 00156 00164 template <class T> 00165 void Fit2D<T>::setPoints(const std::vector<Vector2T, Eigen::aligned_allocator<Vector2T> > & points) 00166 { 00167 const int m = 2; 00168 const int n = points.size(); 00169 00170 // we use the fact that std::vector is contiguous; use a C cast instead of an 00171 // C++ cast (reinterpret_cast + const_cast) to make the line easier to read 00172 m_points = Eigen::Map<MatrixXT>((T *)(&points[0]), m, n); 00173 } 00174 00175 00183 template <class T> 00184 void Fit2D<T>::setPoints(const std::vector<Vector3T> & points) 00185 { 00186 const int m = 2; 00187 const int n = points.size(); 00188 00189 m_points.resize(m, n); 00190 00191 for (int i = 0; i < n; ++i) 00192 { 00193 m_points.col(i) = points[i].head(2); 00194 } 00195 } 00196 00197 00198 } // namespace TRTK 00199 00200 00201 # endif // FIT_2D_HPP_9582945877
Documentation generated by Doxygen