Panorama.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _PANODATA_PANORAMA_H
00025 #define _PANODATA_PANORAMA_H
00026 
00027 // if this file is preprocessed for SWIG, we want to ignore
00028 // all the header inclusions that follow:
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 
00049 class IMPEX PanoramaMemento : public PanoramaDataMemento
00050 {
00051         
00052         friend class Panorama;
00053         
00054     public:
00055         PanoramaMemento()
00056             : PanoramaDataMemento(), optSwitch(0), optPhotoSwitch(0), needsOptimization(false)
00057         {};
00058         
00060         PanoramaMemento(const PanoramaMemento & o);
00061         
00063         PanoramaMemento& operator=(const PanoramaMemento & o);
00064         
00065         virtual ~PanoramaMemento();
00066         
00071         bool loadPTScript(std::istream & i, int & ptoVersion, const std::string & prefix = "");
00072 
00073     private:
00074         enum PTParseState {
00075             P_NONE,
00076             P_OUTPUT,
00077             P_MODIFIER,
00078             P_IMAGE,
00079             P_OPTIMIZE,
00080             P_CP
00081         };
00082         
00090         std::vector<SrcPanoImage *> images;
00092         std::string iccProfileDesc;
00093         
00094         CPVector ctrlPoints;
00095         
00096         PanoramaOptions options;
00097         
00098         OptimizeVector optvec;
00100         int optSwitch;
00102         int optPhotoSwitch;
00103 
00104         // indicates that changes have been made to
00105         // control points or lens parameters after the
00106         // last optimisation
00107         bool needsOptimization;
00108         
00109         void deleteAllImages();
00110 };
00111 
00112 
00113     
00149 class IMPEX Panorama : public ManagedPanoramaData, public AppBase::DocumentData
00150 {
00151     
00152     public:
00153 
00156         Panorama();
00157 
00160         ~Panorama();
00161         
00162         
00163     // ====================== PanoramaData =========================================
00164         
00165         
00171         Panorama getSubset(const UIntSet & imgs) const;
00172         
00177         Panorama duplicate() const;
00178          
00180         PanoramaData* getNewSubset(const UIntSet& imgs) const
00181          {
00182              return new Panorama(this->getSubset(imgs));
00183          }
00184          
00186         PanoramaData* getNewCopy() const
00187          {
00188              return new Panorama(this->duplicate());
00189          }
00190         
00195         PanoramaData* getUnlinkedSubset(UIntSetVector& imageGroups) const;
00196 
00197     // -- Data Access --
00198         
00199     // = images =    
00200         
00202         std::size_t getNrOfImages() const
00203         {
00204             return state.images.size();
00205         };
00206         
00208         const SrcPanoImage & getImage(std::size_t nr) const
00209         {
00210             assert(nr < state.images.size());
00211             return *state.images[nr];
00212         };
00213 
00215         void setImage(std::size_t nr, const SrcPanoImage & img)
00216         {
00217             setSrcImage(nr, img);
00218         };
00219         
00221     //    unsigned int getImageNr(const PanoImage * image) const;
00222         
00225         unsigned int addImage(const SrcPanoImage &img);
00226 
00228         void mergePanorama(const Panorama &newPano);
00229         
00231 //        int addImageAndLens(const std::string & filename);
00232         
00236         //    unsigned int addImage(const std::string & filename);
00237         
00243         void removeImage(unsigned int nr);
00244         
00249         void swapImages(unsigned int img1, unsigned int img2);
00250 
00255         void moveImage(size_t img1, size_t img2);
00256         
00265         SrcPanoImage getSrcImage(unsigned imgNr) const;
00266         
00273         void setSrcImage(unsigned int nr, const SrcPanoImage & img);
00274         
00281         void setImageFilename(unsigned int img, const std::string & fname);
00282         
00294         void activateImage(unsigned int imgNr, bool active=true);
00295         
00297         UIntSet getActiveImages() const;
00298         
00299         
00300     // = CPs =    
00301         
00303          std::size_t getNrOfCtrlPoints() const
00304         {
00305             return state.ctrlPoints.size();
00306         };
00307         
00309         const ControlPoint & getCtrlPoint(std::size_t nr) const
00310         {
00311             assert(nr < state.ctrlPoints.size());
00312             return state.ctrlPoints[nr];
00313         };
00314         
00316         const CPVector & getCtrlPoints() const
00317             { return state.ctrlPoints; };
00318         
00320         std::vector<unsigned int> getCtrlPointsForImage(unsigned int imgNr) const;
00321         
00324         CPointVector getCtrlPointsVectorForImage(unsigned int imgNr) const;
00325 
00327         void setCtrlPoints(const CPVector & points);
00328         
00330         unsigned int addCtrlPoint(const ControlPoint & point);
00331         
00334         void removeCtrlPoint(unsigned int pNr);
00335 
00338         void removeDuplicateCtrlPoints();
00339         
00342         void changeControlPoint(unsigned int pNr, const ControlPoint & point);
00343         
00345         //    unsigned int getCtrlPointNr(const ControlPoint * point) const;
00346         
00348         int getNextCPTypeLineNumber() const;
00349         
00351         void updateLineCtrlPoints();
00352         
00353         
00360         void updateCtrlPointErrors(const CPVector & controlPoints);
00361         
00368         void updateCtrlPointErrors(const UIntSet & imgs, const CPVector & cps);
00369         
00371         const std::string getICCProfileDesc() const;
00373         void setICCProfileDesc(const std::string& newDesc);
00374 
00375     // = Variables =    
00376         
00378         VariableMapVector getVariables() const;
00379 
00387         const VariableMap getImageVariables(unsigned int imgNr) const;
00388         
00394         virtual void updateVariables(const VariableMapVector & vars);
00395         
00397         virtual void updateVariables(const UIntSet & imgs, const VariableMapVector & var);
00398         
00402         virtual void updateVariables(unsigned int imgNr, const VariableMap & var);
00403         
00409         virtual void updateVariable(unsigned int imgNr, const Variable &var);
00410         
00412         virtual void UpdateFocalLength(UIntSet imgs, double newFocalLength);
00414         virtual void UpdateCropFactor(UIntSet imgs, double newCropFactor);
00415         /* Link image variable functions. Used to group image variables which
00416          * should share the same value. The initial value is the one kept by
00417          * the image with number sourceImgNr.
00418          */
00419 #define image_variable( name, type, default_value ) \
00420         virtual void linkImageVariable##name(unsigned int sourceImgNr, unsigned int destImgNr);
00421 #include "image_variables.h"
00422 #undef image_variable
00423 
00424         /* Unlink image variable functions. Makes a image variable independant
00425          * of the other images.
00426          */
00427 #define image_variable( name, type, default_value ) \
00428         virtual void unlinkImageVariable##name(unsigned int imgNr);
00429 #include "image_variables.h"
00430 #undef image_variable
00431         
00435         virtual void updateWhiteBalance(double redFactor, double blueFactor);
00436 
00438         const double getMaxExposureDifference() const;
00440         const bool hasPossibleStacks() const;
00442         void linkPossibleStacks(bool linkPosition);
00443 
00444     // = Optimise Vector =    
00446         const OptimizeVector & getOptimizeVector() const
00447             { return state.optvec; };
00448 
00450         void setOptimizeVector(const OptimizeVector & optvec);
00451         
00453         const int getOptimizerSwitch() const
00454             { return state.optSwitch;};
00456         void setOptimizerSwitch(const int newSwitch);
00457 
00459         const int getPhotometricOptimizerSwitch() const
00460             { return state.optPhotoSwitch; };
00462         void setPhotometricOptimizerSwitch(const int newSwitch);
00463 
00470     // = Panorama options =    
00471 
00473         const PanoramaOptions & getOptions() const
00474             { return state.options; };
00475 
00480         void setOptions(const PanoramaOptions & opt);
00481         
00482 
00483         
00484     // -- script interface --
00485             
00496         void parseOptimizerScript(std::istream & i,
00497                                   const UIntSet & imgs,
00498                                   VariableMapVector & imgVars,
00499                                   CPVector & ctrlPoints) const;
00500             
00502         void printPanoramaScript(std::ostream & o,
00503                                  const OptimizeVector & optvars,
00504                                  const PanoramaOptions & options,
00505                                  const UIntSet & imgs,
00506                                  bool forPTOptimizer,
00507                                  const std::string & stripPrefix="") const;
00508         
00510         void printStitcherScript(std::ostream & o,
00511                                  const PanoramaOptions & target,
00512                                  const UIntSet & imgs) const;
00513 
00514         
00515         
00516     //=========== ManagedPanoramaData ==============================================
00517 
00518 
00519 
00520     // -- Observing --
00521         
00528         void addObserver(PanoramaObserver *o);
00529         
00538         bool removeObserver(PanoramaObserver *observer);
00539         
00544         void clearObservers();
00545         
00551         const bool hasPendingChanges() const;
00552 
00562         void changeFinished(bool keepDirty);
00563         
00571         void changeFinished()
00572             { changeFinished(false); }
00573         
00579         void imageChanged(unsigned int imgNr);
00580 
00582         void updateMasksForImage(unsigned int imgNr, MaskPolygonVector newMasks);
00588         void updateMasks(bool convertPosMaskToNeg=false);
00591         void transferMask(MaskPolygon mask,unsigned int imgNr, const UIntSet& targetImgs);
00593         void updateOptimizeVector();
00595         std::set<size_t> getRefImages();
00598         void checkRefOptStatus(bool& linkRefImgsYaw, bool& linkRefImgsPitch, bool& linkRefImgsRoll);
00599 
00600         // -- Memento interface --
00601         
00603         virtual PanoramaDataMemento* getNewMemento() const;
00604         
00606         virtual bool setMementoToCopyOf(const PanoramaDataMemento* const memento);
00607         
00609         PanoramaMemento getMemento() const
00610             { return state; }
00611         
00613         void setMemento(const PanoramaMemento& memento);
00614         
00615         
00616     // -- Optimization Status --
00617         
00621         bool needsOptimization()
00622             { return state.needsOptimization; };
00623 
00625         void markAsOptimized(bool optimized=true)
00626             { state.needsOptimization = !optimized; };
00627         
00628 
00629 
00630     //=========== Document Data ====================================================
00631 
00632     public:
00637         ReadWriteError readData(std::istream& dataInput, std::string documentType = "");
00638         
00640         ReadWriteError writeData(std::ostream& dataOutput, std::string documentType = "");
00641 
00643         bool isDirty() const
00644         {
00645             if (dirty != AppBase::DocumentData::isDirty())
00646                 DEBUG_WARN("modification status mismatch.");
00647                 
00648             return dirty;
00649         }
00650         
00652         virtual void clearDirty()
00653         {
00654             AppBase::DocumentData::clearDirty();
00655             dirty = false;
00656         }
00657         
00658     protected:
00659         void setDirty(const bool& dirty = true)
00660         { 
00661             AppBase::DocumentData::setDirty(dirty);
00662             
00663             this->dirty = dirty;
00664         }
00665         
00666         
00667     // == additional methods for documents ==
00668         
00669     public:
00671         void setFilePrefix(std::string prefix)
00672             { imgFilePrefix = prefix; }
00673         
00674     protected:
00675         std::string getFilePrefix() const
00676             { return imgFilePrefix; }
00677         
00678     //=========== Internal methods =================================================
00679         
00680     public:
00682         void reset();
00683         
00684     protected:
00687         void adjustVarLinks();
00688     private:
00690         void centerCrop(unsigned int imgNr);
00692         vigra::Rect2D centerCropImage(unsigned int imgNr);
00694         void updateCropMode(unsigned int imgNr);
00695 
00696         std::string imgFilePrefix;
00697 
00699         bool dirty;
00700 
00701         PanoramaMemento state;
00702         std::list<PanoramaObserver *> observers;
00704         UIntSet changedImages;
00705 
00706         bool m_forceImagesUpdate;
00707 
00708         std::set<std::string> m_ptoptimizerVarNames;
00709 };
00710 
00711 } // namespace
00712 #endif // _PANORAMA_H

Generated on 5 Feb 2016 for Hugintrunk by  doxygen 1.4.7