#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/jet_estimate_normals.h>
#include <CGAL/mst_orient_normals.h>
using Generator = CGAL::Random_points_on_sphere_3<Point_3>;
struct Custom_point_map
{
using key_type = std::size_t;
using category = boost::readable_property_map_tag;
double *x, *y, *z;
Custom_point_map (double* x = nullptr, double* y = nullptr, double* z = nullptr)
: x(x), y(y), z(z) { }
friend Point_3 get (
const Custom_point_map& map, std::size_t idx)
{
return Point_3 (map.x[idx], map.y[idx], map.z[idx]);
}
};
struct Custom_normal_map
{
using key_type = std::size_t;
using category = boost::read_write_property_map_tag;
double *buffer;
Custom_normal_map (double* buffer = nullptr)
: buffer (buffer) { }
friend Vector_3 get (
const Custom_normal_map& map, std::size_t idx)
{
map.buffer[idx * 3 + 1],
map.buffer[idx * 3 + 2]);
}
friend void put (
const Custom_normal_map& map, std::size_t idx,
const Vector_3& vector_3)
{
map.buffer[idx * 3 ] = vector_3.x();
map.buffer[idx * 3 + 1] = vector_3.y();
map.buffer[idx * 3 + 2] = vector_3.z();
}
};
int main()
{
constexpr std::size_t nb_points = 1000;
double x[nb_points];
double y[nb_points];
double z[nb_points];
Generator generator;
for (std::size_t i = 0; i < nb_points; ++ i)
{
x[i] = p.x();
y[i] = p.y();
z[i] = p.z();
}
double normals[3 *nb_points];
std::vector<std::size_t> indices;
indices.reserve (nb_points);
for (std::size_t i = 0; i < nb_points; ++ i)
indices.push_back(i);
CGAL::jet_estimate_normals<CGAL::Sequential_tag>
(indices, 12,
CGAL::parameters::point_map (Custom_point_map(x,y,z)).
normal_map (Custom_normal_map(normals)));
(indices, 12,
CGAL::parameters::point_map (Custom_point_map(x,y,z)).
normal_map (Custom_normal_map(normals)));
for (std::size_t i = 0; i < 10; ++ i)
std::cerr << "Point(" << i << ") = " << x[i] << " " << y[i] << " " << z[i]
<< "\tNormal(" << i << ") = "
<< normals[3*i] << " " << normals[3*i+1] << " " << normals[3*i+2] << std::endl;
return EXIT_SUCCESS;
}
PointRange::iterator mst_orient_normals(PointRange &points, unsigned int k, const NamedParameters &np=parameters::default_values())