mirror of https://github.com/CGAL/cgal
separate plane fitting from approximation traits
This commit is contained in:
parent
f958f5616b
commit
f4c40b1244
|
|
@ -100,7 +100,6 @@ struct ApproxTrait {
|
|||
typedef PointProxy Proxy;
|
||||
typedef CompactMetric ErrorMetric;
|
||||
typedef PointProxyFitting ProxyFitting;
|
||||
typedef CGAL::PlaneFitting<Polyhedron> PlaneFitting;
|
||||
|
||||
ApproxTrait(const Polyhedron &_mesh,
|
||||
const VertexPointMap &_point_pmap,
|
||||
|
|
@ -117,10 +116,6 @@ struct ApproxTrait {
|
|||
return ProxyFitting(center_pmap, area_pmap, normal_pmap);
|
||||
}
|
||||
|
||||
PlaneFitting construct_plane_fitting_functor() const {
|
||||
return PlaneFitting(mesh);
|
||||
}
|
||||
|
||||
const Polyhedron &mesh;
|
||||
const VertexPointMap point_pmap;
|
||||
const FacetCenterMap center_pmap;
|
||||
|
|
|
|||
|
|
@ -400,14 +400,12 @@ private:
|
|||
* @tparam FacetSegmentMap `WritablePropertyMap` with `boost::graph_traits<TriangleMesh>::face_handle` as key and `std::size_t` as value type
|
||||
*/
|
||||
template <typename TriangleMesh,
|
||||
typename ApproximationTraits,
|
||||
typename VertexPointMap,
|
||||
typename FacetSegmentMap>
|
||||
typename FacetSegmentMap,
|
||||
typename PlaneFitting = typename CGAL::PlaneFitting<TriangleMesh>,
|
||||
typename GeomTraits = typename TriangleMesh::Traits>
|
||||
class VSA_mesh_extraction
|
||||
{
|
||||
typedef typename ApproximationTraits::GeomTraits GeomTraits;
|
||||
typedef typename ApproximationTraits::PlaneFitting PlaneFitting;
|
||||
|
||||
typedef typename GeomTraits::FT FT;
|
||||
typedef typename GeomTraits::Point_3 Point_3;
|
||||
typedef typename GeomTraits::Vector_3 Vector_3;
|
||||
|
|
@ -447,20 +445,19 @@ public:
|
|||
/**
|
||||
* Extracts the surface mesh from an approximation partition @a _seg_pmap of mesh @a _mesh.
|
||||
* @param _mesh the approximated triangle mesh.
|
||||
* @param _appx_trait approximation traits object.
|
||||
* @param _plane_fitting plane fitting function object.
|
||||
* @param _point_pmap vertex point map of the input mesh.
|
||||
* @param _seg_pmap approximation partition.
|
||||
*/
|
||||
VSA_mesh_extraction(const TriangleMesh &_mesh,
|
||||
const ApproximationTraits &_appx_trait,
|
||||
const PlaneFitting &_plane_fitting,
|
||||
const VertexPointMap &_point_pmap,
|
||||
const FacetSegmentMap &_seg_pmap)
|
||||
: mesh(_mesh),
|
||||
point_pmap(_point_pmap),
|
||||
seg_pmap(_seg_pmap),
|
||||
vanchor_map(vertex_int_map),
|
||||
num_proxies(0),
|
||||
plane_fitting(_appx_trait.construct_plane_fitting_functor()) {
|
||||
num_proxies(0) {
|
||||
GeomTraits traits;
|
||||
vector_functor = traits.construct_vector_3_object();
|
||||
scale_functor = traits.construct_scaled_vector_3_object();
|
||||
|
|
@ -482,7 +479,7 @@ public:
|
|||
BOOST_FOREACH(face_descriptor f, faces(mesh))
|
||||
px_facets[seg_pmap[f]].push_back(f);
|
||||
BOOST_FOREACH(const std::list<face_descriptor> &px_patch, px_facets) {
|
||||
px_planes.push_back(plane_fitting(px_patch.begin(), px_patch.end()));
|
||||
px_planes.push_back(_plane_fitting(px_patch.begin(), px_patch.end()));
|
||||
|
||||
Vector_3 norm = CGAL::NULL_VECTOR;
|
||||
FT area(0);
|
||||
|
|
@ -1068,9 +1065,6 @@ private:
|
|||
|
||||
// All borders cycles.
|
||||
std::vector<Border> borders;
|
||||
|
||||
// The proxy plane fitting functor.
|
||||
PlaneFitting plane_fitting;
|
||||
}; // end class VSA_mesh_extraction
|
||||
|
||||
} // end namespace internal
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ namespace CGAL
|
|||
* @tparam AnchorPositionContainer a container of extracted anchor position
|
||||
* @tparam AnchorVertexContainer a container of extracted anchor vertex
|
||||
* @tparam BoundaryContainer a container of proxy patch boundary
|
||||
* @tparam PlaneFitting a plane fitting functor
|
||||
* @tparam ApproximationTrait an approximation trait
|
||||
|
||||
* @param init select seed initialization
|
||||
|
|
@ -47,6 +48,7 @@ template<typename TriangleMesh,
|
|||
typename AnchorPositionContainer,
|
||||
typename AnchorVertexContainer,
|
||||
typename BoundaryContainer,
|
||||
typename PlaneFitting,
|
||||
typename ApproximationTrait>
|
||||
void vsa_mesh_approximation(
|
||||
const int init,
|
||||
|
|
@ -59,6 +61,7 @@ void vsa_mesh_approximation(
|
|||
AnchorPositionContainer &pos,
|
||||
AnchorVertexContainer &vtx,
|
||||
BoundaryContainer &bdrs,
|
||||
const PlaneFitting &_plane_fitting,
|
||||
const ApproximationTrait &app_trait) {
|
||||
// CGAL_precondition(is_pure_triangle(tm));
|
||||
|
||||
|
|
@ -71,11 +74,12 @@ void vsa_mesh_approximation(
|
|||
|
||||
typedef CGAL::internal::VSA_mesh_extraction<
|
||||
TriangleMesh,
|
||||
ApproximationTrait,
|
||||
VertexPointMap,
|
||||
FacetProxyMap> VSA_mesh_extraction;
|
||||
FacetProxyMap,
|
||||
PlaneFitting,
|
||||
ApproximationTrait::GeomTraits> VSA_mesh_extraction;
|
||||
|
||||
VSA_mesh_extraction extractor(tm, app_trait, v_point_pmap, f_proxy_pmap);
|
||||
VSA_mesh_extraction extractor(tm, _plane_fitting, v_point_pmap, f_proxy_pmap);
|
||||
|
||||
extractor.extract_mesh(tris);
|
||||
BOOST_FOREACH(const typename VSA_mesh_extraction::Anchor &a, extractor.collect_anchors()) {
|
||||
|
|
@ -147,6 +151,7 @@ void vsa_approximate(
|
|||
* @tparam TriangleMesh model of `FaceGraph`.
|
||||
* @tparam AnchorIndexContainer a container of approximated indexed triangle soup
|
||||
* @tparam AnchorPositionContainer a container of extracted anchor position
|
||||
* @tparam PlaneFitting a plane fitting functor
|
||||
* @tparam ApproximationTrait an approximation trait
|
||||
|
||||
* @param tm a triangle mesh
|
||||
|
|
@ -160,11 +165,13 @@ void vsa_approximate(
|
|||
template<typename TriangleMesh,
|
||||
typename AnchorIndexContainer,
|
||||
typename AnchorPositionContainer,
|
||||
typename PlaneFitting,
|
||||
typename ApproximationTrait>
|
||||
void vsa_extract(
|
||||
const TriangleMesh &tm,
|
||||
AnchorIndexContainer &tris,
|
||||
AnchorPositionContainer &pos,
|
||||
const PlaneFitting &_plane_fitting,
|
||||
const ApproximationTrait &app_trait,
|
||||
const int init,
|
||||
const std::size_t number_of_segments,
|
||||
|
|
@ -188,12 +195,13 @@ void vsa_extract(
|
|||
typedef typename boost::property_map<TriangleMesh, boost::vertex_point_t>::type VertexPointMap;
|
||||
typedef CGAL::internal::VSA_mesh_extraction<
|
||||
TriangleMesh,
|
||||
ApproximationTrait,
|
||||
VertexPointMap,
|
||||
FacetProxyMap> VSA_mesh_extraction;
|
||||
FacetProxyMap,
|
||||
PlaneFitting,
|
||||
ApproximationTrait::GeomTraits> VSA_mesh_extraction;
|
||||
|
||||
VSA_mesh_extraction extractor(tm,
|
||||
app_trait,
|
||||
_plane_fitting,
|
||||
get(boost::vertex_point, const_cast<TriangleMesh &>(tm)),
|
||||
f_proxy_pmap);
|
||||
|
||||
|
|
@ -214,6 +222,7 @@ void vsa_extract(
|
|||
std::size_t as value type
|
||||
* @tparam AnchorIndexContainer a container of approximated indexed triangle soup
|
||||
* @tparam AnchorPositionContainer a container of extracted anchor position
|
||||
* @tparam PlaneFitting a plane fitting functor
|
||||
* @tparam ApproximationTrait an approximation trait
|
||||
|
||||
* @param tm a triangle mesh
|
||||
|
|
@ -229,12 +238,14 @@ template<typename TriangleMesh,
|
|||
typename FacetProxyMap,
|
||||
typename AnchorIndexContainer,
|
||||
typename AnchorPositionContainer,
|
||||
typename PlaneFitting,
|
||||
typename ApproximationTrait>
|
||||
void vsa_approximate_and_extract(
|
||||
const TriangleMesh &tm,
|
||||
FacetProxyMap f_proxy_pmap,
|
||||
AnchorIndexContainer &tris,
|
||||
AnchorPositionContainer &pos,
|
||||
const PlaneFitting &_plane_fitting,
|
||||
const ApproximationTrait &app_trait,
|
||||
const int init,
|
||||
const std::size_t number_of_segments,
|
||||
|
|
@ -251,12 +262,13 @@ void vsa_approximate_and_extract(
|
|||
typedef typename boost::property_map<TriangleMesh, boost::vertex_point_t>::type VertexPointMap;
|
||||
typedef CGAL::internal::VSA_mesh_extraction<
|
||||
TriangleMesh,
|
||||
ApproximationTrait,
|
||||
VertexPointMap,
|
||||
FacetProxyMap> VSA_mesh_extraction;
|
||||
FacetProxyMap,
|
||||
PlaneFitting,
|
||||
ApproximationTrait::GeomTraits> VSA_mesh_extraction;
|
||||
|
||||
VSA_mesh_extraction extractor(tm,
|
||||
app_trait,
|
||||
_plane_fitting,
|
||||
get(boost::vertex_point, const_cast<TriangleMesh &>(tm)),
|
||||
f_proxy_pmap);
|
||||
|
||||
|
|
@ -306,8 +318,7 @@ void vsa_approximate(
|
|||
typedef CGAL::PlaneProxy<TriangleMesh> PlaneProxy;
|
||||
typedef CGAL::L21Metric<PlaneProxy, FacetNormalMap, FacetAreaMap> L21Metric;
|
||||
typedef CGAL::L21ProxyFitting<PlaneProxy, L21Metric, FacetNormalMap, FacetAreaMap> L21ProxyFitting;
|
||||
typedef CGAL::PlaneFitting<TriangleMesh> PlaneFitting;
|
||||
typedef CGAL::L21ApproximationTrait<PlaneProxy, TriangleMesh, L21Metric, L21ProxyFitting, PlaneFitting, VertexPointMap, FacetNormalMap, FacetAreaMap> L21ApproximationTrait;
|
||||
typedef CGAL::L21ApproximationTrait<PlaneProxy, TriangleMesh, L21Metric, L21ProxyFitting, VertexPointMap, FacetNormalMap, FacetAreaMap> L21ApproximationTrait;
|
||||
|
||||
VertexPointMap point_pmap = get(boost::vertex_point, const_cast<TriangleMesh &>(tm));
|
||||
// construct facet normal & area map
|
||||
|
|
@ -378,7 +389,7 @@ void vsa_extract(
|
|||
typedef CGAL::L21Metric<PlaneProxy, FacetNormalMap, FacetAreaMap> L21Metric;
|
||||
typedef CGAL::L21ProxyFitting<PlaneProxy, L21Metric, FacetNormalMap, FacetAreaMap> L21ProxyFitting;
|
||||
typedef CGAL::PlaneFitting<TriangleMesh> PlaneFitting;
|
||||
typedef CGAL::L21ApproximationTrait<PlaneProxy, TriangleMesh, L21Metric, L21ProxyFitting, PlaneFitting, VertexPointMap, FacetNormalMap, FacetAreaMap> L21ApproximationTrait;
|
||||
typedef CGAL::L21ApproximationTrait<PlaneProxy, TriangleMesh, L21Metric, L21ProxyFitting, VertexPointMap, FacetNormalMap, FacetAreaMap> L21ApproximationTrait;
|
||||
|
||||
VertexPointMap point_pmap = get(boost::vertex_point, const_cast<TriangleMesh &>(tm));
|
||||
// construct facet normal & area map
|
||||
|
|
@ -406,6 +417,7 @@ void vsa_extract(
|
|||
vsa_extract(tm,
|
||||
tris,
|
||||
pos,
|
||||
PlaneFitting(tm),
|
||||
L21ApproximationTrait(tm, point_pmap, normal_pmap, area_pmap),
|
||||
init,
|
||||
number_of_segments,
|
||||
|
|
@ -462,7 +474,7 @@ void vsa_approximate_and_extract(
|
|||
typedef CGAL::L21Metric<PlaneProxy, FacetNormalMap, FacetAreaMap> L21Metric;
|
||||
typedef CGAL::L21ProxyFitting<PlaneProxy, L21Metric, FacetNormalMap, FacetAreaMap> L21ProxyFitting;
|
||||
typedef CGAL::PlaneFitting<TriangleMesh> PlaneFitting;
|
||||
typedef CGAL::L21ApproximationTrait<PlaneProxy, TriangleMesh, L21Metric, L21ProxyFitting, PlaneFitting, VertexPointMap, FacetNormalMap, FacetAreaMap> L21ApproximationTrait;
|
||||
typedef CGAL::L21ApproximationTrait<PlaneProxy, TriangleMesh, L21Metric, L21ProxyFitting, VertexPointMap, FacetNormalMap, FacetAreaMap> L21ApproximationTrait;
|
||||
|
||||
VertexPointMap point_pmap = get(boost::vertex_point, const_cast<TriangleMesh &>(tm));
|
||||
// construct facet normal & area map
|
||||
|
|
@ -486,6 +498,7 @@ void vsa_approximate_and_extract(
|
|||
f_proxy_pmap,
|
||||
tris,
|
||||
pos,
|
||||
PlaneFitting(tm),
|
||||
app_trait,
|
||||
init,
|
||||
number_of_segments,
|
||||
|
|
|
|||
|
|
@ -153,11 +153,11 @@ template<typename TriangleMesh,
|
|||
typedef typename boost::graph_traits<TriangleMesh>::halfedge_descriptor halfedge_descriptor;
|
||||
|
||||
template<typename FacetIterator>
|
||||
Plane_3 operator()(const FacetIterator &beg, const FacetIterator &end) {
|
||||
Plane_3 operator()(const FacetIterator &beg, const FacetIterator &end) const {
|
||||
CGAL_assertion(beg != end);
|
||||
// area average normal and centroid
|
||||
Vector_3 norm = CGAL::NULL_VECTOR;
|
||||
Vector_3 centroid = CGAL::NULL_VECTOR;
|
||||
Vector_3 cent = CGAL::NULL_VECTOR;
|
||||
FT sum_area(0);
|
||||
for (FacetIterator fitr = beg; fitr != end; ++fitr) {
|
||||
const halfedge_descriptor he = halfedge(*fitr, mesh);
|
||||
|
|
@ -170,14 +170,14 @@ template<typename TriangleMesh,
|
|||
Vector_3 fnorm = CGAL::unit_normal(p0, p1, p2);
|
||||
|
||||
norm = sum_functor(norm, scale_functor(fnorm, farea));
|
||||
centroid = sum_functor(centroid, scale_functor(vec, farea));
|
||||
cent = sum_functor(cent, scale_functor(vec, farea));
|
||||
sum_area += farea;
|
||||
}
|
||||
norm = scale_functor(norm,
|
||||
FT(1.0 / std::sqrt(CGAL::to_double(norm.squared_length()))));
|
||||
centroid = scale_functor(centroid, FT(1) / sum_area);
|
||||
cent = scale_functor(cent, FT(1) / sum_area);
|
||||
|
||||
return Plane_3(CGAL::ORIGIN + centroid, norm);
|
||||
return Plane_3(CGAL::ORIGIN + cent, norm);
|
||||
}
|
||||
|
||||
const TriangleMesh &mesh;
|
||||
|
|
@ -192,7 +192,6 @@ template<typename PlaneProxy,
|
|||
typename TriangleMesh,
|
||||
typename L21ErrorMetric,
|
||||
typename L21ProxyFitting,
|
||||
typename L21PlaneFitting,
|
||||
typename VertexPointMap,
|
||||
typename FacetNormalMap,
|
||||
typename FacetAreaMap>
|
||||
|
|
@ -202,7 +201,6 @@ template<typename PlaneProxy,
|
|||
typedef PlaneProxy Proxy;
|
||||
typedef L21ErrorMetric ErrorMetric;
|
||||
typedef L21ProxyFitting ProxyFitting;
|
||||
typedef L21PlaneFitting PlaneFitting;
|
||||
|
||||
L21ApproximationTrait(
|
||||
const TriangleMesh &_mesh,
|
||||
|
|
@ -225,11 +223,6 @@ template<typename PlaneProxy,
|
|||
return ProxyFitting(normal_pmap, area_pmap);
|
||||
}
|
||||
|
||||
// construct plane fitting functor
|
||||
L21PlaneFitting construct_plane_fitting_functor() const {
|
||||
return L21PlaneFitting(mesh, point_pmap);
|
||||
}
|
||||
|
||||
private:
|
||||
const TriangleMesh &mesh;
|
||||
const VertexPointMap point_pmap;
|
||||
|
|
@ -362,7 +355,7 @@ template<typename TriangleMesh,
|
|||
}
|
||||
|
||||
template<typename FacetIterator>
|
||||
Plane_3 operator()(const FacetIterator beg, const FacetIterator end) {
|
||||
Plane_3 operator()(const FacetIterator beg, const FacetIterator end) const {
|
||||
CGAL_assertion(beg != end);
|
||||
|
||||
std::list<Triangle_3> tris;
|
||||
|
|
@ -401,7 +394,6 @@ template<typename TriangleMesh,
|
|||
typename PlaneProxy,
|
||||
typename L2ErrorMetric,
|
||||
typename L2ProxyFitting,
|
||||
typename PCAPlaneFitting,
|
||||
typename VertexPointMap,
|
||||
typename FacetAreaMap>
|
||||
struct L2ApproximationTrait
|
||||
|
|
@ -411,7 +403,6 @@ public:
|
|||
typedef PlaneProxy Proxy;
|
||||
typedef L2ErrorMetric ErrorMetric;
|
||||
typedef L2ProxyFitting ProxyFitting;
|
||||
typedef PCAPlaneFitting PlaneFitting;
|
||||
|
||||
L2ApproximationTrait(
|
||||
const TriangleMesh &_mesh,
|
||||
|
|
@ -433,11 +424,6 @@ public:
|
|||
return ProxyFitting(mesh, point_pmap, area_pmap);
|
||||
}
|
||||
|
||||
// construct plane fitting functor
|
||||
PlaneFitting construct_plane_fitting_functor() const {
|
||||
return PlaneFitting(mesh, point_pmap);
|
||||
}
|
||||
|
||||
private:
|
||||
const TriangleMesh &mesh;
|
||||
const VertexPointMap point_pmap;
|
||||
|
|
|
|||
Loading…
Reference in New Issue