From 865a388e31ed82032f8560933a8693c247c1b4b2 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Mon, 2 Jan 2017 11:57:37 +0100 Subject: [PATCH] Add file with simple function to call poisson reconstruction --- .../CGAL/poisson_surface_reconstruction.h | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Poisson_surface_reconstruction_3/include/CGAL/poisson_surface_reconstruction.h diff --git a/Poisson_surface_reconstruction_3/include/CGAL/poisson_surface_reconstruction.h b/Poisson_surface_reconstruction_3/include/CGAL/poisson_surface_reconstruction.h new file mode 100644 index 00000000000..ba0a2d3c606 --- /dev/null +++ b/Poisson_surface_reconstruction_3/include/CGAL/poisson_surface_reconstruction.h @@ -0,0 +1,104 @@ +// Copyright (c) 2017 GeometryFactory (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Simon Giraudot + +#ifndef CGAL_POISSON_SURFACE_RECONSTRUCTION_H +#define CGAL_POISSON_SURFACE_RECONSTRUCTION_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { + + + template class HDS, + typename Alloc> + bool + poisson_surface_reconstruction(PointInputIterator begin, + PointInputIterator end, + PointMap point_map, + NormalMap normal_map, + Polyhedron_3& output_mesh, + typename Kernel::FT sm_angle = 20.0, + typename Kernel::FT sm_radius = 30.0, + typename Kernel::FT sm_distance = 0.375) + { + typedef typename Kernel::FT FT; + typedef typename Kernel::Point_3 Point; + typedef typename Kernel::Sphere_3 Sphere; + typedef CGAL::Poisson_reconstruction_function Poisson_reconstruction_function; + typedef CGAL::Surface_mesh_default_triangulation_3 STr; + typedef CGAL::Surface_mesh_complex_2_in_triangulation_3 C2t3; + typedef CGAL::Implicit_surface_3 Surface_3; + + Poisson_reconstruction_function function(begin, end, point_map, normal_map); + if ( ! function.compute_implicit_function() ) + return false; + + FT average_spacing = CGAL::compute_average_spacing + (begin, end, point_map, 6); + + Point inner_point = function.get_inner_point(); + Sphere bsphere = function.bounding_sphere(); + FT radius = std::sqrt(bsphere.squared_radius()); + + FT sm_sphere_radius = 5.0 * radius; + FT sm_dichotomy_error = sm_distance * average_spacing / 1000.0; + + Surface_3 surface(function, + Sphere (inner_point, sm_sphere_radius * sm_sphere_radius), + sm_dichotomy_error / sm_sphere_radius); + + CGAL::Surface_mesh_default_criteria_3 criteria (sm_angle, + sm_radius * average_spacing, + sm_distance * average_spacing); + + STr tr; + C2t3 c2t3(tr); + + CGAL::make_surface_mesh(c2t3, + surface, + criteria, + CGAL::Manifold_with_boundary_tag()); + + if(tr.number_of_vertices() == 0) + return false; + + CGAL::output_surface_facets_to_polyhedron(c2t3, output_mesh); + + return true; + } + + +} + + +#endif // CGAL_POISSON_SURFACE_RECONSTRUCTION_H