@@ -362,7 +362,9 @@ namespace student {
362
362
// Finding cells
363
363
POINT curr_vertex;
364
364
SEGMENT next_segment;
365
+ SEGMENT next_next_segment;
365
366
POINT next_vertex;
367
+ POINT next_next_vertex;
366
368
std::vector<SEGMENT> lines_to_check;
367
369
std::vector<int > group;
368
370
std::vector< std::vector<POINT> > trapezoids;
@@ -372,6 +374,7 @@ namespace student {
372
374
std::vector< std::vector<POINT> > cells;
373
375
int break_now;
374
376
std::vector<int > done;
377
+ bool extra_search = true ;
375
378
376
379
for (int i = 0 ; i < open_line_segments.size (); i++) {
377
380
curr_segment = open_line_segments[i];
@@ -394,12 +397,18 @@ namespace student {
394
397
group.clear ();
395
398
trapezoids.clear ();
396
399
bool double_check = false ;
400
+ bool next_two_seg_same_x = false ;
397
401
398
402
next_segment = open_line_segments[j];
399
403
next_vertex = sorted_vertices[j];
404
+ if ( j != open_line_segments.size ()-1 && extra_search){
405
+ next_next_segment = open_line_segments[j+1 ];
406
+ next_next_vertex = sorted_vertices[j+1 ];
407
+ next_two_seg_same_x = (next_vertex.x == next_next_vertex.x );
408
+ }
400
409
// check to see if the next segemnt is completely free from both sides
401
410
double_check = next_segment.a .x != -1 && next_segment.b .x != -1 ;
402
-
411
+
403
412
// int output13 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
404
413
// int output14 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
405
414
// int output15 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
@@ -417,11 +426,13 @@ namespace student {
417
426
// group 1 -> not blocked from the bottom
418
427
// group 2 -> completely blocked
419
428
420
- // if not blocked from the top
429
+ // if not blocked from the bottom
421
430
if (done[0 ] == 0 ) {
431
+ // cout << "--------cur seg is not blocked from bottom----------" << endl;
422
432
// std::cout << "test -> done[0] == 0 [not blocked from the bottom" << std::endl;
423
- // and the next vertical line is not completely blocked on both of its points
433
+ // and the next vertex is free from both sides
424
434
if (double_check) {
435
+ // cout << "--next seg is free" << endl;
425
436
// make a segment out of the lower limit of the current vertical line,
426
437
// and the current point of the obstacle
427
438
// temp_points1.push_back(curr_segment.a);
@@ -493,6 +504,7 @@ namespace student {
493
504
}
494
505
// if next segment is not blocked from the bottom
495
506
else if (next_segment.a .x != -1 ) {
507
+ // cout << "--next seg is not blocked from bottom" << endl;
496
508
// temp_points1.push_back(curr_segment.a);
497
509
// temp_points1.push_back(curr_vertex);
498
510
// temp_points2.push_back(next_segment.a);
@@ -516,12 +528,19 @@ namespace student {
516
528
// temp_points1.push_back(next_vertex);
517
529
// temp_points1.push_back(curr_vertex);
518
530
trapezoids.push_back ({curr_segment.a ,next_segment.a ,next_vertex,curr_vertex});
519
-
520
- // temp_points1.clear();
521
- // temp_points2.clear();
531
+ if (next_two_seg_same_x && (next_next_segment.b .x != -1 ) && (next_next_segment.a .x == -1 ) && extra_search){
532
+ // cout << "--next next seg is not blocked from top" << endl;
533
+ temp_segment.a = centroid ({curr_segment.a ,curr_vertex});
534
+ temp_segment.b = centroid ({next_next_segment.b ,next_next_vertex});
535
+ lines_to_check.push_back (temp_segment);
536
+ group.push_back (0 );
537
+ temp_points1.clear ();
538
+ trapezoids.push_back ({curr_segment.a ,next_next_vertex,next_next_segment.b ,curr_vertex});
539
+ }
522
540
}
523
541
// if the next segment is not blocked from the top
524
542
else if (next_segment.b .x != -1 ) {
543
+ // cout << "--next seg is not blocked from top" << endl;
525
544
// temp_points1.push_back(curr_segment.a);
526
545
// temp_points1.push_back(curr_vertex);
527
546
// temp_points2.push_back(next_segment.b);
@@ -539,7 +558,14 @@ namespace student {
539
558
// temp_points1.push_back(next_segment.b);
540
559
// temp_points1.push_back(curr_vertex);
541
560
trapezoids.push_back ({curr_segment.a ,next_vertex,next_segment.b ,curr_vertex});
542
-
561
+ if (next_two_seg_same_x && (next_next_segment.a .x != -1 ) && (next_next_segment.b .x == -1 ) && extra_search){
562
+ // cout << "--next next seg is not blocked from bottom" << endl;
563
+ temp_segment.a = centroid ({curr_segment.a ,curr_vertex});
564
+ temp_segment.b = centroid ({next_next_segment.a ,next_next_vertex});
565
+ lines_to_check.push_back (temp_segment);
566
+ group.push_back (0 );
567
+ trapezoids.push_back ({curr_segment.a ,next_next_segment.a ,next_next_vertex,curr_vertex});
568
+ }
543
569
// temp_points1.clear();
544
570
// temp_points2.clear();
545
571
}
@@ -566,8 +592,10 @@ namespace student {
566
592
567
593
// not blocked from the bottom
568
594
if (done[1 ] == 0 ) {
595
+ // cout << "--------cur seg is not blocked from top----------" << endl;
569
596
// if next segment is free from both sides
570
597
if (double_check) {
598
+ // cout << "--next seg is free" << endl;
571
599
// temp_points1.push_back(curr_segment.b);
572
600
// temp_points1.push_back(curr_vertex);
573
601
// temp_points2.push_back(next_segment.a);
@@ -606,6 +634,7 @@ namespace student {
606
634
}
607
635
// if next segement not blocked from the bottom
608
636
else if (next_segment.a .x != -1 ) {
637
+ // cout << "--next seg is not blocked from bottom" << endl;
609
638
// temp_points1.push_back(curr_segment.b);
610
639
// temp_points1.push_back(curr_vertex);
611
640
// temp_points2.push_back(next_segment.a);
@@ -621,12 +650,19 @@ namespace student {
621
650
// temp_points1.push_back(next_vertex);
622
651
// temp_points1.push_back(curr_segment.b);
623
652
trapezoids.push_back ({curr_vertex,next_segment.a ,next_vertex,curr_segment.b });
624
-
653
+ if (next_two_seg_same_x && (next_next_segment.b .x != -1 ) && (next_next_segment.a .x == -1 ) && extra_search){
654
+ // cout << "--next next seg is not blocked from top" << endl;
655
+ temp_segment.a = centroid ({curr_segment.b ,curr_vertex});
656
+ temp_segment.b = centroid ({next_next_segment.b ,next_next_vertex});
657
+ lines_to_check.push_back (temp_segment);
658
+ trapezoids.push_back ({curr_vertex,next_next_vertex,next_next_segment.b ,curr_segment.b });
659
+ }
625
660
// temp_points1.clear();
626
661
// temp_points2.clear();
627
662
}
628
663
// if next segment is not blocked from the top
629
664
else if (next_segment.b .x != -1 ) {
665
+ // cout << "--next seg is not blocked from top" << endl;
630
666
// temp_points1.push_back(curr_segment.b);
631
667
// temp_points1.push_back(curr_vertex);
632
668
// temp_points2.push_back(next_segment.b);
@@ -643,6 +679,14 @@ namespace student {
643
679
// temp_points1.push_back(curr_segment.b);
644
680
trapezoids.push_back ({curr_vertex,next_vertex,next_segment.b ,curr_segment.b });
645
681
682
+ if (next_two_seg_same_x && (next_next_segment.a .x != -1 ) && (next_next_segment.b .x == -1 ) && extra_search){
683
+ // cout << "--next next seg is not blocked from bottom" << endl;
684
+ temp_segment.a = centroid ({curr_segment.b ,curr_vertex});
685
+ temp_segment.b = centroid ({next_next_segment.a ,next_next_vertex});
686
+ lines_to_check.push_back (temp_segment);
687
+ group.push_back (0 );
688
+ trapezoids.push_back ({curr_vertex,next_next_segment.a ,next_next_vertex,curr_segment.b });
689
+ }
646
690
// temp_points1.clear();
647
691
// temp_points2.clear();
648
692
}
@@ -667,7 +711,7 @@ namespace student {
667
711
// temp_points1.clear();
668
712
// temp_points2.clear();
669
713
670
- // blocked from the top
714
+ // blocked from both
671
715
if (done[2 ] == 0 ) {
672
716
// if next segement free from both sides
673
717
if (double_check) {
@@ -875,15 +919,12 @@ namespace student {
875
919
}
876
920
}
877
921
878
- // int output4 = 0;
879
- // int output5 = 0;
880
- // int output6 = 0;
881
- // int enlarge = 600;
922
+
882
923
// std::cout << "cell size " << cells.size() << std::endl;
883
924
// for (unsigned i=0; i<cells.size(); i++) {
884
- // output4 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
885
- // output5 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
886
- // output6 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
925
+ // int output4 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
926
+ // int output5 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
927
+ // int output6 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
887
928
// auto color_rand = cv::Scalar(output4,output5,output6);
888
929
// for(unsigned j=1; j<cells[i].size(); j++){
889
930
// cv::Point2f point_center(cells[i][j-1].x*enlarge,cells[i][j-1].y*enlarge);
0 commit comments