Created
March 22, 2021 16:07
-
-
Save janetournois/e35741be3768945c437c61cad623a420 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | |
#include <CGAL/Surface_mesh.h> | |
#include <CGAL/Variational_shape_approximation.h> | |
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; | |
typedef Kernel::FT FT; | |
typedef CGAL::Surface_mesh<Kernel::Point_3> Mesh; | |
typedef boost::property_map<Mesh, boost::vertex_point_t>::type Vertex_point_map; | |
typedef CGAL::Variational_shape_approximation<Mesh, Vertex_point_map> L21_approx; | |
typedef L21_approx::Error_metric L21_metric; | |
int main() | |
{ | |
const char* file_name = "sphere_remeshed.off"; | |
const FT drop = FT(1e-2); | |
Mesh mesh; | |
std::ifstream input(file_name); | |
if (!input || !(input >> mesh) || !CGAL::is_triangle_mesh(mesh)) { | |
std::cout << "Invalid input file." << std::endl; | |
return false; | |
} | |
std::cout << "Testing \"" << file_name << '\"' << std::endl; | |
// algorithm instance | |
L21_metric error_metric(mesh, | |
get(boost::vertex_point, const_cast<Mesh &>(mesh))); | |
L21_approx approx(mesh, | |
get(boost::vertex_point, const_cast<Mesh &>(mesh)), | |
error_metric); | |
// approximation, seeding from error, drop to the target error incrementally | |
const std::size_t num_iterations = 20; | |
const std::size_t inner_iterations = 5; | |
approx.initialize_seeds( | |
CGAL::parameters::seeding_method(CGAL::Surface_mesh_approximation::RANDOM) | |
.min_error_drop(drop) | |
.number_of_relaxations(inner_iterations)); | |
approx.run(num_iterations); | |
std::cout << "#proxies " << approx.number_of_proxies() << std::endl; | |
// meshing | |
if (approx.extract_mesh(CGAL::parameters::subdivision_ratio(5.0))) { | |
std::cout << "Succeeded." << std::endl; | |
return EXIT_SUCCESS; | |
} | |
std::cout << "Failed." << std::endl; | |
return EXIT_FAILURE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment