contrib/mul/msm/msm_ref_shape_model.h
Go to the documentation of this file.
00001 #ifndef msm_ref_shape_model_h_
00002 #define msm_ref_shape_model_h_
00003 //:
00004 // \file
00005 // \brief Contains mean/modes etc of a shape model in ref. frame
00006 // No information about global transformation 
00007 // - see msm_shape_model for that.
00008 // \author Tim Cootes
00009 
00010 #include <vcl_cassert.h>
00011 #include <vcl_iosfwd.h>
00012 #include <vcl_string.h>
00013 #include <vsl/vsl_fwd.h>
00014 #include <msm/msm_points.h>
00015 #include <vnl/vnl_matrix.h>
00016 #include <mbl/mbl_cloneable_ptr.h>
00017 #include <msm/msm_param_limiter.h>
00018 
00019 //: Contains mean/modes etc of a shape model in a reference frame.
00020 //  Container to hold the components of a statistical shape model
00021 //  in the reference frame.
00022 //  Uses a linear model the shape variation.
00023 //  This has no information about the global transformation 
00024 //  (msm_aligner) - see msm_shape_model for that.
00025 //
00026 //  The associated msm_ref_shape_instance class contains functions to
00027 //  synthesize and match to shapes using this model.
00028 class msm_ref_shape_model
00029 {
00030  protected:
00031   //: Mean of shape model
00032   msm_points mean_;
00033 
00034   //: Scale of mean points (=mean_.scale())
00035   double mean_points_scale_;
00036 
00037   //: Modes of variation
00038   vnl_matrix<double> modes_;
00039 
00040   //: Variance for each mode
00041   vnl_vector<double> mode_var_;
00042 
00043   //: Default choice of parameter limiter
00044   mbl_cloneable_ptr<msm_param_limiter> param_limiter_;
00045 
00046  public:
00047 
00048   // Dflt ctor
00049   msm_ref_shape_model();
00050 
00051   // Destructor
00052   ~msm_ref_shape_model();
00053 
00054   //: Set up model
00055   void set(const msm_points& mean,
00056            const vnl_matrix<double>& modes,
00057            const vnl_vector<double>& mode_var,
00058            const msm_param_limiter& param_limiter);
00059 
00060   //: Mean of shape model as vector
00061   const vnl_vector<double>& mean() const { return mean_.vector(); }
00062 
00063   //: Scale of mean points in ref. frame (=mean_.scale())
00064   double ref_mean_points_scale() const { return mean_points_scale_; }
00065 
00066 
00067   //: Mean of shape model as points
00068   const msm_points& mean_points() const { return mean_; }
00069 
00070   //: Modes of variation
00071   const vnl_matrix<double>& modes() const { return modes_; }
00072 
00073   //: Variance for each mode
00074   const vnl_vector<double>& mode_var() const { return mode_var_; }
00075 
00076   //: Current object which limits parameters
00077   const msm_param_limiter& param_limiter() const 
00078   { return param_limiter_; }
00079 
00080   //: Current object which limits parameters (non-const)
00081   msm_param_limiter& param_limiter()
00082   { return param_limiter_; }
00083 
00084   //: Number of points
00085   unsigned size() const { return mean_.size(); }
00086 
00087   //: Number of modes
00088   unsigned n_modes() const { return modes_.columns(); }
00089 
00090   //: Version number for I/O
00091   short version_no() const;
00092 
00093   //: Name of the class
00094   vcl_string is_a() const;
00095 
00096   //: Print class to os
00097   void print_summary(vcl_ostream& os) const;
00098 
00099   //: Save class to binary file stream
00100   void b_write(vsl_b_ostream& bfs) const;
00101 
00102   //: Load class from binary file stream
00103   void b_read(vsl_b_istream& bfs);
00104 
00105   //: Equality test
00106   bool operator==(const msm_ref_shape_model& points) const;
00107 };
00108 
00109 
00110 //: Binary file stream output operator for class reference
00111 void vsl_b_write(vsl_b_ostream& bfs, const msm_ref_shape_model& pts);
00112 
00113 
00114 //: Binary file stream input operator for class reference
00115 void vsl_b_read(vsl_b_istream& bfs, msm_ref_shape_model& pts);
00116 
00117 //: Stream output operator for class reference
00118 vcl_ostream& operator<<(vcl_ostream& os,const msm_ref_shape_model& pts);
00119 
00120 //: Stream output operator for class reference
00121 void vsl_print_summary(vcl_ostream& os,const msm_ref_shape_model& pts);
00122 
00123 #endif // msm_ref_shape_model_h_