pto_var.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00011 /*  This program is free software; you can redistribute it and/or
00012  *  modify it under the terms of the GNU General Public
00013  *  License as published by the Free Software Foundation; either
00014  *  version 2 of the License, or (at your option) any later version.
00015  *
00016  *  This software is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *  General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public
00022  *  License along with this software; if not, write to the Free Software
00023  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 #include <hugin_version.h>
00028 
00029 #include <fstream>
00030 #include <sstream>
00031 #include <getopt.h>
00032 #ifndef WIN32
00033 #include <unistd.h>
00034 #endif
00035 #include <panodata/Panorama.h>
00036 #include <panodata/ImageVariableTranslate.h>
00037 #include <panodata/ImageVariableGroup.h>
00038 #include <panodata/StandardImageVariableGroups.h>
00039 #include <boost/algorithm/string.hpp>
00040 #include <boost/regex.hpp>
00041 #include <boost/lexical_cast.hpp>
00042 #include "ParseExp.h"
00043 
00044 using namespace std;
00045 using namespace HuginBase;
00046 using namespace AppBase;
00047 
00048 struct ParseVar
00049 {
00050     std::string varname;
00051     int imgNr;
00052     std::string expression;
00053     bool removeOpt;
00054     ParseVar(): varname(""), imgNr(-1), expression(""), removeOpt(false){};
00055 };
00056 
00057 typedef std::vector<ParseVar> ParseVarVec;
00058 
00059 // parse a single variable and put result in struct ParseVar
00060 void ParseSingleOptVar(ParseVarVec& varVec, std::string s)
00061 {
00062     boost::regex reg("([!]?)([a-zA-Z]{1,3})(\\d*?)");
00063     boost::smatch matches;
00064     if(boost::regex_match(s, matches, reg))
00065     {
00066         if(matches.size()==4)
00067         {
00068             ParseVar var;
00069             std::string temp(matches[1].first, matches[1].second);
00070             var.removeOpt=(temp=="!");
00071             //check if variable name is valid
00072             temp=std::string(matches[2].first, matches[2].second);
00073             bool validVarname=false;
00074 #define image_variable( name, type, default_value ) \
00075             if (HuginBase::PTOVariableConverterFor##name::checkApplicability(temp))\
00076             {\
00077                 validVarname=true;\
00078             };
00079 #include "panodata/image_variables.h"
00080 #undef image_variable
00081             if(!validVarname)
00082             {
00083                 return;
00084             };
00085             var.varname=temp;
00086             // now parse (optional) image number
00087             temp=std::string(matches[3].first, matches[3].second);
00088             if(temp.length()>0)
00089             {
00090                 try
00091                 {
00092                     var.imgNr=boost::lexical_cast<int>(temp);
00093                 }
00094                 catch (boost::bad_lexical_cast)
00095                 {
00096                     var.imgNr=-1;
00097                 };
00098             };
00099             varVec.push_back(var);
00100         };
00101     };
00102 };
00103 
00104 void ParseSingleLinkVar(ParseVarVec& varVec, std::string s)
00105 {
00106     boost::regex reg("([a-zA-Z]{1,3})(\\d+?)");
00107     boost::smatch matches;
00108     if(boost::regex_match(s, matches, reg))
00109     {
00110         if(matches.size()==3)
00111         {
00112             ParseVar var;
00113             //check if variable name is valid
00114             std::string temp(matches[1].first, matches[1].second);
00115             bool validVarname=false;
00116 #define image_variable( name, type, default_value ) \
00117             if (HuginBase::PTOVariableConverterFor##name::checkApplicability(temp))\
00118             {\
00119                 validVarname=true;\
00120             };
00121 #include "panodata/image_variables.h"
00122 #undef image_variable
00123             if(!validVarname)
00124             {
00125                 return;
00126             };
00127             var.varname=temp;
00128             // now parse image number
00129             temp=std::string(matches[2].first, matches[2].second);
00130             try
00131             {
00132                 var.imgNr=boost::lexical_cast<int>(temp);
00133             }
00134             catch (boost::bad_lexical_cast)
00135             {
00136                 var.imgNr=-1;
00137                 return;
00138             };
00139             varVec.push_back(var);
00140         };
00141     };
00142 };
00143 
00144 void ParseSingleVar(ParseVarVec& varVec, std::string s)
00145 {
00146     boost::regex reg("([a-zA-Z]{1,3})(\\d*?)=(.*)");
00147     boost::smatch matches;
00148     if(boost::regex_match(s, matches, reg))
00149     {
00150         if(matches.size()==4)
00151         {
00152             ParseVar var;
00153             std::string temp(matches[1].first, matches[1].second);
00154             //check if variable name is valid
00155             bool validVarname=false;
00156 #define image_variable( name, type, default_value ) \
00157             if (HuginBase::PTOVariableConverterFor##name::checkApplicability(temp))\
00158             {\
00159                 validVarname=true;\
00160             };
00161 #include "panodata/image_variables.h"
00162 #undef image_variable
00163             if(!validVarname)
00164             {
00165                 return;
00166             };
00167             var.varname=temp;
00168             // now parse (optional) image number
00169             temp=std::string(matches[2].first, matches[2].second);
00170             if(temp.length()>0)
00171             {
00172                 try
00173                 {
00174                     var.imgNr=boost::lexical_cast<int>(temp);
00175                 }
00176                 catch (boost::bad_lexical_cast)
00177                 {
00178                     var.imgNr=-1;
00179                 };
00180             };
00181             // read expression
00182             var.expression=std::string(matches[3].first, matches[3].second);
00183             if(var.expression.length()==0)
00184             {
00185                 return;
00186             };
00187             varVec.push_back(var);
00188         };
00189     };
00190 };
00191 
00192 //parse complete variables string
00193 void ParseVariableString(ParseVarVec& parseVec, std::string input, void (*func)(ParseVarVec&, std::string))
00194 {
00195     std::vector<std::string> splitResult;
00196     boost::algorithm::split(splitResult, input, boost::algorithm::is_any_of(", "), boost::algorithm::token_compress_on);
00197     for(size_t i=0; i<splitResult.size();i++)
00198     {
00199         (*func)(parseVec, splitResult[i]);
00200     };
00201 };
00202 
00203 // adds given varname to optVec
00204 // does some additional checking:
00205 //   1. don't add y,p,r for anchor image
00206 //   2. handle vignetting and EMoR parameters as group
00207 void AddToOptVec(HuginBase::OptimizeVector& optVec, std::string varname, size_t imgNr, 
00208     std::set<size_t> refImgs, bool linkRefImgsYaw, bool linkRefImgsPitch, bool linkRefImgsRoll, std::vector<std::set<std::string> > groupedVars)
00209 {
00210     if(varname=="y")
00211     {
00212         if(!set_contains(refImgs, imgNr) || linkRefImgsYaw)
00213         {
00214             optVec[imgNr].insert(varname);
00215         };
00216     }
00217     else
00218     {
00219         if(varname=="p")
00220         {
00221             if(!set_contains(refImgs, imgNr) || linkRefImgsPitch)
00222             {
00223                 optVec[imgNr].insert(varname);
00224             };
00225         }
00226         else
00227         {
00228             if(varname=="r")
00229             {
00230                 if(!set_contains(refImgs, imgNr) || linkRefImgsRoll)
00231                 {
00232                     optVec[imgNr].insert(varname);
00233                 };
00234             }
00235             else
00236             {
00237                 if(varname=="TrX" || varname=="TrY" || varname=="TrZ" || varname=="Tpy" || varname=="Tpp")
00238                 {
00239                     if(!set_contains(refImgs, imgNr))
00240                     {
00241                         optVec[imgNr].insert(varname);
00242                     };
00243                 }
00244                 else
00245                 {
00246                     for(size_t i=0; i<groupedVars.size(); i++)
00247                     {
00248                         if(set_contains(groupedVars[i], varname))
00249                         {
00250                             for(std::set<std::string>::const_iterator it=groupedVars[i].begin(); it!=groupedVars[i].end(); it++)
00251                             {
00252                                 optVec[imgNr].insert(*it);
00253                             };
00254                             return;
00255                         };
00256                     };
00257                     optVec[imgNr].insert(varname);
00258                 };
00259             };
00260         };
00261     };
00262 };
00263 
00264 // remove given variable from optvec, handle also correct grouped variables
00265 void RemoveFromOptVec(HuginBase::OptimizeVector& optVec, std::string varname, size_t imgNr, std::vector<std::set<std::string> > groupedVars)
00266 {
00267     for(size_t i=0; i<groupedVars.size(); i++)
00268     {
00269         if(set_contains(groupedVars[i], varname))
00270         {
00271             for(std::set<std::string>::const_iterator it=groupedVars[i].begin(); it!=groupedVars[i].end(); it++)
00272             {
00273                 optVec[imgNr].erase(*it);
00274             };
00275             return;
00276         };
00277     };
00278     optVec[imgNr].erase(varname);
00279 };
00280 
00281 // link or unlink the parsed image variables
00282 void UnLinkVars(Panorama& pano, ParseVarVec parseVec, bool link)
00283 {
00284     for(size_t i=0; i<parseVec.size(); i++)
00285     {
00286         //skip invalid image numbers
00287         if(parseVec[i].imgNr<0 || parseVec[i].imgNr>=(int)pano.getNrOfImages())
00288         {
00289             continue;
00290         };
00291         
00292         //convert to ImageVariableGroup::IVE_name format
00293         std::set<HuginBase::ImageVariableGroup::ImageVariableEnum> variables;
00294 #define image_variable( name, type, default_value ) \
00295         if (HuginBase::PTOVariableConverterFor##name::checkApplicability(parseVec[i].varname))\
00296         {\
00297             variables.insert(HuginBase::ImageVariableGroup::IVE_##name);\
00298         };
00299 #include "panodata/image_variables.h"
00300 #undef image_variable
00301         
00302         if(variables.size()>0)
00303         {
00304             //lens variable
00305             if(set_contains(HuginBase::StandardImageVariableGroups::getLensVariables(), *variables.begin()))
00306             {
00307                 HuginBase::ImageVariableGroup group(HuginBase::StandardImageVariableGroups::getLensVariables(), pano);
00308                 if (link)
00309                 {
00310                     group.linkVariableImage(*variables.begin(), parseVec[i].imgNr);
00311                 }
00312                 else
00313                 {
00314                     group.unlinkVariableImage(*variables.begin(), parseVec[i].imgNr);
00315                     group.updatePartNumbers();
00316                 }
00317             }
00318             else
00319             {
00320                 //stack variables
00321                 // handle yaw, pitch, roll, TrX, TrY and TrZ always together
00322                 if(set_contains(HuginBase::StandardImageVariableGroups::getStackVariables(), *variables.begin()))
00323                 {
00324                     HuginBase::ImageVariableGroup group(HuginBase::StandardImageVariableGroups::getStackVariables(), pano);
00325                     if (link)
00326                     {
00327                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_Yaw, parseVec[i].imgNr);
00328                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_Pitch, parseVec[i].imgNr);
00329                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_Roll, parseVec[i].imgNr);
00330                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_X, parseVec[i].imgNr);
00331                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_Y, parseVec[i].imgNr);
00332                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_Z, parseVec[i].imgNr);
00333                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_TranslationPlaneYaw, parseVec[i].imgNr);
00334                         group.linkVariableImage(HuginBase::ImageVariableGroup::IVE_TranslationPlanePitch, parseVec[i].imgNr);
00335                     }
00336                     else
00337                     {
00338                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_Yaw, parseVec[i].imgNr);
00339                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_Pitch, parseVec[i].imgNr);
00340                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_Roll, parseVec[i].imgNr);
00341                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_X, parseVec[i].imgNr);
00342                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_Y, parseVec[i].imgNr);
00343                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_Z, parseVec[i].imgNr);
00344                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_TranslationPlaneYaw, parseVec[i].imgNr);
00345                         group.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_TranslationPlanePitch, parseVec[i].imgNr);
00346                         group.updatePartNumbers();
00347                     }
00348                 }
00349                 else
00350                 {
00351                     cerr << "Warning: " << parseVec[i].varname << " is not a valid linkable variable." << endl;
00352                 };
00353             };
00354         };
00355     };
00356 };
00357 
00358 bool UpdateSingleVar(Panorama &pano, ParseVar parseVar, size_t imgNr)
00359 {
00360     double val=pano.getImage(imgNr).getVar(parseVar.varname);
00361     Parser::ConstantMap constMap;
00362     constMap["i"]=1.0*imgNr;
00363     constMap["val"]=val;
00364     cout << "Updating variable " << parseVar.varname << imgNr << ": " << val;
00365     if(Parser::ParseExpression(parseVar.expression, val, constMap))
00366     {
00367         cout << " -> " << val << endl;
00368         HuginBase::Variable var(parseVar.varname, val);
00369         pano.updateVariable(imgNr, var);
00370         return true;
00371     }
00372     else
00373     {
00374         cout << endl;
00375         cerr << "Could not parse given expression \"" << parseVar.expression << "\" for image " << imgNr << "." << endl;
00376         return false;
00377     };
00378 };
00379 
00380 static void usage(const char* name)
00381 {
00382     cout << name << ": change image variables inside pto files" << endl
00383          << name << " version " << DISPLAY_VERSION << endl
00384          << endl
00385          << "Usage:  " << name << " [options] --opt|--link|--unlink|--set varlist input.pto" << endl
00386          << endl
00387          << "     -o, --output=file.pto  Output Hugin PTO file. Default: <filename>_var.pto" << endl
00388          << "     -h, --help             Shows this help" << endl
00389          << endl
00390          << "     --opt varlist          Change optimizer variables" << endl
00391          << "     --modify-opt           Modify the existing optimizer variables" << endl
00392          << "                            (without pto_var will start with an" << endl
00393          << "                             empty variables set)" << endl
00394          << "                            Examples:" << endl
00395          << "           --opt y,p,r        Optimize yaw, pitch and roll of all images" << endl
00396          << "                              (special treatment for anchor image applies)" << endl
00397          << "           --opt v0,b2        Optimize hfov of image 0 and barrel distortion" << endl    
00398          << "                              of image 2" << endl
00399          << "           --opt v,!v0        Optimize field of view for all images except" << endl
00400          << "                              for the first image" << endl
00401          << "           --opt !a,!b,!c     Don't optimise distortion (works only with" << endl
00402          << "                              switch --modify-opt together)" << endl
00403          << endl
00404          << "     --link varlist         Link given variables" << endl
00405          << "                            Example:" << endl
00406          << "           --link v3          Link hfov of image 3" << endl
00407          << "           --link a1,b1,c1    Link distortions parameter for image 1" << endl
00408          << endl
00409          << "     --unlink varlist       Unlink given variables" << endl
00410          << "                            Examples:" << endl
00411          << "           --unlink v5        Unlink hfov for image 5" << endl
00412          << "           --unlink a2,b2,c2  Unlink distortions parameters for image 2" << endl
00413          << endl
00414          << "     --set varlist          Sets variables to new values" << endl
00415          << "                            Examples:" << endl
00416          << "           --set y0=0,r0=0,p0=0  Resets position of image 0" << endl
00417          << "           --set Vx4=-10,Vy4=10  Sets vignetting offset for image 4" << endl
00418          << "           --set v=20            Sets the field of view to 20 for all images" << endl
00419          << "           --set y=val+20        Increase yaw by 20 deg for all images" << endl
00420          << "           --set v=val*1.1       Increase fov by 10 % for all images" << endl
00421          << "           --set y=i*20          Set yaw to 0, 20, 40, ..." << endl
00422          << "     --set-from-file filename  Sets variables to new values" << endl
00423          << "                               It reads the varlist from a file" << endl
00424          << endl;
00425 }
00426 
00427 int main(int argc, char* argv[])
00428 {
00429     // parse arguments
00430     const char* optstring = "o:h";
00431 
00432     enum
00433     {
00434         SWITCH_OPT=1000,
00435         SWITCH_LINK,
00436         SWITCH_UNLINK,
00437         SWITCH_SET,
00438         SWITCH_SET_FILE,
00439         OPT_MODIFY_OPTVEC
00440     };
00441     static struct option longOptions[] =
00442     {
00443         {"output", required_argument, NULL, 'o' },
00444         {"opt", required_argument, NULL, SWITCH_OPT },
00445         {"link", required_argument, NULL, SWITCH_LINK },
00446         {"unlink", required_argument, NULL, SWITCH_UNLINK },
00447         {"set", required_argument, NULL, SWITCH_SET },
00448         {"set-from-file", required_argument, NULL, SWITCH_SET_FILE },
00449         {"modify-opt", no_argument, NULL, OPT_MODIFY_OPTVEC },
00450         {"help", no_argument, NULL, 'h' },
00451         0
00452     };
00453 
00454     ParseVarVec optVars;
00455     ParseVarVec linkVars;
00456     ParseVarVec unlinkVars;
00457     ParseVarVec setVars;
00458     bool modifyOptVec=false;
00459     int c;
00460     int optionIndex = 0;
00461     string output;
00462     while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1)
00463     {
00464         switch (c)
00465         {
00466             case 'o':
00467                 output = optarg;
00468                 break;
00469             case 'h':
00470                 usage(argv[0]);
00471                 return 0;
00472             case SWITCH_OPT:
00473                 ParseVariableString(optVars, std::string(optarg), ParseSingleOptVar);
00474                 break;
00475             case SWITCH_LINK:
00476                 ParseVariableString(linkVars, std::string(optarg), ParseSingleLinkVar);
00477                 break;
00478             case SWITCH_UNLINK:
00479                 ParseVariableString(unlinkVars, std::string(optarg), ParseSingleLinkVar);
00480                 break;
00481             case SWITCH_SET:
00482                 ParseVariableString(setVars, std::string(optarg), ParseSingleVar);
00483                 break;
00484             case SWITCH_SET_FILE:
00485                 {
00486                     ifstream ifs(optarg);
00487                     if(ifs.is_open())
00488                     {
00489                         ostringstream contents;
00490                         contents << ifs.rdbuf();
00491                         ifs.close();
00492                         string s(contents.str());
00493                         boost::algorithm::replace_all(s, "\n", ",");
00494                         ParseVariableString(setVars, s, ParseSingleVar);
00495                     }
00496                     else
00497                     {
00498                         cerr << "Could not open file " << optarg << endl;
00499                     };
00500                 };
00501                 break;
00502             case OPT_MODIFY_OPTVEC:
00503                 modifyOptVec=true;
00504                 break;
00505             case ':':
00506                 cerr <<"Option " << longOptions[optionIndex].name << " requires a parameter." << endl;
00507                 return 1;
00508                 break;
00509             case '?':
00510                 break;
00511             default:
00512                 abort ();
00513         }
00514     }
00515 
00516     if (argc - optind == 0)
00517     {
00518         cerr << "Error: " << argv[0] << " needs at least one project file." << endl;
00519         return 1;
00520     };
00521     if (argc - optind != 1)
00522     {
00523         cout << "Error: " << argv[0] << " can only work on one project file at one time" << endl;
00524         return 1;
00525     };
00526 
00527     if(optVars.size() + linkVars.size() + unlinkVars.size() + setVars.size()==0)
00528     {
00529         cerr << "Error: no variables to modify given" << endl;
00530         return 1;
00531     };
00532 
00533     string input=argv[optind];
00534     // read panorama
00535     Panorama pano;
00536     ifstream prjfile(input.c_str());
00537     if (!prjfile.good())
00538     {
00539         cerr << "could not open script : " << input << endl;
00540         return 1;
00541     }
00542     pano.setFilePrefix(hugin_utils::getPathPrefix(input));
00543     DocumentData::ReadWriteError err = pano.readData(prjfile);
00544     if (err != DocumentData::SUCCESSFUL)
00545     {
00546         cerr << "error while parsing panos tool script: " << input << endl;
00547         cerr << "DocumentData::ReadWriteError code: " << err << endl;
00548         return 1;
00549     }
00550 
00551     if(pano.getNrOfImages()==0)
00552     {
00553         cerr << "error: project file does not contains any image" << endl;
00554         cerr << "aborting processing" << endl;
00555         return 1;
00556     };
00557 
00558     //link/unlink variables
00559     if(linkVars.size()>0)
00560     {
00561         UnLinkVars(pano, linkVars, true);
00562     };
00563 
00564     if(unlinkVars.size()>0)
00565     {
00566         UnLinkVars(pano, unlinkVars, false);
00567     };
00568 
00569     // set variables to new value
00570     if(setVars.size()>0)
00571     {
00572         for(size_t i=0; i<setVars.size(); i++)
00573         {
00574             //skip invalid image numbers
00575             if(setVars[i].imgNr>=(int)pano.getNrOfImages())
00576             {
00577                 continue;
00578             };
00579             if(setVars[i].imgNr<0)
00580             {
00581                 UIntSet updatedImgs;
00582                 for(size_t j=0; j<pano.getNrOfImages(); j++)
00583                 {
00584                     //if we already update the variable in this image via links, skip it
00585                     if(set_contains(updatedImgs, j))
00586                     {
00587                         continue;
00588                     };
00589                     // skip following images, if expression could not parsed
00590                     if(!UpdateSingleVar(pano, setVars[i], j))
00591                     {
00592                         break;
00593                     };
00594                     updatedImgs.insert(j);
00595                     if(j==pano.getNrOfImages()-1)
00596                     {
00597                         break;
00598                     };
00599                     // now remember linked variables
00600                     const HuginBase::SrcPanoImage& img1=pano.getImage(j);
00601 #define image_variable( name, type, default_value ) \
00602                     if (HuginBase::PTOVariableConverterFor##name::checkApplicability(setVars[i].varname))\
00603                     {\
00604                         if(img1.name##isLinked())\
00605                         {\
00606                             for(size_t k=j+1; k<pano.getNrOfImages(); k++)\
00607                             {\
00608                                 if(img1.name##isLinkedWith(pano.getImage(k)))\
00609                                 {\
00610                                     updatedImgs.insert(k);\
00611                                 }\
00612                             };\
00613                         };\
00614                     };
00615 #include "panodata/image_variables.h"
00616 #undef image_variable
00617                 };
00618             }
00619             else
00620             {
00621                 UpdateSingleVar(pano, setVars[i], setVars[i].imgNr);
00622             };
00623         };
00624     };
00625 
00626     // update optimzer vector
00627     if(optVars.size()>0)
00628     {
00629         std::set<size_t> refImgs=pano.getRefImages();
00630         bool linkRefImgsYaw=false;
00631         bool linkRefImgsPitch=false;
00632         bool linkRefImgsRoll=false;
00633         pano.checkRefOptStatus(linkRefImgsYaw, linkRefImgsPitch, linkRefImgsRoll);
00634 
00635         //simplify handling of variable groups
00636         std::vector<std::set<std::string> > groupedVars;
00637         std::set<std::string> varSet;
00638         varSet.insert("Vb");
00639         varSet.insert("Vc");
00640         varSet.insert("Vd");
00641         groupedVars.push_back(varSet);
00642         varSet.clear();
00643         varSet.insert("Vx");
00644         varSet.insert("Vy");
00645         groupedVars.push_back(varSet);
00646         varSet.clear();
00647         varSet.insert("Ra");
00648         varSet.insert("Rb");
00649         varSet.insert("Rc");
00650         varSet.insert("Rd");
00651         varSet.insert("Re");
00652         groupedVars.push_back(varSet);
00653 
00654         HuginBase::OptimizeVector optVec;
00655         if(modifyOptVec)
00656         {
00657             optVec=pano.getOptimizeVector();
00658         };
00659         if(optVec.size()!=pano.getNrOfImages())
00660         {
00661             optVec.resize(pano.getNrOfImages());
00662         };
00663         for(size_t i=0; i<optVars.size(); i++)
00664         {
00665             //skip invalid image numbers
00666             if(optVars[i].imgNr>=(int)pano.getNrOfImages())
00667             {
00668                 continue;
00669             };
00670             if(optVars[i].imgNr==-1)
00671             {
00672                 for(size_t imgNr=0; imgNr<pano.getNrOfImages(); imgNr++)
00673                 {
00674                     if(optVars[i].removeOpt)
00675                     {
00676                         RemoveFromOptVec(optVec, optVars[i].varname, imgNr, groupedVars);
00677                     }
00678                     else
00679                     {
00680                         AddToOptVec(optVec, optVars[i].varname, imgNr, refImgs, linkRefImgsYaw, linkRefImgsPitch, linkRefImgsRoll, groupedVars);
00681                     };
00682                 };
00683             }
00684             else
00685             {
00686                 if(optVars[i].removeOpt)
00687                 {
00688                     RemoveFromOptVec(optVec, optVars[i].varname, optVars[i].imgNr, groupedVars);
00689                 }
00690                 else
00691                 {
00692                     AddToOptVec(optVec, optVars[i].varname, optVars[i].imgNr, refImgs, true, true, true, groupedVars);
00693                 };
00694             };
00695         };
00696         pano.setOptimizerSwitch(0);
00697         pano.setPhotometricOptimizerSwitch(0);
00698         pano.setOptimizeVector(optVec);
00699     };
00700 
00701     //write output
00702     UIntSet imgs;
00703     fill_set(imgs,0, pano.getNrOfImages()-1);
00704     // Set output .pto filename if not given
00705     if (output=="")
00706     {
00707         output=input.substr(0,input.length()-4).append("_var.pto");
00708     }
00709     ofstream of(output.c_str());
00710     pano.printPanoramaScript(of, pano.getOptimizeVector(), pano.getOptions(), imgs, false, hugin_utils::getPathPrefix(input));
00711 
00712     cout << endl << "Written output to " << output << endl;
00713     return 0;
00714 }

Generated on Mon Jul 28 01:25:42 2014 for Hugintrunk by  doxygen 1.3.9.1