Gudhi::Points_off_reader< Point_d > Class Template Reference

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

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;
}

When launching:

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

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

Point[0] = 1 1
Point[1] = 7 0
Point[2] = 4 6
Point[3] = 9 6
Point[4] = 0 14
Point[5] = 2 19
Point[6] = 9 17
Examples:
Bottleneck_distance/alpha_rips_persistence_bottleneck_distance.cpp, common/example_CGAL_points_off_reader.cpp, common/example_vector_double_points_off_reader.cpp, Persistent_cohomology/rips_multifield_persistence.cpp, Persistent_cohomology/rips_persistence_step_by_step.cpp, Persistent_cohomology/rips_persistence_via_boundary_matrix.cpp, Rips_complex/example_rips_complex_from_off_file.cpp, Rips_complex/rips_persistence.cpp, Simplex_tree/cech_complex_cgal_mini_sphere_3d.cpp, Witness_complex/example_strong_witness_complex_off.cpp, Witness_complex/example_witness_complex_off.cpp, Witness_complex/strong_witness_persistence.cpp, and Witness_complex/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:
Simplex_tree/cech_complex_cgal_mini_sphere_3d.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.

The documentation for this class was generated from the following file:
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:55 for GUDHI by Doxygen 1.8.13