[519868]: src / hugin_base / panotools / PanoToolsInterface.h  Maximize  Restore  History

Download this file

355 lines (276 with data), 11.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
351
352
353
354
// -*- c-basic-offset: 4 -*-
/** @file PanoToolsInterface.h
*
* @author Pablo d'Angelo <pablo.dangelo@web.de>
*
* $Id$
*
* This 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
* Lesser 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 _PANOTOOLS_PANOTOOLSINTERFACE_H
#define _PANOTOOLS_PANOTOOLSINTERFACE_H
#include <hugin_config.h>
#include <iostream>
#include <string>
#include <set>
#include <hugin_math/hugin_math.h>
#include <panodata/PanoramaVariable.h>
#include <panodata/Lens.h>
#include <panodata/PanoramaOptions.h>
#include <panodata/SrcPanoImage.h>
#include <panodata/ControlPoint.h>
// libpano includes ------------------------------------------------------------
#ifdef _WIN32
// include windows.h with sensible defines, otherwise
// panotools might include with its stupid, commonly
// named macros all over the place.
#define _STLP_VERBOSE_AUTO_LINK
//#define _USE_MATH_DEFINES
#define NOMINMAX
#define VC_EXTRALEAN
#include <windows.h>
#undef DIFFERENCE
#undef min
#undef max
#undef MIN
#undef MAX
#endif
extern "C" {
#ifdef __INTEL__
#define __INTELMEMO__
#undef __INTEL__
#endif
#include <pano13/panorama.h>
#include <pano13/filter.h>
#ifdef __INTELMEMO__
#define __INTEL__
#undef __INTELMEMO__
#endif
#include <pano13/filter.h>
// somehow these are still set after panorama.h has been included
#undef DIFFERENCE
#undef min
#undef max
#undef MIN
#undef MAX
}
//------------------------------------------------------------------------------
namespace vigra { class Diff2D; }
namespace HuginBase { class PanoramaData; }
/** mainly consists of wrapper around the pano tools library,
* to assist in ressource management and to provide a
* nicer interface.
*
* It can be used to feed data from our model directly into the
* panotools library
*/
namespace HuginBase { namespace PTools {
/** Holds transformations for Image -> Pano and the other way */
class Transform
{
public:
/** construct a new Transform object, without
* initializing a transformation
*
* use createTransform or createInvTransform to create a
* transformation, and transform to execute it.
*/
Transform()
: m_initialized(false), m_srcTX(0), m_srcTY(0),
m_destTX(0), m_destTY(0)
{
// initialize pointer
m_srcImage.data = NULL;
m_dstImage.data = NULL;
}
///
~Transform();
private:
// private, no copy constructor for the pt structures yet.
Transform(const Transform &);
Transform & operator=(const Transform &);
public:
/** initialize pano->image transformation
*
* Steps of transform:
*
* 1. pano_proj -> erect
* 2. rotate equirect?? ( rotate yaw in screenpoints ? )
* 3. spherical -> erect ??
* 4. persp_sphere ( rotate point with rotation matrix)
* 5. sphere_tp -> image_proj
* 6. distortion correction
* 7. shift image origin
* 8. shear image
*/
void createTransform(const vigra::Diff2D & srcSize,
VariableMap srcVars,
Lens::LensProjectionFormat srcProj,
const vigra::Diff2D &destSize,
PanoramaOptions::ProjectionFormat destProj,
const std::vector<double> & destProjParam,
double destHFOV,
const vigra::Diff2D & origSrcSize);
/** create pano -> img transform */
void createTransform(const PanoramaData& pano, unsigned int imgNr,
const PanoramaOptions & dest,
vigra::Diff2D srcSize=vigra::Diff2D(0,0));
///
void createTransform(const SrcPanoImage & src, const PanoramaOptions & dest);
/** create image->pano transformation
*
* @param srcSize size of input image
* @param variables of input image
* @param srcProj projection of the image
* @param destSize output panorama size
* @param destProj panorama projection
* @param destHFOV HFOV of panorama
* @param origSrcSize original input image size, 0,0 if the same
* as srcSize.
*
* origSrcSize is needed, because the @p variables are only
* valid for the original input size. To transform a smaller
* image, like a preview image, the parameters have to be adjusted.
* The origial image size, for which @p variables are valid needs
* to be know for this.
*/
void createInvTransform(const vigra::Diff2D & srcSize,
VariableMap srcVars,
Lens::LensProjectionFormat srcProj,
const vigra::Diff2D & destSize,
PanoramaOptions::ProjectionFormat destProj,
const std::vector<double> & destProjParam,
double destHFOV,
const vigra::Diff2D & origSrcSize);
/** create image->pano transformation */
void createInvTransform(const PanoramaData& pano, unsigned int imgNr,
const PanoramaOptions & dest,
vigra::Diff2D srcSize=vigra::Diff2D(0,0));
/** create image->pano transformation */
void createInvTransform(const SrcPanoImage & src, const PanoramaOptions & dest);
/** excecute transform
*/
bool transform(double & x_dest, double & y_dest,
double x_src, double y_src) const;
///
bool transform(hugin_utils::FDiff2D& dest, const hugin_utils::FDiff2D & src) const;
/** like transform, but return image coordinates, not cartesian
* coordinates
*/
bool transformImgCoord(double & x_dest, double & y_dest,
double x_src, double y_src) const;
bool transformImgCoordPartial(double & x_dest, double & y_dest, double x_src, double y_src) const;
///
bool transformImgCoord(hugin_utils::FDiff2D& dest, const hugin_utils::FDiff2D & src) const
{ return transformImgCoord(dest.x, dest.y, src.x, src.y); }
bool emitGLSL(std::ostringstream& oss) const;
private:
// update internal PT data structs.
void updatePTData(const vigra::Diff2D &srcSize,
const VariableMap & srcVars,
Lens::LensProjectionFormat & srcProj,
const vigra::Diff2D & destSize,
PanoramaOptions::ProjectionFormat & destProj,
const std::vector<double> & destProjParam,
double destHFOV);
private:
bool m_initialized;
Image m_srcImage;
Image m_dstImage;
struct MakeParams m_mp;
struct fDesc m_stack[15];
// used to convert from screen to cartesian coordinates
double m_srcTX, m_srcTY;
double m_destTX, m_destTY;
};
/** class around the central align info struct of the panotools
* library
*/
class AlignInfoWrap
{
public:
///
AlignInfoWrap();
///
~AlignInfoWrap();
public:
///
bool setInfo(const PanoramaData& pano);
///
void setGlobal();
/** get the variables stored in this AlignInfo */
VariableMapVector getVariables() const;
///
CPVector getCtrlPoints() const;
// std::map<int,int> m_ctrlPointMap;
// CPVector m_controlPoints;
protected:
AlignInfo gl;
};
/** set an output image, with properties from @p opts,
* that points to the bitmap data of @p imgData
*/
void setDestImage(Image & image, vigra::Diff2D size, unsigned char * imageData,
const PanoramaOptions::ProjectionFormat & format,
const std::vector<double> & projParams,
double destHFOV);
/** fills @p image with a complete input image, including distortion
* correction parameters if @p correctDistortions is set.
*/
void setFullImage(Image & image, vigra::Diff2D size, unsigned char * imageData,
const VariableMap & vars,
const Lens::LensProjectionFormat format,
bool correctDistortions);
/** create an empty aPrefs structure, suitable for transforming
* a input picture into an output picture.
*
* the input/output pictures must be specified with: setAdjustSrcImg()
* and setAdjustDestImg()
*/
void createAdjustPrefs(aPrefs & p, TrformStr & transf);
/** set a new input image for inserting into the panorama.
*/
void setAdjustSrcImg(TrformStr & trf, aPrefs & ap,
int width, int height, unsigned char * imageData,
const VariableMap & vars,
const Lens::LensProjectionFormat format,
bool correctDistortions);
/** set a new output image for the panorama */
void setAdjustDestImg(TrformStr & trf, aPrefs & ap,
int width, int height, unsigned char * imageData,
const PanoramaOptions & opts);
/** prepare a Trform struct for the adjust operation, image -> pano
* see use createAdjustPrefs(), setAdjustSrcImg() and setAdjustDestImg()
* to specify the images and transformation options
*/
void createAdjustTrform(TrformStr & trf);
/** free the resources associated with a TrformStr.
* createAdjustTrform() must have been used to create @p trf
*/
void freeTrform(TrformStr & trf);
/** free the pointer storage needed by Image
*
* does NOT free the data referenced by image
*/
void freeImage(Image &img);
/** set variables to optimize */
void setOptVars(optVars & opt, const std::set<std::string> & optvars);
///
VariableMapVector GetAlignInfoVariables(const AlignInfo & gl);
///
CPVector GetAlignInfoCtrlPoints(const AlignInfo & gl);
}} // namespace
#endif // _H

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

Sign up for the SourceForge newsletter:





No, thanks