Skip to content

Commit

Permalink
Lighten the examples a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
palliez committed Aug 23, 2017
1 parent 02a581a commit 45c7505
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
Expand Up @@ -31,6 +31,8 @@ if ( NOT Boost_FOUND )

endif()

add_definitions(-DBOOST_NO_CXX11_TEMPLATE_ALIASES)

# include for local directory

# include for local package
Expand Down
Expand Up @@ -13,28 +13,28 @@ typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
int main()
{
// create and read Polyhedron
Polyhedron mesh;
std::ifstream input("data/bear.off");
if (!input || !(input >> mesh) || mesh.empty()) {
Polyhedron input;
std::ifstream file("data/bear.off");
if (!file || !(file >> input) || input.empty()) {
std::cerr << "Invalid off file." << std::endl;
return EXIT_FAILURE;
}

// output data
Polyhedron out_mesh;
std::vector<int> tris;
std::vector<Kernel::Point_3> anchor_pos;
Polyhedron output;
std::vector<int> triangles;
std::vector<Kernel::Point_3> anchors;

// 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
number_of_iterations(30). // number of iterations
init_method(1). // hierarchical init
anchor_point(std::back_inserter(anchor_pos)). // get anchor points
indexed_triangles(std::back_inserter(tris))); // get indexed triangles
anchor_point(std::back_inserter(anchors)). // get anchor points
indexed_triangles(std::back_inserter(triangles))); // get indexed triangles

std::cout << "#anchor_pos " << anchor_pos.size() << std::endl;
std::cout << "#tris " << tris.size() << std::endl;
std::cout << "#anchors: " << anchors.size() << std::endl;
std::cout << "#triangles: " << triangles.size() << std::endl;

return EXIT_SUCCESS;
}
Expand Up @@ -11,20 +11,20 @@

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Vector_3 Vector_3;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Point_3 Point;

typedef CGAL::Polyhedron_3<Kernel> Polyhedron_3;
typedef Polyhedron_3::Facet_handle Facet_handle;
typedef Polyhedron_3::Halfedge_handle Halfedge_handle;
typedef Polyhedron_3::Facet_iterator Facet_iterator;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::Facet_handle Facet_handle;
typedef Polyhedron::Halfedge_handle Halfedge_handle;
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, Point_3> > FacetCenterMap;
typedef boost::associative_property_map<std::map<Facet_handle, Point> > FacetCenterMap;

// proxy
struct PointProxy {
Facet_handle seed;
Point_3 center;
Point center;
};

// metric functor
Expand Down Expand Up @@ -57,8 +57,8 @@ struct PointProxyFitting {
template<typename FacetIterator>
PointProxy operator()(const FacetIterator beg, const FacetIterator end) const {
// fitting center
Vector_3 center = CGAL::NULL_VECTOR;
FT area(0);
Vector center = CGAL::NULL_VECTOR;
FT area = FT(0.0);
for (FacetIterator fitr = beg; fitr != end; ++fitr) {
center = center + (center_pmap[*fitr] - CGAL::ORIGIN) * area_pmap[*fitr];
area += area_pmap[*fitr];
Expand All @@ -75,12 +75,12 @@ struct PointProxyFitting {
const FacetCenterMap center_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()
{
// create and read Polyhedron_3
Polyhedron_3 mesh;
Polyhedron mesh;
std::ifstream input("data/bear.off");
if (!input || !(input >> mesh) || mesh.empty()) {
std::cerr << "Invalid off file." << std::endl;
Expand All @@ -89,15 +89,16 @@ int main()

// construct precomputed facet normal and area map
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) {
const Halfedge_handle he = fitr->halfedge();
const Point_3 &p0 = he->opposite()->vertex()->point();
const Point_3 &p1 = he->vertex()->point();
const Point_3 &p2 = he->next()->vertex()->point();
FT area(std::sqrt(CGAL::to_double(CGAL::squared_area(p0, p1, p2))));
const Point &p0 = he->opposite()->vertex()->point();
const Point &p1 = he->vertex()->point();
const Point &p2 = he->next()->vertex()->point();
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_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);
FacetCenterMap center_pmap(facet_centers);
Expand Down

0 comments on commit 45c7505

Please sign in to comment.