00001
00024 #ifndef _PANODATA_PANORAMA_H
00025 #define _PANODATA_PANORAMA_H
00026
00027
00028
00029
00030 #ifndef _HSI_IGNORE_SECTION
00031
00032 #include <hugin_shared.h>
00033 #include <list>
00034 #include <appbase/DocumentData.h>
00035 #include <panodata/PanoramaData.h>
00036
00037
00038 #endif // _HSI_IGNORE_SECTION
00039
00040 namespace HuginBase {
00041
00042
00043
00044
00052 class IMPEX PanoramaMemento : public PanoramaDataMemento
00053 {
00054
00055 friend class Panorama;
00056
00057 public:
00058 PanoramaMemento()
00059 : PanoramaDataMemento(), needsOptimization(false), optSwitch(0), optPhotoSwitch(0)
00060 {};
00061
00063 PanoramaMemento(const PanoramaMemento & o);
00064
00066 PanoramaMemento& operator=(const PanoramaMemento & o);
00067
00068 virtual ~PanoramaMemento();
00069
00070
00071 protected:
00073
00074
00079 bool loadPTScript(std::istream & i, int & ptoVersion, const std::string & prefix = "");
00080
00081
00082 private:
00083 enum PTParseState {
00084 P_NONE,
00085 P_OUTPUT,
00086 P_MODIFIER,
00087 P_IMAGE,
00088 P_OPTIMIZE,
00089 P_CP
00090 };
00091
00099 std::vector<SrcPanoImage *> images;
00100
00101 CPVector ctrlPoints;
00102
00103 PanoramaOptions options;
00104
00105 OptimizeVector optvec;
00107 int optSwitch;
00109 int optPhotoSwitch;
00110
00111
00112
00113
00114 bool needsOptimization;
00115
00116 void deleteAllImages();
00117 };
00118
00119
00120
00156 class IMPEX Panorama : public ManagedPanoramaData, public AppBase::DocumentData
00157 {
00158
00159 public:
00160
00163 Panorama();
00164
00167 ~Panorama();
00168
00169
00170
00171
00172
00178 Panorama getSubset(const UIntSet & imgs) const;
00179
00184 Panorama duplicate() const;
00185
00187 PanoramaData* getNewSubset(const UIntSet& imgs) const
00188 {
00189 return new Panorama(this->getSubset(imgs));
00190 }
00191
00193 PanoramaData* getNewCopy() const
00194 {
00195 return new Panorama(this->duplicate());
00196 }
00197
00198
00199
00200
00201
00202
00204 std::size_t getNrOfImages() const
00205 {
00206 return state.images.size();
00207 };
00208
00210 const SrcPanoImage & getImage(std::size_t nr) const
00211 {
00212 assert(nr < state.images.size());
00213 return *state.images[nr];
00214 };
00215
00217 void setImage(std::size_t nr, const SrcPanoImage & img)
00218 {
00219 setSrcImage(nr, img);
00220 };
00221
00223
00224
00227 unsigned int addImage(const SrcPanoImage &img);
00228
00230 void mergePanorama(const Panorama &newPano);
00231
00233
00234
00238
00239
00245 void removeImage(unsigned int nr);
00246
00251 void swapImages(unsigned int img1, unsigned int img2);
00252
00257 void moveImage(size_t img1, size_t img2);
00258
00267 SrcPanoImage getSrcImage(unsigned imgNr) const;
00268
00275 void setSrcImage(unsigned int nr, const SrcPanoImage & img);
00276
00283 void setImageFilename(unsigned int img, const std::string & fname);
00284
00296 void activateImage(unsigned int imgNr, bool active=true);
00297
00299 UIntSet getActiveImages() const;
00300
00301
00302
00303
00305 std::size_t getNrOfCtrlPoints() const
00306 {
00307 return state.ctrlPoints.size();
00308 };
00309
00311 const ControlPoint & getCtrlPoint(std::size_t nr) const
00312 {
00313 assert(nr < state.ctrlPoints.size());
00314 return state.ctrlPoints[nr];
00315 };
00316
00318 const CPVector & getCtrlPoints() const
00319 { return state.ctrlPoints; };
00320
00322 std::vector<unsigned int> getCtrlPointsForImage(unsigned int imgNr) const;
00323
00326 CPointVector getCtrlPointsVectorForImage(unsigned int imgNr) const;
00327
00329 void setCtrlPoints(const CPVector & points);
00330
00332 unsigned int addCtrlPoint(const ControlPoint & point);
00333
00336 void removeCtrlPoint(unsigned int pNr);
00337
00340 void removeDuplicateCtrlPoints();
00341
00344 void changeControlPoint(unsigned int pNr, const ControlPoint & point);
00345
00347
00348
00350 int getNextCPTypeLineNumber() const;
00351
00353 void updateLineCtrlPoints();
00354
00355
00362 void updateCtrlPointErrors(const CPVector & controlPoints);
00363
00370 void updateCtrlPointErrors(const UIntSet & imgs, const CPVector & cps);
00371
00372
00373
00374
00376 VariableMapVector getVariables() const;
00377
00385 const VariableMap getImageVariables(unsigned int imgNr) const;
00386
00392 virtual void updateVariables(const VariableMapVector & vars);
00393
00395 virtual void updateVariables(const UIntSet & imgs, const VariableMapVector & var);
00396
00400 virtual void updateVariables(unsigned int imgNr, const VariableMap & var);
00401
00407 virtual void updateVariable(unsigned int imgNr, const Variable &var);
00408
00410 virtual void UpdateFocalLength(UIntSet imgs, double newFocalLength);
00412 virtual void UpdateCropFactor(UIntSet imgs, double newCropFactor);
00413
00414
00415
00416
00417 #define image_variable( name, type, default_value ) \
00418 virtual void linkImageVariable##name(unsigned int sourceImgNr, unsigned int destImgNr);
00419 #include "image_variables.h"
00420 #undef image_variable
00421
00422
00423
00424
00425 #define image_variable( name, type, default_value ) \
00426 virtual void unlinkImageVariable##name(unsigned int imgNr);
00427 #include "image_variables.h"
00428 #undef image_variable
00429
00433 virtual void updateWhiteBalance(double redFactor, double blueFactor);
00434
00435
00437 const OptimizeVector & getOptimizeVector() const
00438 { return state.optvec; };
00439
00441 void setOptimizeVector(const OptimizeVector & optvec);
00442
00444 const int getOptimizerSwitch() const
00445 { return state.optSwitch;};
00447 void setOptimizerSwitch(const int newSwitch);
00448
00450 const int getPhotometricOptimizerSwitch() const
00451 { return state.optPhotoSwitch; };
00453 void setPhotometricOptimizerSwitch(const int newSwitch);
00454
00461
00462
00464 const PanoramaOptions & getOptions() const
00465 { return state.options; };
00466
00471 void setOptions(const PanoramaOptions & opt);
00472
00473
00474
00475
00476
00487 void parseOptimizerScript(std::istream & i,
00488 const UIntSet & imgs,
00489 VariableMapVector & imgVars,
00490 CPVector & ctrlPoints) const;
00491
00493 void printPanoramaScript(std::ostream & o,
00494 const OptimizeVector & optvars,
00495 const PanoramaOptions & options,
00496 const UIntSet & imgs,
00497 bool forPTOptimizer,
00498 const std::string & stripPrefix="") const;
00499
00501 void printStitcherScript(std::ostream & o,
00502 const PanoramaOptions & target,
00503 const UIntSet & imgs) const;
00504
00505
00506
00507
00508
00509
00510
00511
00512
00519 void addObserver(PanoramaObserver *o);
00520
00529 bool removeObserver(PanoramaObserver *observer);
00530
00535 void clearObservers();
00536
00546 void changeFinished(bool keepDirty);
00547
00555 void changeFinished()
00556 { changeFinished(false); }
00557
00563 void imageChanged(unsigned int imgNr);
00564
00566 void updateMasksForImage(unsigned int imgNr, MaskPolygonVector newMasks);
00572 void updateMasks(bool convertPosMaskToNeg=false);
00575 void transferMask(MaskPolygon mask,unsigned int imgNr, const UIntSet targetImgs);
00577 void updateOptimizeVector();
00579 std::set<size_t> getRefImages();
00582 void checkRefOptStatus(bool& linkRefImgsYaw, bool& linkRefImgsPitch, bool& linkRefImgsRoll);
00583
00584
00585
00587 virtual PanoramaDataMemento* getNewMemento() const;
00588
00590 virtual bool setMementoToCopyOf(const PanoramaDataMemento* const memento);
00591
00593 PanoramaMemento getMemento() const
00594 { return state; }
00595
00597 void setMemento(const PanoramaMemento& memento);
00598
00599
00600
00601
00605 bool needsOptimization()
00606 { return state.needsOptimization; };
00607
00609 void markAsOptimized(bool optimized=true)
00610 { state.needsOptimization = !optimized; };
00611
00612
00613
00614
00615
00616 public:
00621 ReadWriteError readData(std::istream& dataInput, std::string documentType = "");
00622
00624 ReadWriteError writeData(std::ostream& dataOutput, std::string documentType = "");
00625
00627 bool isDirty() const
00628 {
00629 if (dirty != AppBase::DocumentData::isDirty())
00630 DEBUG_WARN("modification status mismatch.");
00631
00632 return dirty;
00633 }
00634
00636 virtual void clearDirty()
00637 {
00638 AppBase::DocumentData::clearDirty();
00639 dirty = false;
00640 }
00641
00642 protected:
00643 void setDirty(const bool& dirty = true)
00644 {
00645 AppBase::DocumentData::setDirty(dirty);
00646
00647 this->dirty = dirty;
00648 }
00649
00650
00651
00652
00653 public:
00655 void setFilePrefix(std::string prefix)
00656 { imgFilePrefix = prefix; }
00657
00658 protected:
00659 std::string getFilePrefix() const
00660 { return imgFilePrefix; }
00661
00662
00663
00664 public:
00666 void reset();
00667
00668 protected:
00671 void adjustVarLinks();
00672
00673
00675
00676
00678
00679
00681
00682
00683
00684
00685 private:
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00698 void centerCrop(unsigned int imgNr);
00700 vigra::Rect2D centerCropImage(unsigned int imgNr);
00702 void updateCropMode(unsigned int imgNr);
00703
00704 std::string imgFilePrefix;
00705
00707 bool dirty;
00708
00709 PanoramaMemento state;
00710 std::list<PanoramaObserver *> observers;
00712 UIntSet changedImages;
00713
00714 bool m_forceImagesUpdate;
00715
00716 std::set<std::string> m_ptoptimizerVarNames;
00717 };
00718
00719
00720
00721
00722 }
00723
00724
00725
00726
00727 #endif // _PANORAMA_H