-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflector.cpp
1542 lines (1361 loc) · 48 KB
/
reflector.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
#include "reflector.h"
//======================================================================
reflector::reflector(ueye_camera *new_pointer_to_reflector_camera){
verbosity = true;
//mirror_list
initialize_mirror_list();
// reflector configuration text file
file_name_extension_for_configuration_file = ".cfg";
key_list_of_mirrors ="mirrors";
key_reflector ="reflector";
key_reflector_name ="reflector_name";
key_reflector_calibration_image ="calibration_image";
key_tripod_radius_in_m ="tripod_radius_in_m";
key_pitch_of_bolt_in_m_per_revolution =
"pitch_of_bolt_in_m_per_revolution";
initialize_default_reflector();
menu_name = "reflector manipulation";
reflector_calibration_image.
toggle_verbosity(verbosity);
reflector_calibration_image_with_polygons.
toggle_verbosity(verbosity);
pointer_to_reflector_camera = new_pointer_to_reflector_camera;
show_tripods = false;
}
//======================================================================
void reflector::initialize_default_reflector(){
pointer_to_current_mirror_to_work_with = NULL;
list_of_pointers_to_mirrors.clear();
reflector_name = "default_reflector";
reflector_configuration_file_name = reflector_name;
reflector_configuration_file_name += ".cfg";
name_of_calibration_image = "";
name_of_calibration_window_with_highlighted_poygons =
"calibration sccan_image with polygons";
tripod_radius_in_m = 0.295;
pitch_of_bolt_in_m_per_revolution = 0.001;
flag_calibration_image_with_polygons_created = false;
}
//======================================================================
void reflector::interaction(){
std::string key_manipulate_mirror = "m";
add_control(key_manipulate_mirror,"manipulate current mirror ID");
std::string key_choose_mirror_ID = "c";
add_control(key_choose_mirror_ID,"choose mirror ID to manipulate");
std::string key_release_mirror_ID = "r";
add_control(key_release_mirror_ID,"release mirror ID to manipulate");
std::string key_show_calibration_image = "s";
add_control(key_show_calibration_image,
"show calibration sccan_image");
std::string key_show_calibration_image_with_polygons = "sp";
add_control(key_show_calibration_image_with_polygons,
"show calibration image with mirror polygons");
std::string key_toggle_tripods_in_images = "tt";
add_control(key_toggle_tripods_in_images,
"toggle tripods");
std::string key_check_polygon_position_in_live_reflector_display = "cp";
add_control(key_check_polygon_position_in_live_reflector_display,
"check polygon position in live reflector display");
std::string key_calibration_image = "i";
add_control(key_calibration_image,"choose calibration sccan_image");
std::string key_change_name = "name";
add_control(key_change_name,"change reflector name");
std::string key_show_mirror_status = "ms";
add_control(key_show_mirror_status,"show mirror status");
std::string key_delete_current_mirror = "delete";
add_control(key_delete_current_mirror,"delete current mirror ID");
std::string key_save_reflector = "save";
add_control(key_save_reflector,"save reflector setup to file");
std::string key_load_reflector = "load";
add_control(key_load_reflector,"load reflector setup from file");
std::string key_quit = "back";
add_control(key_quit,"back to main menu");
std::stringstream out;
bool user_wants_to_quit_mirror_manipulation = false;
do{
//==============================================================
// prompt snapshot options to command line
//==============================================================
update_status_prompt(get_reflector_prompt());
//==============================================================
// get input of user via command line
//==============================================================
get_user_input();
//==============================================================
// interpret answer of user
//==============================================================
//std::cout<<"valid_user_input: "<<valid_user_input<<std::endl;
//==================================================================
if(valid_user_input.compare(key_load_reflector)==0){
if(read_configuration(get_alphanumeric_string_by_user())){
std::cout<<"reflector -> interaction() ->";
std::cout<<" loading reflector successful."<<std::endl;
}else{
std::cout<<"reflector -> interaction() ->";
std::cout<<" loading reflector failed."<<std::endl;
}
}
//==================================================================
if(valid_user_input.compare(key_show_calibration_image)==0){
reflector_calibration_image.disp_image();
}
//==================================================================
if(valid_user_input.compare(
key_show_calibration_image_with_polygons)==0){
update_calibration_image_with_polygons(false);
reflector_calibration_image_with_polygons.disp_image();
}
//==================================================================
if(valid_user_input.compare(key_toggle_tripods_in_images)==0){
show_tripods = !show_tripods;
}
//==================================================================
if(valid_user_input.compare(
key_check_polygon_position_in_live_reflector_display)==0){
double exposure_time_for_reflector_in_ms =
ask_user_for_non_zero_float(
"exposure time on reflector",0.1,180e3);
check_mirror_polygon_position_in_live_reflector_display(
exposure_time_for_reflector_in_ms);
}
//==================================================================
if(valid_user_input.compare(key_calibration_image)==0){
set_reflector_calibration_image
(get_alphanumeric_string_by_user());
}
//==================================================================
if(valid_user_input.compare(key_change_name)==0){
set_reflector_name(get_alphanumeric_string_by_user());
}
//==================================================================
if(valid_user_input.compare(key_save_reflector)==0){
write_configuration_to_disk();
save_calibration_image_with_mirror_polygons();
}
//==================================================================
if(valid_user_input.compare(key_manipulate_mirror)==0){
if(pointer_to_current_mirror_to_work_with==NULL){
std::cout<<"reflector -> interaction() -> [";
std::cout<<key_manipulate_mirror<<"] manipulate_mirror ";
std::cout<<"but mirror ID is not defined yet!"<<std::endl;
}else{
if(reflector_calibration_image.get_init_status()){
manipulate_mirror_polygon();
}else{
std::cout<<"reflector -> interaction() -> [";
std::cout<<key_manipulate_mirror<<"] manipulate_mirror but ";
std::cout<<"reflector calibration image is not defined yet!";
std::cout<<std::endl;
}
}
}
//==================================================================
if(valid_user_input.compare(key_delete_current_mirror)==0){
// delete current mirror from list
if(pointer_to_current_mirror_to_work_with == NULL){
std::cout << "reflector -> interaction -> delete mirror ->";
std::cout << " no current mirror ID to delete!\n";
}else{
pop_mirror
(pointer_to_current_mirror_to_work_with->get_mirror_ID());
}
}
//==================================================================
if(valid_user_input.compare(key_choose_mirror_ID)==0){
uint user_chosen_mirror_ID;
user_chosen_mirror_ID =
(uint)ask_user_for_integer("Enter mirror ID",0,1E6);
if(choose_mirror_ID_to_work_with(user_chosen_mirror_ID)){
// the mirror does exist already
}else{
// the mirror does not exist yet and is therefore created
add_mirror(user_chosen_mirror_ID);
choose_mirror_ID_to_work_with(user_chosen_mirror_ID);
}
}
//==================================================================
if(valid_user_input.compare(key_release_mirror_ID)==0){
pointer_to_current_mirror_to_work_with = NULL;
}
//==================================================================
if(valid_user_input.compare(key_quit)==0){
//==========================================================
// chose to quit mirror manipulation
//==========================================================
user_wants_to_quit_mirror_manipulation = true;
}
//==================================================================
if(valid_user_input.compare(key_show_mirror_status)==0){
//==========================================================
// show mirror status
//==========================================================
show_mirror_status();
}
//==================================================================
update_status_prompt(get_reflector_prompt());
}while(user_wants_to_quit_mirror_manipulation == false);
}
//======================================================================
void reflector::set_reflector_name(std::string new_reflector_name){
reflector_name = new_reflector_name;
reflector_configuration_file_name = new_reflector_name;
reflector_configuration_file_name += ".cfg";
}
//======================================================================
bool reflector::set_reflector_calibration_image(std::string image_file_name){
if(reflector_calibration_image.load_image(image_file_name)){
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"set_reflector_calibration_image() -> ";
std::cout<<"successful: ";
std::cout<<reflector_calibration_image.get_file_name()<<std::endl;
}
name_of_calibration_image = image_file_name;
reflector_calibration_image_with_polygons =
reflector_calibration_image;
return true;
}else{
name_of_calibration_image = "failed to load image!";
reflector_calibration_image_with_polygons.image_initialized =
reflector_calibration_image.image_initialized;
std::cout<<"reflector -> ";
std::cout<<"set_reflector_calibration_image() -> ";
std::cout<<"failed to load: ";
std::cout<<image_file_name<<std::endl;
return false;
}
}
//======================================================================
void reflector::disp_status(){
std::cout<<get_reflector_prompt();
}
//======================================================================
bool reflector::read_configuration(
std::string file_name_of_reflector_configuration_to_load){
libconfig::Config reflector_configuration_handle;
//==================================================================
// Read the file. If there is an error, report it and exit.
//==================================================================
file_name_of_reflector_configuration_to_load +=
file_name_extension_for_configuration_file;
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<file_name_of_reflector_configuration_to_load<<std::endl;
try
{
reflector_configuration_handle.
readFile(file_name_of_reflector_configuration_to_load.c_str());
}
catch(const libconfig::FileIOException &fioex)
{
std::cout << "I/O error while reading file." << std::endl;
return(EXIT_FAILURE);
}
catch(const libconfig::ParseException &pex)
{
std::cout << "Parse error at " << pex.getFile() << ":";
std::cout << pex.getLine() << " - " << pex.getError() << std::endl;
return(EXIT_FAILURE);
}
//==================================================================
// get data
//==================================================================
const libconfig::Setting& root = reflector_configuration_handle.getRoot();
bool reading_is_valid = true;
// Output a list of all books in the inventory.
try
{
const libconfig::Setting &Reflector = root[key_reflector];
const libconfig::Setting &Mirrors = Reflector[key_list_of_mirrors];
int number_of_mirrors_in_file = Mirrors.getLength();
if(verbosity){
std::cout<<"reflector -> read_configuration() -> There are ";
std::cout<<number_of_mirrors_in_file;
std::cout<<" mirror(s) to be loaded."<<std::endl;
}
// delete all old reflector information
initialize_default_reflector();
//read in new information
//==================================================================
std::string new_reflector_name;
if( Reflector.lookupValue(key_reflector_name, new_reflector_name) ){
set_reflector_name(new_reflector_name);
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_reflector_name<<" is set to "<<reflector_name<<std::endl;
}else{
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_reflector_name<<" fail."<<std::endl;
reading_is_valid = false;
}
//==================================================================
if( Reflector.lookupValue
(key_reflector_calibration_image, name_of_calibration_image) ){
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_reflector_calibration_image<<" is set to ";
std::cout<<name_of_calibration_image<<std::endl;
if(set_reflector_calibration_image(name_of_calibration_image)){
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_reflector_calibration_image;
std::cout<<" loading complete."<<std::endl;
}else{
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_reflector_calibration_image;
std::cout<<" failed to load sccan_image."<<std::endl;
reading_is_valid = false;
}
}else{
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_reflector_calibration_image<<" fail."<<std::endl;
reading_is_valid = false;
}
//==================================================================
double new_tripod_radius_in_m;
if( Reflector.lookupValue
(key_tripod_radius_in_m, new_tripod_radius_in_m) ){
tripod_radius_in_m = new_tripod_radius_in_m;
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_tripod_radius_in_m<<" set to ";
std::cout<<tripod_radius_in_m<<std::endl;
}else{
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_tripod_radius_in_m<<" fail."<<std::endl;
reading_is_valid = false;
}
//==================================================================
double new_pitch_of_bolt_in_m_per_revolution;
if( Reflector.lookupValue
(key_pitch_of_bolt_in_m_per_revolution,
new_pitch_of_bolt_in_m_per_revolution) ){
pitch_of_bolt_in_m_per_revolution =
new_pitch_of_bolt_in_m_per_revolution;
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_pitch_of_bolt_in_m_per_revolution<<" set to ";
std::cout<<pitch_of_bolt_in_m_per_revolution<<std::endl;
}else{
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<key_pitch_of_bolt_in_m_per_revolution<<" fail."<<std::endl;
reading_is_valid = false;
}
//==================================================================
for(
int mirror_itterator = 0;
mirror_itterator<number_of_mirrors_in_file;
mirror_itterator++){
libconfig::Setting &Mirror_file_handle = Mirrors[mirror_itterator];
mirror *pointer_to_a_new_mirror_read_form_file;
pointer_to_a_new_mirror_read_form_file =
new mirror(0,verbosity);
if(pointer_to_a_new_mirror_read_form_file->
import_configuration(&Mirror_file_handle))
{
if(verbosity){
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<"mirror "<<(mirror_itterator+1)<<" of ";
std::cout<<number_of_mirrors_in_file;
std::cout<<" has been loaded successful."<<std::endl;
}
//==========================================================
// init mirror with reflector data
//==========================================================
pointer_to_a_new_mirror_read_form_file -> set_mirror_tripod(
tripod_radius_in_m,pitch_of_bolt_in_m_per_revolution);
//==========================================================
// update mirror masks
//==========================================================
pointer_to_a_new_mirror_read_form_file->
initialize_list_of_points_inside_mirror_polygon(
reflector_calibration_image_with_polygons.image_matrix.
size());
list_of_pointers_to_mirrors.
push_back(pointer_to_a_new_mirror_read_form_file);
}else{
reading_is_valid = false;
std::cout<<"reflector -> read_configuration() -> ";
std::cout<<"mirror "<<(mirror_itterator+1)<<" of ";
std::cout<<number_of_mirrors_in_file;
std::cout<<" failed to load from file!"<<std::endl;
}
}
}
catch(const libconfig::SettingNotFoundException &nfex)
{
std::cout<<"reflector -> read_configuration() ->";
std::cout<<"loading failed! Settings not found!"<<std::endl;
reading_is_valid = false;
}
return reading_is_valid;
}
//======================================================================
bool reflector::write_configuration_to_disk(){
libconfig::Config reflector_configuration_handle;
libconfig::Setting &root = reflector_configuration_handle.getRoot();
// add reflector
if(! root.exists(key_reflector))
root.add(key_reflector, libconfig::Setting::TypeGroup);
libconfig::Setting &Reflector = root[key_reflector];
Reflector.add(key_reflector_name,libconfig::Setting::TypeString)=
reflector_name;
Reflector.add
(key_reflector_calibration_image, libconfig::Setting::TypeString) =
name_of_calibration_image;
Reflector.add(key_tripod_radius_in_m, libconfig::Setting::TypeFloat) =
tripod_radius_in_m;
Reflector.add
(key_pitch_of_bolt_in_m_per_revolution, libconfig::Setting::TypeFloat) =
pitch_of_bolt_in_m_per_revolution;
// add mirrors
if(! Reflector.exists(key_list_of_mirrors))
Reflector.add(key_list_of_mirrors, libconfig::Setting::TypeList);
libconfig::Setting &Mirrors = Reflector[key_list_of_mirrors];
for(int mirror_itterator = 0;
mirror_itterator<list_of_pointers_to_mirrors.size();
mirror_itterator++)
{
// Create the new mirror entry.
libconfig::Setting &Mirror = Mirrors.add(libconfig::Setting::TypeGroup);
list_of_pointers_to_mirrors.
at(mirror_itterator)->export_configuration_setting(&Mirror);
}
// Write out the new configuration.
try
{
reflector_configuration_handle.
writeFile(reflector_configuration_file_name.c_str());
std::cout << "reflector -> ";
std::cout << "write_configuration_to_disk() -> ";
std::cout << "successfull: ";
std::cout << reflector_configuration_file_name << std::endl;
}
catch(const libconfig::FileIOException &fioex)
{
std::cout << "reflector -> ";
std::cout << "write_configuration_to_disk() -> ";
std::cerr << "I/O error while writing file: " ;
std::cerr << reflector_configuration_file_name << std::endl;
return(false);
}
return(true);
}
//======================================================================
bool reflector::save_calibration_image_with_mirror_polygons(){
std::string calibration_image_with_polygons_filename =
reflector_name+"_mirror_polygons.png";
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"save_calibration_image_with_mirror_polygons() -> ";
std::cout<<calibration_image_with_polygons_filename;
}
update_calibration_image_with_polygons(false);
reflector_calibration_image_with_polygons.save_simple_image(
calibration_image_with_polygons_filename);
if(verbosity){
std::cout<<" has been saved"<<std::endl;
}
}
//======================================================================
std::string reflector::get_reflector_prompt(){
std::stringstream out, info;
out<<"|"<<std::endl;
// reflector name
info.str("");
info<<reflector_name;
out<<make_nice_line_with_dots("| reflector name",info.str());
// number of mirrors
info.str("");
info<<list_of_pointers_to_mirrors.size();
out<<make_nice_line_with_dots("| number of mirrors",info.str());
// list of mirrors
info.str("");
if(list_of_pointers_to_mirrors.size()>0){
for(
int mirror_itterator=0;
mirror_itterator<list_of_pointers_to_mirrors.size();
mirror_itterator++)
{
info<<list_of_pointers_to_mirrors.at(mirror_itterator)->
get_mirror_ID()<<", ";
}
}else{
info<<"no mirrors on reflector";
}
out<<make_nice_line_with_dots("| mirror IDs:",info.str());
// current mirror ID to work with
info.str("");
if(pointer_to_current_mirror_to_work_with==NULL){
info<<"has not been set yet";
}else{
info<<pointer_to_current_mirror_to_work_with->
get_mirror_ID();
}
out<<make_nice_line_with_dots
("| current mirror ID to work with",info.str());
out<<"|"<<std::endl;
// reflector calibration sccan_image
info.str("");
if(reflector_calibration_image.get_init_status()){
info<<name_of_calibration_image;
}else{
info<<"has not been set yet";
}
out<<make_nice_line_with_dots
("| reflector calibration sccan_image",info.str());
out<<"|"<<std::endl;
// mirror tripod radius
info.str("");
info<<tripod_radius_in_m<<"m";
out<<make_nice_line_with_dots("| mirror tripod radius",info.str());
// pitch of mirror bolts
info.str("");
info<<pitch_of_bolt_in_m_per_revolution<<"m/revolution";
out<<make_nice_line_with_dots("| pitch of mirror bolts",info.str());
// toggle tripod displaying
info.str("");
if(show_tripods){info<<"TRUE";}else{info<<"FALSE";}
out<<make_nice_line_with_dots("| show tripods",info.str());
out<<"|";
out<<get_line_of_specific_character("_",command_line_columns-1);
out<<std::endl;
return out.str();
}
//======================================================================
std::string reflector::get_reflector_name(){
return reflector_name;
}
//======================================================================
// mirror polygon manipulation
//======================================================================
void reflector::update_calibration_image_with_polygons(bool highlight){
reflector_calibration_image_with_polygons=
reflector_calibration_image;
update_image_with_polygons(
&reflector_calibration_image_with_polygons,
highlight);
}
//======================================================================
void reflector::update_image_with_polygons(
sccan_image *image_to_draw_poygons_in,bool highlight){
if(verbosity){
std::stringstream out;
out<<"reflector -> ";
out<<"update_image_with_polygons -> ";
out<<"highlighting ";
if(highlight){out<<"TRUE";}else{out<<"FALSE";}
}
uint mirror_ID_of_mirror_to_highlight;
if(pointer_to_current_mirror_to_work_with == 0){
mirror_ID_of_mirror_to_highlight = 0;
}else{
mirror_ID_of_mirror_to_highlight =
pointer_to_current_mirror_to_work_with->get_mirror_ID();
}
if(!highlight)
mirror_ID_of_mirror_to_highlight = 0;
//==================================================================
// for each mirror
//==================================================================
for( int mirror_itterator = 0;
mirror_itterator<list_of_pointers_to_mirrors.size();
mirror_itterator++)
{
bool highlight_specific_mirror = false;
if(highlight &&
pointer_to_current_mirror_to_work_with->
get_mirror_ID()
==
list_of_pointers_to_mirrors.
at(mirror_itterator)->
get_mirror_ID())
highlight_specific_mirror = true;
list_of_pointers_to_mirrors.
at(mirror_itterator)->
draw_mirror_polygon(
image_to_draw_poygons_in,
highlight_specific_mirror);
if(show_tripods){
list_of_pointers_to_mirrors.
at(mirror_itterator)->
draw_mirror_tripod(
image_to_draw_poygons_in,
highlight_specific_mirror);
}
}
flag_calibration_image_with_polygons_created = true;
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"update_calibration_image_with_polygons -> ";
std::cout<<"finished"<<std::endl;
}
}
//======================================================================
/*
void reflector::update_image_with_polygons(
sccan_image *image_to_draw_poygons_in,bool highlight){
uint mirror_ID_of_mirror_to_highlight;
if(pointer_to_current_mirror_to_work_with == 0){
mirror_ID_of_mirror_to_highlight = 0;
}else{
mirror_ID_of_mirror_to_highlight =
pointer_to_current_mirror_to_work_with->get_mirror_ID();
}
if(!highlight)
mirror_ID_of_mirror_to_highlight = 0;
// to normalize zhe lines and text fonts to be drawed the image size
// is taken into account
int number_of_pixels_of_image =
image_to_draw_poygons_in->get_number_of_pixels();
double mean_number_of_image_lines =
sqrt((double)number_of_pixels_of_image);
double line_thickness_per_image_line = 2.0/1e3;
double circle_radius_in_pixel_per_image_line = 5.0/1e3;
double circle_thickness_in_pixel_per_image_line = 2.0/1e3;
double text_thickness_per_image_line = 2/1e3;
// line specific information
int line_thickness = (int)
ceil(line_thickness_per_image_line*mean_number_of_image_lines);
int line_Type = 8;
// mirror ID spcific information
cv::Point location_of_mirror_ID;
int text_thickness = (int)
ceil(text_thickness_per_image_line*mean_number_of_image_lines);
double text_fontScale = 0.75;
int text_fontFace = CV_FONT_HERSHEY_SIMPLEX;
// circle spcific information
double circle_radius_in_pixel =
circle_radius_in_pixel_per_image_line*mean_number_of_image_lines;
int circle_thickness_in_pixel =
(int)ceil(
circle_thickness_in_pixel_per_image_line*mean_number_of_image_lines
);
int circle_lineType =8;
//==================================================================
// for each mirror polygon group
//==================================================================
for( int mirror_itterator = 0;
mirror_itterator<list_of_pointers_to_mirrors.size();
mirror_itterator++)
{
int number_of_points =
list_of_pointers_to_mirrors.at(mirror_itterator)->
list_of_points_defining_mirror_polygon.size();
if(number_of_points==0){
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"update_calibration_image_with_polygons -> ";
std::cout<<"No polygon of mirror ID:";
std::cout<<list_of_pointers_to_mirrors.at(mirror_itterator)->
get_mirror_ID()<<std::endl;
}
}else{
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"update_calibration_image_with_polygons -> ";
std::cout<<"Draw polygon of mirror ID:";
std::cout<<list_of_pointers_to_mirrors.at(mirror_itterator)->
get_mirror_ID()<<std::endl;
}
// reset mirror ID location
location_of_mirror_ID.x=0;
location_of_mirror_ID.y=0;
//==========================================================
// for each line to draw
//==========================================================
for(int point_itterator=0;
point_itterator<number_of_points;
point_itterator++)
{
// init start point of line
cv::Point start_point =
list_of_pointers_to_mirrors.at(mirror_itterator)->
list_of_points_defining_mirror_polygon.
at(point_itterator);
// init end point of line
cv::Point end_point;
if((point_itterator+1) ==
list_of_pointers_to_mirrors.
at(mirror_itterator)->
list_of_points_defining_mirror_polygon.size())
{
end_point =
list_of_pointers_to_mirrors.
at(mirror_itterator)->
list_of_points_defining_mirror_polygon.at(0);
}else{
end_point =
list_of_pointers_to_mirrors.
at(mirror_itterator)->
list_of_points_defining_mirror_polygon.
at(point_itterator+1);
}
// draw line
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"update_calibration_image_with_polygons";
std::cout<<" -> ";
std::cout<<"draw line "<<point_itterator+1;
std::cout<<": ("<<start_point.x<<"|"<<start_point.y;
std::cout<<")->("<<end_point.x;
std::cout<<"|"<<end_point.y<<")"<<std::endl;
}
if( list_of_pointers_to_mirrors.
at(mirror_itterator)->
get_mirror_ID()
==
mirror_ID_of_mirror_to_highlight
)
{
//colour highlighted
//std::cout<<"highlighted !!!"<<std::endl;
cv::line(
image_to_draw_poygons_in->
image_matrix,
start_point,
end_point,
cv::Scalar( 0, 255, 0),//Blue,Green,Red
line_thickness,
line_Type
);
}else{
//colour default
cv::line(
image_to_draw_poygons_in->
image_matrix,
start_point,
end_point,
cv::Scalar( 0, 0, 255),//Blue,Green,Red
line_thickness,
line_Type
);
}
// calculate mirror ID location
location_of_mirror_ID = location_of_mirror_ID +
start_point;
// draw a filled circle
if( list_of_pointers_to_mirrors.
at(mirror_itterator)->get_mirror_ID()
==
mirror_ID_of_mirror_to_highlight
)
{
//colour highlighted
cv::circle(
image_to_draw_poygons_in->
image_matrix,
start_point,
circle_radius_in_pixel,
cv::Scalar( 128, 255, 0 ),
circle_thickness_in_pixel,
circle_lineType );
}else{
//colour default
cv::circle(
image_to_draw_poygons_in->
image_matrix,
start_point,
circle_radius_in_pixel,
cv::Scalar( 128, 0, 255 ),
circle_thickness_in_pixel,
circle_lineType );
}
}
// draw mirror ID
// calculate mirror ID location
location_of_mirror_ID.x =
(location_of_mirror_ID.x)/number_of_points;
location_of_mirror_ID.y =
(location_of_mirror_ID.y)/number_of_points;
//create text ID to display
std::stringstream text_to_put_in_image;
text_to_put_in_image<<"ID";
text_to_put_in_image<<list_of_pointers_to_mirrors.
at(mirror_itterator)->get_mirror_ID();
// put text to sccan_image
if( list_of_pointers_to_mirrors.at(mirror_itterator)->
get_mirror_ID()
==
mirror_ID_of_mirror_to_highlight)
{
//colour highlighted
cv::putText(
image_to_draw_poygons_in->
image_matrix,
text_to_put_in_image.str(),
location_of_mirror_ID,
text_fontFace,// fontFace
text_fontScale,// fontScale
cv::Scalar( 64, 255, 64 ),//Blue,Green,Red
text_thickness,
8
);
}else{
//colour default
//colour highlighted
cv::putText(
image_to_draw_poygons_in->
image_matrix,
text_to_put_in_image.str(),
location_of_mirror_ID,
text_fontFace,// fontFace
text_fontScale,// fontScale
cv::Scalar( 64, 64, 255 ),//Blue,Green,Red
text_thickness,
8
);
}
}
}
flag_calibration_image_with_polygons_created = true;
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"update_calibration_image_with_polygons -> ";
std::cout<<"end"<<std::endl;
}
}*/
//======================================================================
/*
void reflector::update_calibration_image_with_polygons(bool highlight){
reflector_calibration_image_with_polygons=
reflector_calibration_image;
uint mirror_ID_of_mirror_to_highlight;
if(pointer_to_current_mirror_to_work_with == 0){
mirror_ID_of_mirror_to_highlight = 0;
}else{
mirror_ID_of_mirror_to_highlight =
pointer_to_current_mirror_to_work_with->get_mirror_ID();
}
if(!highlight)
mirror_ID_of_mirror_to_highlight = 0;
// to normalize zhe lines and text fonts to be drawed the image size
// is taken into account
int number_of_pixels_of_image =
reflector_calibration_image_with_polygons.get_number_of_pixels();
double mean_number_of_image_lines =
sqrt((double)number_of_pixels_of_image);
double line_thickness_per_image_line = 2.0/1e3;
double circle_radius_in_pixel_per_image_line = 5.0/1e3;
double circle_thickness_in_pixel_per_image_line = 2.0/1e3;
double text_thickness_per_image_line = 2/1e3;
// line specific information
int line_thickness = (int)
ceil(line_thickness_per_image_line*mean_number_of_image_lines);
int line_Type = 8;
// mirror ID spcific information
cv::Point location_of_mirror_ID;
int text_thickness = (int)
ceil(text_thickness_per_image_line*mean_number_of_image_lines);
double text_fontScale = 0.75;
int text_fontFace = CV_FONT_HERSHEY_SIMPLEX;
// circle spcific information
double circle_radius_in_pixel =
circle_radius_in_pixel_per_image_line*mean_number_of_image_lines;
int circle_thickness_in_pixel =
(int)ceil(
circle_thickness_in_pixel_per_image_line*mean_number_of_image_lines
);
int circle_lineType =8;
//==================================================================
// for each mirror polygon group
//==================================================================
for( int mirror_itterator = 0;
mirror_itterator<list_of_pointers_to_mirrors.size();
mirror_itterator++)
{
int number_of_points =
list_of_pointers_to_mirrors.at(mirror_itterator)->
list_of_points_defining_mirror_polygon.size();
if(number_of_points==0){
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"update_calibration_image_with_polygons -> ";
std::cout<<"No polygon of mirror ID:";
std::cout<<list_of_pointers_to_mirrors.at(mirror_itterator)->
get_mirror_ID()<<std::endl;
}
}else{
if(verbosity){
std::cout<<"reflector -> ";
std::cout<<"update_calibration_image_with_polygons -> ";
std::cout<<"Draw polygon of mirror ID:";
std::cout<<list_of_pointers_to_mirrors.at(mirror_itterator)->
get_mirror_ID()<<std::endl;
}