fix the way to specify the point inside the intersection of halfspaces

This commit is contained in:
Sébastien Loriot 2015-05-11 17:52:53 +02:00
parent a0e2dd6e6f
commit ebfcedce38
6 changed files with 74 additions and 50 deletions

View File

@ -23,6 +23,6 @@ This version does not construct the dual points explicitely but uses a special t
template <class PlaneIterator, class Polyhedron>
void halfspace_intersection_3 (PlaneIterator begin, PlaneIterator end,
Polyhedron &P,
boost::optional<Polyhedron::Vertex::Point_3> origin);
boost::optional<Polyhedron::Vertex::Point_3> origin = boost::none);
} /* namespace CGAL */

View File

@ -24,7 +24,7 @@ template <class PlaneIterator, class Polyhedron, class Traits>
void halfspace_intersection_with_constructions_3(PlaneIterator pbegin,
PlaneIterator pend,
Polyhedron &P,
boost::optional<Polyhedron::Vertex::Point_3> origin,
boost::optional<Polyhedron::Vertex::Point_3> origin = boost::none,
const Traits & ch_traits = Default_traits);
} /* namespace CGAL */

View File

@ -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;
}

View File

@ -262,7 +262,7 @@ namespace CGAL
template <class PlaneIterator, class Polyhedron>
void halfspace_intersection_3 (PlaneIterator begin, PlaneIterator end,
Polyhedron &P,
boost::optional<typename Polyhedron::Vertex::Point_3> const& origin) {
boost::optional<typename Polyhedron::Vertex::Point_3> 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 <class PlaneIterator, class Polyhedron>
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 <class PlaneIterator, class Polyhedron>
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<typename Polyhedron::Vertex::Point_3>(origin));
halfspace_intersection_3(begin, end , P, boost::make_optional(origin));
}
#endif
} // namespace CGAL
#endif // CGAL_HALFSPACE_INTERSECTION_3_H

View File

@ -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 <class PlaneIterator, class Polyhedron, class Traits>
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<typename Polyhedron::Vertex::Point_3>(origin),
ch_traits);
}
// Compute the intersection of halfspaces by constructing explicitly
// the dual points with the default traits class for convex_hull_3.
template <class PlaneIterator, class Polyhedron>
void halfspace_intersection_with_constructions_3 (PlaneIterator pbegin,
PlaneIterator pend,
Polyhedron &P,
boost::optional<typename Polyhedron::Vertex::Point_3> const& origin) {
boost::optional<typename Polyhedron::Vertex::Point_3> const& origin = boost::none) {
typedef typename Kernel_traits<typename Polyhedron::Vertex::Point_3>::Kernel K;
typedef typename K::Point_3 Point_3;
typedef typename internal::Convex_hull_3::Default_traits_for_Chull_3<Point_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 <class PlaneIterator, class Polyhedron>
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<typename Polyhedron::Vertex::Point_3>(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 <class PlaneIterator, class Polyhedron>
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

View File

@ -0,0 +1,64 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Convex_hull_3/dual/halfspace_intersection_3.h>
#include <CGAL/Convex_hull_3/dual/halfspace_intersection_with_constructions_3.h>
#include <CGAL/point_generators_3.h>
#include <list>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Plane_3 Plane;
typedef K::Point_3 Point;
typedef CGAL::Polyhedron_3<K> Polyhedron_3;
int main (void) {
// generates supporting planes of the facets of a cube
std::list<Plane> 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<Point>(),
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;
}