Created
February 19, 2021 19:52
-
-
Save ochafik/e55c52c50804bcb6f073968a57099e63 to your computer and use it in GitHub Desktop.
CGAL::Polyhedron_3 repair code with CGAL::Polygon_mesh_processing::repair_polygon_soup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2021 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
// | |
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h> | |
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h> | |
template <typename K> | |
std::shared_ptr<CGAL::Polyhedron_3<K>> repairPolyhedron(const CGAL::Polyhedron_3<K> &poly) | |
{ | |
std::vector<typename CGAL::Point_3<K>> points; | |
std::vector<std::vector<std::size_t>> polygons; | |
for (auto fi = poly.facets_begin(); fi != poly.facets_end(); ++fi) { | |
auto hc = fi->facet_begin(); | |
auto hc_end = hc; | |
std::vector<std::size_t> polygon; | |
do { | |
const auto &v = *((hc++)->vertex()); | |
auto vertexIndex = points.size(); | |
points.push_back(v.point()); | |
polygon.push_back(vertexIndex); | |
} while (hc != hc_end); | |
polygons.emplace_back(polygon); | |
} | |
CGAL::Polygon_mesh_processing::repair_polygon_soup( | |
points, polygons); //, CGAL::parameters::geom_traits(Array_traits())); | |
auto out = std::make_shared<CGAL::Polyhedron_3<K>>(); | |
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, polygons, *out); | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment