ImageVariableTranslate.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _PANODATA_IMAGEVARIABLETRANSLATE_H
00025 #define _PANODATA_IMAGEVARIABLETRANSLATE_H
00026 
00027 namespace HuginBase
00028 {
00029 /* We define stuff to use the PTO codes i image_variables.h
00030  */
00041 class IMPEX PTOVariableConverterNoOp
00042 {
00043 public:
00051     inline static bool checkApplicability(const std::string name)
00052     {
00053         return false;
00054     }
00055     
00069     template <class T>
00070     inline static double getValueFromVariable(
00071                                         const std::string name,
00072                                         const ImageVariable<T> & var
00073                                       )
00074     {
00075         return 0;
00076     }
00077     
00088     template <class T>
00089     inline static void setValueFromVariable(
00090                                         const std::string name,
00091                                         ImageVariable<T> & var,
00092                                         const double value
00093                                     )
00094     {
00095     }
00096     
00104     template <class T>
00105     inline static void addToVariableMap(
00106                             const ImageVariable<T> & var,
00107                             VariableMap & map
00108                                 )
00109     {
00110     }
00111 };
00112 
00121 template <char code1, char code2 = '\0', char code3 = '\0', class T = double>
00122 class IMPEX PTOVariableConverterSingle
00123 {
00124 public:
00125     inline static bool checkApplicability(const std::string name)
00126     {
00127         static const char code[] = {code1, code2, code3, '\0'};
00128         return ((std::string)code) == name;
00129     }
00130     
00131     inline static double getValueFromVariable(const std::string name, const ImageVariable<T> & var)
00132     {
00133         return var.getData();
00134     }
00135     
00136     inline static void setValueFromVariable(const std::string name, ImageVariable<T> & var, const double value)
00137     {
00138         var.setData((T)value);
00139     }
00140     
00141     inline static void addToVariableMap(const ImageVariable<T> & var, VariableMap & map)
00142     {
00143         static const char code[] = {code1, code2, code3, '\0'};
00144         map.insert(std::make_pair(code, Variable(code, (double)var.getData())));
00145     }
00146 };
00147 
00148 
00161 template <char base_code, class T = double, size_t size = 4>
00162 class IMPEX PTOVariableConverterVectorChar
00163 {
00164 public:
00165     inline static bool checkApplicability(const std::string name)
00166     {
00167         return name.size() == 2 && name[0] == base_code && name[1] >= 'a' && name[1] < 'a' + char(size);
00168     }
00169     
00170     inline static double getValueFromVariable(const std::string name, const ImageVariable<std::vector<T> > & var)
00171     {
00172         return var.getData()[name[1]-'a'];
00173     }
00174     
00175     inline static void setValueFromVariable(const std::string name, ImageVariable<std::vector<T> > & var, const double value)
00176     {
00177         std::vector<T> temp = var.getData();
00178         temp[name[1]-'a'] = value;
00179         var.setData(temp);
00180     }
00181     
00182     inline static void addToVariableMap(const ImageVariable<std::vector<T> > & var, VariableMap & map)
00183     {
00184         char s[3] = {base_code, 'a', '\0'};
00185         for (size_t index = 0; index < size; index++, s[1]++)
00186         {
00187             map.insert(std::make_pair(s, Variable(s, (double)var.getData()[index])));
00188         }
00189     }
00190 };
00191 
00202 template <class T = double, size_t size = 3>
00203 class IMPEX PTOVariableConverterVector
00204 {
00205 public:
00206     inline static bool checkApplicability(const std::string name)
00207     {
00208         return name[0] >= 'a' && name[0] < 'a' + char(size);
00209     }
00210     
00211     inline static double getValueFromVariable(const std::string name, const ImageVariable<std::vector<T> > & var)
00212     {
00213         return var.getData()[name[0]-'a'];
00214     }
00215     
00216     inline static void setValueFromVariable(const std::string name, ImageVariable<std::vector<T> > & var, const double value)
00217     {
00218         std::vector<T> temp = var.getData();
00219         temp[name[0]-'a'] = value;
00220         var.setData(temp);
00221     }
00222     
00223     inline static void addToVariableMap(const ImageVariable<std::vector<T> > & var, VariableMap & map)
00224     {
00225         char s[] = "a";
00226         for (size_t index = 0; index < size; index++, s[0]++)
00227         {
00228             map.insert(std::make_pair(s, Variable(s, (double)var.getData()[index])));
00229         }
00230     }
00231 };
00232 
00240 template <char code_x1, char code_y1, char code_x2 = '\0', char code_y2 = '\0'>
00241 class IMPEX PTOVariableConverterFDiff2D
00242 {
00243 public:
00244     inline static bool checkApplicability(const std::string name)
00245     {
00246         static const char code_x[] = {code_x1, code_x2, '\0'};
00247         static const char code_y[] = {code_y1, code_y2, '\0'};
00248         return name == (std::string) code_x || name == (std::string) code_y;
00249     }
00250     
00251     inline static double getValueFromVariable(const std::string name, const ImageVariable<hugin_utils::FDiff2D> & var)
00252     {
00253         static const char code_x[] = {code_x1, code_x2, '\0'};
00254         return name == (std::string) code_x ? var.getData().x : var.getData().y;
00255     }
00256     
00257     inline static void setValueFromVariable(const std::string name, ImageVariable<hugin_utils::FDiff2D> & var, const double value)
00258     {
00259         hugin_utils::FDiff2D temp = var.getData();
00260         static const char code_x[] = {code_x1, code_x2, '\0'};
00261         (name == (std::string)code_x ? temp.x : temp.y) = value;
00262         var.setData(temp);
00263     }
00264     
00265     inline static void addToVariableMap(const ImageVariable<hugin_utils::FDiff2D> & var, VariableMap & map)
00266     {
00267         static const char s_x[] = {code_x1, code_x2, '\0'};
00268         static const char s_y[] = {code_y1, code_y2, '\0'};
00269         map.insert(std::make_pair(s_x, Variable(s_x, var.getData().x)));
00270         map.insert(std::make_pair(s_y, Variable(s_y, var.getData().y)));
00271     }
00272 };
00273 
00274 // Now we can define a type to use for every PanoramaVariable.
00275 // We should make sure that any given code is only applicable to one of these.
00277 
00279 typedef PTOVariableConverterNoOp PTOVariableConverterForFilename;
00280 typedef PTOVariableConverterNoOp PTOVariableConverterForSize;
00281 //typedef PTOVariableConverterSingle<'f','\0', '\0', SrcPanoImage::Projection> PTOVariableConverterForProjection;
00282 typedef PTOVariableConverterNoOp PTOVariableConverterForProjection;
00283 typedef PTOVariableConverterSingle<'v'> PTOVariableConverterForHFOV;
00284 
00285 typedef PTOVariableConverterNoOp PTOVariableConverterForResponseType;
00286 typedef PTOVariableConverterVectorChar<'R', float, 5> PTOVariableConverterForEMoRParams;
00287 typedef PTOVariableConverterSingle<'E', 'e', 'v'> PTOVariableConverterForExposureValue;
00288 typedef PTOVariableConverterNoOp PTOVariableConverterForGamma ;
00289 typedef PTOVariableConverterSingle<'E', 'r'>  PTOVariableConverterForWhiteBalanceRed;
00290 typedef PTOVariableConverterSingle<'E', 'b'>  PTOVariableConverterForWhiteBalanceBlue;
00291 
00292 typedef PTOVariableConverterSingle<'r'> PTOVariableConverterForRoll;
00293 typedef PTOVariableConverterSingle<'p'> PTOVariableConverterForPitch;
00294 typedef PTOVariableConverterSingle<'y'> PTOVariableConverterForYaw;
00295 
00296 typedef PTOVariableConverterSingle<'T','r','X'> PTOVariableConverterForX;
00297 typedef PTOVariableConverterSingle<'T','r','Y'> PTOVariableConverterForY;
00298 typedef PTOVariableConverterSingle<'T','r','Z'> PTOVariableConverterForZ;
00299 typedef PTOVariableConverterSingle<'T','p','y'> PTOVariableConverterForTranslationPlaneYaw;
00300 typedef PTOVariableConverterSingle<'T','p','p'> PTOVariableConverterForTranslationPlanePitch;
00301 
00302 typedef PTOVariableConverterSingle<'j'> PTOVariableConverterForStack;
00303 
00304 typedef PTOVariableConverterVector<double, 3> PTOVariableConverterForRadialDistortion;
00305 typedef PTOVariableConverterNoOp PTOVariableConverterForRadialDistortionRed;
00306 typedef PTOVariableConverterNoOp PTOVariableConverterForRadialDistortionBlue;
00307 typedef PTOVariableConverterFDiff2D<'d', 'e'> PTOVariableConverterForRadialDistortionCenterShift;
00308 typedef PTOVariableConverterFDiff2D<'g', 't'> PTOVariableConverterForShear;
00309 
00310 typedef PTOVariableConverterNoOp PTOVariableConverterForCropMode;
00312 typedef PTOVariableConverterNoOp PTOVariableConverterForCropRect;
00313 typedef PTOVariableConverterNoOp PTOVariableConverterForAutoCenterCrop;
00314 
00316 typedef PTOVariableConverterNoOp PTOVariableConverterForFlatfieldFilename;
00317 //typedef PTOVariableConverterSingle<'V', 'm', '\0', int> PTOVariableConverterForVigCorrMode;
00318 typedef PTOVariableConverterNoOp PTOVariableConverterForVigCorrMode;
00319 typedef PTOVariableConverterVectorChar<'V', double, 4> PTOVariableConverterForRadialVigCorrCoeff;
00320 typedef PTOVariableConverterFDiff2D<'V','V', 'x','y'> PTOVariableConverterForRadialVigCorrCenterShift;
00321 
00322 typedef PTOVariableConverterNoOp PTOVariableConverterForExifModel;
00323 typedef PTOVariableConverterNoOp PTOVariableConverterForExifMake;
00324 typedef PTOVariableConverterNoOp PTOVariableConverterForExifLens;
00325 typedef PTOVariableConverterNoOp PTOVariableConverterForExifCropFactor;
00326 typedef PTOVariableConverterNoOp PTOVariableConverterForExifFocalLength;
00327 typedef PTOVariableConverterNoOp PTOVariableConverterForExifOrientation;
00328 typedef PTOVariableConverterNoOp PTOVariableConverterForExifAperture;
00329 typedef PTOVariableConverterNoOp PTOVariableConverterForExifISO;
00330 typedef PTOVariableConverterNoOp PTOVariableConverterForExifDistance;
00331 typedef PTOVariableConverterNoOp PTOVariableConverterForExifFocalLength35;
00332 typedef PTOVariableConverterNoOp PTOVariableConverterForExifExposureTime;
00333 typedef PTOVariableConverterNoOp PTOVariableConverterForExifDate;
00334 typedef PTOVariableConverterNoOp PTOVariableConverterForExifExposureMode;
00335 
00336 #if 0
00337 //panotools variables, currently not used
00338 typedef PTOVariableConverterNoOp PTOVariableConverterForFeatherWidth;
00339 typedef PTOVariableConverterNoOp PTOVariableConverterForMorph;
00340 #endif
00341 typedef PTOVariableConverterNoOp PTOVariableConverterForMasks;
00342 typedef PTOVariableConverterNoOp PTOVariableConverterForActiveMasks;
00343 typedef PTOVariableConverterNoOp PTOVariableConverterForActive;
00344 typedef PTOVariableConverterNoOp PTOVariableConverterForLensNr;
00345 }
00346 
00347 #endif

Generated on 5 Dec 2014 for Hugintrunk by  doxygen 1.4.7