mirror of https://github.com/CGAL/cgal
improve named parameters
This commit is contained in:
parent
5db214812d
commit
cbacf07fe6
|
|
@ -6,6 +6,8 @@
|
||||||
namespace CGAL{
|
namespace CGAL{
|
||||||
namespace internal_np{
|
namespace internal_np{
|
||||||
|
|
||||||
|
enum vsa_no_output_t { vsa_no_output };
|
||||||
|
|
||||||
// define enum types and values for new named parameters
|
// define enum types and values for new named parameters
|
||||||
#define CGAL_add_named_parameter(X, Y, Z) \
|
#define CGAL_add_named_parameter(X, Y, Z) \
|
||||||
enum X { Y };
|
enum X { Y };
|
||||||
|
|
|
||||||
|
|
@ -131,48 +131,46 @@ get_const_property_map(const PropertyTag& p, const PolygonMesh& pmesh)
|
||||||
return pms.get_const_pmap(p, pmesh);
|
return pms.get_const_pmap(p, pmesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PolygonMesh, typename NamedParameters>
|
// output helper functions
|
||||||
class GetFaceIndexMap
|
template <typename Approximation, typename FacetProxyMap>
|
||||||
{
|
void get_proxy_map(const Approximation &approx, FacetProxyMap fproxymap) {
|
||||||
typedef typename property_map_selector<PolygonMesh, boost::face_index_t>::type DefaultMap;
|
approx.get_proxy_map(fproxymap);
|
||||||
typedef typename property_map_selector<PolygonMesh, boost::face_index_t>::const_type DefaultMap_const;
|
}
|
||||||
public:
|
|
||||||
typedef typename boost::lookup_named_param_def <
|
|
||||||
internal_np::face_index_t,
|
|
||||||
NamedParameters,
|
|
||||||
DefaultMap
|
|
||||||
> ::type type;
|
|
||||||
typedef typename boost::lookup_named_param_def <
|
|
||||||
internal_np::face_index_t,
|
|
||||||
NamedParameters,
|
|
||||||
DefaultMap_const
|
|
||||||
> ::type const_type;
|
|
||||||
typedef typename boost::is_same<type, DefaultMap>::type Is_internal_map;
|
|
||||||
typedef typename boost::is_same<const_type, DefaultMap_const>::type Is_internal_map_const;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename PolygonMesh, typename NamedParameters>
|
template <typename Approximation>
|
||||||
class GetFaceNormalMap
|
void get_proxy_map(const Approximation &approx, internal_np::vsa_no_output_t) {}
|
||||||
{
|
|
||||||
struct DummyNormalPmap
|
|
||||||
{
|
|
||||||
typedef typename boost::graph_traits<PolygonMesh>::face_descriptor key_type;
|
|
||||||
typedef typename GetGeomTraits<PolygonMesh, NamedParameters>::type::Vector_3 value_type;
|
|
||||||
typedef value_type reference;
|
|
||||||
typedef boost::readable_property_map_tag category;
|
|
||||||
|
|
||||||
typedef DummyNormalPmap Self;
|
template <typename Approximation, typename OutputIterator>
|
||||||
friend reference get(const Self&, const key_type&) { return CGAL::NULL_VECTOR; }
|
void get_anchor_vertices(const Approximation &approx, OutputIterator out_itr) {
|
||||||
};
|
approx.get_anchor_vertices(out_itr);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
template <typename Approximation>
|
||||||
typedef DummyNormalPmap NoMap;
|
void get_anchor_vertices(const Approximation &approx, internal_np::vsa_no_output_t) {}
|
||||||
typedef typename boost::lookup_named_param_def <
|
|
||||||
internal_np::face_normal_t,
|
template <typename Approximation, typename OutputIterator>
|
||||||
NamedParameters,
|
void get_anchor_points(const Approximation &approx, OutputIterator out_itr) {
|
||||||
DummyNormalPmap//default
|
approx.get_anchor_points(out_itr);
|
||||||
> ::type type;
|
}
|
||||||
};
|
|
||||||
|
template <typename Approximation>
|
||||||
|
void get_anchor_points(const Approximation &approx, internal_np::vsa_no_output_t) {}
|
||||||
|
|
||||||
|
template <typename Approximation, typename OutputIterator>
|
||||||
|
void get_indexed_triangles(const Approximation &approx, OutputIterator out_itr) {
|
||||||
|
approx.get_indexed_triangles(out_itr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Approximation>
|
||||||
|
void get_indexed_triangles(const Approximation &approx, internal_np::vsa_no_output_t) {}
|
||||||
|
|
||||||
|
template <typename Approximation, typename OutputIterator>
|
||||||
|
void get_proxies(const Approximation &approx, OutputIterator out_itr) {
|
||||||
|
approx.get_proxies(out_itr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Approximation>
|
||||||
|
void get_proxies(const Approximation &approx, internal_np::vsa_no_output_t) {}
|
||||||
|
|
||||||
} //end of namespace CGAL
|
} //end of namespace CGAL
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
// List of named parameters used in the Polygon Mesh Processing package
|
// List of named parameters used in the Polygon Mesh Processing package
|
||||||
CGAL_add_named_parameter(geom_traits_t, geom_traits, geom_traits)
|
CGAL_add_named_parameter(geom_traits_t, geom_traits, geom_traits)
|
||||||
CGAL_add_named_parameter(init_method_t, init_method, init_method)
|
|
||||||
CGAL_add_named_parameter(number_of_iterations_t, number_of_iterations, number_of_iterations)
|
|
||||||
CGAL_add_named_parameter(number_of_proxies_t, number_of_proxies, number_of_proxies)
|
|
||||||
CGAL_add_named_parameter(chord_subdivide_t, chord_subdivide, chord_subdivide)
|
|
||||||
CGAL_add_named_parameter(pca_plane_t, pca_plane, pca_plane)
|
|
||||||
|
|
||||||
CGAL_add_named_parameter(face_area_t, face_area, face_area_map)
|
// approximation parameters
|
||||||
CGAL_add_named_parameter(face_normal_t, face_normal, face_normal_map)
|
CGAL_add_named_parameter(init_method_t, init_method, init_method)
|
||||||
CGAL_add_named_parameter(face_proxy_t, face_proxy, face_proxy_map)
|
CGAL_add_named_parameter(seeding_by_number_t, seeding_by_number, seeding_by_number)
|
||||||
|
CGAL_add_named_parameter(seeding_by_error_t, seeding_by_error, seeding_by_error)
|
||||||
|
CGAL_add_named_parameter(iterations_t, iterations, iterations)
|
||||||
|
CGAL_add_named_parameter(inner_iterations_t, inner_iterations, inner_iterations)
|
||||||
|
CGAL_add_named_parameter(chord_subdivide_t, chord_subdivide, chord_subdivide)
|
||||||
|
|
||||||
// output parameters
|
// 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_vertex_t, anchor_vertex, anchor_vertex)
|
CGAL_add_named_parameter(anchor_vertex_t, anchor_vertex, anchor_vertex)
|
||||||
CGAL_add_named_parameter(anchor_point_t, anchor_point, anchor_point)
|
CGAL_add_named_parameter(anchor_point_t, anchor_point, anchor_point)
|
||||||
CGAL_add_named_parameter(indexed_triangles_t, indexed_triangles, indexed_triangles)
|
CGAL_add_named_parameter(indexed_triangles_t, indexed_triangles, indexed_triangles)
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,20 @@ namespace CGAL
|
||||||
* \cgalParamEnd
|
* \cgalParamEnd
|
||||||
* \cgalParamBegin{init_method} the selection of seed initialization method.
|
* \cgalParamBegin{init_method} the selection of seed initialization method.
|
||||||
* \cgalParamEnd
|
* \cgalParamEnd
|
||||||
* \cgalParamBegin{number_of_proxies} the number of proxies to approximate the geometry.
|
* \cgalParamBegin{seeding_by_number} the number of proxies to approximate the geometry.
|
||||||
* \cgalParamEnd
|
* \cgalParamEnd
|
||||||
* \cgalParamBegin{number_of_iterations} the relaxation iterations.
|
* \cgalParamBegin{seeding_by_error} the error drop of the approximation.
|
||||||
|
* \cgalParamEnd
|
||||||
|
* \cgalParamBegin{iterations} the relaxation iterations after seeding.
|
||||||
|
* \cgalParamEnd
|
||||||
|
* \cgalParamBegin{inner_iterations} the relaxation iterations when seeding.
|
||||||
* \cgalParamEnd
|
* \cgalParamEnd
|
||||||
* \cgalParamBegin{chord_subdivide} the threshold of chord subdivision.
|
* \cgalParamBegin{chord_subdivide} the threshold of chord subdivision.
|
||||||
* \cgalParamEnd
|
* \cgalParamEnd
|
||||||
* \cgalParamBegin{face_proxy_map} a property map containing the assigned proxy index of each face of `tm_in`
|
* \cgalParamBegin{face_proxy_map} a property map containing the assigned proxy index of each face of `tm_in`
|
||||||
* \cgalParamEnd
|
* \cgalParamEnd
|
||||||
|
* \cgalParamBegin{proxies} the plane proxies
|
||||||
|
* \cgalParamEnd
|
||||||
* \cgalParamBegin{anchor_vertex} the anchor verteices output iterator
|
* \cgalParamBegin{anchor_vertex} the anchor verteices output iterator
|
||||||
* \cgalParamEnd
|
* \cgalParamEnd
|
||||||
* \cgalParamBegin{anchor_point} the anchor points output iterator
|
* \cgalParamBegin{anchor_point} the anchor points output iterator
|
||||||
|
|
@ -75,8 +81,7 @@ bool vsa_mesh_approximation(const TriangleMesh &tm_in,
|
||||||
|
|
||||||
typedef typename GetVertexPointMap<TriangleMesh, NamedParameters>::type VPMap;
|
typedef typename GetVertexPointMap<TriangleMesh, NamedParameters>::type VPMap;
|
||||||
VPMap point_pmap = choose_param(get_param(np, internal_np::vertex_point),
|
VPMap point_pmap = choose_param(get_param(np, internal_np::vertex_point),
|
||||||
get(boost::vertex_point, const_cast<TriangleMesh &>(tm_in)));
|
get_property_map(vertex_point, const_cast<TriangleMesh &>(tm_in)));
|
||||||
// get_property_map(vertex_point, tm_in));
|
|
||||||
|
|
||||||
typedef CGAL::VSA_approximation<TriangleMesh, VPMap> VSAL21;
|
typedef CGAL::VSA_approximation<TriangleMesh, VPMap> VSAL21;
|
||||||
typedef typename VSAL21::ErrorMetric L21Metric;
|
typedef typename VSAL21::ErrorMetric L21Metric;
|
||||||
|
|
@ -87,59 +92,72 @@ bool vsa_mesh_approximation(const TriangleMesh &tm_in,
|
||||||
L21ProxyFitting l21_fitting(tm_in);
|
L21ProxyFitting l21_fitting(tm_in);
|
||||||
vsa_l21.set_metric(l21_metric, l21_fitting);
|
vsa_l21.set_metric(l21_metric, l21_fitting);
|
||||||
|
|
||||||
std::size_t num_proxies = choose_param(get_param(np, internal_np::number_of_proxies),
|
// default random initialization
|
||||||
num_faces(tm_in) / 100);
|
|
||||||
std::size_t num_iterations = choose_param(get_param(np, internal_np::number_of_iterations), 10);
|
|
||||||
std::cout << "#px = " << num_proxies << ", #itr = " << num_iterations << std::endl;
|
|
||||||
|
|
||||||
int init = choose_param(get_param(np, internal_np::init_method), 0);
|
int init = choose_param(get_param(np, internal_np::init_method), 0);
|
||||||
|
std::size_t num_proxies = choose_param(get_param(np, internal_np::seeding_by_number), 0);
|
||||||
|
std::size_t inner_iterations = choose_param(get_param(np, internal_np::inner_iterations), 10);
|
||||||
|
if (num_proxies == 0 || num_proxies > num_faces(tm_in)) {
|
||||||
|
FT drop = choose_param(get_param(np, internal_np::seeding_by_error), FT(0.01));
|
||||||
|
vsa_l21.seeding_by_error(
|
||||||
|
static_cast<typename VSAL21::Method>(init), drop, inner_iterations);
|
||||||
|
}
|
||||||
|
else {
|
||||||
vsa_l21.seeding_by_number(
|
vsa_l21.seeding_by_number(
|
||||||
static_cast<typename VSAL21::Method>(init), num_proxies, 5);
|
static_cast<typename VSAL21::Method>(init), num_proxies, inner_iterations);
|
||||||
for (std::size_t i = 0; i < num_iterations; ++i)
|
}
|
||||||
|
|
||||||
|
std::size_t iterations = choose_param(get_param(np, internal_np::iterations), 10);
|
||||||
|
for (std::size_t i = 0; i < iterations; ++i)
|
||||||
vsa_l21.run_one_step();
|
vsa_l21.run_one_step();
|
||||||
|
|
||||||
bool pca_plane = choose_param(get_param(np, internal_np::pca_plane) , false);
|
#ifdef CGAL_SURFACE_MESH_APPROXIMATION_DEBUG
|
||||||
|
std::cout << "#px = " << num_proxies
|
||||||
|
<< ", #itr = " << iterations
|
||||||
|
<< ", #inner_itr = " << inner_iterations << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef typename boost::lookup_named_param_def<
|
||||||
|
internal_np::facet_proxy_map_t,
|
||||||
|
NamedParameters,
|
||||||
|
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(vsa_l21, fproxymap);
|
||||||
|
|
||||||
FT split_criterion = choose_param(get_param(np, internal_np::chord_subdivide), FT(1));
|
FT split_criterion = choose_param(get_param(np, internal_np::chord_subdivide), FT(1));
|
||||||
bool is_manifold = vsa_l21.meshing(tm_out, split_criterion, pca_plane);
|
bool is_manifold = vsa_l21.meshing(tm_out, split_criterion);
|
||||||
|
|
||||||
// vsa_l21.get_proxy_map();
|
typedef typename boost::lookup_named_param_def<
|
||||||
|
|
||||||
typedef typename boost::lookup_named_param_def <
|
|
||||||
internal_np::anchor_vertex_t,
|
internal_np::anchor_vertex_t,
|
||||||
NamedParameters,
|
NamedParameters,
|
||||||
std::back_insert_iterator<std::vector<vertex_descriptor> >
|
internal_np::vsa_no_output_t>::type AnchorVertexOutItr;
|
||||||
> ::type AnchorVertexOutItr;
|
AnchorVertexOutItr avtx_out_itr = choose_param(
|
||||||
AnchorVertexOutItr avtx_out_itr = choose_param(get_param(np, internal_np::anchor_vertex)
|
get_param(np, internal_np::anchor_vertex) , internal_np::vsa_no_output);
|
||||||
, std::back_inserter(*(new std::vector<vertex_descriptor>())));
|
get_anchor_vertices(vsa_l21, avtx_out_itr);
|
||||||
vsa_l21.get_anchor_vertices(avtx_out_itr);
|
|
||||||
|
|
||||||
typedef typename boost::lookup_named_param_def <
|
typedef typename boost::lookup_named_param_def<
|
||||||
internal_np::anchor_point_t,
|
internal_np::anchor_point_t,
|
||||||
NamedParameters,
|
NamedParameters,
|
||||||
std::back_insert_iterator<std::vector<Point_3> >
|
internal_np::vsa_no_output_t >::type AnchorPointOutItr;
|
||||||
> ::type AnchorPointOutItr;
|
AnchorPointOutItr apts_out_itr = choose_param(
|
||||||
AnchorPointOutItr apts_out_itr = choose_param(get_param(np, internal_np::anchor_point)
|
get_param(np, internal_np::anchor_point), internal_np::vsa_no_output);
|
||||||
, std::back_inserter(*(new std::vector<Point_3>())));
|
get_anchor_points(vsa_l21, apts_out_itr);
|
||||||
vsa_l21.get_anchor_points(apts_out_itr);
|
|
||||||
|
|
||||||
typedef typename boost::lookup_named_param_def <
|
typedef typename boost::lookup_named_param_def <
|
||||||
internal_np::indexed_triangles_t,
|
internal_np::indexed_triangles_t,
|
||||||
NamedParameters,
|
NamedParameters,
|
||||||
std::back_insert_iterator<std::vector<int> >
|
internal_np::vsa_no_output_t>::type IndexedTrisOutItr;
|
||||||
> ::type IndexedTrisOutItr;
|
IndexedTrisOutItr itris_out_itr = choose_param(
|
||||||
IndexedTrisOutItr itris_out_itr = choose_param(get_param(np, internal_np::indexed_triangles)
|
get_param(np, internal_np::indexed_triangles), internal_np::vsa_no_output);
|
||||||
, std::back_inserter(*(new std::vector<int>())));
|
get_indexed_triangles(vsa_l21, itris_out_itr);
|
||||||
vsa_l21.get_indexed_triangles(itris_out_itr);
|
|
||||||
|
|
||||||
|
typedef typename boost::lookup_named_param_def <
|
||||||
// typedef typename boost::lookup_named_param_def <
|
internal_np::proxies_t,
|
||||||
// internal_np::proxies_t,
|
NamedParameters,
|
||||||
// NamedParameters,
|
internal_np::vsa_no_output_t>::type ProxiesOutItr;
|
||||||
// std::back_insert_iterator<std::vector<PlaneProxy> >
|
ProxiesOutItr pxies_out_itr = choose_param(
|
||||||
// > ::type ProxiesOutItr;
|
get_param(np, internal_np::proxies), internal_np::vsa_no_output);
|
||||||
// ProxiesOutItr pxies_out_itr = choose_param(get_param(np, internal_np::proxies)
|
get_proxies(vsa_l21, pxies_out_itr);
|
||||||
// , std::back_inserter(*(new std::vector<PlaneProxy>())));
|
|
||||||
// vsa_l21.get_proxies(pxies_out_itr);
|
|
||||||
|
|
||||||
return is_manifold;
|
return is_manifold;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,25 @@ int main()
|
||||||
std::vector<int> tris;
|
std::vector<int> tris;
|
||||||
std::vector<Kernel::Point_3> anchor_pos;
|
std::vector<Kernel::Point_3> anchor_pos;
|
||||||
std::list<Polyhedron::Vertex_handle> anchor_vtx;
|
std::list<Polyhedron::Vertex_handle> anchor_vtx;
|
||||||
|
std::vector<CGAL::PlaneProxy<Kernel> > proxies;
|
||||||
|
std::map<Polyhedron::Facet_handle, std::size_t> fidxmap;
|
||||||
|
boost::associative_property_map<std::map<Polyhedron::Facet_handle, std::size_t> > fpxmap(fidxmap);
|
||||||
CGAL::vsa_mesh_approximation(mesh, out_mesh,
|
CGAL::vsa_mesh_approximation(mesh, out_mesh,
|
||||||
CGAL::VSA::parameters::number_of_proxies(6).
|
CGAL::VSA::parameters::seeding_by_number(6).
|
||||||
number_of_iterations(30).
|
iterations(30).
|
||||||
|
inner_iterations(5).
|
||||||
|
chord_subdivide(0.5).
|
||||||
|
facet_proxy_map(fpxmap).
|
||||||
anchor_vertex(std::back_inserter(anchor_vtx)).
|
anchor_vertex(std::back_inserter(anchor_vtx)).
|
||||||
anchor_point(std::back_inserter(anchor_pos)).
|
anchor_point(std::back_inserter(anchor_pos)).
|
||||||
indexed_triangles(std::back_inserter(tris)));
|
indexed_triangles(std::back_inserter(tris)).
|
||||||
|
proxies(std::back_inserter(proxies)));
|
||||||
|
|
||||||
|
std::cout << "#tris " << tris.size() << std::endl;
|
||||||
|
std::cout << "#anchor_pos " << anchor_pos.size() << std::endl;
|
||||||
|
std::cout << "#anchor_vtx " << anchor_vtx.size() << std::endl;
|
||||||
|
std::cout << "#proxies " << proxies.size() << std::endl;
|
||||||
|
std::cout << "#fpxmap " << fidxmap.size() << std::endl;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue