Points_3D_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_3D_OFF_IO_H_
23 #define POINTS_3D_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_3>
39  private:
40  std::vector<Point_3> point_cloud_;
41  bool valid_;
42 
43  public:
54  void init(int dim, int num_vertices, int num_faces, int num_edges) {
55 #ifdef DEBUG_TRACES
56  std::cout << "Points_3D_off_visitor_reader::init - dim=" << dim << " - num_vertices=" <<
57  num_vertices << " - num_faces=" << num_faces << " - num_edges=" << num_edges << std::endl;
58 #endif // DEBUG_TRACES
59  if (dim == 3) {
60  valid_ = true;
61  } else {
62  valid_ = false;
63  std::cerr << "Points_3D_off_reader::Points_3D_off_reader cannot read OFF files in dimension " << dim << "\n";
64  }
65 
66  if (num_faces > 0) {
67  std::cerr << "Points_3D_off_visitor_reader::init faces are not taken into account from OFF file for Points.\n";
68  }
69  if (num_edges > 0) {
70  std::cerr << "Points_3D_off_visitor_reader::init edges are not taken into account from OFF file for Points.\n";
71  }
72  }
73 
86  void point(const std::vector<double>& point) {
87  if (valid_) {
88 #ifdef DEBUG_TRACES
89  std::cout << "Points_3D_off_visitor_reader::point ";
90  for (auto coordinate : point) {
91  std::cout << coordinate << " | ";
92  }
93  std::cout << std::endl;
94 #endif // DEBUG_TRACES
95  // Fill the point cloud
96  point_cloud_.push_back(Point_3(point[0], point[1], point[2]));
97  }
98  }
99 
100  // Off_reader visitor maximal_face implementation - Only points are read
101 
102  void maximal_face(const std::vector<int>& face) { }
103 
104  // Off_reader visitor done implementation - Only points are read
105 
106  void done() { }
107 
112  const std::vector<Point_3>& get_point_cloud() const {
113  return point_cloud_;
114  }
115 
120  bool is_valid() const {
121  return valid_;
122  }
123 };
124 
151 template<typename Point_3>
153  public:
161  Points_3D_off_reader(const std::string& name_file)
162  : valid_(false) {
163  std::ifstream stream(name_file);
164  if (stream.is_open()) {
165  Off_reader off_reader(stream);
167  valid_ = off_reader.read(off_visitor);
168  valid_ = valid_ && off_visitor.is_valid();
169  if (valid_) {
170  point_cloud = off_visitor.get_point_cloud();
171  }
172  } else {
173  std::cerr << "Points_3D_off_reader::Points_3D_off_reader could not open file " << name_file << "\n";
174  }
175  }
176 
181  bool is_valid() const {
182  return valid_;
183  }
184 
189  const std::vector<Point_3>& get_point_cloud() const {
190  return point_cloud;
191  }
192 
193  private:
195  std::vector<Point_3> point_cloud;
197  bool valid_;
198 };
199 
200 } // namespace Gudhi
201 
202 #endif // POINTS_3D_OFF_IO_H_
bool read(OffVisitor &off_visitor)
Read an OFF file and calls the following methods :
Definition: Off_reader.h:65
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_3D_off_io.h:181
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_3D_off_io.h:120
OFF file visitor implementation according to Off_reader in order to read points from an OFF file...
Definition: Points_3D_off_io.h:38
Definition: SimplicialComplexForAlpha.h:26
const std::vector< Point_3 > & get_point_cloud() const
Point cloud getter.
Definition: Points_3D_off_io.h:189
OFF file reader top class visitor.
Definition: Off_reader.h:43
void point(const std::vector< double > &point)
Off_reader visitor point implementation.
Definition: Points_3D_off_io.h:86
Definition: Points_3D_off_io.h:152
Points_3D_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_3D_off_io.h:161
void init(int dim, int num_vertices, int num_faces, int num_edges)
Off_reader visitor init implementation.
Definition: Points_3D_off_io.h:54
const std::vector< Point_3 > & get_point_cloud() const
Point cloud getter.
Definition: Points_3D_off_io.h:112
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu Jun 14 2018 15:00:54 for GUDHI by Doxygen 1.8.13