From ebfcedce387b04aefc0bb0dcce634bd685c55562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 11 May 2015 17:52:53 +0200 Subject: [PATCH] fix the way to specify the point inside the intersection of halfspaces --- .../dual/halfspace_intersection_3.h | 2 +- ...fspace_intersection_with_constructions_3.h | 2 +- .../halfspace_intersection_3.cpp | 6 +- .../dual/halfspace_intersection_3.h | 13 ++-- ...fspace_intersection_with_constructions_3.h | 37 +---------- .../test_halfspace_intersections.cpp | 64 +++++++++++++++++++ 6 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 Convex_hull_3/test/Convex_hull_3/test_halfspace_intersections.cpp diff --git a/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h b/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h index 79eb2c74541..e028bc683a1 100644 --- a/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h +++ b/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h @@ -23,6 +23,6 @@ This version does not construct the dual points explicitely but uses a special t template void halfspace_intersection_3 (PlaneIterator begin, PlaneIterator end, Polyhedron &P, - boost::optional origin); + boost::optional origin = boost::none); } /* namespace CGAL */ diff --git a/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h b/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h index 0e6501841ee..0b62cf26e75 100644 --- a/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h +++ b/Convex_hull_3/doc/Convex_hull_3/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h @@ -24,7 +24,7 @@ template void halfspace_intersection_with_constructions_3(PlaneIterator pbegin, PlaneIterator pend, Polyhedron &P, - boost::optional origin, + boost::optional origin = boost::none, const Traits & ch_traits = Default_traits); } /* namespace CGAL */ diff --git a/Convex_hull_3/examples/Convex_hull_3/halfspace_intersection_3.cpp b/Convex_hull_3/examples/Convex_hull_3/halfspace_intersection_3.cpp index ad0deac57c0..100f5d68ea6 100644 --- a/Convex_hull_3/examples/Convex_hull_3/halfspace_intersection_3.cpp +++ b/Convex_hull_3/examples/Convex_hull_3/halfspace_intersection_3.cpp @@ -34,12 +34,12 @@ int main (void) { Polyhedron_3 P; // compute the intersection - // if a point inside the intersection is unknown, pass boost::none - // to automatically found one using linear programming + // if no point inside the intersection is provided, one + // will be automatically found using linear programming CGAL::halfspace_intersection_3(planes.begin(), planes.end(), P, - Point(0, 0, 0)); + boost::make_optional(Point(0, 0, 0)) ); return 0; } diff --git a/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h b/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h index 8ec251423ce..c1c518afa74 100644 --- a/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h +++ b/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h @@ -262,7 +262,7 @@ namespace CGAL template void halfspace_intersection_3 (PlaneIterator begin, PlaneIterator end, Polyhedron &P, - boost::optional const& origin) { + boost::optional const& origin = boost::none) { // Checks whether the intersection if a polyhedron CGAL_assertion_msg(Convex_hull_3::internal::is_intersection_dim_3(begin, end), "halfspace_intersection_3: intersection not a polyhedron"); @@ -311,20 +311,15 @@ namespace CGAL } } - // Compute the intersection of halfspaces by computing a point inside. - template - void halfspace_intersection_3 (PlaneIterator begin, PlaneIterator end, - Polyhedron &P) { - halfspace_intersection_3(begin, end , P, boost::none); - } - + #ifndef CGAL_NO_DEPRECATED_CODE // Compute the intersection of halfspaces (an interior point is given.) template void halfspace_intersection_3 (PlaneIterator begin, PlaneIterator end, Polyhedron &P, typename Polyhedron::Vertex::Point_3 const& origin) { - halfspace_intersection_3(begin, end , P, boost::optional(origin)); + halfspace_intersection_3(begin, end , P, boost::make_optional(origin)); } + #endif } // namespace CGAL #endif // CGAL_HALFSPACE_INTERSECTION_3_H diff --git a/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h b/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h index a35736ac4fd..c91a5a8f198 100644 --- a/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h +++ b/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h @@ -160,28 +160,13 @@ namespace CGAL P.delegate(build_dual); } - // Compute the intersection of halfspaces by constructing explicitly - // the dual points with the traits class for convex_hull_3 given - // as an argument. - // An interior point is given. - template - void halfspace_intersection_with_constructions_3(PlaneIterator pbegin, - PlaneIterator pend, - Polyhedron &P, - typename Polyhedron::Vertex::Point_3 const& origin, - const Traits & ch_traits) { - halfspace_intersection_with_constructions_3(pbegin, pend, P, - boost::optional(origin), - ch_traits); - } - // Compute the intersection of halfspaces by constructing explicitly // the dual points with the default traits class for convex_hull_3. template void halfspace_intersection_with_constructions_3 (PlaneIterator pbegin, PlaneIterator pend, Polyhedron &P, - boost::optional const& origin) { + boost::optional const& origin = boost::none) { typedef typename Kernel_traits::Kernel K; typedef typename K::Point_3 Point_3; typedef typename internal::Convex_hull_3::Default_traits_for_Chull_3::type Traits; @@ -189,27 +174,7 @@ namespace CGAL halfspace_intersection_with_constructions_3(pbegin, pend, P, origin, Traits()); } - // Compute the intersection of halfspaces by constructing explicitly - // the dual points with the default traits class for convex_hull_3. - // An interior point is given. - template - void halfspace_intersection_with_constructions_3 (PlaneIterator pbegin, - PlaneIterator pend, - Polyhedron &P, - typename Polyhedron::Vertex::Point_3 const& origin) { - halfspace_intersection_with_constructions_3(pbegin, pend, P, - boost::optional(origin)); - } - // Compute the intersection of halfspaces by constructing explicitly - // the dual points with the default traits class for convex_hull_3. - // An interior point is not given. - template - void halfspace_intersection_with_constructions_3 (PlaneIterator pbegin, - PlaneIterator pend, - Polyhedron &P) { - halfspace_intersection_with_constructions_3(pbegin, pend, P, boost::none); - } } // namespace CGAL #endif // CGAL_HALFSPACE_INTERSECTION_WITH_CONSTRUCTION_3_H diff --git a/Convex_hull_3/test/Convex_hull_3/test_halfspace_intersections.cpp b/Convex_hull_3/test/Convex_hull_3/test_halfspace_intersections.cpp new file mode 100644 index 00000000000..2b683273e95 --- /dev/null +++ b/Convex_hull_3/test/Convex_hull_3/test_halfspace_intersections.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::Plane_3 Plane; +typedef K::Point_3 Point; +typedef CGAL::Polyhedron_3 Polyhedron_3; + +int main (void) { + + // generates supporting planes of the facets of a cube + std::list planes; + planes.push_back( Plane( 1, 0, 0,-1) ); // x= 1 + planes.push_back( Plane(-1, 0, 0,-1) ); // x=-1 + planes.push_back( Plane( 0, 1, 0,-1) ); // y= 1 + planes.push_back( Plane( 0,-1, 0,-1) ); // y=-1 + planes.push_back( Plane( 0, 0, 1,-1) ); // z= 1 + planes.push_back( Plane( 0, 0,-1,-1) ); // z=-1 + + // define polyhedron to hold the intersection + Polyhedron_3 P1, P2, P3, P4, P5; + + // test halfspace_intersection_3 with a point inside + CGAL::halfspace_intersection_3(planes.begin(), + planes.end(), + P1, + boost::make_optional(Point(0, 0, 0)) ); + + // test halfspace_intersection_3 with non point inside + CGAL::halfspace_intersection_3(planes.begin(), + planes.end(), + P2); + + // test halfspace_intersection_with_constructions_3 with a point inside + CGAL::halfspace_intersection_with_constructions_3( planes.begin(), + planes.end(), + P3, + boost::make_optional(Point(0, 0, 0)) ); + + // test halfspace_intersection_with_constructions_3 with non point inside + CGAL::halfspace_intersection_with_constructions_3( planes.begin(), + planes.end(), + P4); + + // test halfspace_intersection_with_constructions_3 with non point inside but with the kernel + CGAL::halfspace_intersection_with_constructions_3( planes.begin(), + planes.end(), + P5, + boost::optional(), + K()); + + assert(P1.size_of_vertices()==8 && P1.size_of_facets()==6); + assert(P2.size_of_vertices()==8 && P2.size_of_facets()==6); + assert(P3.size_of_vertices()==8 && P3.size_of_facets()==6); + assert(P4.size_of_vertices()==8 && P4.size_of_facets()==6); + assert(P5.size_of_vertices()==8 && P5.size_of_facets()==6); + + return 0; +} +