CGAL 6.1 - Point Set Processing

Loading...
Searching...
No Matches
Point_set_processing_3/poisson_eliminate_from_mesh_example.cpp
#include <vector>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/poisson_eliminate.h>
#include <CGAL/Polygon_mesh_processing/distance.h>
#include <CGAL/IO/write_points.h>
using Point_3 = CGAL::Simple_cartesian<double>::Point_3;
using Mesh = CGAL::Surface_mesh<Point_3>;
int main(int argc, char* argv[])
{
std::vector<Point_3> points;
std::size_t sampling_size = 20000;
std::size_t target_size = 10000;
Mesh mesh;
if (argc == 4) {
target_size = std::atoi(argv[2]);
sampling_size = std::atoi(argv[3]);
if (sampling_size < target_size) {
std::cout << "usage: poisson_eliminate_from_mesh_example input_mesh target_size sampling_size"
<< std::endl << "with sampling_size > target_size, e.g., by a factor of 2" << std::endl;
return -1;
}
}
if (argc == 3) {
target_size = std::atoi(argv[2]);
sampling_size = 2 * target_size;
}
if (argc < 2)
CGAL::IO::read_polygon_mesh(CGAL::data_file_path("meshes/elephant.off"), mesh);
else
CGAL::IO::read_polygon_mesh(argv[1], mesh);
if (mesh.number_of_faces() == 0) {
std::cout << "mesh could not be loaded" << std::endl;
std::cout << "usage: poisson_eliminate_from_mesh_example input_mesh target_size sampling_size"
<< std::endl << "with sampling_size > target_size, e.g., by a factor of 2" << std::endl;
return -1;
}
points.reserve(sampling_size);
CGAL::Polygon_mesh_processing::sample_triangle_mesh(mesh,
std::back_inserter(points),
CGAL::parameters::number_of_points_on_faces(sampling_size)
.do_sample_vertices(false)
.do_sample_edges(false));
CGAL::IO::write_points("out_sampled.xyz", points, CGAL::parameters::stream_precision(17));
std::vector<Point_3> output;
output.reserve(target_size);
CGAL::poisson_eliminate(points, target_size, std::back_inserter(output));
CGAL::IO::write_points("out_poisson_eliminated.xyz", output, CGAL::parameters::stream_precision(17));
return 0;
}
CGAL::Polygon_mesh_processing::sample_triangle_mesh
PointOutputIterator sample_triangle_mesh(const TriangleMesh &tm, PointOutputIterator out, const NamedParameters &np=parameters::default_values())
CGAL::IO::read_polygon_mesh
bool read_polygon_mesh(const std::string &fname, Graph &g, const NamedParameters &np=parameters::default_values())
CGAL::poisson_eliminate
void poisson_eliminate(const PointRange &points, std::size_t number_of_points, OutputIterator output, const NamedParameters &np=parameters::default_values())
performs Poisson disk elimination with a desired output size.
Definition: poisson_eliminate.h:276
CGAL::IO::write_points
bool write_points(const std::string &fname, const PointRange &points, const NamedParameters &np=parameters::default_values(),)
writes the range of points with properties to a file.
Definition: write_points.h:92
CGAL::Simple_cartesian