[75c70a]: src / hugin_base / panodata / ImageVariableTranslate.h Maximize Restore History

Download this file

ImageVariableTranslate.h    351 lines (314 with data), 15.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// -*- c-basic-offset: 4 -*-
/** @file ImageVariableTranslate.h
*
* @brief Convenience functions for SrcPanoImage to use on the image variables.
*
* @author James Legg
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef _PANODATA_IMAGEVARIABLETRANSLATE_H
#define _PANODATA_IMAGEVARIABLETRANSLATE_H
namespace HuginBase
{
/* We define stuff to use the PTO codes i image_variables.h
*/
/** Parent class to anything that aids conversion between PTO file variables and
* the image variables of SrcPanoImg.
*
* Although this class doesn't really do anything itself, it will be used when
* the variable in SrcPanoImg is not written to a file.
*
* We derive children of these to handle more specific cases, which are usually
* templates to handle similar things (e.g. all vectors)
* We then typedef to make a convertor for each variable in SrcPanoImg.
*/
class IMPEX PTOVariableConverterNoOp
{
public:
/** Check if a given pto format variable name applies to this image
* variable.
*
* @return true if we can handle this variable name, false otherwise.
* @param name The code used to identify the variable in the PTO file
* format. For example "Eev".
*/
inline static bool checkApplicability(const std::string name)
{
return false;
}
/** Get a pto format variable's value, given its name and a reference to the
* variable in SrcPanoImg.
*
* It is a precondition of this function that the checkApplicability
* function returns true when passed name.
*
* @return 0 in this case, but child objects should return the value to
* write in a pto file for this variable.
* @param name The code used to identify the variable in the PTO file
* format. For example "Eev".
* @param var Some ImageVariable used by SrcPanoImg to hold this variable.
* @tparam T the template parameter of the ImageVariable var.
*/
template <class T>
inline static double getValueFromVariable(
const std::string name,
const ImageVariable<T> & var
)
{
return 0;
}
/** Set a ImageVariable in SrcPanoImg given the pto format variable.
*
* It is a precondition of this function that the checkApplicability
* function returns true when passed name.
*
* @param name The name used in the PTO format image variable.
* @param var The image variable used in SrcPanoImg to change.
* @param value The value specified in the PTO format image variable.
* @tparam T The template parameter of ImageVariable var.
*/
template <class T>
inline static void setValueFromVariable(
const std::string name,
ImageVariable<T> & var,
const double value
)
{
}
/** Add all PTO format variables specifed by an image variable in SrcPanoImg
* to a VariableMap.
*
* @param var The image variable used in SrcPanoImg to get values from.
* @param map The VariableMap
* @tparam T The template parameter of ImageVariable var.
*/
template <class T>
inline static void addToVariableMap(
const ImageVariable<T> & var,
VariableMap & map
)
{
}
};
/** Object to group conversion functions for PTO format variables of up to three
* characters representing a single variable in SrcPanoImg.
* @tparam code1 1st character of identifier used in PTO file format.
* @tparam code2 2nd character of identifier used in PTO file format (or '/0').
* @tparam code3 3rd character of identifier used in PTO file format (or '/0').
* @tparam T type used in the ImageVariable. Should really be double, but some
* are small integers or enumerations.
*/
template <char code1, char code2 = '\0', char code3 = '\0', class T = double>
class IMPEX PTOVariableConverterSingle
{
public:
inline static bool checkApplicability(const std::string name)
{
static const char code[] = {code1, code2, code3, '\0'};
return ((std::string)code) == name;
}
inline static double getValueFromVariable(const std::string name, const ImageVariable<T> & var)
{
return var.getData();
}
inline static void setValueFromVariable(const std::string name, ImageVariable<T> & var, const double value)
{
var.setData((T)value);
}
inline static void addToVariableMap(const ImageVariable<T> & var, VariableMap & map)
{
static const char code[] = {code1, code2, code3, '\0'};
map.insert(std::make_pair(code, Variable(code, (double)var.getData())));
}
};
/** Object to group conversion functions for PTO format variables representing
* a std::vector variable in SrcPanoImg, using an identifying first character.
*
* It can only represent PTO format variables that can be expressed as some
* constant character followed by a index character, where the first element of
* the vector has the index character 'a' and the others follow in order.
*
* @tparam base_code string used in PTO file format upto the the character.
* @tparam T type used in SrcImageVariable. Should really be double, but could
* be float or something.
* @tparam size The number of letters and the size of the vector.
*/
template <char base_code, class T = double, size_t size = 4>
class IMPEX PTOVariableConverterVectorChar
{
public:
inline static bool checkApplicability(const std::string name)
{
return name.size() == 2 && name[0] == base_code && name[1] >= 'a' && name[1] < 'a' + char(size);
}
inline static double getValueFromVariable(const std::string name, const ImageVariable<std::vector<T> > & var)
{
return var.getData()[name[1]-'a'];
}
inline static void setValueFromVariable(const std::string name, ImageVariable<std::vector<T> > & var, const double value)
{
std::vector<T> temp = var.getData();
temp[name[1]-'a'] = value;
var.setData(temp);
}
inline static void addToVariableMap(const ImageVariable<std::vector<T> > & var, VariableMap & map)
{
char s[3] = {base_code, 'a', '\0'};
for (size_t index = 0; index < size; index++, s[1]++)
{
map.insert(std::make_pair(s, Variable(s, (double)var.getData()[index])));
}
}
};
/** Object to group conversion functions for PTO format variables representing
* a std::vector variable in SrcPanoImg, using characters stating from 'a'.
*
* This can only be used for one variable, and it is RadialDistortion.
*
* @tparam base_code string used in PTO file format upto the the character.
* @tparam T type used in the ImageVariable. Should really be double, but could
* be float or something.
* @tparam size The number of letters and the size of the vector.
*/
template <class T = double, size_t size = 3>
class IMPEX PTOVariableConverterVector
{
public:
inline static bool checkApplicability(const std::string name)
{
return name[0] >= 'a' && name[0] < 'a' + char(size);
}
inline static double getValueFromVariable(const std::string name, const ImageVariable<std::vector<T> > & var)
{
return var.getData()[name[0]-'a'];
}
inline static void setValueFromVariable(const std::string name, ImageVariable<std::vector<T> > & var, const double value)
{
std::vector<T> temp = var.getData();
temp[name[0]-'a'] = value;
var.setData(temp);
}
inline static void addToVariableMap(const ImageVariable<std::vector<T> > & var, VariableMap & map)
{
char s[] = "a";
for (size_t index = 0; index < size; index++, s[0]++)
{
map.insert(std::make_pair(s, Variable(s, (double)var.getData()[index])));
}
}
};
/** Object to group conversion functions for PTO format variables representing
* a hugin_utils::FDiff2D variable in SrcPanoImg. Each element must have a pto
* file format code that is 1 or 2 characters in length.
*
* @tparam code_x The PTO format code that matches the x memeber in the FDiff2D.
* @tparam code_y The PTO format code that matches the y memeber in the FDiff2D.
*/
template <char code_x1, char code_y1, char code_x2 = '\0', char code_y2 = '\0'>
class IMPEX PTOVariableConverterFDiff2D
{
public:
inline static bool checkApplicability(const std::string name)
{
static const char code_x[] = {code_x1, code_x2, '\0'};
static const char code_y[] = {code_y1, code_y2, '\0'};
return name == (std::string) code_x || name == (std::string) code_y;
}
inline static double getValueFromVariable(const std::string name, const ImageVariable<hugin_utils::FDiff2D> & var)
{
static const char code_x[] = {code_x1, code_x2, '\0'};
return name == (std::string) code_x ? var.getData().x : var.getData().y;
}
inline static void setValueFromVariable(const std::string name, ImageVariable<hugin_utils::FDiff2D> & var, const double value)
{
hugin_utils::FDiff2D temp = var.getData();
static const char code_x[] = {code_x1, code_x2, '\0'};
(name == (std::string)code_x ? temp.x : temp.y) = value;
var.setData(temp);
}
inline static void addToVariableMap(const ImageVariable<hugin_utils::FDiff2D> & var, VariableMap & map)
{
static const char s_x[] = {code_x1, code_x2, '\0'};
static const char s_y[] = {code_y1, code_y2, '\0'};
map.insert(std::make_pair(s_x, Variable(s_x, var.getData().x)));
map.insert(std::make_pair(s_y, Variable(s_y, var.getData().y)));
}
};
// Now we can define a type to use for every PanoramaVariable.
// We should make sure that any given code is only applicable to one of these.
/// @see image_variables.h
/// @todo This could be n, but it is a string, not a double.
typedef PTOVariableConverterNoOp PTOVariableConverterForFilename;
typedef PTOVariableConverterNoOp PTOVariableConverterForSize;
//typedef PTOVariableConverterSingle<'f','\0', '\0', SrcPanoImage::Projection> PTOVariableConverterForProjection;
typedef PTOVariableConverterNoOp PTOVariableConverterForProjection;
typedef PTOVariableConverterSingle<'v'> PTOVariableConverterForHFOV;
typedef PTOVariableConverterNoOp PTOVariableConverterForResponseType;
typedef PTOVariableConverterVectorChar<'R', float, 5> PTOVariableConverterForEMoRParams;
typedef PTOVariableConverterSingle<'E', 'e', 'v'> PTOVariableConverterForExposureValue;
typedef PTOVariableConverterNoOp PTOVariableConverterForGamma ;
typedef PTOVariableConverterSingle<'E', 'r'> PTOVariableConverterForWhiteBalanceRed;
typedef PTOVariableConverterSingle<'E', 'b'> PTOVariableConverterForWhiteBalanceBlue;
typedef PTOVariableConverterSingle<'r'> PTOVariableConverterForRoll;
typedef PTOVariableConverterSingle<'p'> PTOVariableConverterForPitch;
typedef PTOVariableConverterSingle<'y'> PTOVariableConverterForYaw;
typedef PTOVariableConverterSingle<'T','r','X'> PTOVariableConverterForX;
typedef PTOVariableConverterSingle<'T','r','Y'> PTOVariableConverterForY;
typedef PTOVariableConverterSingle<'T','r','Z'> PTOVariableConverterForZ;
typedef PTOVariableConverterSingle<'T','e','0'> PTOVariableConverterForSpin;
typedef PTOVariableConverterSingle<'T','e','1'> PTOVariableConverterForTilt;
typedef PTOVariableConverterSingle<'T','e','2'> PTOVariableConverterForRotate;
typedef PTOVariableConverterSingle<'j'> PTOVariableConverterForStack;
typedef PTOVariableConverterVector<double, 3> PTOVariableConverterForRadialDistortion;
typedef PTOVariableConverterNoOp PTOVariableConverterForRadialDistortionRed;
typedef PTOVariableConverterNoOp PTOVariableConverterForRadialDistortionBlue;
typedef PTOVariableConverterFDiff2D<'d', 'e'> PTOVariableConverterForRadialDistortionCenterShift;
typedef PTOVariableConverterFDiff2D<'g', 't'> PTOVariableConverterForShear;
typedef PTOVariableConverterNoOp PTOVariableConverterForCropMode;
/// @todo This could be S, but it is 4 integers in the form a,b,c,d -hence not a double.
typedef PTOVariableConverterNoOp PTOVariableConverterForCropRect;
typedef PTOVariableConverterNoOp PTOVariableConverterForAutoCenterCrop;
/// @todo This could be Vf, but it is a string, not a double.
typedef PTOVariableConverterNoOp PTOVariableConverterForFlatfieldFilename;
//typedef PTOVariableConverterSingle<'V', 'm', '\0', int> PTOVariableConverterForVigCorrMode;
typedef PTOVariableConverterNoOp PTOVariableConverterForVigCorrMode;
typedef PTOVariableConverterVectorChar<'V', double, 4> PTOVariableConverterForRadialVigCorrCoeff;
typedef PTOVariableConverterFDiff2D<'V','V', 'x','y'> PTOVariableConverterForRadialVigCorrCenterShift;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifModel;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifMake;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifLens;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifCropFactor;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifFocalLength;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifOrientation;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifAperture;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifISO;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifDistance;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifFocalLength35;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifExposureTime;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifDate;
typedef PTOVariableConverterNoOp PTOVariableConverterForExifExposureMode;
#if 0
//panotools variables, currently not used
typedef PTOVariableConverterNoOp PTOVariableConverterForFeatherWidth;
typedef PTOVariableConverterNoOp PTOVariableConverterForMorph;
#endif
typedef PTOVariableConverterNoOp PTOVariableConverterForMasks;
typedef PTOVariableConverterNoOp PTOVariableConverterForActiveMasks;
typedef PTOVariableConverterNoOp PTOVariableConverterForActive;
typedef PTOVariableConverterNoOp PTOVariableConverterForLensNr;
}
#endif