[e2185a]: src / hugin_base / panodata / SrcPanoImage.h  Maximize  Restore  History

Download this file

418 lines (352 with data), 14.2 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
// -*- c-basic-offset: 4 -*-
/** @file SrcPanoImage.h
*
* @brief
*
* @author Pablo d'Angelo <pablo.dangelo@web.de>
* James Legg
*
* !! from PanoImage.h 1970
*
* $Id$
*
* 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_SRCPANOIMAGE_H
#define _PANODATA_SRCPANOIMAGE_H
// if this file is preprocessed for SWIG, we want to ignore
// all the header inclusions that follow:
#ifndef _HSI_IGNORE_SECTION
#include <hugin_shared.h>
#include <hugin_config.h>
#include <iostream>
#include <vector>
#include <vigra/diff2d.hxx>
#include <hugin_utils/utils.h>
#include <hugin_math/hugin_math.h>
#include "PanoramaVariable.h"
#include "ImageVariable.h"
#include "Mask.h"
#endif // _HSI_IGNORE_SECTION
namespace HuginBase {
class Panorama;
/** Base class containing all the variables, but missing some of the other
* important functions and with some daft accessors.
*
* Used for lazy metaprogramming, we include image_variables.h several times
* with different defintions of image_variable to get all the repetitive bits
* out the way. This should reduce typos and cut and paste errors.
*/
class IMPEX BaseSrcPanoImage
{
public:
///
enum Projection {
RECTILINEAR = 0,
PANORAMIC = 1,
CIRCULAR_FISHEYE = 2,
FULL_FRAME_FISHEYE = 3,
EQUIRECTANGULAR = 4,
FISHEYE_ORTHOGRAPHIC = 8,
FISHEYE_STEREOGRAPHIC = 10,
FISHEYE_EQUISOLID = 21,
FISHEYE_THOBY = 20
};
///
enum CropMode {
NO_CROP=0,
CROP_RECTANGLE=1,
CROP_CIRCLE=2
};
/// vignetting correction mode (bitflags, no real enum)
enum VignettingCorrMode {
VIGCORR_NONE = 0, ///< no vignetting correction
VIGCORR_RADIAL = 1, ///< radial vignetting correction
VIGCORR_FLATFIELD = 2, ///< flatfield correction
VIGCORR_DIV = 4 ///< correct by division.
};
///
enum ResponseType {
RESPONSE_EMOR=0, ///< empirical model of response
RESPONSE_LINEAR, ///< linear response
RESPONSE_GAMMA, ///< a simple gamma response curve
RESPONSE_FILE, ///< load response curve from file (not implemented yet)
RESPONSE_ICC ///< use ICC for transformation into linear data (not implemented yet)
};
/// Check that the variables match.
bool operator==(const BaseSrcPanoImage & other) const;
public:
///
BaseSrcPanoImage()
{
setDefaults();
}
virtual ~BaseSrcPanoImage() {};
// property accessors
public:
// get[variable name] functions. Return the value stored in the ImageVariable.
#define image_variable( name, type, default_value ) \
type get##name() const { return m_##name.getData(); }
#include "image_variables.h"
#undef image_variable
// get[variable name]IV functions. Return a const reference to the ImageVariable.
#define image_variable( name, type, default_value ) \
const ImageVariable<type > & get##name##IV() const { return m_##name; }
#include "image_variables.h"
#undef image_variable
// set[variable name] functions
#define image_variable( name, type, default_value ) \
void set##name(type data) { m_##name.setData(data); }
#include "image_variables.h"
#undef image_variable
/* The link[variable name] functions
* Pass a pointer to another SrcPanoImg and the respective image variable
* will be shared between the images. Afterwards, changing the variable with
* set[variable name] on either image also sets the other image.
*/
#define image_variable( name, type, default_value ) \
void link##name (BaseSrcPanoImage * target) \
{ m_##name.linkWith(&(target->m_##name)); }
#include "image_variables.h"
#undef image_variable
/* The unlink[variable name] functions
* Unlinking a variable makes it unique to this image. Then changing it will
* not affect the other images.
*/
#define image_variable( name, type, default_value ) \
void unlink##name () \
{ m_##name.removeLinks(); }
#include "image_variables.h"
#undef image_variable
/* The [variable name]isLinked functions
* Returns true if the variable has links, or false if it is independant.
*/
#define image_variable( name, type, default_value ) \
bool name##isLinked () const \
{ return m_##name.isLinked(); }
#include "image_variables.h"
#undef image_variable
/* The [variable name]isLinkedWith functions
* Returns true if the variable is linked with the equivalent variable in
* the specified image, false otherwise.
*/
#define image_variable( name, type, default_value ) \
bool name##isLinkedWith (const BaseSrcPanoImage & image) const \
{ return m_##name.isLinkedWith(&(image.m_##name)); }
#include "image_variables.h"
#undef image_variable
protected:
///
void setDefaults();
// the image variables m_[variable name]
#define image_variable( name, type, default_value ) \
ImageVariable<type > m_##name;
#include "image_variables.h"
#undef image_variable
};
/** All variables of a source image.
*
* In the long term, this simplified class will replace
* PanoImage and Image options and the variables array.
* All image variables are stored in this class, regardless of what the
* variable is attached to (lens, sensor, position).
*/
class IMPEX SrcPanoImage : public BaseSrcPanoImage
{
public:
///
SrcPanoImage()
{
setDefaults();
}
virtual ~SrcPanoImage() {};
public:
/** "resize" image,
* adjusts all distortion coefficients for usage with a source image
* of size @p size
*/
void resize(const vigra::Size2D & size);
/** check if a coordinate is inside the source image
*/
bool isInside(vigra::Point2D p, bool ignoreMasks=false) const;
///
bool horizontalWarpNeeded();
// Accessors
// These are either:
// #- extra ones that are derived from image varibles, or
// #- replacements where we need extra processing.
public:
bool getCorrectTCA() const;
/** Set the crop mode.
*
* This sets the cropping region to the entire image when set to NO_CROP,
* unlike the lazy metaprogrammed equivalent in BaseSrcPanoImage.
*/
void setCropMode(CropMode val);
/** returns true, if projection requires cicular crop */
bool isCircularCrop() const;
/** Set the image size in pixels
*
* If we aren't cropping the image, set the size to the entire image
*/
void setSize(vigra::Size2D val);
hugin_utils::FDiff2D getRadialDistortionCenter() const;
hugin_utils::FDiff2D getRadialVigCorrCenter() const;
// these are linked to ExposureValue, which is done with the above.
// exposure value is log2 of inverse exposure factor.
double getExposure() const;
void setExposure(const double & val);
/** Get the width of the image in pixels.
*
* Should not be used, use getSize().width() instead.
* This is here for compatiblity with PnaoImage, but should be removed.
*
* @todo replace all calls to getWidth() with getSize().width().
*/
int getWidth() const
{ return getSize().width(); }
/** Get the height of the image in pixels.
*
* Should not be used, use getSize().height() instead.
* This is here for compatiblity with PnaoImage, but should be removed.
*
* @todo replace all calls to getHeight() with getSize().height().
*/
int getHeight() const
{ return getSize().height(); }
double getVar(const std::string & name) const;
void setVar(const std::string & name, double val);
/** Return all the image variables in a variable map
*
* Returns a map of all the variables for this image. It is adivisable to
* use the individual getX functions where apropriate instead.
*
* @todo remove this infavour of the individual get*() functions. This
* creates a map of all the variables, regardless of which ones are actually
* needed, every time it is called.
*/
VariableMap getVariableMap() const;
/** try to convert Exif date time string to struct tm
* @return 0, if conversion was sucessfull */
const int getExifDateTime(struct tm* datetime) const;
/** unlinking vignetting parameters should unlink the vignetting correction mode
*/
void unlinkRadialVigCorrCoeff ()
{
m_RadialVigCorrCoeff.removeLinks();
m_VigCorrMode.removeLinks();
}
/** unlinking vignetting parameters should unlink the vignetting correction mode
*/
void unlinkRadialVigCorrCenterShift ()
{
m_RadialVigCorrCenterShift.removeLinks();
m_VigCorrMode.removeLinks();
}
/** unlinking the EMOR parameters should unlink the correction mode.
*/
void unlinkEMoRParams ()
{
m_EMoRParams.removeLinks();
m_ResponseType.removeLinks();
}
/** linking vignetting parameters should link the vignetting correction mode
*/
void linkRadialVigCorrCoeff (SrcPanoImage * target)
{
m_RadialVigCorrCoeff.linkWith(&(target->m_RadialVigCorrCoeff));
m_VigCorrMode.linkWith(&(target->m_VigCorrMode));
}
/** linking vignetting parameters should link the vignetting correction mode
*/
void linkRadialVigCorrCenterShift (SrcPanoImage * target)
{
m_RadialVigCorrCenterShift.linkWith(&(target->m_RadialVigCorrCenterShift));
m_VigCorrMode.linkWith(&(target->m_VigCorrMode));
}
/** linking the EMOR parameters should link the correction mode.
*/
void linkEMoRParams (SrcPanoImage * target)
{
m_EMoRParams.linkWith(&(target->m_EMoRParams));
m_ResponseType.linkWith(&(target->m_ResponseType));
}
void linkStack (SrcPanoImage * target)
{ m_Stack.linkWith(&(target->m_Stack)); }
/** check if the image size is known, if try to load the information from the file */
bool checkImageSizeKnown();
/** try to fill out information about the image, by examining the exif data
*/
bool readEXIF();
/** apply values found in EXIF data to SrcPanoImage class, call readEXIF() before to initialize some values*/
bool applyEXIFValues(bool applyEVValue=true);
/** calculate hfov of an image given focal length, image size and crop factor */
static double calcHFOV(SrcPanoImage::Projection proj, double fl, double crop, vigra::Size2D imageSize);
/** calcualte focal length, given crop factor and hfov */
static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize);
/** calculate crop factor, given focal length and hfov */
static double calcCropFactor(SrcPanoImage::Projection proj, double hfov, double focalLength, vigra::Size2D imageSize);
/** calculate exposure value */
double calcExifExposureValue();
/** updates the focal length, changes the hfov to reflect thew newFocalLength */
void updateFocalLength(double newFocalLength);
/** updates the crop factor, the hfov is calculates so that focal length remains the same */
void updateCropFactor(double focalLength, double newCropFactor);
/** tries to read cropfactor from lensfun database
you need to call SrcPanoImage::readEXIF before to fill some values
@return true, if information could be read from database */
bool readCropfactorFromDB();
/** tries to read projection and crop area from lensfun database
you need to call SrcPanoImage::readEXIF before to fill some values
@return true, if information could be read from database */
bool readProjectionFromDB();
/** tries to read distortion data from lensfun database
you need to call SrcPanoImage::readEXIF before to fill some values
@return true, if information could be read from database */
bool readDistortionFromDB();
/** tries to read vignetting data from lensfun database
you need to call SrcPanoImage::readEXIF before to fill some values
@return true, if information could be read from database */
bool readVignettingFromDB();
/** returns true, if image has masks associated */
bool hasMasks() const;
/** returns true, if image has positive masks */
bool hasPositiveMasks() const;
/** returns true, if image has active masks */
bool hasActiveMasks() const;
/** add newMask to list of masks */
void addMask(MaskPolygon newMask);
/** add newMask to list of active masks */
void addActiveMask(MaskPolygon newMask);
/** clears list of active masks */
void clearActiveMasks();
/** changes type of mask with index to given newType */
void changeMaskType(unsigned int index, HuginBase::MaskPolygon::MaskType newType);
/** delete mask at index */
void deleteMask(unsigned int index);
/** delete all masks */
void deleteAllMasks();
/** writes all mask lines to stream, using given image number */
void printMaskLines(std::ostream &o, unsigned int newImgNr) const;
/** returns true, if point p is inside of one mask polygon */
bool isInsideMasks(vigra::Point2D p) const;
private:
/** Check if Exiv orientation tag can be trusted */
bool trustExivOrientation();
};
typedef std::vector<SrcPanoImage> ImageVector;
} // namespace
#endif // PANOIMAGE_H

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks