#ifndef GARLAND_HECKBERT_H_
#define GARLAND_HECKBERT_H_
#include <gudhi/Point.h>
#include <gudhi/Edge_contraction.h>
#include <gudhi/Skeleton_blocker.h>
#include <gudhi/Off_reader.h>
#include <iostream>
#include "Garland_heckbert/Error_quadric.h"
struct Geometry_trait {
typedef Point_d Point;
};
struct Garland_heckbert_traits
public:
struct Garland_heckbert_vertex : public Simple_geometric_vertex {
Error_quadric<Geometry_trait::Point> quadric;
};
typedef Garland_heckbert_vertex Graph_vertex;
};
using EdgeProfile = Gudhi::contraction::Edge_profile<Complex>;
public:
typedef Gudhi::contraction::Placement_policy<EdgeProfile>::Placement_type Placement_type;
GH_placement(
Complex& complex) : complex_(complex) { (void)complex_; }
Placement_type operator()(const EdgeProfile& profile) const override {
auto sum_quad(profile.v0().quadric);
sum_quad += profile.v1().quadric;
boost::optional<Point> min_quadric_pt(sum_quad.min_cost());
if (min_quadric_pt)
return Placement_type(*min_quadric_pt);
else
return profile.p0();
}
};
public:
typedef Gudhi::contraction::Cost_policy<EdgeProfile>::Cost_type Cost_type;
GH_cost(
Complex& complex) : complex_(complex) { (void)complex_; }
Cost_type operator()(EdgeProfile const& profile, boost::optional<Point> const& new_point) const override {
Cost_type res;
if (new_point) {
auto sum_quad(profile.v0().quadric);
sum_quad += profile.v1().quadric;
res = sum_quad.cost(*new_point);
}
return res;
}
};
public:
GH_visitor(
Complex& complex) : complex_(complex) { (void)complex_; }
auto & quadric_v(complex[v].quadric);
auto t_it = t.begin();
const auto& p0(complex.
point(*t_it++));
const auto& p1(complex.
point(*t_it++));
const auto& p2(complex.
point(*t_it++));
quadric_v += Error_quadric<Point>(p0, p1, p2);
}
}
}
void on_contracting(EdgeProfile
const &profile, boost::optional< Point > placement)
override {
profile.v0().quadric += profile.v1().quadric;
}
};
int main(int argc, char *argv[]) {
if (argc != 4) {
std::cerr << "Usage " << argv[0] <<
" input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n";
return EXIT_FAILURE;
}
if (!off_reader.is_valid()) {
std::cerr << "Unable to read file:" << argv[1] << std::endl;
return EXIT_FAILURE;
}
std::cerr << "Only points of dimension 3 are supported." << std::endl;
return EXIT_FAILURE;
}
std::clog <<
"Load complex with " << complex.
num_vertices() <<
" vertices" << std::endl;
int num_contractions = atoi(argv[3]);
new GH_cost(complex),
new GH_placement(complex),
Gudhi::contraction::make_link_valid_contraction<EdgeProfile>(),
new GH_visitor(complex));
std::clog << "Contract " << num_contractions << " edges" << std::endl;
contractor.contract_edges(num_contractions);
std::clog << "Final complex has " <<
complex.num_vertices() << " vertices, " <<
complex.
num_edges() <<
" edges and " <<
complex.
num_triangles() <<
" triangles." << std::endl;
Gudhi::skeleton_blocker::Skeleton_blocker_off_writer<Complex> off_writer(argv[2], complex);
return EXIT_SUCCESS;
}
#endif
Interface for a visitor of the edge contraction process.
Definition: Contraction_visitor.h:27
virtual void on_started(ComplexType &complex)
Called before the edge contraction process starts.
Definition: Contraction_visitor.h:41
virtual void on_contracting(const Profile &profile, boost::optional< Point > placement)
Called when an edge is about to be contracted and replaced by a vertex whose position is *placement.
Definition: Contraction_visitor.h:61
Policy to specify the cost of contracting an edge.
Definition: Cost_policy.h:25
Policy to specify where the merged point had to be placed after an edge contraction.
Definition: Placement_policy.h:25
Class that allows to contract iteratively edges of a simplicial complex.
Definition: Skeleton_blocker_contractor.h:98
Complex_triangle_around_vertex_range triangle_range(Vertex_handle v) const
Range over triangles around a vertex of the simplicial complex. Methods .begin() and ....
Definition: Skeleton_blocker_complex.h:1358
Complex_vertex_range vertex_range() const
Returns a Complex_vertex_range over all vertices of the complex.
Definition: Skeleton_blocker_complex.h:1282
Class that represents a geometric complex that can be simplified. The class allows access to points o...
Definition: Skeleton_blocker_geometric_complex.h:29
const Point & point(Vertex_handle v) const
Returns the Point associated to the vertex v.
Definition: Skeleton_blocker_geometric_complex.h:101
Class that allows to load a Skeleton_blocker_complex from an off file.
Definition: Skeleton_blocker_off_io.h:108
Simple traits that is a model of SkeletonBlockerGeometricDS and can be passed as a template argument ...
Definition: Skeleton_blocker_simple_geometric_traits.h:31
Definition: SkeletonBlockerDS.h:56
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15