contrib/mul/mbl/mbl_clamped_plate_spline_2d.h
Go to the documentation of this file.
00001 #ifndef mbl_clamped_plate_spline_2d_h_
00002 #define mbl_clamped_plate_spline_2d_h_
00003 
00004 //:
00005 // \file
00006 // \brief Construct clamped plate spline to map 2D to 2D
00007 // \author Tim Cootes
00008 
00009 #include <vgl/vgl_point_2d.h>
00010 #include <vcl_vector.h>
00011 #include <vnl/vnl_vector.h>
00012 #include <vnl/vnl_matrix.h>
00013 #include <vsl/vsl_binary_io.h>
00014 
00015 //=======================================================================
00016 //: Construct clamped plate spline to map 2D points in unit disk.
00017 // I.e. does some mapping (x',y') = f(x,y).
00018 //
00019 // Acts only within unit disk.  The deformation and its derivatives are
00020 // zero at the unit circle.
00021 //
00022 // For more details, see "Measuring Geodesic Distances on the Space of
00023 // Bounded Diffeomorphisms", C.Twining, S.Marsland et.al.
00024 //
00025 // The warp is `guided' by a set of
00026 // landmarks p(0) .. p(n-1) in the source plane which are to be
00027 // mapped to a (possibly deformed) set q(0)..q(n-1) in the destination.
00028 // Thus the mapping is constrained so that f(p(i)) = q(i) for i = 0..n-1.
00029 // The points are given to the build() function to set up the object.
00030 //
00031 // If one wishes to map a set of source points to multiple target points,
00032 // use set_source_pts(src_pts);  then build(target_pts); for each target set.
00033 class mbl_clamped_plate_spline_2d {
00034 private:
00035   vnl_vector<double> Wx_,Wy_;
00036 
00037   vcl_vector<vgl_point_2d<double> > src_pts_;
00038 
00039     //: Used to estimate weights in set_source_points()
00040   vnl_matrix<double> L_inv_;
00041 
00042     //: Check that all points are inside unit circle
00043   bool all_in_unit_circle(const vcl_vector<vgl_point_2d<double> >& pts);
00044 
00045    //: Set parameters from vectors
00046   void set_params(const vnl_vector<double>& Wx,
00047                   const vnl_vector<double>& Wy);
00048 
00049   void set_up_rhs(vnl_vector<double>& Bx,
00050                   vnl_vector<double>& By,
00051                   const vcl_vector<vgl_point_2d<double> >& src_pts,
00052                   const vcl_vector<vgl_point_2d<double> >& dest_pts);
00053 
00054 public:
00055 
00056     //: Dflt ctor
00057   mbl_clamped_plate_spline_2d();
00058 
00059     //: Destructor
00060   virtual ~mbl_clamped_plate_spline_2d();
00061 
00062     //: Sets up internal transformation to map source_pts onto dest_pts
00063   void build(const vcl_vector<vgl_point_2d<double> >& source_pts,
00064              const vcl_vector<vgl_point_2d<double> >& dest_pts);
00065 
00066     //: Define source point positions
00067     //  Performs pre-computations so that build(dest_points) can be
00068     //  called multiple times efficiently
00069   void set_source_pts(const vcl_vector<vgl_point_2d<double> >& source_pts);
00070 
00071     //: Sets up internal transformation to map source_pts onto dest_pts
00072   void build(const vcl_vector<vgl_point_2d<double> >& dest_pts);
00073 
00074        //: Return transformed version of (x,y)
00075   vgl_point_2d<double>  operator()(double x, double y) const;
00076 
00077        //: Return transformed version of (x,y)
00078   vgl_point_2d<double>  operator()(const vgl_point_2d<double>&  p) const
00079   { return operator()(p.x(),p.y()); }
00080 
00081     //: Version number for I/O
00082   short version_no() const;
00083 
00084     //: Print class to os
00085   void print_summary(vcl_ostream& os) const;
00086 
00087     //: Save class to binary file stream
00088   void b_write(vsl_b_ostream& bfs) const;
00089 
00090     //: Load class from binary file stream
00091   void b_read(vsl_b_istream& bfs);
00092 
00093     //: Comparison operator
00094   bool operator==(const mbl_clamped_plate_spline_2d& tps) const;
00095 };
00096 
00097   //: Binary file stream output operator for class reference
00098 void vsl_b_write(vsl_b_ostream& bfs, const mbl_clamped_plate_spline_2d& b);
00099 
00100   //: Binary file stream input operator for class reference
00101 void vsl_b_read(vsl_b_istream& bfs, mbl_clamped_plate_spline_2d& b);
00102 
00103   //: Stream output operator for class reference
00104 vcl_ostream& operator<<(vcl_ostream& os,const mbl_clamped_plate_spline_2d& b);
00105 
00106 #endif
00107 
00108