Loading...
Searching...
No Matches
Points_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_OFF_IO_H_
11#define POINTS_OFF_IO_H_
12
13#include <gudhi/Off_reader.h>
14
15#include <string>
16#include <vector>
17#include <fstream>
18#include <map>
19
20namespace Gudhi {
21
25template<typename Point_d>
27 private:
28 std::vector<Point_d> point_cloud;
29
30 public:
41 void init(int dim, int num_vertices, int num_faces, int num_edges) {
42#ifdef DEBUG_TRACES
43 std::clog << "Points_off_visitor_reader::init - dim=" << dim << " - num_vertices=" <<
44 num_vertices << " - num_faces=" << num_faces << " - num_edges=" << num_edges << std::endl;
45#endif // DEBUG_TRACES
46 if (num_faces > 0) {
47 std::cerr << "Points_off_visitor_reader::init faces are not taken into account from OFF file for Points.\n";
48 }
49 if (num_edges > 0) {
50 std::cerr << "Points_off_visitor_reader::init edges are not taken into account from OFF file for Points.\n";
51 }
52 }
53
67 void point(const std::vector<double>& point) {
68#ifdef DEBUG_TRACES
69 std::clog << "Points_off_visitor_reader::point ";
70 for (auto coordinate : point) {
71 std::clog << coordinate << " | ";
72 }
73 std::clog << std::endl;
74#endif // DEBUG_TRACES
75 // Fill the point cloud
76 point_cloud.push_back(Point_d(point.begin(), point.end()));
77 }
78
79 // Off_reader visitor maximal_face implementation - Only points are read
80 void maximal_face(const std::vector<int>& face) { }
81
82 // Off_reader visitor done implementation - Only points are read
83 void done() { }
84
89 const std::vector<Point_d>& get_point_cloud() const {
90 return point_cloud;
91 }
92};
93
121template<typename Point_d>
123 public:
131 Points_off_reader(const std::string& name_file)
132 : valid_(false) {
133 std::ifstream stream(name_file);
134 if (stream.is_open()) {
135 Off_reader off_reader(stream);
137 valid_ = off_reader.read(off_visitor);
138 if (valid_) {
139 point_cloud = off_visitor.get_point_cloud();
140 }
141 } else {
142 std::cerr << "Points_off_reader::Points_off_reader could not open file " << name_file << "\n";
143 }
144 }
145
150 bool is_valid() const {
151 return valid_;
152 }
153
158 const std::vector<Point_d>& get_point_cloud() const {
159 return point_cloud;
160 }
161
162 private:
164 std::vector<Point_d> point_cloud;
166 bool valid_;
167};
168
169} // namespace Gudhi
170
171#endif // POINTS_OFF_IO_H_
OFF file reader top class visitor.
Definition: Off_reader.h:29
bool read(OffVisitor &off_visitor)
Read an OFF file and calls the following methods :
Definition: Off_reader.h:51
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:122
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:131
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:158
bool is_valid() const
Returns if the OFF file read operation was successful or not.
Definition: Points_off_io.h:150
OFF file visitor implementation according to Off_reader in order to read points from an OFF file.
Definition: Points_off_io.h:26
void point(const std::vector< double > &point)
Off_reader visitor point implementation.
Definition: Points_off_io.h:67
void init(int dim, int num_vertices, int num_faces, int num_edges)
Off_reader visitor init implementation.
Definition: Points_off_io.h:41
const std::vector< Point_d > & get_point_cloud() const
Point cloud getter.
Definition: Points_off_io.h:89