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(), needsOptimization(false), optSwitch(0), optPhotoSwitch(0)
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         
00191         
00192     // -- Data Access --
00193         
00194     // = images =    
00195         
00197         std::size_t getNrOfImages() const
00198         {
00199             return state.images.size();
00200         };
00201         
00203         const SrcPanoImage & getImage(std::size_t nr) const
00204         {
00205             assert(nr < state.images.size());
00206             return *state.images[nr];
00207         };
00208 
00210         void setImage(std::size_t nr, const SrcPanoImage & img)
00211         {
00212             setSrcImage(nr, img);
00213         };
00214         
00216     //    unsigned int getImageNr(const PanoImage * image) const;
00217         
00220         unsigned int addImage(const SrcPanoImage &img);
00221 
00223         void mergePanorama(const Panorama &newPano);
00224         
00226 //        int addImageAndLens(const std::string & filename);
00227         
00231         //    unsigned int addImage(const std::string & filename);
00232         
00238         void removeImage(unsigned int nr);
00239         
00244         void swapImages(unsigned int img1, unsigned int img2);
00245 
00250         void moveImage(size_t img1, size_t img2);
00251         
00260         SrcPanoImage getSrcImage(unsigned imgNr) const;
00261         
00268         void setSrcImage(unsigned int nr, const SrcPanoImage & img);
00269         
00276         void setImageFilename(unsigned int img, const std::string & fname);
00277         
00289         void activateImage(unsigned int imgNr, bool active=true);
00290         
00292         UIntSet getActiveImages() const;
00293         
00294         
00295     // = CPs =    
00296         
00298          std::size_t getNrOfCtrlPoints() const
00299         {
00300             return state.ctrlPoints.size();
00301         };
00302         
00304         const ControlPoint & getCtrlPoint(std::size_t nr) const
00305         {
00306             assert(nr < state.ctrlPoints.size());
00307             return state.ctrlPoints[nr];
00308         };
00309         
00311         const CPVector & getCtrlPoints() const
00312             { return state.ctrlPoints; };
00313         
00315         std::vector<unsigned int> getCtrlPointsForImage(unsigned int imgNr) const;
00316         
00319         CPointVector getCtrlPointsVectorForImage(unsigned int imgNr) const;
00320 
00322         void setCtrlPoints(const CPVector & points);
00323         
00325         unsigned int addCtrlPoint(const ControlPoint & point);
00326         
00329         void removeCtrlPoint(unsigned int pNr);
00330 
00333         void removeDuplicateCtrlPoints();
00334         
00337         void changeControlPoint(unsigned int pNr, const ControlPoint & point);
00338         
00340         //    unsigned int getCtrlPointNr(const ControlPoint * point) const;
00341         
00343         int getNextCPTypeLineNumber() const;
00344         
00346         void updateLineCtrlPoints();
00347         
00348         
00355         void updateCtrlPointErrors(const CPVector & controlPoints);
00356         
00363         void updateCtrlPointErrors(const UIntSet & imgs, const CPVector & cps);
00364         
00366         const std::string getICCProfileDesc() const;
00368         void setICCProfileDesc(const std::string& newDesc);
00369 
00370     // = Variables =    
00371         
00373         VariableMapVector getVariables() const;
00374 
00382         const VariableMap getImageVariables(unsigned int imgNr) const;
00383         
00389         virtual void updateVariables(const VariableMapVector & vars);
00390         
00392         virtual void updateVariables(const UIntSet & imgs, const VariableMapVector & var);
00393         
00397         virtual void updateVariables(unsigned int imgNr, const VariableMap & var);
00398         
00404         virtual void updateVariable(unsigned int imgNr, const Variable &var);
00405         
00407         virtual void UpdateFocalLength(UIntSet imgs, double newFocalLength);
00409         virtual void UpdateCropFactor(UIntSet imgs, double newCropFactor);
00410         /* Link image variable functions. Used to group image variables which
00411          * should share the same value. The initial value is the one kept by
00412          * the image with number sourceImgNr.
00413          */
00414 #define image_variable( name, type, default_value ) \
00415         virtual void linkImageVariable##name(unsigned int sourceImgNr, unsigned int destImgNr);
00416 #include "image_variables.h"
00417 #undef image_variable
00418 
00419         /* Unlink image variable functions. Makes a image variable independant
00420          * of the other images.
00421          */
00422 #define image_variable( name, type, default_value ) \
00423         virtual void unlinkImageVariable##name(unsigned int imgNr);
00424 #include "image_variables.h"
00425 #undef image_variable
00426         
00430         virtual void updateWhiteBalance(double redFactor, double blueFactor);
00431 
00433         const double getMaxExposureDifference() const;
00435         const bool hasPossibleStacks() const;
00437         void linkPossibleStacks(bool linkPosition);
00438 
00439     // = Optimise Vector =    
00441         const OptimizeVector & getOptimizeVector() const
00442             { return state.optvec; };
00443 
00445         void setOptimizeVector(const OptimizeVector & optvec);
00446         
00448         const int getOptimizerSwitch() const
00449             { return state.optSwitch;};
00451         void setOptimizerSwitch(const int newSwitch);
00452 
00454         const int getPhotometricOptimizerSwitch() const
00455             { return state.optPhotoSwitch; };
00457         void setPhotometricOptimizerSwitch(const int newSwitch);
00458 
00465     // = Panorama options =    
00466 
00468         const PanoramaOptions & getOptions() const
00469             { return state.options; };
00470 
00475         void setOptions(const PanoramaOptions & opt);
00476         
00477 
00478         
00479     // -- script interface --
00480             
00491         void parseOptimizerScript(std::istream & i,
00492                                   const UIntSet & imgs,
00493                                   VariableMapVector & imgVars,
00494                                   CPVector & ctrlPoints) const;
00495             
00497         void printPanoramaScript(std::ostream & o,
00498                                  const OptimizeVector & optvars,
00499                                  const PanoramaOptions & options,
00500                                  const UIntSet & imgs,
00501                                  bool forPTOptimizer,
00502                                  const std::string & stripPrefix="") const;
00503         
00505         void printStitcherScript(std::ostream & o,
00506                                  const PanoramaOptions & target,
00507                                  const UIntSet & imgs) const;
00508 
00509         
00510         
00511     //=========== ManagedPanoramaData ==============================================
00512 
00513 
00514 
00515     // -- Observing --
00516         
00523         void addObserver(PanoramaObserver *o);
00524         
00533         bool removeObserver(PanoramaObserver *observer);
00534         
00539         void clearObservers();
00540         
00546         const bool hasPendingChanges() const;
00547 
00557         void changeFinished(bool keepDirty);
00558         
00566         void changeFinished()
00567             { changeFinished(false); }
00568         
00574         void imageChanged(unsigned int imgNr);
00575 
00577         void updateMasksForImage(unsigned int imgNr, MaskPolygonVector newMasks);
00583         void updateMasks(bool convertPosMaskToNeg=false);
00586         void transferMask(MaskPolygon mask,unsigned int imgNr, const UIntSet& targetImgs);
00588         void updateOptimizeVector();
00590         std::set<size_t> getRefImages();
00593         void checkRefOptStatus(bool& linkRefImgsYaw, bool& linkRefImgsPitch, bool& linkRefImgsRoll);
00594 
00595         // -- Memento interface --
00596         
00598         virtual PanoramaDataMemento* getNewMemento() const;
00599         
00601         virtual bool setMementoToCopyOf(const PanoramaDataMemento* const memento);
00602         
00604         PanoramaMemento getMemento() const
00605             { return state; }
00606         
00608         void setMemento(const PanoramaMemento& memento);
00609         
00610         
00611     // -- Optimization Status --
00612         
00616         bool needsOptimization()
00617             { return state.needsOptimization; };
00618 
00620         void markAsOptimized(bool optimized=true)
00621             { state.needsOptimization = !optimized; };
00622         
00623 
00624 
00625     //=========== Document Data ====================================================
00626 
00627     public:
00632         ReadWriteError readData(std::istream& dataInput, std::string documentType = "");
00633         
00635         ReadWriteError writeData(std::ostream& dataOutput, std::string documentType = "");
00636 
00638         bool isDirty() const
00639         {
00640             if (dirty != AppBase::DocumentData::isDirty())
00641                 DEBUG_WARN("modification status mismatch.");
00642                 
00643             return dirty;
00644         }
00645         
00647         virtual void clearDirty()
00648         {
00649             AppBase::DocumentData::clearDirty();
00650             dirty = false;
00651         }
00652         
00653     protected:
00654         void setDirty(const bool& dirty = true)
00655         { 
00656             AppBase::DocumentData::setDirty(dirty);
00657             
00658             this->dirty = dirty;
00659         }
00660         
00661         
00662     // == additional methods for documents ==
00663         
00664     public:
00666         void setFilePrefix(std::string prefix)
00667             { imgFilePrefix = prefix; }
00668         
00669     protected:
00670         std::string getFilePrefix() const
00671             { return imgFilePrefix; }
00672         
00673     //=========== Internal methods =================================================
00674         
00675     public:
00677         void reset();
00678         
00679     protected:
00682         void adjustVarLinks();
00683     private:
00685         void centerCrop(unsigned int imgNr);
00687         vigra::Rect2D centerCropImage(unsigned int imgNr);
00689         void updateCropMode(unsigned int imgNr);
00690 
00691         std::string imgFilePrefix;
00692 
00694         bool dirty;
00695 
00696         PanoramaMemento state;
00697         std::list<PanoramaObserver *> observers;
00699         UIntSet changedImages;
00700 
00701         bool m_forceImagesUpdate;
00702 
00703         std::set<std::string> m_ptoptimizerVarNames;
00704 };
00705 
00706 } // namespace
00707 #endif // _PANORAMA_H

Generated on 2 Sep 2015 for Hugintrunk by  doxygen 1.4.7