improve named parameters

This commit is contained in:
Lingjie Zhu 2017-09-04 23:06:43 +08:00
parent 5db214812d
commit cbacf07fe6
5 changed files with 131 additions and 98 deletions

View File

@ -6,6 +6,8 @@
namespace CGAL{
namespace internal_np{
enum vsa_no_output_t { vsa_no_output };
// define enum types and values for new named parameters
#define CGAL_add_named_parameter(X, Y, Z) \
enum X { Y };

View File

@ -131,48 +131,46 @@ get_const_property_map(const PropertyTag& p, const PolygonMesh& pmesh)
return pms.get_const_pmap(p, pmesh);
}
template<typename PolygonMesh, typename NamedParameters>
class GetFaceIndexMap
{
typedef typename property_map_selector<PolygonMesh, boost::face_index_t>::type DefaultMap;
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;
};
// output helper functions
template <typename Approximation, typename FacetProxyMap>
void get_proxy_map(const Approximation &approx, FacetProxyMap fproxymap) {
approx.get_proxy_map(fproxymap);
}
template<typename PolygonMesh, typename NamedParameters>
class GetFaceNormalMap
{
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;
template <typename Approximation>
void get_proxy_map(const Approximation &approx, internal_np::vsa_no_output_t) {}
typedef DummyNormalPmap Self;
friend reference get(const Self&, const key_type&) { return CGAL::NULL_VECTOR; }
};
template <typename Approximation, typename OutputIterator>
void get_anchor_vertices(const Approximation &approx, OutputIterator out_itr) {
approx.get_anchor_vertices(out_itr);
}
public:
typedef DummyNormalPmap NoMap;
typedef typename boost::lookup_named_param_def <
internal_np::face_normal_t,
NamedParameters,
DummyNormalPmap//default
> ::type type;
};
template <typename Approximation>
void get_anchor_vertices(const Approximation &approx, internal_np::vsa_no_output_t) {}
template <typename Approximation, typename OutputIterator>
void get_anchor_points(const Approximation &approx, OutputIterator out_itr) {
approx.get_anchor_points(out_itr);
}
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

View File

@ -1,15 +1,17 @@
// 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(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)
CGAL_add_named_parameter(face_normal_t, face_normal, face_normal_map)
CGAL_add_named_parameter(face_proxy_t, face_proxy, face_proxy_map)
// approximation parameters
CGAL_add_named_parameter(init_method_t, init_method, init_method)
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
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_point_t, anchor_point, anchor_point)
CGAL_add_named_parameter(indexed_triangles_t, indexed_triangles, indexed_triangles)

View File

@ -41,14 +41,20 @@ namespace CGAL
* \cgalParamEnd
* \cgalParamBegin{init_method} the selection of seed initialization method.
* \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
* \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
* \cgalParamBegin{chord_subdivide} the threshold of chord subdivision.
* \cgalParamEnd
* \cgalParamBegin{face_proxy_map} a property map containing the assigned proxy index of each face of `tm_in`
* \cgalParamEnd
* \cgalParamBegin{proxies} the plane proxies
* \cgalParamEnd
* \cgalParamBegin{anchor_vertex} the anchor verteices output iterator
* \cgalParamEnd
* \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;
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, tm_in));
get_property_map(vertex_point, const_cast<TriangleMesh &>(tm_in)));
typedef CGAL::VSA_approximation<TriangleMesh, VPMap> VSAL21;
typedef typename VSAL21::ErrorMetric L21Metric;
@ -87,59 +92,72 @@ bool vsa_mesh_approximation(const TriangleMesh &tm_in,
L21ProxyFitting l21_fitting(tm_in);
vsa_l21.set_metric(l21_metric, l21_fitting);
std::size_t num_proxies = choose_param(get_param(np, internal_np::number_of_proxies),
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;
// default random initialization
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(
static_cast<typename VSAL21::Method>(init), num_proxies, 5);
for (std::size_t i = 0; i < num_iterations; ++i)
static_cast<typename VSAL21::Method>(init), num_proxies, inner_iterations);
}
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();
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));
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,
NamedParameters,
std::back_insert_iterator<std::vector<vertex_descriptor> >
> ::type AnchorVertexOutItr;
AnchorVertexOutItr avtx_out_itr = choose_param(get_param(np, internal_np::anchor_vertex)
, std::back_inserter(*(new std::vector<vertex_descriptor>())));
vsa_l21.get_anchor_vertices(avtx_out_itr);
internal_np::vsa_no_output_t>::type AnchorVertexOutItr;
AnchorVertexOutItr avtx_out_itr = choose_param(
get_param(np, internal_np::anchor_vertex) , internal_np::vsa_no_output);
get_anchor_vertices(vsa_l21, avtx_out_itr);
typedef typename boost::lookup_named_param_def <
typedef typename boost::lookup_named_param_def<
internal_np::anchor_point_t,
NamedParameters,
std::back_insert_iterator<std::vector<Point_3> >
> ::type AnchorPointOutItr;
AnchorPointOutItr apts_out_itr = choose_param(get_param(np, internal_np::anchor_point)
, std::back_inserter(*(new std::vector<Point_3>())));
vsa_l21.get_anchor_points(apts_out_itr);
internal_np::vsa_no_output_t >::type AnchorPointOutItr;
AnchorPointOutItr apts_out_itr = choose_param(
get_param(np, internal_np::anchor_point), internal_np::vsa_no_output);
get_anchor_points(vsa_l21, apts_out_itr);
typedef typename boost::lookup_named_param_def <
internal_np::indexed_triangles_t,
NamedParameters,
std::back_insert_iterator<std::vector<int> >
> ::type IndexedTrisOutItr;
IndexedTrisOutItr itris_out_itr = choose_param(get_param(np, internal_np::indexed_triangles)
, std::back_inserter(*(new std::vector<int>())));
vsa_l21.get_indexed_triangles(itris_out_itr);
internal_np::vsa_no_output_t>::type IndexedTrisOutItr;
IndexedTrisOutItr itris_out_itr = choose_param(
get_param(np, internal_np::indexed_triangles), internal_np::vsa_no_output);
get_indexed_triangles(vsa_l21, itris_out_itr);
// typedef typename boost::lookup_named_param_def <
// internal_np::proxies_t,
// NamedParameters,
// std::back_insert_iterator<std::vector<PlaneProxy> >
// > ::type ProxiesOutItr;
// ProxiesOutItr pxies_out_itr = choose_param(get_param(np, internal_np::proxies)
// , std::back_inserter(*(new std::vector<PlaneProxy>())));
// vsa_l21.get_proxies(pxies_out_itr);
typedef typename boost::lookup_named_param_def <
internal_np::proxies_t,
NamedParameters,
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(vsa_l21, pxies_out_itr);
return is_manifold;
}

View File

@ -26,12 +26,25 @@ int main()
std::vector<int> tris;
std::vector<Kernel::Point_3> anchor_pos;
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::parameters::number_of_proxies(6).
number_of_iterations(30).
CGAL::VSA::parameters::seeding_by_number(6).
iterations(30).
inner_iterations(5).
chord_subdivide(0.5).
facet_proxy_map(fpxmap).
anchor_vertex(std::back_inserter(anchor_vtx)).
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;
}