mirror of https://github.com/CGAL/cgal
refactor does_polygon_soup_self_intersect
This commit is contained in:
parent
fe4193f9eb
commit
bcfd317c17
|
|
@ -20,9 +20,15 @@
|
||||||
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
|
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
|
||||||
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
||||||
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
|
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
|
||||||
|
#include <CGAL/tags.h>
|
||||||
|
#include <CGAL/type_traits.h>
|
||||||
|
|
||||||
#include <boost/iterator/transform_iterator.hpp>
|
#include <boost/iterator/transform_iterator.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace CGAL::Polygon_mesh_processing {
|
namespace CGAL::Polygon_mesh_processing {
|
||||||
|
|
||||||
template <class ConcurrencyTag = Sequential_tag,
|
template <class ConcurrencyTag = Sequential_tag,
|
||||||
|
|
@ -33,20 +39,26 @@ bool does_polygon_soup_self_intersect(const PointRange& points,
|
||||||
PolygonRange polygons,
|
PolygonRange polygons,
|
||||||
const CGAL_NP_CLASS& np = parameters::default_values())
|
const CGAL_NP_CLASS& np = parameters::default_values())
|
||||||
{
|
{
|
||||||
//let's be a bit more permissive and allow duplicated vertices
|
using std::cbegin;
|
||||||
auto pm = parameters::choose_parameter<typename GetPointMap<PointRange, CGAL_NP_CLASS>::const_type>(parameters::get_parameter(np, internal_np::point_map));
|
using std::cend;
|
||||||
using Point_3 = typename boost::property_traits<decltype(pm)>::value_type;
|
using std::size;
|
||||||
using PointRange_const_iterator = typename PointRange::const_iterator;
|
|
||||||
using PointRange_value_type = typename std::iterator_traits<PointRange_const_iterator>::value_type;
|
|
||||||
auto to_point =[pm](const PointRange_value_type& v) { return get(pm, v); };
|
|
||||||
|
|
||||||
std::vector<Point_3> unique_points(boost::make_transform_iterator(points.begin(), to_point),
|
using Default_pm = typename GetPointMap<PointRange, CGAL_NP_CLASS>::const_type;
|
||||||
boost::make_transform_iterator(points.end(), to_point));
|
auto pm = parameters::choose_parameter<Default_pm>(parameters::get_parameter(np, internal_np::point_map));
|
||||||
|
using Point_3 = CGAL::cpp20::remove_cvref_t<decltype(get(pm, *cbegin(points)))>;
|
||||||
|
|
||||||
|
//let's be a bit more permissive and allow duplicated vertices
|
||||||
|
auto to_point =[pm](const auto& v) { return get(pm, v); };
|
||||||
|
auto first = boost::make_transform_iterator(cbegin(points), to_point);
|
||||||
|
auto last = boost::make_transform_iterator(cend(points), to_point);
|
||||||
|
|
||||||
|
std::vector<Point_3> unique_points(first, last);
|
||||||
|
|
||||||
merge_duplicate_points_in_polygon_soup(unique_points, polygons);
|
merge_duplicate_points_in_polygon_soup(unique_points, polygons);
|
||||||
|
|
||||||
bool is_pure_triangles = std::all_of(polygons.begin(), polygons.end(),
|
bool is_pure_triangles = std::all_of(CGAL_MAYBE_EXEC_POLICY(ConcurrencyTag)
|
||||||
[](const auto&f) { return f.size() == 3; });
|
cbegin(polygons), cend(polygons),
|
||||||
|
[](const auto&f) { return size(f) == 3; });
|
||||||
if(is_pure_triangles)
|
if(is_pure_triangles)
|
||||||
{
|
{
|
||||||
// if the polygon soup is pure triangles,
|
// if the polygon soup is pure triangles,
|
||||||
|
|
@ -55,15 +67,13 @@ bool does_polygon_soup_self_intersect(const PointRange& points,
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, we need to triangulate the polygons beforehand
|
// otherwise, we need to triangulate the polygons beforehand
|
||||||
using Polygon = CGAL::cpp20::remove_cvref_t<decltype(*polygons.begin())>;
|
using Id = CGAL::cpp20::remove_cvref_t<decltype(*cbegin(*cbegin(polygons)))>;
|
||||||
using Id = typename std::iterator_traits<typename Polygon::const_iterator>::value_type;
|
using New_polygon_type = std::vector<Id>;
|
||||||
auto to_std_vector = [](const Polygon& poly)
|
|
||||||
{
|
|
||||||
return std::vector<Id>(poly.begin(), poly.end());
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<std::vector<Id>> triangles(boost::make_transform_iterator(polygons.begin(), to_std_vector),
|
auto to_std_vector = [](const auto& poly) { return New_polygon_type{cbegin(poly), cend(poly)}; };
|
||||||
boost::make_transform_iterator(polygons.end(), to_std_vector));
|
|
||||||
|
std::vector<New_polygon_type> triangles(boost::make_transform_iterator(cbegin(polygons), to_std_vector),
|
||||||
|
boost::make_transform_iterator(cend(polygons), to_std_vector));
|
||||||
bool OK = triangulate_polygons(points, triangles, np);
|
bool OK = triangulate_polygons(points, triangles, np);
|
||||||
|
|
||||||
if (!OK) return false;
|
if (!OK) return false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue