Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
Skeleton_blocker_off_io.h
1  /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): David Salinas
6  *
7  * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 #ifndef SKELETON_BLOCKER_OFF_IO_H_
23 #define SKELETON_BLOCKER_OFF_IO_H_
24 
25 #include "gudhi/Off_reader.h"
26 
27 namespace Gudhi {
28 
29 namespace skbl {
30 
34 template<typename Complex>
36  Complex& complex_;
37  typedef typename Complex::Vertex_handle Vertex_handle;
38  typedef typename Complex::Point Point;
39 
40  const bool load_only_points_;
41 
42 public:
43  Skeleton_blocker_off_visitor_reader(Complex& complex,bool load_only_points = false):
44  complex_(complex),
45  load_only_points_(load_only_points){}
46 
47 
48  void init(int dim,int num_vertices,int num_faces,int num_edges){
49  //todo do an assert to check that this number are correctly read
50  //todo reserve size for vector points
51  }
52 
53 
54  void point(const std::vector<double>& point){
55  complex_.add_vertex(point);
56  }
57 
58  void maximal_face(const std::vector<int>& face){
59  if (!load_only_points_){
60  for(size_t i = 0 ; i < face.size();++i)
61  for(size_t j = i+1 ; j < face.size();++j){
62  complex_.add_edge(Vertex_handle(face[i]),Vertex_handle(face[j]));
63  }
64  }
65  }
66 
67  void done(){
68  }
69 };
70 
74 template<typename Complex>
76 public:
82  Skeleton_blocker_off_reader(const std::string & name_file,Complex& read_complex,bool read_only_points = false):valid_(false){
83  std::ifstream stream(name_file);
84  if(stream.is_open()){
85  Skeleton_blocker_off_visitor_reader<Complex> off_visitor(read_complex,read_only_points);
86  Off_reader off_reader(stream);
87  valid_ = off_reader.read(off_visitor);
88  }
89  }
90 
94  bool is_valid() const{
95  return valid_;
96  }
97 
98 private:
99  bool valid_;
100 };
101 
102 } // namespace skbl
103 
104 
105 } // namespace Gudhi
106 
107 
108 #endif /* SKELETON_BLOCKER_OFF_IO_H_ */
Class that allows to load a Skeleton_blocker_complex from an off file.
Definition: Skeleton_blocker_off_io.h:75
bool read(OffVisitor &off_visitor)
Definition: Off_reader.h:73
Definition: Off_reader.h:51
bool is_valid() const
Definition: Skeleton_blocker_off_io.h:94
Skeleton_blocker_off_reader(const std::string &name_file, Complex &read_complex, bool read_only_points=false)
Definition: Skeleton_blocker_off_io.h:82
Off reader visitor that can be passed to Off_reader to read a Skeleton_blocker_complex.
Definition: Skeleton_blocker_off_io.h:35