Skip to content

Commit

Permalink
Add example for sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
afabri committed Dec 12, 2023
1 parent 43213ee commit 6ca34b6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(Polygon_mesh_processing_Examples)
# CGAL and its components
find_package(CGAL REQUIRED)

create_single_source_cgal_program("sample_example.cpp" )
create_single_source_cgal_program("extrude.cpp" )
create_single_source_cgal_program("polyhedral_envelope.cpp" )
create_single_source_cgal_program("polyhedral_envelope_of_triangle_soup.cpp" )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/distance.h>

#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Point_set_3.h>
#include <iostream>
#include <string>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point;

typedef CGAL::Point_set_3<Point> Point_set;

typedef CGAL::Surface_mesh<Point> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;

namespace PMP = CGAL::Polygon_mesh_processing;

int main(int argc, char* argv[])
{
const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/eight.off");

Mesh mesh;
if(!PMP::IO::read_polygon_mesh(filename, mesh))
{
std::cerr << "Invalid input." << std::endl;
return 1;
}

const double points_per_face = (argc > 2) ? atof(argv[2]) : 10;

std::vector<Point> points;

PMP::sample_triangle_mesh(mesh, std::back_inserter(points), CGAL::parameters::number_of_points_per_face(points_per_face));

std::cout.precision(17);
for(const Point& p : points){
std::cout << p << std::endl;
}

Point_set point_set;
PMP::sample_triangle_mesh(mesh,
point_set.point_back_inserter(),
CGAL::parameters::point_map(point_set.point_push_map()));

std::cout << point_set.number_of_points() << std::endl;
return 0;
}

0 comments on commit 6ca34b6

Please sign in to comment.