Skip to content

Commit b51f35b

Browse files
committed
added logic to handle adding extra trapazoids if next two segements are on same x
1 parent 24a2965 commit b51f35b

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

extrinsicCalib/extrinsicCalib.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
216 495
2+
621 464
3+
597 198
4+
201 227

src/student_interface.cpp

+57-16
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ namespace student {
362362
//Finding cells
363363
POINT curr_vertex;
364364
SEGMENT next_segment;
365+
SEGMENT next_next_segment;
365366
POINT next_vertex;
367+
POINT next_next_vertex;
366368
std::vector<SEGMENT> lines_to_check;
367369
std::vector<int> group;
368370
std::vector< std::vector<POINT> > trapezoids;
@@ -372,6 +374,7 @@ namespace student {
372374
std::vector< std::vector<POINT> > cells;
373375
int break_now;
374376
std::vector<int> done;
377+
bool extra_search = true;
375378

376379
for(int i = 0; i < open_line_segments.size(); i++) {
377380
curr_segment = open_line_segments[i];
@@ -394,12 +397,18 @@ namespace student {
394397
group.clear();
395398
trapezoids.clear();
396399
bool double_check = false;
400+
bool next_two_seg_same_x = false;
397401

398402
next_segment = open_line_segments[j];
399403
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+
}
400409
// check to see if the next segemnt is completely free from both sides
401410
double_check = next_segment.a.x != -1 && next_segment.b.x != -1;
402-
411+
403412
// int output13 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
404413
// int output14 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
405414
// int output15 = 0 + (rand() % static_cast<int>(255 - 0 + 1));
@@ -417,11 +426,13 @@ namespace student {
417426
// group 1 -> not blocked from the bottom
418427
// group 2 -> completely blocked
419428

420-
// if not blocked from the top
429+
// if not blocked from the bottom
421430
if(done[0] == 0) {
431+
// cout << "--------cur seg is not blocked from bottom----------" << endl;
422432
// 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
424434
if(double_check) {
435+
// cout << "--next seg is free" << endl;
425436
// make a segment out of the lower limit of the current vertical line,
426437
// and the current point of the obstacle
427438
// temp_points1.push_back(curr_segment.a);
@@ -493,6 +504,7 @@ namespace student {
493504
}
494505
// if next segment is not blocked from the bottom
495506
else if(next_segment.a.x != -1) {
507+
// cout << "--next seg is not blocked from bottom" << endl;
496508
// temp_points1.push_back(curr_segment.a);
497509
// temp_points1.push_back(curr_vertex);
498510
// temp_points2.push_back(next_segment.a);
@@ -516,12 +528,19 @@ namespace student {
516528
// temp_points1.push_back(next_vertex);
517529
// temp_points1.push_back(curr_vertex);
518530
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+
}
522540
}
523541
//if the next segment is not blocked from the top
524542
else if(next_segment.b.x != -1) {
543+
// cout << "--next seg is not blocked from top" << endl;
525544
// temp_points1.push_back(curr_segment.a);
526545
// temp_points1.push_back(curr_vertex);
527546
// temp_points2.push_back(next_segment.b);
@@ -539,7 +558,14 @@ namespace student {
539558
// temp_points1.push_back(next_segment.b);
540559
// temp_points1.push_back(curr_vertex);
541560
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+
}
543569
// temp_points1.clear();
544570
// temp_points2.clear();
545571
}
@@ -566,8 +592,10 @@ namespace student {
566592

567593
// not blocked from the bottom
568594
if(done[1] == 0) {
595+
// cout << "--------cur seg is not blocked from top----------" << endl;
569596
// if next segment is free from both sides
570597
if(double_check) {
598+
// cout << "--next seg is free" << endl;
571599
// temp_points1.push_back(curr_segment.b);
572600
// temp_points1.push_back(curr_vertex);
573601
// temp_points2.push_back(next_segment.a);
@@ -606,6 +634,7 @@ namespace student {
606634
}
607635
// if next segement not blocked from the bottom
608636
else if(next_segment.a.x != -1) {
637+
// cout << "--next seg is not blocked from bottom" << endl;
609638
// temp_points1.push_back(curr_segment.b);
610639
// temp_points1.push_back(curr_vertex);
611640
// temp_points2.push_back(next_segment.a);
@@ -621,12 +650,19 @@ namespace student {
621650
// temp_points1.push_back(next_vertex);
622651
// temp_points1.push_back(curr_segment.b);
623652
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+
}
625660
// temp_points1.clear();
626661
// temp_points2.clear();
627662
}
628663
// if next segment is not blocked from the top
629664
else if(next_segment.b.x != -1) {
665+
// cout << "--next seg is not blocked from top" << endl;
630666
// temp_points1.push_back(curr_segment.b);
631667
// temp_points1.push_back(curr_vertex);
632668
// temp_points2.push_back(next_segment.b);
@@ -643,6 +679,14 @@ namespace student {
643679
// temp_points1.push_back(curr_segment.b);
644680
trapezoids.push_back({curr_vertex,next_vertex,next_segment.b,curr_segment.b});
645681

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+
}
646690
// temp_points1.clear();
647691
// temp_points2.clear();
648692
}
@@ -667,7 +711,7 @@ namespace student {
667711
// temp_points1.clear();
668712
// temp_points2.clear();
669713

670-
//blocked from the top
714+
//blocked from both
671715
if(done[2] == 0) {
672716
// if next segement free from both sides
673717
if(double_check) {
@@ -875,15 +919,12 @@ namespace student {
875919
}
876920
}
877921

878-
// int output4 = 0;
879-
// int output5 = 0;
880-
// int output6 = 0;
881-
// int enlarge = 600;
922+
882923
// std::cout << "cell size " << cells.size() << std::endl;
883924
// 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));
887928
// auto color_rand = cv::Scalar(output4,output5,output6);
888929
// for(unsigned j=1; j<cells[i].size(); j++){
889930
// cv::Point2f point_center(cells[i][j-1].x*enlarge,cells[i][j-1].y*enlarge);

0 commit comments

Comments
 (0)