MoleculeProcessor.h
Go to the documentation of this file.
00001 /*
00002  * MoleculeProcessor.h
00003  *
00004  *  Created on: Oct 20, 2010
00005  *      Author: erublee
00006  */
00007 
00008 #ifndef MOLECULEPROCESSOR_H_
00009 #define MOLECULEPROCESSOR_H_
00010 
00011 #include "pano_core/ImageAtom.h"
00012 #include "pano_core/ImageMolecule.h"
00013 
00014 #include <list>
00015 #include <map>
00016 #include <set>
00017 
00018 namespace pano
00019 {
00020 
00024 class MoleculeProcessor
00025 {
00026 
00027 private:
00028   MoleculeProcessor();
00029 public:
00031   static const std::string SHOW_PAIRS;
00032 
00034   static const std::string GRAPHVIZ_FILENAME;
00035 
00037   static const std::string VERBOSE_GRAPHVIZ_FILENAME;
00038 
00042   static AtomPair matchwithFitter(cv::Ptr<ImageAtom> atom1, cv::Ptr<ImageAtom> atom2, ModelFitter& modelfitter);
00043   static AtomPair matchwithFitter(cv::Ptr<ImageAtom> atom1, cv::Ptr<ImageAtom> atom2, cv::Ptr<ModelFitter> modelfitter){
00044      return matchwithFitter(atom1,atom2,*modelfitter);
00045     }
00046 
00053   static std::list<AtomPair> queryWithAtom(const ImageMolecule& molecule, cv::Ptr<ImageAtom> atom2,
00054                                            cv::Ptr<ModelFitter> modelfitter, float angle_thresh = -1.0);
00055 
00060   static void create_num_steps_map(const ImageMolecule& mol, const cv::Ptr<ImageAtom> anchor_atom, const cv::Ptr<
00061       ImageAtom>& atom, std::map<cv::Ptr<ImageAtom>, size_t>& num_steps_map,
00062                                    std::map<cv::Ptr<ImageAtom>, std::set<std::string> > atoms_queried, std::map<
00063                                        cv::Ptr<ImageAtom>, bool>& node_lock, const std::string& graphvizDbgFilename =
00064                                        std::string(""));
00065 
00070   static void getCyclePairsAndAtoms(const ImageMolecule& mol, const std::map<cv::Ptr<ImageAtom>, size_t>& num_steps,
00071                                     const cv::Ptr<ImageAtom>& in_atom,
00072                                     std::map<cv::Ptr<ImageAtom>, AtomPair>& atom_to_pair_map,
00073                                     std::list<cv::Ptr<ImageAtom> >& atomchain, std::list<AtomPair>& cyclePairs);
00074 
00075   enum TFinder
00076   {
00077     DIJKSTRA
00078   };
00079 
00083   static void findAndSetTrinsics(ImageMolecule& mol, TFinder WAY);
00084 };
00085 
00086 class MoleculeGlob;
00087 
00093 struct Globber
00094 {
00095   static const std::string VERBOSE;
00096   MoleculeGlob* glob;
00097   cv::Ptr<ModelFitter> fitter;
00098   Globber(MoleculeGlob*glob, cv::Ptr<ModelFitter> fitter) :
00099     glob(glob), fitter(fitter)
00100   {
00101   }
00102   void operator()(cv::Ptr<ImageAtom> atom);
00103 
00104 };
00105 
00110 class MoleculeGlob : public serializable
00111 {
00112 
00113 public:
00114   MoleculeGlob();
00115 
00116   float minDistToAtom(const ImageAtom & atom) const;
00117 
00120   cv::Ptr<ImageAtom> minDistAtom( const ImageAtom & atom) const;
00121 
00124   cv::Ptr<ImageAtom> queryAtomToGlob( cv::Ptr<ModelFitter> fitter,
00125                          const ImageAtom& atom, std::list<AtomPair>& pairs, bool clone = true);
00126 
00133   cv::Ptr<ImageAtom> addAtomToGlob(cv::Ptr<ModelFitter> fitter, const ImageAtom& atom);
00134 
00146   Globber getGlobber(cv::Ptr<ModelFitter> fitter)
00147   {
00148     return Globber(this, fitter);
00149   }
00150 
00159   cv::Ptr<ImageMolecule> getBiggestMolecule() const;
00160 
00168   void truncateMolecules(cv::Ptr<ImageMolecule> mol_in = cv::Ptr<ImageMolecule>());
00169 
00172   void addPrefittedPairs(const std::list<AtomPair>& pairs, cv::Ptr<ImageAtom> atom = cv::Ptr<ImageAtom>());
00173 
00176   void addPrefittedPairs(const std::vector<AtomPair>& pairs, cv::Ptr<ImageAtom> atom= cv::Ptr<ImageAtom>());
00177 
00180   void reset()
00181   {
00182     molecules.clear();
00183   }
00184 
00185   void addMolecule(cv::Ptr<ImageMolecule> molecule)
00186   {
00187     molecules.insert(molecule);
00188   }
00189 
00192   const std::set<cv::Ptr<ImageMolecule> > & getMolecules() const
00193   {
00194     return molecules;
00195   }
00196 
00197   void overideDirectory(std::string directory);
00198 
00199   std::set<cv::Ptr<ImageMolecule> > & getMolecules()
00200   {
00201     return molecules;
00202   }
00203 
00204   cv::Ptr<ImageMolecule> getMerged() const;
00205 
00206   void batchFindAndSetTrinsics();
00207 
00208   /*
00209    * serializable functions
00210    */
00211   virtual int version() const
00212   {
00213     return 0;
00214   }
00215 
00216   virtual void serialize(cv::FileStorage& fs) const;
00217   virtual void deserialize(const cv::FileNode& fn);
00218   void setMatcher(cv::Ptr<cv::DescriptorMatcher> matcher);
00219 private:
00220   void generateMasks(const ImageAtom& atom, std::vector<cv::Mat>& masks)const;
00221   void addAtomDescriptors(cv::Ptr<ImageAtom> atom);
00225   std::set<cv::Ptr<ImageMolecule> > molecules;
00226   int uid_count_;
00227   friend struct PairGlobber;
00228 
00229   std::vector<cv::Ptr<ImageAtom> > atoms_;
00230   std::map<int,int> atom_uids_idxs_;
00231   std::vector<cv::Mat> all_descriptions_;
00232   cv::Ptr<cv::DescriptorMatcher> matcher_;
00233 
00234 };
00235 
00236 struct MoleculePeeler
00237 {
00238   void operator()(cv::Ptr<ImageMolecule>& mol)
00239   {
00240     mol->peelAtoms();
00241   }
00242 };
00243 
00244 }
00245 
00246 #endif // MOLECULEPROCESSOR_H


pano_core
Author(s): Ethan Rublee
autogenerated on Mon Oct 6 2014 08:04:38