-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserinterface.cpp
More file actions
1685 lines (1556 loc) · 47.9 KB
/
userinterface.cpp
File metadata and controls
1685 lines (1556 loc) · 47.9 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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef USERINTERFACE_CPP
#define USERINTERFACE_CPP USERINTERFACE_CPP
#define PRINT(x) cout << #x << " => " << x << endl;
#include <cstdint>
#include <limits>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <complex.h>
//#include <fftw3.h>
#include <thread>
#include <random>
//#include "tiffio.h"
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include "opencv2/core/types.hpp"
using namespace std;
using namespace cv;
double scaling_factor = 1.0;
//#include "datafun.h"
//#include "datafun.cpp"
#include "node.h"
#include "united_junction.h"
unsigned long long THREADS = 1;
bool THREADS_set = false;
double RV = 8; // 8 vision radius (~2 times fibre thickness)
double RM = 0; //minimum vision radius
double RS = 3; //step radius (~ 0.5 - 1 x fiber thickness)
unsigned long long STEPS = 360; //number of steps the smoothing function is computed for
double DEV = 0.5; // 0.55 deviation of gaussian smooth of circlefun
double TH = 0; //0.5 threshold for findpks
unsigned long long ML = 6; //minimum loop length
double SG = 1.8; //1.8 ; 2.3 (a bit less than half fibre thickness)
//computed
#define RN (RF+RS) //neighbor radius
#define RF (RS/SQRT2) //forbidden radius
bool RV_set = false;
bool RM_set = false;
bool RS_set = false;
bool STEPS_set = false;
bool DEV_set = false;
bool TH_set = false;
bool ML_set = false;
bool SG_set = false;
bool rescale = true;
bool cropped = false;
unsigned long long crop_x1 = 0;
unsigned long long crop_y1 = 0;
unsigned long long crop_x2 = 0;
unsigned long long crop_y2 = 0;
unsigned long long node_thresh_below = 0;
unsigned long long node_thresh_above = 0;
bool del_nodes_below_thresh = false;
bool del_nodes_above_thresh = false;
unsigned long long node_line_thresh_below = 0;
unsigned long long node_line_thresh_above = 0;
bool del_lines_below_thresh = false;
bool del_lines_above_thresh = false;
bool modified_hessian = false;
bool del_worst_sect = false;
bool sect_thickness_set = false;
double sect_thickness;
bool start_points_exist = false;
vector<Point*> man_start_points;
bool auto_start_points = false;
unsigned long long n_startpoints = 100;
double rad_startpoints = 20*RS;
bool rad_startpoints_specified = false;
double thresh_startpoints = 0;
unsigned long long tracing_channel = 0;
bool trace_channel = false;
unsigned long long max_iter = 0;
bool invert_bright = false;
//i suppose this is why one uses header files...
bool is_number(string, double&);
bool is_number(string);
bool is_number(string, unsigned long long&);
vector<vector<node*>> find_lines(vector<node*>,double);
void double_vector_to_file(string, vector<double>);
vector<double> line_lengths(vector<vector<node*>>);
void draw_lines(const Mat, const vector<vector<node*>>, const string, const double, const double);
string replace_keywords(string);
double mean_persistence_length(vector<vector<node*>>);
double mean_persistence_length(vector<vector<node*>>,string);
class line_analysis{
public:
static vector<line_analysis*> line_options;
double angle = 3.14159*22.5/180.0;
bool angle_set = false;
bool visualize = false;
bool on_only_loops = false;
string data_path = "<imagename>_line_lengths.dat";
bool data_path_set = false;
unsigned long long imgnum = 10;
bool imgnum_set = false;
string images_folder = "./";
string pers_path = "";
line_analysis(vector<string> line, bool& successful){
if (line[0] == "save_loop_line_lengths"){ on_only_loops = true;}
for (unsigned long long i = 1; i < line.size(); ++i){
if (is_number(line[i],angle)){
if(angle_set){
cout << "line angle can only be set once per line analysis";
successful = false;
return;
}
else {angle_set = true;}
}
else if (line[i] == "draw_lines" && !visualize){
visualize = true;
if (i + 1 < line.size()){
++i; //the = is correct here
if (!(imgnum_set = is_number(line[i], imgnum) || line[i] == "persistence_data")){
images_folder = line[i];
}
if (i + 1 < line.size() && !(line[i+1] == "persistence_data")){
if (imgnum_set){
++i;
images_folder = line[i];
}
else if (is_number(line[i+1], imgnum)){
++i;
}
else {successful = false; return;}
}
}
}
else if (line[i] == "persistence_data" && pers_path == ""){
pers_path = "<imagename>_persitence_data.dat";
if (i + 1 < line.size() && line[i+1] != "draw_lines"){
++i;
pers_path = line[i];
}
}
else if (!data_path_set){
data_path_set = true;
data_path = line[i];
}
else{
successful = false;
return;
}
}
if (!angle_set) {successful = false;}
}
double process(Mat I, vector<node*> list){
vector<vector<node*>> lines = find_lines(list,angle);
vector<double> linelengths = line_lengths(lines);
double_vector_to_file(replace_keywords(data_path),linelengths);
if(visualize){
draw_lines(I,lines,images_folder,imgnum,1);
}
return mean_persistence_length(lines,pers_path);
}
};
vector<line_analysis*> line_analysis::line_options;
class draw_command{
public:
bool all_nodes = false;
bool only_loops = false;
Scalar all_nodes_color = Scalar(255,0,0);
bool all_nodes_hue = false;
Scalar only_loops_color = Scalar(0,0,255);
bool only_loops_hue = false;
double all_nodes_thickness = 1;
double only_loops_thickness = 1;
string background = "original";
bool background_specified = false;
string folder = "";
string name = "";
string ending = "";
bool name_specified = false;
Mat image;
bool cropped = false;
};
vector<draw_command*> draw_commands;
class save_loops{
public:
double thickness = 0;
string path = "<imagename>_loop_areas.dat";
};
vector<save_loops*> loop_area_settings;
string circleness_path = "";
string loop_circumference_path = "";
string loop_diam_path = "";
string all_abs_angs_path = "";
string loop_abs_angs_path = "";
double add_noise = 0;
double pointilise = 0;
//this is only nessesary because i am a shit programmer in my next project i am gonna do things right
void double_vector_to_file(string,vector<double>);
void ull_vector_to_file(string,vector<unsigned long long>);
bool is_number(string,unsigned long long&);
string replace_keywords(string);
class junc_opt{
public:
string path;
unsigned long long unite = 0;
vector<double> data_floating;
vector<unsigned long long> data_integer;
static vector<unsigned long long> unite_vals_all;
static vector<unsigned long long> unite_vals_loop;
//static vector<vector<junc_opt*>*> unite_val_settings_all;
//static vector<vector<junc_opt*>*> unite_val_settings_loop;
junc_opt(vector<string> w, string default_path, bool& successful){
path = default_path;
if (w.size() == 3){
if(is_number(w[1],unite)){
path = w[2];
}
else if (is_number(w[2],unite)){
path = w[1];
}
else{ cout << w[0] << " arguments could not be interpretetd as a number and a path" << endl; successful = false;}
}
else if (w.size() == 2){
if(!is_number(w[1],unite)){
path = w[1];
}
}
}
void save_data(){
if(data_integer.size() == 0){
double_vector_to_file(replace_keywords(path),data_floating);
}
else {
ull_vector_to_file(replace_keywords(path),data_integer);
}
}
};
vector<unsigned long long> junc_opt::unite_vals_all;
vector<unsigned long long> junc_opt::unite_vals_loop;
void arrange_unite_vals(vector<junc_opt*> junc_opts, vector<unsigned long long>& unite_vals){
for (auto it = junc_opts.begin(); it != junc_opts.end(); ++it){
bool unite_val_exists = false;
for (unsigned long long i = 0;(!unite_val_exists) && (i < unite_vals.size()); ++i){
if ((*it)->unite == unite_vals[i]){
//unite_val_settings[i]->push_back((*it));
unite_val_exists = true;
}
}
if (!unite_val_exists){
//unite_val_settings.push_back(new vector<junc_opt*>);
unite_vals.push_back((*it)->unite);
//unite_val_settings.back()->push_back(*it);
}
}
}
void arrange_unite_vals_all(vector<junc_opt*> junc_opts){
arrange_unite_vals(junc_opts, junc_opt::unite_vals_all);
}
void arrange_unite_vals_loop(vector<junc_opt*> junc_opts){
arrange_unite_vals(junc_opts, junc_opt::unite_vals_loop);
}
void save_junc_data(vector<junc_opt*> vec){
for (auto it = vec.begin(); it != vec.end(); ++it){
(*it)->save_data();
}
}
vector<junc_opt*> junc_dist_all;
vector<junc_opt*> junc_dist_loop;
vector<junc_opt*> junc_conn_all;
vector<junc_opt*> junc_conn_loop;
//string junc_dist_all_path = "";
//string junc_dist_loop_path = "";
//string junc_conn_all_path = "";
//string junc_conn_loop_path = "";
string aux_data_path = "";
string scale_unit = "";
string tracing_data_path = "";
string loop_data_path = "";
string animation_path = "";
Scalar animation_color = Scalar(0,0,255);
double animation_thickness = 1.0;
vector<string> split_string_exclude(string s, string t){
vector<string> res;
long long spacepos = 0;
while((spacepos = s.find_first_of(t)) != -1){
if (spacepos != 0){
res.push_back(s.substr(0,spacepos));
}
s = s.substr(spacepos + 1);
}
if (s != ""){
res.push_back(s);
}
return res;
}
vector<string> scale_params(vector<string> w, bool& successful, bool& scaled){
vector<string> res;
for (unsigned long long i = 0; i < w.size() && successful; ++i){
if (w[i] != scale_unit){
res.push_back(w[i]);
}
else if (i >= 2) {
try{
res.back() = to_string(stod(res.back())/scaling_factor);
}
catch(const std::invalid_argument& ia){
cout << "when trying to convert: \"" << w[i-1] << "\" from " << scale_unit << " to pixel, it could not be interpreted as a number" << endl;
successful = false;
}
if (successful) {
cout << w[i-1] << " " << w[i] << " was converted to " << res.back() << " pixel" << endl;
scaled = true;
}
}
}
return res;
}
bool split_path(string full_path, string& folder, string& file, string& ending){
bool directory = false;
long long lastslash = full_path.find_last_of("/");
long long lastdot = full_path.find_last_of(".");
if (lastslash == full_path.length() - 1){
folder = full_path;
directory = true;
}
else if (lastdot < lastslash && lastdot != -1){
folder = full_path.substr(0,lastslash + 1);
file = full_path.substr(lastslash + 1);
}
else if(lastdot != -1){
//cout << "folder: " + full_path.substr(0,lastslash + 1) + "\nfile: " + full_path.substr(lastslash + 1,lastdot) + "\nending: " << full_path.substr(lastdot) << endl;
folder = full_path.substr(0,lastslash + 1);
file = full_path.substr(lastslash + 1,lastdot - lastslash - 1);
ending = full_path.substr(lastdot);
//cout << "folder: " + full_path.substr(0,lastslash + 1) + "\nfile: " +file + " " + full_path.substr(lastslash + 1,lastslash + 3) << endl;
//cout << "ending: " << full_path.substr(lastdot,-1) << endl;
}
else {
folder = full_path.substr(0,lastslash + 1);
file = full_path.substr(lastslash + 1,lastdot);
//cout << "folder: " + full_path.substr(0,lastslash + 1) + "\nfile: " + full_path.substr(lastslash + 1) << endl;
//cout << "no dot" << endl;
}
return (!directory);
}
/*
int main(){
vector<string> test = split_string_exclude(" zhis is a test masafaka"," ");
for(unsigned long long i = 0; i < test.size(); ++i){
cout << ":" << test[i] << ":" << endl;
}
}
*/
bool is_number(string s,double& n){
try{
n = stod(s);
return true;
}
catch(const std::invalid_argument& ia){
return false;
}
}
bool is_number(string s,long long& n){
try{
n = stoll(s);
return true;
}
catch(const std::invalid_argument& ia){
return false;
}
}
bool is_number(string s,unsigned long long& n){
try{
n = stoull(s);
return true;
}
catch(const std::invalid_argument& ia){
return false;
}
}
bool is_number(string s){
try{
stod(s);
return true;
}
catch(const std::invalid_argument& ia){
return false;
}
}
//bool interprete_save(vecotr<string> w){ //I know that in unix world we use the word "write" instead of "save", but this programm might be used by windows users therefore i use "save" as a keyword.
//
//}
//draw network 255 0 0 2 only_loops 0 0 255 1 original name .png
bool interprete_draw(vector<string> w){
bool successful = true;
unsigned long long l = w.size() - 1;
draw_commands.push_back(new draw_command);
for (unsigned long long i = 1; i <= l && successful; ++i){
if (w[i] == "network"){
if (!(draw_commands.back()->all_nodes)){
draw_commands.back()->all_nodes = true;
if (l >= i + 1 && is_number(w[i+1])){
if (l >= i + 4 && is_number(w[i+2]) && is_number(w[i+3]) && is_number(w[i+4])){
int r = stoi(w[i+1]);
int g = stoi(w[i+2]);
int b = stoi(w[i+3]);
if ( 0 <= r && 0 <= g && 0 <= b && 255 >= r && 255 >= g && 255 >= b){
draw_commands.back()->all_nodes_color = Scalar(b,g,r);
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
draw_commands.back()->all_nodes_thickness = abs(stoi(w[i+4]));
i += 4;
}
else if (l >= i + 3 && is_number(w[i+2]) && is_number(w[i+3])){
int r = stoi(w[i+1]);
int g = stoi(w[i+2]);
int b = stoi(w[i+3]);
if ( 0 <= r && 0 <= g && 0 <= b && 255 >= r && 255 >= g && 255 >= b){
draw_commands.back()->all_nodes_color = Scalar(b,g,r);
i += 3;
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
}
else if (l >= i + 2 && is_number(w[i+2])) {
int c = stoi(w[i+1]);
if ( 0 <= c && 255 >= c){
draw_commands.back()->all_nodes_color = Scalar(c,c,c);
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
draw_commands.back()->all_nodes_thickness = abs(stoi(w[i+2]));
i += 2;
}
else {
int c = stoi(w[i+1]);
if ( 0 <= c && 255 >= c){
draw_commands.back()->all_nodes_color = Scalar(c,c,c);
i += 1;
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
}
}
else if (l >= i + 1 && w[i+1] == "angle_hue"){
draw_commands.back()->all_nodes_hue = true;
i += 1;
if (l >= i + 1 && is_number(w[i+1],draw_commands.back()->all_nodes_thickness)){
i += 1;
PRINT(i)
}
}
}
else {
cout << "ERROR: the way all node connections are supposed to be drawn was already specified" << endl;
successful = false;
}
}
else if (w[i] == "only_loops"){
if(!(draw_commands.back()->only_loops)){
draw_commands.back()->only_loops = true;
if (l >= i + 1 && is_number(w[i+1])){
if (l >= i + 4 && is_number(w[i+2]) && is_number(w[i+3]) && is_number(w[i+4])){
int r = stoi(w[i+1]);
int g = stoi(w[i+2]);
int b = stoi(w[i+3]);
if ( 0 <= r && 0 <= g && 0 <= b && 255 >= r && 255 >= g && 255 >= b){
draw_commands.back()->only_loops_color = Scalar(b,g,r);
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
draw_commands.back()->only_loops_thickness = abs(stoi(w[i+4]));
i += 4;
}
else if (l >= i + 3 && is_number(w[i+2]) && is_number(w[i+3])){
int r = stoi(w[i+1]);
int g = stoi(w[i+2]);
int b = stoi(w[i+3]);
if ( 0 <= r && 0 <= g && 0 <= b && 255 >= r && 255 >= g && 255 >= b){
draw_commands.back()->only_loops_color = Scalar(b,g,r);
i += 3;
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
}
else if (l >= i + 2 && is_number(w[i+2])) {
int c = stoi(w[i+1]);
if ( 0 <= c && 255 >= c){
draw_commands.back()->only_loops_color = Scalar(c,c,c);
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
draw_commands.back()->only_loops_thickness = abs(stoi(w[i+2]));
i += 2;
}
else {
int c = stoi(w[i+1]);
if ( 0 <= c && 255 >= c){
draw_commands.back()->only_loops_color = Scalar(c,c,c);
i += 1;
}
else {
cout << "ERROR: color values have to be between 0 and 255" << endl;
successful = false;
}
}
}
else if (l >= i + 1 && w[i+1] == "angle_hue"){
draw_commands.back()->only_loops_hue = true;
++i;
if (l >= i + 1 && is_number(w[i+1],draw_commands.back()->only_loops_thickness)){
++i;
}
}
}
else{
cout << "ERROR: the way the node connections involved in closed loops are supposed to be drawn was already specified" << endl;
successful = false;
}
}
else if (w[i] == "original" || w[i] == "cropped" || w[i] == "tubeness" || w[i] == "hessian" || w[i] == "visualized_hessian" || w[i] == "white" || w[i] == "black"){
if (!(draw_commands.back()->background_specified)){
if (w[i] != "original"){
draw_commands.back()->cropped = true;
}
draw_commands.back()->background = w[i];
}
else {
cout << "ERROR: image to be drawn on was alreadey specified" << endl;
successful = false;
}
}
else if (w[i] == "name"){
if(!(draw_commands.back()->name_specified)){
++i;
draw_commands.back()->name_specified = true;
split_path(w[i], draw_commands.back()->folder, draw_commands.back()->name, draw_commands.back()->ending);
if (draw_commands.back()->ending != "" ){
if (draw_commands.back()->ending == ".bmp" || draw_commands.back()->ending == ".bmp" || draw_commands.back()->ending == ".jpeg" || draw_commands.back()->ending == ".jpg" || draw_commands.back()->ending == ".jpe" || draw_commands.back()->ending == ".jp2" || draw_commands.back()->ending == ".png" || draw_commands.back()->ending == ".pbm" || draw_commands.back()->ending == ".pgm" || draw_commands.back()->ending == ".ppm" || draw_commands.back()->ending == ".sr" || draw_commands.back()->ending == ".ras" || draw_commands.back()->ending == ".tiff" || draw_commands.back()->ending == ".tif" ){
}
else{
cout << "ERROR: file ending:\"" << draw_commands.back()->ending << "\" not supported. Supporded endings are: .bmp, .bmp, jpeg, .jpg, .jpe, .jp2, .png, .pbm, .pgm, .ppm, .sr, .ras, .tiff and .tif" << endl;
successful = false;
}
}
}
else {
cout << "ERROR: name of the image to be saved was already specified" << endl;
successful = false;
}
}
else {
successful = false;
cout << "ERROR: Argument:\"" << w[i] << "\" of drawing command could not be interpreted" << endl;
}
}
return successful;
}
bool read_settings_line(string l){
bool successful = true;
vector<string> w = split_string_exclude(l," "); // w for words (i know i can't code)
if (w.size() != 0){
cout << endl << "Interpreting: \""+ l + "\"" << endl;
bool scaled = false;
if (scale_unit != ""){
w = scale_params(w, successful, scaled);
}
if (w[0] == "threads"){
if (!THREADS_set){
if (w.size() == 2){
try{
THREADS = abs(stoi(w[1]));
cout << THREADS << " threads will be used for the computation" << endl;
}
catch( const std::invalid_argument& ia){
cout << "ERROR: value intended for the number of threads: \"" << w[1] << " could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: To many input arguments for threads. It expects 1 argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else {
cout << "ERROR: number of threads was already set" << endl;
successful = false;
}
}
else if (w[0] == "sigma_conv"){
if (!SG_set && successful){
if (w.size() == 2){
try{
SG = abs(stod(w[1]));
cout << "sigma_conv set to: " << SG << " pixel" << endl;
SG_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for sigma_conv: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for sigma_conv, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: sigma_conv was already set to: " << SG << " pixel" << endl;
successful = false;
}
}
else if (w[0] == "r_min"){
if (!RM_set){
if (w.size() == 2){
try{
RM = abs(stod(w[1]));
cout << "r_min set to: " << RM << " pixel" << endl;
RM_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for r_min: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for r_min, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: r_min was already set to: " << RM << " pixel" << endl;
successful = false;
}
}
else if (w[0] == "r_max"){
if (!RV_set){
if (w.size() == 2){
try{
RV = abs(stod(w[1]));
cout << "r_max set to: " << RV << " pixel" << endl;
RV_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for r_max: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for r_max, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: r_max was already set to: " << RV << " pixel" << endl;
successful = false;
}
}
else if (w[0] == "sigma_smooth"){
if (scaled) {
successful = false;
cout << "sigma_smooth has the unit radians and is scale invariat, trying to scale it with the image is senseless" << endl;
}
else if (!DEV_set){
if (w.size() == 2){
try{
DEV = abs(stod(w[1]));
cout << "sigma_smooth set to: " << DEV << " radians" << endl;
DEV_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for sigma_smooth: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for sigma_smooth, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: sigma_smooth was already set to: " << DEV << " radians" << endl;
successful = false;
}
}
else if (w[0] == "steps"){
if (scaled) {
successful = false;
cout << "steps has no unit and is scale invariat, trying to scale it with the image is senseless" << endl;
}
else if (!STEPS_set && successful){
if (w.size() == 2){
try{
STEPS = abs(stoi(w[1]));
cout << "steps set to: " << STEPS << endl;
STEPS_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for steps: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for steps, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: steps was already set to: " << STEPS << endl;
successful = false;
}
}
else if (w[0] == "thresh"){
if (scaled) {
successful = false;
cout << "thresh is specified in arbitrary units and is scale invariat, trying to scale it with the image is senseless" << endl;
}
if (!TH_set && successful){
if (w.size() == 2){
try{
TH = stod(w[1]);
cout << "thresh set to: " << TH << endl;
TH_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for thresh: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for thresh, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else if (!scaled){
cout << "ERROR: thresh was already set to: " << TH << endl;
successful = false;
}
}
else if (w[0] == "r_step"){
if (!RS_set){
if (w.size() == 2){
try{
RS = abs(stod(w[1]));
cout << "r_step set to: " << RS << " pixel" << endl;
RS_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for r_step: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for r_step, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: r_step was already set to: " << RS << " pixel" << endl;
successful = false;
}
}
else if (w[0] == "min_loop_length"){
if (scaled) {
successful = false;
cout << "thresh is specified in arbitrary units and is scale invariat, trying to scale it with the image is senseless" << endl;
}
else if (!ML_set){
if (w.size() == 2){
try{
ML = abs(stoi(w[1]));
cout << "min_loop_length set to: " << ML << endl;
ML_set = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: value intended for min_loop_length: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for min_loop_length, it requires 1 input argument instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: min_loop_length was already set to: " << ML << endl;
successful = false;
}
}
else if (w[0] == "crop"){
if (!cropped){
if (w.size() == 5){
try{
crop_x1 = abs(stoi(w[1]));
crop_y1 = abs(stoi(w[2]));
crop_x2 = abs(stoi(w[3]));
crop_y2 = abs(stoi(w[4]));
cout << "The two corners of the cropping rectangle are set to: (x,y) = (" << crop_x1 << "," << crop_y1 << ") and (" << crop_x2 << "," << crop_y2 << ") pixel" << endl;
cropped = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: At least one of the values intended for cropping: \"" << w[1] << " " << w[2] << " " << w[3] << " " << w[4] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for crop, crop requires 4 input arguments instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: min_loop_length was already set to: " << ML << endl;
successful = false;
}
}
else if (w[0] == "startpoint"){
if (w.size() == 3){
try{
man_start_points.push_back(new Point(abs(stoi(w[1])),abs(stoi(w[2]))));
cout << "Start point added at: (x,y) = (" << man_start_points.back()->x << "," << man_start_points.back()->y << ")" << endl;
start_points_exist = true;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: At least one of the values intended as coordinates for a start point: \"" << w[1] << " " << w[2] << w[4] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else {
cout << "ERROR: wrong number of input arguments for startpoint, it requires 2 input arguments instead of " << w.size() - 1 << endl;
successful = false;
}
}
else if (w[0] == "auto_startpoint"){
if (!auto_start_points){
if (w.size() == 4){
try{
auto_start_points = true;
n_startpoints = abs(stoi(w[1]));
rad_startpoints = abs(stoi(w[2]));
rad_startpoints_specified = true;
thresh_startpoints = stoi(w[3]);
cout << "Startpoints will be generated automatically.\nThe maximum number of generated start points is set to:" << n_startpoints << "\n The minimum distance between generated startpoints is set to:" << rad_startpoints << " pixel" << "\n The threshold for startpoints is set to:" << thresh_startpoints << endl;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: At least one of the arguments intended for the automated start point generation: \"" << w[1] << " " << w[2] << " " << w[3] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else if (w.size() == 3){
try{
auto_start_points = true;
n_startpoints = abs(stoi(w[1]));
rad_startpoints = abs(stoi(w[2]));
rad_startpoints_specified = true;
cout << "Startpoints will be generated automatically.\nThe maximum number of generated start points is set to:" << n_startpoints << "\n The minimum distance between generated startpoints is set to:" << rad_startpoints << " pixel" << endl;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: At least one of the arguments intended for the automated start point generation: \"" << w[1] << " " << w[2] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else if (w.size() == 2){
try{
auto_start_points = true;
n_startpoints = abs(stoi(w[1]));
cout << "Startpoints will be generated automatically.\nThe maximum number of generated start points is set to:" << n_startpoints << endl;
}
catch(const std::invalid_argument& ia){
cout << "ERROR: At least one of the arguments intended for the automated start point generation: \"" << w[1] << "\" could not be interpreted as a number" << endl;
successful = false;
}
}
else if (w.size() == 1){
auto_start_points = true;
cout << "Startpoints will be generated automatically" << endl;
}
else {
cout << "ERROR: wrong number of input arguments for auto_startpoint, it requires 0 to 3 input arguments instead of " << w.size() - 1 << endl;
successful = false;
}
}
else{
cout << "ERROR: Automated start point generation was already activated" << endl;
successful = false;
}
}
//draw network 255 0 0 only_loops 0 0 255 original .png
else if (w[0] == "draw"){