2 #ifndef vgl_line_2d_regression_hxx_ 3 #define vgl_line_2d_regression_hxx_ 11 # include <vcl_msvc_warnings.h> 14 #include <vnl/vnl_matrix_fixed.h> 15 #include <vnl/algo/vnl_symmetric_eigensystem.h> 70 vnl_matrix_fixed<T, 2, 2> M;
71 M(0, 0) = Sxx_-Sx_*Sx_/npts_;
72 M(0, 1) = M(1, 0) = Sxy_-Sx_*Sy_/npts_;
73 M(1, 1) = Syy_-Sy_*Sy_/npts_;
75 vnl_symmetric_eigensystem<T> sym(M.as_ref());
78 T c = -(a*Sx_/npts_ + b*Sy_/npts_);
89 std::cout <<
"In vgl_line_2d_regression<T>::fit_constrained() - less than 1 point\n";
92 vnl_matrix_fixed<T, 2, 2> M;
93 M(0, 0) = Sxx_-2*Sx_*x +npts_*x*x;
94 M(0, 1) = M(1, 0) = Sxy_-Sx_*y-x*Sy_+npts_*x*y;
95 M(1, 1) = Syy_-2*Sy_*y+npts_*y*y;
96 vnl_symmetric_eigensystem<T> sym(M.as_ref());
109 double t0 = Sxx_*a*a + 2*Sxy_*a*b + Syy_*b*b;
110 double t1 = 2*Sx_*a*c + 2*Sy_*b*c + npts_*c*c;
111 double rms = std::sqrt(std::fabs(t0+t1)/((a*a+b*b)*npts_));
118 return this->get_rms_error(line_.a(), line_.b(), line_.c());
136 squared_error_ = this->get_rms_error();
137 squared_error_ *=squared_error_;
138 squared_error_ *= npts_;
153 squared_error_ = squared_error_ + ds;
154 return std::sqrt(squared_error_/(npts_+1));
158 #undef VGL_LINE_2D_REGRESSION_INSTANTIATE 159 #define VGL_LINE_2D_REGRESSION_INSTANTIATE(T) \ 160 template class vgl_line_2d_regression<T > 162 #endif // vgl_line_2d_regression_hxx_ bool fit()
Fit a line to the current point set.
double get_rms_error_est(vgl_point_2d< T > const &p, bool increment=true)
Get estimated fitting error if the point (x, y) were added to the fit.
void increment_partial_sums(const T x, const T y)
Add a point to the 2d_regression.
void init_rms_error_est()
Initialize estimated fitting error.
void clear()
Clear 2d_regression sums.
void decrement_partial_sums(const T x, const T y)
Remove a point from the 2d_regression.
double get_rms_error()
Get fitting error for current fitted line.
A helper class for line fitting.
bool fit_constrained(T x, T y)
Fit a line to the current point set constrained to pass through (x,y).
double vgl_distance(vgl_point_2d< T >const &p1, vgl_point_2d< T >const &p2)
return the distance between two points.
vgl_line_2d_regression()
Constructor.
Set of distance functions.