mirror of https://github.com/CGAL/cgal
named params
This commit is contained in:
parent
64261f0acd
commit
c50bb0593a
|
|
@ -22,7 +22,7 @@ int main()
|
|||
}
|
||||
|
||||
// output indexed triangle mesh
|
||||
std::vector<Kernel::Point_3> points;
|
||||
std::vector<Kernel::Point_3> anchors;
|
||||
std::vector<CGAL::cpp11::array<std::size_t, 3> > triangles; // triplets of indices
|
||||
|
||||
// output facet proxy index property map
|
||||
|
|
@ -40,9 +40,9 @@ int main()
|
|||
nb_of_iterations(40). // set number of clustering iterations after seeding
|
||||
mesh_chord_error(0.3). // set chord approximation error threshold when meshing
|
||||
facet_proxy_map(fpxmap). // get facet partition map
|
||||
proxies(std::back_inserter(proxies)). // get proxies
|
||||
anchor_points(std::back_inserter(points)). // anchor points
|
||||
indexed_triangles(std::back_inserter(triangles))); // indexed triangles
|
||||
proxies(std::back_inserter(proxies)). // output proxies
|
||||
anchors(std::back_inserter(anchors)). // output anchor points
|
||||
triangles(std::back_inserter(triangles))); // output indexed triangles
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ int main()
|
|||
CGAL::Surface_mesh_approximation::parameters::seeding_method(CGAL::Hierarchical). // hierarchical seeding
|
||||
max_nb_proxies(200). // seeding with maximum number of proxies
|
||||
nb_of_iterations(30). // number of clustering iterations after seeding
|
||||
vertex_output_iterator(std::back_inserter(vertices)). // anchor vertices
|
||||
triangle_output_iterator(std::back_inserter(triangles))); // indexed triangles
|
||||
anchors(std::back_inserter(vertices)). // anchor vertices
|
||||
triangles(std::back_inserter(triangles))); // indexed triangles
|
||||
|
||||
std::cout << "#anchor vertices: " << vertices.size() << std::endl;
|
||||
std::cout << "#triangles: " << triangles.size() << std::endl;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ typedef boost::associative_property_map<std::map<Facet_handle, FT> > Facet_area_
|
|||
typedef boost::associative_property_map<std::map<Facet_handle, Point> > Facet_center_map;
|
||||
|
||||
// user-defined "compact" error metric
|
||||
struct Compact_metric {
|
||||
// use point as proxy
|
||||
struct Compact_metric
|
||||
{
|
||||
// use point as proxy
|
||||
typedef Point Proxy;
|
||||
|
||||
// we keep a precomputed property map to speed up computations
|
||||
|
|
@ -49,7 +50,7 @@ struct Compact_metric {
|
|||
center = center + (center_pmap[*fitr] - CGAL::ORIGIN) * area_pmap[*fitr];
|
||||
sum_areas += area_pmap[*fitr];
|
||||
}
|
||||
center = center / sum_areas;
|
||||
center = center / sum_areas; // TODO: deal with case where sum = 0
|
||||
return CGAL::ORIGIN + center;
|
||||
}
|
||||
|
||||
|
|
@ -65,10 +66,7 @@ int main()
|
|||
// creates polyhedral surface and reads input mesh
|
||||
Polyhedron input;
|
||||
std::ifstream file("data/bear.off");
|
||||
if (!file || !(file >> input) || input.empty()) {
|
||||
std::cerr << "Invalid off file." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
file >> input;
|
||||
|
||||
// constructs precomputed facet normal and area map
|
||||
std::map<Facet_handle, FT> facet_areas;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
||||
typedef boost::graph_traits<Polyhedron>::face_descriptor Face_descriptor;
|
||||
typedef boost::unordered_map<face_descriptor, std::size_t> Facet_index_map;
|
||||
typedef boost::unordered_map<Face_descriptor, std::size_t> Facet_index_map;
|
||||
typedef boost::associative_property_map<Facet_index_map> Facet_proxy_pmap;
|
||||
|
||||
int main()
|
||||
|
|
@ -27,7 +27,7 @@ int main()
|
|||
|
||||
// free function interface with named parameters
|
||||
CGAL::mesh_approximation(input,
|
||||
max_nb_proxies(200). // first stop criterion
|
||||
CGAL::Surface_mesh_approximation::parameters::max_nb_proxies(200). // first stop criterion
|
||||
min_error_drop(0.05). // second stop criterion
|
||||
nb_of_iterations(30). // number of relaxation iterations after seeding
|
||||
facet_proxy_map(fpxmap)); // output facet-proxy map
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@ int main()
|
|||
file >> input;
|
||||
|
||||
// The output will be an indexed triangle mesh
|
||||
std::vector<Kernel::Point_3> points;
|
||||
std::vector<Kernel::Point_3> anchors;
|
||||
std::vector<CGAL::cpp11::array<std::size_t, 3> > triangles;
|
||||
|
||||
// free function interface with named parameters
|
||||
CGAL::mesh_approximation(input,
|
||||
CGAL::Surface_mesh_approximation::parameters::max_nb_proxies(200).
|
||||
anchor_points(std::back_inserter(points)). // anchor points
|
||||
indexed_triangles(std::back_inserter(triangles))); // indexed triangles
|
||||
anchors(std::back_inserter(anchors)). // anchor points
|
||||
triangles(std::back_inserter(triangles))); // indexed triangles
|
||||
|
||||
std::cout << "#vertices: " << points.size() << std::endl;
|
||||
std::cout << "#anchor points: " << anchors.size() << std::endl;
|
||||
std::cout << "#triangles: " << triangles.size() << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <CGAL/linear_least_squares_fitting_3.h>
|
||||
#include <CGAL/array.h>
|
||||
|
||||
#include <CGAL/L21_metric.h>
|
||||
#include <CGAL/L21_metric_plane_proxy.h>
|
||||
#include <CGAL/Default.h>
|
||||
#include <CGAL/tags.h>
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ public:
|
|||
// ErrorMetric type
|
||||
#ifndef DOXYGEN_RUNNING
|
||||
typedef typename CGAL::Default::Get<ErrorMetric,
|
||||
CGAL::L21_metric<TriangleMesh, VertexPointMap, false, Geom_traits> >::type Error_metric;
|
||||
CGAL::VSA::L21_metric_plane_proxy<TriangleMesh, VertexPointMap, false, Geom_traits> >::type Error_metric;
|
||||
#else
|
||||
typedef ErrorMetric Error_metric;
|
||||
#endif
|
||||
|
|
@ -947,9 +947,9 @@ public:
|
|||
* @param out_itr output iterator
|
||||
*/
|
||||
template <typename OutputIterator>
|
||||
void proxies(OutputIterator out_itr) const {
|
||||
void proxies(OutputIterator out) const {
|
||||
BOOST_FOREACH(const Proxy_wrapper &pxw, m_proxies)
|
||||
*out_itr++ = pxw.px;
|
||||
*out++ = pxw.px;
|
||||
}
|
||||
|
||||
#ifdef CGAL_SURFACE_MESH_APPROXIMATION_DEBUG
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <CGAL/license/Surface_mesh_approximation.h>
|
||||
|
||||
|
||||
#include <CGAL/boost/graph/named_function_params.h>
|
||||
|
||||
namespace CGAL{
|
||||
|
|
|
|||
|
|
@ -74,36 +74,48 @@ public:
|
|||
|
||||
// output helper functions
|
||||
template <typename Approximation, typename FacetProxyMap>
|
||||
void get_proxy_map(const Approximation &approx, FacetProxyMap fproxymap) {
|
||||
void facet_proxy_map(const Approximation &approx, FacetProxyMap fproxymap) {
|
||||
approx.proxy_map(fproxymap);
|
||||
}
|
||||
|
||||
template <typename Approximation>
|
||||
void get_proxy_map(const Approximation &, internal_np::vsa_no_output_t) {}
|
||||
void facet_proxy_map(const Approximation &, internal_np::vsa_no_output_t) {}
|
||||
|
||||
// proxies
|
||||
|
||||
template <typename Approximation, typename OutputIterator>
|
||||
void get_proxies(const Approximation &approx, OutputIterator out_itr) {
|
||||
approx.proxies(out_itr);
|
||||
void proxies(const Approximation &approx, OutputIterator out)
|
||||
{
|
||||
approx.proxies(out);
|
||||
}
|
||||
|
||||
template <typename Approximation>
|
||||
void get_proxies(const Approximation &, internal_np::vsa_no_output_t) {}
|
||||
void proxies(const Approximation &, internal_np::vsa_no_output_t)
|
||||
{}
|
||||
|
||||
// anchors
|
||||
|
||||
template <typename Approximation, typename OutputIterator>
|
||||
void get_anchor_points(const Approximation &approx, OutputIterator out_itr) {
|
||||
approx.anchor_points(out_itr);
|
||||
void anchors(const Approximation &approx, OutputIterator out)
|
||||
{
|
||||
approx.anchor_points(out);
|
||||
}
|
||||
|
||||
template <typename Approximation>
|
||||
void get_anchor_points(const Approximation &, internal_np::vsa_no_output_t) {}
|
||||
void anchors(const Approximation &, internal_np::vsa_no_output_t) {}
|
||||
|
||||
// indexed triangles
|
||||
|
||||
template <typename Approximation, typename OutputIterator>
|
||||
void get_indexed_triangles(const Approximation &approx, OutputIterator out_itr) {
|
||||
approx.indexed_triangles(out_itr);
|
||||
void triangles(const Approximation &approx, OutputIterator out)
|
||||
{
|
||||
approx.indexed_triangles(out);
|
||||
}
|
||||
|
||||
template <typename Approximation>
|
||||
void get_indexed_triangles(const Approximation &, internal_np::vsa_no_output_t) {}
|
||||
void triangles(const Approximation &, internal_np::vsa_no_output_t)
|
||||
{}
|
||||
|
||||
} //end of namespace CGAL
|
||||
|
||||
#endif //CGAL_NAMED_PARAMETERS_HELPERS_H
|
||||
|
|
|
|||
|
|
@ -12,5 +12,5 @@ CGAL_add_named_parameter(mesh_chord_error_t, mesh_chord_error, mesh_chord_error)
|
|||
// output parameters
|
||||
CGAL_add_named_parameter(facet_proxy_map_t, facet_proxy_map, facet_proxy_map)
|
||||
CGAL_add_named_parameter(proxies_t, proxies, proxies)
|
||||
CGAL_add_named_parameter(anchor_points_t, anchor_points, anchor_points)
|
||||
CGAL_add_named_parameter(indexed_triangles_t, indexed_triangles, indexed_triangles)
|
||||
CGAL_add_named_parameter(anchor_points_t, anchors, anchors)
|
||||
CGAL_add_named_parameter(indexed_triangles_t, triangles, triangles)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ bool mesh_approximation(const TriangleMesh &tm, const NamedParameters &np)
|
|||
Vertex_point_map point_pmap = choose_param(get_param(np, internal_np::vertex_point),
|
||||
get_property_map(vertex_point, const_cast<TriangleMesh &>(tm)));
|
||||
|
||||
typedef CGAL::L21_metric<TriangleMesh, Vertex_point_map, false, Geom_traits> L21_metric;
|
||||
typedef CGAL::VSA::L21_metric_plane_proxy<TriangleMesh, Vertex_point_map, false, Geom_traits> L21_metric;
|
||||
typedef CGAL::VSA_approximation<TriangleMesh, Vertex_point_map> L21_approx;
|
||||
typedef L21_approx::Error_metric L21_metric;
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ bool mesh_approximation(const TriangleMesh &tm, const NamedParameters &np)
|
|||
internal_np::vsa_no_output_t>::type FPMap;
|
||||
FPMap fproxymap = choose_param(
|
||||
get_param(np, internal_np::facet_proxy_map), internal_np::vsa_no_output);
|
||||
get_proxy_map(approx, fproxymap);
|
||||
proxies(approx, fproxymap);
|
||||
|
||||
// get proxies
|
||||
typedef typename boost::lookup_named_param_def <
|
||||
|
|
@ -124,7 +124,7 @@ bool mesh_approximation(const TriangleMesh &tm, const NamedParameters &np)
|
|||
internal_np::vsa_no_output_t>::type ProxiesOutItr;
|
||||
ProxiesOutItr pxies_out_itr = choose_param(
|
||||
get_param(np, internal_np::proxies), internal_np::vsa_no_output);
|
||||
get_proxies(approx, pxies_out_itr);
|
||||
proxies(approx, pxies_out_itr);
|
||||
|
||||
// meshing
|
||||
const FT chord_error = choose_param(get_param(np, internal_np::mesh_chord_error), FT(5.0));
|
||||
|
|
@ -136,8 +136,8 @@ bool mesh_approximation(const TriangleMesh &tm, const NamedParameters &np)
|
|||
NamedParameters,
|
||||
internal_np::vsa_no_output_t>::type Anchor_point_output_iterator;
|
||||
Anchor_point_output_iterator apts_out_itr = choose_param(
|
||||
get_param(np, internal_np::anchor_points) , internal_np::vsa_no_output);
|
||||
get_anchor_points(approx, apts_out_itr);
|
||||
get_param(np, internal_np::anchors) , internal_np::vsa_no_output);
|
||||
anchors(approx, apts_out_itr);
|
||||
|
||||
// get indexed triangles
|
||||
typedef typename boost::lookup_named_param_def<
|
||||
|
|
@ -145,8 +145,8 @@ bool mesh_approximation(const TriangleMesh &tm, const NamedParameters &np)
|
|||
NamedParameters,
|
||||
internal_np::vsa_no_output_t>::type Indexed_triangles_output_iterator;
|
||||
Indexed_triangles_output_iterator tris_out_itr = choose_param(
|
||||
get_param(np, internal_np::indexed_triangles) , internal_np::vsa_no_output);
|
||||
get_indexed_triangles(approx, tris_out_itr);
|
||||
get_param(np, internal_np::triangles) , internal_np::vsa_no_output);
|
||||
triangles(approx, tris_out_itr);
|
||||
|
||||
return is_manifold;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue