PhotometricOptimizer.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _PHOTOMETRIC_OPTIMIZER_H_
00025 #define _PHOTOMETRIC_OPTIMIZER_H_
00026 
00027 #include <hugin_shared.h>
00028 #include <algorithms/PanoramaAlgorithm.h>
00029 #include <algorithms/optimizer/PTOptimizer.h>
00030 
00031 #include <vector>
00032 #include <panodata/PanoramaData.h>
00033 #include <appbase/ProgressReporterOld.h>
00034 #include <vigra_ext/VignettingCorrection.h>
00035 
00036 namespace HuginBase
00037 {
00038     
00039     class IMPEX PhotometricOptimizer : public TimeConsumingPanoramaAlgorithm
00040     {
00041         
00042         public:
00044             typedef std::vector<vigra_ext::PointPairRGB> PointPairs;
00045         
00047             PhotometricOptimizer(PanoramaData& panorama, AppBase::ProgressDisplay* progressDisplay,
00048                                  const OptimizeVector& vars,
00049                                  const PointPairs& correspondences)
00050                 : TimeConsumingPanoramaAlgorithm(panorama, progressDisplay),
00051                   o_vars(vars), o_correspondences(correspondences), o_resultError(0.0)
00052             {};
00053         
00055             virtual ~PhotometricOptimizer() {};
00056     
00057             
00058         public:
00060             static void optimizePhotometric(PanoramaData& pano, const OptimizeVector& vars,
00061                                             const PointPairs& correspondences,
00062                                             AppBase::ProgressReporter& progress,
00063                                             double& error);
00064         
00065         protected:
00067             struct VarMapping
00068             {
00069                 std::string type;
00070                 std::set<unsigned> imgs;
00071             };
00072 
00074             struct OptimData
00075             {
00076                 
00077                 const PanoramaData& m_pano;
00078                 std::vector<SrcPanoImage> m_imgs;
00079                 std::vector<VarMapping> m_vars;
00080                 std::vector<vigra_ext::PointPairRGB> m_data;
00081                 double huberSigma;
00082                 bool symmetricError;
00083 
00084                 int m_maxIter;
00085                 AppBase::ProgressReporter& m_progress;
00086 
00087 
00089                 OptimData(const PanoramaData& pano, const OptimizeVector& optvars,
00090                           const std::vector<vigra_ext::PointPairRGB>& data,
00091                           double mEstimatorSigma, bool symmetric,
00092                           int maxIter, AppBase::ProgressReporter& progress);
00093 
00095                 void ToX(double * x);
00096 
00098                 void FromX(double * x);
00099                 
00100             };
00101             
00102             static int photometricVis(double *p, double *x, int m, int n, int iter, double sqerror, void * data);
00103 
00105             static void photometricError(double* p, double* x, int m, int n, void* data);
00106 
00107 
00108         public:
00110             virtual bool modifiesPanoramaData() const
00111                 { return true; }
00112             
00114             virtual bool runAlgorithm();
00115     
00116             
00117         public:
00118             double getResultError() const
00119             {
00120                 // [TODO] if(!hasRunSuccessfully()) DEBUG;
00121                 return o_resultError;
00122             }
00123                 
00124             
00125         protected:
00126             const OptimizeVector& o_vars;
00127             const PointPairs& o_correspondences;
00128             double o_resultError;
00129     };
00130 
00131 
00132 
00133 
00134     class IMPEX SmartPhotometricOptimizer : public PhotometricOptimizer, protected SmartOptimizerStub
00135     {
00136         public:
00138             enum PhotometricOptimizeMode {
00139                 OPT_PHOTOMETRIC_LDR=0, 
00140                 OPT_PHOTOMETRIC_LDR_WB, 
00141                 OPT_PHOTOMETRIC_HDR, 
00142                 OPT_PHOTOMETRIC_HDR_WB
00143             };
00144         
00146             SmartPhotometricOptimizer(PanoramaData& panorama, AppBase::ProgressDisplay* progressDisplay,
00147                                        const OptimizeVector& vars,
00148                                        const PointPairs& correspondences,
00149                                        PhotometricOptimizeMode optMode)
00150                 : PhotometricOptimizer(panorama, progressDisplay, vars, correspondences), o_optMode(optMode)
00151             {};
00152             
00154             virtual ~SmartPhotometricOptimizer() {};
00155         
00156             
00157         public:
00160             static void smartOptimizePhotometric(PanoramaData & pano, PhotometricOptimizeMode mode,
00161                                                  const std::vector<vigra_ext::PointPairRGB> & correspondences,
00162                                                  AppBase::ProgressReporter & progress,
00163                                                  double & error);
00164             
00166             virtual bool runAlgorithm();
00167 
00168             
00169         protected:
00170             PhotometricOptimizeMode o_optMode;
00171     };
00172 
00173     
00174     
00175 } // namespace
00176 
00177 
00178 #endif

Generated on 5 Dec 2014 for Hugintrunk by  doxygen 1.4.7