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;
00095         int bands = 0;
00096         
00097         CPVector ctrlPoints;
00098         
00099         PanoramaOptions options;
00100         
00101         OptimizeVector optvec;
00103         int optSwitch;
00105         int optPhotoSwitch;
00106 
00107         // indicates that changes have been made to
00108         // control points or lens parameters after the
00109         // last optimisation
00110         bool needsOptimization;
00111         
00112         void deleteAllImages();
00113 };
00114 
00115 
00116     
00152 class IMPEX Panorama : public ManagedPanoramaData, public AppBase::DocumentData
00153 {
00154     
00155     public:
00156 
00159         Panorama();
00160 
00163         ~Panorama();
00164         
00165         
00166     // ====================== PanoramaData =========================================
00167         
00168         
00174         Panorama getSubset(const UIntSet & imgs) const;
00175         
00180         Panorama duplicate() const;
00181          
00183         PanoramaData* getNewSubset(const UIntSet& imgs) const
00184          {
00185              return new Panorama(this->getSubset(imgs));
00186          }
00187          
00189         PanoramaData* getNewCopy() const
00190          {
00191              return new Panorama(this->duplicate());
00192          }
00193         
00198         PanoramaData* getUnlinkedSubset(UIntSetVector& imageGroups) const;
00199 
00200     // -- Data Access --
00201         
00202     // = images =    
00203         
00205         std::size_t getNrOfImages() const
00206         {
00207             return state.images.size();
00208         };
00209         
00211         const SrcPanoImage & getImage(std::size_t nr) const
00212         {
00213             assert(nr < state.images.size());
00214             return *state.images[nr];
00215         };
00216 
00218         void setImage(std::size_t nr, const SrcPanoImage & img)
00219         {
00220             setSrcImage(nr, img);
00221         };
00222         
00224     //    unsigned int getImageNr(const PanoImage * image) const;
00225         
00228         unsigned int addImage(const SrcPanoImage &img);
00229 
00231         void mergePanorama(const Panorama &newPano);
00232         
00234 //        int addImageAndLens(const std::string & filename);
00235         
00239         //    unsigned int addImage(const std::string & filename);
00240         
00246         void removeImage(unsigned int nr);
00247         
00252         void swapImages(unsigned int img1, unsigned int img2);
00253 
00258         void moveImage(size_t img1, size_t img2);
00259         
00268         SrcPanoImage getSrcImage(unsigned imgNr) const;
00269         
00276         void setSrcImage(unsigned int nr, const SrcPanoImage & img);
00277         
00284         void setImageFilename(unsigned int img, const std::string & fname);
00285         
00297         void activateImage(unsigned int imgNr, bool active=true);
00298         
00300         UIntSet getActiveImages() const;
00301         
00302         
00303     // = CPs =    
00304         
00306          std::size_t getNrOfCtrlPoints() const
00307         {
00308             return state.ctrlPoints.size();
00309         };
00310         
00312         const ControlPoint & getCtrlPoint(std::size_t nr) const
00313         {
00314             assert(nr < state.ctrlPoints.size());
00315             return state.ctrlPoints[nr];
00316         };
00317         
00319         const CPVector & getCtrlPoints() const
00320             { return state.ctrlPoints; };
00321         
00323         std::vector<unsigned int> getCtrlPointsForImage(unsigned int imgNr) const;
00324         
00327         CPointVector getCtrlPointsVectorForImage(unsigned int imgNr) const;
00328 
00330         void setCtrlPoints(const CPVector & points);
00331         
00333         unsigned int addCtrlPoint(const ControlPoint & point);
00334         
00337         void removeCtrlPoint(unsigned int pNr);
00338 
00341         void removeDuplicateCtrlPoints();
00342         
00345         void changeControlPoint(unsigned int pNr, const ControlPoint & point);
00346         
00348         //    unsigned int getCtrlPointNr(const ControlPoint * point) const;
00349         
00351         int getNextCPTypeLineNumber() const;
00352         
00354         void updateLineCtrlPoints();
00355         
00356         
00363         void updateCtrlPointErrors(const CPVector & controlPoints);
00364         
00371         void updateCtrlPointErrors(const UIntSet & imgs, const CPVector & cps);
00372         
00374         const std::string getICCProfileDesc() const;
00376         void setICCProfileDesc(const std::string& newDesc);
00379         const int getNrOfBands() const;
00381         void setNrOfBands(const int nrBands);
00382 
00383     // = Variables =    
00384         
00386         VariableMapVector getVariables() const;
00387 
00395         const VariableMap getImageVariables(unsigned int imgNr) const;
00396         
00402         virtual void updateVariables(const VariableMapVector & vars);
00403         
00405         virtual void updateVariables(const UIntSet & imgs, const VariableMapVector & var);
00406         
00410         virtual void updateVariables(unsigned int imgNr, const VariableMap & var);
00411         
00417         virtual void updateVariable(unsigned int imgNr, const Variable &var);
00418         
00420         virtual void UpdateFocalLength(UIntSet imgs, double newFocalLength);
00422         virtual void UpdateCropFactor(UIntSet imgs, double newCropFactor);
00423         /* Link image variable functions. Used to group image variables which
00424          * should share the same value. The initial value is the one kept by
00425          * the image with number sourceImgNr.
00426          */
00427 #define image_variable( name, type, default_value ) \
00428         virtual void linkImageVariable##name(unsigned int sourceImgNr, unsigned int destImgNr);
00429 #include "image_variables.h"
00430 #undef image_variable
00431 
00432         /* Unlink image variable functions. Makes a image variable independant
00433          * of the other images.
00434          */
00435 #define image_variable( name, type, default_value ) \
00436         virtual void unlinkImageVariable##name(unsigned int imgNr);
00437 #include "image_variables.h"
00438 #undef image_variable
00439         
00443         virtual void updateWhiteBalance(double redFactor, double blueFactor);
00444 
00446         const double getMaxExposureDifference() const;
00448         const bool hasPossibleStacks() const;
00450         void linkPossibleStacks(bool linkPosition);
00451 
00452     // = Optimise Vector =    
00454         const OptimizeVector & getOptimizeVector() const
00455             { return state.optvec; };
00456 
00458         void setOptimizeVector(const OptimizeVector & optvec);
00459         
00461         const int getOptimizerSwitch() const
00462             { return state.optSwitch;};
00464         void setOptimizerSwitch(const int newSwitch);
00465 
00467         const int getPhotometricOptimizerSwitch() const
00468             { return state.optPhotoSwitch; };
00470         void setPhotometricOptimizerSwitch(const int newSwitch);
00471 
00478     // = Panorama options =    
00479 
00481         const PanoramaOptions & getOptions() const
00482             { return state.options; };
00483 
00488         void setOptions(const PanoramaOptions & opt);
00489         
00490 
00491         
00492     // -- script interface --
00493             
00504         void parseOptimizerScript(std::istream & i,
00505                                   const UIntSet & imgs,
00506                                   VariableMapVector & imgVars,
00507                                   CPVector & ctrlPoints) const;
00508             
00510         void printPanoramaScript(std::ostream & o,
00511                                  const OptimizeVector & optvars,
00512                                  const PanoramaOptions & options,
00513                                  const UIntSet & imgs,
00514                                  bool forPTOptimizer,
00515                                  const std::string & stripPrefix="") const;
00516         
00518         void printStitcherScript(std::ostream & o,
00519                                  const PanoramaOptions & target,
00520                                  const UIntSet & imgs) const;
00521 
00522         
00523         
00524     //=========== ManagedPanoramaData ==============================================
00525 
00526 
00527 
00528     // -- Observing --
00529         
00536         void addObserver(PanoramaObserver *o);
00537         
00546         bool removeObserver(PanoramaObserver *observer);
00547         
00552         void clearObservers();
00553         
00559         const bool hasPendingChanges() const;
00560 
00570         void changeFinished(bool keepDirty);
00571         
00579         void changeFinished()
00580             { changeFinished(false); }
00581         
00587         void imageChanged(unsigned int imgNr);
00588 
00590         void updateMasksForImage(unsigned int imgNr, MaskPolygonVector newMasks);
00596         void updateMasks(bool convertPosMaskToNeg=false);
00599         void transferMask(MaskPolygon mask,unsigned int imgNr, const UIntSet& targetImgs);
00601         void updateOptimizeVector();
00603         std::set<size_t> getRefImages();
00606         void checkRefOptStatus(bool& linkRefImgsYaw, bool& linkRefImgsPitch, bool& linkRefImgsRoll);
00607 
00608         // -- Memento interface --
00609         
00611         virtual PanoramaDataMemento* getNewMemento() const;
00612         
00614         virtual bool setMementoToCopyOf(const PanoramaDataMemento* const memento);
00615         
00617         PanoramaMemento getMemento() const
00618             { return state; }
00619         
00621         void setMemento(const PanoramaMemento& memento);
00622         
00623         
00624     // -- Optimization Status --
00625         
00629         bool needsOptimization()
00630             { return state.needsOptimization; };
00631 
00633         void markAsOptimized(bool optimized=true)
00634             { state.needsOptimization = !optimized; };
00635         
00636 
00637 
00638     //=========== Document Data ====================================================
00639 
00640     public:
00645         ReadWriteError readData(std::istream& dataInput, std::string documentType = "");
00646         
00648         ReadWriteError writeData(std::ostream& dataOutput, std::string documentType = "");
00649 
00651         bool isDirty() const
00652         {
00653             if (dirty != AppBase::DocumentData::isDirty())
00654                 DEBUG_WARN("modification status mismatch.");
00655                 
00656             return dirty;
00657         }
00658         
00660         virtual void clearDirty()
00661         {
00662             AppBase::DocumentData::clearDirty();
00663             dirty = false;
00664         }
00665         
00666     protected:
00667         void setDirty(const bool& dirty = true)
00668         { 
00669             AppBase::DocumentData::setDirty(dirty);
00670             
00671             this->dirty = dirty;
00672         }
00673         
00674         
00675     // == additional methods for documents ==
00676         
00677     public:
00679         void setFilePrefix(std::string prefix)
00680             { imgFilePrefix = prefix; }
00681         
00682     protected:
00683         std::string getFilePrefix() const
00684             { return imgFilePrefix; }
00685         
00686     //=========== Internal methods =================================================
00687         
00688     public:
00690         void reset();
00691         
00692     protected:
00695         void adjustVarLinks();
00696     private:
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 } // namespace
00720 #endif // _PANORAMA_H

Generated on 6 Dec 2016 for Hugintrunk by  doxygen 1.4.7