#include <CGAL/trace.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Surface_mesh_default_triangulation_3.h>
#include <CGAL/make_surface_mesh.h>
#include <CGAL/Implicit_surface_3.h>
#include <CGAL/IO/facets_in_complex_2_to_triangle_mesh.h>
#include <CGAL/Poisson_reconstruction_function.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/compute_average_spacing.h>
#include <CGAL/Polygon_mesh_processing/distance.h>
#include <vector>
#include <fstream>
typedef CGAL::Point_with_normal_3<Kernel> Point_with_normal;
typedef std::vector<Point_with_normal> PointList;
typedef CGAL::Poisson_reconstruction_function<Kernel> Poisson_reconstruction_function;
typedef CGAL::Surface_mesh_default_triangulation_3 STr;
typedef CGAL::Surface_mesh_complex_2_in_triangulation_3<STr> C2t3;
typedef CGAL::Implicit_surface_3<Kernel, Poisson_reconstruction_function> Surface_3;
int main(void)
{
FT sm_angle = 20.0;
FT sm_radius = 30;
FT sm_distance = 0.375;
PointList points;
std::ifstream stream("data/kitten.xyz");
if (!stream ||
!CGAL::read_xyz_points(
stream,
std::back_inserter(points),
CGAL::parameters::normal_map(CGAL::make_normal_of_point_with_normal_map(PointList::value_type()))))
{
std::cerr << "Error: cannot read file data/kitten.xyz" << std::endl;
return EXIT_FAILURE;
}
Poisson_reconstruction_function function(points.begin(), points.end(),
CGAL::make_normal_of_point_with_normal_map(PointList::value_type()) );
if ( ! function.compute_implicit_function() )
return EXIT_FAILURE;
FT average_spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag>(points, 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<STr> 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 EXIT_FAILURE;
std::ofstream out("kitten_poisson-20-30-0.375.off");
Polyhedron output_mesh;
CGAL::facets_in_complex_2_to_triangle_mesh(c2t3, output_mesh);
out << output_mesh;
double max_dist =
points,
4000);
std::cout << "Max distance to point_set: " << max_dist << std::endl;
return EXIT_SUCCESS;
}