11 #ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ 12 #define SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ 14 #include <gudhi/Off_reader.h> 22 namespace skeleton_blocker {
27 template<
typename Complex>
30 typedef typename Complex::Vertex_handle Vertex_handle;
31 typedef typename Complex::Point Point;
33 const bool load_only_points_;
38 load_only_points_(load_only_points) { }
40 void init(
int dim,
int num_vertices,
int num_faces,
int num_edges) {
45 void point(
const std::vector<double>& point) {
46 complex_.add_vertex(Point(point.begin(), point.end()));
49 void maximal_face(
const std::vector<int>& face) {
50 if (!load_only_points_) {
51 for (
size_t i = 0; i < face.size(); ++i)
52 for (
size_t j = i + 1; j < face.size(); ++j) {
53 complex_.add_edge_without_blockers(Vertex_handle(face[i]), Vertex_handle(face[j]));
64 template<
typename Complex>
67 typedef typename Complex::Vertex_handle Vertex_handle;
68 typedef typename Complex::Simplex Simplex;
69 typedef typename Complex::Point Point;
71 const bool load_only_points_;
72 std::vector<Point> points_;
73 std::vector<Simplex> maximal_faces_;
78 load_only_points_(load_only_points) { }
80 void init(
int dim,
int num_vertices,
int num_faces,
int num_edges) {
81 maximal_faces_.reserve(num_faces);
82 points_.reserve(num_vertices);
85 void point(
const std::vector<double>& point) {
86 points_.emplace_back(point.begin(), point.end());
89 void maximal_face(
const std::vector<int>& face) {
90 if (!load_only_points_) {
93 s.add_vertex(Vertex_handle(x));
94 maximal_faces_.emplace_back(s);
99 complex_ = make_complex_from_top_faces<Complex>(maximal_faces_.begin(), maximal_faces_.end(),
100 points_.begin(), points_.end());
107 template<
typename Complex>
116 bool read_only_points =
false,
bool is_flag =
false) : valid_(false) {
117 std::ifstream stream(name_file);
118 if (stream.is_open()) {
119 if (is_flag || read_only_points) {
122 valid_ = off_reader.
read(off_visitor);
126 valid_ = off_reader.
read(off_visitor);
142 template<
typename Complex>
143 class Skeleton_blocker_off_writer {
150 Skeleton_blocker_off_writer(
const std::string & name_file,
const Complex& save_complex) {
153 std::ofstream stream(name_file);
154 if (stream.is_open()) {
156 size_t num_triangles = std::distance(save_complex.triangle_range().begin(), save_complex.triangle_range().end());
157 stream << save_complex.num_vertices() <<
" " << num_triangles <<
" 0 \n";
161 std::map<Vertex_handle, size_t> vertex_num;
162 size_t current_vertex = 0;
164 for (
auto v : save_complex.vertex_range()) {
165 vertex_num[v] = current_vertex++;
166 const auto& pt(save_complex.point(v));
172 for (
const auto & t : save_complex.triangle_range()) {
175 stream << vertex_num[x] <<
" ";
180 std::cerr <<
"could not open file " << name_file << std::endl;
187 namespace skbl = skeleton_blocker;
191 #endif // SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ bool read(OffVisitor &off_visitor)
Read an OFF file and calls the following methods :
Definition: Off_reader.h:51
Definition: SimplicialComplexForAlpha.h:14
Skeleton_blocker_off_reader(const std::string &name_file, Complex &read_complex, bool read_only_points=false, bool is_flag=false)
Definition: Skeleton_blocker_off_io.h:115
OFF file reader top class visitor.
Definition: Off_reader.h:29
Off reader visitor that can be passed to Off_reader to read a Skeleton_blocker_complex.
Definition: Skeleton_blocker_off_io.h:28
bool is_valid() const
Definition: Skeleton_blocker_off_io.h:134
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15
Off reader visitor that can be passed to Off_reader to read a Skeleton_blocker_complex.
Definition: Skeleton_blocker_off_io.h:65
Class that allows to load a Skeleton_blocker_complex from an off file.
Definition: Skeleton_blocker_off_io.h:108