From c573ccb82773bfe26ab2b41c53b3a8fd825dd229 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 24 Aug 2022 16:18:07 +0200 Subject: [PATCH 1/4] Fix static filter of Do_intersect_3(Bbox_3,Triangle_3) See the publication at https://www.semanticscholar.org/paper/High-performance-triangle-versus-box-intersection-Christensen-Karlsson/bad661b58359ec01be2deb2f47ec8fd8eb293747 The test of intersection of `bbox` and `triangle.bbox` was missing. --- .../internal/Static_filters/Do_intersect_3.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/Do_intersect_3.h b/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/Do_intersect_3.h index 44a3ae05669..3b94f56663c 100644 --- a/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/Do_intersect_3.h +++ b/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/Do_intersect_3.h @@ -509,6 +509,8 @@ public: (pts[i][1] >= b.ymin() && pts[i][1] <= b.ymax()) && (pts[i][2] >= b.zmin() && pts[i][2] <= b.zmax()) ) { + // If any of the three points of the triangle is inside the bbox, + // then the box and triangle intersect. return true; } @@ -520,6 +522,21 @@ public: } } + // If the bbox of the triangle does not intersect `b`, then the bbox and + // the triangle do not intersect. + for(int i=0; i< 3; ++i) { + double triangle_bbox_min = pts[0][i]; + double triangle_bbox_max = triangle_bbox_min; + for(int j=1; j<3; ++j) { + if(pts[j][i] < triangle_bbox_min) + triangle_bbox_min = pts[j][i]; + if(pts[j][i] > triangle_bbox_max) + triangle_bbox_max = pts[j][i]; + } + if(triangle_bbox_min > b.max_coord(i) || triangle_bbox_max < b.min_coord(i)) + return false; + } + // copy of the regular code with do_axis_intersect_aux_impl statically filtered auto do_axis_intersect_aux_impl = [](double alpha, double beta, double c_alpha, double c_beta) -> Uncertain { From c61e3a978bf6fad148ea485d93a08d030c482dc9 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 24 Aug 2022 16:18:26 +0200 Subject: [PATCH 2/4] Fix typo size/side --- .../internal/Bbox_3_Triangle_3_do_intersect.h | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h index 8eca9e6a517..0c88e508457 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h @@ -273,13 +273,13 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr }}; int forbidden_axis = -1; - int forbidden_size = -1; + int forbidden_side = -1; //determine whether one vector is collinear with an axis int tmp = collinear_axis(sides[0]); if(tmp != -1) { forbidden_axis = tmp; - forbidden_size = 0; + forbidden_side = 0; } else { @@ -287,7 +287,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr if(tmp != -1) { forbidden_axis = tmp; - forbidden_size = 1; + forbidden_side = 1; } else { @@ -295,7 +295,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr if(tmp != -1) { forbidden_axis = tmp; - forbidden_size = 2; + forbidden_side = 2; } } } @@ -305,7 +305,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr if(forbidden_axis != 0) { - if(forbidden_size != 0) + if(forbidden_side != 0) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -314,7 +314,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr return false; } - if(forbidden_size != 1) + if(forbidden_side != 1) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -323,7 +323,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr return false; } - if(forbidden_size != 2) + if(forbidden_side != 2) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -335,7 +335,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr if(forbidden_axis != 1) { - if(forbidden_size != 0) + if(forbidden_side != 0) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -344,7 +344,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr return false; } - if(forbidden_size != 1) + if(forbidden_side != 1) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -353,7 +353,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr return false; } - if(forbidden_size != 2) + if(forbidden_side != 2) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -365,7 +365,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr if(forbidden_axis != 2) { - if(forbidden_size != 0) + if(forbidden_side != 0) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -374,7 +374,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr return false; } - if(forbidden_size != 1) + if(forbidden_side != 1) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) @@ -383,7 +383,7 @@ do_intersect_bbox_or_iso_cuboid_impl(const std::array< std::array, 3>& tr return false; } - if(forbidden_size != 2) + if(forbidden_side != 2) { Uncertain b = do_axis_intersect(triangle, sides, bbox, do_axis_intersect_aux_impl); if(is_indeterminate(b)) From 550e4306c8fe76a04a723fb7a2983109a9ad715f Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 25 Aug 2022 13:09:18 +0100 Subject: [PATCH 3/4] Add triangles completelty to the left of the bbox parallel/projection on face inside, projection on face intersects --- .../Intersections_3/bbox_other_do_intersect_test.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp b/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp index 29debe09068..1bb0a2ce95b 100644 --- a/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp +++ b/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp @@ -378,7 +378,7 @@ bool test(bool exact_kernel = false) typedef typename K::Triangle_3 Triangle; typedef typename K::Iso_cuboid_3 Iso_cuboid_3; - CGAL::Bbox_3 bbox(1.0,1.0,1.0,10.0,50.0,100.0); + CGAL::Bbox_3 bbox(1.0,1.0,1.0, 10.0,50.0,100.0); Point p1(FT(0.), FT(0.), FT(0.)); Point p2(FT(0.), FT(100.), FT(100.)); @@ -559,8 +559,11 @@ bool test(bool exact_kernel = false) Triangle tABC(pA,pB,pC); Triangle t1(Point(1,1,1),Point(0,0,0),Point(0,0,1)); Triangle t2(Point(4,1,7),Point(8,1,99),Point(7,1,11)); - Triangle t3(Point(0,1,1),Point(0,0,0),Point(0,0,1)); - + // triangles completely to the left side of the cube + Triangle t3(Point(0, 1, 1), Point(0, 0, 0), Point(0, 0, 1)); // parallel to the left side + Triangle t4(Point(-1, 3, 2), Point(0, 2, 2), Point(0, 3, 2)); // projection inside the left side + Triangle t5(Point(-1, 3, 2), Point(0, 1, 2), Point(0, 3, -1)); // projection with one point outside of the left side + b &= test_aux(t123,"t123",bbox,true); b &= test_aux(t124,"t124",bbox,true); b &= test_aux(t126,"t126",bbox,true); @@ -569,6 +572,9 @@ bool test(bool exact_kernel = false) b &= test_aux(t1,"t1",bbox,true); b &= test_aux(t2,"t2",bbox,true); b &= test_aux(t3,"t3",bbox,false); + b &= test_aux(t4,"t4",bbox,false); + b &= test_aux(t5,"t5",bbox, false); + b &= test_aux(t123,"t123",Iso_cuboid_3(bbox),true); b &= test_aux(t124,"t124",Iso_cuboid_3(bbox),true); From f0f01b70badc9668fa95c815e088a4fc6bd02852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 7 Sep 2022 08:44:42 +0200 Subject: [PATCH 4/4] remove trailing whitespace --- .../test/Intersections_3/bbox_other_do_intersect_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp b/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp index 1bb0a2ce95b..bd5adeccdeb 100644 --- a/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp +++ b/Intersections_3/test/Intersections_3/bbox_other_do_intersect_test.cpp @@ -563,7 +563,7 @@ bool test(bool exact_kernel = false) Triangle t3(Point(0, 1, 1), Point(0, 0, 0), Point(0, 0, 1)); // parallel to the left side Triangle t4(Point(-1, 3, 2), Point(0, 2, 2), Point(0, 3, 2)); // projection inside the left side Triangle t5(Point(-1, 3, 2), Point(0, 1, 2), Point(0, 3, -1)); // projection with one point outside of the left side - + b &= test_aux(t123,"t123",bbox,true); b &= test_aux(t124,"t124",bbox,true); b &= test_aux(t126,"t126",bbox,true);