summaryrefslogtreecommitdiff
path: root/src/Bottleneck_distance/example
diff options
context:
space:
mode:
authorfgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-07-23 11:07:58 +0000
committerfgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-07-23 11:07:58 +0000
commitaa9705ab541323e1d7aa0129c8faf0416b0489e0 (patch)
tree28688c65b2457993ae366e663a6422500ba4c623 /src/Bottleneck_distance/example
parent6c611b11c08bc314d8075ae6a038d4af549a7f2e (diff)
read files
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bottleneckDistance@1393 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d7f1b1166b65f7d7abc007abb47d86f8d4ba4157
Diffstat (limited to 'src/Bottleneck_distance/example')
-rw-r--r--src/Bottleneck_distance/example/bottleneck_example.cpp64
1 files changed, 49 insertions, 15 deletions
diff --git a/src/Bottleneck_distance/example/bottleneck_example.cpp b/src/Bottleneck_distance/example/bottleneck_example.cpp
index b3d26f3c..b581a3be 100644
--- a/src/Bottleneck_distance/example/bottleneck_example.cpp
+++ b/src/Bottleneck_distance/example/bottleneck_example.cpp
@@ -2,9 +2,9 @@
* (Geometric Understanding in Higher Dimensions) is a generic C++
* library for computational topology.
*
- * Author(s): Francois Godi
+ * Author(s): Francois Godi, small modifications by Pawel Dlotko
*
- * Copyright (C) 2015 INRIA Sophia-Antipolis (France)
+ * Copyright (C) 2015 INRIA Saclay (France)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,21 +22,55 @@
#include <gudhi/Graph_matching.h>
#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+using namespace std;
-int main() {
- std::vector< std::pair<double,double> > v1, v2;
+//PD: I am using this type of procedures a lot in Gudhi stat. We should make one for all at some point.
+std::vector< std::pair<double, double> > read_diagram_from_file( const char* filename )
+{
+ ifstream in;
+ in.open( filename );
+ std::vector< std::pair<double, double> > result;
+ if ( !in.is_open() )
+ {
+ std::cerr << "File : " << filename << " do not exist. The program will now terminate \n";
+ throw "File do not exist \n";
+ }
- v1.push_back(std::pair<double,double>(2.7,3.7));
- v1.push_back(std::pair<double,double>(9.6,14));
- v1.push_back(std::pair<double,double>(34.2,34.974));
+ std::string line;
+ while (!in.eof())
+ {
+ getline(in,line);
+ if ( line.length() != 0 )
+ {
+ std::stringstream lineSS;
+ lineSS << line;
+ double beginn, endd;
+ lineSS >> beginn;
+ lineSS >> endd;
+ result.push_back( std::make_pair( beginn , endd ) );
+ }
+ }
+ in.close();
+ return result;
+}//read_diagram_from_file
- v2.push_back(std::pair<double,double>(2.8,4.45));
- v2.push_back(std::pair<double,double>(9.5,14.1));
-
- double b = Gudhi::Bottleneck_distance::compute(v1, v2, 0.0001);
- std::cout << "Approx. bottleneck distance = " << b << std::endl;
-
- b = Gudhi::Bottleneck_distance::compute(v1, v2);
- std::cout << "Bottleneck distance = " << b << std::endl;
+int main( int argc , char** argv )
+{
+ if ( argc < 3 )
+ {
+ std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck distance (set by default to zero). The program will now terminate \n";
+ }
+ std::vector< std::pair< double , double > > diag1 = read_diagram_from_file( argv[1] );
+ std::vector< std::pair< double , double > > diag2 = read_diagram_from_file( argv[2] );
+ double tolerance = 0;
+ if ( argc == 4 )
+ {
+ tolerance = atof( argv[3] );
+ }
+ double b = Gudhi::Bottleneck_distance::compute(diag1, diag2, tolerance);
+ std::cout << "The distance between the diagrams is : " << b << ". The tolerace is : " << tolerance << std::endl;
}