mirror of https://github.com/CGAL/cgal
massaging the examples as desired (do not compile)
added todo list
This commit is contained in:
parent
86e6a2af7c
commit
7f515a63d4
|
|
@ -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
|
||||
-
|
||||
|
|
@ -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<std::size_t> triangles;
|
||||
std::vector<Kernel::Point_3> anchors;
|
||||
std::vector<Kernel::Point_3> 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;
|
||||
|
|
@ -13,52 +13,52 @@ typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
|||
typedef boost::property_map<Polyhedron, boost::vertex_point_t>::type VertexPointMap;
|
||||
|
||||
|
||||
typedef CGAL::VSA_approximation<Polyhedron, VertexPointMap> VSA;
|
||||
typedef CGAL::VSA::Mesh_approximation<Polyhedron, VertexPointMap> 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<Polyhedron &>(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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ typedef boost::associative_property_map<std::map<Facet_handle, FT> > FacetAreaMa
|
|||
typedef boost::associative_property_map<std::map<Facet_handle, Point> > 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<Polyhedron, VertexPointMap,
|
||||
CompactMetric, PointProxyFitting> CompactVSA;
|
||||
|
||||
typedef CGAL::VSA::Mesh_approximation<Polyhedron, VertexPointMap,
|
||||
CompactMetric, PointProxyFitting> 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<Polyhedron &>(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;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/vsa_mesh_approximation.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel> 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;
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/vsa_mesh_approximation.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel> 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<std::size_t> triangles;
|
||||
std::vector<Kernel::Point_3> 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;
|
||||
}
|
||||
Loading…
Reference in New Issue