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