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 
00050 #ifdef HUGIN_USE_EXIV2
00051 #include <exiv2/exif.hpp>
00052 #endif
00053 
00054 #endif // _HSI_IGNORE_SECTION
00055 
00056 namespace HuginBase {
00057 
00058 class Panorama;
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         successfullEXIFread=false;
00207     }
00208     
00209     virtual ~SrcPanoImage() {};
00210 public:
00215     SrcPanoImage(const std::string &filename)
00216     {
00217         setDefaults();
00218         m_Filename = filename;
00219         double crop = 0;
00220         double fl = 0;
00221         successfullEXIFread=readEXIF(fl, crop, true, true);
00222     };
00224     const bool hasEXIFread() const {return successfullEXIFread;};
00225     
00226     
00227 public:
00232     void resize(const vigra::Size2D & size);
00233 
00236     bool isInside(vigra::Point2D p, bool ignoreMasks=false) const;
00237 
00239     bool horizontalWarpNeeded();
00240 
00241     // Accessors
00242     // These are either:
00243     // #- extra ones that are derived from image varibles, or
00244     // #- replacements where we need extra processing.
00245 public:
00246     bool getCorrectTCA() const;
00247     
00253     void setCropMode(CropMode val);
00254 
00256     bool isCircularCrop() const;
00257 
00262     void setSize(vigra::Size2D val);
00263     
00264     hugin_utils::FDiff2D getRadialDistortionCenter() const;
00265     
00266     hugin_utils::FDiff2D getRadialVigCorrCenter() const;
00267     
00268     // these are linked to ExposureValue, which is done with the above.
00269     // exposure value  is log2 of inverse exposure factor.
00270     double getExposure() const;
00271     void setExposure(const double & val);
00272     
00273     
00281     int getWidth() const
00282     { return getSize().width(); }
00283     
00291     int getHeight() const
00292     { return getSize().height(); }
00293         
00294     double getVar(const std::string & name) const;
00295     
00296     void setVar(const std::string & name, double val);
00297     
00307     VariableMap getVariableMap() const;
00308     
00311     const int getExifDateTime(struct tm* datetime) const;
00312 
00315     void unlinkRadialVigCorrCoeff ()
00316     {
00317         m_RadialVigCorrCoeff.removeLinks();
00318         m_VigCorrMode.removeLinks();
00319     }
00320     
00323     void unlinkRadialVigCorrCenterShift ()
00324     {
00325         m_RadialVigCorrCenterShift.removeLinks();
00326         m_VigCorrMode.removeLinks();
00327     }
00328     
00331     void unlinkEMoRParams ()
00332     {
00333         m_EMoRParams.removeLinks();
00334         m_ResponseType.removeLinks();
00335     }
00336     
00339     void linkRadialVigCorrCoeff (SrcPanoImage * target)
00340     {
00341         m_RadialVigCorrCoeff.linkWith(&(target->m_RadialVigCorrCoeff));
00342         m_VigCorrMode.linkWith(&(target->m_VigCorrMode));
00343     }
00344 
00347     void linkRadialVigCorrCenterShift (SrcPanoImage * target)
00348     {
00349         m_RadialVigCorrCenterShift.linkWith(&(target->m_RadialVigCorrCenterShift));
00350         m_VigCorrMode.linkWith(&(target->m_VigCorrMode));
00351     }
00352     
00355     void linkEMoRParams (SrcPanoImage * target)
00356     {
00357         m_EMoRParams.linkWith(&(target->m_EMoRParams));
00358         m_ResponseType.linkWith(&(target->m_ResponseType));
00359     }
00360     
00361     void linkStack (SrcPanoImage * target)
00362     { m_Stack.linkWith(&(target->m_Stack)); }
00363     
00369     bool readEXIF(double & focalLength, double & cropFactor, bool applyEXIF, bool applyExposureValue);
00370     bool readEXIF(double & focalLength, double & cropFactor, double & eV, bool applyEXIF, bool applyExposureValue);
00371     
00373     static double calcHFOV(SrcPanoImage::Projection proj, double fl, double crop, vigra::Size2D imageSize);
00374     
00376     static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize);
00377 
00379     static double calcCropFactor(SrcPanoImage::Projection proj, double hfov, double focalLength, vigra::Size2D imageSize);
00380 
00382     void updateFocalLength(double newFocalLength);
00384     void updateCropFactor(double focalLength, double newCropFactor);
00385 
00389     bool readCropfactorFromDB();
00393     bool readProjectionFromDB();
00397     bool readDistortionFromDB();
00401     bool readVignettingFromDB();
00402 
00404     bool hasMasks() const;
00406     bool hasPositiveMasks() const;
00408     bool hasActiveMasks() const;
00410     void addMask(MaskPolygon newMask);
00412     void addActiveMask(MaskPolygon newMask);
00414     void clearActiveMasks();
00416     void changeMaskType(unsigned int index, HuginBase::MaskPolygon::MaskType newType);
00418     void deleteMask(unsigned int index);
00420     void deleteAllMasks();
00422     void printMaskLines(std::ostream &o, unsigned int newImgNr) const;
00424     bool isInsideMasks(vigra::Point2D p) const;
00425 
00426 private:
00427 
00429     bool getExiv2Value(Exiv2::ExifData& exifData, std::string keyName, long & value);
00430     bool getExiv2Value(Exiv2::ExifData& exifData, std::string keyName, float & value);
00431     bool getExiv2Value(Exiv2::ExifData& exifData, std::string keyName, std::string & value);
00432     bool getExiv2Value(Exiv2::ExifData& exifData, uint16_t tagID, std::string groupName, std::string & value);
00433 
00435     bool trustExivOrientation();
00436     bool successfullEXIFread;
00437 };
00438 
00439 typedef std::vector<SrcPanoImage> ImageVector;
00440 
00441 } // namespace
00442 
00443 #endif // PANOIMAGE_H

Generated on Thu Jul 31 01:25:42 2014 for Hugintrunk by  doxygen 1.3.9.1