Points_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): Vincent Rouvreau
6  *
7  * Copyright (C) 2015 Inria
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 POINTS_OFF_IO_H_
23 #define POINTS_OFF_IO_H_
24 
25 #include <gudhi/Off_reader.h>
26 
27 #include <string>
28 #include <vector>
29 #include <fstream>
30 #include <map>
31 
32 namespace Gudhi {
33 
37 template<typename Point_d>
39  private:
40  std::vector<Point_d> point_cloud;
41 
42  public:
53  void init(int dim, int num_vertices, int num_faces, int num_edges) {
54 #ifdef DEBUG_TRACES
55  std::cout << "Points_off_visitor_reader::init - dim=" << dim << " - num_vertices=" <<
56  num_vertices << " - num_faces=" << num_faces << " - num_edges=" << num_edges << std::endl;
57 #endif // DEBUG_TRACES
58  if (num_faces > 0) {
59  std::cerr << "Points_off_visitor_reader::init faces are not taken into account from OFF file for Points.\n";
60  }
61  if (num_edges > 0) {
62  std::cerr << "Points_off_visitor_reader::init edges are not taken into account from OFF file for Points.\n";
63  }
64  }
65 
79  void point(const std::vector<double>& point) {
80 #ifdef DEBUG_TRACES
81  std::cout << "Points_off_visitor_reader::point ";
82  for (auto coordinate : point) {
83  std::cout << coordinate << " | ";
84  }
85  std::cout << std::endl;
86 #endif // DEBUG_TRACES
87  // Fill the point cloud
88  point_cloud.push_back(Point_d(point.begin(), point.end()));
89  }
90 
91  // Off_reader visitor maximal_face implementation - Only points are read
92  void maximal_face(const std::vector<int>& face) { }
93 
94  // Off_reader visitor done implementation - Only points are read
95  void done() { }
96 
101  const std::vector<Point_d>& get_point_cloud() const {
102  return point_cloud;
103  }
104 };
105 
133 template<typename Point_d>
135  public:
143  Points_off_reader(const std::string& name_file)
144  : valid_(false) {
145  std::ifstream stream(name_file);
146  if (stream.is_open()) {
147  Off_reader off_reader(stream);
149  valid_ = off_reader.read(off_visitor);
150  if (valid_) {
151  point_cloud = off_visitor.get_point_cloud();
152  }
153  } else {
154  std::cerr << "Points_off_reader::Points_off_reader could not open file " << name_file << "\n";
155  }
156  }
157 
162  bool is_valid() const {
163  return valid_;
164  }
165 
170  const std::vector<Point_d>& get_point_cloud() const {
171  return point_cloud;
172  }
173 
174  private:
176  std::vector<Point_d> point_cloud;
178  bool valid_;
179 };
180 
181 } // namespace Gudhi
182 
183 #endif // POINTS_OFF_IO_H_
bool read(OffVisitor &off_visitor)
Read an OFF file and calls the following methods :
Definition: Off_reader.h:65
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:134
OFF file visitor implementation according to Off_reader in order to read points from an OFF file...
Definition: Points_off_io.h:38
Definition: SimplicialComplexForAlpha.h:26
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:170
Points_off_reader(const std::string &name_file)
Reads the OFF file and constructs a vector of points from the points that are in the OFF file...
Definition: Points_off_io.h:143
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:101
void init(int dim, int num_vertices, int num_faces, int num_edges)
Off_reader visitor init implementation.
Definition: Points_off_io.h:53
OFF file reader top class visitor.
Definition: Off_reader.h:43
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_off_io.h:162
void point(const std::vector< double > &point)
Off_reader visitor point implementation.
Definition: Points_off_io.h:79
GUDHI  Version 2.3.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Tue Sep 4 2018 14:32:59 for GUDHI by Doxygen 1.8.13