Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panorama.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
24 #ifndef _PANODATA_PANORAMA_H
25 #define _PANODATA_PANORAMA_H
26 
27 // if this file is preprocessed for SWIG, we want to ignore
28 // all the header inclusions that follow:
29 
30 #ifndef _HSI_IGNORE_SECTION
31 
32 #include <hugin_shared.h>
33 #include <list>
34 #include <appbase/DocumentData.h>
35 #include <panodata/PanoramaData.h>
36 
37 
38 #endif // _HSI_IGNORE_SECTION
39 
40 namespace HuginBase {
41 
50 {
51 
52  friend class Panorama;
53 
54  public:
56  : PanoramaDataMemento(), optSwitch(0), optPhotoSwitch(0), needsOptimization(false)
57  {};
58 
61 
63  PanoramaMemento& operator=(const PanoramaMemento & o);
64 
65  virtual ~PanoramaMemento();
66 
71  bool loadPTScript(std::istream & i, int & ptoVersion, const std::string & prefix = "");
72 
73  private:
74  enum PTParseState {
80  P_CP
81  };
82 
90  std::vector<SrcPanoImage *> images;
92  std::string iccProfileDesc;
95  int bands = 0;
96 
98 
100 
106 
107  // indicates that changes have been made to
108  // control points or lens parameters after the
109  // last optimisation
111 
112  void deleteAllImages();
113 };
114 
115 
116 
153 {
154 
155  public:
156 
159  Panorama();
160 
163  ~Panorama();
164 
165 
166  // ====================== PanoramaData =========================================
167 
168 
174  Panorama getSubset(const UIntSet & imgs) const;
175 
180  Panorama duplicate() const;
181 
183  PanoramaData* getNewSubset(const UIntSet& imgs) const
184  {
185  return new Panorama(this->getSubset(imgs));
186  }
187 
190  {
191  return new Panorama(this->duplicate());
192  }
193 
198  PanoramaData* getUnlinkedSubset(UIntSetVector& imageGroups) const;
199 
200  // -- Data Access --
201 
202  // = images =
203 
205  std::size_t getNrOfImages() const
206  {
207  return state.images.size();
208  };
209 
211  inline const SrcPanoImage & getImage(std::size_t nr) const
212  {
213  assert(nr < state.images.size());
214  return *state.images[nr];
215  };
216 
218  void setImage(std::size_t nr, const SrcPanoImage & img)
219  {
220  setSrcImage(nr, img);
221  };
222 
224  // unsigned int getImageNr(const PanoImage * image) const;
225 
228  unsigned int addImage(const SrcPanoImage &img);
229 
231  void mergePanorama(const Panorama &newPano);
232 
234 // int addImageAndLens(const std::string & filename);
235 
239  // unsigned int addImage(const std::string & filename);
240 
246  void removeImage(unsigned int nr);
247 
252  void swapImages(unsigned int img1, unsigned int img2);
253 
258  void moveImage(size_t img1, size_t img2);
259 
268  SrcPanoImage getSrcImage(unsigned imgNr) const;
269 
276  void setSrcImage(unsigned int nr, const SrcPanoImage & img);
277 
284  void setImageFilename(unsigned int img, const std::string & fname);
285 
297  void activateImage(unsigned int imgNr, bool active=true);
298 
300  UIntSet getActiveImages() const;
301 
302 
303  // = CPs =
304 
306  std::size_t getNrOfCtrlPoints() const
307  {
308  return state.ctrlPoints.size();
309  };
310 
312  const ControlPoint & getCtrlPoint(std::size_t nr) const
313  {
314  assert(nr < state.ctrlPoints.size());
315  return state.ctrlPoints[nr];
316  };
317 
319  const CPVector & getCtrlPoints() const
320  { return state.ctrlPoints; };
321 
323  std::vector<unsigned int> getCtrlPointsForImage(unsigned int imgNr) const;
324 
327  CPointVector getCtrlPointsVectorForImage(unsigned int imgNr) const;
328 
330  void setCtrlPoints(const CPVector & points);
331 
333  unsigned int addCtrlPoint(const ControlPoint & point);
334 
337  void removeCtrlPoint(unsigned int pNr);
338 
341  void removeDuplicateCtrlPoints();
342 
345  void changeControlPoint(unsigned int pNr, const ControlPoint & point);
346 
348  // unsigned int getCtrlPointNr(const ControlPoint * point) const;
349 
351  int getNextCPTypeLineNumber() const;
352 
354  void updateLineCtrlPoints();
355 
356 
363  void updateCtrlPointErrors(const CPVector & controlPoints);
364 
371  void updateCtrlPointErrors(const UIntSet & imgs, const CPVector & cps);
372 
374  const std::string getICCProfileDesc() const;
376  void setICCProfileDesc(const std::string& newDesc);
379  const int getNrOfBands() const;
381  void setNrOfBands(const int nrBands);
382 
383  // = Variables =
384 
386  VariableMapVector getVariables() const;
387 
395  const VariableMap getImageVariables(unsigned int imgNr) const;
396 
402  virtual void updateVariables(const VariableMapVector & vars);
403 
405  virtual void updateVariables(const UIntSet & imgs, const VariableMapVector & var);
406 
410  virtual void updateVariables(unsigned int imgNr, const VariableMap & var);
411 
417  virtual void updateVariable(unsigned int imgNr, const Variable &var);
418 
420  virtual void UpdateFocalLength(UIntSet imgs, double newFocalLength);
422  virtual void UpdateCropFactor(UIntSet imgs, double newCropFactor);
423  /* Link image variable functions. Used to group image variables which
424  * should share the same value. The initial value is the one kept by
425  * the image with number sourceImgNr.
426  */
427 #define image_variable( name, type, default_value ) \
428  virtual void linkImageVariable##name(unsigned int sourceImgNr, unsigned int destImgNr);
429 #include "image_variables.h"
430 #undef image_variable
431 
432  /* Unlink image variable functions. Makes a image variable independant
433  * of the other images.
434  */
435 #define image_variable( name, type, default_value ) \
436  virtual void unlinkImageVariable##name(unsigned int imgNr);
437 #include "image_variables.h"
438 #undef image_variable
439 
443  virtual void updateWhiteBalance(double redFactor, double blueFactor);
444 
446  const double getMaxExposureDifference() const;
448  const bool hasPossibleStacks() const;
450  void linkPossibleStacks(bool linkPosition);
451 
452  // = Optimise Vector =
455  { return state.optvec; };
456 
458  void setOptimizeVector(const OptimizeVector & optvec);
459 
461  const int getOptimizerSwitch() const
462  { return state.optSwitch;};
464  void setOptimizerSwitch(const int newSwitch);
465 
468  { return state.optPhotoSwitch; };
470  void setPhotometricOptimizerSwitch(const int newSwitch);
471 
478  // = Panorama options =
479 
481  const PanoramaOptions & getOptions() const
482  { return state.options; };
483 
488  void setOptions(const PanoramaOptions & opt);
489 
490 
491 
492  // -- script interface --
493 
495  void printPanoramaScript(std::ostream & o,
496  const OptimizeVector & optvars,
497  const PanoramaOptions & options,
498  const UIntSet & imgs,
499  bool forPTOptimizer,
500  const std::string & stripPrefix="") const;
501 
503  void printStitcherScript(std::ostream & o,
504  const PanoramaOptions & target,
505  const UIntSet & imgs) const;
506 
507 
508 
509  //=========== ManagedPanoramaData ==============================================
510 
511 
512 
513  // -- Observing --
514 
521  void addObserver(PanoramaObserver *o);
522 
531  bool removeObserver(PanoramaObserver *observer);
532 
537  void clearObservers();
538 
544  const bool hasPendingChanges() const;
545 
555  void changeFinished(bool keepDirty);
556 
565  { changeFinished(false); }
566 
572  void imageChanged(unsigned int imgNr);
573 
575  void updateMasksForImage(unsigned int imgNr, MaskPolygonVector newMasks);
581  void updateMasks(bool convertPosMaskToNeg=false);
584  void transferMask(MaskPolygon mask,unsigned int imgNr, const UIntSet& targetImgs);
586  void updateOptimizeVector();
588  std::set<size_t> getRefImages();
591  void checkRefOptStatus(bool& linkRefImgsYaw, bool& linkRefImgsPitch, bool& linkRefImgsRoll);
592 
593  // -- Memento interface --
594 
596  virtual PanoramaDataMemento* getNewMemento() const;
597 
599  virtual bool setMementoToCopyOf(const PanoramaDataMemento* const memento);
600 
603  { return state; }
604 
606  void setMemento(const PanoramaMemento& memento);
607 
608 
609  // -- Optimization Status --
610 
615  { return state.needsOptimization; };
616 
618  void markAsOptimized(bool optimized=true)
619  { state.needsOptimization = !optimized; };
620 
621 
622 
623  //=========== Document Data ====================================================
624 
625  public:
631  bool ReadPTOFile(const std::string& filename, const std::string& prefix = "");
633  bool WritePTOFile(const std::string& filename, const std::string& prefix = "");
634 
636  bool isDirty() const
637  {
638  if (dirty != AppBase::DocumentData::isDirty())
639  DEBUG_WARN("modification status mismatch.");
640 
641  return dirty;
642  }
643 
645  virtual void clearDirty()
646  {
648  dirty = false;
649  }
650 
651  protected:
652  void setDirty(const bool& dirty = true)
653  {
655 
656  this->dirty = dirty;
657  }
658 
659 
660  // == additional methods for documents ==
661 
662  public:
664  void setFilePrefix(std::string prefix)
665  { imgFilePrefix = prefix; }
666 
667  protected:
668  std::string getFilePrefix() const
669  { return imgFilePrefix; }
670 
671  //=========== Internal methods =================================================
672 
673  public:
675  void reset();
676 
677  protected:
680  void adjustVarLinks();
681  private:
683  void centerCrop(unsigned int imgNr);
685  vigra::Rect2D centerCropImage(unsigned int imgNr);
687  void updateCropMode(unsigned int imgNr);
688 
689  std::string imgFilePrefix;
690 
692  bool dirty;
693 
695  std::list<PanoramaObserver *> observers;
698 
700 
701  std::set<std::string> m_ptoptimizerVarNames;
702 };
703 
704 } // namespace
705 #endif // _PANORAMA_H
std::vector< UIntSet > UIntSetVector
Definition: PanoramaData.h:56
std::list< PanoramaObserver * > observers
Definition: Panorama.h:695
virtual void clearDirty()
Definition: DocumentData.h:53
PanoramaData * getNewSubset(const UIntSet &imgs) const
Definition: Panorama.h:183
std::string imgFilePrefix
Definition: Panorama.h:689
void setFilePrefix(std::string prefix)
sets the path prefix of the images reffered with relative paths
Definition: Panorama.h:664
std::set< std::string > m_ptoptimizerVarNames
Definition: Panorama.h:701
bool m_forceImagesUpdate
Definition: Panorama.h:699
virtual bool isDirty() const
Definition: DocumentData.h:50
std::vector< SrcPanoImage * > images
The images inside the panorama.
Definition: Panorama.h:90
std::size_t getNrOfCtrlPoints() const
number of control points
Definition: Panorama.h:306
a variable has a value and a name.
virtual void clearDirty()
clear dirty flag.
Definition: Panorama.h:645
const CPVector & getCtrlPoints() const
get all control point of this Panorama
Definition: Panorama.h:319
int optSwitch
stores the optimizer switch, use OR of HuginBase::OptimizerSwitches
Definition: Panorama.h:103
PanoramaOptions options
Definition: Panorama.h:99
represents a control point
Definition: ControlPoint.h:38
int optPhotoSwitch
stores the photometric optimizer switch, use OR of HuginBase::OptimizerSwitches
Definition: Panorama.h:105
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
std::vector< VariableMap > VariableMapVector
#define DEBUG_WARN(msg)
Definition: utils.h:74
Model for a panorama.
Definition: Panorama.h:152
virtual void setDirty(const bool &dirty=true)
Definition: DocumentData.h:57
void setDirty(const bool &dirty=true)
Definition: Panorama.h:652
const OptimizeVector & getOptimizeVector() const
return the optimize settings stored inside panorama
Definition: Panorama.h:454
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
const ControlPoint & getCtrlPoint(std::size_t nr) const
get a control point, counting starts with 0
Definition: Panorama.h:312
Model for a panorama.
Definition: PanoramaData.h:81
std::vector< MaskPolygon > MaskPolygonVector
Definition: Mask.h:147
#define IMPEX
Definition: hugin_shared.h:39
OptimizeVector optvec
Definition: Panorama.h:101
void changeFinished()
notify observers about changes in this class
Definition: Panorama.h:564
std::vector< CPoint > CPointVector
Definition: ControlPoint.h:102
std::map< std::string, Variable > VariableMap
PanoramaMemento getMemento() const
get the internal state
Definition: Panorama.h:602
const PanoramaOptions & getOptions() const
returns the options for this panorama
Definition: Panorama.h:481
this handler class will receive change events from the Panorama.
Definition: PanoramaData.h:401
const int getPhotometricOptimizerSwitch() const
return the photometric optimizer master switch
Definition: Panorama.h:467
void markAsOptimized(bool optimized=true)
Definition: Panorama.h:618
Memento class for a Panorama object.
Definition: Panorama.h:49
bool isDirty() const
true if there are unsaved changes
Definition: Panorama.h:636
const int getOptimizerSwitch() const
returns optimizer master switch
Definition: Panorama.h:461
Memento class for a PanoramaData object.
Definition: PanoramaData.h:443
UIntSet changedImages
the images that have been changed since the last changeFinished()
Definition: Panorama.h:697
bool dirty
this indicates that there are unsaved changes
Definition: Panorama.h:692
std::vector< ControlPoint > CPVector
Definition: ControlPoint.h:99
PanoramaData * getNewCopy() const
Definition: Panorama.h:189
std::vector< std::set< std::string > > OptimizeVector
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
bool needsOptimization()
true if control points or lens variables have been changed after the last optimisation ...
Definition: Panorama.h:614
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
void setImage(std::size_t nr, const SrcPanoImage &img)
set a panorama image, counting starts with 0
Definition: Panorama.h:218
This file specifies what image variables SrcPanoImg should have.
std::string getFilePrefix() const
Definition: Panorama.h:668
PanoramaMemento state
Definition: Panorama.h:694
base class, which stores one mask polygon
Definition: Mask.h:52
std::string iccProfileDesc
description of the icc profile
Definition: Panorama.h:92