contrib/mul/mfpf/mfpf_feature_vec.h
Go to the documentation of this file.
00001 #ifndef mfpf_feature_vec_h_
00002 #define mfpf_feature_vec_h_
00003 //:
00004 // \file
00005 // \brief Container for set of poses and associated fit values
00006 // \author Martin Roberts
00007 
00008 #include <mfpf/mfpf_pose.h>
00009 #include <mfpf/mfpf_pose_set.h>
00010 #include <vsl/vsl_vector_io.h>
00011 #include <vcl_iostream.h>
00012 #include <vcl_cstdlib.h>
00013 
00014 
00015 //As well as pose_set, it can be helpful to think of vector combined pose/fit
00016 struct mfpf_feature
00017 {
00018     mfpf_pose pose;
00019     double fit;
00020     mfpf_feature() {fit=0.0;}
00021     mfpf_feature(const mfpf_pose& p,double f):pose(p),fit(f) {}
00022     
00023 };
00024 typedef vcl_vector<mfpf_feature > mfpf_feature_vec ;
00025 
00026 
00027 
00028 inline void vsl_b_write(vsl_b_ostream& bfs,
00029                         const mfpf_feature& f)
00030 {
00031   vsl_b_write(bfs,short(1));  // Version number
00032   vsl_b_write(bfs,f.pose);
00033   vsl_b_write(bfs,f.fit);
00034 }
00035 inline void vsl_b_read(vsl_b_istream& bfs,
00036                         mfpf_feature& f)
00037 {
00038 
00039   short version;
00040   vsl_b_read(bfs,version);
00041   switch (version)
00042   {
00043     case (1):
00044       vsl_b_read(bfs,f.pose);
00045       vsl_b_read(bfs,f.fit);
00046       break;
00047     default:
00048       vcl_cerr << "vsl_b_read(bfs,mfpf_feature): "
00049                << "Unexpected version number " << version << vcl_endl;
00050       vcl_abort();
00051   }    
00052 }
00053 
00054 inline void mfpf_pose_set_to_feature_vec(const mfpf_pose_set& pose_set, mfpf_feature_vec& feature_vec)
00055 {
00056     vcl_vector<mfpf_pose>::const_iterator posesIter=pose_set.poses.begin();
00057     vcl_vector<mfpf_pose>::const_iterator posesIterEnd=pose_set.poses.end();
00058     vcl_vector<double >::const_iterator fitsIter=pose_set.fits.begin();
00059 
00060     feature_vec.clear();
00061     feature_vec.reserve(pose_set.poses.size());
00062     while(posesIter != posesIterEnd)
00063     {
00064         feature_vec.push_back(mfpf_feature(*posesIter++,*fitsIter++));
00065     }
00066 }
00067 inline void mfpf_feature_vec_to_pose_set(const mfpf_feature_vec& feature_vec, mfpf_pose_set& pose_set )
00068 {
00069     pose_set.poses.clear();    pose_set.fits.clear();
00070     pose_set.poses.reserve(feature_vec.size()); pose_set.fits.reserve(feature_vec.size()); 
00071     mfpf_feature_vec::const_iterator featureIter=feature_vec.begin();
00072     mfpf_feature_vec::const_iterator featureIterEnd=feature_vec.end();
00073 
00074     while(featureIter != featureIterEnd)
00075     {
00076         pose_set.poses.push_back(mfpf_pose(featureIter->pose));
00077         pose_set.fits.push_back(featureIter->fit);
00078         ++featureIter;
00079     }
00080 }
00081 
00082 #endif // mfpf_feature_vec_h_
00083