mirror of https://github.com/CGAL/cgal
Merge pull request #6081 from MaelRL/PMP-PM_to_PS_array_point-GF
Allow polygon soups to use an `std::array` point type in PM_to_PS
This commit is contained in:
commit
12028fed4a
|
|
@ -16,6 +16,7 @@
|
|||
#include <CGAL/license/Polygon_mesh_processing/repair.h>
|
||||
|
||||
#include <CGAL/algorithm.h>
|
||||
#include <CGAL/assertions.h>
|
||||
#include <CGAL/boost/graph/iterator.h>
|
||||
#include <CGAL/boost/graph/Named_function_parameters.h>
|
||||
#include <CGAL/boost/graph/named_params_helper.h>
|
||||
|
|
@ -26,8 +27,33 @@
|
|||
#include <boost/range/value_type.hpp>
|
||||
#include <boost/range/reference.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
namespace CGAL {
|
||||
namespace Polygon_mesh_processing {
|
||||
namespace internal {
|
||||
|
||||
template <typename PM_Point, typename PS_Point>
|
||||
struct PM_to_PS_point_converter
|
||||
{
|
||||
PS_Point operator()(const PM_Point& p) const
|
||||
{
|
||||
CGAL_static_assertion((std::is_convertible<PM_Point, PS_Point>::value));
|
||||
return PS_Point(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PM_Point, typename PS_FT>
|
||||
struct PM_to_PS_point_converter<PM_Point, std::array<PS_FT, 3> >
|
||||
{
|
||||
std::array<PS_FT, 3> operator()(const PM_Point& p) const
|
||||
{
|
||||
return { p[0], p[1], p[2] };
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
/// \ingroup PMP_repairing_grp
|
||||
///
|
||||
|
|
@ -84,20 +110,24 @@ void polygon_mesh_to_polygon_soup(const PolygonMesh& mesh,
|
|||
typedef typename GetVertexPointMap<PolygonMesh, NamedParameters>::const_type VPM;
|
||||
VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
|
||||
get_const_property_map(vertex_point, mesh));
|
||||
typedef typename boost::property_traits<VPM>::value_type PM_Point;
|
||||
|
||||
typedef CGAL::dynamic_vertex_property_t<std::size_t> Vertex_index;
|
||||
typedef typename boost::property_map<PolygonMesh, Vertex_index>::const_type VIM;
|
||||
VIM vim = get(Vertex_index(), mesh);
|
||||
|
||||
typedef typename boost::range_value<PointRange>::type PS_Point;
|
||||
typedef typename boost::range_value<PolygonRange>::type Polygon;
|
||||
|
||||
internal::PM_to_PS_point_converter<PM_Point, PS_Point> converter;
|
||||
|
||||
std::size_t index = points.size(); // so that multiple meshes can be put into the same soup
|
||||
CGAL::internal::reserve(points, points.size() + vertices(mesh).size());
|
||||
CGAL::internal::reserve(polygons, polygons.size() + faces(mesh).size());
|
||||
|
||||
for(const vertex_descriptor v : vertices(mesh))
|
||||
{
|
||||
points.emplace_back(get(vpm, v));
|
||||
points.push_back(converter(get(vpm, v)));
|
||||
put(vim, v, index++);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue