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 #include <panotools/PanoToolsUtils.h>
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     
00069     class CombinedPanoCommand : public PanoCommand
00070     {
00071         public:
00077             CombinedPanoCommand(Panorama & pano, std::vector<PanoCommand*> & commands)
00078                 : PanoCommand(pano), commands(commands)
00079                 {};
00080             ~CombinedPanoCommand()
00081                 {
00082                     for (std::vector<PanoCommand*>::iterator it = commands.begin();
00083                          it != commands.end();
00084                          it++)
00085                     {
00086                         delete *it;
00087                     }
00088                 }
00089             virtual bool processPanorama(Panorama & pano)
00090                 {
00091                     bool result = true;
00092                     for (std::vector<PanoCommand*>::iterator it = commands.begin();
00093                          it != commands.end();
00094                          it++)
00095                     {
00096                         result &= (**it).processPanorama(pano);
00097                     }
00099                     return result;
00100                 };
00101             
00102             virtual std::string getName() const
00103                 {
00104                     return "multiple commmands";
00105                 };
00106         private:
00107             std::vector<PanoCommand*> commands;
00108     };
00109 
00110 
00111     //=========================================================================
00112     //=========================================================================
00113     
00114 
00116     class NewPanoCmd : public PanoCommand
00117     {
00118     public:
00119         NewPanoCmd(Panorama & pano)
00120             : PanoCommand(pano)
00121             { m_clearDirty=true; };
00122 
00123         virtual bool processPanorama(Panorama& pano)
00124             {
00125                 pano.reset();
00126 
00127                 return true;
00128             }
00129         
00130         virtual std::string getName() const
00131             {
00132                 return "new panorama";
00133             }
00134     };
00135 
00136     //=========================================================================
00137     //=========================================================================
00138 
00140     class AddImagesCmd : public PanoCommand
00141     {
00142     public:
00143         AddImagesCmd(Panorama & pano, const std::vector<SrcPanoImage> & images)
00144             : PanoCommand(pano), imgs(images)
00145             { };
00146 
00147         virtual bool processPanorama(Panorama& pano)
00148             {
00149                 std::vector<SrcPanoImage>::const_iterator it;
00150                 for (it = imgs.begin(); it != imgs.end(); ++it) {
00151                     pano.addImage(*it);
00152                 }
00153 
00154                 return true;
00155             }
00156         
00157         virtual std::string getName() const
00158             {
00159                 return "add images";
00160             }
00161 
00162     private:
00163         std::vector<SrcPanoImage> imgs;
00164     };
00165 
00166 
00167     //=========================================================================
00168     //=========================================================================
00169 
00170 
00175     class RemoveImageCmd : public PanoCommand
00176     {
00177     public:
00178         RemoveImageCmd(Panorama & p, unsigned int imgNr)
00179             : PanoCommand(p), imgNr(imgNr)
00180             { };
00181 
00182         virtual bool processPanorama(Panorama& pano)
00183             {
00184                 pano.removeImage(imgNr);
00185 
00186                 return true;
00187             }
00188         
00189         virtual std::string getName() const
00190             {
00191                 return "remove image";
00192             }
00193 
00194     private:
00195         unsigned int imgNr;
00196     };
00197 
00198     //=========================================================================
00199     //=========================================================================
00200 
00201 
00205     class RemoveImagesCmd : public PanoCommand
00206     {
00207     public:
00208         RemoveImagesCmd(Panorama & p, UIntSet imgs)
00209             : PanoCommand(p), imgNrs(imgs)
00210             { };
00211 
00212         virtual bool processPanorama(Panorama& pano)
00213             {
00214                 for (UIntSet::reverse_iterator it = imgNrs.rbegin();
00215                      it != imgNrs.rend(); ++it)
00216                 {
00217                     pano.removeImage(*it);
00218                 }
00219 
00220                 return true;
00221             }
00222         
00223         virtual std::string getName() const
00224             {
00225                 return "remove images";
00226             }
00227 
00228     private:
00229         UIntSet imgNrs;
00230     };
00231 
00232     //=========================================================================
00233     //=========================================================================
00234 
00235 #if 0
00236 
00237     class ChangeImageCmd : public PanoCommand
00238     {
00239     public:
00240         Cmd(Panorama & p)
00241             : PanoCommand(p)
00242             { };
00243 
00244         virtual bool processPanorama(Panorama& pano)
00245             {
00246 
00247                 return true;
00248             }
00249         
00250         virtual std::string getName() const
00251             {
00252                 return "unnamed command";
00253             }
00254 
00255     private:
00256     };
00257 #endif
00258 
00259     //=========================================================================
00260     //=========================================================================
00261 
00263     class UpdateVariablesCmd : public PanoCommand
00264     {
00265     public:
00266         UpdateVariablesCmd(Panorama & p, const VariableMapVector & vars)
00267             : PanoCommand(p),
00268               vars(vars)
00269             { };
00270 
00271         virtual bool processPanorama(Panorama& pano)
00272             {
00273                 pano.updateVariables(vars);
00274 
00275                 return true;
00276             }
00277         
00278         virtual std::string getName() const
00279             {
00280                 return "update Variables";
00281             }
00282 
00283     private:
00284         VariableMapVector vars;
00285     };
00286 
00287     //=========================================================================
00288     //=========================================================================
00289 
00291     class UpdateCPsCmd : public PanoCommand
00292     {
00293     public:
00294         UpdateCPsCmd(Panorama & p, const CPVector & cps, bool doUpdateCPError=true)
00295             : PanoCommand(p),
00296               cps(cps), updateCPError(doUpdateCPError)
00297             { };
00298 
00299         virtual bool processPanorama(Panorama& pano)
00300             {
00301                 CPVector::const_iterator it;
00302                 unsigned int i=0;
00303                 for (it = cps.begin(); it != cps.end(); ++it, i++) {
00304                     pano.changeControlPoint(i, *it);
00305                 }
00306                 if(updateCPError)
00307                 {
00308                     HuginBase::PTools::calcCtrlPointErrors(pano);
00309                 };
00310 
00311                 return true;
00312             }
00313         
00314         virtual std::string getName() const
00315             {
00316                 return "update control points";
00317             }
00318 
00319     private:
00320         CPVector cps;
00321         bool updateCPError;
00322     };
00323 
00324     //=========================================================================
00325     //=========================================================================
00326 
00328     class UpdateVariablesCPCmd : public PanoCommand
00329     {
00330     public:
00331         UpdateVariablesCPCmd(Panorama & p, const VariableMapVector & vars,
00332                              const CPVector & cps)
00333             : PanoCommand(p),
00334               vars(vars), cps(cps)
00335             { };
00336 
00337         virtual bool processPanorama(Panorama& pano)
00338             {
00339                 pano.updateVariables(vars);
00340                 pano.updateCtrlPointErrors(cps);
00341 
00342                 return true;
00343             }
00344         
00345         virtual std::string getName() const
00346             {
00347                 return "update Variables";
00348             }
00349 
00350     private:
00351         VariableMapVector vars;
00352         CPVector cps;
00353     };
00354 
00355 
00356     //=========================================================================
00357     //=========================================================================
00358 
00360     class UpdateVariablesCPSetCmd : public PanoCommand
00361     {
00362     public:
00363         UpdateVariablesCPSetCmd(Panorama & p, UIntSet imgs, const VariableMapVector & vars,
00364                                 const CPVector & cps)
00365             : PanoCommand(p),
00366               m_imgs(imgs),
00367               vars(vars), cps(cps)
00368             { };
00369 
00370         virtual bool processPanorama(Panorama& pano)
00371             {
00372                 pano.updateVariables(m_imgs, vars);
00373                 pano.updateCtrlPointErrors(m_imgs, cps);
00374                 pano.markAsOptimized();
00375 
00376                 return true;
00377             }
00378         
00379         virtual std::string getName() const
00380             {
00381                 return "update Variables";
00382             }
00383 
00384     private:
00385         UIntSet m_imgs;
00386         VariableMapVector vars;
00387         CPVector cps;
00388     };
00389 
00390     //=========================================================================
00391     //=========================================================================
00392 
00394     class UpdateImageVariablesCmd : public PanoCommand
00395     {
00396     public:
00397         UpdateImageVariablesCmd(Panorama & p, unsigned int ImgNr, const VariableMap & vars)
00398             : PanoCommand(p), imgNr(ImgNr),
00399               vars(vars)
00400             { };
00401 
00402         virtual bool processPanorama(Panorama& pano)
00403             {
00404                 pano.updateVariables(imgNr, vars);
00405 
00406                 return true;
00407             }
00408         
00409         virtual std::string getName() const
00410             {
00411                 return "update image variables";
00412             }
00413 
00414     private:
00415         unsigned int imgNr;
00416         VariableMap vars;
00417     };
00418 
00419     //=========================================================================
00420     //=========================================================================
00421 
00423     class UpdateImagesVariablesCmd : public PanoCommand
00424     {
00425     public:
00426         UpdateImagesVariablesCmd(Panorama & p, const UIntSet & change, const VariableMapVector & vars)
00427             : PanoCommand(p), change(change),
00428               vars(vars)
00429             { };
00430 
00431         virtual bool processPanorama(Panorama& pano)
00432             {
00433                 UIntSet::iterator it;
00434                 VariableMapVector::const_iterator v_it = vars.begin();
00435                 for (it = change.begin(); it != change.end(); ++it) {
00436                     pano.updateVariables(*it, *v_it);
00437                     ++v_it;
00438                 }
00439                 HuginBase::PTools::calcCtrlPointErrors(pano);
00440 
00441                 return true;
00442             }
00443         
00444         virtual std::string getName() const
00445             {
00446                 return "update image variables";
00447             }
00448 
00449     private:
00450         UIntSet change;
00451         VariableMapVector vars;
00452     };
00453 
00454 
00455     //=========================================================================
00456     //=========================================================================
00457 
00459     class UpdateOptimizeVectorCmd : public PanoCommand
00460     {
00461     public:
00462         UpdateOptimizeVectorCmd(Panorama &p, OptimizeVector optvec)
00463             : PanoCommand(p),
00464               m_optvec(optvec)
00465         { };
00466 
00467     virtual bool processPanorama(Panorama & pano)
00468         {
00469             pano.setOptimizeVector(m_optvec);
00470             return true;
00471         }
00472 
00473     virtual std::string getName() const
00474         {
00475             return "update optimize vector";
00476         }
00477 
00478     private:
00479         OptimizeVector m_optvec;
00480         int mode;
00481 
00482     };
00483 
00484 
00485     //=========================================================================
00486     //=========================================================================
00487 
00489     class UpdateOptimizerSwitchCmd : public PanoCommand
00490     {
00491     public:
00492         UpdateOptimizerSwitchCmd(Panorama &p, int mode)
00493             : PanoCommand(p),
00494               m_mode(mode)
00495         { };
00496 
00497     virtual bool processPanorama(Panorama & pano)
00498         {
00499             pano.setOptimizerSwitch(m_mode);
00500             return true;
00501         }
00502 
00503     virtual std::string getName() const
00504         {
00505             return "update optimizer master switch";
00506         }
00507 
00508     private:
00509         int m_mode;
00510     };
00511 
00512     //=========================================================================
00513     //=========================================================================
00514 
00516     class UpdatePhotometricOptimizerSwitchCmd : public PanoCommand
00517     {
00518     public:
00519         UpdatePhotometricOptimizerSwitchCmd(Panorama &p, int mode)
00520             : PanoCommand(p),
00521               m_mode(mode)
00522         { };
00523 
00524     virtual bool processPanorama(Panorama & pano)
00525         {
00526             pano.setPhotometricOptimizerSwitch(m_mode);
00527             return true;
00528         }
00529 
00530     virtual std::string getName() const
00531         {
00532             return "update photometric optimizer master switch";
00533         }
00534 
00535     private:
00536         int m_mode;
00537     };
00538 
00539 
00540     //=========================================================================
00541     //=========================================================================
00542 
00544     class SetVariableCmd : public PanoCommand
00545     {
00546     public:
00547         SetVariableCmd(Panorama & p, const UIntSet & images, const Variable & var)
00548             : PanoCommand(p), images(images),
00549               var(var)
00550             { };
00551 
00552         virtual bool processPanorama(Panorama& pano)
00553             {
00554                 UIntSet::iterator it;
00555                 for (it = images.begin(); it != images.end(); ++it) {
00556                     pano.updateVariable(*it, var);
00557                 }
00558                 HuginBase::PTools::calcCtrlPointErrors(pano);
00559 
00560                 return true;
00561             }
00562         
00563         virtual std::string getName() const
00564             {
00565                 return "set image variable";
00566             }
00567 
00568     private:
00569         UIntSet images;
00570         Variable var;
00571     };
00572 
00573 
00574     //=========================================================================
00575     //=========================================================================
00576 
00577 
00579     class CenterPanoCmd : public PanoCommand
00580     {
00581     public:
00582         CenterPanoCmd(Panorama & p )
00583             : PanoCommand(p)
00584             { }
00585 
00586         virtual bool processPanorama(Panorama& pano)
00587             {
00588                 pano.centerHorizontically();
00589                 // adjust canvas size
00590                 PanoramaOptions opts=pano.getOptions();
00591                 double hfov, height;
00592                 pano.fitPano(hfov, height);
00593                 opts.setHFOV(hfov);
00594                 opts.setHeight(hugin_utils::roundi(height));
00595                 pano.setOptions(opts);
00596 
00597                 return true;
00598             }
00599         
00600         virtual std::string getName() const
00601             {
00602                 return "center panorama";
00603             }
00604 
00605     private:
00606     };
00607 
00608 
00609     //=========================================================================
00610     //=========================================================================
00611 
00612 
00614     class StraightenPanoCmd : public PanoCommand
00615     {
00616     public:
00617         StraightenPanoCmd(Panorama & p )
00618             : PanoCommand(p)
00619             { }
00620 
00621         virtual bool processPanorama(Panorama& pano)
00622             {
00623                 pano.straighten();
00624                 PanoramaOptions opts=pano.getOptions();
00625                 if(opts.getHFOV()<360)
00626                 {
00627                     // center non 360 deg panos
00628                     pano.centerHorizontically();
00629                 };
00630                 // adjust canvas size
00631                 double hfov, height;
00632                 pano.fitPano(hfov, height);
00633                 opts.setHFOV(hfov);
00634                 opts.setHeight(hugin_utils::roundi(height));
00635                 pano.setOptions(opts);
00636 
00637                 return true;
00638             }
00639         
00640         virtual std::string getName() const
00641             {
00642                 return "straighten panorama";
00643             }
00644 
00645     private:
00646     };
00647 
00648 
00649     //=========================================================================
00650     //=========================================================================
00651 
00652 
00654     class AddCtrlPointCmd : public PanoCommand
00655     {
00656     public:
00657         AddCtrlPointCmd(Panorama & p, const ControlPoint & cpoint)
00658             : PanoCommand(p), point(cpoint)
00659             { }
00660 
00661         virtual bool processPanorama(Panorama& pano)
00662             {
00663                 pano.addCtrlPoint(point);
00664                 HuginBase::PTools::calcCtrlPointErrors(pano);
00665 
00666                 return true;
00667             }
00668         
00669         virtual std::string getName() const
00670             {
00671                 return "add control point";
00672             }
00673 
00674     private:
00675         ControlPoint point;
00676     };
00677 
00678 
00679 
00680     //=========================================================================
00681     //=========================================================================
00682 
00683 
00685     class AddCtrlPointsCmd : public PanoCommand
00686     {
00687     public:
00688         AddCtrlPointsCmd(Panorama & p, const CPVector & cpoints)
00689             : PanoCommand(p), cps(cpoints)
00690             { }
00691 
00692         virtual bool processPanorama(Panorama& pano)
00693             {
00694                 for (CPVector::iterator it = cps.begin();
00695                      it != cps.end(); ++it)
00696                 {
00697                     pano.addCtrlPoint(*it);
00698                 }
00699                 HuginBase::PTools::calcCtrlPointErrors(pano);
00700 
00701                 return true;
00702             }
00703         
00704         virtual std::string getName() const
00705             {
00706                 return "add control points";
00707             }
00708 
00709     private:
00710         CPVector cps;
00711     };
00712 
00713 
00714     //=========================================================================
00715     //=========================================================================
00716 
00717 
00719     class RemoveCtrlPointCmd : public PanoCommand
00720     {
00721     public:
00722         RemoveCtrlPointCmd(Panorama & p, unsigned int cpNr)
00723             : PanoCommand(p), pointNr(cpNr)
00724             { }
00725 
00726         virtual bool processPanorama(Panorama& pano)
00727             {
00728                 pano.removeCtrlPoint(pointNr);
00729 
00730                 return true;
00731             }
00732         
00733         virtual std::string getName() const
00734             {
00735                 return "remove control point";
00736             }
00737 
00738     private:
00739         unsigned int pointNr;
00740     };
00741 
00742 
00743     //=========================================================================
00744     //=========================================================================
00745 
00746 
00748     class RemoveCtrlPointsCmd : public PanoCommand
00749     {
00750     public:
00751         RemoveCtrlPointsCmd(Panorama & p, const UIntSet & points )
00752             : PanoCommand(p), m_points(points)
00753             { }
00754 
00755         virtual bool processPanorama(Panorama& pano)
00756             {
00757                 for(UIntSet::reverse_iterator it = m_points.rbegin();
00758                     it != m_points.rend(); ++it)
00759                 {
00760                     pano.removeCtrlPoint(*it);
00761                 }
00762 
00763                 return true;
00764             }
00765         
00766         virtual std::string getName() const
00767             {
00768                 return "remove control points";
00769             }
00770 
00771     private:
00772         UIntSet m_points;
00773     };
00774 
00775 
00776     //=========================================================================
00777     //=========================================================================
00778 
00779 
00781     class ChangeCtrlPointCmd : public PanoCommand
00782     {
00783     public:
00784         ChangeCtrlPointCmd(Panorama & p, unsigned int nr, ControlPoint point)
00785             : PanoCommand(p), pNr(nr), point(point)
00786             { }
00787 
00788         virtual bool processPanorama(Panorama& pano)
00789             {
00790                 pano.changeControlPoint(pNr, point);
00791                 HuginBase::PTools::calcCtrlPointErrors(pano);
00792 
00793                 return true;
00794             }
00795         
00796         virtual std::string getName() const
00797             {
00798                 return "change control point";
00799             }
00800 
00801     private:
00802         unsigned int pNr;
00803         ControlPoint point;
00804     };
00805 
00806 
00807 
00808     //=========================================================================
00809     //=========================================================================
00810 
00812     class SetActiveImagesCmd : public PanoCommand
00813     {
00814     public:
00815         SetActiveImagesCmd(Panorama & p, UIntSet & active)
00816             : PanoCommand(p), m_active(active)
00817             { };
00818 
00819         virtual bool processPanorama(Panorama& pano)
00820             {
00821                 UIntSet::iterator it;
00822                                 for (unsigned int i = 0; i < pano.getNrOfImages(); i++) {
00823                     if (set_contains(m_active, i)) {
00824                                                 pano.activateImage(i, true);
00825                                         } else {
00826                                                 pano.activateImage(i, false);
00827                                         }
00828                 }
00829 
00830                 return true;
00831             }
00832         
00833         virtual std::string getName() const
00834             {
00835                 return "change active images";
00836             }
00837 
00838     private:
00839         UIntSet m_active;
00840     };
00841 
00842 
00843     //=========================================================================
00844     //=========================================================================
00845 
00847     class SwapImagesCmd : public PanoCommand
00848     {
00849     public:
00850         SwapImagesCmd(Panorama & p, unsigned int i1, unsigned int i2)
00851             : PanoCommand(p), m_i1(i1), m_i2(i2)
00852             { };
00853 
00854         virtual bool processPanorama(Panorama& pano)
00855             {
00856                 pano.swapImages(m_i1, m_i2);
00857 
00858                 return true;
00859             }
00860         
00861         virtual std::string getName() const
00862             {
00863                 return "swap images";
00864             }
00865 
00866     private:
00867         unsigned int m_i1;
00868         unsigned int m_i2;
00869     };
00870 
00872     class MoveImageCmd : public PanoCommand
00873     {
00874     public:
00875         MoveImageCmd(Panorama & p, size_t i1, size_t i2)
00876             : PanoCommand(p), m_i1(i1), m_i2(i2)
00877             { };
00878 
00879         virtual bool processPanorama(Panorama& pano)
00880             {
00881                 pano.moveImage(m_i1, m_i2);
00882 
00883                 return true;
00884             }
00885         
00886         virtual std::string getName() const
00887             {
00888                 return "move images";
00889             }
00890 
00891     private:
00892         unsigned int m_i1;
00893         unsigned int m_i2;
00894     };
00895 
00897     class MergePanoCmd : public PanoCommand
00898     {
00899     public:
00900         MergePanoCmd(Panorama & p, Panorama & p2)
00901             : PanoCommand(p), newPano(p2)
00902             { };
00903 
00904         virtual bool processPanorama(Panorama& pano)
00905             {
00906                 pano.mergePanorama(newPano);
00907                 HuginBase::PTools::calcCtrlPointErrors(pano);
00908 
00909                 return true;
00910             }
00911         
00912         virtual std::string getName() const
00913             {
00914                 return "merge panorama";
00915             }
00916 
00917     private:
00918         Panorama newPano;
00919     };
00920 
00921     //=========================================================================
00922     //=========================================================================
00923 
00926     class UpdateSrcImageCmd : public PanoCommand
00927     {
00928         public:
00929             UpdateSrcImageCmd(Panorama & p, unsigned i, SrcPanoImage img)
00930             : PanoCommand(p), img(img), imgNr(i)
00931             { };
00932 
00933             virtual bool processPanorama(Panorama& pano)
00934             {
00935                 pano.setSrcImage(imgNr, img);
00936 
00937                 return true;
00938             }
00939             
00940         virtual std::string getName() const
00941             {
00942                 return "update source image";
00943             }
00944     
00945     private:
00946             SrcPanoImage img;
00947             unsigned imgNr;
00948     };
00949 
00950     //=========================================================================
00951     //=========================================================================
00952 
00955     class UpdateSrcImagesCmd : public PanoCommand
00956     {
00957         public:
00958             UpdateSrcImagesCmd(Panorama & p, UIntSet i, std::vector<SrcPanoImage> imgs)
00959             : PanoCommand(p), imgs(imgs), imgNrs(i)
00960             { };
00961 
00962             virtual bool processPanorama(Panorama& pano)
00963             {
00964                 int i = 0;
00965                 for (UIntSet::iterator it = imgNrs.begin();
00966                      it != imgNrs.end(); ++it)
00967                 {
00968                     pano.setSrcImage(*it, imgs[i]);
00969                     i++;
00970                 }
00971                 HuginBase::PTools::calcCtrlPointErrors(pano);
00972 
00973                 return true;
00974             }
00975             
00976         virtual std::string getName() const
00977             {
00978                 return "update source images";
00979             }
00980     
00981     private:
00982             std::vector<SrcPanoImage> imgs;
00983             UIntSet imgNrs;
00984     };
00985 
00986 
00987     //=========================================================================
00988     //=========================================================================
00989 
00991     class SetPanoOptionsCmd : public PanoCommand
00992     {
00993     public:
00994         SetPanoOptionsCmd(Panorama & p, const PanoramaOptions & opts)
00995             : PanoCommand(p), options(opts)
00996             { };
00997 
00998         virtual bool processPanorama(Panorama& pano)
00999             {
01000                 pano.setOptions(options);
01001 
01002                 return true;
01003             }
01004         
01005         virtual std::string getName() const
01006             {
01007                 return "set panorama options";
01008             }
01009 
01010     private:
01011         PanoramaOptions options;
01012     };
01013 
01014     //=========================================================================
01015     //=========================================================================
01016 
01022     class LoadPTProjectCmd : public PanoCommand
01023     {
01024     public:
01025         LoadPTProjectCmd(Panorama & p, const std::string  & filename, const std::string & prefix = "")
01026             : PanoCommand(p),
01027             filename(filename),
01028             prefix(prefix)
01029             { m_clearDirty=true; }
01030 
01031         virtual bool processPanorama(Panorama& pano)
01032             {
01033                 std::ifstream in(filename.c_str());
01034 #ifndef _Hgn1_PANORAMA_H
01035                 PanoramaMemento newPano;
01036                 if (newPano.loadPTScript(in,prefix)) {
01037                     pano.setMemento(newPano);
01038                 } else {
01039                     DEBUG_ERROR("could not load panotools script");
01040                 }
01041 #else
01042                 AppBase::DocumentData::ReadWriteError err = pano.readData(in);
01043                 if (err != AppBase::DocumentData::SUCCESSFUL) {
01044                     DEBUG_ERROR("could not load panotools script");
01045                     return false;
01046                 }
01047 #endif
01048                 
01049                 in.close();
01050 
01051                 return true;
01052             }
01053         
01054         virtual std::string getName() const
01055             {
01056                 return "load project";
01057             }
01058 
01059     private:
01060         const std::string &filename;
01061         const std::string &prefix;
01062     };
01063 
01064     //=========================================================================
01065     //=========================================================================
01066 
01069     class RotatePanoCmd : public PanoCommand
01070     {
01071     public:
01072         RotatePanoCmd(Panorama & p, double yaw, double pitch, double roll)
01073             : PanoCommand(p), y(yaw), p(pitch), r(roll)
01074             { };
01075 
01076         virtual bool processPanorama(Panorama& pano)
01077             {
01078                 pano.rotate(y, p, r);
01079 
01080                 return true;
01081             }
01082         
01083         virtual std::string getName() const
01084             {
01085                 return "rotate panorama";
01086             }
01087 
01088     private:
01089         double y,p,r;
01090     };
01091 
01092     //=========================================================================
01093     //=========================================================================
01094 
01097     class TranslatePanoCmd : public PanoCommand
01098     {
01099     public:
01100         TranslatePanoCmd(Panorama & p, double TrX, double TrY, double TrZ)
01101             : PanoCommand(p), X(TrX), Y(TrY), Z(TrZ)
01102             { };
01103 
01104         virtual bool processPanorama(Panorama& pano)
01105             {
01106                 pano.translate(X, Y, Z);
01107 
01108                 return true;
01109             }
01110 
01111         virtual std::string getName() const
01112             {
01113                 return "translate panorama";
01114             }
01115 
01116      private:
01117        double X,Y,Z;
01118      };
01119 
01120     //=========================================================================
01121     //=========================================================================
01122 
01123 
01124 
01127     class UpdateFocalLengthCmd : public PanoCommand
01128     {
01129     public:
01130         UpdateFocalLengthCmd(Panorama & p, UIntSet imgs, double newFocalLength)
01131             : PanoCommand(p), imgNrs(imgs), m_focalLength(newFocalLength)
01132             { };
01133 
01134         virtual bool processPanorama(Panorama& pano)
01135             {
01136                 pano.UpdateFocalLength(imgNrs,m_focalLength);
01137                 return true;
01138             }
01139         
01140         virtual std::string getName() const
01141             {
01142                 return "update focal length";
01143             }
01144 
01145     private:
01146         UIntSet imgNrs;
01147         double m_focalLength;
01148     };
01149 
01150     //=========================================================================
01151     //=========================================================================
01152 
01153 
01156     class UpdateCropFactorCmd : public PanoCommand
01157     {
01158     public:
01159         UpdateCropFactorCmd(Panorama & p, UIntSet imgs, double newCropFactor)
01160             : PanoCommand(p), imgNrs(imgs), m_cropFactor(newCropFactor)
01161             { };
01162 
01163         virtual bool processPanorama(Panorama& pano)
01164             {
01165                 //search all image with the same lens, otherwise the crop factor is updated via links, 
01166                 //but not the hfov if the image is not the given UIntSet
01167                 UIntSet allImgWithSameLens;
01168                 UIntSet testedLens;
01169                 HuginBase::StandardImageVariableGroups variable_groups(pano);
01170                 HuginBase::ImageVariableGroup & lenses = variable_groups.getLenses();
01171                 for(UIntSet::const_iterator it=imgNrs.begin();it!=imgNrs.end();it++)
01172                 {
01173                     allImgWithSameLens.insert(*it);
01174                     unsigned int lensNr=lenses.getPartNumber(*it);
01175                     if(set_contains(testedLens,lensNr))
01176                         continue;
01177                     testedLens.insert(lensNr);
01178                     for(unsigned int i=0;i<pano.getNrOfImages();i++)
01179                     {
01180                         if(lenses.getPartNumber(i)==lensNr)
01181                         {
01182                             allImgWithSameLens.insert(i);
01183                         };
01184                     };
01185                 };
01186                 pano.UpdateCropFactor(allImgWithSameLens, m_cropFactor);
01187                 return true;
01188             }
01189         
01190         virtual std::string getName() const
01191             {
01192                 return "update crop factor";
01193             }
01194 
01195     private:
01196         UIntSet imgNrs;
01197         double m_cropFactor;
01198     };
01199 
01200     //=========================================================================
01201     //=========================================================================
01202 
01203 
01206     class ChangePartNumberCmd : public PanoCommand
01207     {
01208     public:
01209         ChangePartNumberCmd(Panorama & p,
01210                             UIntSet image_numbers,
01211                             std::size_t new_part_number,
01212                             std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables
01213                             )
01214             :   PanoCommand(p),
01215                 image_numbers(image_numbers),
01216                 new_part_number(new_part_number),
01217                 variables(variables)
01218             { };
01219 
01220         virtual bool processPanorama(Panorama& pano)
01221             {
01222                 // it might change as we are setting them
01223                 std::size_t new_new_part_number = new_part_number;
01224                 HuginBase::ImageVariableGroup group(variables, pano);
01225                 for (UIntSet::iterator it = image_numbers.begin();
01226                      it != image_numbers.end(); it++)
01227                 {
01228                     group.switchParts(*it, new_new_part_number);
01229                     // update the lens number if it changes.
01230                     new_new_part_number = group.getPartNumber(*it);
01231                 }
01232                 return true;
01233             }
01234         
01235         virtual std::string getName() const
01236             {
01237                 return "Change part number";
01238             }
01239 
01240     private:
01241         UIntSet image_numbers;
01242         std::size_t new_part_number;
01243         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables;
01244     };
01245     
01246     //=========================================================================
01247     //=========================================================================
01248     
01249     
01253     class ChangePartImagesLinkingCmd : public PanoCommand
01254     {
01255     public:
01266         ChangePartImagesLinkingCmd(Panorama & p,
01267                     UIntSet image_numbers,
01268                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> changeVariables,
01269                     bool new_linked_state,
01270                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> groupVariables)
01271             :   PanoCommand(p),
01272                 image_numbers(image_numbers),
01273                 changeVariables(changeVariables),
01274                 new_linked_state(new_linked_state),
01275                 groupVariables(groupVariables)
01276             { };
01277 
01278         virtual bool processPanorama(Panorama& pano)
01279             {
01280                 HuginBase::ImageVariableGroup group(groupVariables, pano);
01281                 if (new_linked_state)
01282                 {
01283                     for (UIntSet::iterator imageIt = image_numbers.begin();
01284                         imageIt != image_numbers.end(); imageIt++)
01285                     {
01286                         // link the variables
01287                         for (std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator variableIt = changeVariables.begin();
01288                              variableIt != changeVariables.end(); variableIt++)
01289                         {
01290                             group.linkVariableImage(*variableIt, *imageIt);
01291                         }
01292                     }
01293                 } else {
01294                     for (UIntSet::iterator imageIt = image_numbers.begin();
01295                         imageIt != image_numbers.end(); imageIt++)
01296                     {
01297                         // unlink the variable
01298                         for (std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator variableIt = changeVariables.begin();
01299                              variableIt != changeVariables.end(); variableIt++)
01300                         {
01301                             group.unlinkVariableImage(*variableIt, *imageIt);
01302                             group.updatePartNumbers();
01303                         }
01304                     }
01305                 }
01306                 return true;
01307             }
01308         
01309         virtual std::string getName() const
01310             {
01311                 return "Change image variable links";
01312             }
01313 
01314     private:
01315         UIntSet image_numbers;
01316         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> changeVariables;
01317         bool new_linked_state;
01318         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> groupVariables;
01319     };
01320     
01321     
01322     //=========================================================================
01323     //=========================================================================
01324     
01325     
01328     class LinkLensVarsCmd : public PanoCommand
01329     {
01330     public:
01331         LinkLensVarsCmd(Panorama & p,
01332                     std::size_t lens_number,
01333                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables
01334                     )
01335             :   PanoCommand(p),
01336                 lens_number(lens_number),
01337                 variables(variables)
01338             { };
01339 
01340         virtual bool processPanorama(Panorama& pano)
01341             {
01342                 HuginBase::StandardImageVariableGroups variable_groups(pano);
01343                 HuginBase::ImageVariableGroup & lenses = variable_groups.getLenses();
01344                 std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator it;
01345                 for (it = variables.begin(); it != variables.end(); it++)
01346                 {
01347                     lenses.linkVariablePart(*it, lens_number);
01348                 }
01349                 return true;
01350             }
01351         
01352         virtual std::string getName() const
01353             {
01354                 return "Link lens variables";
01355             }
01356 
01357     private:
01358         std::size_t lens_number;
01359         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables;
01360     };
01361     //=========================================================================
01362     //=========================================================================
01363     
01365 #define image_variable( name, type, default_value )\
01366     class ChangeImage##name##Cmd : public PanoCommand\
01367     {\
01368     public:\
01369         ChangeImage##name##Cmd(Panorama & p,\
01370                                UIntSet image_numbers,\
01371                                type value)\
01372             :   PanoCommand(p),\
01373                 image_numbers(image_numbers),\
01374                 value(value)\
01375             { };\
01376         \
01377         virtual bool processPanorama(Panorama& pano)\
01378             {\
01379                 for (UIntSet::iterator it = image_numbers.begin();\
01380                      it != image_numbers.end(); it++)\
01381                 {\
01382                     HuginBase::SrcPanoImage img = pano.getSrcImage(*it);\
01383                     img.set##name(value);\
01384                     pano.setSrcImage(*it, img);\
01385                 }\
01386                 return true;\
01387             }\
01388         \
01389         virtual std::string getName() const\
01390             {\
01391                 return "Change image's " #name;\
01392             }\
01393     private:\
01394         UIntSet image_numbers;\
01395         type value;\
01396     };
01397 #include <panodata/image_variables.h>
01398 #undef image_variable
01399     
01400     
01401     //=========================================================================
01402     //=========================================================================
01403     
01404     
01408     class NewPartCmd : public PanoCommand
01409     {
01410     public:
01418         NewPartCmd( Panorama & p,
01419                     UIntSet image_numbers,
01420                     std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> vars)
01421             :   PanoCommand(p),
01422                 image_numbers(image_numbers),
01423                 vars(vars)
01424         { }
01425         
01426         virtual bool processPanorama(Panorama& pano)
01427         {
01428             // unlink all the variables in the first image.
01429             DEBUG_ASSERT (image_numbers.size() > 0);
01430             unsigned int image_index = *image_numbers.begin();
01431             for (std::set<HuginBase::ImageVariableGroup::ImageVariableEnum>::iterator it = vars.begin();
01432                     it != vars.end(); it++)
01433             {
01434                 switch (*it)
01435                 {
01436 #define image_variable( name, type, default_value )\
01437                     case HuginBase::ImageVariableGroup::IVE_##name:\
01438                         pano.unlinkImageVariable##name(image_index);\
01439                         break;
01440 #include <panodata/image_variables.h>
01441 #undef image_variable
01442                 }
01443             }
01444             // now the first image should have a new part in the group.
01445             // we want to switch the rest of the images to the new part.
01446             HuginBase::ImageVariableGroup group(vars, pano);
01447             for (UIntSet::iterator it = ++image_numbers.begin();
01448                     it != image_numbers.end(); it++)
01449             {
01450                 std::size_t part_number = group.getPartNumber(image_index);
01451                 group.switchParts(*it, part_number);
01452             }
01453             return true;
01454         }
01455         
01456         virtual std::string getName() const
01457             {
01458                 return "New Part";
01459             }
01460 
01461     private:
01462         UIntSet image_numbers;
01463         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> vars;
01464     };
01465 
01466     //=========================================================================
01467     //=========================================================================
01468 
01470     class UpdateMaskForImgCmd : public PanoCommand
01471     {
01472     public:
01473         UpdateMaskForImgCmd(Panorama & p, unsigned int img, const HuginBase::MaskPolygonVector & mask)
01474             : PanoCommand(p),
01475               m_img(img), m_mask(mask)
01476             { };
01477 
01478         virtual bool processPanorama(Panorama& pano)
01479             {
01480                 pano.updateMasksForImage(m_img,m_mask);
01481 
01482                 return true;
01483             }
01484         
01485         virtual std::string getName() const
01486             {
01487                 return "update mask";
01488             }
01489 
01490     private:
01491         unsigned int m_img;
01492         HuginBase::MaskPolygonVector m_mask;
01493     };
01494 
01495     //=========================================================================
01496     //=========================================================================
01497 
01499     class UpdateWhiteBalance : public PanoCommand
01500     {
01501     public:
01502         UpdateWhiteBalance(Panorama & p, double redFactor, double blueFactor)
01503             : PanoCommand(p),
01504               m_red(redFactor), m_blue(blueFactor)
01505         { };
01506 
01507         virtual bool processPanorama(Panorama& pano)
01508             {
01509                 pano.updateWhiteBalance(m_red,m_blue);
01510 
01511                 return true;
01512             }
01513         
01514         virtual std::string getName() const
01515             {
01516                 return "update global white balance";
01517             }
01518 
01519     private:
01520         double m_red;
01521         double m_blue;
01522     };
01523 
01524     //=========================================================================
01525     //=========================================================================
01526 
01528     class ResetToMeanExposure : public PanoCommand
01529     {
01530     public:
01531         ResetToMeanExposure(Panorama & p)
01532             : PanoCommand(p)
01533         { };
01534 
01535         virtual bool processPanorama(Panorama& pano)
01536             {
01537                 HuginBase::PanoramaOptions opts=pano.getOptions();
01538                 opts.outputExposureValue = PT::calcMeanExposure(pano);
01539                 pano.setOptions(opts);
01540 
01541                 return true;
01542             }
01543         
01544         virtual std::string getName() const
01545             {
01546                 return "set exposure to mean exposure";
01547             }
01548     };
01549 
01550     //=========================================================================
01551     //=========================================================================
01552 
01554     class DistributeImagesCmd : public PanoCommand
01555     {
01556     public:
01557         DistributeImagesCmd(Panorama & p)
01558             : PanoCommand(p)
01559         { };
01560 
01561         virtual bool processPanorama(Panorama& pano)
01562             {
01563                 int nrImages=pano.getNrOfImages();
01564                 if(nrImages>0)
01565                 {
01566                     const SrcPanoImage& img=pano.getImage(0);
01567                     double hfov=img.getHFOV();
01568                     int imgsPerRow;
01569                     //distribute all images
01570                     //for rectilinear images calculate number of rows
01571                     if(img.getProjection()==HuginBase::SrcPanoImage::RECTILINEAR)
01572                     {
01573                         imgsPerRow=std::max(3, int(360/(0.8*hfov)));
01574                         imgsPerRow=std::min(imgsPerRow, nrImages);
01575                     }
01576                     else
01577                     {
01578                         //all other images do in one row to prevent cluttered images with fisheye images and the like
01579                         imgsPerRow=nrImages;
01580                     };
01581                     double offset=0.75*hfov;
01582                     if((imgsPerRow-1)*offset>360)
01583                     {
01584                         offset=360/(imgsPerRow-1);
01585                     };
01586                     double yaw=-(imgsPerRow-1)/2.0*offset;
01587                     double pitch=0;
01588                     if(imgsPerRow<nrImages)
01589                     {
01590                         pitch=(-(std::ceil(double(nrImages)/double(imgsPerRow))-1)/2.0*offset);
01591                     };
01592                     HuginBase::VariableMapVector varsVec=pano.getVariables();
01593                     size_t counter=0;
01594                     for(size_t i=0; i<nrImages; i++)
01595                     {
01596                         HuginBase::VariableMap::iterator it=varsVec[i].find("y");
01597                         if(it!=varsVec[i].end())
01598                         {
01599                             it->second.setValue(yaw);
01600                         };
01601                         it=varsVec[i].find("p");
01602                         if(it!=varsVec[i].end())
01603                         {
01604                             it->second.setValue(pitch);
01605                         };
01606                         yaw+=offset;
01607                         counter++;
01608                         if(counter==imgsPerRow)
01609                         {
01610                             counter=0;
01611                             pitch+=offset;
01612                             yaw=-(imgsPerRow-1)/2.0*offset;
01613                         };
01614                     };
01615                     pano.updateVariables(varsVec);
01616                 };
01617 
01618                 return true;
01619             }
01620         
01621         virtual std::string getName() const
01622             {
01623                 return "distribute images";
01624             }
01625     };
01626 
01627 
01628 } // namespace PT
01629 
01630 #endif // _PANOCOMMAND_H

Generated on Mon Sep 22 01:25:38 2014 for Hugintrunk by  doxygen 1.3.9.1