Points_3D_off_io.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): Vincent Rouvreau
4  *
5  * Copyright (C) 2015 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 #ifndef POINTS_3D_OFF_IO_H_
11 #define POINTS_3D_OFF_IO_H_
12 
13 #include <gudhi/Off_reader.h>
14 
15 #include <string>
16 #include <vector>
17 #include <fstream>
18 #include <map>
19 
20 namespace Gudhi {
21 
25 template<typename Point_3>
27  private:
28  std::vector<Point_3> point_cloud_;
29  bool valid_;
30 
31  public:
42  void init(int dim, int num_vertices, int num_faces, int num_edges) {
43 #ifdef DEBUG_TRACES
44  std::clog << "Points_3D_off_visitor_reader::init - dim=" << dim << " - num_vertices=" <<
45  num_vertices << " - num_faces=" << num_faces << " - num_edges=" << num_edges << std::endl;
46 #endif // DEBUG_TRACES
47  if (dim == 3) {
48  valid_ = true;
49  } else {
50  valid_ = false;
51  std::cerr << "Points_3D_off_reader::Points_3D_off_reader cannot read OFF files in dimension " << dim << "\n";
52  }
53 
54  if (num_faces > 0) {
55  std::cerr << "Points_3D_off_visitor_reader::init faces are not taken into account from OFF file for Points.\n";
56  }
57  if (num_edges > 0) {
58  std::cerr << "Points_3D_off_visitor_reader::init edges are not taken into account from OFF file for Points.\n";
59  }
60  }
61 
74  void point(const std::vector<double>& point) {
75  if (valid_) {
76 #ifdef DEBUG_TRACES
77  std::clog << "Points_3D_off_visitor_reader::point ";
78  for (auto coordinate : point) {
79  std::clog << coordinate << " | ";
80  }
81  std::clog << std::endl;
82 #endif // DEBUG_TRACES
83  // Fill the point cloud
84  point_cloud_.push_back(Point_3(point[0], point[1], point[2]));
85  }
86  }
87 
88  // Off_reader visitor maximal_face implementation - Only points are read
89 
90  void maximal_face(const std::vector<int>& face) { }
91 
92  // Off_reader visitor done implementation - Only points are read
93 
94  void done() { }
95 
100  const std::vector<Point_3>& get_point_cloud() const {
101  return point_cloud_;
102  }
103 
108  bool is_valid() const {
109  return valid_;
110  }
111 };
112 
139 template<typename Point_3>
141  public:
149  Points_3D_off_reader(const std::string& name_file)
150  : valid_(false) {
151  std::ifstream stream(name_file);
152  if (stream.is_open()) {
153  Off_reader off_reader(stream);
155  valid_ = off_reader.read(off_visitor);
156  valid_ = valid_ && off_visitor.is_valid();
157  if (valid_) {
158  point_cloud = off_visitor.get_point_cloud();
159  }
160  } else {
161  std::cerr << "Points_3D_off_reader::Points_3D_off_reader could not open file " << name_file << "\n";
162  }
163  }
164 
169  bool is_valid() const {
170  return valid_;
171  }
172 
177  const std::vector<Point_3>& get_point_cloud() const {
178  return point_cloud;
179  }
180 
181  private:
183  std::vector<Point_3> point_cloud;
185  bool valid_;
186 };
187 
188 } // namespace Gudhi
189 
190 #endif // POINTS_3D_OFF_IO_H_
bool read(OffVisitor &off_visitor)
Read an OFF file and calls the following methods :
Definition: Off_reader.h:51
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_3D_off_io.h:169
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_3D_off_io.h:108
OFF file visitor implementation according to Off_reader in order to read points from an OFF file...
Definition: Points_3D_off_io.h:26
Definition: SimplicialComplexForAlpha.h:14
const std::vector< Point_3 > & get_point_cloud() const
Point cloud getter.
Definition: Points_3D_off_io.h:177
OFF file reader top class visitor.
Definition: Off_reader.h:29
void point(const std::vector< double > &point)
Off_reader visitor point implementation.
Definition: Points_3D_off_io.h:74
Definition: Points_3D_off_io.h:140
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:149
void init(int dim, int num_vertices, int num_faces, int num_edges)
Off_reader visitor init implementation.
Definition: Points_3D_off_io.h:42
const std::vector< Point_3 > & get_point_cloud() const
Point cloud getter.
Definition: Points_3D_off_io.h:100
GUDHI  Version 3.3.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Tue Aug 11 2020 11:09:13 for GUDHI by Doxygen 1.8.13