Go to the documentation of this file.00001 #include "msm_ref_shape_model.h"
00002
00003
00004
00005
00006
00007 #include <vcl_iostream.h>
00008 #include <vsl/vsl_indent.h>
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vnl/io/vnl_io_vector.h>
00011 #include <vnl/io/vnl_io_matrix.h>
00012 #include <vcl_cstdlib.h>
00013 #include <vcl_cassert.h>
00014
00015
00016
00017
00018
00019
00020 msm_ref_shape_model::msm_ref_shape_model()
00021 : mean_points_scale_(0)
00022 {
00023 }
00024
00025
00026
00027
00028
00029 msm_ref_shape_model::~msm_ref_shape_model()
00030 {
00031 }
00032
00033
00034 void msm_ref_shape_model::set(const msm_points& mean,
00035 const vnl_matrix<double>& modes,
00036 const vnl_vector<double>& mode_var,
00037 const msm_param_limiter& param_limiter)
00038 {
00039 assert(mean.vector().size()%2==0);
00040 assert(mode_var.size()==modes.columns());
00041 if (mode_var.size()!=0)
00042 {
00043 assert(mean.size()*2==modes.rows());
00044 }
00045
00046 mean_ = mean;
00047 mean_points_scale_ = mean.scale();
00048 modes_ = modes;
00049 mode_var_ = mode_var;
00050 param_limiter_ = param_limiter;
00051 }
00052
00053
00054 bool msm_ref_shape_model::operator==(const msm_ref_shape_model& model) const
00055 {
00056 if (model.mean_.size()!=mean_.size()) return false;
00057 if (model.mode_var_.size()!=mode_var_.size()) return false;
00058 if (mean_.size()==0) return true;
00059
00060 const double epsilon = 1e-3;
00061
00062 double ssd1=vnl_vector_ssd(model.mean_.vector(),mean_.vector());
00063 if (vcl_fabs(ssd1/mean_.size())>epsilon) return false;
00064
00065 double ssd2=vnl_vector_ssd(model.mode_var_,mode_var_);
00066 if (vcl_fabs(ssd2/mode_var_.size())>epsilon) return false;
00067
00068 double max_d = (modes_-model.modes_).absolute_value_max();
00069 if (max_d>epsilon) return false;
00070
00071 return true;
00072 }
00073
00074
00075
00076
00077
00078
00079 short msm_ref_shape_model::version_no() const
00080 {
00081 return 1;
00082 }
00083
00084
00085
00086
00087
00088 vcl_string msm_ref_shape_model::is_a() const
00089 {
00090 return vcl_string("msm_ref_shape_model");
00091 }
00092
00093
00094
00095
00096
00097
00098 void msm_ref_shape_model::print_summary(vcl_ostream& os) const
00099 {
00100 os << "n_pts: "<<size()<<" n_modes: "<<n_modes()<<vcl_endl;
00101 vsl_indent_inc(os);
00102 os << vcl_endl << vsl_indent() << " param_limiter: ";
00103 if (param_limiter_.isDefined())
00104 os<<param_limiter_; else os<<"-";
00105 os<<vcl_endl;
00106 vsl_indent_dec(os);
00107 }
00108
00109
00110
00111
00112
00113
00114 void msm_ref_shape_model::b_write(vsl_b_ostream& bfs) const
00115 {
00116 vsl_b_write(bfs,version_no());
00117 vsl_b_write(bfs,mean_);
00118 vsl_b_write(bfs,modes_);
00119 vsl_b_write(bfs,mode_var_);
00120 vsl_b_write(bfs,param_limiter_);
00121 }
00122
00123
00124
00125
00126
00127
00128 void msm_ref_shape_model::b_read(vsl_b_istream& bfs)
00129 {
00130 short version;
00131 vsl_b_read(bfs,version);
00132 switch (version)
00133 {
00134 case (1):
00135 vsl_b_read(bfs,mean_);
00136 vsl_b_read(bfs,modes_);
00137 vsl_b_read(bfs,mode_var_);
00138 vsl_b_read(bfs,param_limiter_);
00139 break;
00140 default:
00141 vcl_cerr << "msm_ref_shape_model::b_read() :\n"
00142 << "Unexpected version number " << version << vcl_endl;
00143 bfs.is().clear(vcl_ios::badbit);
00144 return;
00145 }
00146
00147 mean_points_scale_=mean_.scale();
00148 }
00149
00150
00151
00152
00153
00154
00155 void vsl_b_write(vsl_b_ostream& bfs, const msm_ref_shape_model& b)
00156 {
00157 b.b_write(bfs);
00158 }
00159
00160
00161
00162
00163
00164 void vsl_b_read(vsl_b_istream& bfs, msm_ref_shape_model& b)
00165 {
00166 b.b_read(bfs);
00167 }
00168
00169
00170
00171
00172
00173 vcl_ostream& operator<<(vcl_ostream& os,const msm_ref_shape_model& b)
00174 {
00175 vsl_indent_inc(os);
00176 b.print_summary(os);
00177 vsl_indent_dec(os);
00178 return os;
00179 }
00180
00181
00182 void vsl_print_summary(vcl_ostream& os,const msm_ref_shape_model& b)
00183 {
00184 os << b;
00185 }