[1b6fd0]: src / Panorama / Panorama.h Maximize Restore History

Download this file

Panorama.h    367 lines (289 with data), 10.7 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
// -*- c-basic-offset: 4 -*-
/** @file Panorama.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 PANORAMA_H
#define PANORAMA_H
#include <vector>
#include <functional>
#include <qobject.h>
#include <qstring.h>
#include <qprocess.h>
#include <qsettings.h>
#include <qdom.h>
#include "PanoImage.h"
namespace PT {
QString getAttrib(QDomNamedNodeMap map, QString name);
//=========================================================================
//=========================================================================
// represents a control point
struct ControlPoint
{
enum OptimizeMode {
X_Y = 0, /// evaluate x,y
X, /// evaluate x, points are on a vertical line
Y /// evaluate y, points are on a horizontal line
};
ControlPoint()
: image1(0), image2(0),
x1(0),y1(0),
x2(0),y2(0),
error(0), mode(X_Y)
{ };
ControlPoint(Panorama & pano, const QDomNode & node);
ControlPoint(PanoImage * s, double sX, double sY,
PanoImage * d, double dX, double dY,
OptimizeMode mode = X_Y)
: image1(s), image2(d),
x1(sX),y1(sY),
x2(dX),y2(dY),
error(0), mode(mode)
{ };
void printScriptLine(std::ostream & o) const;
QDomNode toXML(QDomDocument & doc) const;
void setFromXML(const QDomNode & elem, Panorama & pano);
PanoImage * image1;
PanoImage * image2;
double x1,y1;
double x2,y2;
double error;
OptimizeMode mode;
};
typedef std::vector<ControlPoint*> CPVector;
//=========================================================================
//=========================================================================
struct ControlPointInImage : public std::binary_function<const ControlPoint &, unsigned int, bool>{
bool operator()(const ControlPoint & point, const PanoImage * img) const
{
return ((point.image1 == img) || (point.image2 == img));
}
};
//=========================================================================
//=========================================================================
class PanoramaOptions
{
public:
PanoramaOptions()
: projectionFormat(EQUIRECTANGULAR),
HFOV(360),
width(0), height(0),
outfile("panorama.jpg"),outputFormat("JPEG"),
quality(80),progressive(false),
colorCorrection(NONE), colorReferenceImage(0),
gamma(1.0), interpolator(POLY_3)
{};
virtual ~PanoramaOptions() {};
enum ProjectionFormat { RECTILINEAR = 0,
CYLINDRICAL = 1,
EQUIRECTANGULAR = 2 };
enum ColorCorrection { NONE = 0,
BRIGHTNESS_COLOR,
BRIGHTNESS,
COLOR };
enum Interpolator {
POLY_3 = 0,
SPLINE_16,
SPLINE_36,
SINC_256,
SPLINE_64,
BILINEAR,
NEAREST_NEIGHBOUR,
SINC_1024
};
QDomNode toXML(QDomDocument & doc) const;
void setFromXML(const QDomNode & elem);
void printScriptLine(std::ostream & o) const;
// they are public, because they need to be set through
// get/setOptions in Panorama.
ProjectionFormat projectionFormat;
double HFOV;
unsigned int width;
unsigned int height;
QString outfile;
QString outputFormat;
// jpeg options
int quality;
bool progressive;
ColorCorrection colorCorrection;
unsigned int colorReferenceImage;
// misc options
double gamma;
Interpolator interpolator;
};
//=========================================================================
//=========================================================================
/** The central Panorama object.
*
* It contains the model (see Model View Controller Pattern) of
* a Panorama.
*
* It also provides easy access to the operations that can be done
* on a Panorama (with the Panorama Tools).
*
* Operations are implemented using the Command pattern, with
* PanoramaCommand as the base class for Panoramas.
*
* @todo how to implementet more complicated commmands, that
* requires a decision that cant be made automatically, and
* needs user interaction with the commands, like
* optimize). Split it into multiple commands, and save the
* state information inside the class. or create commands
* that open dialogs etc?
*
*
* */
class Panorama : public QObject
{
Q_OBJECT
public:
Panorama();
virtual ~Panorama();
QDomElement toXML(QDomDocument & doc);
void setFromXML(const QDomNode & elem);
/** run PTOptimizer to optimize the panorama.
*
* reads the optimization results when finished */
void optimize();
/** create panorama */
void stitch(const PanoramaOptions & target);
/** read settings.
*/
void readSettings();
void writeSettings();
//
// functions needed for the commands
//
/** add an Image to the panorama
* @return image number
*/
PanoImage * addImage(const QString & filename);
/** remove an Image.
*
* deletes all associated control points
*/
void removeImage(PanoImage * img);
/** get an image
*/
PanoImage * getImage(unsigned int nr)
{
Q_ASSERT(nr < images.size());
return images[nr];
};
/** get # of images */
unsigned int getNrImages()
{ return images.size(); }
ControlPoint * addControlPoint(const ControlPoint & point);
void removeControlPoint(ControlPoint * point);
// ignores the image pointers.
void changeControlPoint(unsigned int ctrlPointNr, ControlPoint point);
ControlPoint * getControlPoint(unsigned int nr)
{
Q_ASSERT(nr < controlPoints.size());
return controlPoints[nr];
};
void setOptions(const PanoramaOptions & opt);
const PanoramaOptions & getOptions() const
{
return options;
}
//
// functions to get panorama information.
//
/// set PTStitcher executable
void setPTStitcherFileName(QString app)
{ stitcherExe = app; }
/// set PTOptimizer executable
void setPTOptimizerFileName(QString app)
{ optimizerExe = app; }
public:
/// create an optimizer script
void printOptimizerScript(std::ostream & o);
/// create the stitcher script
void printStitcherScript(std::ostream & o);
/// read after optimization, fills in control point errors.
void readOptimizerScript(std::istream & i);
/** return all control points.
*
* ugly. exposes details...
*/
std::vector<ControlPoint*> getCtrlPoints()
{ return controlPoints; };
/** return control points for a given image */
std::vector<ControlPoint *> getCtrlPointsForImage(PanoImage * img) const;
/** return all images
*
* ugly, exposes internals...
*/
std::vector<PanoImage*> & getImages()
{ return images; };
bool hasCommonLens() const
{ return commonLens; }
virtual const char * isA() const { return "Panorama"; };
void setCommonLens(bool);
void updateLens(const LensSettings & l, PanoImage * img);
// report changes
/// call if
void reportChange();
void reportChangedImage(unsigned int img);
void reportAddedImage(unsigned int img);
void reportRemovedImage(unsigned int img);
void reportAddedCtrlPoint(unsigned int point);
void reportRemovedCtrlPoint(unsigned int point);
bool isDirty()
{ return dirty; };
void setDirty(bool d)
{ dirty = d; };
public slots:
void processExited();
signals:
/// some internal state changed. this includes
/// everything inside the panorama, images as well as
/// panorama settings.
void stateChanged();
/// a specific image has been changed
void imageChanged(unsigned int nr);
/// an image has been added
void imageAdded(unsigned int nr);
/// an image has been removed
void imageRemoved(unsigned int nr);
// signals about control points
void ctrlPointAdded(unsigned int nr);
void ctrlPointRemoved(unsigned int nr);
private:
enum ProcessType { NO_PROCESS, OPTIMIZER, STITCHER };
/// save the panorama into a file suitable for PTOptimizer
std::vector<PanoImage *> images;
std::vector<QPixmap> imageData;
PanoramaOptions options;
std::vector<ControlPoint *> controlPoints;
// same lens
bool commonLens;
// to run stitcher & optimizer
QProcess process;
ProcessType currentProcess;
QString optimizerExe;
QString stitcherExe;
QString PTScriptFile;
bool dirty;
QSettings settings;
};
}
#endif // PANORAMA_H