AssistantMakefilelibExport.cpp

Go to the documentation of this file.
00001 
00008 /*  This is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2 of the License, or (at your option) any later version.
00012  *
00013  *  This software is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public
00019  *  License along with this software; if not, write to the Free Software
00020  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #include "AssistantMakefilelibExport.h"
00025 
00026 #include <makefilelib/char_type.h>
00027 #include <iostream>
00028 #include <stdexcept>
00029 #include <fstream>
00030 #include <sstream>
00031 #include <locale>
00032 #include <makefilelib/Comment.h>
00033 #include <makefilelib/Variable.h>
00034 #include <makefilelib/VariableDef.h>
00035 #include <makefilelib/VariableRef.h>
00036 #include <makefilelib/MakefileItem.h>
00037 #include <makefilelib/Makefile.h>
00038 #include <makefilelib/AutoVariable.h>
00039 #include <makefilelib/Newline.h>
00040 #include <makefilelib/Rule.h>
00041 #include <makefilelib/Conditional.h>
00042 #include <makefilelib/Manager.h>
00043 #include <makefilelib/Anything.h>
00044 
00045 #include <panodata/PanoramaData.h>
00046 #include <hugin_utils/utils.h>
00047 #include "algorithms/optimizer/ImageGraph.h"
00048 
00049 namespace HuginBase
00050 {
00051 using namespace makefile;
00052 using namespace std;
00053 using namespace vigra;
00054 namespace mf = makefile;
00055 
00057 #define  newVarDef(var, name, ...) \
00058 mf::Variable* var = mgr.own(new mf::Variable(name, __VA_ARGS__)); \
00059 var->getDef().add();
00060 
00061 void AssistantMakefilelibExport::echoInfo(Rule& inforule, const std::string& info)
00062 {
00063 #ifdef _WINDOWS
00064     inforule.addCommand("echo " + hugin_utils::QuoteStringInternal<std::string>(info,"^","^&|<>"), false);
00065 #else
00066     // we need only a special quoting for the single quote, all other special chars are ignored by
00067     // surrounding with single quotes
00068     // also $ needs to be quoted inside the shell script
00069     inforule.addCommand("echo '" + hugin_utils::QuoteStringInternal<std::string>(
00070         hugin_utils::replaceAll<std::string>(info,"'","'\\''"),"$","$") + "'", false);
00071 #endif
00072 }
00073 
00074 bool AssistantMakefilelibExport::createItems()
00075 {
00076     // we use this Variable for initializing pointers that get an object only under certain conditions
00077     mf::Variable* nullvar = mgr.own(new mf::Variable("NOT_DEFINED", "This_variable_has_not_been_defined"));
00078 
00079     mgr.own_add((new Comment(
00080         "makefile for automatic panorama generating, created by hugin using the new makefilelib")));
00081 
00082 #ifdef _WINDOWS
00083     mgr.own_add(new Comment("Force using cmd.exe"));
00084     mf::Variable* winshell = mgr.own(new mf::Variable("SHELL", getenv("ComSpec"), Makefile::NONE));
00085     winshell->getDef().add();
00086 #endif
00087 
00088     //----------
00089     // set the tool commands
00090     mgr.own_add(new Comment("Tool configuration"));
00091     newVarDef(vicpfind, "ICPFIND", progs.icpfind)
00092     newVarDef(vceleste, "CELESTE", progs.celeste)
00093     newVarDef(vcheckpto, "CHECKPTO", progs.checkpto)
00094     newVarDef(vcpclean, "CPCLEAN", progs.cpclean)
00095     newVarDef(vautooptimiser, "AUTOOPTIMISER", progs.autooptimiser)
00096     newVarDef(vpanomodify, "PANO_MODIFY", progs.pano_modify)
00097     newVarDef(vlinefind, "LINEFIND", progs.linefind)
00098 
00099     newVarDef(vproject, "PROJECT", projectFile, Makefile::MAKE);
00100     newVarDef(vprojectShell, "PROJECT_SHELL", projectFile,Makefile::SHELL)
00101 
00102     Rule* all = mgr.own(new Rule());
00103     all->addTarget("all");
00104     all->addPrereq(vproject->getRef());
00105 
00106     mf::string outinproject=cstr(" -o ")+vprojectShell->getRef()+cstr(" ")+vprojectShell->getRef();
00107     bool runicp=(pano.getNrOfCtrlPoints()==0);
00108     if(!runicp)
00109     {
00110         //we check, if all images are connected
00111         //if not, we run also icpfind
00112         CPGraph graph;
00113         createCPGraph(pano, graph);
00114         CPComponents comps;
00115         runicp=findCPComponents(graph, comps)>1;
00116     };
00117     //build commandline for icpfind
00118     if(runicp)
00119     {
00120         //create cp find
00121         echoInfo(*all,"Finding control points...");
00122         all->addCommand(vicpfind->getRef()+outinproject);
00123         //building celeste command
00124         if(runCeleste)
00125         {
00126             mf::string celesteCommand=vceleste->getRef()+" ";
00127             valuestream.str("");    // clear the streams buffer
00128             valuestream << " -t " << celesteThreshold;
00129             celesteCommand+=valuestream.str()+" ";
00130             if(celesteSmallRadius)
00131                 celesteCommand+="-r 1 ";
00132             echoInfo(*all,"Remove control points in clouds...");
00133             all->addCommand(celesteCommand+cstr(" -o ")+vprojectShell->getRef()+cstr(" -i ")+vprojectShell->getRef());
00134         };
00135         //building cpclean command
00136         if(runCPClean)
00137         {
00138             echoInfo(*all,"Statistical cleaning of control points...");
00139             all->addCommand(vcpclean->getRef()+outinproject);
00140         };
00141     };
00142     //vertical line detector
00143     if(runLinefind)
00144     {
00145         CPVector allCP=pano.getCtrlPoints();
00146         bool hasVerticalLines=false;
00147         if(allCP.size()>0)
00148         {
00149             for(size_t i=0;i<allCP.size() && !hasVerticalLines;i++)
00150             {
00151                 hasVerticalLines=(allCP[i].mode==ControlPoint::X);
00152             };
00153         };
00154         if(!hasVerticalLines)
00155         {
00156             echoInfo(*all,"Searching for vertical lines...");
00157             all->addCommand(vlinefind->getRef()+outinproject);
00158         };
00159     };
00160     //now optimise all
00161     all->addCommand(vcheckpto->getRef()+" "+vprojectShell->getRef());
00162     echoInfo(*all,"Optimise project...");
00163     all->addCommand(vautooptimiser->getRef()+" -a -m -l -s"+outinproject);
00164     // if necessary scale down final pano
00165     echoInfo(*all,"Setting output options...");
00166     valuestream.str("");
00167     if(scale<=1.0)
00168     {
00169         valuestream << " --canvas=" << hugin_utils::roundi(scale*100) << "%%";
00170     };
00171     all->addCommand(vpanomodify->getRef()+valuestream.str()+cstr(" --crop=AUTO")+outinproject);
00172     all->add();
00173     return true;
00174 }
00175 
00176 }; //namespace
00177 

Generated on 21 Oct 2014 for Hugintrunk by  doxygen 1.4.7