00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00067
00068
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
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
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
00111
00112 CPGraph graph;
00113 createCPGraph(pano, graph);
00114 CPComponents comps;
00115 runicp=findCPComponents(graph, comps)>1;
00116 };
00117
00118 if(runicp)
00119 {
00120
00121 echoInfo(*all,"Finding control points...");
00122 all->addCommand(vicpfind->getRef()+outinproject);
00123
00124 if(runCeleste)
00125 {
00126 mf::string celesteCommand=vceleste->getRef()+" ";
00127 valuestream.str("");
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
00136 if(runCPClean)
00137 {
00138 echoInfo(*all,"Statistical cleaning of control points...");
00139 all->addCommand(vcpclean->getRef()+outinproject);
00140 };
00141 };
00142
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
00161 all->addCommand(vcheckpto->getRef()+" "+vprojectShell->getRef());
00162 echoInfo(*all,"Optimise project...");
00163 all->addCommand(vautooptimiser->getRef()+" -a -m -l -s"+outinproject);
00164
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 };
00177