Loading...
Searching...
No Matches
Gudhi::Points_off_reader< Point_d > Class Template Reference

OFF file reader implementation in order to read points from an OFF file. More...

#include <include/gudhi/Points_off_io.h>

Public Member Functions

 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. More...
 
bool is_valid () const
 Returns if the OFF file read operation was successful or not. More...
 
const std::vector< Point_d > & get_point_cloud () const
 Point cloud getter. More...
 

Detailed Description

template<typename Point_d>
class Gudhi::Points_off_reader< Point_d >

OFF file reader implementation in order to read points from an OFF file.

This class is using the Points_off_visitor_reader to visit the OFF file according to Off_reader.

Point_d must have a constructor with the following form:

template<class InputIterator > Point_d::Point_d(int d, InputIterator first, InputIterator last)

where d is the point dimension.

Example

This example loads points from an OFF file and builds a vector of points (vector of double). Then, it is asked to display the points.

#include <gudhi/Points_off_io.h>
#include <iostream>
#include <string>
#include <vector>
using Point_d = std::vector<double>;
void usage(char * const progName) {
std::cerr << "Usage: " << progName << " inputFile.off" << std::endl;
exit(-1);
}
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << "Error: Number of arguments (" << argc << ") is not correct" << std::endl;
usage(argv[0]);
}
std::string off_input_file(argv[1]);
// Read the OFF file (input file name given as parameter) and triangulate points
Gudhi::Points_off_reader<Point_d> off_reader(off_input_file);
// Check the read operation was correct
if (!off_reader.is_valid()) {
std::cerr << "Unable to read file " << off_input_file << std::endl;
usage(argv[0]);
}
// Retrieve the triangulation
std::vector<Point_d> point_cloud = off_reader.get_point_cloud();
std::ofstream output_file(off_input_file + ".txt");
int n {0};
for (auto point : point_cloud) {
output_file << "Point[" << n << "] = ";
for (std::size_t i {0}; i < point.size(); i++)
output_file << point[i] << " ";
output_file << "\n";
++n;
}
output_file.close();
return 0;
}
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:122

When launching:

$> ./vector_double_off_reader ../../data/points/alphacomplexdoc.off

the program outputs a file ../../data/points/alphacomplexdoc.off.txt:

Point[0] = 1 1 0
Point[1] = 7 0 0
Point[2] = 4 6 0
Point[3] = 9 6 0
Point[4] = 0 14 0
Point[5] = 2 19 0
Point[6] = 9 17 0
Examples
alpha_complex_persistence.cpp, alpha_rips_persistence_bottleneck_distance.cpp, cech_complex_cgal_mini_sphere_3d.cpp, cech_persistence.cpp, edge_collapse_conserve_persistence.cpp, example_CGAL_points_off_reader.cpp, example_rips_complex_from_off_file.cpp, example_strong_witness_complex_off.cpp, example_vector_double_points_off_reader.cpp, example_witness_complex_off.cpp, point_cloud_edge_collapse_rips_persistence.cpp, rips_multifield_persistence.cpp, rips_persistence.cpp, rips_persistence_step_by_step.cpp, rips_persistence_via_boundary_matrix.cpp, sparse_rips_persistence.cpp, strong_witness_persistence.cpp, and weak_witness_persistence.cpp.

Constructor & Destructor Documentation

◆ Points_off_reader()

template<typename Point_d >
Gudhi::Points_off_reader< Point_d >::Points_off_reader ( const std::string &  name_file)
inline

Reads the OFF file and constructs a vector of points from the points that are in the OFF file.

Parameters
[in]name_fileOFF file to read.
Postcondition
Check with is_valid() function to see if read operation was successful.

Member Function Documentation

◆ get_point_cloud()

template<typename Point_d >
const std::vector< Point_d > & Gudhi::Points_off_reader< Point_d >::get_point_cloud ( ) const
inline

Point cloud getter.

Returns
point_cloud.
Examples
example_strong_witness_complex_off.cpp, and example_witness_complex_off.cpp.

◆ is_valid()

template<typename Point_d >
bool Gudhi::Points_off_reader< Point_d >::is_valid ( ) const
inline

Returns if the OFF file read operation was successful or not.

Returns
OFF file read status.
Examples
example_strong_witness_complex_off.cpp, and example_witness_complex_off.cpp.

The documentation for this class was generated from the following file: