[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin_base/algorithms/optimizer/PTOptimizer.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00028 #ifndef _PTOPTIMIZER_H
00029 #define _PTOPTIMIZER_H
00030 
00031 #include <algorithm/PanoramaAlgorithm.h>
00032 
00033 #include <hugin_shared.h>
00034 #include <set>
00035 #include <boost/graph/breadth_first_search.hpp>
00036 #include <panodata/PanoramaData.h>
00037 
00038 namespace HuginBase {
00039     
00040     
00042     class IMPEX PTOptimizer : public PanoramaAlgorithm
00043     {
00044     
00045         public:
00047             PTOptimizer(PanoramaData& panorama)
00048              : PanoramaAlgorithm(panorama)
00049             {};
00050         
00052             virtual ~PTOptimizer()
00053             {}
00054             
00055             
00056         public:
00058             virtual bool modifiesPanoramaData() const
00059                 { return true; }
00060             
00062             virtual bool runAlgorithm();
00063     };
00064     
00065     
00067     class IMPEX AutoOptimise : public PTOptimizer
00068     {
00069         
00070         public:
00072             AutoOptimise(PanoramaData& panorama)
00073              : PTOptimizer(panorama)
00074             {};
00075         
00077             virtual ~AutoOptimise()
00078             {}
00079             
00080         
00081         public:
00083             static void autoOptimise(PanoramaData& pano);
00084             
00085         protected:
00087             class OptimiseVisitor: public boost::default_bfs_visitor
00088             {
00089             public:
00090                 OptimiseVisitor(PanoramaData& pano, const std::set<std::string> & optvec)
00091                     : m_opt(optvec), m_pano(pano)
00092                 {};
00093                 
00095                 template <typename Vertex, typename Graph>
00096                 void discover_vertex(Vertex v, const Graph & g);
00097                 
00099                 VariableMapVector getVariables() const
00100                     { return m_pano.getVariables(); }
00101             
00102 //                ///
00103 //                const CPVector & getCtrlPoints() const
00104 //                    { return m_cps; }
00105             
00106             private:
00107                 const std::set<std::string> & m_opt;
00108                 PanoramaData & m_pano;
00109             };
00110             
00111             
00112         public:
00114             virtual bool runAlgorithm()
00115             {
00116                 autoOptimise(o_panorama);
00117                 return true; // let's hope so.
00118             }
00119 
00120     };
00121     
00123     class IMPEX SmartOptimizerStub
00124     {
00125         public:
00127             enum OptMode {
00128                 OPT_POS=1,
00129                 OPT_B=2, 
00130                 OPT_AC=4, 
00131                 OPT_DE=8, 
00132                 OPT_HFOV=16, 
00133                 OPT_GT=32, 
00134                 OPT_VIG=64, 
00135                 OPT_VIGCENTRE=128, 
00136                 OPT_EXP=256, 
00137                 OPT_WB=512, 
00138                 OPT_RESP=1024
00139             };
00140             
00142             static OptimizeVector createOptVars(const PanoramaData& optPano, int mode, unsigned anchorImg=0);   
00143     };
00144     
00145     class IMPEX SmartOptimise : public PTOptimizer, protected SmartOptimizerStub
00146     {
00147         
00148         public:
00150             SmartOptimise(PanoramaData& panorama)
00151              : PTOptimizer(panorama)
00152             {};
00153         
00155             virtual ~SmartOptimise()
00156             {}
00157         
00158         public:
00160             static void smartOptimize(PanoramaData& pano);
00161         
00162             
00163         public:
00165             virtual bool runAlgorithm()
00166             {
00167                 smartOptimize(o_panorama);
00168                 return true; // let's hope so.
00169             }
00170 
00171     };
00172     
00173 }//namesapce
00174 
00175 
00176 
00177 //==============================================================================
00178 // template implementation
00179 
00180 
00181 #include <algorithms/optimizer/ImageGraph.h>
00182 #include <panotools/PanoToolsOptimizerWrapper.h>
00183 
00184 namespace HuginBase {
00185 
00186 template <typename Vertex, typename Graph>
00187 void AutoOptimise::OptimiseVisitor::discover_vertex(Vertex v, const Graph & g)
00188 {
00189     UIntSet imgs;
00190     imgs.insert(v);
00191     //        VariableMapVector vars(1);
00192 #ifdef DEBUG
00193     std::cerr << "before optim "<< v << " : ";
00194     printVariableMap(std::cerr, m_pano.getImageVariables(v));
00195     std::cerr << std::endl;
00196 #endif
00197     
00198     // collect all optimized neighbours
00199     typename boost::graph_traits<CPGraph>::adjacency_iterator ai;
00200     typename boost::graph_traits<CPGraph>::adjacency_iterator ai_end;
00201     for (tie(ai, ai_end) = adjacent_vertices(v, g);
00202          ai != ai_end; ++ai)
00203     {
00204         if (*ai != v) {
00205             if ( (get(boost::vertex_color, g))[*ai] != boost::color_traits<boost::default_color_type>::white()) {
00206                 // image has been already optimized, use as anchor
00207                 imgs.insert(unsigned(*ai));
00208                 DEBUG_DEBUG("non white neighbour " << (*ai));
00209             } else {
00210                 DEBUG_DEBUG("white neighbour " << (*ai));
00211             }
00212         }
00213     }
00214     
00215     // get pano with neighbouring images.
00216     PanoramaData& localPano = *(m_pano.getNewSubset(imgs)); // don't forget to delete
00217     
00218     // find number of current image in subset
00219     unsigned currImg = 0;
00220     unsigned cnt=0;
00221     for (UIntSet::const_iterator it= imgs.begin(); it != imgs.end(); ++it) {
00222         if (v == *it) {
00223             currImg = cnt;
00224         }
00225         cnt++;
00226     }
00227     
00228     OptimizeVector optvec(imgs.size());
00229     optvec[currImg] = m_opt;
00230     localPano.setOptimizeVector(optvec);
00231     
00232     if ( imgs.size() > 1) {
00233         DEBUG_DEBUG("optimising image " << v << ", with " << imgs.size() -1 << " already optimised neighbour imgs.");
00234         
00235         PTools::optimize(localPano);
00236         m_pano.updateVariables(unsigned(v), localPano.getImageVariables(currImg));
00237 #ifdef DEBUG
00238         std::cerr << "after optim " << v << " : ";
00239         printVariableMap(std::cerr, m_pano.getImageVariables(v));
00240         std::cerr << std::endl;
00241 #endif
00242     }
00243 
00244     delete &localPano;
00245 }
00246 
00247 } //namespace
00248 #endif //_h

Generated on Mon Sep 20 01:01:27 2010 for Hugintrunk by doxygen 1.3.9.1