All Classes Functions Variables Typedefs Friends Groups Pages
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 Saclay (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 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 
80  void point(const std::vector<double>& point) {
81 #ifdef DEBUG_TRACES
82  std::cout << "Points_off_visitor_reader::point ";
83  for (auto coordinate : point) {
84  std::cout << coordinate << " | ";
85  }
86  std::cout << std::endl;
87 #endif // DEBUG_TRACES
88  // Fill the point cloud
89  point_cloud.push_back(Point_d(point.size(), point.begin(), point.end()));
90  }
91 
92  // Off_reader visitor maximal_face implementation - Only points are read
93  void maximal_face(const std::vector<int>& face) { }
94 
95  // Off_reader visitor done implementation - Only points are read
96  void done() { }
97 
102  const std::vector<Point_d>& get_point_cloud() const {
103  return point_cloud;
104  }
105 };
106 
134 template<typename Point_d>
136  public:
144  Points_off_reader(const std::string& name_file)
145  : valid_(false) {
146  std::ifstream stream(name_file);
147  if (stream.is_open()) {
148  Off_reader off_reader(stream);
150  valid_ = off_reader.read(off_visitor);
151  if (valid_) {
152  point_cloud = off_visitor.get_point_cloud();
153  }
154  } else {
155  std::cerr << "Points_off_reader::Points_off_reader could not open file " << name_file << "\n";
156  }
157  }
158 
163  bool is_valid() const {
164  return valid_;
165  }
166 
171  const std::vector<Point_d>& get_point_cloud() const {
172  return point_cloud;
173  }
174 
175  private:
177  std::vector<Point_d> point_cloud;
179  bool valid_;
180 };
181 
182 } // namespace Gudhi
183 
184 #endif // POINTS_OFF_IO_H_
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:102
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:135
OFF file visitor implementation according to Off_reader in order to read points from an OFF file...
Definition: Points_off_io.h:38
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:171
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:144
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:163
void point(const std::vector< double > &point)
Off_reader visitor point implementation.
Definition: Points_off_io.h:80
GUDHI  Version 1.3.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding. Generated on Fri Apr 15 2016 17:36:21 for GUDHI by doxygen 1.8.6