Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin_base/panodata/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 #include <hugin_shared.h> 00034 #include <hugin_config.h> 00035 #include <iostream> 00036 #include <vector> 00037 #include <vigra/diff2d.hxx> 00038 00039 #include <hugin_utils/utils.h> 00040 #include <hugin_math/hugin_math.h> 00041 #include "PanoramaVariable.h" 00042 #include "PanoImage.h" 00043 #include "ImageVariable.h" 00044 #include "Mask.h" 00045 00046 #ifdef HUGIN_USE_EXIV2 00047 #include <exiv2/exif.hpp> 00048 #endif 00049 00050 namespace HuginBase { 00051 00052 class Panorama; 00053 00061 class IMPEX BaseSrcPanoImage 00062 { 00063 public: 00065 enum Projection { 00066 RECTILINEAR = 0, 00067 PANORAMIC = 1, 00068 CIRCULAR_FISHEYE = 2, 00069 FULL_FRAME_FISHEYE = 3, 00070 EQUIRECTANGULAR = 4, 00071 FISHEYE_ORTHOGRAPHIC = 8, 00072 FISHEYE_STEREOGRAPHIC = 10, 00073 FISHEYE_EQUISOLID = 21 00074 }; 00075 00077 enum CropMode { 00078 NO_CROP=0, 00079 CROP_RECTANGLE=1, 00080 CROP_CIRCLE=2 00081 }; 00082 00084 enum VignettingCorrMode { 00085 VIGCORR_NONE = 0, 00086 VIGCORR_RADIAL = 1, 00087 VIGCORR_FLATFIELD = 2, 00088 VIGCORR_DIV = 4 00089 }; 00090 00092 enum ResponseType { 00093 RESPONSE_EMOR=0, 00094 RESPONSE_LINEAR, 00095 RESPONSE_GAMMA, 00096 RESPONSE_FILE, 00097 RESPONSE_ICC 00098 }; 00099 00101 bool operator==(const BaseSrcPanoImage & other) const; 00102 00103 00104 public: 00106 BaseSrcPanoImage() 00107 { 00108 setDefaults(); 00109 } 00110 00111 virtual ~BaseSrcPanoImage() {}; 00112 00113 // property accessors 00114 public: 00115 // get[variable name] functions. Return the value stored in the ImageVariable. 00116 #define image_variable( name, type, default_value ) \ 00117 type get##name() const { return m_##name.getData(); } 00118 #include "image_variables.h" 00119 #undef image_variable 00120 00121 // get[variable name]IV functions. Return a const reference to the ImageVariable. 00122 #define image_variable( name, type, default_value ) \ 00123 const ImageVariable<type> & get##name##IV() const { return m_##name; } 00124 #include "image_variables.h" 00125 #undef image_variable 00126 00127 // set[variable name] functions 00128 #define image_variable( name, type, default_value ) \ 00129 void set##name(type data) { m_##name.setData(data); } 00130 #include "image_variables.h" 00131 #undef image_variable 00132 00133 /* The link[variable name] functions 00134 * Pass a pointer to another SrcPanoImg and the respective image variable 00135 * will be shared between the images. Afterwards, changing the variable with 00136 * set[variable name] on either image also sets the other image. 00137 */ 00138 #define image_variable( name, type, default_value ) \ 00139 void link##name (BaseSrcPanoImage * target) \ 00140 { m_##name.linkWith(&(target->m_##name)); } 00141 #include "image_variables.h" 00142 #undef image_variable 00143 00144 /* The unlink[variable name] functions 00145 * Unlinking a variable makes it unique to this image. Then changing it will 00146 * not affect the other images. 00147 */ 00148 #define image_variable( name, type, default_value ) \ 00149 void unlink##name () \ 00150 { m_##name.removeLinks(); } 00151 #include "image_variables.h" 00152 #undef image_variable 00153 00154 /* The [variable name]isLinked functions 00155 * Returns true if the variable has links, or false if it is independant. 00156 */ 00157 #define image_variable( name, type, default_value ) \ 00158 bool name##isLinked () const \ 00159 { return m_##name.isLinked(); } 00160 #include "image_variables.h" 00161 #undef image_variable 00162 00163 /* The [variable name]isLinkedWith functions 00164 * Returns true if the variable is linked with the equivalent variable in 00165 * the specified image, false otherwise. 00166 */ 00167 #define image_variable( name, type, default_value ) \ 00168 bool name##isLinkedWith (const BaseSrcPanoImage & image) const \ 00169 { return m_##name.isLinkedWith(&(image.m_##name)); } 00170 #include "image_variables.h" 00171 #undef image_variable 00172 00173 protected: 00175 void setDefaults(); 00176 00177 // the image variables m_[variable name] 00178 #define image_variable( name, type, default_value ) \ 00179 ImageVariable<type> m_##name; 00180 #include "image_variables.h" 00181 #undef image_variable 00182 }; 00183 00184 00192 class IMPEX SrcPanoImage : public BaseSrcPanoImage 00193 { 00194 public: 00196 SrcPanoImage() 00197 { 00198 setDefaults(); 00199 } 00200 00201 virtual ~SrcPanoImage() {}; 00202 public: 00207 SrcPanoImage(const std::string &filename) 00208 { 00209 setDefaults(); 00210 m_Filename = filename; 00211 double crop = 0; 00212 double fl = 0; 00213 readEXIF(fl, crop, true, true); 00214 }; 00215 00216 00217 public: 00222 void resize(const vigra::Size2D & size); 00223 00226 bool isInside(vigra::Point2D p, bool ignoreMasks=false) const; 00227 00229 bool horizontalWarpNeeded(); 00230 00231 // Accessors 00232 // These are either: 00233 // #- extra ones that are derived from image varibles, or 00234 // #- replacements where we need extra processing. 00235 public: 00236 bool getCorrectTCA() const; 00237 00243 void setCropMode(CropMode val); 00244 00249 void setSize(vigra::Size2D val); 00250 00251 hugin_utils::FDiff2D getRadialDistortionCenter() const; 00252 00253 hugin_utils::FDiff2D getRadialVigCorrCenter() const; 00254 00255 // these are linked to ExposureValue, which is done with the above. 00256 // exposure value is log2 of inverse exposure factor. 00257 double getExposure() const; 00258 void setExposure(const double & val); 00259 00260 00268 int getWidth() const 00269 { return getSize().width(); } 00270 00278 int getHeight() const 00279 { return getSize().height(); } 00280 00281 double getVar(const std::string & name) const; 00282 00283 void setVar(const std::string & name, double val); 00284 00294 VariableMap getVariableMap() const; 00295 00296 00302 ImageOptions getOptions() const; 00303 00308 void setOptions(const ImageOptions & opt); 00309 00310 00313 const int getExifDateTime(struct tm* datetime) const 00314 { return Exiv2::exifTime(m_ExifDate.getData().c_str(),datetime); } 00315 00318 void unlinkRadialVigCorrCoeff () 00319 { 00320 m_RadialVigCorrCoeff.removeLinks(); 00321 m_VigCorrMode.removeLinks(); 00322 } 00323 00326 void unlinkRadialVigCorrCenterShift () 00327 { 00328 m_RadialVigCorrCenterShift.removeLinks(); 00329 m_VigCorrMode.removeLinks(); 00330 } 00331 00334 void unlinkEMoRParams () 00335 { 00336 m_EMoRParams.removeLinks(); 00337 m_ResponseType.removeLinks(); 00338 } 00339 00342 void linkRadialVigCorrCoeff (SrcPanoImage * target) 00343 { 00344 m_RadialVigCorrCoeff.linkWith(&(target->m_RadialVigCorrCoeff)); 00345 m_VigCorrMode.linkWith(&(target->m_VigCorrMode)); 00346 } 00347 00350 void linkRadialVigCorrCenterShift (SrcPanoImage * target) 00351 { 00352 m_RadialVigCorrCenterShift.linkWith(&(target->m_RadialVigCorrCenterShift)); 00353 m_VigCorrMode.linkWith(&(target->m_VigCorrMode)); 00354 } 00355 00358 void linkEMoRParams (SrcPanoImage * target) 00359 { 00360 m_EMoRParams.linkWith(&(target->m_EMoRParams)); 00361 m_ResponseType.linkWith(&(target->m_ResponseType)); 00362 } 00363 00364 void linkStack (SrcPanoImage * target) 00365 { m_Stack.linkWith(&(target->m_Stack)); } 00366 00372 bool readEXIF(double & focalLength, double & cropFactor, bool applyEXIF, bool applyExposureValue); 00373 bool readEXIF(double & focalLength, double & cropFactor, double & eV, bool applyEXIF, bool applyExposureValue); 00374 00376 static double calcHFOV(SrcPanoImage::Projection proj, double fl, double crop, vigra::Size2D imageSize); 00377 00379 static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize); 00380 00382 static double calcCropFactor(SrcPanoImage::Projection proj, double hfov, double focalLength, vigra::Size2D imageSize); 00383 00385 void updateFocalLength(double newFocalLength); 00387 void updateCropFactor(double focalLength, double newCropFactor); 00388 00390 bool hasMasks() const; 00392 bool hasPositiveMasks() const; 00394 bool hasActiveMasks() const; 00396 void addMask(MaskPolygon newMask); 00398 void addActiveMask(MaskPolygon newMask); 00400 void clearActiveMasks(); 00402 void changeMaskType(unsigned int index, HuginBase::MaskPolygon::MaskType newType); 00404 void deleteMask(unsigned int index); 00406 void printMaskLines(std::ostream &o, unsigned int newImgNr) const; 00408 bool isInsideMasks(vigra::Point2D p) const; 00409 00410 private: 00411 00413 bool getExiv2Value(Exiv2::ExifData& exifData, std::string keyName, long & value); 00414 bool getExiv2Value(Exiv2::ExifData& exifData, std::string keyName, float & value); 00415 bool getExiv2Value(Exiv2::ExifData& exifData, std::string keyName, std::string & value); 00416 00418 bool trustExivOrientation(); 00419 }; 00420 00421 typedef std::vector<SrcPanoImage> ImageVector; 00422 00423 } // namespace 00424 00425 #endif // PANOIMAGE_H
1.3.9.1