-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsetsm_code.cpp
12291 lines (10340 loc) · 566 KB
/
setsm_code.cpp
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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2017 Myoung-Jong Noh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <atomic>
#include <memory>
#include "setsm_code.hpp"
#include "log.hpp"
#ifdef BUILDMPI
#include "mpi.h"
#include "mpi_helpers.hpp"
#endif
const char setsm_version[] = "4.3.16";
int main(int argc,char *argv[])
{
#ifdef BUILDMPI
init_mpi(argc, argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif
init_logging();
setlogmask (LOG_UPTO (LOG_NOTICE));
openlog ("setsm", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_NOTICE);
syslog (LOG_NOTICE, "git_description: %s user: %s\n", GIT_DESCRIPTION, getlogin());
#ifdef DEBUG_SYSLOG
printf ("setsm git_description: %s user: %s\n", GIT_DESCRIPTION, getlogin());
#endif
closelog ();
setbuf(stdout, NULL);
TIFFSetWarningHandler(NULL);
char* projectfilename = (char*)"default.txt";
int i=0;
ARGINFO args;
args.sensor_type = SB; //1 = satellite, 2 = Aerial Photo
args.pyramid_level = 4;
args.SDM_SS = 3;
args.SDM_AS = 20.0;
args.SDM_days = 1;
args.number_of_images = 2;
args.check_arg = 0;
args.check_DEM_space = false;
args.check_Threads_num = false;
args.check_seeddem = false;
args.check_minH = false;
args.check_maxH = false;
args.check_tiles_SR = false;
args.check_tiles_ER = false;
args.check_tiles_SC = false;
args.check_tiles_EC = false;
args.check_RA_line = false;
args.check_RA_sample= false;
args.check_gridonly = false;
args.check_RA_tileR = false;
args.check_RA_tileC = false;
args.check_tilesize = false;
args.check_boundary = false;
args.check_checktiff = false;
args.check_ortho = false;
args.check_RA_only = false;
args.check_LSF = false;
args.check_LSF_DEM = false;
args.check_LSFDEMpath = false;
args.check_LSF2 = 0;
args.check_Matchtag = false;
args.check_EO = false;
args.check_fl = false;
args.check_ccd = false;
args.check_full_cal = false;
args.check_coreg = 0; //image coreg = 1, DEM coreg = 2, image + DEM = 3
args.check_sdm_ortho = 0; //no coreg = 1 , with coreg = 2
args.check_DEM_coreg_output = false;
args.check_tif_rounding = false;
args.check_txt_input = 0; //no txt input = 0, DEM coregistration txt input = 1;
args.check_downsample = false;
args.check_DS_txy = false;
args.number_of_images = 2;
args.projection = 3;//PS = 1, UTM = 2
args.param.pm = 0;
args.sensor_provider = DG; //DG = 1, Pleiades = 2, Planet = 3
args.check_imageresolution = false;
args.utm_zone = -99;
args.ortho_count = 1;
args.overlap_length = 50;
args.RA_only = 0;
args.focal_length = 120;
args.CCD_size = 12;
args.SGM_py = 1;
args.DS_sigma = 1.6;
args.DS_kernel = 9;
args.GCP_spacing = -9;
TransParam param;
param.bHemisphere = 1;
int image_count = 0;
int RA_line_count = 1;
int RA_sample_count = 1;
args.ra_line[0] = 0.0; //first image is a reference for RPCs bias computation
args.ra_sample[0] = 0.0;
args.System_memory = getSystemMemory(); //default system memory
int DEM_divide = 0;
double **Imageparams = NULL;
if(argc == 1)
{
char save_filepath[500];
char LeftImagefilename[500];
args.check_arg = 0;
Imageparams = (double**)calloc(args.number_of_images, sizeof(double*));
for(int ti = 0 ; ti < args.number_of_images ; ti++)
{
Imageparams[ti] = (double*)calloc(sizeof(double),2);
Imageparams[ti][0] = 0.0;
Imageparams[ti][1] = 0.0;
}
DEM_divide = SETSMmainfunction(¶m,projectfilename,args,save_filepath,Imageparams);
#ifdef BUILDMPI
if(rank == 0) {
#endif
char DEMFilename[500];
char Outputpath[500];
sprintf(DEMFilename, "%s/%s_dem.tif", save_filepath,args.Outputpath_name);
sprintf(Outputpath, "%s", save_filepath);
printf("%s\n",LeftImagefilename);
printf("%s\n",DEMFilename);
printf("%s\n",Outputpath);
if(DEM_divide == 0)
orthogeneration(param,args,LeftImagefilename, DEMFilename, Outputpath,1,DEM_divide,Imageparams);
else
orthogeneration(param,args,LeftImagefilename, DEMFilename, Outputpath,1,DEM_divide,Imageparams);
#ifdef BUILDMPI
}
#endif
}
else if(argc == 2)
{
if (strcmp("-help",argv[1]) == 0)
{
printf("Usage:./setsm [-help] : general explanation\n");
printf("\texecution 1 : ./setsm : execute setsm with default.txt\n");
printf("\t\texample usage : ./setsm\n");
printf("\texecution 2 : ./setsm [image1] [image2] [output_directory]\n");
printf("\t\t(execute setsm with image1, image2, and output directory for saving the results)\n");
printf("\t\texample usage : ./setsm /home/image1.tif /home/image2.tif /home/output\n");
printf("\t\t\t or ./setsm /home/image1.bin /home/image2.bin /home/output\n");
printf("\texecution 3 : ./setsm [image1] [image2] [output_directory] [-options]\n");
printf("\t\t(execute setsm with image1, image2 and output directory for saving the results with user-defined options\n");
printf("\t\texample usage : ./setsm /home/image1.tif /home/image2.tif /home/output -outres 10 -threads 12 -seed /home/seed_dem.bin 50\n\n");
printf("setsm version : %s\n", setsm_version);
printf("supported image format : tif with xml, and binary with envi header file\n");
printf("options\n");
printf("\t[-outres value]\t: Output grid spacing[m] of Digital Elevation Model(DEM)\n");
printf("\t[-seed filepath sigma]\t: Seed DEM(tif or binary format with envi header file for reducing computation loads with a height accuracy[m] of seed dem\n");
printf("\t\t(if this option is set, setsm defines serach-spaces between + 1*sigma and - 1*sigma for calculating a height of grid position.\n");
printf("\t\tThis option is not recommended on very changeable area. setsm can reconstruct 3D surface information without any seed dem\n");
printf("\t[-boundary_min_X value1 -boundary_min_Y value2 -boundary_max_X value3 -boundary_max_Y value4]\t: Define specific DEM area to generate. The X and Y coordinate values should be Polar Stereographic or UTM\n");
printf("\t[-tilesize value]\t: Set a tilesize for one time processing. Default is 8,000 pixels\n");
printf("\t[-projection value]\t: Set planemetric coordinate projection. The value is 'ps' or 'utm'. Default projection is automatically defined by latitude of the input information of xml (between 60N and 60S is utm, and other is ps\n");
printf("\t[-threads value]\t : Total number of threads for utilizing openmp parallel codes\n");
printf("\t\t(if you don't know about this value, input '0'. Openmp can automatically detect a best value of your system)\n");
printf("\t[-RAonly value]\t: If set to 1 (true), program will exit after RA calculation. Default = 0 (false)\n");
}
}
else if(argc == 3)
{
if(strcmp("-gridonly",argv[1]) == 0)
{
char save_filepath[500];
args.check_gridonly = true;
sprintf(args.Outputpath,"%s",argv[2]);
char *Outputpath_name = SetOutpathName(args.Outputpath);
sprintf(args.Outputpath_name,"%s",Outputpath_name);
printf("after pathname %s\n",args.Outputpath_name);
printf("%s\n",args.Outputpath);
printf("%s\n", args.Outputpath_name);
free(Outputpath_name);
Imageparams = (double**)calloc(args.number_of_images, sizeof(double*));
for(int ti = 0 ; ti < args.number_of_images ; ti++)
{
Imageparams[ti] = (double*)calloc(sizeof(double),2);
Imageparams[ti][0] = 0.0;
Imageparams[ti][1] = 0.0;
}
DEM_divide = SETSMmainfunction(¶m,projectfilename,args,save_filepath,Imageparams);
}
}
else if(argc == 4)
{
args.check_arg = 1;
sprintf(args.Image[0],"%s",argv[1]);
sprintf(args.Image[1],"%s",argv[2]);
sprintf(args.Outputpath,"%s",argv[3]);
char *Outputpath_name = SetOutpathName(args.Outputpath);
sprintf(args.Outputpath_name,"%s",Outputpath_name);
printf("after pathname %s\n",args.Outputpath_name);
printf("%s\n",args.Image[0]);
printf("%s\n",args.Image[1]);
printf("%s\n",args.Outputpath);
printf("%s\n", args.Outputpath_name);
free(Outputpath_name);
char save_filepath[500];
char LeftImagefilename[500];
if( strcmp(args.Image[0],args.Image[1]) != 0)
{
Imageparams = (double**)calloc(args.number_of_images, sizeof(double*));
for(int ti = 0 ; ti < args.number_of_images ; ti++)
{
Imageparams[ti] = (double*)calloc(sizeof(double),2);
Imageparams[ti][0] = 0.0;
Imageparams[ti][1] = 0.0;
}
DEM_divide = SETSMmainfunction(¶m,projectfilename,args,save_filepath,Imageparams);
#ifdef BUILDMPI
if(rank == 0) {
#endif
char DEMFilename[500];
char Outputpath[500];
sprintf(Outputpath, "%s", save_filepath);
if(DEM_divide == 0)
{
sprintf(DEMFilename, "%s/%s_dem.tif", save_filepath,args.Outputpath_name);
orthogeneration(param,args,LeftImagefilename, DEMFilename, Outputpath,1,DEM_divide,Imageparams);
}
else
{
for(int iter = 1 ; iter <= DEM_divide ; iter++)
{
sprintf(DEMFilename, "%s/%s_%d_dem.tif", save_filepath,args.Outputpath_name,iter);
orthogeneration(param,args,LeftImagefilename, DEMFilename, Outputpath,1,iter,Imageparams);
}
}
#ifdef BUILDMPI
}
#endif
}
else
printf("Please check input 1 and input 2. Both is same\n");
}
else if(argc > 4)
{
bool cal_flag = true;
for (i=0; i<argc; i++)
{
if (strcmp("-LSFDEM",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '1' for Yes or '0' for No\n");
cal_flag = false;
}
else
{
args.check_LSF_DEM = atoi(argv[i+1]);
printf("LSFDEM %d\n",args.check_LSF_DEM);
}
}
if (strcmp("-LSFDEM_path",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input DEM path for LSF\n");
cal_flag = false;
}
else
{
sprintf(args.Outputpath,"%s",argv[i+1]);
args.check_LSFDEMpath = true;
printf("LSFDEMpath %s\n",args.Outputpath);
}
}
if (strcmp("-round",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '1' for generating rounded tifs by 128\n");
cal_flag = false;
}
else
{
args.check_tif_rounding = atoi(argv[i+1]);
printf("Rounded Tiff generation %d\n",args.check_tif_rounding);
}
}
if (strcmp("-coreg",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '1' for Orthoimage or '2' for DEM\n");
cal_flag = false;
}
else
{
args.check_coreg = atoi(argv[i+1]);
printf("Coregistration %d\n",args.check_coreg);
}
}
if (strcmp("-txt_input",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input image txt file\n");
cal_flag = false;
}
else
{
args.check_txt_input = 1;
printf("txt input %d\n",args.check_txt_input);
if(args.check_txt_input == 1)
{
sprintf(args.DEM_input_file,"%s",argv[i+1]);
printf("txt input %s\n",args.DEM_input_file);
}
}
}
if (strcmp("-coreg_output",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '2' for generation both coregistered image and whole image diff stat or '1' for generation whole image diff stat or '0' for no generation\n");
cal_flag = false;
}
else
{
if(args.check_coreg == 2 || args.check_coreg == 3)
{
args.check_DEM_coreg_output = atoi(argv[i+1]);
printf("Coregistration output tif gneneration %d\n",args.check_DEM_coreg_output);
}
}
}
if (strcmp("-gcp_space",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input the GCP space value\n");
cal_flag = false;
}
else
{
args.GCP_spacing = atof(argv[i+1]);
printf("%f\n",args.GCP_spacing);
}
}
if (strcmp("-SDM",argv[i]) == 0 || strcmp("-sdm",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '1' for Orthoimage only without coreg, '2' for orthoimage with coreg, '3' for DEM with original image\n");
cal_flag = false;
}
else
{
args.check_sdm_ortho = atoi(argv[i+1]);
printf("SDM with orthoimage %d\n",args.check_sdm_ortho);
}
}
if (strcmp("-outres",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input the outres value\n");
cal_flag = false;
}
else
{
args.DEM_space = atof(argv[i+1]);
printf("%f\n",args.DEM_space);
args.check_DEM_space = true;
}
}
if (strcmp("-projection", argv[i]) == 0) {
if (argc == i + 1) {
printf("Please input Projection info\n");
cal_flag = false;
} else {
if(strcmp("utm",argv[i+1]) == 0 || strcmp("UTM",argv[i+1]) == 0)
{
args.projection = 2;
printf("UTM projection \n");
}
else
{
args.projection = 1;
printf("PS projection\n");
}
}
}
if (strcmp("-North",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input North value\n");
cal_flag = false;
}
else
{
int dir = atoi(argv[i+1]);
if(dir == 1)
{
param.bHemisphere = 1;
param.pm = 1;
}
else
{
param.bHemisphere = 2;
param.pm = -1;
}
}
}
if (strcmp("-mem",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input System memory\n");
cal_flag = false;
}
else
{
args.System_memory = atof(argv[i+1]);
printf("System memory %f\n",args.System_memory);
}
}
}
if(args.check_LSF_DEM)
{
char str_DEMfile[1000];
char str_matchfile[1000];
char str_matchfile_tif[1000];
char str_smooth_file[500];
char DEM_header[500];
char smooth_GEOTIFF_filename[500];
char result_file[500];
char metafilename[500];
if(args.projection == 3)
param.projection = 1;
else
param.projection = args.projection;
char *ext = strrchr(args.Outputpath,'.');
if(ext)
{
if (!strcmp("tif",ext+1) || !strcmp("TIF",ext+1) || !strcmp("raw",ext+1))
{
printf("DEM file open\n");
sprintf(str_DEMfile, "%s", args.Outputpath);
char *tmp_chr = remove_ext(args.Outputpath);
sprintf(str_smooth_file, "%s_smooth.raw", tmp_chr);
sprintf(DEM_header, "%s_smooth.hdr", tmp_chr);
sprintf(smooth_GEOTIFF_filename, "%s_smooth.tif", tmp_chr);
int full_size = strlen(tmp_chr);
char *t_name = (char*)malloc(sizeof(char)*(full_size-4));
for(int kk = 0; kk < full_size-4 ; kk++)
t_name[kk] = tmp_chr[kk];
sprintf(metafilename,"%s_meta.txt",t_name);
sprintf(str_matchfile,"%s_matchtag.raw",t_name);
sprintf(str_matchfile_tif,"%s_matchtag.tif",t_name);
sprintf(result_file,"%s_smooth_result.txt",t_name);
free(tmp_chr);
}
else
{
printf("No DEM(tif or raw) exists!!\n");
exit(1);
}
}
else
{
char *Outputpath_name = SetOutpathName(args.Outputpath);
sprintf(str_DEMfile, "%s/%s_dem.tif", args.Outputpath,Outputpath_name);
sprintf(str_smooth_file,"%s/%s_dem_smooth.raw",args.Outputpath,Outputpath_name);
sprintf(DEM_header, "%s/%s_dem_smooth.hdr", args.Outputpath,Outputpath_name);
sprintf(smooth_GEOTIFF_filename, "%s/%s_dem_smooth.tif", args.Outputpath, Outputpath_name);
sprintf(metafilename,"%s/%s_meta.txt",args.Outputpath,Outputpath_name);
sprintf(str_matchfile,"%s/%s_matchtag.raw",args.Outputpath,Outputpath_name);
sprintf(str_matchfile_tif,"%s/%s_matchtag.tif",args.Outputpath,Outputpath_name);
sprintf(result_file,"%s/%sdem_smooth_result.txt",args.Outputpath,Outputpath_name);
free(Outputpath_name);
}
printf("dem file %s\n",str_DEMfile);
printf("metafilename %s\n",metafilename);
printf("matchfile %s\n",str_matchfile);
printf("smooth DEM %s\n",str_smooth_file);
printf("DEM_header %s\n",DEM_header);
printf("smooth_GEOTIFF_filename %s\n", smooth_GEOTIFF_filename);
printf("result file %s\n",result_file);
FILE *pFile_DEM = fopen(str_DEMfile,"r");
printf("check exist %s %d\n",str_DEMfile,!!pFile_DEM);
if(pFile_DEM)
{
double MPP_stereo_angle = 1;
FILE *pMetafile = fopen(metafilename,"r");
if(pMetafile)
{
printf("meta file exist!!");
char linestr[1000];
char linestr1[1000];
char* pos1;
char* token = NULL;
bool check_mpp = false;
while(!feof(pMetafile) && !check_mpp)
{
fgets(linestr,sizeof(linestr),pMetafile);
strcpy(linestr1,linestr);
token = strtok(linestr,"=");
if(strcmp(token,"Setereo_pair_expected_height_accuracy") == 0)
{
pos1 = strstr(linestr1,"=")+1;
MPP_stereo_angle = atof(pos1);
check_mpp = true;
}
}
fclose(pMetafile);
}
else
printf("meta file doesn't exist!!\n");
printf("MPP_stereo_angle %f\n",MPP_stereo_angle);
double minX, maxY;
double grid_size = args.DEM_space;
CSize DEM_size = GetDEMsize(str_DEMfile,metafilename,¶m,&grid_size,&minX,&maxY);
float *seeddem = GetDEMValue(str_DEMfile,DEM_size);
long data_length = (long)DEM_size.width*(long)DEM_size.height;
printf("data_length %ld\n",data_length);
printf("projection %d\tHemisphere %d\n",param.projection,param.bHemisphere);
printf("%d\n",DEM_size.width);
printf("%d\n",DEM_size.height);
printf("%f\n",grid_size);
LSFINFO *Grid_info = (LSFINFO*)malloc(sizeof(LSFINFO)*data_length);
if(Grid_info == NULL)
{
printf("Insufficient memory available\n");
exit(1);
}
for(long count_index = 0 ; count_index < data_length; count_index++)
Grid_info[count_index].lsf_kernel = 2;
float *smooth_DEM = (float*)malloc(sizeof(float)*data_length);
if(smooth_DEM == NULL)
{
printf("Insufficient memory available\n");
exit(1);
}
double max_std = -100000;
int max_std_iter = -1;
int min_std_iter = 100;
double min_std = 100000;
int max_iter_th;
if(grid_size >= 2)
max_iter_th = 2;
else
max_iter_th = 2;
const int max_iter_count = 5;
int s_iter = 0;
bool check_smooth_iter = true;
double sigma_avg = 10000;
double sigma_std = 10000;
while(check_smooth_iter && s_iter < max_iter_count)
{
printf("start LSF\n");
if((sigma_avg < 0.5 && sigma_std < 1) || s_iter == max_iter_count-1)
{
if(s_iter > max_iter_th)
{
printf("final local suface fitting\n");
check_smooth_iter = false;
}
}
DEM_STDKenel_LSF(Grid_info, &sigma_avg, &sigma_std,seeddem,smooth_DEM,grid_size,s_iter,DEM_size, MPP_stereo_angle);
if(sigma_avg > max_std)
{
max_std = sigma_avg;
max_std_iter = s_iter;
}
if(sigma_avg < min_std)
{
min_std = sigma_avg;
min_std_iter = s_iter;
}
printf("End LSF %d\tsigma avg std %f\t%f\n",s_iter,sigma_avg,sigma_std);
memcpy(seeddem,smooth_DEM,sizeof(float)*data_length);
s_iter++;
}
free(smooth_DEM);
free(Grid_info);
WriteGeotiff(smooth_GEOTIFF_filename, seeddem, DEM_size.width, DEM_size.height, grid_size, minX, maxY, param.projection, param.utm_zone, param.bHemisphere, 4);
FILE *presult = fopen(result_file,"w");
fprintf(presult,"%d\t%f\t%d\t%f\n",max_std_iter,max_std,min_std_iter,min_std);
fclose(presult);
printf("%d\t%f\t%d\t%f\n",max_std_iter,max_std,min_std_iter,min_std);
free(seeddem);
fclose(pFile_DEM);
}
}
else
{
args.check_arg = 1;
bool bminx = false;
bool bmaxx = false;
bool bminy = false;
bool bmaxy = false;
for (i=0; i<argc; i++)
{
if (strcmp("-SGMpy",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input sgm pyramid level steps (default is -1)\n");
cal_flag = false;
}
else
{
args.SGM_py = atoi(argv[i+1]);
printf("Steps of sgm pyramid level %d\n",args.SGM_py);
}
}
if (strcmp("-PL",argv[i]) == 0 || strcmp("-pl",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input pyramid level steps (default is 4)\n");
cal_flag = false;
}
else
{
args.pyramid_level = atoi(argv[i+1]);
printf("Steps of pyramid level %d\n",args.pyramid_level);
}
}
if (strcmp("-SDM_SS",argv[i]) == 0 || strcmp("-sdm_ss",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input SDM search size (default is 3)\n");
cal_flag = false;
}
else
{
args.SDM_SS = atoi(argv[i+1]);
printf("SDM search size %d\n",args.SDM_SS);
}
}
if (strcmp("-SDM_DAYS",argv[i]) == 0 || strcmp("-sdm_days",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input time difference(day) between images (default is 1)\n");
cal_flag = false;
}
else
{
args.SDM_days = atof(argv[i+1]);
printf("SDM time gap %f(days)\n",args.SDM_days);
}
}
if (strcmp("-SDM_AS",argv[i]) == 0 || strcmp("-sdm_as",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input average velocity per day(m/day) for SDM\n");
cal_flag = false;
}
else
{
args.SDM_AS = atof(argv[i+1]);
printf("Average velocity %f(m/day)\n",args.SDM_AS);
}
}
if (strcmp("-PC",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please select option of full resolution DEM grid (default is 0)\n");
cal_flag = false;
}
else
{
args.check_full_cal = atoi(argv[i+1]);
printf("Option of full resolution DEM grid %d\n",args.check_full_cal);
}
}
if (strcmp("-Sensor",argv[i]) == 0 || strcmp("-sensor",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '1' for RFM(default) or '0' for Collinear Equation(Frame)\n");
cal_flag = false;
}
else
{
int temp;
temp = atoi(argv[i+1]);
if(temp == 1)
{
args.sensor_type = SB;
printf("Spaceborne RFM Sensor %d\n",args.sensor_type);
}
else
{
args.sensor_type = AB;
printf("Airborne frame Sensor %d\n",args.sensor_type);
}
}
}
if (strcmp("-NImages",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input Number of images (default is 2 for stereo)\n");
cal_flag = false;
}
else
{
args.number_of_images = atoi(argv[i+1]);
printf("Number of Images %d\n",args.number_of_images);
}
}
if (strcmp("-FL",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input focal length[mm]\n");
cal_flag = false;
}
else
{
args.focal_length = atof(argv[i+1]);
printf("focal length %f\n",args.focal_length);
args.check_fl = true;
}
}
if (strcmp("-CCDsize",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input CCD size[um]\n");
cal_flag = false;
}
else
{
args.CCD_size = atof(argv[i+1]);
printf("CCD size %f\n",args.CCD_size);
args.check_ccd = true;
}
}
if (strcmp("-EO",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input Exterior Orientation informations\n");
cal_flag = false;
}
else
{
sprintf(args.EO_Path,"%s",argv[i+1]);
args.check_EO = true;
printf("EO_path %s\n",args.EO_Path);
}
}
if (strcmp("-image",argv[i]) == 0 || strcmp("-Image",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input image path\n");
cal_flag = false;
}
else
{
sprintf(args.Image[image_count],"%s",argv[i+1]);
printf("image%d %s\n",image_count,args.Image[image_count]);
image_count++;
}
}
if (strcmp("-outpath",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input outpath\n");
cal_flag = false;
}
else
{
sprintf(args.Outputpath,"%s",argv[i+1]);
printf("Out path %s\n",args.Outputpath);
}
}
if (strcmp("-provider", argv[i]) == 0) {
if (argc == i + 1) {
printf("Please input Provider info\n");
cal_flag = false;
} else {
if(strcmp("DG",argv[i+1]) == 0 || strcmp("dg",argv[i+1]) == 0)
{
args.sensor_provider = DG;
printf("Image Provider : Digital Globe\n");
}
else if(strcmp("Pleiades",argv[i+1]) == 0 || strcmp("pleiades",argv[i+1]) == 0)
{
args.sensor_provider = PL;
printf("Image Provider : Pleiades\n");
}
else if(strcmp("Planet",argv[i+1]) == 0 || strcmp("planet",argv[i+1]) == 0)
{
args.sensor_provider = PT;
printf("Image Provider : Planet\n");
}
else
{
args.projection = 1;
printf("Not suppoted Provider. Please use Digital Globe (Worldview, QuickBird, GeoEye) or Pleiades\n");
exit(1);
}
}
}
if (strcmp("-GSD",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input the image resolution (GSD) value\n");
cal_flag = false;
}
else
{
args.image_resolution = atof(argv[i+1]);
printf("%f\n",args.image_resolution);
args.check_imageresolution = true;
}
}
if (strcmp("-LSF",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '1 ' for applying LSF smoothing\n ");
cal_flag = false;
}
else
{
int input_number = atoi(argv[i+1]);
if(input_number == 1 || input_number == 2)
{
args.check_LSF2 = input_number;
printf("LSF %d\n",args.check_LSF2);
}
else
printf("LSF is not applied!!\n");
}
}
if (strcmp("-MT",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input '1 ' for applying v331 matchtag info\n ");
cal_flag = false;
}
else
{
int input_number = atoi(argv[i+1]);
if(input_number == 1)
{
args.check_Matchtag = true;
printf("MT %d\n",args.check_Matchtag);
}
else
printf("MT is not applied!!\n");
}
}
if (strcmp("-outres",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input the outres value\n");
cal_flag = false;
}
else
{
args.DEM_space = atof(argv[i+1]);
printf("%f\n",args.DEM_space);
args.check_DEM_space = true;
}
}
if (strcmp("-threads",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input the threads value\n");
cal_flag = false;
}
else
{
args.Threads_num = atoi(argv[i+1]);
printf("%d\n",args.Threads_num);
args.check_Threads_num = true;
}
}
if (strcmp("-downsample",argv[i]) == 0)
{
if (argc == i+1) {
printf("Please input the threads value\n");
cal_flag = false;
}
else
{
sprintf(args.seedDEMfilename,"%s",argv[i+1]);
printf("source %s\n",args.seedDEMfilename);
sprintf(args.Outputpath_name,"%s",argv[i+2]);
printf("target %s\n",args.Outputpath_name);
args.check_downsample = true;