[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin_base/panodata/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 #include <hugin_shared.h>
00028 #include <appbase/DocumentData.h>
00029 #include <panodata/PanoramaData.h>
00030 
00031 
00032 namespace HuginBase {
00033     
00034     
00035     
00036     
00044 class IMPEX PanoramaMemento : public PanoramaDataMemento
00045 {
00046         
00047         friend class Panorama;
00048         
00049     public:
00050         PanoramaMemento()
00051         : PanoramaDataMemento(), needsOptimization(false)
00052         {};
00053         
00055         PanoramaMemento(const PanoramaMemento & o);
00056         
00058         PanoramaMemento& operator=(const PanoramaMemento & o);
00059         
00060         virtual ~PanoramaMemento();
00061         
00062         
00063     protected:
00065         //  enum PTFileFormat { PTFILE_HUGIN, PTFILE_PTGUI, PTFILE_PTA };
00066         
00071         bool loadPTScript(std::istream & i, int & ptoVersion, const std::string & prefix = "");
00072     
00073         
00074     private:
00075         enum PTParseState {
00076             P_NONE,
00077             P_OUTPUT,
00078             P_MODIFIER,
00079             P_IMAGE,
00080             P_OPTIMIZE,
00081             P_CP
00082         };
00083         
00091         std::vector<SrcPanoImage *> images;
00092         
00093         CPVector ctrlPoints;
00094         
00095         PanoramaOptions options;
00096         
00097         OptimizeVector optvec;
00098         
00099         // indicates that changes have been made to
00100         // control points or lens parameters after the
00101         // last optimisation
00102         bool needsOptimization;
00103         
00104         void deleteAllImages();
00105 };
00106 
00107 
00108     
00144 class IMPEX Panorama : public ManagedPanoramaData, public AppBase::DocumentData
00145 {
00146     
00147     public:
00148 
00151         Panorama();
00152 
00155         ~Panorama();
00156         
00157         
00158     // ====================== PanoramaData =========================================
00159         
00160         
00166         Panorama getSubset(const UIntSet & imgs) const;
00167         
00172         Panorama duplicate() const;
00173          
00175         PanoramaData* getNewSubset(const UIntSet& imgs) const
00176          {
00177              return new Panorama(this->getSubset(imgs));
00178          }
00179          
00181         PanoramaData* getNewCopy() const
00182          {
00183              return new Panorama(this->duplicate());
00184          }
00185         
00186         
00187     // -- Data Access --
00188         
00189     // = images =    
00190         
00192         std::size_t getNrOfImages() const
00193         {
00194             return state.images.size();
00195         };
00196         
00198         const SrcPanoImage & getImage(std::size_t nr) const
00199         {
00200             assert(nr < state.images.size());
00201             return *state.images[nr];
00202         };
00203 
00205         void setImage(std::size_t nr, SrcPanoImage img)
00206         {
00207             setSrcImage(nr, img);
00208         };
00209         
00211     //    unsigned int getImageNr(const PanoImage * image) const;
00212         
00215         unsigned int addImage(const SrcPanoImage &img);
00216 
00218         void mergePanorama(const Panorama &newPano);
00219         
00221 //        int addImageAndLens(const std::string & filename);
00222         
00226         //    unsigned int addImage(const std::string & filename);
00227         
00233         void removeImage(unsigned int nr);
00234         
00239         void swapImages(unsigned int img1, unsigned int img2);
00240         
00249         SrcPanoImage getSrcImage(unsigned imgNr) const;
00250         
00257         void setSrcImage(unsigned int nr, const SrcPanoImage & img);
00258         
00265         void setImageFilename(unsigned int img, const std::string & fname);
00266         
00269         void setImageOptions(unsigned int i, const ImageOptions & opts);
00270         
00282         void activateImage(unsigned int imgNr, bool active=true);
00283         
00285         UIntSet getActiveImages() const;
00286         
00287         
00288     // = CPs =    
00289         
00291          std::size_t getNrOfCtrlPoints() const
00292         {
00293             return state.ctrlPoints.size();
00294         };
00295         
00297         const ControlPoint & getCtrlPoint(std::size_t nr) const
00298         {
00299             assert(nr < state.ctrlPoints.size());
00300             return state.ctrlPoints[nr];
00301         };
00302         
00304         const CPVector & getCtrlPoints() const
00305             { return state.ctrlPoints; };
00306         
00308         std::vector<unsigned int> getCtrlPointsForImage(unsigned int imgNr) const;
00309         
00311         void setCtrlPoints(const CPVector & points);
00312         
00314         unsigned int addCtrlPoint(const ControlPoint & point);
00315         
00318         void removeCtrlPoint(unsigned int pNr);
00319 
00322         void removeDuplicateCtrlPoints();
00323         
00326         void changeControlPoint(unsigned int pNr, const ControlPoint & point);
00327         
00329         //    unsigned int getCtrlPointNr(const ControlPoint * point) const;
00330         
00332         int getNextCPTypeLineNumber() const;
00333         
00335         void updateLineCtrlPoints();
00336         
00337         
00344         void updateCtrlPointErrors(const CPVector & controlPoints);
00345         
00352         void updateCtrlPointErrors(const UIntSet & imgs, const CPVector & cps);
00353         
00354         
00355     // = Variables =    
00356         
00358         VariableMapVector getVariables() const;
00359 
00367         const VariableMap getImageVariables(unsigned int imgNr) const;
00368         
00374         virtual void updateVariables(const VariableMapVector & vars);
00375         
00377         virtual void updateVariables(const UIntSet & imgs, const VariableMapVector & var);
00378         
00382         virtual void updateVariables(unsigned int imgNr, const VariableMap & var);
00383         
00389         virtual void updateVariable(unsigned int imgNr, const Variable &var);
00390         
00392         virtual void UpdateFocalLength(UIntSet imgs, double newFocalLength);
00394         virtual void UpdateCropFactor(UIntSet imgs, double newCropFactor);
00395         /* Link image variable functions. Used to group image variables which
00396          * should share the same value. The initial value is the one kept by
00397          * the image with number sourceImgNr.
00398          */
00399 #define image_variable( name, type, default_value ) \
00400         virtual void linkImageVariable##name(unsigned int sourceImgNr, unsigned int destImgNr);
00401 #include "image_variables.h"
00402 #undef image_variable
00403 
00404         /* Unlink image variable functions. Makes a image variable independant
00405          * of the other images.
00406          */
00407 #define image_variable( name, type, default_value ) \
00408         virtual void unlinkImageVariable##name(unsigned int imgNr);
00409 #include "image_variables.h"
00410 #undef image_variable
00411         
00412     // = Optimise Vector =    
00414         const OptimizeVector & getOptimizeVector() const
00415             { return state.optvec; };
00416 
00418         void setOptimizeVector(const OptimizeVector & optvec);
00419         
00426     // = Panorama options =    
00427 
00429         const PanoramaOptions & getOptions() const
00430             { return state.options; };
00431 
00436         void setOptions(const PanoramaOptions & opt);
00437         
00438 
00439         
00440     // -- script interface --
00441             
00452         void parseOptimizerScript(std::istream & i,
00453                                   const UIntSet & imgs,
00454                                   VariableMapVector & imgVars,
00455                                   CPVector & ctrlPoints) const;
00456             
00458         void printPanoramaScript(std::ostream & o,
00459                                  const OptimizeVector & optvars,
00460                                  const PanoramaOptions & options,
00461                                  const UIntSet & imgs,
00462                                  bool forPTOptimizer,
00463                                  const std::string & stripPrefix="") const;
00464         
00466         void printStitcherScript(std::ostream & o,
00467                                  const PanoramaOptions & target,
00468                                  const UIntSet & imgs) const;
00469 
00470         
00471         
00472     //=========== ManagedPanoramaData ==============================================
00473 
00474 
00475 
00476     // -- Observing --
00477         
00484         void addObserver(PanoramaObserver *o);
00485         
00494         bool removeObserver(PanoramaObserver *observer);
00495         
00500         void clearObservers();
00501         
00511         void changeFinished(bool keepDirty);
00512         
00522         void changeFinished()
00523             { changeFinished(false); }
00524         
00530         void imageChanged(unsigned int imgNr);
00531 
00533         void updateMasksForImage(unsigned int imgNr, MaskPolygonVector newMasks);
00539         void updateMasks();
00540         
00541         
00542         // -- Memento interface --
00543         
00545         virtual PanoramaDataMemento* getNewMemento() const;
00546         
00548         virtual bool setMementoToCopyOf(const PanoramaDataMemento* const memento);
00549         
00551         PanoramaMemento getMemento() const
00552             { return state; }
00553         
00555         void setMemento(const PanoramaMemento& memento);
00556         
00557         
00558     // -- Optimization Status --
00559         
00563         bool needsOptimization()
00564             { return state.needsOptimization; };
00565 
00567         void markAsOptimized(bool optimized=true)
00568             { state.needsOptimization = !optimized; };
00569         
00570 
00571 
00572     //=========== Document Data ====================================================
00573 
00574     public:
00579         ReadWriteError readData(std::istream& dataInput, std::string documentType = "");
00580         
00582         ReadWriteError writeData(std::ostream& dataOutput, std::string documentType = "");
00583 
00585         bool isDirty() const
00586         {
00587             if (dirty != AppBase::DocumentData::isDirty())
00588                 DEBUG_WARN("modification status mismatch.");
00589                 
00590             return dirty;
00591         }
00592         
00594         void clearDirty()
00595         {
00596             AppBase::DocumentData::clearDirty();
00597             
00598             dirty = false;
00599             changeFinished(true);
00600         }
00601         
00602     protected:
00603         void setDirty(const bool& dirty = true)
00604         { 
00605             AppBase::DocumentData::setDirty(dirty);
00606             
00607             this->dirty = dirty;
00608         }
00609         
00610         
00611     // == additional methods for documents ==
00612         
00613     public:
00615         void setFilePrefix(std::string prefix)
00616             { imgFilePrefix = prefix; }
00617         
00618     protected:
00619         std::string getFilePrefix() const
00620             { return imgFilePrefix; }
00621         
00622     //=========== Internal methods =================================================
00623         
00624     public:
00626         void reset();
00627         
00628     protected:
00631         void adjustVarLinks();
00632 
00633 
00635     //    void notifyImageAdded(unsigned int imgNr);
00636 
00638     //    void notifyImageRemoved(unsigned int imgNr);
00639 
00641     //    void notifyImageChanged(unsigned int imgNr);
00642 
00643         
00644 
00645     private:
00646 
00647         // data
00648 //        enum ProcessType { NO_PROCESS, OPTIMIZER, STITCHER };
00649 
00650         // to run stitcher & optimizer
00651 //        ProcessType currentProcess;
00652 //        std::string optimizerExe;
00653 //        std::string stitcherExe;
00654 //        std::string PTScriptFile;
00655         
00656         //
00657         std::string imgFilePrefix;
00658 
00660         bool dirty;
00661 
00662         PanoramaMemento state;
00663         std::set<PanoramaObserver *> observers;
00665         UIntSet changedImages;
00666 
00667         bool m_forceImagesUpdate;
00668 
00669         std::set<std::string> m_ptoptimizerVarNames;
00670 };
00671 
00672 
00673 
00674 
00675 } // namespace
00676 
00677 
00678 
00679 
00680 #endif // _PANORAMA_H

Generated on Mon Sep 20 01:01:26 2010 for Hugintrunk by doxygen 1.3.9.1