[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

hugin1/PT/PanoCommand.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _Hgn1_PANOCOMMAND_H
00025 #define _Hgn1_PANOCOMMAND_H
00026 
00027 
00028 #include <huginapp/PanoCommand.h>
00029 
00030 //#include "PanoImage.h"
00031 #include "Panorama.h"
00032 //#include "PanoToolsInterface.h"
00033 #include <panodata/StandardImageVariableGroups.h>
00034 
00035 
00036 
00037 namespace PT {
00038 
00041     class PanoCommand : public HuginBase::PanoCommand<std::string>
00042     {
00043         public:
00044             PanoCommand(Panorama& p)
00045               : HuginBase::PanoCommand<std::string>(p), o_pano(p)
00046             {
00047             };
00048 
00049             virtual ~PanoCommand() {};
00050             
00051             virtual bool processPanorama(HuginBase::ManagedPanoramaData& panoramaData)
00052             {
00053                 return processPanorama(o_pano);
00054             }
00055             
00056             virtual bool processPanorama(Panorama& pano) { return true; };
00057             
00058         protected:
00059             Panorama& o_pano;
00060     };
00061 
00062     
00063     //=========================================================================
00064     //=========================================================================
00065     
00066 
00068     class NewPanoCmd : public PanoCommand
00069     {
00070     public:
00071         NewPanoCmd(Panorama & pano)
00072             : PanoCommand(pano)
00073             { };
00074 
00075         virtual bool processPanorama(Panorama& pano)
00076             {
00077                 pano.reset();
00078                 pano.changeFinished();
00079 
00080                 return true;
00081             }
00082         
00083         virtual std::string getName() const
00084             {
00085                 return "new panorama";
00086             }
00087     };
00088 
00089     //=========================================================================
00090     //=========================================================================
00091 
00093     class AddImagesCmd : public PanoCommand
00094     {
00095     public:
00096         AddImagesCmd(Panorama & pano, const std::vector<SrcPanoImage> & images)
00097             : PanoCommand(pano), imgs(images)
00098             { };
00099 
00100         virtual bool processPanorama(Panorama& pano)
00101             {
00102                 std::vector<SrcPanoImage>::const_iterator it;
00103                 for (it = imgs.begin(); it != imgs.end(); ++it) {
00104                     pano.addImage(*it);
00105                 }
00106                 pano.changeFinished();
00107 
00108                 return true;
00109             }
00110         
00111         virtual std::string getName() const
00112             {
00113                 return "add images";
00114             }
00115 
00116     private:
00117         std::vector<SrcPanoImage> imgs;
00118     };
00119 
00120 
00121     //=========================================================================
00122     //=========================================================================
00123 
00124 
00129     class RemoveImageCmd : public PanoCommand
00130     {
00131     public:
00132         RemoveImageCmd(Panorama & p, unsigned int imgNr)
00133             : PanoCommand(p), imgNr(imgNr)
00134             { };
00135 
00136         virtual bool processPanorama(Panorama& pano)
00137             {
00138                 pano.removeImage(imgNr);
00139                 pano.changeFinished();
00140 
00141                 return true;
00142             }
00143         
00144         virtual std::string getName() const
00145             {
00146                 return "remove image";
00147             }
00148 
00149     private:
00150         unsigned int imgNr;
00151     };
00152 
00153     //=========================================================================
00154     //=========================================================================
00155 
00156 
00160     class RemoveImagesCmd : public PanoCommand
00161     {
00162     public:
00163         RemoveImagesCmd(Panorama & p, UIntSet imgs)
00164             : PanoCommand(p), imgNrs(imgs)
00165             { };
00166 
00167         virtual bool processPanorama(Panorama& pano)
00168             {
00169                 for (UIntSet::reverse_iterator it = imgNrs.rbegin();
00170                      it != imgNrs.rend(); ++it)
00171                 {
00172                     pano.removeImage(*it);
00173                 }
00174                 pano.changeFinished();
00175 
00176                 return true;
00177             }
00178         
00179         virtual std::string getName() const
00180             {
00181                 return "remove images";
00182             }
00183 
00184     private:
00185         UIntSet imgNrs;
00186     };
00187 
00188     //=========================================================================
00189     //=========================================================================
00190 
00191 #if 0
00192 
00193     class ChangeImageCmd : public PanoCommand
00194     {
00195     public:
00196         Cmd(Panorama & p)
00197             : PanoCommand(p)
00198             { };
00199 
00200         virtual bool processPanorama(Panorama& pano)
00201             {
00202 
00203                 return true;
00204             }
00205         
00206         virtual std::string getName() const
00207             {
00208                 return "unnamed command";
00209             }
00210 
00211     private:
00212     };
00213 #endif
00214 
00215     //=========================================================================
00216     //=========================================================================
00217 
00219     class UpdateVariablesCmd : public PanoCommand
00220     {
00221     public:
00222         UpdateVariablesCmd(Panorama & p, const VariableMapVector & vars)
00223             : PanoCommand(p),
00224               vars(vars)
00225             { };
00226 
00227         virtual bool processPanorama(Panorama& pano)
00228             {
00229                 pano.updateVariables(vars);
00230                 pano.changeFinished();
00231 
00232                 return true;
00233             }
00234         
00235         virtual std::string getName() const
00236             {
00237                 return "update Variables";
00238             }
00239 
00240     private:
00241         VariableMapVector vars;
00242     };
00243 
00244     //=========================================================================
00245     //=========================================================================
00246 
00248     class UpdateCPsCmd : public PanoCommand
00249     {
00250     public:
00251         UpdateCPsCmd(Panorama & p, const CPVector & cps)
00252             : PanoCommand(p),
00253               cps(cps)
00254             { };
00255 
00256         virtual bool processPanorama(Panorama& pano)
00257             {
00258                 CPVector::const_iterator it;
00259                 unsigned int i=0;
00260                 for (it = cps.begin(); it != cps.end(); ++it, i++) {
00261                     pano.changeControlPoint(i, *it);
00262                 }
00263                 pano.changeFinished();
00264 
00265                 return true;
00266             }
00267         
00268         virtual std::string getName() const
00269             {
00270                 return "update control points";
00271             }
00272 
00273     private:
00274         CPVector cps;
00275     };
00276 
00277     //=========================================================================
00278     //=========================================================================
00279 
00281     class UpdateVariablesCPCmd : public PanoCommand
00282     {
00283     public:
00284         UpdateVariablesCPCmd(Panorama & p, const VariableMapVector & vars,
00285                              const CPVector & cps)
00286             : PanoCommand(p),
00287               vars(vars), cps(cps)
00288             { };
00289 
00290         virtual bool processPanorama(Panorama& pano)
00291             {
00292                 pano.updateVariables(vars);
00293                 pano.updateCtrlPointErrors(cps);
00294                 pano.changeFinished();
00295 
00296                 return true;
00297             }
00298         
00299         virtual std::string getName() const
00300             {
00301                 return "update Variables";
00302             }
00303 
00304     private:
00305         VariableMapVector vars;
00306         CPVector cps;
00307     };
00308 
00309 
00310     //=========================================================================
00311     //=========================================================================
00312 
00314     class UpdateVariablesCPSetCmd : public PanoCommand
00315     {
00316     public:
00317         UpdateVariablesCPSetCmd(Panorama & p, UIntSet imgs, const VariableMapVector & vars,
00318                                 const CPVector & cps)
00319             : PanoCommand(p),
00320               m_imgs(imgs),
00321               vars(vars), cps(cps)
00322             { };
00323 
00324         virtual bool processPanorama(Panorama& pano)
00325             {
00326                 pano.updateVariables(m_imgs, vars);
00327                 pano.updateCtrlPointErrors(m_imgs, cps);
00328                 pano.markAsOptimized();
00329                 pano.changeFinished();
00330 
00331                 return true;
00332             }
00333         
00334         virtual std::string getName() const
00335             {
00336                 return "update Variables";
00337             }
00338 
00339     private:
00340         UIntSet m_imgs;
00341         VariableMapVector vars;
00342         CPVector cps;
00343     };
00344 
00345     //=========================================================================
00346     //=========================================================================
00347 
00349     class UpdateImageVariablesCmd : public PanoCommand
00350     {
00351     public:
00352         UpdateImageVariablesCmd(Panorama & p, unsigned int ImgNr, const VariableMap & vars)
00353             : PanoCommand(p), imgNr(ImgNr),
00354               vars(vars)
00355             { };
00356 
00357         virtual bool processPanorama(Panorama& pano)
00358             {
00359                 pano.updateVariables(imgNr, vars);
00360                 pano.changeFinished();
00361 
00362                 return true;
00363             }
00364         
00365         virtual std::string getName() const
00366             {
00367                 return "update image variables";
00368             }
00369 
00370     private:
00371         unsigned int imgNr;
00372         VariableMap vars;
00373     };
00374 
00375     //=========================================================================
00376     //=========================================================================
00377 
00379     class UpdateImagesVariablesCmd : public PanoCommand
00380     {
00381     public:
00382         UpdateImagesVariablesCmd(Panorama & p, const UIntSet & change, const VariableMapVector & vars)
00383             : PanoCommand(p), change(change),
00384               vars(vars)
00385             { };
00386 
00387         virtual bool processPanorama(Panorama& pano)
00388             {
00389                 UIntSet::iterator it;
00390                 VariableMapVector::const_iterator v_it = vars.begin();
00391                 for (it = change.begin(); it != change.end(); ++it) {
00392                     pano.updateVariables(*it, *v_it);
00393                     ++v_it;
00394                 }
00395                 pano.changeFinished();
00396 
00397                 return true;
00398             }
00399         
00400         virtual std::string getName() const
00401             {
00402                 return "update image variables";
00403             }
00404 
00405     private:
00406         UIntSet change;
00407         VariableMapVector vars;
00408     };
00409 
00410 
00411     class UpdateOptimizeVectorCmd : public PanoCommand
00412     {
00413     public:
00414         UpdateOptimizeVectorCmd(Panorama &p, OptimizeVector optvec)
00415             : PanoCommand(p),
00416               m_optvec(optvec)
00417         { };
00418 
00419     virtual bool processPanorama(Panorama & pano)
00420         {
00421             pano.setOptimizeVector(m_optvec);
00422             pano.changeFinished();
00423             return true;
00424         }
00425 
00426     virtual std::string getName() const
00427         {
00428             return "update optimize vector";
00429         }
00430 
00431     private:
00432         OptimizeVector m_optvec;
00433         int mode;
00434 
00435     };
00436         
00437 
00438 
00439     //=========================================================================
00440     //=========================================================================
00441 
00443     class SetVariableCmd : public PanoCommand
00444     {
00445     public:
00446         SetVariableCmd(Panorama & p, const UIntSet & images, const Variable & var)
00447             : PanoCommand(p), images(images),
00448               var(var)
00449             { };
00450 
00451         virtual bool processPanorama(Panorama& pano)
00452             {
00453                 UIntSet::iterator it;
00454                 for (it = images.begin(); it != images.end(); ++it) {
00455                     pano.updateVariable(*it, var);
00456                 }
00457                 pano.changeFinished();
00458 
00459                 return true;
00460             }
00461         
00462         virtual std::string getName() const
00463             {
00464                 return "set image variable";
00465             }
00466 
00467     private:
00468         UIntSet images;
00469         Variable var;
00470     };
00471 
00472 
00473     //=========================================================================
00474     //=========================================================================
00475 
00476 
00478     class CenterPanoCmd : public PanoCommand
00479     {
00480     public:
00481         CenterPanoCmd(Panorama & p )
00482             : PanoCommand(p)
00483             { }
00484 
00485         virtual bool processPanorama(Panorama& pano)
00486             {
00487                 pano.centerHorizontically();
00488                 pano.changeFinished();
00489 
00490                 return true;
00491             }
00492         
00493         virtual std::string getName() const
00494             {
00495                 return "center panorama";
00496             }
00497 
00498     private:
00499     };
00500 
00501 
00502     //=========================================================================
00503     //=========================================================================
00504 
00505 
00507     class StraightenPanoCmd : public PanoCommand
00508     {
00509     public:
00510         StraightenPanoCmd(Panorama & p )
00511             : PanoCommand(p)
00512             { }
00513 
00514         virtual bool processPanorama(Panorama& pano)
00515             {
00516                 pano.straighten();
00517                 pano.changeFinished();
00518 
00519                 return true;
00520             }
00521         
00522         virtual std::string getName() const
00523             {
00524                 return "center panorama";
00525             }
00526 
00527     private:
00528     };
00529 
00530 
00531     //=========================================================================
00532     //=========================================================================
00533 
00534 
00536     class AddCtrlPointCmd : public PanoCommand
00537     {
00538     public:
00539         AddCtrlPointCmd(Panorama & p, const ControlPoint & cpoint)
00540             : PanoCommand(p), point(cpoint)
00541             { }
00542 
00543         virtual bool processPanorama(Panorama& pano)
00544             {
00545                 pano.addCtrlPoint(point);
00546                 pano.changeFinished();
00547 
00548                 return true;
00549             }
00550         
00551         virtual std::string getName() const
00552             {
00553                 return "add control point";
00554             }
00555 
00556     private:
00557         ControlPoint point;
00558     };
00559 
00560 
00561 
00562     //=========================================================================
00563     //=========================================================================
00564 
00565 
00567     class AddCtrlPointsCmd : public PanoCommand
00568     {
00569     public:
00570         AddCtrlPointsCmd(Panorama & p, const CPVector & cpoints)
00571             : PanoCommand(p), cps(cpoints)
00572             { }
00573 
00574         virtual bool processPanorama(Panorama& pano)
00575             {
00576                 for (CPVector::iterator it = cps.begin();
00577                      it != cps.end(); ++it)
00578                 {
00579                     pano.addCtrlPoint(*it);
00580                 }
00581                 pano.changeFinished();
00582 
00583                 return true;
00584             }
00585         
00586         virtual std::string getName() const
00587             {
00588                 return "add control points";
00589             }
00590 
00591     private:
00592         CPVector cps;
00593     };
00594 
00595 
00596     //=========================================================================
00597     //=========================================================================
00598 
00599 
00601     class RemoveCtrlPointCmd : public PanoCommand
00602     {
00603     public:
00604         RemoveCtrlPointCmd(Panorama & p, unsigned int cpNr)
00605             : PanoCommand(p), pointNr(cpNr)
00606             { }
00607 
00608         virtual bool processPanorama(Panorama& pano)
00609             {
00610                 pano.removeCtrlPoint(pointNr);
00611                 pano.changeFinished();
00612 
00613                 return true;
00614             }
00615         
00616         virtual std::string getName() const
00617             {
00618                 return "remove control point";
00619             }
00620 
00621     private:
00622         unsigned int pointNr;
00623     };
00624 
00625 
00626     //=========================================================================
00627     //=========================================================================
00628 
00629 
00631     class RemoveCtrlPointsCmd : public PanoCommand
00632     {
00633     public:
00634         RemoveCtrlPointsCmd(Panorama & p, const UIntSet & points )
00635             : PanoCommand(p), m_points(points)
00636             { }
00637 
00638         virtual bool processPanorama(Panorama& pano)
00639             {
00640                 for(UIntSet::reverse_iterator it = m_points.rbegin();
00641                     it != m_points.rend(); ++it)
00642                 {
00643                     pano.removeCtrlPoint(*it);
00644                 }
00645                 pano.changeFinished();
00646 
00647                 return true;
00648             }
00649         
00650         virtual std::string getName() const
00651             {
00652                 return "remove control points";
00653             }
00654 
00655     private:
00656         UIntSet m_points;
00657     };
00658 
00659 
00660     //=========================================================================
00661     //=========================================================================
00662 
00663 
00665     class ChangeCtrlPointCmd : public PanoCommand
00666     {
00667     public:
00668         ChangeCtrlPointCmd(Panorama & p, unsigned int nr, ControlPoint point)
00669             : PanoCommand(p), pNr(nr), point(point)
00670             { }
00671 
00672         virtual bool processPanorama(Panorama& pano)
00673             {
00674                 pano.changeControlPoint(pNr, point);
00675                 pano.changeFinished();
00676 
00677                 return true;
00678             }
00679         
00680         virtual std::string getName() const
00681             {
00682                 return "change control point";
00683             }
00684 
00685     private:
00686         unsigned int pNr;
00687         ControlPoint point;
00688     };
00689 
00690 
00691 
00692     //=========================================================================
00693     //=========================================================================
00694 
00696     class SetActiveImagesCmd : public PanoCommand
00697     {
00698     public:
00699         SetActiveImagesCmd(Panorama & p, UIntSet & active)
00700             : PanoCommand(p), m_active(active)
00701             { };
00702 
00703         virtual bool processPanorama(Panorama& pano)
00704             {
00705                 UIntSet::iterator it;
00706                 LensVector::const_iterator v_it = vect.begin();
00707                                 for (unsigned int i = 0; i < pano.getNrOfImages(); i++) {
00708                     if (set_contains(m_active, i)) {
00709                                                 pano.activateImage(i, true);
00710                                         } else {
00711                                                 pano.activateImage(i, false);
00712                                         }
00713                 }
00714                 pano.changeFinished();
00715 
00716                 return true;
00717             }
00718         
00719         virtual std::string getName() const
00720             {
00721                 return "change lens";
00722             }
00723 
00724     private:
00725         UIntSet m_active;
00726         LensVector vect;
00727     };
00728 
00729 
00730     //=========================================================================
00731     //=========================================================================
00732 
00734     class SwapImagesCmd : public PanoCommand
00735     {
00736     public:
00737         SwapImagesCmd(Panorama & p, unsigned int i1, unsigned int i2)
00738             : PanoCommand(p), m_i1(i1), m_i2(i2)
00739             { };
00740 
00741         virtual bool processPanorama(Panorama& pano)
00742             {
00743                 pano.swapImages(m_i1, m_i2);
00744                 pano.changeFinished();
00745 
00746                 return true;
00747             }
00748         
00749         virtual std::string getName() const
00750             {
00751                 return "swap images";
00752             }
00753 
00754     private:
00755         unsigned int m_i1;
00756         unsigned int m_i2;
00757     };
00758 
00759 
00761     class MergePanoCmd : public PanoCommand
00762     {
00763     public:
00764         MergePanoCmd(Panorama & p, Panorama & p2)
00765             : PanoCommand(p), newPano(p2)
00766             { };
00767 
00768         virtual bool processPanorama(Panorama& pano)
00769             {
00770                 pano.mergePanorama(newPano);
00771                 pano.changeFinished();
00772 
00773                 return true;
00774             }
00775         
00776         virtual std::string getName() const
00777             {
00778                 return "merge panorama";
00779             }
00780 
00781     private:
00782         Panorama newPano;
00783     };
00784 
00785     //=========================================================================
00786     //=========================================================================
00787 
00791     class SetImageOptionsCmd : public PanoCommand
00792     {
00793     public:
00794         SetImageOptionsCmd(Panorama & p, ImageOptions opts, UIntSet imgs)
00795             : PanoCommand(p), options(opts), imgNrs(imgs)
00796             { };
00797 
00798         virtual bool processPanorama(Panorama& pano)
00799             {
00800                 for (UIntSet::iterator it = imgNrs.begin();
00801                      it != imgNrs.end(); ++it)
00802                 {
00803                     pano.setImageOptions(*it, options);
00804                 }
00805                 pano.changeFinished();
00806 
00807                 return true;
00808             }
00809         
00810         virtual std::string getName() const
00811             {
00812                 return "set image options";
00813             }
00814 
00815     private:
00816         ImageOptions options;
00817         UIntSet imgNrs;
00818     };
00819 
00820     //=========================================================================
00821     //=========================================================================
00822 
00826     class UpdateSrcImageCmd : public PanoCommand
00827     {
00828         public:
00829             UpdateSrcImageCmd(Panorama & p, unsigned i, SrcPanoImage img)
00830             : PanoCommand(p), img(img), imgNr(i)
00831             { };
00832 
00833             virtual bool processPanorama(Panorama& pano)
00834             {
00835                 pano.setSrcImage(imgNr, img);
00836                 pano.changeFinished();
00837 
00838                 return true;
00839             }
00840             
00841         virtual std::string getName() const
00842             {
00843                 return "set image options";
00844             }
00845     
00846     private:
00847             SrcPanoImage img;
00848             unsigned imgNr;
00849     };
00850 
00851     //=========================================================================
00852     //=========================================================================
00853 
00857     class UpdateSrcImagesCmd : public PanoCommand
00858     {
00859         public:
00860             UpdateSrcImagesCmd(Panorama & p, UIntSet i, std::vector<SrcPanoImage> imgs)
00861             : PanoCommand(p), imgs(imgs), imgNrs(i)
00862             { };
00863 
00864             virtual bool processPanorama(Panorama& pano)
00865             {
00866                 int i = 0;
00867                 for (UIntSet::iterator it = imgNrs.begin();
00868                      it != imgNrs.end(); ++it)
00869                 {
00870                     pano.setSrcImage(*it, imgs[i]);
00871                     i++;
00872                 }
00873                 pano.changeFinished();
00874 
00875                 return true;
00876             }
00877             
00878         virtual std::string getName() const
00879             {
00880                 return "set multiple image options";
00881             }
00882     
00883     private:
00884             std::vector<SrcPanoImage> imgs;
00885             UIntSet imgNrs;
00886     };
00887 
00888 
00889     //=========================================================================
00890     //=========================================================================
00891 
00895     class UpdateImageOptionsCmd : public PanoCommand
00896     {
00897         public:
00898             UpdateImageOptionsCmd(Panorama & p, std::vector<ImageOptions> opts, UIntSet imgs)
00899             : PanoCommand(p), options(opts), imgNrs(imgs)
00900             {
00901                 assert(opts.size() == imgs.size());
00902             };
00903 
00904             virtual bool processPanorama(Panorama& pano)
00905             {
00906                 int i=0;
00907                 for (UIntSet::iterator it = imgNrs.begin();
00908                      it != imgNrs.end(); ++it)
00909                 {
00910                     pano.setImageOptions(*it, options[i]);
00911                     i++;
00912                 }
00913                 pano.changeFinished();
00914 
00915                 return true;
00916             }
00917             
00918         virtual std::string getName() const
00919             {
00920                 return "set image options";
00921             }
00922     
00923     private:
00924             std::vector<ImageOptions> options;
00925             UIntSet imgNrs;
00926     };
00927 
00928     //=========================================================================
00929     //=========================================================================
00930 
00932     class SetPanoOptionsCmd : public PanoCommand
00933     {
00934     public:
00935         SetPanoOptionsCmd(Panorama & p, const PanoramaOptions & opts)
00936             : PanoCommand(p), options(opts)
00937             { };
00938 
00939         virtual bool processPanorama(Panorama& pano)
00940             {
00941                 pano.setOptions(options);
00942                 pano.changeFinished();
00943 
00944                 return true;
00945             }
00946         
00947         virtual std::string getName() const
00948             {
00949                 return "unnamed command";
00950             }
00951 
00952     private:
00953         PanoramaOptions options;
00954     };
00955 
00956     //=========================================================================
00957     //=========================================================================
00958 
00964     class LoadPTProjectCmd : public PanoCommand
00965     {
00966     public:
00967         LoadPTProjectCmd(Panorama & p, const std::string  & filename, const std::string & prefix = "")
00968             : PanoCommand(p),
00969             filename(filename),
00970             prefix(prefix)
00971             { }
00972 
00973         virtual bool processPanorama(Panorama& pano)
00974             {
00975                 std::ifstream in(filename.c_str());
00976 #ifndef _Hgn1_PANORAMA_H
00977                 PanoramaMemento newPano;
00978                 if (newPano.loadPTScript(in,prefix)) {
00979                     pano.setMemento(newPano);
00980                 } else {
00981                     DEBUG_ERROR("could not load panotools script");
00982                 }
00983 #else
00984                 AppBase::DocumentData::ReadWriteError err = pano.readData(in);
00985                 if (err != AppBase::DocumentData::SUCCESSFUL) {
00986                     DEBUG_ERROR("could not load panotools script");
00987                     return false;
00988                 }
00989 #endif
00990                 
00991                 in.close();
00992                 pano.changeFinished();
00993 
00994                 return true;
00995             }
00996         
00997         virtual std::string getName() const
00998             {
00999                 return "load project";
01000             }
01001 
01002     private:
01003         const std::string &filename;
01004         const std::string &prefix;
01005     };
01006 
01007     //=========================================================================
01008     //=========================================================================
01009 
01012     class SetVigCorrCmd : public PanoCommand
01013     {
01014         public:
01015             SetVigCorrCmd(Panorama & p, unsigned int imageNr,
01016                           unsigned int vigCorrMode, std::vector<double> & coeff,
01017                           const std::string & flatfield)
01018             : PanoCommand(p), m_imageNr(imageNr),
01019               m_mode(vigCorrMode), m_coeff(coeff), m_flat(flatfield)
01020             { };
01021 
01022             virtual bool processPanorama(Panorama& pano)
01023             {
01024                 // set data inside panorama options
01025                 // modify panorama options.
01026                 PT::ImageOptions opts = pano.getImage(m_imageNr).getOptions();
01027                 opts.m_vigCorrMode = m_mode;
01028                 opts.m_flatfield = m_flat;
01029                 pano.setImageOptions(m_imageNr, opts);
01030                 pano.changeFinished();
01031 
01032                 return true;
01033             }
01034             
01035         virtual std::string getName() const
01036             {
01037                 return "set image options";
01038             }
01039     
01040     private:
01041             ImageOptions options;
01042             unsigned int m_imageNr;
01043             unsigned int m_mode;
01044             std::vector<double> m_coeff;
01045             std::string m_flat;
01046     };
01047 
01048 
01049     //=========================================================================
01050     //=========================================================================
01051 
01052 
01055     class RotatePanoCmd : public PanoCommand
01056     {
01057     public:
01058         RotatePanoCmd(Panorama & p, double yaw, double pitch, double roll)
01059             : PanoCommand(p), y(yaw), p(pitch), r(roll)
01060             { };
01061 
01062         virtual bool processPanorama(Panorama& pano)
01063             {
01064                 pano.rotate(y, p, r);
01065                 pano.changeFinished();
01066 
01067                 return true;
01068             }
01069         
01070         virtual std::string getName() const
01071             {
01072                 return "set image options";
01073             }
01074 
01075     private:
01076         double y,p,r;
01077     };
01078 
01079     //=========================================================================
01080     //=========================================================================
01081 
01084     class UpdateFocalLengthCmd : public PanoCommand
01085     {
01086     public:
01087         UpdateFocalLengthCmd(Panorama & p, UIntSet imgs, double newFocalLength)
01088             : PanoCommand(p), imgNrs(imgs), m_focalLength(newFocalLength)
01089             { };
01090 
01091         virtual bool processPanorama(Panorama& pano)
01092             {
01093                 pano.UpdateFocalLength(imgNrs,m_focalLength);
01094                 pano.changeFinished();
01095                 return true;
01096             }
01097         
01098         virtual std::string getName() const
01099             {
01100                 return "update focal length";
01101             }
01102 
01103     private:
01104         UIntSet imgNrs;
01105         double m_focalLength;
01106     };
01107 
01108     //=========================================================================
01109     //=========================================================================
01110 
01111 
01114     class UpdateCropFactorCmd : public PanoCommand
01115     {
01116     public:
01117         UpdateCropFactorCmd(Panorama & p, UIntSet imgs, double newCropFactor)
01118             : PanoCommand(p), imgNrs(imgs), m_cropFactor(newCropFactor)
01119             { };
01120 
01121         virtual bool processPanorama(Panorama& pano)
01122             {
01123                 //search all image with the same lens, otherwise the crop factor is updated via links, 
01124                 //but not the hfov if the image is not the given UIntSet
01125                 UIntSet allImgWithSameLens;
01126                 UIntSet testedLens;
01127                 HuginBase::StandardImageVariableGroups variable_groups(pano);
01128                 HuginBase::ImageVariableGroup & lenses = variable_groups.getLenses();
01129                 for(UIntSet::const_iterator it=imgNrs.begin();it!=imgNrs.end();it++)
01130                 {
01131                     allImgWithSameLens.insert(*it);
01132                     unsigned int lensNr=lenses.getPartNumber(*it);
01133                     if(set_contains(testedLens,lensNr))
01134                         continue;
01135                     testedLens.insert(lensNr);
01136                     for(unsigned int i=0;i<pano.getNrOfImages();i++)
01137                     {
01138                         if(lenses.getPartNumber(i)==lensNr)
01139                         {
01140                             allImgWithSameLens.insert(i);
01141                         };
01142                     };
01143                 };
01144                 pano.UpdateCropFactor(allImgWithSameLens, m_cropFactor);
01145                 pano.changeFinished();
01146                 return true;
01147             }
01148         
01149         virtual std::string getName() const
01150             {
01151                 return "update crop factor";
01152             }
01153 
01154     private:
01155         UIntSet imgNrs;
01156         double m_cropFactor;
01157     };
01158 
01159     //=========================================================================
01160     //=========================================================================
01161 
01162 
01165     class ChangePartNumberCmd : public PanoCommand
01166     {
01167     public:
01168         ChangePartNumberCmd(Panorama & p,
01169                             UIntSet image_numbers,
01170                             std::size_t new_part_number,
01171                             std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables
01172                             )
01173             :   PanoCommand(p),
01174                 image_numbers(image_numbers),
01175                 new_part_number(new_part_number),
01176                 variables(variables)
01177             { };
01178 
01179         virtual bool processPanorama(Panorama& pano)
01180             {
01181                 // it might change as we are setting them
01182                 std::size_t new_new_part_number = new_part_number;
01183                 HuginBase::ImageVariableGroup group(variables, pano);
01184                 for (UIntSet::iterator it = image_numbers.begin();
01185                      it != image_numbers.end(); it++)
01186                 {
01187                     group.switchParts(*it, new_new_part_number);
01188                     // update the lens number if it changes.
01189                     new_new_part_number = group.getPartNumber(*it);
01190                 }
01191                 pano.changeFinished();
01192                 return true;
01193             }
01194         
01195         virtual std::string getName() const
01196             {
01197                 return "Change part number";
01198             }
01199 
01200     private:
01201         UIntSet image_numbers;
01202         std::size_t new_part_number;
01203         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables;
01204     };
01205     
01206     //=========================================================================
01207     //=========================================================================
01208     
01209     
01213     class ChangePartImagesLinkingCmd : public PanoCommand
01214     {
01215     public:
01226         ChangePartImagesLinkingCmd(Panorama & p,
01227                     UIntSet image_numbers,
01228                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> changeVariables,
01229                     bool new_linked_state,
01230                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> groupVariables)
01231             :   PanoCommand(p),
01232                 image_numbers(image_numbers),
01233                 changeVariables(changeVariables),
01234                 new_linked_state(new_linked_state),
01235                 groupVariables(groupVariables)
01236             { };
01237 
01238         virtual bool processPanorama(Panorama& pano)
01239             {
01240                 HuginBase::ImageVariableGroup group(groupVariables, pano);
01241                 if (new_linked_state)
01242                 {
01243                     for (UIntSet::iterator imageIt = image_numbers.begin();
01244                         imageIt != image_numbers.end(); imageIt++)
01245                     {
01246                         // link the variables
01247                         for (std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator variableIt = changeVariables.begin();
01248                              variableIt != changeVariables.end(); variableIt++)
01249                         {
01250                             group.linkVariableImage(*variableIt, *imageIt);
01251                         }
01252                     }
01253                 } else {
01254                     for (UIntSet::iterator imageIt = image_numbers.begin();
01255                         imageIt != image_numbers.end(); imageIt++)
01256                     {
01257                         // unlink the variable
01258                         for (std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator variableIt = changeVariables.begin();
01259                              variableIt != changeVariables.end(); variableIt++)
01260                         {
01261                             group.unlinkVariableImage(*variableIt, *imageIt);
01262                             group.updatePartNumbers();
01263                         }
01264                     }
01265                 }
01266                 pano.changeFinished();
01267                 return true;
01268             }
01269         
01270         virtual std::string getName() const
01271             {
01272                 return "Change image variable links";
01273             }
01274 
01275     private:
01276         UIntSet image_numbers;
01277         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> changeVariables;
01278         bool new_linked_state;
01279         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> groupVariables;
01280     };
01281     
01282     
01283     //=========================================================================
01284     //=========================================================================
01285     
01286     
01289     class LinkLensVarsCmd : public PanoCommand
01290     {
01291     public:
01292         LinkLensVarsCmd(Panorama & p,
01293                     std::size_t lens_number,
01294                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables
01295                     )
01296             :   PanoCommand(p),
01297                 lens_number(lens_number),
01298                 variables(variables)
01299             { };
01300 
01301         virtual bool processPanorama(Panorama& pano)
01302             {
01303                 HuginBase::StandardImageVariableGroups variable_groups(pano);
01304                 HuginBase::ImageVariableGroup & lenses = variable_groups.getLenses();
01305                 std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator it;
01306                 for (it = variables.begin(); it != variables.end(); it++)
01307                 {
01308                     lenses.linkVariablePart(*it, lens_number);
01309                 }
01310                 pano.changeFinished();
01311                 return true;
01312             }
01313         
01314         virtual std::string getName() const
01315             {
01316                 return "Link lens variables";
01317             }
01318 
01319     private:
01320         std::size_t lens_number;
01321         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables;
01322     };
01323     //=========================================================================
01324     //=========================================================================
01325     
01327 #define image_variable( name, type, default_value )\
01328     class ChangeImage##name##Cmd : public PanoCommand\
01329     {\
01330     public:\
01331         ChangeImage##name##Cmd(Panorama & p,\
01332                                UIntSet image_numbers,\
01333                                type value)\
01334             :   PanoCommand(p),\
01335                 image_numbers(image_numbers),\
01336                 value(value)\
01337             { };\
01338         \
01339         virtual bool processPanorama(Panorama& pano)\
01340             {\
01341                 for (UIntSet::iterator it = image_numbers.begin();\
01342                      it != image_numbers.end(); it++)\
01343                 {\
01344                     HuginBase::SrcPanoImage img = pano.getSrcImage(*it);\
01345                     img.set##name(value);\
01346                     pano.setSrcImage(*it, img);\
01347                 }\
01348                 pano.changeFinished();\
01349                 return true;\
01350             }\
01351         \
01352         virtual std::string getName() const\
01353             {\
01354                 return "Change image's " #name;\
01355             }\
01356     private:\
01357         UIntSet image_numbers;\
01358         type value;\
01359     };
01360 #include <panodata/image_variables.h>
01361 #undef image_variable
01362     
01363     
01364     //=========================================================================
01365     //=========================================================================
01366     
01367     
01371     class NewPartCmd : public PanoCommand
01372     {
01373     public:
01381         NewPartCmd( Panorama & p,
01382                     UIntSet image_numbers,
01383                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> vars)
01384             :   PanoCommand(p),
01385                 image_numbers(image_numbers),
01386                 vars(vars)
01387         { }
01388         
01389         virtual bool processPanorama(Panorama& pano)
01390         {
01391             // unlink all the variables in the first image.
01392             DEBUG_ASSERT (image_numbers.size() > 0);
01393             unsigned int image_index = *image_numbers.begin();
01394             for (std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator it = vars.begin();
01395                     it != vars.end(); it++)
01396             {
01397                 switch (*it)
01398                 {
01399 #define image_variable( name, type, default_value )\
01400                     case HuginBase::ImageVariableGroup::IVE_##name:\
01401                         pano.unlinkImageVariable##name(image_index);\
01402                         break;
01403 #include <panodata/image_variables.h>
01404 #undef image_variable
01405                 }
01406             }
01407             // now the first image should have a new part in the group.
01408             // we want to switch the rest of the images to the new part.
01409             HuginBase::ImageVariableGroup group(vars, pano);
01410             for (UIntSet::iterator it = ++image_numbers.begin();
01411                     it != image_numbers.end(); it++)
01412             {
01413                 std::size_t part_number = group.getPartNumber(image_index);
01414                 group.switchParts(*it, part_number);
01415             }
01416             pano.changeFinished();
01417             return true;
01418         }
01419         
01420         virtual std::string getName() const
01421             {
01422                 return "New Part";
01423             }
01424 
01425     private:
01426         UIntSet image_numbers;
01427         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> vars;
01428     };
01429 
01430     //=========================================================================
01431     //=========================================================================
01432 
01434     class UpdateMaskForImgCmd : public PanoCommand
01435     {
01436     public:
01437         UpdateMaskForImgCmd(Panorama & p, unsigned int img, const HuginBase::MaskPolygonVector & mask)
01438             : PanoCommand(p),
01439               m_img(img), m_mask(mask)
01440             { };
01441 
01442         virtual bool processPanorama(Panorama& pano)
01443             {
01444                 pano.updateMasksForImage(m_img,m_mask);
01445                 pano.changeFinished();
01446 
01447                 return true;
01448             }
01449         
01450         virtual std::string getName() const
01451             {
01452                 return "update mask";
01453             }
01454 
01455     private:
01456         unsigned int m_img;
01457         HuginBase::MaskPolygonVector m_mask;
01458     };
01459 
01460 } // namespace PT
01461 
01462 #endif // _PANOCOMMAND_H

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