00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00025 #include "PanoramaMakefilelibExport.h"
00026
00027 #include <makefilelib/char_type.h>
00028 #include <iostream>
00029 #include <stdexcept>
00030 #include <fstream>
00031 #include <sstream>
00032 #include <locale>
00033 #include <makefilelib/Comment.h>
00034 #include <makefilelib/Variable.h>
00035 #include <makefilelib/VariableDef.h>
00036 #include <makefilelib/VariableRef.h>
00037 #include <makefilelib/MakefileItem.h>
00038 #include <makefilelib/Makefile.h>
00039 #include <makefilelib/AutoVariable.h>
00040 #include <makefilelib/Newline.h>
00041 #include <makefilelib/Rule.h>
00042 #include <makefilelib/Conditional.h>
00043 #include <makefilelib/Manager.h>
00044 #include <makefilelib/Anything.h>
00045
00046 #include <panodata/PanoramaData.h>
00047 #include <hugin_utils/utils.h>
00048 #include <hugin_version.h>
00049 #include <algorithms/basic/LayerStacks.h>
00050 #ifdef _WINDOWS
00051 #include "windows.h"
00052 #endif
00053
00055 #define newVarDef(var, name, ...) \
00056 mf::Variable* var = mgr.own(new mf::Variable(name, __VA_ARGS__)); \
00057 var->getDef().add();
00058
00059 namespace HuginBase
00060 {
00061 using namespace makefile;
00062 using namespace std;
00063 using namespace vigra;
00064 namespace mf = makefile;
00065
00067 static const makefile::string hdrgrayRemappedExt("_gray.pgm");
00068 static const makefile::string hdrRemappedExt(".exr");
00069 static const makefile::string ldrRemappedExt(".tif");
00070 static const makefile::string ldrRemappedMode("TIFF_m");
00071 static const makefile::string hdrRemappedMode("EXR_m");
00072
00073 PanoramaMakefilelibExport::PanoramaMakefilelibExport(PanoramaData & pano_,
00074 const UIntSet & images_,
00075 const std::string & ptofile_,
00076 const std::string & outputPrefix_,
00077 const PTPrograms & progs_,
00078 const std::string & includePath_,
00079 std::vector<std::string> & outputFiles_,
00080 std::ostream & makefile_,
00081 const std::string& tmpDir_,
00082 const bool copyMetadata_,
00083 const int nrThreads_)
00084 : PanoramaAlgorithm(pano),
00085 pano(pano_), ptofile(ptofile_), outputPrefix(outputPrefix_),
00086 progs(progs_), includePath(includePath_), outputFiles(outputFiles_),
00087 makefile(makefile_), tmpDir(tmpDir_), copyMetadata(copyMetadata_), nrThreads(nrThreads_)
00088 {
00089 images=getImagesinROI(pano_,images_);
00090 valuestream.imbue(makefile::GetMakefileLocale());
00091 };
00092
00093 bool PanoramaMakefilelibExport::createItems()
00094 {
00095
00096 mf::Variable* nullvar = mgr.own(new mf::Variable("NOT_DEFINED", "This_variable_has_not_been_defined"));
00097
00098 mgr.own_add((new Comment(
00099 "makefile for panorama stitching, created by hugin using the new makefilelib")));
00100
00101
00102
00103 if(!tmpDir.empty())
00104 {
00105 #ifdef UNIX_LIKE
00106 mgr.own_add(new Comment("set temporary directory for UNIX_LIKE"));
00107 mf::Variable* vtmpdir = mgr.own(new mf::Variable("TMPDIR", tmpDir));
00108 vtmpdir->setExport(true); vtmpdir->getDef().add();
00109 #else
00110
00111
00112
00113 mgr.own_add(new Comment("set temporary directory for not UNIX_LIKE"));
00114 mf::Variable* vtmpdir = mgr.own(new mf::Variable("TMP", Makefile::quoteEnvironment(tmpDir),Makefile::NONE));
00115 vtmpdir->getDef().add();
00116 #endif
00117 }
00118
00119 #ifdef _WINDOWS
00120 mgr.own_add(new Comment("Force using cmd.exe"));
00121 mf::Variable* winshell = mgr.own(new mf::Variable("SHELL", getenv("ComSpec"), Makefile::NONE));
00122 winshell->getDef().add();
00123 #endif
00124
00125
00126
00127 mgr.own_add(new Comment("Tool configuration"));
00128 newVarDef(vnona, "NONA", progs.nona);
00129 newVarDef(vPTStitcher, "PTSTITCHER", progs.PTStitcher);
00130 newVarDef(vPTmender, "PTMENDER", progs.PTmender);
00131 newVarDef(vPTblender, "PTBLENDER", progs.PTblender);
00132 newVarDef(vPTmasker, "PTMASKER", progs.PTmasker);
00133 newVarDef(vPTroller, "PTROLLER", progs.PTroller);
00134 newVarDef(venblend, "ENBLEND", progs.enblend);
00135 newVarDef(venfuse, "ENFUSE", progs.enfuse);
00136 newVarDef(vsmartblend, "SMARTBLEND", progs.smartblend);
00137 newVarDef(vhdrmerge, "HDRMERGE", progs.hdrmerge);
00138 #ifdef _WINDOWS
00139 newVarDef(vrm, "RM", "del", Makefile::NONE);
00140 #else
00141 newVarDef(vrm, "RM", "rm");
00142 #endif
00143
00144 mf::Variable* vexiftool = mgr.own(new mf::Variable("EXIFTOOL", progs.exiftool));
00145 vexiftool->getDef().add();
00146
00147 if(nrThreads>0)
00148 {
00149
00150 mf::Variable* vOpenMPThreads = mgr.own(new mf::Variable("OMP_NUM_THREADS", nrThreads));
00151 vOpenMPThreads->setExport(true);
00152 vOpenMPThreads->getDef().add();
00153 };
00154
00155
00156 mgr.own_add(new Comment("Project parameters"));
00157 PanoramaOptions opts = pano.getOptions();
00158 mf::Variable* vhugin_projection = mgr.own(new mf::Variable("HUGIN_PROJECTION",
00159 opts.getProjection()));
00160 vhugin_projection->getDef().add();
00161
00162 mf::Variable* vhugin_hfov = mgr.own(new mf::Variable("HUGIN_HFOV", opts.getHFOV()));
00163 vhugin_hfov->getDef().add();
00164 mf::Variable* vhugin_width = mgr.own(new mf::Variable("HUGIN_WIDTH", opts.getWidth()));
00165 vhugin_width->getDef().add();
00166 mf::Variable* vhugin_height = mgr.own(new mf::Variable("HUGIN_HEIGHT", opts.getHeight()));
00167 vhugin_height->getDef().add();
00168
00169
00170
00171 mgr.own_add(new Comment("options for the programs"));
00172
00173 mf::Variable* vnonaldr = nullvar;
00174 mf::Variable* vnonaopts = nullvar;
00175 if(opts.remapper == PanoramaOptions::NONA)
00176 {
00177 makefile::string val;
00178 if (opts.outputImageType == "tif" && opts.outputLayersCompression.size() != 0)
00179 val = "-z " + opts.outputLayersCompression;
00180 else if (opts.outputImageType == "jpg")
00181 val = "-z LZW ";
00182
00183 vnonaldr = mgr.own(new mf::Variable("NONA_LDR_REMAPPED_COMP", val, Makefile::NONE));
00184 vnonaldr->getDef().add();
00185
00186 valuestream.str("");
00187 if(opts.remapUsingGPU)
00188 {
00189 valuestream << "-g ";
00190 };
00191 if(nrThreads>0)
00192 {
00193 valuestream << "-t " << nrThreads;
00194 };
00195 vnonaopts = mgr.own(new mf::Variable("NONA_OPTS",valuestream.str(), Makefile::NONE));
00196 vnonaopts->getDef().add();
00197 }
00198
00199
00200 mf::Variable* venblendopts = nullvar;
00201 mf::Variable* venblendldrcomp = nullvar;
00202 mf::Variable* venblendexposurecomp = nullvar;
00203 mf::Variable* venblendhdrcomp = nullvar;
00204
00205 if(opts.blendMode == PanoramaOptions::ENBLEND_BLEND)
00206 {
00207 {
00208 valuestream.str("");
00209 valuestream << opts.enblendOptions;
00210 if (opts.getHFOV() == 360.0)
00211
00212 valuestream << " -w";
00213
00214 vigra::Rect2D roi = opts.getROI();
00215 if (roi.top() != 0 || roi.left() != 0 )
00216 valuestream << " -f" << roi.width() << "x" << roi.height() << "+" << roi.left() << "+" << roi.top();
00217 else
00218 valuestream << " -f" << roi.width() << "x" << roi.height();
00219 venblendopts = mgr.own(new mf::Variable("ENBLEND_OPTS", valuestream.str(), Makefile::NONE));
00220 venblendopts->getDef().add();
00221 }
00222
00223 {
00224 valuestream.str("");
00225 if (opts.outputImageType == "tif" && opts.outputImageTypeCompression.size() != 0)
00226 valuestream << "--compression=" << opts.outputImageTypeCompression;
00227 else if (opts.outputImageType == "jpg")
00228 valuestream << "--compression=" << opts.quality;
00229
00230 venblendldrcomp = mgr.own(new mf::Variable("ENBLEND_LDR_COMP", valuestream.str(), Makefile::NONE));
00231 venblendldrcomp->getDef().add();
00232 }
00233
00234 {
00235 makefile::string val;
00236 if (opts.outputImageType == "tif" && opts.outputLayersCompression.size() != 0)
00237 val = "--compression=" + opts.outputLayersCompression;
00238 else if (opts.outputImageType == "jpg")
00239 val = "--compression=LZW ";
00240
00241 venblendexposurecomp = mgr.own(new mf::Variable("ENBLEND_EXPOSURE_COMP", val, Makefile::NONE));
00242 venblendexposurecomp->getDef().add();
00243 }
00244
00245 {
00246 makefile::string val;
00247 if (opts.outputImageTypeHDR == "tif" && opts.outputImageTypeHDRCompression.size() != 0) {
00248 val += "--compression=" + opts.outputImageTypeHDRCompression;
00249 }
00250 venblendhdrcomp = mgr.own(new mf::Variable("ENBLEND_HDR_COMP", val, Makefile::NONE));
00251 venblendhdrcomp->getDef().add();
00252 }
00253 }
00254
00255 mf::Variable* vptblenderopts = nullvar;
00256 if(opts.blendMode == PanoramaOptions::PTBLENDER_BLEND)
00257 {
00258 valuestream.str("");
00259 switch (opts.colorCorrection)
00260 {
00261 case PanoramaOptions::NONE:
00262 break;
00263 case PanoramaOptions::BRIGHTNESS_COLOR:
00264 valuestream << " -k " << opts.colorReferenceImage;
00265 break;
00266 case PanoramaOptions::BRIGHTNESS:
00267 valuestream << " -k " << opts.colorReferenceImage;
00268 break;
00269 case PanoramaOptions::COLOR:
00270 valuestream << " -k " << opts.colorReferenceImage;
00271 break;
00272 }
00273 vptblenderopts = mgr.own(new mf::Variable("PTBLENDER_OPTS", valuestream.str(), Makefile::NONE));
00274 vptblenderopts->getDef().add();
00275 }
00276
00277
00278 mf::Variable* vsmartblendopts = nullvar;
00279 if(opts.blendMode == PanoramaOptions::SMARTBLEND_BLEND)
00280 {
00281 vsmartblendopts = mgr.own(new mf::Variable(
00282 "SMARTBLEND_OPTS",
00283 opts.getHFOV() == 360.0 ? " -w" : ""));
00284 vsmartblendopts->getDef().add();
00285
00286 }
00287
00288
00289 mf::Variable* vhdrmergeopts = nullvar;
00290 if(opts.hdrMergeMode == PanoramaOptions::HDRMERGE_AVERAGE)
00291 {
00292 vhdrmergeopts = mgr.own(new mf::Variable(
00293 "HDRMERGE_OPTS", opts.hdrmergeOptions, Makefile::NONE));
00294 vhdrmergeopts->getDef().add();
00295 }
00296
00297
00298 newVarDef(venfuseopts,
00299 "ENFUSE_OPTS", opts.enfuseOptions +
00300 (opts.getHFOV() == 360.0 ? " -w" : ""), Makefile::NONE);
00301
00302
00303 newVarDef(vexiftoolcopyargs,
00304 "EXIFTOOL_COPY_ARGS", progs.exiftool_opts, Makefile::NONE);
00305
00306 pano_projection_features proj;
00307 bool readProjectionName=panoProjectionFeaturesQuery(opts.getProjection(), &proj)!=0;
00308
00309 std::ostringstream infostream;
00310 infostream.imbue(makefile::GetMakefileLocale());
00311 infostream << fixed;
00312 infostream.str("");
00313 #ifdef _WIN32
00314 std::string linebreak("&\\#xd;&\\#xa;");
00315 std::string quotechar("\"");
00316 #else
00317 std::string linebreak("&\\#xa;");
00318 std::string quotechar("'");
00319 #endif
00320 infostream << quotechar << "-Software=Hugin " << DISPLAY_VERSION << quotechar << " ";
00321 infostream << quotechar << "-UserComment<$${UserComment}" << linebreak;
00322 if(readProjectionName)
00323 {
00324 infostream << "Projection: " << proj.name << " (" << opts.getProjection() << ")" << linebreak;
00325 };
00326 infostream << "FOV: " << setprecision(0) << opts.getHFOV() << " x " << setprecision(0) << opts.getVFOV() << linebreak;
00327 infostream << "Ev: " << setprecision(2) << opts.outputExposureValue << quotechar << " -f";
00328 newVarDef(vexiftoolinfoargs, "EXIFTOOL_INFO_ARGS", infostream.str(), Makefile::NONE);
00329
00330
00331
00332 mgr.own_add(new Comment("the output panorama"));
00333
00334 newVarDef(vldrremappedprefix,
00335 "LDR_REMAPPED_PREFIX", outputPrefix, Makefile::MAKE);
00336 newVarDef(vldrremappedprefixshell,
00337 "LDR_REMAPPED_PREFIX_SHELL", vldrremappedprefix->getValue(), Makefile::SHELL);
00338
00339 newVarDef(vhdrstackremappedprefix,
00340 "HDR_STACK_REMAPPED_PREFIX", outputPrefix + "_hdr_", Makefile::MAKE);
00341 newVarDef(vhdrstackremappedprefixshell,
00342 "HDR_STACK_REMAPPED_PREFIX_SHELL", vhdrstackremappedprefix->getValue(), Makefile::SHELL);
00343
00344 newVarDef(vldrexposureremappedprefix,
00345 "LDR_EXPOSURE_REMAPPED_PREFIX", outputPrefix + "_exposure_layers_", Makefile::MAKE);
00346 newVarDef(vldrexposureremappedprefixshell,
00347 "LDR_EXPOSURE_REMAPPED_PREFIX_SHELL", vldrexposureremappedprefix->getValue(), Makefile::SHELL);
00348
00349 newVarDef(vprojectfile, "PROJECT_FILE", ptofile, Makefile::MAKE);
00350 newVarDef(vprojectfileshell, "PROJECT_FILE_SHELL", ptofile, Makefile::SHELL);
00351
00352 newVarDef(vldrblended, "LDR_BLENDED", outputPrefix + "." + opts.outputImageType, Makefile::MAKE);
00353 newVarDef(vldrblendedshell, "LDR_BLENDED_SHELL", vldrblended->getValue(), Makefile::SHELL);
00354
00355 newVarDef(vldrstackedblended, "LDR_STACKED_BLENDED", outputPrefix + "_fused." + opts.outputImageType, Makefile::MAKE);
00356 newVarDef(vldrstackedblendedshell, "LDR_STACKED_BLENDED_SHELL", vldrstackedblended->getValue(), Makefile::SHELL);
00357
00358 newVarDef(vldrexposurelayersfused,
00359 "LDR_EXPOSURE_LAYERS_FUSED", outputPrefix + "_blended_fused." + opts.outputImageType, Makefile::MAKE);
00360 newVarDef(vldrexposurelayersfusedshell,
00361 "LDR_EXPOSURE_LAYERS_FUSED_SHELL", vldrexposurelayersfused->getValue(), Makefile::SHELL);
00362
00363 newVarDef(vhdrblended, "HDR_BLENDED", outputPrefix + "_hdr." + opts.outputImageTypeHDR, Makefile::MAKE);
00364 newVarDef(vhdrblendedshell, "HDR_BLENDED_SHELL", vhdrblended->getValue(), Makefile::SHELL);
00365
00366
00367
00368 mgr.own_add(new Comment ("first input image"));
00369 newVarDef(vinimage1, "INPUT_IMAGE_1", pano.getImage(0).getFilename(), Makefile::MAKE);
00370 newVarDef(vinimage1shell, "INPUT_IMAGE_1_SHELL", pano.getImage(0).getFilename(), Makefile::SHELL);
00371
00372 mgr.own_add(new Comment("all input images"));
00373
00374 std::vector<std::string> inimages;
00375
00376 for (unsigned int i=0; i < pano.getNrOfImages(); i++)
00377 {
00378 inimages.push_back(pano.getImage(i).getFilename());
00379 }
00380 newVarDef(vinimages, "INPUT_IMAGES", inimages.begin(), inimages.end(), Makefile::MAKE, "\\\n");
00381 newVarDef(vinimagesshell, "INPUT_IMAGES_SHELL", inimages.begin(), inimages.end(), Makefile::SHELL, "\\\n");
00382
00383
00384 std::vector<std::string> remappedImages;
00385 std::vector<std::string> remappedHDRImages;
00386 std::vector<std::string> remappedHDRgrayImages;
00387
00388 for (UIntSet::const_iterator it = images.begin(); it != images.end(); it++)
00389 {
00390 std::ostringstream fn1, fn2, fn3;
00391 fn1 << outputPrefix << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
00392 fn2 << outputPrefix << "_hdr_" << std::setfill('0') << std::setw(4) << *it << hdrRemappedExt;
00393 fn3 << outputPrefix << "_hdr_" << std::setfill('0') << std::setw(4) << *it << hdrgrayRemappedExt;
00394 remappedImages.push_back(fn1.str());
00395 remappedHDRImages.push_back(fn2.str());
00396 remappedHDRgrayImages.push_back(fn3.str());
00397 }
00398 mgr.own_add(new Comment("remapped images"));
00399 newVarDef(vldrlayers, "LDR_LAYERS", remappedImages.begin(), remappedImages.end(), Makefile::MAKE, "\\\n");
00400 newVarDef(vldrlayersshell, "LDR_LAYERS_SHELL", remappedImages.begin(), remappedImages.end(), Makefile::SHELL, "\\\n");
00401
00402 mgr.own_add(new Comment("remapped images (hdr)"));
00403 newVarDef(vhdrlayers, "HDR_LAYERS", remappedHDRImages.begin(), remappedHDRImages.end(), Makefile::MAKE, "\\\n");
00404 newVarDef(vhdrlayersshell, "HDR_LAYERS_SHELL", remappedHDRImages.begin(), remappedHDRImages.end(), Makefile::SHELL, "\\\n");
00405
00406 mgr.own_add(new Comment("remapped maxval images"));
00407 newVarDef(vhdrgraylayers, "HDR_LAYERS_WEIGHTS", remappedHDRgrayImages.begin(), remappedHDRgrayImages.end(), Makefile::MAKE, "\\\n");
00408 newVarDef(vhdrgraylayersshell, "HDR_LAYERS_WEIGHTS_SHELL", remappedHDRgrayImages.begin(), remappedHDRgrayImages.end(), Makefile::SHELL, "\\\n");
00409
00410
00411
00412 std::vector<mf::Variable*> hdr_stacks, hdr_stacks_shell, hdr_stacks_input, hdr_stacks_input_shell;
00413 mgr.own_add(new Comment("stacked hdr images"));
00414 std::vector<UIntSet> stacks = getHDRStacks(pano, images, opts);
00415 mf::Variable* vhdrstacks,* vhdrstacksshell;
00416 std::vector<std::string> stackedhdrImgs;
00417 createstacks(stacks, "HDR_STACK", "_stack_hdr_", "_hdr_", hdrRemappedExt,
00418 hdr_stacks, hdr_stacks_shell, hdr_stacks_input, hdr_stacks_input_shell, vhdrstacks, vhdrstacksshell, stackedhdrImgs);
00419
00420 std::vector<mf::Variable*> ldrexp_stacks, ldrexp_stacks_shell, ldrexp_stacks_input, ldrexp_stacks_input_shell, ldrexp_stacks_pt_input, ldrexp_stacks_input_pt_shell;
00421 mgr.own_add(new Comment("number of image sets with similar exposure"));
00422 mf::Variable* vldrexposurelayers,* vldrexposurelayersshell,* vldrexposurelayersremapped,* vldrexposurelayersremappedshell;
00423 std::vector<UIntSet> exposures = getExposureLayers(pano, images, opts);
00424 std::vector<std::string> exposureimgs;
00425 createexposure(exposures, "LDR_EXPOSURE_LAYER", "_exposure_", "_exposure_layers_", ldrRemappedExt,
00426 ldrexp_stacks, ldrexp_stacks_shell, ldrexp_stacks_input, ldrexp_stacks_input_shell, ldrexp_stacks_pt_input, ldrexp_stacks_input_pt_shell,
00427 vldrexposurelayers, vldrexposurelayersshell, vldrexposurelayersremapped, vldrexposurelayersremappedshell,
00428 exposureimgs);
00429
00430 std::vector<mf::Variable*> ldr_stacks, ldr_stacks_shell, ldr_stacks_input, ldr_stacks_input_shell;
00431 mgr.own_add(new Comment("stacked ldr images"));
00432 mf::Variable* vldrstacks,* vldrstacksshell;
00433 std::vector<std::string> stackedldrimgs;
00434 createstacks(stacks, "LDR_STACK", "_stack_ldr_", "_exposure_layers_", ldrRemappedExt,
00435 ldr_stacks, ldr_stacks_shell, ldr_stacks_input, ldr_stacks_input_shell, vldrstacks, vldrstacksshell, stackedldrimgs);
00436
00437
00438
00439 if(!includePath.empty())
00440 {
00441 mgr.own_add(new Anything("include " + Makefile::quote(includePath, Makefile::MAKE)));
00442 return true;
00443 }
00444
00445
00446
00447
00448 std::vector<mf::Variable*> allprereqs, cleanprereqs;
00449
00450 if(opts.outputLDRBlended)
00451 {
00452 allprereqs.push_back(vldrblended);
00453 append(outputFiles, vldrblended->getValues());
00454 newVarDef(vdoldrblend, "DO_LDR_BLENDED", 1);
00455 if(!opts.outputLDRLayers)
00456 {
00457 cleanprereqs.push_back(vldrlayersshell);
00458 append(outputFiles, vldrlayers->getValues());
00459 }
00460 }
00461
00462 if(opts.outputLDRLayers)
00463 {
00464 allprereqs.push_back(vldrlayers);
00465 append(outputFiles, vldrlayers->getValues());
00466 }
00467
00468 if(opts.outputLDRExposureRemapped)
00469 {
00470 allprereqs.push_back(vldrexposurelayersremapped);
00471 append(outputFiles, vldrexposurelayersremapped->getValues());
00472 }
00473
00474 if(opts.outputLDRExposureLayers)
00475 {
00476 allprereqs.push_back(vldrexposurelayers);
00477 append(outputFiles, exposureimgs);
00478 if(!opts.outputLDRExposureRemapped)
00479 {
00480 cleanprereqs.push_back(vldrexposurelayersremappedshell);
00481 append(outputFiles, vldrexposurelayersremapped->getValues());
00482 }
00483 }
00484
00485 if(opts.outputLDRExposureLayersFused)
00486 {
00487 allprereqs.push_back(vldrexposurelayersfused);
00488 append(outputFiles, vldrexposurelayersfused->getValues());
00489 newVarDef(vdoldrexposurelayersfused, "DO_LDR_EXPOSURE_LAYERS_FUSED", 1);
00490 if(!opts.outputLDRExposureLayers)
00491 {
00492 cleanprereqs.push_back(vldrexposurelayersshell);
00493 append(outputFiles, exposureimgs);
00494 if(!opts.outputLDRExposureRemapped)
00495 {
00496 cleanprereqs.push_back(vldrexposurelayersremappedshell);
00497 append(outputFiles, vldrexposurelayersremapped->getValues());
00498 }
00499 }
00500 }
00501
00502 if(opts.outputLDRStacks)
00503 {
00504 allprereqs.push_back(vldrstacks);
00505 append(outputFiles, stackedldrimgs);
00506 if(!opts.outputLDRExposureRemapped)
00507 {
00508 cleanprereqs.push_back(vldrexposurelayersremappedshell);
00509 append(outputFiles, vldrexposurelayersremapped->getValues());
00510 }
00511 }
00512
00513 if(opts.outputLDRExposureBlended)
00514 {
00515 allprereqs.push_back(vldrstackedblended);
00516 append(outputFiles, vldrstackedblended->getValues());
00517 newVarDef(vdoldrstackedblended, "DO_LDR_STACKED_BLENDED", 1);
00518 if(!opts.outputLDRStacks)
00519 {
00520 cleanprereqs.push_back(vldrstacksshell);
00521 append(outputFiles, stackedldrimgs);
00522 if(!opts.outputLDRExposureRemapped)
00523 {
00524 cleanprereqs.push_back(vldrexposurelayersremappedshell);
00525 append(outputFiles, vldrexposurelayersremapped->getValues());
00526 }
00527 }
00528 }
00529
00530 if(opts.outputHDRLayers)
00531 {
00532 allprereqs.push_back(vhdrlayers);
00533 append(outputFiles, vhdrlayers->getValues());
00534 append(outputFiles, vhdrgraylayers->getValues());
00535 }
00536
00537 if(opts.outputHDRStacks)
00538 {
00539 allprereqs.push_back(vhdrstacks);
00540 append(outputFiles, stackedhdrImgs);
00541 if(!opts.outputHDRLayers)
00542 {
00543 cleanprereqs.push_back(vhdrlayersshell);
00544 cleanprereqs.push_back(vhdrgraylayersshell);
00545 append(outputFiles, vhdrlayers->getValues());
00546 append(outputFiles, vhdrgraylayers->getValues());
00547 }
00548 }
00549
00550 if(opts.outputHDRBlended)
00551 {
00552 allprereqs.push_back(vhdrblended);
00553 append(outputFiles, vhdrblended->getValues());
00554 newVarDef(vdohdrblended, "DO_HDR_BLENDED", 1);
00555 if(!opts.outputHDRStacks)
00556 {
00557 cleanprereqs.push_back(vhdrstacksshell);
00558 append(outputFiles, stackedhdrImgs);
00559 if(!opts.outputHDRLayers)
00560 {
00561 cleanprereqs.push_back(vhdrlayersshell);
00562 cleanprereqs.push_back(vhdrgraylayersshell);
00563 append(outputFiles, vhdrlayers->getValues());
00564 append(outputFiles, vhdrgraylayers->getValues());
00565 }
00566 }
00567 }
00568
00569
00570
00571
00572 Rule* start = mgr.own(new Rule());
00573 start->addTarget("startStitching");
00574 echoInfo(*start,"===========================================================================");
00575 echoInfo(*start,"Stitching panorama");
00576 echoInfo(*start,"===========================================================================");
00577
00578 Rule* all = mgr.own(new Rule());
00579 all->addTarget("all");
00580 all->addPrereq(start);
00581 for(std::vector<mf::Variable*>::const_iterator it = allprereqs.begin(); it != allprereqs.end(); it++)
00582 {
00583 all->addPrereq((*it));
00584 }
00585 all->add();
00586
00587 start->add();
00588
00589 Rule* clean = mgr.own(new Rule());
00590 clean->addTarget("clean");
00591 echoInfo(*clean,"===========================================================================");
00592 echoInfo(*clean,"Remove temporary files");
00593 echoInfo(*clean,"===========================================================================");
00594 std::string vdefs;
00595 for(std::vector<mf::Variable*>::const_iterator it = cleanprereqs.begin(); it != cleanprereqs.end(); it++)
00596 {
00597 vdefs += (*it)->getRef() + " ";
00598 }
00599 if(vdefs.length()>0)
00600 {
00601 clean->addCommand(vrm->getRef() + " " + vdefs,true,true);
00602 };
00603 clean->add();
00604
00605
00606
00607 Rule* test = mgr.own(new Rule());
00608 test->addTarget("test");
00609 echoInfo(*test,"===========================================================================");
00610 echoInfo(*test,"Testing programs");
00611 echoInfo(*test,"===========================================================================");
00612
00613 switch(opts.remapper) {
00614 case PanoramaOptions::NONA:
00615 createcheckProgCmd(*test,"nona",vnona->getRef()+" --help");
00616 break;
00617 case PanoramaOptions::PTMENDER:
00618 break;
00619 }
00620
00621 switch(opts.blendMode) {
00622 case PanoramaOptions::ENBLEND_BLEND:
00623 createcheckProgCmd(*test,"enblend",venblend->getRef()+" -h");
00624 break;
00625 case PanoramaOptions::PTBLENDER_BLEND:
00626 createcheckProgCmd(*test,"PTblender",vPTblender->getRef()+" -h");
00627 break;
00628 case PanoramaOptions::SMARTBLEND_BLEND:
00629 createcheckProgCmd(*test,"smartblend",vsmartblend->getRef());
00630 break;
00631 }
00632
00633 createcheckProgCmd(*test,"enfuse",venfuse->getRef()+" -h");
00634
00635 createcheckProgCmd(*test,"hugin_hdrmerge",vhdrmerge->getRef()+" -h");
00636
00637 if(copyMetadata)
00638 {
00639 createcheckProgCmd(*test,"exiftool",vexiftool->getRef()+" -ver");
00640 };
00641 test->add();
00642
00643
00644
00645 Rule* info = mgr.own(new Rule());
00646 info->addTarget("info");
00647 echoInfo(*info,"===========================================================================");
00648 echoInfo(*info,"*************** Panorama makefile generated by Hugin ***************");
00649 echoInfo(*info,"===========================================================================");
00650 echoInfo(*info,"System information");
00651 echoInfo(*info,"===========================================================================");
00652 printSystemInfo(*info);
00653 infostream.str("");
00654 infostream << DISPLAY_VERSION;
00655 echoInfo(*info,"===========================================================================");
00656 echoInfo(*info,"Output options");
00657 echoInfo(*info,"===========================================================================");
00658 echoInfo(*info,"Hugin Version: "+infostream.str());
00659 echoInfo(*info,"Project file: "+ptofile);
00660 echoInfo(*info,"Output prefix: "+outputPrefix);
00661 if (readProjectionName)
00662 {
00663 infostream.str("");
00664 infostream << proj.name << " (" << opts.getProjection() << ")";
00665 echoInfo(*info,"Projection: "+infostream.str());
00666 }
00667 std::vector<double> parameters=opts.getProjectionParameters();
00668 if(parameters.size()>0)
00669 {
00670 infostream.str("");
00671 unsigned int i=0;
00672 infostream << setprecision(2) << parameters[i];
00673 i++;
00674 while(i<parameters.size())
00675 {
00676 infostream << ", " << parameters[i];
00677 i++;
00678 };
00679 echoInfo(*info,"Projection parameters: "+infostream.str());
00680 };
00681 infostream.str("");
00682 infostream << setprecision(0) << opts.getHFOV() << " x " << setprecision(0) << opts.getVFOV();
00683 echoInfo(*info,"Field of view: "+infostream.str());
00684 infostream.str("");
00685 infostream << opts.getWidth() << " x " << opts.getHeight();
00686 echoInfo(*info,"Canvas dimensions: "+infostream.str());
00687 infostream.str("");
00688 infostream << "(" << opts.getROI().left() << "," << opts.getROI().top() << ") - (" << opts.getROI().right() << "," << opts.getROI().bottom() << ")";
00689 echoInfo(*info,"Crop area: "+infostream.str());
00690 infostream.str("");
00691 infostream << setprecision(2) << opts.outputExposureValue;
00692 echoInfo(*info,"Output exposure value: "+infostream.str());
00693 infostream.str("");
00694 infostream << setprecision(3) << opts.outputStacksMinOverlap;
00695 echoInfo(*info,"Output stacks minimum overlap: "+infostream.str());
00696 infostream.str("");
00697 infostream << setprecision(2) << opts.outputLayersExposureDiff;
00698 echoInfo(*info,"Output layers maximum Ev difference: "+infostream.str());
00699 echoInfo(*info,"Selected outputs");
00700 if(opts.outputLDRBlended || opts.outputLDRLayers)
00701 {
00702 echoInfo(*info,"Normal panorama");
00703 if(opts.outputLDRBlended)
00704 echoInfo(*info,"* Blended panorama");
00705 if(opts.outputLDRLayers)
00706 echoInfo(*info,"* Remapped images");
00707 };
00708 if(opts.outputLDRExposureBlended || opts.outputLDRExposureLayersFused || opts.outputLDRExposureLayers || opts.outputLDRExposureRemapped || opts.outputLDRStacks)
00709 {
00710 echoInfo(*info,"Exposure fusion");
00711 if(opts.outputLDRExposureBlended)
00712 echoInfo(*info,"* Fused and blended panorama");
00713 if(opts.outputLDRExposureLayersFused)
00714 echoInfo(*info,"* Blended and fused panorama");
00715 if(opts.outputLDRExposureLayers)
00716 echoInfo(*info,"* Blended exposure layers");
00717 if(opts.outputLDRStacks)
00718 echoInfo(*info,"* Remapped fused stacks");
00719 if(opts.outputLDRExposureRemapped)
00720 echoInfo(*info,"* Remapped images");
00721 };
00722 if(opts.outputHDRBlended || opts.outputHDRLayers || opts.outputHDRStacks)
00723 {
00724 echoInfo(*info,"HDR merging");
00725 if(opts.outputHDRBlended)
00726 echoInfo(*info,"* Merged and blended panorama");
00727 if(opts.outputHDRStacks)
00728 echoInfo(*info,"* Remapped merged stacks");
00729 if(opts.outputHDRLayers)
00730 echoInfo(*info,"* Remapped images");
00731 };
00732 if(opts.remapUsingGPU)
00733 echoInfo(*info,"Using GPU for remapping");
00734
00735 echoInfo(*info,"===========================================================================");
00736 echoInfo(*info,"Input images");
00737 echoInfo(*info,"===========================================================================");
00738 infostream.str("");
00739 infostream << pano.getNrOfImages();
00740 echoInfo(*info,"Number of images in project file: "+infostream.str());
00741 infostream.str("");
00742 infostream << images.size();
00743 echoInfo(*info,"Number of active images: "+infostream.str());
00744 for(UIntSet::const_iterator it=images.begin();it!=images.end();it++)
00745 {
00746 infostream.str("");
00747 const HuginBase::SrcPanoImage &img=pano.getImage(*it);
00748 infostream << "Image " << *it << ": " << img.getFilename();
00749 echoInfo(*info,infostream.str());
00750 infostream.str("");
00751 infostream << "Image " << *it << ": Size " << img.getSize().width() << "x" << img.getSize().height() << ", Exposure: " << setprecision(2) << img.getExposureValue();
00752 echoInfo(*info,infostream.str());
00753 };
00754 info->add();
00755
00756
00757
00758 if(opts.remapper == PanoramaOptions::NONA)
00759 {
00760 mgr.own_add(new Comment("Rules for ordinary TIFF_m and hdr output"));
00761 UIntSet::const_iterator it = images.begin();
00762 size_t i=0;
00763 for(; it != images.end(); it++, i++)
00764 {
00765 std::string source = Makefile::quote(pano.getImage(*it).getFilename(), Makefile::MAKE);
00766 std::ostringstream imgnr;
00767 imgnr << *it;
00768
00769
00770 Rule* ruleldr = mgr.own(new Rule()); ruleldr->add();
00771 ruleldr->addTarget(Makefile::quote(remappedImages[i], Makefile::MAKE));
00772 ruleldr->addPrereq(source);
00773 ruleldr->addPrereq(vprojectfile);
00774 ruleldr->addCommand(
00775 vnona->getRef() +" "+ vnonaopts->getRef() +" "+ vnonaldr->getRef()
00776 + " -r ldr -m " + ldrRemappedMode + " -o " + vldrremappedprefixshell->getRef() +
00777 " -i " + imgnr.str() +" "+ vprojectfileshell->getRef());
00778
00779
00780 Rule* rulehdr = mgr.own(new Rule()); rulehdr->add();
00781 rulehdr->addTarget(Makefile::quote(remappedHDRImages[i], Makefile::MAKE));
00782 rulehdr->addPrereq(source);
00783 rulehdr->addPrereq(vprojectfile);
00784 rulehdr->addCommand(
00785 vnona->getRef() +" "+ vnonaopts->getRef() +" -r hdr -m " + hdrRemappedMode + " -o " +
00786 vhdrstackremappedprefixshell->getRef() + " -i " + imgnr.str() +" "+ vprojectfileshell->getRef());
00787 }
00788
00789 mgr.own_add(new Comment("Rules for exposure layer output"));
00790
00791 size_t j=0;
00792 for(i=0; i < exposures.size(); i++)
00793 {
00794 for(UIntSet::const_iterator it = exposures[i].begin(); it != exposures[i].end(); it++, j++)
00795 {
00796 std::ostringstream expvalue, imgnr;
00797 imgnr << *it;
00798 expvalue.imbue(makefile::GetMakefileLocale());
00799 expvalue << pano.getSrcImage(*it).getExposureValue();
00800 Rule* rule = mgr.own(new Rule()); rule->add();
00801 rule->addTarget(Makefile::quote(vldrexposurelayersremapped->getValues()[j], Makefile::MAKE));
00802 rule->addPrereq(Makefile::quote(pano.getImage(*it).getFilename(), Makefile::MAKE));
00803 rule->addPrereq(vprojectfile);
00804 rule->addCommand(
00805 vnona->getRef() +" "+ vnonaopts->getRef() +" "+ vnonaldr->getRef()
00806 + " -r ldr -e " + expvalue.str() + " -m " + ldrRemappedMode + " -o " + vldrexposureremappedprefixshell->getRef() +
00807 " -i " + imgnr.str() +" "+ vprojectfileshell->getRef());
00808
00809 }
00810 }
00811 }
00812
00813 if(opts.remapper == PanoramaOptions::PTMENDER)
00814 {
00815 Rule* rule = mgr.own(new Rule()); rule->add();
00816 rule->addTarget(vldrlayers);
00817 rule->addPrereq(vinimages);
00818 rule->addPrereq(vprojectfile);
00819 rule->addCommand(vPTmender->getRef() + " -o " + vldrremappedprefixshell->getRef() +" "+
00820 vprojectfileshell->getRef());
00821 }
00822
00823
00824
00825 mgr.own_add(new Comment("Rules for LDR and HDR stack merging, a rule for each stack"));
00826 for(size_t i=0; i< stacks.size(); i++)
00827 {
00828 std::ostringstream imgnr;
00829 imgnr << i;
00830
00831 Rule* ruleldr = mgr.own(new Rule()); ruleldr->add();
00832 ruleldr->addTarget(ldr_stacks[i]);
00833 ruleldr->addPrereq(ldr_stacks_input[i]);
00834 ruleldr->addCommand(venfuse->getRef() +" "+ venfuseopts->getRef() + " -o " +
00835 ldr_stacks_shell[i]->getRef() +" -- "+ ldr_stacks_input_shell[i]->getRef());
00836 if(copyMetadata)
00837 {
00838 ruleldr->addCommand("-" + vexiftool->getRef() + " -overwrite_original_in_place -TagsFromFile " +
00839 vinimage1shell->getRef() +" "+ vexiftoolcopyargs->getRef() +" "+ ldr_stacks_shell[i]->getRef());
00840 };
00841
00842 Rule* rulehdr = mgr.own(new Rule()); rulehdr->add();
00843 rulehdr->addTarget(hdr_stacks[i]);
00844 rulehdr->addPrereq(hdr_stacks_input[i]);
00845 rulehdr->addCommand(vhdrmerge->getRef() +" "+ vhdrmergeopts->getRef() + " -o " +
00846 hdr_stacks_shell[i]->getRef() +" -- "+ hdr_stacks_input_shell[i]->getRef());
00847 }
00848
00849
00850
00851 const std::string enblendcmd = venblend->getRef() +" "+ venblendldrcomp->getRef() +" "+
00852 venblendopts->getRef() + " -o ";
00853 const std::string exifcmd = "-" + vexiftool->getRef() + " -overwrite_original_in_place -TagsFromFile " +
00854 vinimage1shell->getRef() +" "+ vexiftoolcopyargs->getRef() +' ';
00855 const std::string exifcmd2 = "-" + vexiftool->getRef() + " -E -overwrite_original_in_place -TagsFromFile " +
00856 vinimage1shell->getRef() +" "+ vexiftoolcopyargs->getRef() + " " + vexiftoolinfoargs->getRef() + " ";
00857 const std::string ptrollercmd = vPTroller->getRef() + " -o ";
00858
00859 if(opts.blendMode == PanoramaOptions::ENBLEND_BLEND)
00860 {
00861 Rule* rule = mgr.own(new Rule()); rule->add();
00862
00863
00864 rule->addTarget(vldrblended);
00865 rule->addPrereq(vldrlayers);
00866 rule->addCommand(enblendcmd + vldrblendedshell->getRef() +" -- "+ vldrlayersshell->getRef());
00867 if(copyMetadata)
00868 {
00869 rule->addCommand(exifcmd2 + vldrblendedshell->getRef());
00870 };
00871
00872
00873 for(unsigned i=0; i < exposures.size(); i++)
00874 {
00875 rule = mgr.own(new Rule()); rule->add();
00876 rule->addTarget(ldrexp_stacks[i]);
00877 rule->addPrereq(ldrexp_stacks_input[i]);
00878 rule->addCommand(venblend->getRef() +" "+ venblendexposurecomp->getRef() + " " +
00879 venblendopts->getRef() + " -o " + ldrexp_stacks_shell[i]->getRef() + " -- " +
00880 ldrexp_stacks_input_shell[i]->getRef());
00881 if(copyMetadata)
00882 {
00883 rule->addCommand(exifcmd + ldrexp_stacks_shell[i]->getRef());
00884 };
00885 }
00886
00887
00888 rule = mgr.own(new Rule()); rule->add();
00889 rule->addTarget(vldrstackedblended);
00890 rule->addPrereq(vldrstacks);
00891 rule->addCommand(enblendcmd + vldrstackedblendedshell->getRef() +" -- "+ vldrstacksshell->getRef());
00892 if(copyMetadata)
00893 {
00894 rule->addCommand(exifcmd2 + vldrstackedblendedshell->getRef());
00895 };
00896
00897
00898 rule = mgr.own(new Rule()); rule->add();
00899 rule->addTarget(vldrexposurelayersfused);
00900 rule->addPrereq(vldrexposurelayers);
00901 rule->addCommand(venfuse->getRef() +" "+ venblendldrcomp->getRef() +" "+ venfuseopts->getRef() + " -o " +
00902 vldrexposurelayersfusedshell->getRef() +" -- "+ vldrexposurelayersshell->getRef());
00903 if(copyMetadata)
00904 {
00905 rule->addCommand(exifcmd2 + vldrexposurelayersfusedshell->getRef());
00906 };
00907
00908
00909 rule = mgr.own(new Rule()); rule->add();
00910 rule->addTarget(vhdrblended);
00911 rule->addPrereq(vhdrstacks);
00912 rule->addCommand(venblend->getRef() +" "+ venblendhdrcomp->getRef() +" "+ venblendopts->getRef() + " -o " +
00913 vhdrblendedshell->getRef() +" -- "+ vhdrstacksshell->getRef());
00914
00915
00916 rule = mgr.own(new Rule()); rule->add();
00917 rule->addTarget(vldrremappedprefix->getRef() + "_multilayer.tif");
00918 rule->addPrereq(vldrlayers);
00919 rule->addCommand("tiffcp " + vldrlayersshell->getRef() +" "+ vldrremappedprefixshell->getRef() + "_multilayer.tif");
00920
00921 rule = mgr.own(new Rule()); rule->add();
00922 rule->addTarget(vldrremappedprefix->getRef() + "_fused_multilayer.tif");
00923 rule->addPrereq(vldrstacks);
00924 rule->addPrereq(vldrexposurelayers);
00925 rule->addCommand("tiffcp " + vldrstacksshell->getRef() +" "+ vldrexposurelayersshell->getRef() +" "+ vldrremappedprefixshell->getRef() + "_fused_multilayer.tif");
00926
00927 rule = mgr.own(new Rule()); rule->add();
00928 rule->addTarget(vldrremappedprefix->getRef() + "_multilayer.psd");
00929 rule->addPrereq(vldrlayers);
00930 rule->addCommand("PTtiff2psd -o " + vldrremappedprefixshell->getRef() + "_multilayer.psd " + vldrlayersshell->getRef());
00931
00932 rule = mgr.own(new Rule()); rule->add();
00933 rule->addTarget(vldrremappedprefix->getRef() + "_fused_multilayer.psd");
00934 rule->addPrereq(vldrstacks);
00935 rule->addPrereq(vldrexposurelayers);
00936 rule->addCommand("PTtiff2psd -o " + vldrremappedprefixshell->getRef() + "_fused_multilayer.psd " + vldrstacksshell->getRef() +
00937 vldrexposurelayersshell->getRef());
00938 }
00939
00940
00941 if(opts.blendMode == PanoramaOptions::NO_BLEND)
00942 {
00943 Rule* rule = mgr.own(new Rule()); rule->add();
00944
00945
00946 rule->addTarget(vldrblended);
00947 rule->addPrereq(vldrlayers);
00948 rule->addCommand("-" + vrm->getRef() +" "+ vldrblendedshell->getRef());
00949 rule->addCommand(ptrollercmd + vldrblendedshell->getRef() +" "+ vldrlayersshell->getRef());
00950 if(copyMetadata)
00951 {
00952 rule->addCommand(exifcmd2 + vldrblendedshell->getRef());
00953 };
00954
00955
00956 for(unsigned i=0; i < exposures.size(); i++)
00957 {
00958 rule = mgr.own(new Rule()); rule->add();
00959 rule->addTarget(ldrexp_stacks[i]);
00960 rule->addPrereq(ldrexp_stacks_input[i]);
00961 rule->addCommand("-" + vrm->getRef() +" "+ ldrexp_stacks_shell[i]->getRef());
00962 rule->addCommand(ptrollercmd + ldrexp_stacks_shell[i]->getRef());
00963 if(copyMetadata)
00964 {
00965 rule->addCommand(exifcmd + ldrexp_stacks_shell[i]->getRef());
00966 };
00967 }
00968
00969 rule = mgr.own(new Rule()); rule->add();
00970 rule->addTarget(vldrstackedblended);
00971 rule->addPrereq(vldrstacks);
00972 rule->addCommand("-" + vrm->getRef() +" "+ vldrstackedblendedshell->getRef());
00973 rule->addCommand(ptrollercmd + vldrstackedblendedshell->getRef() +" "+ vldrstacksshell->getRef());
00974 if(copyMetadata)
00975 {
00976 rule->addCommand(exifcmd2 + vldrstackedblendedshell->getRef());
00977 };
00978
00979
00980 rule = mgr.own(new Rule()); rule->add();
00981 rule->addTarget(vhdrblended);
00982 rule->addPrereq(vhdrlayers);
00983 rule->addCommand(vhdrmerge->getRef() +" "+ vhdrmergeopts->getRef() + " -o " +
00984 vhdrblendedshell->getRef() +" "+ vhdrlayersshell->getRef());
00985 }
00986 return true;
00987 }
00988
00989
00990 void PanoramaMakefilelibExport::createstacks(const std::vector<UIntSet> stackdata,
00991 const std::string stkname,
00992 const std::string filenamecenter, const std::string inputfilenamecenter, const std::string filenameext,
00993 std::vector<mf::Variable*>& stacks,
00994 std::vector<mf::Variable*>& stacks_shell,
00995 std::vector<mf::Variable*>& stacks_input,
00996 std::vector<makefile::Variable*>& stacks_input_shell,
00997 mf::Variable*& vstacks,
00998 mf::Variable*& vstacksshell,
00999 std::vector<std::string>& allfiles)
01000 {
01001 std::ostringstream stknrs;
01002 for (unsigned i=0; i < stackdata.size(); i++)
01003 {
01004 stknrs << i << " ";
01005 std::ostringstream filename, stackname;
01006 filename << outputPrefix << filenamecenter << std::setfill('0') << std::setw(4) << i << filenameext;
01007 stackname << stkname << "_" << i;
01008 allfiles.push_back(filename.str());
01009
01010 std::vector<std::string> inputs;
01011 for (UIntSet::const_iterator it = stackdata[i].begin(); it != stackdata[i].end(); it++)
01012 {
01013 std::ostringstream fns;
01014 fns << outputPrefix << inputfilenamecenter << std::setfill('0') << std::setw(4) << *it << filenameext;
01015 inputs.push_back(fns.str());
01016 }
01017 mf::Variable* v;
01018 v = mgr.own(new mf::Variable(stackname.str(), filename.str(), Makefile::MAKE));
01019 stacks.push_back(v);
01020 v->getDef().add();
01021
01022 v = mgr.own(new mf::Variable(stackname.str() + "_SHELL", filename.str(), Makefile::SHELL));
01023 stacks_shell.push_back(v);
01024 v->getDef().add();
01025
01026 v= mgr.own(new mf::Variable(stackname.str() + "_INPUT", inputs.begin(), inputs.end(), Makefile::MAKE, "\\\n"));
01027 stacks_input.push_back(v);
01028 v->getDef().add();
01029
01030 v = mgr.own(new mf::Variable(stackname.str() + "_INPUT_SHELL", inputs.begin(), inputs.end(), Makefile::SHELL, "\\\n"));
01031 stacks_input_shell.push_back(v);
01032 v->getDef().add();
01033 }
01034 newVarDef(vhdrstacksnr, stkname + "S_NUMBERS", stknrs.str(), Makefile::NONE);
01035
01036 std::string stackrefs;
01037 std::string stackrefsshell;
01038 std::vector<mf::Variable*>::const_iterator it, it2;
01039 it = stacks.begin();
01040 it2 = stacks_shell.begin();
01041 for(; it != stacks.end() && it2 != stacks_shell.end(); it++, it2++)
01042 {
01043 stackrefs += (*it)->getRef() + " ";
01044 stackrefsshell += (*it2)->getRef() + " ";
01045 }
01046 vstacks = mgr.own(new mf::Variable(stkname + "S", stackrefs, Makefile::NONE));
01047 vstacks->getDef().add();
01048 vstacksshell = mgr.own(new mf::Variable(stkname + "S_SHELL", stackrefsshell, Makefile::NONE));
01049 vstacksshell->getDef().add();
01050
01051 }
01052 void PanoramaMakefilelibExport::createexposure(const std::vector<UIntSet> stackdata,
01053 const std::string stkname,
01054 const std::string filenamecenter, const std::string inputfilenamecenter, const std::string filenameext,
01055 std::vector<mf::Variable*>& stacks,
01056 std::vector<mf::Variable*>& stacks_shell,
01057 std::vector<mf::Variable*>& stacks_input,
01058 std::vector<mf::Variable*>& stacks_input_shell,
01059 std::vector<mf::Variable*>& stacks_input_pt,
01060 std::vector<mf::Variable*>& stacks_input_pt_shell,
01061 mf::Variable*& vstacks,
01062 mf::Variable*& vstacksshell,
01063 mf::Variable*& vstacksrem,
01064 mf::Variable*& vstacksremshell,
01065 std::vector<std::string>& alllayers)
01066 {
01067 std::vector<std::string> allimgs;
01068 std::ostringstream stknrs;
01069 for (unsigned i=0; i < stackdata.size(); i++)
01070 {
01071 stknrs << i << " ";
01072 std::ostringstream filename, stackname;
01073 filename << outputPrefix << filenamecenter << std::setfill('0') << std::setw(4) << i << filenameext;
01074 stackname << stkname << "_" << i;
01075 alllayers.push_back(filename.str());
01076
01077 std::vector<std::string> inputs, inputspt;
01078 double exposure = 0;
01079 for (UIntSet::const_iterator it = stackdata[i].begin(); it != stackdata[i].end(); it++)
01080 {
01081 std::ostringstream fns, fnpt;
01082 fns << outputPrefix << inputfilenamecenter << std::setfill('0') << std::setw(4) << *it << filenameext;
01083 fnpt << outputPrefix << std::setfill('0') << std::setw(4) << *it << filenameext;
01084 inputs.push_back(fns.str());
01085 inputspt.push_back(fnpt.str());
01086
01087 exposure += pano.getSrcImage(*it).getExposureValue();
01088 allimgs.push_back(fns.str());
01089 }
01090 mf::Variable* v;
01091 v = mgr.own(new mf::Variable(stackname.str(), filename.str(), Makefile::MAKE));
01092 stacks.push_back(v);
01093 v->getDef().add();
01094
01095 v = mgr.own(new mf::Variable(stackname.str() + "_SHELL", filename.str(), Makefile::SHELL));
01096 stacks_shell.push_back(v);
01097 v->getDef().add();
01098
01099 v= mgr.own(new mf::Variable(stackname.str() + "_INPUT", inputs.begin(), inputs.end(), Makefile::MAKE, "\\\n"));
01100 stacks_input.push_back(v);
01101 v->getDef().add();
01102
01103 v = mgr.own(new mf::Variable(stackname.str() + "_INPUT_SHELL", inputs.begin(), inputs.end(), Makefile::SHELL, "\\\n"));
01104 stacks_input_shell.push_back(v);
01105 v->getDef().add();
01106
01107 v= mgr.own(new mf::Variable(stackname.str() + "_INPUT_PTMENDER", inputspt.begin(), inputspt.end(), Makefile::MAKE, "\\\n"));
01108 stacks_input_pt.push_back(v);
01109 v->getDef().add();
01110
01111 v = mgr.own(new mf::Variable(stackname.str() + "_INPUT_PTMENDER_SHELL", inputspt.begin(), inputspt.end(), Makefile::SHELL, "\\\n"));
01112 stacks_input_pt_shell.push_back(v);
01113 v->getDef().add();
01114
01115 v = mgr.own(new mf::Variable(stackname.str() + "_EXPOSURE", exposure / stackdata[i].size()));
01116 v->getDef().add();
01117 }
01118 newVarDef(vhdrstacksnr, stkname + "S_NUMBERS", stknrs.str(), Makefile::NONE);
01119
01120 std::string stackrefs;
01121 std::string stackrefsshell;
01122 std::vector<mf::Variable*>::const_iterator it, it2;
01123 it = stacks.begin();
01124 it2 = stacks_shell.begin();
01125 for(; it != stacks.end() && it2 != stacks_shell.end(); it++, it2++)
01126 {
01127 stackrefs += (*it)->getRef() + " ";
01128 stackrefsshell += (*it2)->getRef() + " ";
01129 }
01130 vstacks = mgr.own(new mf::Variable(stkname + "S", stackrefs, Makefile::NONE));
01131 vstacks->getDef().add();
01132 vstacksshell = mgr.own(new mf::Variable(stkname + "S_SHELL", stackrefsshell, Makefile::NONE));
01133 vstacksshell->getDef().add();
01134 vstacksrem = mgr.own( new mf::Variable(stkname + "S_REMAPPED", allimgs.begin(), allimgs.end(), Makefile::MAKE, "\\\n"));
01135 vstacksrem->getDef().add();
01136 vstacksremshell = mgr.own( new mf::Variable(stkname + "S_REMAPPED_SHELL", allimgs.begin(), allimgs.end(), Makefile::SHELL, "\\\n"));
01137 vstacksremshell->getDef().add();
01138 }
01139
01140 void PanoramaMakefilelibExport::createcheckProgCmd(Rule& testrule, const std::string& progName, const std::string& progCommand)
01141 {
01142 std::string command;
01143 #ifdef _WINDOWS
01144 testrule.addCommand("echo Checking " + progName + "...", false);
01145 testrule.addCommand(progCommand + " > NUL 2>&1 && echo " + progName + " is ok || echo " +
01146 progName + " failed", false, true);
01147 #else
01148 testrule.addCommand("echo -n 'Checking " + progName + "...'", false);
01149 testrule.addCommand(progCommand + " > /dev/null 2>&1 && echo '[OK]' || echo '[FAILED]'", false, true);
01150 #endif
01151 }
01152
01153 void PanoramaMakefilelibExport::echoInfo(Rule& inforule, const std::string& info)
01154 {
01155 #ifdef _WINDOWS
01156 inforule.addCommand("echo " + hugin_utils::QuoteStringInternal<std::string>(info,"^","^&|<>"), false);
01157 #else
01158
01159
01160
01161 inforule.addCommand("echo '" + hugin_utils::QuoteStringInternal<std::string>(
01162 hugin_utils::replaceAll<std::string>(info,"'","'\\''"),"$","$") + "'", false);
01163 #endif
01164 }
01165
01166 void PanoramaMakefilelibExport::printSystemInfo(Rule& inforule)
01167 {
01168 std::ostringstream infostream("");
01169 infostream.imbue(makefile::GetMakefileLocale());
01170 #ifdef _WINDOWS
01171 OSVERSIONINFOEX osvi;
01172 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
01173 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
01174 if(!GetVersionEx((OSVERSIONINFO *) &osvi))
01175 return;
01176 SYSTEM_INFO siSysInfo;
01177 GetSystemInfo(&siSysInfo);
01178 MEMORYSTATUSEX statex;
01179 statex.dwLength = sizeof(statex);
01180 GlobalMemoryStatusEx(&statex);
01181
01182 infostream << "Windows ";
01183
01184 if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion > 4)
01185 {
01186 if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
01187 infostream << "2000 ";
01188 if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==1)
01189 infostream << "XP ";
01190 if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2 && osvi.wProductType==VER_NT_WORKSTATION && siSysInfo.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
01191 infostream << "XP Professional x64 Edition ";
01192 if(osvi.dwMajorVersion==6)
01193 {
01194 if(osvi.dwMinorVersion==0)
01195 {
01196 if(osvi.wProductType==VER_NT_WORKSTATION)
01197 infostream << "Vista ";
01198 else
01199 infostream << "Server 2008 ";
01200 }
01201 if(osvi.dwMinorVersion==1)
01202 {
01203 if(osvi.wProductType==VER_NT_WORKSTATION)
01204 infostream << "7 ";
01205 else
01206 infostream << "Server 2008 R2 ";
01207 }
01208 };
01209 }
01210
01211 infostream << "(" << osvi.dwMajorVersion << "." << osvi.dwMinorVersion << " " << osvi.szCSDVersion << ")";
01212 echoInfo(inforule,"Operating System: "+infostream.str());
01213 switch(siSysInfo.wProcessorArchitecture)
01214 {
01215 case PROCESSOR_ARCHITECTURE_INTEL:
01216 infostream.str("x86");
01217 break;
01218 case PROCESSOR_ARCHITECTURE_AMD64:
01219 infostream.str("AMD64");
01220 break;
01221 default:
01222 infostream.str("unknown");
01223 break;
01224 };
01225 echoInfo(inforule,"Architecture: "+infostream.str());
01226 infostream.str("");
01227 infostream << siSysInfo.dwNumberOfProcessors;
01228 echoInfo(inforule,"Number of logical processors: "+infostream.str());
01229 infostream.str("");
01230 infostream << statex.ullTotalPhys/1024 << " kiB (" << setprecision(2) << statex.dwMemoryLoad << "%% occupied)";
01231 echoInfo(inforule,"Physical memory: "+infostream.str());
01232 unsigned __int64 freeBytes;
01233 if(GetDiskFreeSpaceEx(NULL,(PULARGE_INTEGER)&freeBytes,NULL,NULL))
01234 {
01235 infostream.str("");
01236 infostream << freeBytes/(1024*1024) << " MiB";
01237 echoInfo(inforule,"Free space on disc: " + infostream.str());
01238 };
01239 infostream.str("");
01240 UINT cp=GetACP();
01241 infostream << cp;
01242 switch(cp)
01243 {
01244 case 1250:
01245 infostream << " (Central European Windows)";
01246 break;
01247 case 1251:
01248 infostream << " (Cyrillic Windows)";
01249 break;
01250 case 1252:
01251 infostream << " (Western European Windows)";
01252 break;
01253 case 1253:
01254 infostream << " (Greek Windows)";
01255 break;
01256 case 1254:
01257 infostream << " (Turkish Windows)";
01258 break;
01259 case 1255:
01260 infostream << " (Hebrew Windows)";
01261 break;
01262 case 1256:
01263 infostream << " (Arabic Windows)";
01264 break;
01265 case 1257:
01266 infostream << " (Baltic Windows)";
01267 break;
01268 case 1258:
01269 infostream << " (Vietnamese Windows)";
01270 break;
01271 };
01272 echoInfo(inforule,"Active codepage: " + infostream.str());
01273 #else
01274 #ifdef __APPLE__
01275 inforule.addCommand("system_profiler SPSoftwareDataType SPHardwareDataType", false, true);
01276 echoInfo(inforule,"Disc usage");
01277 inforule.addCommand("df -h", false, true);
01278 #else
01279 inforule.addCommand("echo -n 'Operating system: '", false);
01280 inforule.addCommand("uname -o", false, true);
01281 inforule.addCommand("echo -n 'Release: '", false);
01282 inforule.addCommand("uname -r", false, true);
01283 inforule.addCommand("echo -n 'Kernel version: '", false);
01284 inforule.addCommand("uname -v", false, true);
01285 inforule.addCommand("echo -n 'Machine: '", false);
01286 inforule.addCommand("uname -m", false, true);
01287 echoInfo(inforule,"Disc usage");
01288 inforule.addCommand("df -h", false, true);
01289 echoInfo(inforule,"Memory usage");
01290 inforule.addCommand("free -m", false, true);
01291 #endif
01292 #endif
01293 };
01294
01295 void printstacks(const std::vector<UIntSet>& stackdata)
01296 {
01297 std::cout << "printstacks: \n";
01298 for(std::vector<UIntSet>::const_iterator itv = stackdata.begin(); itv != stackdata.end(); itv++)
01299 {
01300 for(UIntSet::const_iterator itu = itv->begin(); itu != itv->end(); itu++)
01301 {
01302 std::cout << *itu << " ";
01303 }
01304 std::cout << "\n";
01305 }
01306 }
01307
01308 template<typename T>
01309 void append(std::vector<T>& dst, const std::vector<T>& src)
01310 {
01311 dst.insert(dst.end(), src.begin(), src.end());
01312 }
01313 template<typename T>
01314 void append(std::vector<T>& vec, const T& element)
01315 {
01316 vec.push_back(element);
01317 }
01318 }