From 7f515a63d41bf43d83bb5d65636dbe331f7c000a Mon Sep 17 00:00:00 2001 From: Pierre Alliez Date: Tue, 14 Nov 2017 18:12:18 +0100 Subject: [PATCH] massaging the examples as desired (do not compile) added todo list --- .../Surface_mesh_approximation/todo.txt | 6 +++ ...mple.cpp => vsa_approximation_example.cpp} | 14 +++--- .../vsa_class_interface_example.cpp | 46 +++++++++---------- ...e.cpp => vsa_isotropic_metric_example.cpp} | 16 +++---- .../vsa_segmentation_example.cpp | 30 ++++++++++++ .../vsa_simple_approximation_example.cpp | 39 ++++++++++++++++ 6 files changed, 113 insertions(+), 38 deletions(-) create mode 100644 Surface_mesh_approximation/examples/Surface_mesh_approximation/todo.txt rename Surface_mesh_approximation/examples/Surface_mesh_approximation/{vsa_example.cpp => vsa_approximation_example.cpp} (73%) rename Surface_mesh_approximation/examples/Surface_mesh_approximation/{vsa_metric_example.cpp => vsa_isotropic_metric_example.cpp} (91%) create mode 100644 Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_segmentation_example.cpp create mode 100644 Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_simple_approximation_example.cpp diff --git a/Surface_mesh_approximation/examples/Surface_mesh_approximation/todo.txt b/Surface_mesh_approximation/examples/Surface_mesh_approximation/todo.txt new file mode 100644 index 00000000000..7d267cb22ac --- /dev/null +++ b/Surface_mesh_approximation/examples/Surface_mesh_approximation/todo.txt @@ -0,0 +1,6 @@ +Examples: +- free function for approximation, with only indexed triangles as output +- free function for approximation, with polyhedron set as output +- free function for segmentation, with segmentation as output +- class interface + - diff --git a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_example.cpp b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_approximation_example.cpp similarity index 73% rename from Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_example.cpp rename to Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_approximation_example.cpp index e32a1d64517..578f9b78a69 100644 --- a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_example.cpp +++ b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_approximation_example.cpp @@ -14,7 +14,7 @@ int main() { // create polyhedral surface and read input surface triangle mesh Polyhedron input; - std::ifstream file("data/bear.off"); + std::ifstream file("data/mask.off"); if (!file || !(file >> input) || input.empty()) { std::cerr << "Invalid off file." << std::endl; return EXIT_FAILURE; @@ -23,19 +23,19 @@ int main() // output polyhedral surface and indexed triangle mesh Polyhedron output; std::vector triangles; - std::vector anchors; + std::vector points; // free function interface with named parameters bool valid_polyhedron = CGAL::VSA::mesh_approximation(input, - CGAL::VSA::parameters::init_method(CGAL::Hierarchical). // hierarchical init - refine_until(200). // refine until target number of proxies + CGAL::VSA::parameters::init_method(CGAL::VSA::Hierarchical). // hierarchical init + refine_until_proxies(200). // refine until target number of proxies iterations(30). // number of relaxation iterations after seeding - anchor_points(std::back_inserter(anchors)). // get anchor vertices + anchor_points(std::back_inserter(points)). // get anchor points indexed_triangles(std::back_inserter(triangles)). // get indexed triangles output); // output to polyhedron, if 2-manifold and oriented - std::cout << "#anchor vertices: " << anchors.size() << std::endl; - std::cout << "#triangles: " << triangles.size() << std::endl; + std::cout << "#anchor points: " << points.size() << std::endl; + std::cout << "#triangles: " << triangles.size() / 3 << std::endl; if (valid_polyhedron) std::cout << "oriented 2-manifold output." << std::endl; diff --git a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_class_interface_example.cpp b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_class_interface_example.cpp index 126adb8b4da..56f66648324 100644 --- a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_class_interface_example.cpp +++ b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_class_interface_example.cpp @@ -13,52 +13,52 @@ typedef CGAL::Polyhedron_3 Polyhedron; typedef boost::property_map::type VertexPointMap; -typedef CGAL::VSA_approximation VSA; +typedef CGAL::VSA::Mesh_approximation Mesh_approximation; -// default L21 metric -typedef VSA::ErrorMetric L21_metric; -typedef VSA::ProxyFitting L21_proxy_fitting; +// L21 error metric +typedef VSA::L21_error_metric Metric; +typedef VSA::L21_proxy_fitting Proxy_fitting; int main() { // create polyhedral surface and read input mesh Polyhedron input; - std::ifstream file("data/bear.off"); + std::ifstream file("data/mask.off"); if (!file || !(file >> input) || input.empty()) { std::cerr << "Invalid off file." << std::endl; return EXIT_FAILURE; } // create VSA approximation algorithm instance - VSA l21_approx(input, + Mesh_approximation approx(input, get(boost::vertex_point, const_cast(input))); // set error and fitting functors - L21_metric metric(input); - L21_proxy_fitting proxy_fitting(input); - l21_approx.set_metric(metric, proxy_fitting); + Metric metric(input); + Proxy_fitting proxy_fitting(input); + approx.set_metric(metric, proxy_fitting); // initialize 100 random proxies - l21_approx.init_by_number(CGAL::Random, 100); + approx.init_by_number(CGAL::Random, 100); - // run 30 iterations to reduce the approximation error - for (std::size_t i = 0; i < 30; ++i) - l21_approx.run_one_step(); + // run 30 iterations + approx.run(30); - // add proxies to the one with the maximum fitting error - // and run 10 iterations - l21_approx.add_proxies_furthest(3, 5); - for (std::size_t i = 0; i < 10; ++i) - l21_approx.run_one_step(); + // add 3 proxies to the one with the maximum fitting error + // run 5 iterations between each addition + approx.add_proxies_furthest(3, 5); - // teleport 2 proxies from local minima - l21_approx.teleport_proxies(2); - for (std::size_t i = 0; i < 10; ++i) - l21_approx.run_one_step(); + // run 10 iterations + approx.run(10); + + // teleport 2 proxies to tunnel out of local minima + // run 5 iterations between each teleport + l21_approx.teleport_proxies(2, 5); + approx.run(10); // mesh and output final polyhedral surface Polyhedron output; - l21_approx.extract_mesh(output); + approx.meshing(output); return EXIT_SUCCESS; } diff --git a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_metric_example.cpp b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_isotropic_metric_example.cpp similarity index 91% rename from Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_metric_example.cpp rename to Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_isotropic_metric_example.cpp index fb310312444..13e46ed262b 100644 --- a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_metric_example.cpp +++ b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_isotropic_metric_example.cpp @@ -24,7 +24,7 @@ typedef boost::associative_property_map > FacetAreaMa typedef boost::associative_property_map > FacetCenterMap; // use point as proxy -typedef Point PointProxy; +typedef Point PointProxy; // TOFIX: CGAL capitalization -> Point_proxy (everywhere) // user-defined "compact" error metric struct CompactMetric { @@ -71,8 +71,9 @@ struct PointProxyFitting { const FacetCenterMap center_pmap; const FacetAreaMap area_pmap; }; -typedef CGAL::VSA_approximation CompactVSA; + +typedef CGAL::VSA::Mesh_approximation Approximation; int main() { @@ -101,18 +102,17 @@ int main() FacetCenterMap center_pmap(facet_centers); // create compact metric approximation algorithm instance - CompactVSA compact_approx(input, + Approximation approx(input, get(boost::vertex_point, const_cast(input))); // construct metric and fitting functors CompactMetric metric(center_pmap); PointProxyFitting proxy_fitting(center_pmap, area_pmap); - compact_approx.set_metric(metric, proxy_fitting); + approx.set_metric(metric, proxy_fitting); // approximation via 200 proxies and 30 iterations - compact_approx.init_by_number(CGAL::Hierarchical, 200); - for (std::size_t i = 0; i < 30; ++i) - compact_approx.run_one_step(); + approx.init_by_number(CGAL::Hierarchical, 200); + approx.run(30); return EXIT_SUCCESS; } diff --git a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_segmentation_example.cpp b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_segmentation_example.cpp new file mode 100644 index 00000000000..4930a644d5c --- /dev/null +++ b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_segmentation_example.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef CGAL::Polyhedron_3 Polyhedron; + +int main() +{ + // create polyhedral surface and read input surface triangle mesh + Polyhedron input; + std::ifstream file("data/mask.off"); + if (!file || !(file >> input) || input.empty()) { + std::cerr << "Invalid off file." << std::endl; + return EXIT_FAILURE; + } + + // free function interface with named parameters + CGAL::VSA::mesh_segmentation(input, + CGAL::VSA::parameters::init_method(CGAL::VSA::Hierarchical). // hierarchical init + refine_until(200). // refine until target number of proxies + iterations(30)); // number of relaxation iterations after seeding + + return EXIT_SUCCESS; +} diff --git a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_simple_approximation_example.cpp b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_simple_approximation_example.cpp new file mode 100644 index 00000000000..b714a7d0d57 --- /dev/null +++ b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_simple_approximation_example.cpp @@ -0,0 +1,39 @@ +#include +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef CGAL::Polyhedron_3 Polyhedron; + +int main() +{ + // create polyhedral surface and read input surface triangle mesh + Polyhedron input; + std::ifstream file("data/mask.off"); + if (!file || !(file >> input) || input.empty()) { + std::cerr << "Invalid off file." << std::endl; + return EXIT_FAILURE; + } + + // output polyhedral surface and indexed triangle mesh + std::vector triangles; + std::vector points; + + // free function interface with named parameters + bool valid_polyhedron = CGAL::VSA::mesh_approximation(input, + CGAL::VSA::parameters::init_method(CGAL::VSA::Hierarchical). // hierarchical init + refine_until_proxies(200). // refine until target number of proxies + iterations(30). // number of relaxation iterations after seeding + anchor_points(std::back_inserter(points)). // get anchor points + indexed_triangles(std::back_inserter(triangles))); // get indexed triangles + + std::cout << "#anchor points: " << points.size() << std::endl; + std::cout << "#triangles: " << triangles.size() / 3 << std::endl; + + return EXIT_SUCCESS; +}