mirror of https://github.com/CGAL/cgal
Vertex normal map used as a function to avoid cascaded templating
This commit is contained in:
parent
449ba102eb
commit
70ebce80ff
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <CGAL/Named_function_parameters.h>
|
||||
#include <CGAL/boost/graph/named_params_helper.h>
|
||||
#include <boost/property_map/function_property_map.hpp>
|
||||
|
||||
namespace CGAL {
|
||||
namespace Surface_mesh_simplification {
|
||||
|
|
@ -50,8 +51,9 @@ struct GH_helper{
|
|||
|
||||
Vertex_normal_map vertex_normals = choose_parameter(get_parameter(np, internal_np::vertex_normal_map),
|
||||
get(Vertex_normal_tag(), tmesh));
|
||||
if constexpr(must_compute_vertex_normals)
|
||||
if constexpr(must_compute_vertex_normals){
|
||||
Polygon_mesh_processing::compute_vertex_normals(tmesh, vertex_normals, np);
|
||||
}
|
||||
return vertex_normals;
|
||||
}
|
||||
|
||||
|
|
@ -64,25 +66,21 @@ struct GH_helper{
|
|||
FT dm(const NamedParameters& np) const {
|
||||
using parameters::choose_parameter;
|
||||
using parameters::get_parameter;
|
||||
// choose_parameter(get_parameter(np, internal_np::discontinuity_multiplier), 100);
|
||||
return FT(100);
|
||||
return choose_parameter(get_parameter(np, internal_np::discontinuity_multiplier), 100);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<typename TriangleMesh,
|
||||
typename GeomTraits,
|
||||
typename VertexNormalMap = typename boost::property_map<TriangleMesh,
|
||||
CGAL::dynamic_vertex_property_t<typename GeomTraits::Vector_3> >::const_type >
|
||||
template<typename TriangleMesh, typename GeomTraits>
|
||||
class GarlandHeckbert_plane_and_line_policies
|
||||
: public internal::GarlandHeckbert_composed_policies<TriangleMesh, GeomTraits,
|
||||
GarlandHeckbert_plane_policies<TriangleMesh, GeomTraits>,
|
||||
internal::GarlandHeckbert_line_policies<TriangleMesh, GeomTraits, VertexNormalMap>,
|
||||
internal::GarlandHeckbert_line_policies<TriangleMesh, GeomTraits>,
|
||||
true>
|
||||
{
|
||||
typedef GarlandHeckbert_plane_policies<TriangleMesh, GeomTraits> GH_plane_polices;
|
||||
typedef internal::GarlandHeckbert_line_policies<TriangleMesh, GeomTraits, VertexNormalMap> GH_line_polices;
|
||||
typedef internal::GarlandHeckbert_line_policies<TriangleMesh, GeomTraits> GH_line_polices;
|
||||
typedef internal::GarlandHeckbert_composed_policies<TriangleMesh, GeomTraits,
|
||||
GH_plane_polices,
|
||||
GH_line_polices,
|
||||
|
|
@ -99,24 +97,10 @@ public:
|
|||
typedef typename GeomTraits::FT FT;
|
||||
|
||||
public:
|
||||
// GarlandHeckbert_plane_and_line_policies(TriangleMesh& tmesh,
|
||||
// const FT line_weight = FT(0.001),
|
||||
// const FT dm = FT(100))
|
||||
// : Base(tmesh, GH_plane_polices(tmesh, dm), GH_line_polices(tmesh, dm), FT(1.)/line_weight, dm)
|
||||
// { }
|
||||
|
||||
template<typename VNM>
|
||||
GarlandHeckbert_plane_and_line_policies(TriangleMesh& tmesh,
|
||||
const FT line_weight,
|
||||
const FT dm,
|
||||
const VNM vnm)
|
||||
: Base(tmesh, GH_plane_polices(tmesh, dm), GH_line_polices(tmesh, dm, vnm), FT(1.)/line_weight, dm)
|
||||
{ }
|
||||
|
||||
template<typename NP = parameters::Default_named_parameters>
|
||||
GarlandHeckbert_plane_and_line_policies(TriangleMesh& tmesh, const NP& np = parameters::default_values()):
|
||||
Base(tmesh,
|
||||
GH_plane_polices(tmesh, internal::GH_helper<TM,NP>().dm(np)),
|
||||
GH_plane_polices(tmesh),
|
||||
GH_line_polices(tmesh, internal::GH_helper<TM,NP>().vnm(tmesh, np)),
|
||||
FT(1.)/internal::GH_helper<TM,NP>().lw(np),
|
||||
FT(1.),
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <CGAL/Default.h>
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
#include <boost/property_map/function_property_map.hpp>
|
||||
|
||||
namespace CGAL {
|
||||
namespace Surface_mesh_simplification {
|
||||
|
|
@ -31,7 +32,7 @@ This policy is not useful on its own; it is designed to be combined with another
|
|||
Therefore, it is kept internal.
|
||||
*/
|
||||
|
||||
template <typename TriangleMesh, typename GeomTraits, typename VertexNormalMap>
|
||||
template <typename TriangleMesh, typename GeomTraits>
|
||||
class Line_quadric_calculator
|
||||
{
|
||||
typedef typename GarlandHeckbert_matrix_types<GeomTraits>::Mat_4 Mat_4;
|
||||
|
|
@ -42,28 +43,23 @@ class Line_quadric_calculator
|
|||
typedef typename GeomTraits::Vector_3 Vector_3;
|
||||
|
||||
private:
|
||||
VertexNormalMap m_vertex_normal_map;
|
||||
std::function<Vector_3(vertex_descriptor)> m_vertex_normal_map;
|
||||
|
||||
public:
|
||||
Line_quadric_calculator() = delete;
|
||||
|
||||
template <typename VNM>
|
||||
Line_quadric_calculator(const VNM vnm)
|
||||
: m_vertex_normal_map(vnm)
|
||||
: m_vertex_normal_map([vnm](vertex_descriptor v) -> Vector_3{ return get(vnm, v); })
|
||||
{ }
|
||||
|
||||
// Line_quadric_calculator(const TriangleMesh& tmesh):m_vertex_normal_map(tmesh.number_of_vertices())
|
||||
// {
|
||||
// Polygon_mesh_processing::compute_vertex_normals(tmesh, m_vertex_normal_map);
|
||||
// }
|
||||
|
||||
template <typename VertexPointMap>
|
||||
Mat_4 construct_quadric_from_vertex(typename boost::graph_traits<TriangleMesh>::vertex_descriptor v,
|
||||
const TriangleMesh& /*tmesh*/,
|
||||
const VertexPointMap point_map,
|
||||
const GeomTraits& gt) const
|
||||
{
|
||||
return construct_line_quadric_from_normal(get(m_vertex_normal_map, v), get(point_map, v), gt);
|
||||
return construct_line_quadric_from_normal(m_vertex_normal_map(v), get(point_map, v), gt);
|
||||
}
|
||||
|
||||
template <typename VertexPointMap>
|
||||
|
|
@ -101,10 +97,10 @@ template<typename TriangleMesh,
|
|||
CGAL::dynamic_vertex_property_t<typename GeomTraits::Vector_3> >::const_type >
|
||||
class GarlandHeckbert_line_policies
|
||||
: public internal::GarlandHeckbert_cost_and_placement<
|
||||
internal::Line_quadric_calculator<TriangleMesh, GeomTraits, VertexNormalMap>, TriangleMesh, GeomTraits>
|
||||
internal::Line_quadric_calculator<TriangleMesh, GeomTraits>, TriangleMesh, GeomTraits>
|
||||
{
|
||||
public:
|
||||
typedef internal::Line_quadric_calculator<TriangleMesh, GeomTraits, VertexNormalMap> Quadric_calculator;
|
||||
typedef internal::Line_quadric_calculator<TriangleMesh, GeomTraits> Quadric_calculator;
|
||||
|
||||
private:
|
||||
typedef internal::GarlandHeckbert_cost_and_placement<
|
||||
|
|
|
|||
|
|
@ -91,7 +91,8 @@ get_all_meshes(const std::vector<std::string>& filenames)
|
|||
|
||||
template <typename Policy>
|
||||
Surface_mesh edge_collapse(Surface_mesh& mesh,
|
||||
const double ratio = 0.2)
|
||||
const double ratio,
|
||||
const Policy p)
|
||||
{
|
||||
typedef typename Policy::Get_cost Cost;
|
||||
typedef typename Policy::Get_placement Placement;
|
||||
|
|
@ -99,8 +100,6 @@ Surface_mesh edge_collapse(Surface_mesh& mesh,
|
|||
|
||||
std::cout << "Edge collapse mesh of " << num_edges(mesh) << " edges. Policy: " << typeid(Policy).name() << std::endl;
|
||||
|
||||
const Policy p ( mesh );
|
||||
|
||||
const Cost& cost = p.get_cost();
|
||||
const Placement& unbounded_placement = p.get_placement();
|
||||
Bounded_placement bounded_placement(unbounded_placement);
|
||||
|
|
@ -119,6 +118,12 @@ Surface_mesh edge_collapse(Surface_mesh& mesh,
|
|||
return mesh;
|
||||
}
|
||||
|
||||
template <typename Policy>
|
||||
Surface_mesh edge_collapse(Surface_mesh& mesh,
|
||||
const double ratio = 0.2){
|
||||
return edge_collapse(mesh, ratio, Policy(mesh));
|
||||
}
|
||||
|
||||
// =================================================================================================
|
||||
// =================================================================================================
|
||||
// =================================================================================================
|
||||
|
|
@ -281,6 +286,14 @@ void run(const std::pair<TriangleMesh, std::string>& input)
|
|||
gather_face_aspect_ratio(input.first, out);
|
||||
}
|
||||
|
||||
template<typename TriangleMesh>
|
||||
void test_parameters_plane_and_line(const TriangleMesh& mesh){
|
||||
using CGAL::Surface_mesh_simplification::make_GarlandHeckbert_plane_and_line_policies;
|
||||
TriangleMesh cp = mesh;
|
||||
edge_collapse(cp, 0.2, make_GarlandHeckbert_plane_and_line_policies(cp,
|
||||
CGAL::parameters::line_policies_weight(0.001).discontinuity_multiplier(50).geom_traits(Kernel())));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> default_data = { "data/helmet.off",
|
||||
|
|
@ -295,8 +308,10 @@ int main(int argc, char** argv)
|
|||
data = default_data;
|
||||
|
||||
std::vector<std::pair<Surface_mesh, std::string> > named_meshes = get_all_meshes(data);
|
||||
for(const auto& e : named_meshes)
|
||||
for(const auto& e : named_meshes){
|
||||
run(e);
|
||||
test_parameters_plane_and_line(e.first);
|
||||
}
|
||||
|
||||
std::cout << "Done!" << std::endl;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue