handle convex hull functionality for up to 3 points to a mutable graph and to an output iterator

This commit is contained in:
Konstantinos Katrioplas 2018-05-30 12:23:39 +02:00
parent ec000ea312
commit be4dfe77ac
6 changed files with 5181 additions and 46 deletions

View File

@ -7,9 +7,7 @@ namespace CGAL {
[`first`, `last`). The polyhedron `pm` is cleared, then [`first`, `last`). The polyhedron `pm` is cleared, then
the convex hull is stored in `pm`. Note that the convex hull will be triangulated, the convex hull is stored in `pm`. Note that the convex hull will be triangulated,
that is `pm` will contain only triangular facets. that is `pm` will contain only triangular facets.
if the convex hull is a point or a segment, endpoints will be added in pm as isolated vertices.
\pre There are at least four points in the range
[`first`, `last`) not all of which are collinear.
\tparam InputIterator must be an input iterator with a value type equivalent to `Traits::Point_3`. \tparam InputIterator must be an input iterator with a value type equivalent to `Traits::Point_3`.
\tparam PolygonMesh must be a model of `MutableFaceGraph`. \tparam PolygonMesh must be a model of `MutableFaceGraph`.
@ -69,24 +67,20 @@ const Traits& ch_traits = Default_traits);
/*! /*!
\ingroup PkgConvexHull3Functions \ingroup PkgConvexHull3Functions
\brief computes the convex hull of the set of points in the range. \brief copies in `out` the points on the convex hull of the points in `range`.
The result is put in an output iterator as a list of points.
\tparam InputRange a range of `Traits::Point_3`, model of `Range`. \tparam InputRange a range of `Traits::Point_3`, model of `ConstRange`.
Its iterator type is `ForwardIterator`.
\tparam OutputIterator must be an output iterator with a value type equivalent to `Traits::Point_3`. \tparam OutputIterator must be an output iterator with a value type equivalent to `Traits::Point_3`.
\tparam Traits must be model of the concept `ConvexHullTraits_3`. \tparam Traits must be model of the concept `ConvexHullTraits_3`.
For the purposes of checking the postcondition that the convex hull
is valid, `Traits` must also be a model of the concept
`IsStronglyConvexTraits_3`. Furthermore, `Traits` must define a type `Polygon_mesh` that is a model of
`MutableFaceGraph`.
If the kernel `R` of the points determined by the value type of `InputIterator` If the kernel `R` of the points from `InputRange`
is a kernel with exact predicates but inexact constructions is a kernel with exact predicates but inexact constructions
(in practice we check `R::Has_filtered_predicates_tag` is `Tag_true` and `R::FT` is a floating point type), (in practice we check `R::Has_filtered_predicates_tag` is `Tag_true` and `R::FT` is a floating point type),
then the default traits class of `convex_hull_3()` is `Convex_hull_traits_3<R>`, and `R` otherwise. then the default traits class of `convex_hull_3()` is `Convex_hull_traits_3<R>`, and `R` otherwise.
@param range the range of input points. @param range the range of input points.
@param out an output iterator where the list of points will be put. @param out an output iterator where the extreme points will be put.
@param traits an instance of `Traits`. @param traits an instance of `Traits`.
*/ */
template <class InputRange, class OutputIterator, class Traits> template <class InputRange, class OutputIterator, class Traits>

View File

@ -93,6 +93,15 @@ void make_tetrahedron(const Point& p0, const Point& p1, const Point& p2, const P
*(w.out)++ = p3; *(w.out)++ = p3;
} }
template <class Point_3, class OutputIterator>
void make_triangle(const Point_3& p1, const Point_3& p2, const Point_3& p3,
internal::Convex_hull_3::Output_iterator_wrapper<OutputIterator>& w)
{
++w.out++ = p1;
++w.out++ = p2;
++w.out++ = p3;
}
template <class TDS, class OutputIterator> template <class TDS, class OutputIterator>
void copy_face_graph(const TDS& tds, internal::Convex_hull_3::Output_iterator_wrapper<OutputIterator>& wrapper) void copy_face_graph(const TDS& tds, internal::Convex_hull_3::Output_iterator_wrapper<OutputIterator>& wrapper)
{ {
@ -104,6 +113,43 @@ void copy_face_graph(const TDS& tds, internal::Convex_hull_3::Output_iterator_wr
} }
} }
template <class Point_3, class OutputIterator>
void add_isolated_points(const Point_3& point,
internal::Convex_hull_3::Output_iterator_wrapper<OutputIterator>& w)
{
++w.out++ = point;
}
template <class Point_3, class Polyhedron_3>
void add_isolated_points(const Point_3& point, Polyhedron_3& P)
{
typedef typename boost::graph_traits<Polyhedron_3>::vertex_descriptor vertex_descriptor;
typedef typename boost::property_map<Polyhedron_3, CGAL::vertex_point_t>::type Vpmap;
Vpmap vpm = get(CGAL::vertex_point, P);
vertex_descriptor v = add_vertex(P);
put(vpm, v, point);
}
template <class Point_3, class OutputIterator>
void add_isolated_points(const Point_3& p1, const Point_3& p2,
internal::Convex_hull_3::Output_iterator_wrapper<OutputIterator>& w)
{
++w.out++ = p1;
++w.out++ = p2;
}
template <class Point_3, class Polyhedron_3>
void add_isolated_points(const Point_3& p1, const Point_3& p2, Polyhedron_3& P)
{
typedef typename boost::graph_traits<Polyhedron_3>::vertex_descriptor vertex_descriptor;
typedef typename boost::property_map<Polyhedron_3, CGAL::vertex_point_t>::type Vpmap;
Vpmap vpm = get(CGAL::vertex_point, P);
vertex_descriptor v1 = add_vertex(P);
vertex_descriptor v2 = add_vertex(P);
put(vpm, v1, p1);
put(vpm, v2, p2);
}
template <class Point_3, class OutputIterator> template <class Point_3, class OutputIterator>
void copy_ch2_to_face_graph(const std::list<Point_3>& CH_2, void copy_ch2_to_face_graph(const std::list<Point_3>& CH_2,
internal::Convex_hull_3::Output_iterator_wrapper<OutputIterator>& w) internal::Convex_hull_3::Output_iterator_wrapper<OutputIterator>& w)
@ -689,9 +735,6 @@ void non_coplanar_quickhull_3(std::list<typename Traits::Point_3>& points,
// CGAL_ch_postcondition(is_strongly_convex_3(P, traits)); // CGAL_ch_postcondition(is_strongly_convex_3(P, traits));
} }
template <class InputIterator, class Polyhedron_3, class Traits> template <class InputIterator, class Polyhedron_3, class Traits>
void void
ch_quickhull_polyhedron_3(std::list<typename Traits::Point_3>& points, ch_quickhull_polyhedron_3(std::list<typename Traits::Point_3>& points,
@ -907,8 +950,7 @@ convex_hull_3(InputIterator first, InputIterator beyond,
template <class InputIterator> template <class InputIterator>
void convex_hull_3(InputIterator first, InputIterator beyond, void convex_hull_3(InputIterator first, InputIterator beyond, Object& ch_object)
Object& ch_object)
{ {
typedef typename std::iterator_traits<InputIterator>::value_type Point_3; typedef typename std::iterator_traits<InputIterator>::value_type Point_3;
typedef typename internal::Convex_hull_3::Default_traits_for_Chull_3<Point_3>::type Traits; typedef typename internal::Convex_hull_3::Default_traits_for_Chull_3<Point_3>::type Traits;
@ -924,42 +966,69 @@ void convex_hull_3(InputIterator first, InputIterator beyond,
typedef typename Traits::Point_3 Point_3; typedef typename Traits::Point_3 Point_3;
typedef std::list<Point_3> Point_3_list; typedef std::list<Point_3> Point_3_list;
typedef typename Point_3_list::iterator P3_iterator; typedef typename Point_3_list::iterator P3_iterator;
typedef std::pair<P3_iterator,P3_iterator> P3_iterator_pair;
if(first == beyond)
return;
Point_3_list points(first, beyond); Point_3_list points(first, beyond);
CGAL_ch_precondition(points.size() > 3); clear(polyhedron);
// at least 4 points
typename Traits::Collinear_3 collinear = traits.collinear_3_object(); typename Traits::Collinear_3 collinear = traits.collinear_3_object();
typename Traits::Equal_3 equal = traits.equal_3_object(); typename Traits::Equal_3 equal = traits.equal_3_object();
P3_iterator point1_it = points.begin(); P3_iterator point1_it = points.begin();
P3_iterator point2_it = points.begin(); P3_iterator point2_it = points.begin();
point2_it++; point2_it++;
// find three that are not collinear
while (point2_it != points.end() && equal(*point1_it,*point2_it)) while (point2_it != points.end() && equal(*point1_it,*point2_it))
++point2_it; ++point2_it;
CGAL_ch_precondition_msg(point2_it != points.end(), // if there is only one point or all points are equal
"All points are equal; cannot construct polyhedron."); if(point2_it == points.end())
{
add_isolated_points(*point1_it, polyhedron);
return;
}
P3_iterator point3_it = point2_it; P3_iterator point3_it = point2_it;
++point3_it; ++point3_it;
CGAL_ch_precondition_msg(point3_it != points.end(), // if there are only two or only two points have different coordinates then return those.
"Only two points with different coordinates; cannot construct polyhedron."); if(point3_it == points.end())
{
add_isolated_points(*point1_it, *point2_it, polyhedron);
return;
}
// if there are 3 points not equal, then the third is not at points.end()
if(points.size() == 3)
{
if(collinear(*point1_it,*point2_it,*point3_it))
{
typedef typename Traits::Less_distance_to_point_3 Less_dist;
Less_dist less_dist = traits.less_distance_to_point_3_object();
P3_iterator_pair endpoints =
min_max_element(points.begin(), points.end(),
boost::bind(less_dist, *points.begin(), _1, _2),
boost::bind(less_dist, *points.begin(), _1, _2));
add_isolated_points(*endpoints.first, *endpoints.second, polyhedron);
}
else
{
make_triangle(*point1_it, *point2_it, *point3_it, polyhedron);
}
return;
}
else
{
while (point3_it != points.end() && collinear(*point1_it,*point2_it,*point3_it)) while (point3_it != points.end() && collinear(*point1_it,*point2_it,*point3_it))
++point3_it; ++point3_it;
CGAL_ch_precondition_msg(point3_it != points.end(),
"All points are collinear; cannot construct polyhedron.");
clear(polyhedron);
// result will be a polyhedron // result will be a polyhedron
internal::Convex_hull_3::ch_quickhull_polyhedron_3(points, point1_it, point2_it, point3_it, internal::Convex_hull_3::ch_quickhull_polyhedron_3(points, point1_it, point2_it, point3_it,
polyhedron, traits); polyhedron, traits);
}
} }
@ -975,7 +1044,7 @@ void convex_hull_3(InputIterator first, InputIterator beyond,
template <class InputRange, class OutputIterator, class Traits> template <class InputRange, class OutputIterator, class Traits>
OutputIterator OutputIterator
extreme_points_3(InputRange range, extreme_points_3(const InputRange& range,
OutputIterator out, OutputIterator out,
const Traits& traits) const Traits& traits)
{ {
@ -986,7 +1055,7 @@ extreme_points_3(InputRange range,
template <class InputRange, class OutputIterator> template <class InputRange, class OutputIterator>
OutputIterator OutputIterator
extreme_points_3(InputRange range, OutputIterator out) extreme_points_3(const InputRange& range, OutputIterator out)
{ {
typedef typename InputRange::const_iterator Iterator_type; typedef typename InputRange::const_iterator Iterator_type;
typedef typename std::iterator_traits<Iterator_type>::value_type Point_3; typedef typename std::iterator_traits<Iterator_type>::value_type Point_3;

View File

@ -0,0 +1,289 @@
0.041666666666666671 0.75 1 0 0 1
0 0.75 1 0 0 1
0 0.6875 1 0 0 1
0.041666666666666671 0.5 1 0 0 1
0 0.5 1 0 0 1
0 0.4375 1 0 0 1
0 0.5625 1 0 0 1
0 0.625 1 0 0 1
0.0625 0.6875 1 0 0 1
0 0.8125 1 0 0 1
0.071428571428571425 0.8214285714285714 1 0 0 1
0 0.875 1 0 0 1
0.0625 0.89583333333333337 1 0 0 1
0 0.9375 1 0 0 1
0.083333333333333329 0.625 1 0 0 1
0.0625 0.5625 1 0 0 1
0.0625 0.4375 1 0 0 1
0 0.375 1 0 0 1
0.0625 0.375 1 0 0 1
0 0.3125 1 0 0 1
0.083333333333333329 0.3125 1 0 0 1
0.125 0.875 1 0 0 1
0 0.25 1 0 0 1
0.041666666666666671 0.25 1 0 0 1
0 0.1875 1 0 0 1
0.75 0.041666666666666671 1 0 0 1
0.75 0.10416666666666667 1 0 0 1
0.6875 0.083333333333333329 1 0 0 1
0.7589285714285714 0.17857142857142858 1 0 0 1
0.6875 0.14583333333333334 1 0 0 1
0.63749999999999996 0.1125 1 0 0 1
0.625 0.0625 1 0 0 1
0.5625 0.0625 1 0 0 1
0.58333333333333337 0.125 1 0 0 1
0.5089285714285714 0.11607142857142858 1 0 0 1
0.5 0.041666666666666671 1 0 0 1
0.4375 0.0625 1 0 0 1
0.4375 0.125 1 0 0 1
0.38750000000000001 0.13750000000000001 1 0 0 1
0.375 0.083333333333333329 1 0 0 1
0.29166666666666669 0.1875 1 0 0 1
0.25892857142857145 0.11607142857142858 1 0 0 1
0.33333333333333331 0.125 1 0 0 1
0.3125 0.0625 1 0 0 1
0.25 0.041666666666666671 1 0 0 1
0.17857142857142858 0.071428571428571425 1 0 0 1
0.14583333333333334 0.1875 1 0 0 1
0.1875 0.14583333333333334 1 0 0 1
0.1875 0.1875 1 0 0 1
0.22916666666666666 0.1875 1 0 0 1
0.125 0.125 1 0 0 1
0.10416666666666667 0.0625 1 0 0 1
0.071428571428571425 0.17857142857142858 1 0 0 1
0.0625 0.10416666666666667 1 0 0 1
0.050000000000000003 0.050000000000000003 1 0 0 1
0.10416666666666667 0.25 1 0 0 1
0 0.125 1 0 0 1
0 0.0625 1 0 0 1
0 0 1 0 0 1
0.0625 0 1 0 0 1
0.125 0 1 0 0 1
0.1875 0 1 0 0 1
0.25 0 1 0 0 1
0.3125 0 1 0 0 1
0.375 0 1 0 0 1
0.4375 0 1 0 0 1
0.5 0 1 0 0 1
0.5625 0 1 0 0 1
0.625 0 1 0 0 1
0.6875 0 1 0 0 1
0.75 0 1 0 0 1
0.9375 0.10416666666666667 1 0 0 1
0.89583333333333337 0.0625 1 0 0 1
0.94999999999999996 0.050000000000000003 1 0 0 1
0.8125 0.1875 1 0 0 1
0.8125 0.14583333333333334 1 0 0 1
0.85416666666666663 0.1875 1 0 0 1
0.8125 0.22916666666666666 1 0 0 1
0.875 0.125 1 0 0 1
0.8214285714285714 0.071428571428571425 1 0 0 1
0.8839285714285714 0.25892857142857145 1 0 0 1
0.9285714285714286 0.17857142857142858 1 0 0 1
0.8125 0 1 0 0 1
0.875 0 1 0 0 1
0.9375 0 1 0 0 1
1 0 1 0 0 1
1 0.0625 1 0 0 1
1 0.1875 1 0 0 1
1 0.25 1 0 0 1
0.95833333333333337 0.25 1 0 0 1
1 0.125 1 0 0 1
1 0.3125 1 0 0 1
1 0.375 1 0 0 1
0.9375 0.3125 1 0 0 1
0.91666666666666663 0.375 1 0 0 1
1 0.5625 1 0 0 1
1 0.625 1 0 0 1
0.9375 0.5625 1 0 0 1
0.9375 0.625 1 0 0 1
1 0.6875 1 0 0 1
0.94999999999999996 0.94999999999999996 1 0 0 1
1 1 1 0 0 1
0.9375 1 1 0 0 1
1 0.9375 1 0 0 1
1 0.875 1 0 0 1
0.9375 0.89583333333333337 1 0 0 1
0.8125 1 1 0 0 1
0.75 1 1 0 0 1
0.75 0.95833333333333337 1 0 0 1
0.8214285714285714 0.9285714285714286 1 0 0 1
0.875 1 1 0 0 1
0.89583333333333337 0.9375 1 0 0 1
0.6875 1 1 0 0 1
0.95833333333333337 0.75 1 0 0 1
1 0.8125 1 0 0 1
0.9285714285714286 0.8214285714285714 1 0 0 1
1 0.75 1 0 0 1
0.875 0.875 1 0 0 1
0.95833333333333337 0.5 1 0 0 1
0.8125 0.8125 1 0 0 1
0.85416666666666663 0.8125 1 0 0 1
0.8125 0.85416666666666663 1 0 0 1
0.89583333333333337 0.75 1 0 0 1
0.91666666666666663 0.6875 1 0 0 1
0.9375 0.4375 1 0 0 1
1 0.4375 1 0 0 1
1 0.5 1 0 0 1
0.875 0.33333333333333331 1 0 0 1
0.86250000000000004 0.38750000000000001 1 0 0 1
0.8125 0.29166666666666669 1 0 0 1
0.75 0.25 1 0 0 1
0.35416666666666669 0.1875 1 0 0 1
0.6875 0.20833333333333334 1 0 0 1
0.5625 0.1875 1 0 0 1
0.625 0.16666666666666666 1 0 0 1
0.49107142857142855 0.19642857142857142 1 0 0 1
0.41666666666666669 0.1875 1 0 0 1
0.54166666666666663 0.25 1 0 0 1
0.6160714285714286 0.24107142857142858 1 0 0 1
0.6875 0.27083333333333331 1 0 0 1
0.7410714285714286 0.32142857142857145 1 0 0 1
0.8125 0.35416666666666669 1 0 0 1
0.6875 0.3125 1 0 0 1
0.88749999999999996 0.63749999999999996 1 0 0 1
0.875 0.58333333333333337 1 0 0 1
0.8214285714285714 0.7589285714285714 1 0 0 1
0.85416666666666663 0.6875 1 0 0 1
0.8839285714285714 0.5089285714285714 1 0 0 1
0.875 0.4375 1 0 0 1
0.58333333333333337 0.3125 1 0 0 1
0.64583333333333337 0.3125 1 0 0 1
0.8125 0.41666666666666669 1 0 0 1
0.6875 0.35416666666666669 1 0 0 1
0.75 0.39583333333333331 1 0 0 1
0.625 0.375 1 0 0 1
0.8125 0.5625 1 0 0 1
0.83333333333333337 0.625 1 0 0 1
0.8035714285714286 0.49107142857142855 1 0 0 1
0.75 0.45833333333333331 1 0 0 1
0.75 0.5 1 0 0 1
0.6785714285714286 0.42857142857142855 1 0 0 1
0.70833333333333337 0.8125 1 0 0 1
0.7410714285714286 0.8839285714285714 1 0 0 1
0.66666666666666663 0.875 1 0 0 1
0.75 0.54166666666666663 1 0 0 1
0.70833333333333337 0.5 1 0 0 1
0.72916666666666663 0.6875 1 0 0 1
0.7589285714285714 0.6160714285714286 1 0 0 1
0.79166666666666663 0.6875 1 0 0 1
0.6875 0.9375 1 0 0 1
0.75 0.75 1 0 0 1
0.11607142857142858 0.7410714285714286 1 0 0 1
0.3125 0.91666666666666663 1 0 0 1
0.36249999999999999 0.88749999999999996 1 0 0 1
0.375 0.9375 1 0 0 1
0.6875 0.64583333333333337 1 0 0 1
0.6875 0.6875 1 0 0 1
0.64583333333333337 0.8125 1 0 0 1
0.61250000000000004 0.86250000000000004 1 0 0 1
0.6785714285714286 0.7410714285714286 1 0 0 1
0.6785714285714286 0.5714285714285714 1 0 0 1
0.125 0.66666666666666663 1 0 0 1
0.13750000000000001 0.61250000000000004 1 0 0 1
0.1875 0.70833333333333337 1 0 0 1
0.1875 0.77083333333333337 1 0 0 1
0.3125 0.85416666666666663 1 0 0 1
0.375 0.83333333333333337 1 0 0 1
0.58333333333333337 0.8125 1 0 0 1
0.5625 0.875 1 0 0 1
0.49107142857142855 0.8839285714285714 1 0 0 1
0.5089285714285714 0.8035714285714286 1 0 0 1
0.64583333333333337 0.6875 1 0 0 1
0.64583333333333337 0.5 1 0 0 1
0.60416666666666663 0.4375 1 0 0 1
0.14583333333333334 0.3125 1 0 0 1
0.17857142857142858 0.24107142857142858 1 0 0 1
0.20833333333333334 0.3125 1 0 0 1
0.19642857142857142 0.5089285714285714 1 0 0 1
0.11607142857142858 0.49107142857142855 1 0 0 1
0.1875 0.4375 1 0 0 1
0.16666666666666666 0.375 1 0 0 1
0.32142857142857145 0.5714285714285714 1 0 0 1
0.35416666666666669 0.5 1 0 0 1
0.39583333333333331 0.5625 1 0 0 1
0.1875 0.64583333333333337 1 0 0 1
0.1125 0.36249999999999999 1 0 0 1
0.125 0.41666666666666669 1 0 0 1
0.25 0.45833333333333331 1 0 0 1
0.29166666666666669 0.5 1 0 0 1
0.25 0.5 1 0 0 1
0.125 0.5625 1 0 0 1
0.41666666666666669 0.6875 1 0 0 1
0.375 0.625 1 0 0 1
0.4375 0.625 1 0 0 1
0.5089285714285714 0.30357142857142855 1 0 0 1
0.5 0.375 1 0 0 1
0.42857142857142855 0.32142857142857145 1 0 0 1
0.54166666666666663 0.4375 1 0 0 1
0.5625 0.375 1 0 0 1
0.39583333333333331 0.4375 1 0 0 1
0.4375 0.39583333333333331 1 0 0 1
0.4375 0.4375 1 0 0 1
0.5714285714285714 0.5089285714285714 1 0 0 1
0.5 0.25 1 0 0 1
0.32142857142857145 0.25892857142857145 1 0 0 1
0.25 0.54166666666666663 1 0 0 1
0.35416666666666669 0.6875 1 0 0 1
0.3125 0.72916666666666663 1 0 0 1
0.3125 0.6875 1 0 0 1
0.45833333333333331 0.25 1 0 0 1
0.1875 0.58333333333333337 1 0 0 1
0.25 0.25 1 0 0 1
0.27083333333333331 0.3125 1 0 0 1
0.3125 0.3125 1 0 0 1
0.35416666666666669 0.3125 1 0 0 1
0.25 0.60416666666666663 1 0 0 1
0.39583333333333331 0.25 1 0 0 1
0.77083333333333337 0.8125 1 0 0 1
0.625 1 1 0 0 1
0.5 0.95833333333333337 1 0 0 1
0.5 1 1 0 0 1
0.4375 1 1 0 0 1
0.5625 0.9375 1 0 0 1
0.5625 1 1 0 0 1
0.25 0.95833333333333337 1 0 0 1
0.25 1 1 0 0 1
0.1875 1 1 0 0 1
0.3125 1 1 0 0 1
0.375 1 1 0 0 1
0.4375 0.9375 1 0 0 1
0.625 0.91666666666666663 1 0 0 1
0.17857142857142858 0.9285714285714286 1 0 0 1
0.125 1 1 0 0 1
0.10416666666666667 0.9375 1 0 0 1
0.0625 1 1 0 0 1
0.050000000000000003 0.94999999999999996 1 0 0 1
0 1 1 0 0 1
0.14583333333333334 0.8125 1 0 0 1
0.1875 0.85416666666666663 1 0 0 1
0.25 0.89583333333333337 1 0 0 1
0.41666666666666669 0.875 1 0 0 1
0.4375 0.8125 1 0 0 1
0.24107142857142858 0.38392857142857145 1 0 0 1
0.32142857142857145 0.42857142857142855 1 0 0 1
0.45833333333333331 0.5625 1 0 0 1
0.5 0.5 1 0 0 1
0.52083333333333337 0.5625 1 0 0 1
0.47916666666666669 0.4375 1 0 0 1
0.42857142857142855 0.49107142857142855 1 0 0 1
0.5 0.625 1 0 0 1
0.5625 0.60416666666666663 1 0 0 1
0.5625 0.5625 1 0 0 1
0.3125 0.35416666666666669 1 0 0 1
0.375 0.375 1 0 0 1
0.49107142857142855 0.6964285714285714 1 0 0 1
0.5714285714285714 0.6785714285714286 1 0 0 1
0.60416666666666663 0.5625 1 0 0 1
0.625 0.625 1 0 0 1
0.60416666666666663 0.75 1 0 0 1
0.54166666666666663 0.75 1 0 0 1
0.5 0.75 1 0 0 1
0.3125 0.64583333333333337 1 0 0 1
0.25892857142857145 0.6785714285714286 1 0 0 1
0.45833333333333331 0.75 1 0 0 1
0.25 0.75 1 0 0 1
0.24107142857142858 0.8214285714285714 1 0 0 1
0.1875 0.8125 1 0 0 1
0.3125 0.79166666666666663 1 0 0 1
0.38392857142857145 0.7589285714285714 1 0 0 1

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,15 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/convex_hull_3.h> #include <CGAL/convex_hull_3.h>
#include <CGAL/Convex_hull_traits_3.h> #include <CGAL/Convex_hull_traits_3.h>
#include <CGAL/Exact_rational.h> #include <CGAL/Exact_rational.h>
#include <CGAL/Cartesian.h> #include <CGAL/Cartesian.h>
#include <CGAL/Polyhedron_3.h> #include <CGAL/Polyhedron_3.h>
#include <CGAL/boost/graph/named_params_helper.h>
#include <vector> #include <vector>
#include <cassert> #include <cassert>
#include <algorithm>
#include <fstream>
typedef CGAL::Exact_rational NT; typedef CGAL::Exact_rational NT;
typedef CGAL::Cartesian<NT> K; typedef CGAL::Cartesian<NT> K;
@ -12,6 +17,7 @@ typedef CGAL::Convex_hull_traits_3<K> Traits;
typedef Traits::Polygon_mesh Polyhedron_3; typedef Traits::Polygon_mesh Polyhedron_3;
typedef K::Point_3 Point_3; typedef K::Point_3 Point_3;
void test_function_overload() void test_function_overload()
{ {
std::vector<Point_3> points; std::vector<Point_3> points;
@ -23,28 +29,188 @@ void test_function_overload()
points.push_back(Point_3(2,5,3)); points.push_back(Point_3(2,5,3));
points.push_back(Point_3(1,3,2)); points.push_back(Point_3(1,3,2));
Polyhedron_3 polyhedron;
CGAL::convex_hull_3(points.begin(), points.end(), polyhedron);
std::vector<Point_3> extreme_points; std::vector<Point_3> extreme_points;
CGAL::extreme_points_3(points, std::back_inserter(extreme_points)); CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.size() == 5);
Polyhedron_3 polyhedron;
CGAL::convex_hull_3(points.begin(), points.end(), polyhedron);
typedef Polyhedron_3::Point_iterator Point_iterator; typedef Polyhedron_3::Point_iterator Point_iterator;
int i = 0;
for (Point_iterator p_it = polyhedron.points_begin(); p_it != polyhedron.points_end(); ++p_it) for (Point_iterator p_it = polyhedron.points_begin(); p_it != polyhedron.points_end(); ++p_it)
{ {
Point_3 p = *p_it; Point_3 p = *p_it;
CGAL_assertion(p == extreme_points[i]); CGAL_assertion(std::find(extreme_points.begin(), extreme_points.end(), p) != extreme_points.end());
i++;
} }
} }
void test_triangulated_cube(const char* fname)
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> SurfaceMesh;
std::ifstream input(fname);
SurfaceMesh mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
std::cerr << fname << " is not a valid off file.\n";
exit(1);
}
std::vector<Point_3> mesh_points;
typedef typename boost::property_map<SurfaceMesh, boost::vertex_point_t>::type Pmap;
Pmap vpmap = get_property_map(boost::vertex_point, mesh);
typedef typename boost::graph_traits<SurfaceMesh>::vertex_descriptor vertex_descriptor;
BOOST_FOREACH(vertex_descriptor v, vertices(mesh))
{
Point_3 p = get(vpmap, v);
mesh_points.push_back(p);
}
std::vector<Point_3> extreme_points;
CGAL::extreme_points_3(mesh_points, std::back_inserter(extreme_points)) ;
CGAL_assertion(extreme_points.size() == 8);
}
void test_coplanar_points(const char* fname)
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point_3;
std::ifstream input(fname);
std::vector<Point_3> points;
if(input)
{
Point_3 p;
int i = 0;
while(input >> p)
{
if(i % 2 == 0) // avoid normals in .xyz file
{
points.push_back(p);
}
++i;
}
}
else
std::cerr << "error loading file\n";
CGAL_assertion(points.size() == 289);
std::vector<Point_3> convex_hull;
CGAL::extreme_points_3(points, std::back_inserter(convex_hull));
CGAL_assertion(convex_hull.size() == 4);
}
void test_3_points()
{
std::vector<Point_3> points;
points.push_back(Point_3(0,0,0));
points.push_back(Point_3(10,0,0));
points.push_back(Point_3(0,10,0));
Polyhedron_3 polyhedron;
CGAL::convex_hull_3(points.begin(), points.end(), polyhedron);
std::vector<Point_3> convex_polyhedron(polyhedron.points_begin(), polyhedron.points_end());
CGAL_assertion(convex_polyhedron.size() == 3);
std::vector<Point_3> extreme_points;
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(convex_polyhedron.size() == 3);
typedef Polyhedron_3::Point_iterator Point_iterator;
for (Point_iterator p_it = polyhedron.points_begin(); p_it != polyhedron.points_end(); ++p_it)
{
Point_3 p = *p_it;
CGAL_assertion(std::find(extreme_points.begin(), extreme_points.end(), p) != extreme_points.end());
}
}
void test_3_collinear()
{
std::vector<Point_3> points;
points.push_back(Point_3(0,0,0));
points.push_back(Point_3(1,0,0));
points.push_back(Point_3(2,0,0));
Polyhedron_3 polyhedron;
CGAL::convex_hull_3(points.begin(), points.end(), polyhedron);
std::vector<Point_3> convex_polyhedron(polyhedron.points_begin(), polyhedron.points_end());
CGAL_assertion(convex_polyhedron.size() == 2);
std::vector<Point_3> extreme_points;
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(convex_polyhedron.size() == 2);
typedef Polyhedron_3::Point_iterator Point_iterator;
for (Point_iterator p_it = polyhedron.points_begin(); p_it != polyhedron.points_end(); ++p_it)
{
Point_3 p = *p_it;
CGAL_assertion(std::find(extreme_points.begin(), extreme_points.end(), p) != extreme_points.end());
}
}
void test_up_to_3_extreme_points()
{
std::vector<Point_3> points;
std::vector<Point_3> extreme_points;
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.empty());
Point_3 p1(0, 0, 0);
points.push_back(p1);
extreme_points.clear();
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.size() == 1);
Point_3 p2(1, 0, 0);
points.push_back(p2);
extreme_points.clear();
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.size() == 2);
Point_3 p3(1, 1, 0);
points.push_back(p3);
extreme_points.clear();
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.size() == 3);
}
void test_equal_points()
{
std::vector<Point_3> points;
std::vector<Point_3> extreme_points;
// test two equal
Point_3 p1(0, 0, 0);
points.push_back(p1);
points.push_back(p1);
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.size() == 1);
// test many equal
extreme_points.clear();
for(int i = 0; i < 10; ++i)
points.push_back(p1);
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.size() == 1);
// test with only 2 different
extreme_points.clear();
Point_3 p3(0.1, 0, 0);
points.push_back(p3);
CGAL::extreme_points_3(points, std::back_inserter(extreme_points));
CGAL_assertion(extreme_points.size() == 2);
}
int main() int main()
{ {
test_function_overload(); test_function_overload();
test_3_points();
test_up_to_3_extreme_points();
test_3_collinear();
test_triangulated_cube("data/cube_meshed.off");
test_coplanar_points("data/coplanar_points.xyz");
test_equal_points();
return 0; return 0;
} }

View File

@ -44,6 +44,10 @@ Release date: September 2018
to reflect the real needs of the code (some types and operators were used to reflect the real needs of the code (some types and operators were used
in the code but did not appear in the concepts). in the code but did not appear in the concepts).
### Convex hull 3
- Added the function `extreme_points_3()` computing the
points on the convex hull without underlying connectivity.
### Polygon Mesh Processing ### Polygon Mesh Processing
- Added a function to apply a transformation to a mesh: - Added a function to apply a transformation to a mesh:
- `CGAL::Polygon_mesh_processing::transform()` - `CGAL::Polygon_mesh_processing::transform()`
@ -83,7 +87,6 @@ Release date: September 2018
- Improve the function `CGAL::Euler::collapse_edge` so that the target - Improve the function `CGAL::Euler::collapse_edge` so that the target
vertex of the collapsed edge is always kept after the collapse. vertex of the collapsed edge is always kept after the collapse.
Release 4.12 Release 4.12
------------ ------------