mirror of https://github.com/CGAL/cgal
Lighten the examples a bit
This commit is contained in:
parent
a8b86837fb
commit
d04b2ee4d8
|
|
@ -31,6 +31,8 @@ if ( NOT Boost_FOUND )
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_definitions(-DBOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||||
|
|
||||||
# include for local directory
|
# include for local directory
|
||||||
|
|
||||||
# include for local package
|
# include for local package
|
||||||
|
|
|
||||||
|
|
@ -13,28 +13,28 @@ typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create and read Polyhedron
|
// create and read Polyhedron
|
||||||
Polyhedron mesh;
|
Polyhedron input;
|
||||||
std::ifstream input("data/bear.off");
|
std::ifstream file("data/bear.off");
|
||||||
if (!input || !(input >> mesh) || mesh.empty()) {
|
if (!file || !(file >> input) || input.empty()) {
|
||||||
std::cerr << "Invalid off file." << std::endl;
|
std::cerr << "Invalid off file." << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// output data
|
// output data
|
||||||
Polyhedron out_mesh;
|
Polyhedron output;
|
||||||
std::vector<int> tris;
|
std::vector<int> triangles;
|
||||||
std::vector<Kernel::Point_3> anchor_pos;
|
std::vector<Kernel::Point_3> anchors;
|
||||||
|
|
||||||
// free function interface with named parameters
|
// free function interface with named parameters
|
||||||
CGAL::vsa_mesh_approximation(mesh, out_mesh,
|
CGAL::vsa_mesh_approximation(input, output,
|
||||||
CGAL::VSA::parameters::number_of_proxies(200). // number of fitting proxies
|
CGAL::VSA::parameters::number_of_proxies(200). // number of fitting proxies
|
||||||
number_of_iterations(30). // number of iterations
|
number_of_iterations(30). // number of iterations
|
||||||
init_method(1). // hierarchical init
|
init_method(1). // hierarchical init
|
||||||
anchor_point(std::back_inserter(anchor_pos)). // get anchor points
|
anchor_point(std::back_inserter(anchors)). // get anchor points
|
||||||
indexed_triangles(std::back_inserter(tris))); // get indexed triangles
|
indexed_triangles(std::back_inserter(triangles))); // get indexed triangles
|
||||||
|
|
||||||
std::cout << "#anchor_pos " << anchor_pos.size() << std::endl;
|
std::cout << "#anchors: " << anchors.size() << std::endl;
|
||||||
std::cout << "#tris " << tris.size() << std::endl;
|
std::cout << "#triangles: " << triangles.size() << std::endl;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,20 @@
|
||||||
|
|
||||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||||
typedef Kernel::FT FT;
|
typedef Kernel::FT FT;
|
||||||
typedef Kernel::Vector_3 Vector_3;
|
typedef Kernel::Vector_3 Vector;
|
||||||
typedef Kernel::Point_3 Point_3;
|
typedef Kernel::Point_3 Point;
|
||||||
|
|
||||||
typedef CGAL::Polyhedron_3<Kernel> Polyhedron_3;
|
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
||||||
typedef Polyhedron_3::Facet_handle Facet_handle;
|
typedef Polyhedron::Facet_handle Facet_handle;
|
||||||
typedef Polyhedron_3::Halfedge_handle Halfedge_handle;
|
typedef Polyhedron::Halfedge_handle Halfedge_handle;
|
||||||
typedef Polyhedron_3::Facet_iterator Facet_iterator;
|
typedef Polyhedron::Facet_iterator Facet_iterator;
|
||||||
typedef boost::associative_property_map<std::map<Facet_handle, FT> > FacetAreaMap;
|
typedef boost::associative_property_map<std::map<Facet_handle, FT> > FacetAreaMap;
|
||||||
typedef boost::associative_property_map<std::map<Facet_handle, Point_3> > FacetCenterMap;
|
typedef boost::associative_property_map<std::map<Facet_handle, Point> > FacetCenterMap;
|
||||||
|
|
||||||
// proxy
|
// proxy
|
||||||
struct PointProxy {
|
struct PointProxy {
|
||||||
Facet_handle seed;
|
Facet_handle seed;
|
||||||
Point_3 center;
|
Point center;
|
||||||
};
|
};
|
||||||
|
|
||||||
// metric functor
|
// metric functor
|
||||||
|
|
@ -57,8 +57,8 @@ struct PointProxyFitting {
|
||||||
template<typename FacetIterator>
|
template<typename FacetIterator>
|
||||||
PointProxy operator()(const FacetIterator beg, const FacetIterator end) const {
|
PointProxy operator()(const FacetIterator beg, const FacetIterator end) const {
|
||||||
// fitting center
|
// fitting center
|
||||||
Vector_3 center = CGAL::NULL_VECTOR;
|
Vector center = CGAL::NULL_VECTOR;
|
||||||
FT area(0);
|
FT area = FT(0.0);
|
||||||
for (FacetIterator fitr = beg; fitr != end; ++fitr) {
|
for (FacetIterator fitr = beg; fitr != end; ++fitr) {
|
||||||
center = center + (center_pmap[*fitr] - CGAL::ORIGIN) * area_pmap[*fitr];
|
center = center + (center_pmap[*fitr] - CGAL::ORIGIN) * area_pmap[*fitr];
|
||||||
area += area_pmap[*fitr];
|
area += area_pmap[*fitr];
|
||||||
|
|
@ -75,12 +75,12 @@ struct PointProxyFitting {
|
||||||
const FacetCenterMap center_pmap;
|
const FacetCenterMap center_pmap;
|
||||||
const FacetAreaMap area_pmap;
|
const FacetAreaMap area_pmap;
|
||||||
};
|
};
|
||||||
typedef CGAL::VSA_approximation<Polyhedron_3, PointProxy, CompactMetric, PointProxyFitting> CompactVSA;
|
typedef CGAL::VSA_approximation<Polyhedron, PointProxy, CompactMetric, PointProxyFitting> CompactVSA;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create and read Polyhedron_3
|
// create and read Polyhedron_3
|
||||||
Polyhedron_3 mesh;
|
Polyhedron mesh;
|
||||||
std::ifstream input("data/bear.off");
|
std::ifstream input("data/bear.off");
|
||||||
if (!input || !(input >> mesh) || mesh.empty()) {
|
if (!input || !(input >> mesh) || mesh.empty()) {
|
||||||
std::cerr << "Invalid off file." << std::endl;
|
std::cerr << "Invalid off file." << std::endl;
|
||||||
|
|
@ -89,15 +89,16 @@ int main()
|
||||||
|
|
||||||
// construct precomputed facet normal and area map
|
// construct precomputed facet normal and area map
|
||||||
std::map<Facet_handle, FT> facet_areas;
|
std::map<Facet_handle, FT> facet_areas;
|
||||||
std::map<Facet_handle, Point_3> facet_centers;
|
std::map<Facet_handle, Point> facet_centers;
|
||||||
for(Facet_iterator fitr = mesh.facets_begin(); fitr != mesh.facets_end(); ++fitr) {
|
for(Facet_iterator fitr = mesh.facets_begin(); fitr != mesh.facets_end(); ++fitr) {
|
||||||
const Halfedge_handle he = fitr->halfedge();
|
const Halfedge_handle he = fitr->halfedge();
|
||||||
const Point_3 &p0 = he->opposite()->vertex()->point();
|
const Point &p0 = he->opposite()->vertex()->point();
|
||||||
const Point_3 &p1 = he->vertex()->point();
|
const Point &p1 = he->vertex()->point();
|
||||||
const Point_3 &p2 = he->next()->vertex()->point();
|
const Point &p2 = he->next()->vertex()->point();
|
||||||
FT area(std::sqrt(CGAL::to_double(CGAL::squared_area(p0, p1, p2))));
|
const FT area = std::sqrt(CGAL::to_double(CGAL::squared_area(p0, p1, p2)));
|
||||||
|
const Point barycenter = CGAL::centroid(p0, p1, p2);
|
||||||
facet_areas.insert(std::pair<Facet_handle, FT>(fitr, area));
|
facet_areas.insert(std::pair<Facet_handle, FT>(fitr, area));
|
||||||
facet_centers.insert(std::pair<Facet_handle, Point_3>(fitr, CGAL::centroid(p0, p1, p2)));
|
facet_centers.insert(std::pair<Facet_handle, Point>(fitr, barycenter));
|
||||||
}
|
}
|
||||||
FacetAreaMap area_pmap(facet_areas);
|
FacetAreaMap area_pmap(facet_areas);
|
||||||
FacetCenterMap center_pmap(facet_centers);
|
FacetCenterMap center_pmap(facet_centers);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue