-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmanager_class.cpp
2766 lines (2248 loc) · 90.7 KB
/
manager_class.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
/*-------------------------------------------------------------------
File : manager_class.cpp
Description : Manages the correlation process to be performed either on
the CPU or the GPU. Given a user selected domain, from
MainApp.cpp, selects the individual points to be used on
the correlation. Can also select the bounding contour of
the correlation domain for plotting purposes.
The class inherits from Qt Object, to be able to emit and
receive Qt signals, to communicate with the MainApp GUI.
Author : Javier Gonzalez, 29-October-2017 - 21-May-2018
-----------------------------------------------------------------*/
//----------------------------------------------------------------------
//
// include
//
//----------------------------------------------------------------------
#include "manager_class.h"
//----------------------------------------------------------------------
//
// functors
//
//----------------------------------------------------------------------
// This functor is used to aggregate the deformation points resulting from one
// correlation step with
// correlation parameters into the next set of undeformed points. Next
// undeformed points need to
// be integer values, since the undeformed intensity values are queried
// from the undeformed image
// at the nodal points, without interpolation.
struct add_pair {
add_pair(std::pair<float, float> x_in) : x(x_in) {}
std::pair<float, float> operator()(std::pair<float, float> y) const {
return std::make_pair((int)(x.first + y.first + 0.5f),
(int)(x.second + y.second + 0.5f));
}
private:
std::pair<float, float> x;
};
//----------------------------------------------------------------------
//
// classes
//
//----------------------------------------------------------------------
managerClass::managerClass(QObject *parent) : QObject(parent) {}
managerClass::~managerClass() {
delete[] global_initial_guess;
global_initial_guess = nullptr;
delete[] initial_guess;
initial_guess = nullptr;
}
void managerClass::set_filenames(QStringList *fileNames_in) {
fileNames = fileNames_in;
}
#if CUDA_ENABLED
void managerClass::set_cuda_manager(CudaClass *cuda_manager_in) {
cuda_manager = cuda_manager_in;
}
#endif
bool managerClass::set_domain(rectangularDomainStruct rectangularDomain_in) {
domain_type = domain_rectangular;
rectangularDomain = rectangularDomain_in;
return true;
}
bool managerClass::set_domain(annularDomainStruct annularDomain_in) {
domain_type = domain_annular;
annularDomain = annularDomain_in;
return true;
}
bool managerClass::set_domain(blobDomainStruct blobDomain_in) {
domain_type = domain_blob;
blobDomain = blobDomain_in;
return true;
}
void managerClass::set_color_mode(colorEnum color_mode_in,
int number_of_colors_in) {
color_mode = color_mode_in;
switch (color_mode) {
case color_monochrome:
color_flag = cv::IMREAD_GRAYSCALE;
number_of_colors = 1;
break;
case color_color:
color_flag = cv::IMREAD_ANYCOLOR;
number_of_colors = number_of_colors_in;
break;
default:
assert(false);
break;
}
}
void managerClass::set_update(updateEnum update_in) { update = update_in; }
void managerClass::set_processor(processorEnum processor_in) {
processor = processor_in;
}
void managerClass::set_model(fittingModelEnum model_in) {
model = model_in;
number_of_model_parameters =
ModelClass::get_number_of_model_parameters(model);
}
void managerClass::set_interpolation(interpolationModelEnum interpolation_in) {
interpolation = interpolation_in;
}
void managerClass::set_global_initial_guess(float *global_initial_guess_in) {
delete[] global_initial_guess;
global_initial_guess = nullptr;
delete[] initial_guess;
initial_guess = nullptr;
global_initial_guess = new float[number_of_model_parameters];
initial_guess = new float[number_of_model_parameters];
for (int p = 0; p < number_of_model_parameters; ++p) {
global_initial_guess[p] = global_initial_guess_in[p];
}
}
void managerClass::set_max_iters(int max_iters_in) { max_iters = max_iters_in; }
void managerClass::set_precision(float precision_in) {
precision = precision_in;
}
void managerClass::set_plot_inside_points(bool plot_inside_points_in) {
plot_inside_points = plot_inside_points_in;
}
void managerClass::set_plot_contour_points(bool plot_contour_points_in) {
plot_contour_points = plot_contour_points_in;
}
void managerClass::set_error_handling_mode(
errorHandlingModeEnum error_handling_mode_in) {
error_handling_mode = error_handling_mode_in;
}
void managerClass::set_undeformed_image(std::string und_fileName_in,
int current_frame_order,
referenceImageEnum referenceImage) {
switch (processor) {
case processor_CPU:
if (current_frame_order == 0) {
// Load und image from disk
undeformed_opencvMat = cv::imread(und_fileName_in, color_flag);
// Call the cpu pyramid to make the pyramid
correlator->set_undeformed_image(undeformed_opencvMat);
} else if (referenceImage == refImage_Previous) {
// Call the cpu pyramid to repoint the defPyramid to undPyramid
correlator->set_und_image_from_def();
}
break;
case processor_GPU:
#if CUDA_ENABLED
if (current_frame_order == 0) {
// First undeformed pyramid is already made by the
// mainApp::updateGpuPyramids, which is called
// whenever we 1)load new images or 2)change the pyramid parameters or
// 3)change the color mode
// or 4)are done correlating or 5)change processor type. Via
// cuda_manager::resetImagePyramids
} else if (referenceImage == refImage_Previous) {
// Rename the defPyramid as undPyramid and delete the old undPyramid
cuda_manager->makeUndPyramidFromDef();
}
#endif
break;
default:
assert(false);
break;
}
}
void managerClass::set_deformed_image(std::string def_fileName_in,
int current_frame_order) {
switch (processor) {
case processor_CPU:
if (current_frame_order == 0) {
// Load und image from disk
deformed_opencvMat = cv::imread(def_fileName_in, color_flag);
// Call the cpu pyramid to make the pyramid
correlator->set_deformed_image(deformed_opencvMat);
} else {
// Call the cpu pyramid to repoint the defPyramid to undPyramid
correlator->set_def_image_from_nxt();
}
break;
case processor_GPU:
#if CUDA_ENABLED
if (current_frame_order == 0) {
// First deformed pyramid is already made by the
// mainApp::updateGpuPyramids, which is called
// whenever we 1) load new images or 2)change the pyramid parameters or
// 3)change the color mode
// or 4)are done correlating or 5)change processor type. Via
// cuda_manager::resetImagePyramids
// Temporary code while the cuda pyramids are implemented
// deformed_opencvMat = cv::imread( def_fileName_in, color_flag );
// end of temporary code
} else {
cuda_manager->makeDefPyramidFromNxt();
}
#endif
break;
default:
assert(false);
break;
}
}
bool managerClass::set_next_image(std::string next_fileName_in) {
bool error = true;
switch (processor) {
case processor_CPU:
next_opencvMat = cv::imread(next_fileName_in, color_flag);
correlator->set_next_image(next_opencvMat);
error = next_opencvMat.empty();
break;
case processor_GPU:
#if CUDA_ENABLED
cuda_manager->resetNextPyramid(next_fileName_in);
error = false; // for now
#endif
break;
default:
assert(false);
break;
}
return error;
}
void managerClass::set_referenceImage(referenceImageEnum referenceImage_in) {
referenceImage = referenceImage_in;
}
bool managerClass::perform_single_frame_correlation_rectangular(
int hs, int vs, frame_results *results_in, int current_frame_order) {
int x1 = (int)rectangularDomain.x_end;
int x0 = (int)rectangularDomain.x_begin;
int y1 = (int)rectangularDomain.y_end;
int y0 = (int)rectangularDomain.y_begin;
// Integer size required for correlation constructor
int xdim = (abs(x1 - x0) / hs - 1) / 2;
int ydim = (abs(y1 - y0) / vs - 1) / 2;
// Float set of square dimensions, with float arithmetic for precise
// positioning of centers
// when using subdivisions
float fx1 = rectangularDomain.x_end;
float fx0 = rectangularDomain.x_begin;
float fhs = (float)hs;
float fy1 = rectangularDomain.y_end;
float fy0 = rectangularDomain.y_begin;
float fvs = (float)vs;
// Float size needed for precise positioning of correlation
// squares. Otherwhise rounding error aggregates over squares.
float fxdim = (fabs(fx1 - fx0) / fhs - 1.f) / 2.f;
float fydim = (fabs(fy1 - fy0) / fvs - 1.f) / 2.f;
time_all_point_selection = 0;
for (int i = 0; i < hs; ++i) {
int center_x = (int)(0.5f + fx0 + fxdim + (2.f * fxdim + 1.f) * (float)i);
for (int j = 0; j < vs; ++j) {
int iSector = i * vs + j;
int center_y = (int)(0.5f + fy0 + fydim + (2.f * fydim + 1.f) * (float)j);
// Define the center_x and center_y. Note "adjust_rectangular_domain"
// modifies sector's center_x and center_y.
adjust_rectangular_domain(center_x, center_y, &results_in[iSector],
current_frame_order); // want later to make
// parameters i and j, not
// center_x and center_y
adjust_initial_guess(initial_guess, &results_in[iSector],
current_frame_order);
// Definition of the undeformed xy points and number_of_points for this
// sector.
std::chrono::system_clock::time_point start_point_selection =
std::chrono::system_clock::now();
if (current_frame_order == 0) {
results_in[iSector].und_contour = get_contour_points_rectangularDomain(
center_x - xdim, center_y - ydim, center_x + xdim, center_y + ydim);
switch (processor) {
case processor_CPU:
results_in[iSector].und_inside_points =
get_inside_points_rectangularDomain(
center_x - xdim, center_y - ydim, center_x + xdim,
center_y + ydim);
break;
case processor_GPU:
#if CUDA_ENABLED
cuda_manager->resetPolygon(iSector, center_x - xdim, center_y - ydim,
center_x + xdim, center_y + ydim);
if (plot_inside_points) {
results_in[iSector].und_inside_points =
cuda_manager->getUndXY0ToCPU(iSector);
}
#endif
break;
default:
assert(false);
break;
}
} else // Logic to get the undeformed points on frames other than the
// first
{
switch (deformationDescription) {
case def_Eulerian:
// Do nothing
break;
case def_strict_Lagrangian:
results_in[iSector].und_inside_points =
results_in[iSector].def_inside_points;
results_in[iSector].und_contour = results_in[iSector].def_contour;
if (processor == processor_GPU) {
#if CUDA_ENABLED
cuda_manager->updatePolygon(iSector, def_strict_Lagrangian);
if (plot_inside_points) {
results_in[iSector].und_inside_points =
cuda_manager->getUndXY0ToCPU(iSector);
}
#endif
}
break;
case def_Lagrangian: {
std::pair<float, float> center_offset =
std::make_pair(results_in[iSector].und_center_x -
results_in[iSector].past_und_center_x,
results_in[iSector].und_center_y -
results_in[iSector].past_und_center_y);
std::transform(results_in[iSector].und_contour.begin(),
results_in[iSector].und_contour.end(),
results_in[iSector].und_contour.begin(),
add_pair(center_offset));
switch (processor) {
case processor_CPU:
std::transform(results_in[iSector].und_inside_points.begin(),
results_in[iSector].und_inside_points.end(),
results_in[iSector].und_inside_points.begin(),
add_pair(center_offset));
break;
case processor_GPU:
#if CUDA_ENABLED
cuda_manager->updatePolygon(iSector, def_Lagrangian);
if (plot_inside_points) {
results_in[iSector].und_inside_points =
cuda_manager->getUndXY0ToCPU(iSector);
}
#endif
break;
default:
assert(false);
break;
}
} break;
default:
assert(false);
break;
}
}
std::chrono::system_clock::time_point duration_point_selection =
std::chrono::system_clock::now();
time_all_point_selection +=
(float)std::chrono::duration_cast<std::chrono::milliseconds>(
duration_point_selection - start_point_selection)
.count() /
1000.f;
#if DEBUG_TIME_POINT_SELECTION
std::cout << "manager() :point selection wall execution time(s): "
<< time_all_point_selection << '\n';
#endif
CorrelationResult *correlationResults = nullptr;
// Call the correlator with these points
switch (processor) {
case processor_CPU:
initial_guess = correlator->Newton_Raphson(
initial_guess, (int)results_in[iSector].und_inside_points.size(),
center_x, center_y,
(float *)results_in[iSector].und_inside_points.data());
error = correlator->get_error_status();
break;
case processor_GPU:
#if CUDA_ENABLED
correlationResults = cuda_manager->correlate(iSector, initial_guess,
results_in[iSector]);
errorType = correlationResults->errorCode;
error = (errorType != error_none);
#endif
break;
default:
assert(true);
break;
}
// Updating center and other correlation results from the correlator for
// the report
update_results(&results_in[iSector], correlationResults);
switch (processor) {
case processor_CPU:
if (plot_inside_points ||
deformationDescription == def_strict_Lagrangian) {
results_in[iSector].def_inside_points = correlator->getDefXY0();
}
break;
case processor_GPU:
#if CUDA_ENABLED
if (plot_inside_points) {
results_in[iSector].def_inside_points =
cuda_manager->getDefXY0ToCPU(iSector);
}
#endif
break;
default:
assert(false);
break;
}
if (plot_inside_points) {
// connect(manager, SIGNAL( send_und_inside_points (v_points, bool,
// float, float) ), und_imageLabel, SLOT( set_inside_points (v_points,
// bool, float, float) ) );
// connect(manager, SIGNAL( send_def_inside_points (v_points, bool,
// float, float) ), def_imageLabel, SLOT( set_inside_points (v_points,
// bool, float, float) ) );
if (current_frame_order == 0 || referenceImage == refImage_Previous) {
emit send_und_inside_points(results_in[iSector].und_inside_points,
error);
}
emit send_def_inside_points(results_in[iSector].def_inside_points,
error);
}
if (plot_contour_points) {
results_in[iSector].def_contour = deformPoints(
results_in[iSector].und_contour, results_in[iSector].und_center_x,
results_in[iSector].und_center_y);
// connect(manager, SIGNAL( send_und_contour_points(v_points, bool) ),
// und_imageLabel, SLOT( set_contour_points(v_points, bool) ) );
// connect(manager, SIGNAL( send_def_contour_points(v_points, bool) ),
// def_imageLabel, SLOT( set_contour_points(v_points, bool) ) );
if (current_frame_order == 0 || referenceImage == refImage_Previous) {
emit send_und_contour_points(results_in[iSector].und_contour, error);
}
emit send_def_contour_points(results_in[iSector].def_contour, error);
}
if (stop_flag)
break;
if (error) {
switch (processor) {
case processor_CPU:
errorType = correlator->get_error_code();
break;
case processor_GPU:
// errorType is already read
break;
default:
assert(false);
break;
}
if (error_handling_mode == errorMode_stopAll ||
error_handling_mode == errorMode_stopFrame)
break;
}
} // This completes all the iterations of a correlation event
if (stop_flag)
break;
if (error && (error_handling_mode == errorMode_stopAll ||
error_handling_mode == errorMode_stopFrame))
break;
}
// Update the global correlation results, that averages through all sector's
// results, like center.
update_global_results(hs, vs, results_in);
// This completes one frame worth of correlations
return error;
}
bool managerClass::perform_single_frame_correlation_annular(
int rs, int as, frame_results *results_in, int current_frame_order) {
float ri = annularDomain.r_inside;
float ro = annularDomain.r_outside;
float cx = annularDomain.x_center;
float cy = annularDomain.y_center;
float dr = (ro - ri) / (float)rs;
float da = 2.f * PI / (float)as;
time_all_point_selection = 0;
for (int i = 0; i < rs; ++i) {
for (int j = 0; j < as; ++j) {
int iSector = i * as + j;
// Need to refresh r every sector because of the Lagrangian description
float r; // inside radius of the sector
float a; // angle of the sector
// The undeformed domain is selected depending on the deformation
// description mode and
// whether we are in the first frame. Note "adjust_annular_domain" defines
// r and a.
adjust_annular_domain(i, j, r, a, ri, dr, da, cx, cy, as, results_in,
current_frame_order);
// Adjust_initial_guess customizes global_initial_guess for this sector,
// into initial_guess
adjust_initial_guess(initial_guess, &results_in[iSector],
current_frame_order);
// Compute the undeformed points only on the first frame
std::chrono::system_clock::time_point start_point_selection =
std::chrono::system_clock::now();
if (current_frame_order == 0) {
results_in[iSector].und_contour =
get_contour_points_annularDomain(r, dr, a, da, cx, cy);
switch (processor) {
case processor_CPU:
results_in[iSector].und_inside_points =
get_inside_points_annularDomain(r, dr, a, da, cx, cy, as);
break;
case processor_GPU:
#if CUDA_ENABLED
cuda_manager->resetPolygon(iSector, r, dr, a, da, cx, cy, as);
if (plot_inside_points) {
results_in[i * as + j].und_inside_points =
cuda_manager->getUndXY0ToCPU(iSector);
}
#endif
break;
default:
assert(false);
break;
}
} else // Logic to get the undeformed points on frames other than the
// first
{
switch (deformationDescription) {
case def_Eulerian:
// Do nothing
break;
case def_strict_Lagrangian:
results_in[iSector].und_inside_points =
results_in[iSector].def_inside_points;
results_in[iSector].und_contour = results_in[iSector].def_contour;
if (processor == processor_GPU) {
#if CUDA_ENABLED
cuda_manager->updatePolygon(iSector, def_strict_Lagrangian);
if (plot_inside_points) {
results_in[iSector].und_inside_points =
cuda_manager->getUndXY0ToCPU(iSector);
}
#endif
}
break;
case def_Lagrangian: {
std::pair<float, float> center_offset =
std::make_pair(results_in[iSector].und_center_x -
results_in[iSector].past_und_center_x,
results_in[iSector].und_center_y -
results_in[iSector].past_und_center_y);
std::transform(results_in[iSector].und_contour.begin(),
results_in[iSector].und_contour.end(),
results_in[iSector].und_contour.begin(),
add_pair(center_offset));
switch (processor) {
case processor_CPU:
std::transform(results_in[iSector].und_inside_points.begin(),
results_in[iSector].und_inside_points.end(),
results_in[iSector].und_inside_points.begin(),
add_pair(center_offset));
break;
case processor_GPU:
#if CUDA_ENABLED
cuda_manager->updatePolygon(iSector, def_Lagrangian);
if (plot_inside_points) {
results_in[iSector].und_inside_points =
cuda_manager->getUndXY0ToCPU(iSector);
}
#endif
break;
default:
assert(false);
break;
}
} break;
default:
assert(false);
break;
}
}
std::chrono::system_clock::time_point duration_point_selection =
std::chrono::system_clock::now();
time_all_point_selection +=
(float)std::chrono::duration_cast<std::chrono::milliseconds>(
duration_point_selection - start_point_selection)
.count() /
1000.f;
#if DEBUG_TIME_POINT_SELECTION
std::cout << "manager() :point selection wall execution time(s): "
<< time_all_point_selection << '\n';
#endif
CorrelationResult *correlationResults = nullptr;
switch (processor) {
case processor_CPU:
correlator->Newton_Raphson(
initial_guess, (int)results_in[iSector].und_inside_points.size(),
(float *)results_in[iSector].und_inside_points.data());
error = correlator->get_error_status();
break;
case processor_GPU:
#if CUDA_ENABLED
correlationResults = cuda_manager->correlate(iSector, initial_guess,
results_in[iSector]);
errorType = correlationResults->errorCode;
error = (errorType != error_none);
#endif
break;
default:
assert(true);
break;
}
// Updating center and other correlation results from the correlator
update_results(&results_in[iSector], correlationResults);
if (plot_inside_points ||
deformationDescription == def_strict_Lagrangian) {
switch (processor) {
case processor_CPU:
results_in[iSector].def_inside_points = correlator->getDefXY0();
break;
case processor_GPU:
#if CUDA_ENABLED
if (plot_inside_points) {
results_in[iSector].def_inside_points =
cuda_manager->getDefXY0ToCPU(iSector);
}
#endif
break;
default:
assert(false);
break;
}
}
if (plot_inside_points) {
// connect(manager, SIGNAL( send_und_inside_points (v_points, bool,
// float, float) ), und_imageLabel, SLOT( iside_points (v_points, bool,
// float, float) ) );
// connect(manager, SIGNAL( send_def_inside_points (v_points, bool,
// float, float) ), def_imageLabel, SLOT( set_inside_points (v_points,
// bool, float, float) ) );
if (current_frame_order == 0 || referenceImage == refImage_Previous) {
emit send_und_inside_points(results_in[iSector].und_inside_points,
error);
}
emit send_def_inside_points(results_in[iSector].def_inside_points,
error);
}
if (plot_contour_points) {
results_in[iSector].def_contour = deformPoints(
results_in[iSector].und_contour, results_in[iSector].und_center_x,
results_in[iSector].und_center_y, ro);
// connect( manager , SIGNAL( send_und_contour_points( v_points , bool)
// ), und_imageLabel, SLOT( set_contour_points( v_points , bool ) ) );
// connect( manager , SIGNAL( send_def_contour_points( v_points , bool)
// ), def_imageLabel, SLOT( set_contour_points( v_points , bool ) ) );
if (current_frame_order == 0 || referenceImage == refImage_Previous) {
emit send_und_contour_points(results_in[iSector].und_contour, error);
}
emit send_def_contour_points(results_in[iSector].def_contour, error);
}
if (stop_flag)
break;
if (error) {
switch (processor) {
case processor_CPU:
errorType = correlator->get_error_code();
break;
case processor_GPU:
// errorType is already read
break;
default:
assert(false);
break;
}
if (error_handling_mode == errorMode_stopAll ||
error_handling_mode == errorMode_stopFrame)
break;
}
} // sectors loop
if (stop_flag)
break;
if (error && (error_handling_mode == errorMode_stopAll ||
error_handling_mode == errorMode_stopFrame))
break;
}
// Update the global correlation results, that averages through all sector's
// results, like center,
// aggregate angle, and dilation parameter
update_global_results(rs, as, results_in);
return error;
}
v_points managerClass::get_inside_points_annularDomain(float r, float dr,
float a, float da,
float cx, float cy,
int as) {
#if DEBUG_MANAGER_INSIDE_POINTS
printf("manager(): get_inside_points_annularDomain\n");
#endif
#if DEBUG_TIME_POINT_SELECTION
std::chrono::system_clock::time_point start =
std::chrono::system_clock::now();
#endif
int x0, y0, x1, y1;
float corner_00_x;
float corner_01_x;
float corner_10_x;
float corner_11_x;
float corner_00_y;
float corner_01_y;
float corner_10_y;
float corner_11_y;
float arc_x;
float arc_y;
v_points inside_points_vector;
switch (as) {
case 0:
assert(false);
break;
case 1:
x0 = cx - (r + dr);
x1 = cx + (r + dr);
y0 = cy - (r + dr);
y1 = cy + (r + dr);
break;
default: {
float sin0 = (float)sin(a);
float cos0 = (float)cos(a);
float sin1 = (float)sin(a + da);
float cos1 = (float)cos(a + da);
float sin2 = (float)sin(a + da / 2.f);
float cos2 = (float)cos(a + da / 2.f);
corner_00_x = cx + (r)*cos0;
corner_01_x = cx + (r)*cos1;
corner_10_x = cx + (r + dr) * cos0 * 1.2f; // Cheap sag
corner_11_x = cx + (r + dr) * cos1 * 1.2f;
corner_00_y = cy + (r)*sin0;
corner_01_y = cy + (r)*sin1;
corner_10_y = cy + (r + dr) * sin0 * 1.2f;
corner_11_y = cy + (r + dr) * sin1 * 1.2f;
arc_x = cx + (r + dr) * cos2;
arc_y = cy + (r + dr) * sin2;
x0 = std::min(arc_x, std::min(std::min(corner_00_x, corner_01_x),
std::min(corner_10_x, corner_11_x)));
x1 = std::max(arc_x, std::max(std::max(corner_00_x, corner_01_x),
std::max(corner_10_x, corner_11_x)));
y0 = std::min(arc_y, std::min(std::min(corner_00_y, corner_01_y),
std::min(corner_10_y, corner_11_y)));
y1 = std::max(arc_y, std::max(std::max(corner_00_y, corner_01_y),
std::max(corner_10_y, corner_11_y)));
break;
}
}
float ro2 = (r + dr) * (r + dr);
float ri2 = r * r;
inside_points_vector.reserve(PI * (ro2 - ri2) / (float)as * 1.1f);
#pragma omp parallel
for (float i = x0; i < x1; ++i) {
v_points inside_points_vector_private;
#pragma omp for nowait
for (int j = y0; j < y1; ++j) {
float r2 = (i - cx) * (i - cx) + (j - cy) * (j - cy);
if (r2 > ri2 && r2 < ro2) {
float cross1 = (corner_11_x - i) * (corner_01_y - corner_11_y) -
(corner_11_y - j) * (corner_01_x - corner_11_x);
float cross2 = (corner_00_x - i) * (corner_10_y - corner_00_y) -
(corner_00_y - j) * (corner_10_x - corner_00_x);
if (cross1 * cross2 > 0 || as == 1) {
inside_points_vector_private.push_back(std::make_pair(i, (float)j));
}
}
}
#pragma omp critical
inside_points_vector.insert(inside_points_vector.end(),
inside_points_vector_private.begin(),
inside_points_vector_private.end());
}
#if DEBUG_TIME_POINT_SELECTION
std::chrono::system_clock::time_point duration =
std::chrono::system_clock::now();
float total = (float)std::chrono::duration_cast<std::chrono::milliseconds>(
duration - start)
.count() /
1000.f;
std::cout << "manager() :get_inside_points_annularDomain: wall execution "
"time(s): "
<< total << '\n';
#endif
return inside_points_vector;
}
v_points managerClass::get_contour_points_annularDomain(float r, float dr,
float a, float da,
float cx, float cy) {
v_points contour;
float sin0 = (float)sin(a);
float cos0 = (float)cos(a);
float sin1 = (float)sin(a + da);
float cos1 = (float)cos(a + da);
float corner_00_x = cx + (r)*cos0;
float corner_01_x = cx + (r)*cos1;
float corner_10_x = cx + (r + dr) * cos0;
float corner_11_x = cx + (r + dr) * cos1;
float corner_00_y = cy + (r)*sin0;
float corner_01_y = cy + (r)*sin1;
float corner_10_y = cy + (r + dr) * sin0;
float corner_11_y = cy + (r + dr) * sin1;
// The contour of the angular sector approximates the circular arcs as
// polylines.
// Every segment in the polyline is the smallest of 2 options. Either covering
// a min arc angle or
// having a length specified by the global blob segment distance.
float angular_step_out =
std::min(da / ((float)sqrt(min_blob_segment_squared) / (r + dr)),
min_angular_step_deg * PI / 180.f);
int number_of_intermediate_angular_steps_out =
(int)floor(da / angular_step_out);
float angular_step_in =
std::min(da / ((float)sqrt(min_blob_segment_squared) / (r)),
min_angular_step_deg * PI / 180.f);
int number_of_intermediate_angular_steps_in =
(int)floor(da / angular_step_in);
contour.reserve(number_of_intermediate_angular_steps_out +
number_of_intermediate_angular_steps_in + 4);
contour.push_back(std::make_pair(corner_00_x, corner_00_y));
contour.push_back(std::make_pair(corner_10_x, corner_10_y));
for (int i = 1; i <= number_of_intermediate_angular_steps_out; ++i) {
contour.push_back(
std::make_pair(cx + (r + dr) * cos(a + i * angular_step_out),
cy + (r + dr) * sin(a + i * angular_step_out)));
}
contour.push_back(std::make_pair(corner_11_x, corner_11_y));
contour.push_back(std::make_pair(corner_01_x, corner_01_y));
for (int i = number_of_intermediate_angular_steps_in; i >= 1; --i) {
contour.push_back(std::make_pair(cx + (r)*cos(a + i * angular_step_in),
cy + (r)*sin(a + i * angular_step_in)));
}
return contour;
}