[f9fc67]: src / hugin_base / algorithms / panorama_makefile / PanoramaMakefileExport.cpp  Maximize  Restore  History

Download this file

983 lines (880 with data), 41.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
// -*- c-basic-offset: 4 -*-
/** @file PanoramaMakefileExport.h
*
* @author Pablo d'Angelo <pablo.dangelo@web.de>
*
* $Id: utils.h 1814 2006-12-31 14:37:05Z dangelo $
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "PanoramaMakefileExport.h"
#include <fstream>
#include <iomanip>
#include <panodata/PanoramaData.h>
#include <hugin_utils/utils.h>
#include <algorithms/nona/ComputeImageROI.h>
#include <algorithms/basic/CalculateOverlap.h>
#if defined MAC_SELF_CONTAINED_BUNDLE
#define COULD_EXECUTE_EXIFTOOL_WITH_PERL
#endif
namespace HuginBase {
using namespace std;
using namespace hugin_utils;
using namespace vigra;
// should be moved somewhere else (will be after GSOC anyway)
vector<UIntSet> getHDRStacks(const PanoramaData & pano, UIntSet allImgs)
{
vector<UIntSet> result;
// if no images are available, return empty result vector
if ( allImgs.empty() )
{
return result;
}
UIntSet stack;
HuginBase::CalculateImageOverlap overlap(&pano);
overlap.calculate(50); // we are testing 50*50=2500 points
do {
unsigned srcImg = *(allImgs.begin());
stack.insert(srcImg);
allImgs.erase(srcImg);
// find all images that have a suitable overlap.
for (UIntSet::iterator it = allImgs.begin(); it != allImgs.end(); ) {
unsigned srcImg2 = *it;
it++;
if(overlap.getOverlap(srcImg,srcImg2)>0.7)
{
stack.insert(srcImg2);
allImgs.erase(srcImg2);
}
}
result.push_back(stack);
stack.clear();
} while (allImgs.size() > 0);
return result;
}
// should be moved somewhere else (will be after GSOC anyway)
vector<UIntSet> getExposureLayers(const PanoramaData & pano, UIntSet allImgs)
{
vector<UIntSet> result;
// if no images are available, return empty result vector
if ( allImgs.empty() )
{
return result;
}
UIntSet stack;
do {
unsigned srcImg = *(allImgs.begin());
stack.insert(srcImg);
allImgs.erase(srcImg);
// find all images that have a suitable overlap.
const SrcPanoImage & simg = pano.getImage(srcImg);
// FIXME this should be a user preference
double maxEVDiff = 0.5;
for (UIntSet::iterator it = allImgs.begin(); it != allImgs.end(); ) {
unsigned srcImg2 = *it;
it++;
const SrcPanoImage & simg2 = pano.getImage(srcImg2);
if ( fabs(simg.getExposureValue() - simg2.getExposureValue()) < maxEVDiff )
{
stack.insert(srcImg2);
allImgs.erase(srcImg2);
}
}
result.push_back(stack);
stack.clear();
} while (allImgs.size() > 0);
return result;
}
// should be moved somewhere else (will be after GSOC anyway)
UIntSet getImagesinROI (const PanoramaData& pano, const UIntSet activeImages)
{
UIntSet images;
PanoramaOptions opts = pano.getOptions();
for (UIntSet::const_iterator it = activeImages.begin(); it != activeImages.end(); ++it)
{
Rect2D roi = estimateOutputROI(pano, opts, *it);
if (! (roi.isEmpty())) {
images.insert(*it);
}
}
return images;
}
/* write make file line for checking, if progCommand can be runned
prints progName on command line */
void checkProg(std::ostream& o,const std::string& progName, const std::string& progCommand)
{
#ifdef _WINDOWS
o << "\t@echo Checking " << progName << "..." << endl
<< "\t" << progCommand << " > NUL 2>&1 && echo " << progName << " is ok || echo "
<< progName << " failed" << endl;
#else
o << "\t@echo -n 'Checking " << progName << "...'" << endl
<< "\t" << progCommand << " > /dev/null 2>&1 && echo '[OK]' || echo '[FAILED]'" << endl;
#endif
};
void PanoramaMakefileExport::createMakefile(const PanoramaData& pano,
const UIntSet& rimages,
const std::string& ptofile,
const std::string& outputPrefix,
const PTPrograms& progs,
const std::string& includePath,
std::vector<std::string> & outputFiles,
std::ostream& o,
const std::string& tmpDir)
{
PanoramaOptions opts = pano.getOptions();
#ifdef UNIX_LIKE
// set numeric locale to C, for correct number output
char * t = setlocale(LC_NUMERIC,NULL);
char * old_locale = (char*) malloc(strlen(t)+1);
strcpy(old_locale, t);
setlocale(LC_NUMERIC,"C");
#endif
// output only images in current ROI
UIntSet images = getImagesinROI(pano,rimages);
// execute exiftool with perl if necessary
#ifdef COULD_EXECUTE_EXIFTOOL_WITH_PERL
bool executeWithPerl = false;
std::string perlCommand = "";
#if defined MAC_SELF_CONTAINED_BUNDLE
// if exiftool is inside the bundle (not the best def, but works)
if(progs.exiftool.find(".app") != std::string::npos)
{
executeWithPerl = true;
perlCommand += "perl -w";
}
#endif
#endif
o << "# makefile for panorama stitching, created by hugin " << endl
<< endl;
// pass settings for different temporary directory
if (tmpDir != "") {
o << "# set temporary directory" << endl;
#ifdef UNIX_LIKE
o << "export TMPDIR=" << quoteStringShell(tmpDir) << endl;
#else // WINDOWS
o << "export TEMP=" << quoteStringShell(tmpDir) << endl
<< "export TMP=" << quoteStringShell(tmpDir) << endl;
#endif
}
#ifdef _WINDOWS
o << "# Force using cmd.exe" << endl
<< "SHELL=" << getenv("ComSpec") << endl <<endl;
#endif
o << endl
<< endl
<< "# Tool configuration" << endl
<< "NONA=" << quoteStringShell(progs.nona) << endl
<< "PTSTITCHER=" << quoteStringShell(progs.PTStitcher) << endl
<< "PTMENDER=" << quoteStringShell(progs.PTmender) << endl
<< "PTBLENDER=" << quoteStringShell(progs.PTblender) << endl
<< "PTMASKER=" << quoteStringShell(progs.PTmasker) << endl
<< "PTROLLER=" << quoteStringShell(progs.PTroller) << endl
<< "ENBLEND=" << quoteStringShell(progs.enblend) << endl
<< "ENFUSE=" << quoteStringShell(progs.enfuse) << endl
<< "SMARTBLEND=" << quoteStringShell(progs.smartblend) << endl
<< "HDRMERGE=" << quoteStringShell(progs.hdrmerge) << endl
#ifdef _WINDOWS
<< "RM=del" << endl
#else
<< "RM=rm" << endl
#endif
#ifdef COULD_EXECUTE_EXIFTOOL_WITH_PERL
<< "EXIFTOOL=" << (executeWithPerl? perlCommand+" " : "") << quoteStringShell(progs.exiftool) << endl
#else
<< "EXIFTOOL=" << quoteStringShell(progs.exiftool) << endl
#endif
<< endl
<< "# Project parameters" << endl
<< "HUGIN_PROJECTION=" << opts.getProjection() << endl
<< "HUGIN_HFOV=" << opts.getHFOV() << endl
<< "HUGIN_WIDTH=" << opts.getWidth() << endl
<< "HUGIN_HEIGHT=" << opts.getHeight() << endl
<< endl
<< "# options for the programs" << endl << endl;
// set remapper specific settings
switch(opts.remapper) {
case PanoramaOptions::NONA:
{
o << "NONA_LDR_REMAPPED_COMP=";
if (opts.outputImageType == "tif" && opts.outputLayersCompression.size() != 0) {
o << "-z " << opts.outputLayersCompression;
} else if (opts.outputImageType == "jpg") {
o << "-z PACKBITS ";
}
o << endl;
o << "NONA_OPTS=";
if (opts.remapUsingGPU)
{
o << "-g ";
}
o << endl;
}
break;
case PanoramaOptions::PTMENDER:
break;
}
// set blender specific settings
switch(opts.blendMode) {
case PanoramaOptions::ENBLEND_BLEND:
{
o << "ENBLEND_OPTS=" << opts.enblendOptions;
if (opts.getHFOV() == 360.0) {
// blend over the border
o << " -w";
}
vigra::Rect2D roi = opts.getROI();
if (roi.top() != 0 || roi.left() != 0 ) {
o << " -f" << roi.width() << "x" << roi.height() << "+" << roi.left() << "+" << roi.top();
} else {
o << " -f" << roi.width() << "x" << roi.height();
}
o << endl;
o << "ENBLEND_LDR_COMP=";
if (opts.outputImageType == "tif" && opts.outputImageTypeCompression.size() != 0) {
o << "--compression " << opts.outputImageTypeCompression;
} else if (opts.outputImageType == "jpg") {
o << "--compression " << opts.quality;
}
o << endl;
o << "ENBLEND_HDR_COMP=";
if (opts.outputImageTypeHDR == "tif" && opts.outputImageTypeHDRCompression.size() != 0) {
o << "--compression " << opts.outputImageTypeHDRCompression;
}
o << endl;
}
break;
case PanoramaOptions::PTBLENDER_BLEND:
{
o << "PTBLENDER_OPTS=";
switch (opts.colorCorrection) {
case PanoramaOptions::NONE:
break;
case PanoramaOptions::BRIGHTNESS_COLOR:
o << " -k " << opts.colorReferenceImage;
break;
case PanoramaOptions::BRIGHTNESS:
o << " -k " << opts.colorReferenceImage;
break;
case PanoramaOptions::COLOR:
o << " -k " << opts.colorReferenceImage;
break;
}
o << endl;
}
break;
case PanoramaOptions::SMARTBLEND_BLEND:
{
o << "SMARTBLEND_OPTS=" << progs.smartblend_opts;
if (opts.getHFOV() == 360.0) {
// blend over the border
o << " -w";
}
o << endl;
// TODO: build smartblend command line from given images. (requires additional program)
}
break;
}
switch (opts.hdrMergeMode)
{
case PanoramaOptions::HDRMERGE_AVERAGE:
o << "HDRMERGE_OPTS=" << opts.hdrmergeOptions << endl;
break;
case PanoramaOptions::HDRMERGE_DEGHOST:
break;
}
o << "ENFUSE_OPTS=" << opts.enfuseOptions;
// TODO: blend only over border if this is indeed a
// image with 360 deg overlap
if (opts.getHFOV() == 360.0) {
// blend over the border
o << " -w";
}
o << endl;
o << "EXIFTOOL_COPY_ARGS=" << progs.exiftool_opts << endl;
o << endl;
string hdrExt = string(".") + opts.outputImageTypeHDR;
string ldrExt = string(".") + opts.outputImageType;
string ldrRemappedExt(".tif");
string ldrRemappedMode("TIFF_m");
string hdrRemappedExt = ".exr";
string hdrRemappedMode = "EXR_m";
// set a suitable target file.
std::string output = outputPrefix;
// bool externalBlender = false;
// bool remapToMultiple = false;
/*
if (opts.blendMode == PT::PanoramaOptions::NO_BLEND) {
// just remapping or simple blending
if (opts.outputFormat == PT::PanoramaOptions::TIFF_m) {
remapToMultiple = true;
}
} else {
externalBlender = true;
remapToMultiple = true;
}
*/
std::string sLDR_BLENDED = output + ldrExt;
std::string sLDR_STACKED_BLENDED = output + "_fused" + ldrExt;
std::string sLDR_EXPOSURE_LAYERS_FUSED = output + "_blended_fused" + ldrExt;
std::string sHDR_BLENDED = output + "_hdr" + hdrExt;
o << "# the output panorama" << endl
<< "LDR_REMAPPED_PREFIX=" << escapeStringMake(output) << endl
<< "LDR_REMAPPED_PREFIX_SHELL=" << quoteStringShell(output) << endl
<< "HDR_STACK_REMAPPED_PREFIX=" << escapeStringMake(output + "_hdr_") << endl
<< "HDR_STACK_REMAPPED_PREFIX_SHELL=" << quoteStringShell(output + "_hdr_") << endl
<< "LDR_EXPOSURE_REMAPPED_PREFIX=" << escapeStringMake(output + "_exposure_layers_") << endl
<< "LDR_EXPOSURE_REMAPPED_PREFIX_SHELL=" << quoteStringShell(output + "_exposure_layers_") << endl
<< "PROJECT_FILE=" << escapeStringMake(ptofile) << endl
<< "PROJECT_FILE_SHELL=" << quoteStringShell(ptofile) << endl
<< "LDR_BLENDED=" << escapeStringMake(sLDR_BLENDED) << endl
<< "LDR_BLENDED_SHELL=" << quoteStringShell(sLDR_BLENDED) << endl
<< "LDR_STACKED_BLENDED=" << escapeStringMake(sLDR_STACKED_BLENDED) << endl
<< "LDR_STACKED_BLENDED_SHELL=" << quoteStringShell(sLDR_STACKED_BLENDED) << endl
<< "LDR_EXPOSURE_LAYERS_FUSED=" << escapeStringMake(sLDR_EXPOSURE_LAYERS_FUSED) << endl
<< "LDR_EXPOSURE_LAYERS_FUSED_SHELL=" << quoteStringShell(sLDR_EXPOSURE_LAYERS_FUSED) << endl
<< "HDR_BLENDED=" << escapeStringMake(sHDR_BLENDED) << endl
<< "HDR_BLENDED_SHELL=" << quoteStringShell(sHDR_BLENDED) << endl
<< endl
<< "# first input image" << endl
<< "INPUT_IMAGE_1=" << escapeStringMake(pano.getImage(0).getFilename()) << endl
<< "INPUT_IMAGE_1_SHELL=" << quoteStringShell(pano.getImage(0).getFilename()) << endl
<< "# all input images" << endl
<< "INPUT_IMAGES=";
for (unsigned int i=0; i < pano.getNrOfImages(); i++) {
o << escapeStringMake(pano.getImage(i).getFilename());
if (i+1 != pano.getNrOfImages()) o << "\\" << endl;
}
o << endl << endl;
o << "INPUT_IMAGES_SHELL=";
for (unsigned int i=0; i < pano.getNrOfImages(); i++) {
o << quoteStringShell(pano.getImage(i).getFilename());
if (i+1 != pano.getNrOfImages()) o << "\\" << endl;
}
vector<string> remappedImages;
o << endl
<< endl
<< "# remapped images" << endl
<< "LDR_LAYERS=";
for (UIntSet::iterator it = images.begin(); it != images.end();) {
std::ostringstream fns;
fns << output << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
remappedImages.push_back(fns.str());
o << escapeStringMake(fns.str());
++it;
if (it != images.end()) o << "\\" << endl;
}
o << endl << endl
<< "LDR_LAYERS_SHELL=";
for(int i=0; i < (int) remappedImages.size(); i++) {
o << quoteStringShell(remappedImages[i]);
if (i != remappedImages.size() -1) {
o << "\\" << endl;
}
}
vector<string> remappedHDRImages;
o << endl
<< endl
<< "# remapped images (hdr)" << endl
<< "HDR_LAYERS=";
for (UIntSet::iterator it = images.begin(); it != images.end();) {
std::ostringstream fns;
fns << output << "_hdr_" << std::setfill('0') << std::setw(4) << *it << hdrRemappedExt;
remappedHDRImages.push_back(fns.str());
o << escapeStringMake(fns.str());
++it;
if (it != images.end()) o << "\\" << endl;
}
o << endl << endl
<< "HDR_LAYERS_SHELL=";
for(int i=0; i < (int) remappedHDRImages.size(); i++) {
o << quoteStringShell(remappedHDRImages[i]);
if (i != remappedHDRImages.size() - 1) {
o << "\\" << endl;
}
}
vector<string> remappedHDRImagesGray;
o << endl
<< endl
<< "# remapped maxval images" << endl
<< "HDR_LAYERS_WEIGHTS=";
for (UIntSet::iterator it = images.begin(); it != images.end();) {
std::ostringstream fns;
fns << output << "_hdr_" << std::setfill('0') << std::setw(4) << *it << "_gray.pgm";
remappedHDRImagesGray.push_back(fns.str());
o << escapeStringMake(fns.str()) << " ";
++it;
if (it != images.end()) o << "\\" << endl;
}
o << endl << endl
<< "HDR_LAYERS_WEIGHTS_SHELL=";
for(unsigned i=0; i < remappedHDRImagesGray.size(); i++) {
o << quoteStringShell(remappedHDRImagesGray[i]);
if (i != remappedHDRImagesGray.size() - 1) {
o << "\\" << endl;
}
}
o << endl;
vector<string> stackedImages;
vector<UIntSet> stacks = getHDRStacks(pano, images);
DEBUG_DEBUG( stacks.size() << " stacks found");
o << endl
<< "# stacked images" << endl
<< "HDR_STACKS_NUMBERS = ";
for (unsigned i=0; i < stacks.size(); i++)
o << i << " ";
o << endl;
for (unsigned i=0; i < stacks.size(); i++) {
std::ostringstream fns;
fns << output << "_stack_hdr_" << std::setfill('0') << std::setw(4) << i << hdrRemappedExt;
stackedImages.push_back(fns.str());
std::ostringstream stackedImgVar;
stackedImgVar << "HDR_STACK_" << i;
o << stackedImgVar.str() << " = " << escapeStringMake(fns.str()) << endl;
o << stackedImgVar.str() << "_SHELL = " << quoteStringShell(fns.str()) << endl;
o << stackedImgVar.str() << "_INPUT = ";
for (UIntSet::iterator it = stacks[i].begin(); it != stacks[i].end();) {
std::ostringstream fns;
fns << output << "_hdr_" << std::setfill('0') << std::setw(4) << *it << hdrRemappedExt;
o << escapeStringMake(fns.str());
++it;
if (it != stacks[i].end()) o << "\\" << endl;
}
o << endl << endl;
o << stackedImgVar.str() << "_INPUT_SHELL = ";
for (UIntSet::iterator it = stacks[i].begin(); it != stacks[i].end();) {
std::ostringstream fns;
fns << output << "_hdr_" << std::setfill('0') << std::setw(4) << *it << hdrRemappedExt;
o << quoteStringShell(fns.str());
++it;
if (it != stacks[i].end()) o << "\\" << endl;
}
o << endl << endl;
}
o << endl;
o << "HDR_STACKS = ";
for (unsigned i=0; i < stacks.size(); i++)
o << "$(HDR_STACK_" << i << ") ";
o << endl;
o << "HDR_STACKS_SHELL = ";
for (unsigned i=0; i < stacks.size(); i++)
o << "$(HDR_STACK_" << i << "_SHELL) ";
o << endl;
// add support for exposure blending stuff...
vector<string> similarExposureRemappedImages;
vector<string> similarExposureImages;
vector<UIntSet> similarExposures = getExposureLayers(pano, images);
DEBUG_DEBUG( similarExposures.size() << " similar exposures found");
o << endl
<< endl
<< "# number of image sets with similar exposure" << endl
<< "LDR_EXPOSURE_EXPOSURE_LAYERS_NUMBERS = ";
for (unsigned i=0; i < similarExposures.size(); i++)
o << i << " ";
o << endl;
for (unsigned i=0; i < similarExposures.size(); i++) {
std::ostringstream fns;
fns << output << "_exposure_" << std::setfill('0') << std::setw(2) << i << ldrExt;
similarExposureImages.push_back(fns.str());
string destImg = fns.str();
std::ostringstream expImgVar;
expImgVar << "LDR_EXPOSURE_LAYER_" << i;
o << expImgVar.str() << " = " << escapeStringMake(destImg) << endl;
o << expImgVar.str() << "_SHELL = " << quoteStringShell(destImg) << endl;
o << expImgVar.str() << "_INPUT = ";
double exposure=0;
for (UIntSet::iterator it = similarExposures[i].begin(); it != similarExposures[i].end();) {
exposure += pano.getImage(*it).getExposureValue();
std::ostringstream fns;
fns << output << "_exposure_layers_" << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
similarExposureRemappedImages.push_back(fns.str());
o << escapeStringMake(fns.str());
++it;
if (it != similarExposures[i].end()) o << "\\" << endl;
}
o << endl << endl;
o << expImgVar.str() << "_INPUT_SHELL = ";
for (UIntSet::iterator it = similarExposures[i].begin(); it != similarExposures[i].end();) {
std::ostringstream fns;
fns << output << "_exposure_layers_" << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
o << quoteStringShell(fns.str());
++it;
if (it != similarExposures[i].end()) o << "\\" << endl;
}
o << endl << endl;
o << expImgVar.str() << "_INPUT_PTMENDER = ";
for (UIntSet::iterator it = similarExposures[i].begin(); it != similarExposures[i].end();) {
std::ostringstream fns;
fns << output << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
o << escapeStringMake(fns.str());
++it;
if (it != similarExposures[i].end()) o << "\\" << endl;
}
o << endl << endl << expImgVar.str() << "_INPUT_PTMENDER_SHELL = ";
for (UIntSet::iterator it = similarExposures[i].begin(); it != similarExposures[i].end();) {
std::ostringstream fns;
fns << output << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
o << quoteStringShell(fns.str());
++it;
if (it != similarExposures[i].end()) o << "\\" << endl;
}
// calculate output exposure value for this set.
o << endl
<< "LDR_EXPOSURE_LAYER_" << i << "_EXPOSURE = "
<< exposure / similarExposures[i].size() << endl;
}
o << endl;
o << "LDR_EXPOSURE_LAYERS = ";
for (unsigned i=0; i < similarExposures.size(); i++)
o << "$(LDR_EXPOSURE_LAYER_" << i << ") ";
o << endl;
o << "LDR_EXPOSURE_LAYERS_SHELL = ";
for (unsigned i=0; i < similarExposures.size(); i++)
o << "$(LDR_EXPOSURE_LAYER_" << i << "_SHELL) ";
o << endl;
o << "LDR_EXPOSURE_LAYERS_REMAPPED = ";
for (unsigned i=0; i < similarExposureRemappedImages.size(); i++)
{
o << escapeStringMake(similarExposureRemappedImages[i]);
if (i+1 != similarExposureRemappedImages.size()) o << "\\" << endl;
}
o << endl << endl;
o << "LDR_EXPOSURE_LAYERS_REMAPPED_SHELL = ";
for (unsigned i=0; i < similarExposureRemappedImages.size(); i++)
{
o << quoteStringShell(similarExposureRemappedImages[i]);
if (i+1 != similarExposureRemappedImages.size()) o << "\\" << endl;
}
o << endl << endl;
vector<string> ldrStackedImages;
o << endl
<< "# stacked images for enfuse or other automatic exposure blending tools" << endl
<< "LDR_STACKS_NUMBERS = ";
for (unsigned i=0; i < stacks.size(); i++)
o << i << " ";
o << endl;
for (unsigned i=0; i < stacks.size(); i++) {
std::ostringstream fns;
fns << output << "_stack_ldr_" << std::setfill('0') << std::setw(4) << i << ldrRemappedExt;
ldrStackedImages.push_back(fns.str());
std::ostringstream stackedImgVar;
stackedImgVar << "LDR_STACK_" << i;
o << stackedImgVar.str() << " = " << escapeStringMake(fns.str()) << endl;
o << stackedImgVar.str() << "_SHELL = " << quoteStringShell(fns.str()) << endl;
o << stackedImgVar.str() << "_INPUT = ";
for (UIntSet::iterator it = stacks[i].begin(); it != stacks[i].end();) {
std::ostringstream fns;
fns << output << "_exposure_layers_" << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
o << escapeStringMake(fns.str());
++it;
if (it != stacks[i].end()) o << "\\" << endl;
}
o << endl << endl;
o << stackedImgVar.str() << "_INPUT_SHELL = ";
for (UIntSet::iterator it = stacks[i].begin(); it != stacks[i].end();) {
std::ostringstream fns;
fns << output << "_exposure_layers_" << std::setfill('0') << std::setw(4) << *it << ldrRemappedExt;
o << quoteStringShell(fns.str());
++it;
if (it != stacks[i].end()) o << "\\" << endl;
}
o << endl << endl;
}
o << endl;
o << "LDR_STACKS = ";
for (unsigned i=0; i < stacks.size(); i++)
o << "$(LDR_STACK_" << i << ") ";
o << endl;
o << "LDR_STACKS_SHELL = ";
for (unsigned i=0; i < stacks.size(); i++)
o << "$(LDR_STACK_" << i << "_SHELL) ";
o << endl;
// TODO: include custom makefile here
if (includePath.size() > 0) {
o << "include " << escapeStringMake(includePath) << endl << endl;
} else {
// create rules for all possible targets.
std::string targets;
std::string cleanTargets;
// output all targets
if (opts.outputLDRBlended) {
targets += "$(LDR_BLENDED) ";
outputFiles.push_back(sLDR_BLENDED);
o << "DO_LDR_BLENDED = 1" << endl;
// depends on remapped ldr images and stacked ldr images
if (! opts.outputLDRLayers) {
outputFiles.insert(outputFiles.end(), remappedImages.begin(), remappedImages.end());
cleanTargets += "$(LDR_LAYERS_SHELL) ";
}
}
if (opts.outputLDRLayers) {
targets += "$(LDR_LAYERS) ";
outputFiles.insert(outputFiles.end(), remappedImages.begin(), remappedImages.end());
}
if (opts.outputLDRExposureRemapped) {
targets += "$(LDR_EXPOSURE_LAYERS_REMAPPED) ";
outputFiles.insert(outputFiles.end(), similarExposureRemappedImages.begin(), similarExposureRemappedImages.end());
}
if (opts.outputLDRExposureLayers) {
targets += " $(LDR_EXPOSURE_LAYERS) ";
outputFiles.insert(outputFiles.end(), similarExposureImages.begin(), similarExposureImages.end());
if (! opts.outputLDRExposureRemapped) {
outputFiles.insert(outputFiles.end(), similarExposureRemappedImages.begin(), similarExposureRemappedImages.end());
cleanTargets += "$(LDR_EXPOSURE_LAYERS_REMAPPED_SHELL) ";
}
}
if (opts.outputLDRExposureBlended) {
targets += " $(LDR_STACKED_BLENDED) ";
outputFiles.push_back(sLDR_STACKED_BLENDED);
o << "DO_LDR_STACKED_BLENDED = 1" << endl;
outputFiles.insert(outputFiles.end(),ldrStackedImages.begin(), ldrStackedImages.end());
// always clean temp files used by exposure stacks
cleanTargets += "$(LDR_STACKS_SHELL) ";
if (! opts.outputLDRExposureRemapped && ! opts.outputLDRExposureLayers) {
outputFiles.insert(outputFiles.end(), similarExposureRemappedImages.begin(), similarExposureRemappedImages.end());
cleanTargets += "$(LDR_EXPOSURE_LAYERS_REMAPPED_SHELL) ";
}
}
if (opts.outputLDRExposureLayersFused) {
targets += " $(LDR_EXPOSURE_LAYERS_FUSED) ";
outputFiles.push_back(sLDR_EXPOSURE_LAYERS_FUSED);
o << "DO_LDR_EXPOSURE_LAYERS_FUSED = 1" << endl;
outputFiles.insert(outputFiles.end(),similarExposureImages.begin(), similarExposureImages.end());
if (! opts.outputLDRExposureRemapped && ! opts.outputLDRExposureLayers) {
outputFiles.insert(outputFiles.end(), similarExposureRemappedImages.begin(), similarExposureRemappedImages.end());
cleanTargets += "$(LDR_EXPOSURE_LAYERS_REMAPPED_SHELL) ";
cleanTargets += "$(LDR_EXPOSURE_LAYERS_SHELL) ";
}
}
if (opts.outputHDRLayers) {
targets += "$(HDR_LAYERS) ";
outputFiles.insert(outputFiles.end(),remappedHDRImages.begin(), remappedHDRImages.end());
outputFiles.insert(outputFiles.end(),remappedHDRImagesGray.begin(), remappedHDRImagesGray.end());
}
if (opts.outputHDRStacks) {
targets += "$(HDR_STACKS) ";
outputFiles.insert(outputFiles.end(),stackedImages.begin(), stackedImages.end());
if (!opts.outputHDRLayers) {
outputFiles.insert(outputFiles.end(),remappedHDRImages.begin(), remappedHDRImages.end());
outputFiles.insert(outputFiles.end(),remappedHDRImagesGray.begin(), remappedHDRImagesGray.end());
cleanTargets += "$(HDR_LAYERS_SHELL) $(HDR_LAYERS_WEIGHTS_SHELL) ";
}
}
if (opts.outputHDRBlended) {
targets += "$(HDR_BLENDED) ";
outputFiles.push_back(sHDR_BLENDED);
o << "DO_HDR_BLENDED = 1" << endl;
if (!opts.outputHDRStacks) {
outputFiles.insert(outputFiles.end(),stackedImages.begin(), stackedImages.end());
cleanTargets += "$(HDR_STACKS_SHELL) ";
if (! opts.outputHDRLayers) {
outputFiles.insert(outputFiles.end(),remappedHDRImages.begin(), remappedHDRImages.end());
outputFiles.insert(outputFiles.end(),remappedHDRImagesGray.begin(), remappedHDRImagesGray.end());
cleanTargets += "$(HDR_LAYERS_SHELL) $(HDR_LAYERS_WEIGHTS_SHELL) ";
}
}
}
// targets and clean rule.
o << "TEMP_FILES_SHELL = " << cleanTargets << endl
<< endl
<< "all: " << targets << endl << endl
<< "clean: " << endl
<< "\t-$(RM) $(TEMP_FILES_SHELL)" << endl
<< endl;
// test rule
o << "test: " << endl;
// test remapper
switch(opts.remapper) {
case PanoramaOptions::NONA:
checkProg(o,"nona","@-$(NONA) --help");
break;
case PanoramaOptions::PTMENDER:
break;
}
// test blender
switch(opts.blendMode) {
case PanoramaOptions::ENBLEND_BLEND:
checkProg(o,"enblend","@-$(ENBLEND) -h");
break;
case PanoramaOptions::PTBLENDER_BLEND:
checkProg(o,"PTblender","@-$(PTBLENDER) -h");
break;
case PanoramaOptions::SMARTBLEND_BLEND:
checkProg(o,"smartblend","@-$(SMARTBLEND)");
break;
}
// test enfuse
checkProg(o,"enfuse","@-$(ENFUSE) -h");
// test hugin_hdrmerge
checkProg(o,"hugin_hdrmerge","@-$(HDRMERGE) -h");
// test exiftool
checkProg(o,"exiftool","@-$(EXIFTOOL) -ver");
// test rm
/* Needs to be replaced by a test that creates and deletes a file in the TEMP dir
o << "\t@echo -n 'Checking rm...'" << endl
#ifdef MAC_OS_X
<< "\t@-which $(RM) > " << NULL_DEVICE << " 2>&1 && echo '[OK]' || echo '[FAIL]'" << endl;
#else
<< "\t@-$(RM) --version > " << NULL_DEVICE << " 2>&1 && echo '[OK]' || echo '[FAIL]'" << endl;
#endif
*/
o << endl;
// ==============================
// output rules for all targets.
// remapped LDR images for exposure stacks.
switch(opts.remapper) {
case PanoramaOptions::NONA:
// produce rules for remapping with nona:
{
o << "# Rules for ordinary TIFF_m output" << endl;
int i=0;
for (UIntSet::iterator it = images.begin();
it != images.end(); ++it)
{
string destImg = escapeStringMake(remappedImages[i]);
string srcImg = escapeStringMake(pano.getImage(*it).getFilename());
o << destImg << ": " << srcImg << " $(PROJECT_FILE)" << endl
<< "\t$(NONA) $(NONA_OPTS) $(NONA_LDR_REMAPPED_COMP) -r ldr -m " << ldrRemappedMode << " -o $(LDR_REMAPPED_PREFIX_SHELL) -i " << *it << " $(PROJECT_FILE_SHELL)" << endl << endl;
i++;
}
o << "# Rules for merge to hdr output" << endl;
i=0;
for (UIntSet::iterator it = images.begin();
it != images.end(); ++it)
{
string destImg = escapeStringMake(remappedHDRImages[i]);
string srcImg = escapeStringMake(pano.getImage(*it).getFilename());
o << destImg << ": " << srcImg << " $(PROJECT_FILE)" << endl
<< "\t$(NONA) $(NONA_OPTS) -r hdr -m " << hdrRemappedMode << " -o $(HDR_STACK_REMAPPED_PREFIX_SHELL) -i " << *it << " $(PROJECT_FILE_SHELL)" << endl << endl;
i++;
}
// rules for exposure sets.
o << "# Rules for exposure layer output" << endl;
int j=0;
for (unsigned i=0; i < similarExposures.size(); i++) {
for (UIntSet::iterator it = similarExposures[i].begin();
it != similarExposures[i].end(); ++it)
{
string destImg = escapeStringMake(similarExposureRemappedImages[j]);
string srcImg = escapeStringMake(pano.getImage(*it).getFilename());
/*
o << destImg << ": " << srcImg << " $(PROJECT_FILE)" << endl
<< "\t$(NONA) -r ldr -e $(LDR_EXPOSURE_LAYER_" << i << "_EXPOSURE) -m "
<< ldrRemappedMode << " -o $(LDR_EXPOSURE_REMAPPED_PREFIX) -i " << *it
<< " $(PROJECT_FILE)" << endl << endl;
*/
o << destImg << ": " << srcImg << " $(PROJECT_FILE)" << endl
<< "\t$(NONA) $(NONA_OPTS) $(NONA_LDR_REMAPPED_COMP) -r ldr -e " << pano.getImage(*it).getExposureValue()
<< " -m " << ldrRemappedMode << " -o $(LDR_EXPOSURE_REMAPPED_PREFIX_SHELL) -i " << *it
<< " $(PROJECT_FILE_SHELL)" << endl << endl;
j++;
}
}
}
break;
case PanoramaOptions::PTMENDER:
o << "$(LDR_LAYERS) : $(INPUT_IMAGES) $(PROJECT_FILE)" << endl
<< "\t$(PTMENDER) -o $(LDR_REMAPPED_PREFIX_SHELL) $(PROJECT_FILE_SHELL)" << endl << endl;
break;
}
// ====================================
// output rules for HDR merging
// write rules for each HDR stack
// only output pixes that are defined in all input images
for (unsigned i=0; i < stacks.size(); i++) {
o << "$(HDR_STACK_" << i << ") : $(HDR_STACK_" << i << "_INPUT)" << endl
<< "\t$(HDRMERGE) $(HDRMERGE_OPTS) -o $(HDR_STACK_" << i << "_SHELL) $(HDR_STACK_" << i << "_INPUT_SHELL)" << endl
<< endl;
}
// ====================================
// output rules for LDR stack merging
for (unsigned i=0; i < stacks.size(); i++) {
o << "$(LDR_STACK_" << i << ") : $(LDR_STACK_" << i << "_INPUT)" << endl
<< "\t$(ENFUSE) $(ENFUSE_OPTS) -o $(LDR_STACK_" << i << "_SHELL) $(LDR_STACK_" << i << "_INPUT_SHELL)" << endl
<< "\t- $(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_STACK_" << i << "_SHELL)" << endl
<< endl;
}
switch(opts.blendMode) {
case PanoramaOptions::ENBLEND_BLEND:
// write rules for blending with enblend
o << "$(LDR_BLENDED) : $(LDR_LAYERS)" << endl;
o << "\t$(ENBLEND) $(ENBLEND_LDR_COMP) $(ENBLEND_OPTS) -o $(LDR_BLENDED_SHELL) $(LDR_LAYERS_SHELL) " << endl;
o << "\t- $(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_BLENDED_SHELL)" << endl << endl;
// for LDR exposure blend planes
for (unsigned i=0; i < similarExposures.size(); i++) {
o << "$(LDR_EXPOSURE_LAYER_" << i <<") : $(LDR_EXPOSURE_LAYER_" << i << "_INPUT)" << endl
<< "\t$(ENBLEND) $(ENBLEND_LDR_COMP) $(ENBLEND_OPTS) -o $(LDR_EXPOSURE_LAYER_" << i <<"_SHELL) $(LDR_EXPOSURE_LAYER_" << i << "_INPUT_SHELL)" << endl
<< "\t-$(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_EXPOSURE_LAYER_" << i <<"_SHELL)" << endl << endl;
}
// rules for enfuse blending
o << "$(LDR_STACKED_BLENDED) : $(LDR_STACKS)" << endl
<< "\t$(ENBLEND) $(ENBLEND_LDR_COMP) $(ENBLEND_OPTS) -o $(LDR_STACKED_BLENDED_SHELL) $(LDR_STACKS_SHELL) " << endl
<< "\t- $(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_STACKED_BLENDED_SHELL)" << endl << endl;
// rules for fusing blended layers
o << "$(LDR_EXPOSURE_LAYERS_FUSED) : $(LDR_EXPOSURE_LAYERS)" << endl
<< "\t$(ENFUSE) $(ENBLEND_LDR_COMP) $(ENFUSE_OPTS) -o $(LDR_EXPOSURE_LAYERS_FUSED_SHELL) $(LDR_EXPOSURE_LAYERS_SHELL) " << endl
<< "\t- $(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_EXPOSURE_LAYERS_FUSED_SHELL)" << endl << endl;
// rules for hdr blending
o << "$(HDR_BLENDED) : $(HDR_STACKS)" << endl;
o << "\t$(ENBLEND) $(ENBLEND_HDR_COMP) $(ENBLEND_OPTS) -o $(HDR_BLENDED_SHELL) $(HDR_STACKS_SHELL) " << endl << endl;
// rules for multilayer output
o << "$(LDR_REMAPPED_PREFIX)_multilayer.tif : $(LDR_LAYERS)" << endl;
o << "\ttiffcp $(LDR_LAYERS_SHELL) $(LDR_REMAPPED_PREFIX_SHELL)_multilayer.tif" << endl << endl;
o << "$(LDR_REMAPPED_PREFIX)_fused_multilayer.tif : $(LDR_STACKS) $(LDR_EXPOSURE_LAYERS)" << endl;
o << "\ttiffcp $(LDR_STACKS_SHELL) $(LDR_EXPOSURE_LAYERS_SHELL) $(LDR_REMAPPED_PREFIX_SHELL)_fused_multilayer.tif" << endl << endl;
o << "$(LDR_REMAPPED_PREFIX)_multilayer.psd : $(LDR_LAYERS)" << endl;
o << "\tPTtiff2psd -o $(LDR_REMAPPED_PREFIX_SHELL)_multilayer.psd $(LDR_LAYERS_SHELL)" << endl << endl;
o << "$(LDR_REMAPPED_PREFIX)_fused_multilayer.psd : $(LDR_STACKS) $(LDR_EXPOSURE_LAYERS)" << endl;
o << "\tPTtiff2psd -o $(LDR_REMAPPED_PREFIX_SHELL)_fused_multilayer.psd $(LDR_STACKS_SHELL) $(LDR_EXPOSURE_LAYERS_SHELL)" << endl << endl;
break;
case PanoramaOptions::NO_BLEND:
o << "$(LDR_BLENDED) : $(LDR_LAYERS)" << endl
<< "\t-$(RM) $(LDR_BLENDED_SHELL)" << endl
<< "\t$(PTROLLER) -o $(LDR_BLENDED_SHELL) $(LDR_LAYERS_SHELL) " << endl
<< "\t- $(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_BLENDED_SHELL)" << endl << endl;
// for LDR exposure blend planes
for (unsigned i=0; i < similarExposures.size(); i++) {
o << "$(LDR_EXPOSURE_LAYER_" << i <<") : $(LDR_EXPOSURE_LAYER_" << i << "_INPUT)" << endl
<< "\t-$(RM) $(LDR_EXPOSURE_LAYER_" << i <<"_SHELL)" << endl
<< "\t$(PTROLLER) -o $(LDR_EXPOSURE_LAYER_" << i <<"_SHELL) $(LDR_EXPOSURE_LAYER_" << i << "_INPUT_SHELL)" << endl
<< "\t- $(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_EXPOSURE_LAYER_" << i <<"_SHELL)" << endl << endl;
}
o << "$(LDR_STACKED_BLENDED) : $(LDR_STACKS)" << endl
<< "\t-$(RM) $(LDR_STACKED_BLENDED_SHELL)" << endl
<< "\t$(PTROLLER) -o $(LDR_STACKED_BLENDED_SHELL) $(LDR_STACKS_SHELL)" << endl
<< "\t- $(EXIFTOOL) -overwrite_original_in_place -TagsFromFile $(INPUT_IMAGE_1_SHELL) $(EXIFTOOL_COPY_ARGS) $(LDR_STACKED_BLENDED_SHELL)" << endl << endl;
// rules for non-blended HDR panoramas
o << "$(HDR_BLENDED) : $(HDR_LAYERS)" << endl;
o << "\t$(HDRMERGE) $(HDRMERGE_OPTS) -o $(HDR_BLENDED_SHELL) $(HDR_LAYERS_SHELL)" << endl << endl;
break;
case PanoramaOptions::PTBLENDER_BLEND:
// TODO: output PTBlender + PTmasker + PTroller rules
break;
case PanoramaOptions::SMARTBLEND_BLEND:
// TODO: build smartblend command line from given images. (requires additional program)
break;
default:
// TODO:
break;
}
}
#ifdef UNIX_LIKE
// reset locale
setlocale(LC_NUMERIC,old_locale);
free(old_locale);
#endif
}
} //namespace

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks