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/ProgressDisplay.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, const float imageStepSize)
00050                 : TimeConsumingPanoramaAlgorithm(panorama, progressDisplay),
00051                   o_vars(vars), o_correspondences(correspondences), o_resultError(0.0), o_imageStepSize(imageStepSize)
00052             {};
00053         
00055             virtual ~PhotometricOptimizer() {};
00056     
00057             
00058         public:
00060             static void optimizePhotometric(PanoramaData& pano, const OptimizeVector& vars,
00061                                             const PointPairs& correspondences,
00062                                             const float imageStepSize,
00063                                             AppBase::ProgressDisplay* progress,
00064                                             double& error);
00065         
00066         protected:
00068             struct VarMapping
00069             {
00070                 std::string type;
00071                 std::set<unsigned> imgs;
00072             };
00073 
00075             struct OptimData
00076             {
00077                 
00078                 const PanoramaData& m_pano;
00079                 std::vector<SrcPanoImage> m_imgs;
00080                 std::vector<VarMapping> m_vars;
00081                 std::vector<vigra_ext::PointPairRGB> m_data;
00082                 double huberSigma;
00083                 bool symmetricError;
00084 
00085                 int m_maxIter;
00086                 AppBase::ProgressDisplay* m_progress;
00087 
00088 
00090                 OptimData(const PanoramaData& pano, const OptimizeVector& optvars,
00091                           const std::vector<vigra_ext::PointPairRGB>& data,
00092                           double mEstimatorSigma, bool symmetric,
00093                           int maxIter, AppBase::ProgressDisplay* progress);
00094 
00096                 void ToX(double * x);
00097 
00099                 void FromX(double * x);
00100                 
00101             };
00102             
00103             static int photometricVis(double *p, double *x, int m, int n, int iter, double sqerror, void * data);
00104 
00106             static void photometricError(double* p, double* x, int m, int n, void* data);
00107 
00108 
00109         public:
00111             virtual bool modifiesPanoramaData() const
00112                 { return true; }
00113             
00115             virtual bool runAlgorithm();
00116     
00117             
00118         public:
00119             double getResultError() const
00120             {
00121                 // [TODO] if(!hasRunSuccessfully()) DEBUG;
00122                 return o_resultError;
00123             }
00124                 
00125             
00126         protected:
00127             const OptimizeVector& o_vars;
00128             const PointPairs& o_correspondences;
00129             const float o_imageStepSize;
00130             double o_resultError;
00131     };
00132 
00133 
00134 
00135 
00136     class IMPEX SmartPhotometricOptimizer : public PhotometricOptimizer, protected SmartOptimizerStub
00137     {
00138         public:
00140             enum PhotometricOptimizeMode {
00141                 OPT_PHOTOMETRIC_LDR=0, 
00142                 OPT_PHOTOMETRIC_LDR_WB, 
00143                 OPT_PHOTOMETRIC_HDR, 
00144                 OPT_PHOTOMETRIC_HDR_WB
00145             };
00146         
00148             SmartPhotometricOptimizer(PanoramaData& panorama, AppBase::ProgressDisplay* progressDisplay,
00149                                        const OptimizeVector& vars,
00150                                        const PointPairs& correspondences,
00151                                        const float imageStepSize,
00152                                        PhotometricOptimizeMode optMode)
00153                 : PhotometricOptimizer(panorama, progressDisplay, vars, correspondences, imageStepSize), o_optMode(optMode)
00154             {};
00155             
00157             virtual ~SmartPhotometricOptimizer() {};
00158         
00159             
00160         public:
00163             static void smartOptimizePhotometric(PanoramaData & pano, PhotometricOptimizeMode mode,
00164                                                  const std::vector<vigra_ext::PointPairRGB> & correspondences,
00165                                                  const float imageStepSize,
00166                                                  AppBase::ProgressDisplay* progress,
00167                                                  double & error);
00168             
00170             virtual bool runAlgorithm();
00171 
00172             
00173         protected:
00174             PhotometricOptimizeMode o_optMode;
00175     };
00176 
00177     
00178     
00179 } // namespace
00180 
00181 
00182 #endif

Generated on 8 Dec 2016 for Hugintrunk by  doxygen 1.4.7