Go to the documentation of this file.00001
00002 #ifndef imesh_pca_h_
00003 #define imesh_pca_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <imesh/imesh_mesh.h>
00017 #include <vcl_vector.h>
00018 #include <vcl_cassert.h>
00019 #include <vnl/vnl_vector.h>
00020 #include <vnl/vnl_matrix.h>
00021 #include <vpgl/vpgl_proj_camera.h>
00022
00023
00024
00025 class imesh_pca_mesh : public imesh_mesh
00026 {
00027 public:
00028
00029 imesh_pca_mesh() {}
00030
00031
00032 imesh_pca_mesh(const vcl_vector<imesh_mesh>& meshes);
00033
00034
00035 imesh_pca_mesh(const imesh_mesh& mesh,
00036 const vnl_vector<double>& mean,
00037 const vnl_vector<double>& std_devs,
00038 const vnl_matrix<double>& pc);
00039
00040
00041 imesh_pca_mesh(const imesh_pca_mesh& other);
00042
00043
00044 imesh_pca_mesh& operator=(const imesh_pca_mesh& other);
00045
00046
00047
00048 void init(const vnl_vector<double>& mean,
00049 const vnl_vector<double>& std_devs,
00050 const vnl_matrix<double>& pc);
00051
00052
00053 void set_params(const vnl_vector<double>& p);
00054
00055
00056
00057
00058 void set_param(unsigned int i, double param);
00059
00060
00061 const vnl_vector<double>& params() const {return params_;}
00062
00063
00064 const vnl_matrix<double>& principal_comps() const {return pc_; }
00065
00066
00067 const vnl_vector<double>& std_devs() const {return std_devs_;}
00068
00069
00070
00071 void set_mean();
00072
00073
00074 vnl_vector<double> project(const imesh_vertex_array_base& verts) const;
00075
00076
00077 const imesh_vertex_array_base& mean_vertices() const { return *mean_verts_; }
00078 imesh_vertex_array_base& mean_vertices() { return *mean_verts_; }
00079
00080
00081 template <unsigned int d>
00082 const imesh_vertex_array<d>& mean_vertices() const
00083 {
00084 assert(dynamic_cast<imesh_vertex_array<d>*>(mean_verts_.get()));
00085 return static_cast<const imesh_vertex_array<d>&>(*mean_verts_);
00086 }
00087 template <unsigned int d>
00088 imesh_vertex_array<d>& mean_vertices()
00089 {
00090 assert(dynamic_cast<imesh_vertex_array<d>*>(mean_verts_.get()));
00091 return static_cast<imesh_vertex_array<d>&>(*mean_verts_);
00092 }
00093
00094 protected:
00095
00096 vnl_matrix<double> compute_mean(const vcl_vector<imesh_mesh>& meshes);
00097
00098 imesh_pca_mesh(const imesh_mesh& mesh);
00099
00100 vnl_vector<double> std_devs_;
00101 vnl_matrix<double> pc_;
00102 vcl_auto_ptr<imesh_vertex_array_base> mean_verts_;
00103
00104 vnl_vector<double> params_;
00105 };
00106
00107
00108
00109
00110
00111 vcl_vector<vnl_matrix<double> >
00112 imesh_pca_image_jacobians(const vpgl_proj_camera<double>& camera,
00113 const imesh_pca_mesh& mesh);
00114
00115
00116
00117 imesh_pca_mesh imesh_read_pca(const vcl_string& mean_file,
00118 const vcl_string& pca_file);
00119
00120
00121 bool imesh_read_pca(const vcl_string& pca_file,
00122 vnl_vector<double>& mean,
00123 vnl_vector<double>& std_devs,
00124 vnl_matrix<double>& pc);
00125
00126
00127 void imesh_write_pca(const vcl_string& mesh_file,
00128 const vcl_string& pca_file,
00129 const imesh_pca_mesh& pmesh);
00130
00131
00132 bool imesh_write_pca(const vcl_string& filename,
00133 const vnl_vector<double>& mean,
00134 const vnl_vector<double>& std_devs,
00135 const vnl_matrix<double>& pc);
00136
00137
00138 #endif // imesh_pca_h_