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.3.0 (2012-03-29) 00011 */ 00012 00018 #ifndef FIT_3D_HPP_3453465476 00019 #define FIT_3D_HPP_3453465476 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 Fit3D : 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::ArrayXT ArrayXT; 00066 typedef typename super::MatrixXT MatrixXT; 00067 typedef typename super::VectorXT VectorXT; 00068 typedef typename super::Vector2T Vector2T; 00069 typedef typename super::Vector3T Vector3T; 00070 typedef typename super::Vector4T Vector4T; 00071 typedef typename super::Matrix2T Matrix2T; 00072 typedef typename super::Matrix3T Matrix3T; 00073 00074 using super::DATA_POINTS_TOO_SIMILAR; 00075 using super::INFINITY_NOT_AVAILABLE; 00076 using super::NAN_NOT_AVAILABLE; 00077 using super::NOT_ENOUGH_POINTS; 00078 using super::UNKNOWN_ERROR; 00079 using super::WRONG_POINT_SIZE; 00080 00081 Fit3D(); 00082 virtual ~Fit3D(); 00083 00084 void compute() = 0; 00085 00086 T getDistanceTo(const Coordinate<T> & point) const = 0; 00087 T getRMS() const = 0; 00088 unsigned getNumberPointsRequired() const = 0; 00089 00090 void setPoints(const std::vector<Coordinate<T> > &); 00091 void setPoints(const std::vector<Vector3T> &); 00092 void setPoints(const std::vector<Vector4T, Eigen::aligned_allocator<Vector4T> > &); 00093 00094 protected: 00095 MatrixXT m_points; 00096 }; 00097 00098 00104 template <class T> 00105 Fit3D<T>::Fit3D() 00106 { 00107 } 00108 00109 00115 template <class T> 00116 Fit3D<T>::~Fit3D() 00117 { 00118 } 00119 00120 00134 template <class T> 00135 void Fit3D<T>::setPoints(const std::vector<Coordinate<T> > & points) 00136 { 00137 const int m = 3; 00138 const int n = points.size(); 00139 00140 m_points.resize(m, n); 00141 00142 for (int i = 0; i < n; ++i) 00143 { 00144 00145 if (!(points[i].size() == 3 || points[i].size() == 4)) 00146 { 00147 ErrorObj error; 00148 error.setClassName("Fit3D<T>"); 00149 error.setFunctionName("setPoints"); 00150 error.setErrorMessage("One or more source points are of wrong size."); 00151 error.setErrorCode(WRONG_POINT_SIZE); 00152 throw error; 00153 } 00154 00155 m_points.col(i) = points[i].toArray().head(3); 00156 } 00157 } 00158 00159 00167 template <class T> 00168 void Fit3D<T>::setPoints(const std::vector<Vector3T> & points) 00169 { 00170 const int m = 3; 00171 const int n = points.size(); 00172 00173 // we use the fact that std::vector is contiguous; use a C cast instead of an 00174 // C++ cast (reinterpret_cast + const_cast) to make the line easier to read 00175 m_points = Eigen::Map<MatrixXT>((T *)(&points[0]), m, n); 00176 } 00177 00178 00186 template <class T> 00187 void Fit3D<T>::setPoints(const std::vector<Vector4T, Eigen::aligned_allocator<Vector4T> > & points) 00188 { 00189 const int m = 3; 00190 const int n = points.size(); 00191 00192 m_points.resize(m, n); 00193 00194 for (int i = 0; i < n; ++i) 00195 { 00196 m_points.col(i) = points[i].head(3); 00197 } 00198 } 00199 00200 00201 } // namespace TRTK 00202 00203 00204 # endif // FIT_3D_HPP_3453465476
Documentation generated by Doxygen