diff --git a/Intersections_3/include/CGAL/Intersection_traits_3.h b/Intersections_3/include/CGAL/Intersection_traits_3.h index bb843288f1d..c49fc277357 100644 --- a/Intersections_3/include/CGAL/Intersection_traits_3.h +++ b/Intersections_3/include/CGAL/Intersection_traits_3.h @@ -179,6 +179,7 @@ struct Intersection_traits + // Iso_cuboid_3 Point_3, variant of one template struct Intersection_traits { @@ -226,6 +227,44 @@ struct Intersection_traits typedef typename boost::optional< variant_type > result_type; }; +// Bbox_3 Plane_3, variant of 4 +template +struct Intersection_traits { + typedef typename + boost::variant< typename K::Point_3, typename K::Segment_3, + typename K::Triangle_3, std::vector > variant_type; + + typedef typename boost::optional< variant_type > result_type; +}; + +template +struct Intersection_traits { + typedef typename + boost::variant< typename K::Point_3, typename K::Segment_3, + typename K::Triangle_3, std::vector > variant_type; + + typedef typename boost::optional< variant_type > result_type; +}; + +// Bbox_3 Triangle_3, variant of 4 +template +struct Intersection_traits { + typedef typename + boost::variant< typename K::Point_3, typename K::Segment_3, + typename K::Triangle_3, std::vector > variant_type; + + typedef typename boost::optional< variant_type > result_type; +}; + +template +struct Intersection_traits { + typedef typename + boost::variant< typename K::Point_3, typename K::Segment_3, + typename K::Triangle_3, std::vector > variant_type; + + typedef typename boost::optional< variant_type > result_type; +}; + // Point_3 Line_3, variant of one template diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h index 639a7986aee..c6fd821083e 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h @@ -27,6 +27,7 @@ #include #include +#include namespace CGAL { @@ -43,6 +44,23 @@ bool do_intersect(const Plane_3& a, return K().do_intersect_3_object()(a, b); } +template +typename Intersection_traits::result_type +intersection(const CGAL::Bbox_3& box, + const Plane_3& pl) { + typename K::Iso_cuboid_3 cub(box.xmin(), box.ymin(), box.zmin(), + box.xmax(), box.ymax(), box.zmax()); + return typename K::Intersect_3()(cub, pl); +} + +template +typename Intersection_traits::result_type +intersection(const Plane_3& a, + const CGAL::Bbox_3& b) { + return intersection(b,a); +} + + } #endif // CGAL_INTERSECTIONS_3_BBOX_3_PLANE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h index c7d5a122a9e..33fb3bc1717 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h @@ -27,6 +27,7 @@ #include #include +#include namespace CGAL { @@ -42,6 +43,21 @@ bool do_intersect(const Triangle_3& a, return K().do_intersect_3_object()(a, b); } +template +typename Intersection_traits::result_type +intersection(const CGAL::Bbox_3& box, + const Triangle_3& tr) { + typename K::Iso_cuboid_3 cub(box.xmin(), box.ymin(), box.zmin(), + box.xmax(), box.ymax(), box.zmax()); + return typename K::Intersect_3()(cub, tr); +} + +template +typename Intersection_traits::result_type +intersection(const Triangle_3& a, + const CGAL::Bbox_3& b) { + return intersection(b,a); +} } // namespace CGAL diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h index a04a1978908..0e8f1ebc186 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h @@ -162,8 +162,6 @@ intersection( Poly clipped; clip_poly_halfspace(poly, planes[i], clipped); poly = clipped; - for(auto p : poly) - std::cout<size() == 4); for(auto p : *poly) { - std::cout<::result_type Res; + Res res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1,2,2))); + + const std::vector

* poly = boost::get >(&*res); + CGAL_assertion(poly != nullptr); + CGAL_assertion(poly->size() == 4); + for(auto p : *poly) + { + CGAL_assertion(p.x() == 1); + } + res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(2,2,2))); + poly = boost::get >(&*res); + CGAL_assertion(poly != nullptr); + CGAL_assertion(poly->size() == 4); + //vertex + check_intersection (cub, Pl(0.5, -0.5, -0.5, 0), + P(2,1,1)); + //triangle + + check_intersection (cub, Pl(P(2, 1.66, 2), + P(1.66,2,2), + P(2,2,1.66)), + Tr(P(2, 2, 1.66), + P(1.66,2,2), + P(2,1.66,2))); + + //random + Pl pl(0.265189, 0.902464, 0.33946, -2.47551); + res = CGAL::intersection(cub, pl); + poly = boost::get >(&*res); + CGAL_assertion(poly != nullptr); + CGAL_assertion(poly->size() == 5); + for(auto p : *poly) + { + CGAL_assertion(pl.has_on(p)); + } + } + else + { + CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1.5,0,0))); + //face + typedef typename CGAL::Intersection_traits::result_type Res; + Res res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1,2,2))); + res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(2,2,2))); + CGAL::intersection (cub, Pl(0.5, -0.5, -0.5, 0)); + CGAL::intersection (cub, Pl(P(2, 1.66, 2), + P(1.66,2,2), + P(2,2,1.66))); + Pl pl(0.265189, 0.902464, 0.33946, -2.47551); + res = CGAL::intersection(cub, pl); + } + } + + void Box_Tr(bool is_exact) + { + std::cout << "Triangle_3 - Cuboid_3\n"; + + Cub cub(P(1,1,1), P(2,2,2)); + + check_no_intersection(cub, Tr(P(1.1, 2,0), + P(2, 3, 1), + P(4, 5, 6))); + + //tr in a face + check_intersection(cub, Tr(P(1,1.1,1), + P(1,1.5,1), + P(1,1,1.1)), + Tr(P(1,1.1,1), + P(1,1.5,1), + P(1,1,1.1)) + ); + //face in a tr + + typedef typename CGAL::Intersection_traits::result_type Res; + Tr tr(P(-3, -3, 1), P(3,-3,1), P(1.5,6,1)); + Res res = CGAL::intersection(cub, tr); + if(is_exact) + { + std::vector

* poly = boost::get >(&*res); + CGAL_assertion(poly != nullptr); + CGAL_assertion(poly->size() == 4); + for(auto p : *poly) + { + CGAL_assertion(tr.has_on(p) && cub.has_on_boundary(p)); + } + } + + //tr adj to a point + + check_intersection (cub, Tr(P(1, 0.5, 0.5), + P(3, 2, 1), + P(3, 1, 2)), + P(2,1,1)); + //tr adj to an edge + check_intersection (cub, Tr(P(1,0,4), P(2,1,0), P(4,3,0)), + S(P(2,1,2), P(2,1,1))); + //tr inside + check_intersection (cub, Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1)), + Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1))); + //tr through + tr = Tr(P(2, 4, 2), + P(1, 3.5, -0.5), + P(1, -1, 1)); + res = CGAL::intersection(cub, tr); + if(is_exact) + { + std::vector

* poly = boost::get >(&*res); + CGAL_assertion(poly != nullptr); + CGAL_assertion(poly->size() == 4); + for(auto p : *poly) + { + CGAL_assertion(tr.has_on(p) && cub.has_on_boundary(p)); + } + } + } void run(bool is_exact = false) @@ -1049,6 +1185,8 @@ struct Test { Tet_Tr(is_exact); Pl_Cub(is_exact); Cub_Tr(is_exact); + Pl_Box(is_exact); + Box_Tr(is_exact); //@} Bbox_L();