SrcPanoImage.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00030 #ifndef _PANODATA_SRCPANOIMAGE_H
00031 #define _PANODATA_SRCPANOIMAGE_H
00032 
00033 // if this file is preprocessed for SWIG, we want to ignore
00034 // all the header inclusions that follow:
00035 
00036 #ifndef _HSI_IGNORE_SECTION
00037 
00038 #include <hugin_shared.h>
00039 #include <hugin_config.h>
00040 #include <iostream>
00041 #include <vector>
00042 #include <vigra/diff2d.hxx>
00043 
00044 #include <hugin_utils/utils.h>
00045 #include <hugin_math/hugin_math.h>
00046 #include "PanoramaVariable.h"
00047 #include "ImageVariable.h"
00048 #include "Mask.h"
00049 #include <map>
00050 
00051 #endif // _HSI_IGNORE_SECTION
00052 
00053 namespace HuginBase {
00054 
00055 class Panorama;
00056 
00058 typedef std::map<std::string, std::string> FileMetaData;
00059 
00067 class IMPEX BaseSrcPanoImage
00068 {
00069 public:
00071     enum Projection {
00072         RECTILINEAR = 0,
00073         PANORAMIC = 1,
00074         CIRCULAR_FISHEYE = 2,
00075         FULL_FRAME_FISHEYE = 3,
00076         EQUIRECTANGULAR = 4,
00077         FISHEYE_ORTHOGRAPHIC = 8,
00078         FISHEYE_STEREOGRAPHIC = 10,
00079         FISHEYE_EQUISOLID = 21,
00080         FISHEYE_THOBY = 20
00081     };
00082     
00084     enum CropMode {
00085         NO_CROP=0,
00086         CROP_RECTANGLE=1,
00087         CROP_CIRCLE=2
00088     };
00089 
00091     enum VignettingCorrMode { 
00092         VIGCORR_NONE = 0,      
00093         VIGCORR_RADIAL = 1,    
00094         VIGCORR_FLATFIELD = 2, 
00095         VIGCORR_DIV = 4        
00096     };
00097 
00099     enum ResponseType {
00100         RESPONSE_EMOR=0,                 
00101         RESPONSE_LINEAR,                 
00102         RESPONSE_GAMMA,                  
00103         RESPONSE_FILE,                   
00104         RESPONSE_ICC                     
00105     };
00106 
00108     bool operator==(const BaseSrcPanoImage & other) const;    
00109     
00110     
00111 public:
00113     BaseSrcPanoImage()
00114     {
00115         setDefaults();
00116     }
00117     
00118     virtual ~BaseSrcPanoImage() {};
00119     
00120     // property accessors
00121 public:
00122     // get[variable name] functions. Return the value stored in the ImageVariable.
00123 #define image_variable( name, type, default_value ) \
00124     type get##name() const { return m_##name.getData(); }
00125 #include "image_variables.h"
00126 #undef image_variable
00127 
00128     // get[variable name]IV functions. Return a const reference to the ImageVariable.
00129 #define image_variable( name, type, default_value ) \
00130     const ImageVariable<type > & get##name##IV() const { return m_##name; }
00131 #include "image_variables.h"
00132 #undef image_variable
00133 
00134     // set[variable name] functions
00135 #define image_variable( name, type, default_value ) \
00136     void set##name(type data) { m_##name.setData(data); }
00137 #include "image_variables.h"
00138 #undef image_variable
00139 
00140     /* The link[variable name] functions
00141      * Pass a pointer to another SrcPanoImg and the respective image variable
00142      * will be shared between the images. Afterwards, changing the variable with
00143      * set[variable name] on either image also sets the other image.
00144      */
00145 #define image_variable( name, type, default_value ) \
00146     void link##name (BaseSrcPanoImage * target) \
00147     { m_##name.linkWith(&(target->m_##name)); }
00148 #include "image_variables.h"
00149 #undef image_variable
00150 
00151     /* The unlink[variable name] functions
00152      * Unlinking a variable makes it unique to this image. Then changing it will
00153      * not affect the other images.
00154      */
00155 #define image_variable( name, type, default_value ) \
00156     void unlink##name () \
00157     { m_##name.removeLinks(); }
00158 #include "image_variables.h"
00159 #undef image_variable
00160 
00161     /* The [variable name]isLinked functions
00162      * Returns true if the variable has links, or false if it is independant.
00163      */
00164 #define image_variable( name, type, default_value ) \
00165     bool name##isLinked () const \
00166     { return m_##name.isLinked(); }
00167 #include "image_variables.h"
00168 #undef image_variable
00169 
00170     /* The [variable name]isLinkedWith functions
00171      * Returns true if the variable is linked with the equivalent variable in
00172      * the specified image, false otherwise.
00173      */
00174 #define image_variable( name, type, default_value ) \
00175     bool name##isLinkedWith (const BaseSrcPanoImage & image) const \
00176     { return m_##name.isLinkedWith(&(image.m_##name)); }
00177 #include "image_variables.h"
00178 #undef image_variable
00179 
00180 protected:
00182     void setDefaults();
00183 
00184     // the image variables m_[variable name]
00185 #define image_variable( name, type, default_value ) \
00186     ImageVariable<type > m_##name;
00187 #include "image_variables.h"
00188 #undef image_variable
00189 };
00190 
00191 
00199 class IMPEX SrcPanoImage : public BaseSrcPanoImage
00200 {
00201 public:
00203     SrcPanoImage()
00204     {
00205         setDefaults();
00206     }
00207     
00208     virtual ~SrcPanoImage() {};
00209 public:
00214     void resize(const vigra::Size2D & size);
00215 
00218     bool isInside(vigra::Point2D p, bool ignoreMasks=false) const;
00219 
00221     bool horizontalWarpNeeded();
00222 
00223     // Accessors
00224     // These are either:
00225     // #- extra ones that are derived from image varibles, or
00226     // #- replacements where we need extra processing.
00227 public:
00228     bool getCorrectTCA() const;
00229     
00235     void setCropMode(CropMode val);
00236 
00238     bool isCircularCrop() const;
00239 
00244     void setSize(vigra::Size2D val);
00245     
00246     hugin_utils::FDiff2D getRadialDistortionCenter() const;
00247     
00248     hugin_utils::FDiff2D getRadialVigCorrCenter() const;
00249     
00250     // these are linked to ExposureValue, which is done with the above.
00251     // exposure value  is log2 of inverse exposure factor.
00252     double getExposure() const;
00253     void setExposure(const double & val);
00254     
00255     
00263     int getWidth() const
00264     { return getSize().width(); }
00265     
00273     int getHeight() const
00274     { return getSize().height(); }
00275         
00276     double getVar(const std::string & name) const;
00277     
00278     void setVar(const std::string & name, double val);
00279     
00289     VariableMap getVariableMap() const;
00290     
00293     const int getExifDateTime(struct tm* datetime) const;
00294 
00297     void unlinkRadialVigCorrCoeff ()
00298     {
00299         m_RadialVigCorrCoeff.removeLinks();
00300         m_VigCorrMode.removeLinks();
00301     }
00302     
00305     void unlinkRadialVigCorrCenterShift ()
00306     {
00307         m_RadialVigCorrCenterShift.removeLinks();
00308         m_VigCorrMode.removeLinks();
00309     }
00310     
00313     void unlinkEMoRParams ()
00314     {
00315         m_EMoRParams.removeLinks();
00316         m_ResponseType.removeLinks();
00317     }
00318     
00321     void linkRadialVigCorrCoeff (SrcPanoImage * target)
00322     {
00323         m_RadialVigCorrCoeff.linkWith(&(target->m_RadialVigCorrCoeff));
00324         m_VigCorrMode.linkWith(&(target->m_VigCorrMode));
00325     }
00326 
00329     void linkRadialVigCorrCenterShift (SrcPanoImage * target)
00330     {
00331         m_RadialVigCorrCenterShift.linkWith(&(target->m_RadialVigCorrCenterShift));
00332         m_VigCorrMode.linkWith(&(target->m_VigCorrMode));
00333     }
00334     
00337     void linkEMoRParams (SrcPanoImage * target)
00338     {
00339         m_EMoRParams.linkWith(&(target->m_EMoRParams));
00340         m_ResponseType.linkWith(&(target->m_ResponseType));
00341     }
00342     
00343     void linkStack (SrcPanoImage * target)
00344     { m_Stack.linkWith(&(target->m_Stack)); }
00345     
00347     bool checkImageSizeKnown();
00350     bool readEXIF();
00352     bool applyEXIFValues(bool applyEVValue=true);
00353     
00355     static double calcHFOV(SrcPanoImage::Projection proj, double fl, double crop, vigra::Size2D imageSize);
00356     
00358     static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize);
00359 
00361     static double calcCropFactor(SrcPanoImage::Projection proj, double hfov, double focalLength, vigra::Size2D imageSize);
00362 
00364     double calcExifExposureValue();
00365 
00367     void updateFocalLength(double newFocalLength);
00369     void updateCropFactor(double focalLength, double newCropFactor);
00370 
00374     bool readCropfactorFromDB();
00378     bool readProjectionFromDB();
00382     bool readDistortionFromDB();
00386     bool readVignettingFromDB();
00389     std::string getDBLensName() const;
00390 
00392     bool hasMasks() const;
00394     bool hasPositiveMasks() const;
00396     bool hasActiveMasks() const;
00398     void addMask(MaskPolygon newMask);
00400     void addActiveMask(MaskPolygon newMask);
00402     void clearActiveMasks();
00404     void changeMaskType(unsigned int index, HuginBase::MaskPolygon::MaskType newType);
00406     void deleteMask(unsigned int index);
00408     void deleteAllMasks();
00410     void printMaskLines(std::ostream &o, unsigned int newImgNr) const;
00412     bool isInsideMasks(vigra::Point2D p) const;
00413 
00414 private:
00415 
00417     bool trustExivOrientation();
00418 };
00419 
00420 typedef std::vector<SrcPanoImage> ImageVector;
00421 
00422 } // namespace
00423 
00424 #endif // PANOIMAGE_H

Generated on 29 Jul 2015 for Hugintrunk by  doxygen 1.4.7