From 1ae99c5f04b6d14a730bdc8fea2e77d33665cd26 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 14 Dec 2017 12:31:48 +0000 Subject: Add cmake improvement for Persistence representation module. Was bad tested and too hard to maintain git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration_cmake_improvement@3071 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fa4684701edbe6d172e75f119afa912eb3b5dad7 --- .../utilities/persistence_intervals/CMakeLists.txt | 38 +++++++++------------ ...te_birth_death_range_in_persistence_diagram.cpp | 22 +++++++----- .../compute_bottleneck_distance.cpp | 20 +++++------ .../compute_number_of_dominant_intervals.cpp | 1 - .../plot_histogram_of_intervals_lengths.cpp | 39 ++++++++++++---------- .../plot_persistence_Betti_numbers.cpp | 30 ++++++++--------- .../plot_persistence_intervals.cpp | 13 ++++---- 7 files changed, 81 insertions(+), 82 deletions(-) (limited to 'src/Persistence_representations/utilities/persistence_intervals') diff --git a/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt index 2ba6efe5..897e12a3 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt +++ b/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt @@ -1,40 +1,32 @@ cmake_minimum_required(VERSION 2.6) project(Persistence_representations_intervals_utilities) -file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") -add_executable ( plot_persistence_intervals plot_persistence_intervals.cpp ) - -add_test(NAME plot_persistence_intervals COMMAND $ - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( compute_birth_death_range_in_persistence_diagram compute_birth_death_range_in_persistence_diagram.cpp ) - -add_test(NAME compute_birth_death_range_in_persistence_diagram COMMAND $ - "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") +add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp ) -add_executable ( compute_number_of_dominant_intervals compute_number_of_dominant_intervals.cpp ) +add_test(NAME plot_histogram_of_intervals_lengths COMMAND $ + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" "-1") -add_test(NAME compute_number_of_dominant_intervals COMMAND $ - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" "-1" "2") +add_persistence_representation_plot_utility(plot_persistence_intervals "") +add_persistence_representation_plot_utility(plot_persistence_Betti_numbers "") -add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp ) +add_persistence_representation_creation_utility(compute_birth_death_range_in_persistence_diagram "-1") -add_test(NAME plot_histogram_of_intervals_lengths COMMAND $ - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" "2") -add_executable ( plot_persistence_Betti_numbers plot_persistence_Betti_numbers.cpp ) +add_executable ( compute_number_of_dominant_intervals compute_number_of_dominant_intervals.cpp ) +add_test(NAME Persistence_representation_utilities_compute_number_of_dominant_intervals + COMMAND $ + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" "-1" "2") -add_test(NAME plot_persistence_Betti_numbers COMMAND $ - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) add_executable ( compute_bottleneck_distance compute_bottleneck_distance.cpp ) if (TBB_FOUND) target_link_libraries(compute_bottleneck_distance ${TBB_LIBRARIES}) endif(TBB_FOUND) - - add_test(NAME compute_bottleneck_distance COMMAND $ - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") + add_test(NAME Persistence_representation_utilities_compute_bottleneck_distance + COMMAND $ + "-1" + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" + "${CMAKE_CURRENT_BINARY_DIR}/../second.pers") endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp index 66fa31ca..9102da79 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp @@ -20,7 +20,6 @@ * along with this program. If not, see . */ -#include #include #include @@ -31,16 +30,21 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - std::cout << "This program compute the range of birth and death times of persistence pairs in diagrams provided as " - "an input. \n"; - std::cout << "The first parameter of the program is the dimension of persistence to be used. If your file contains "; - std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence " - "pairs you want to use. If your input files consist only "; - std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; - std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n"; + std::cout << "This program computes the range of birth and death times of persistence pairs in diagrams provided as " + << "an input.\n" + << "The first parameter is the dimension of persistence to be used to create persistence intervals. " + << "If your file contains the information about dimension of persistence pairs, please provide here the " + << "dimension of persistence pairs you want to use. " + << "If your input files consist only of birth-death pairs, please set this first parameter to -1.\n" + << "The remaining parameters of the program are the names of files with persistence diagrams.\n"; + + if (argc < 3) { + std::cout << "Wrong parameter list, the program will now terminate \n"; + return 1; + } - int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits::max(); + int dim = atoi(argv[1]); if (dim >= 0) { dimension = (unsigned)dim; } diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp index 0b1b526d..c8290845 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp @@ -21,7 +21,6 @@ */ #include -#include #include #include @@ -31,21 +30,21 @@ using Persistence_intervals_with_distances = Gudhi::Persistence_representations::Persistence_intervals_with_distances; int main(int argc, char** argv) { - std::cout << "This program compute the bottleneck distance of persistence diagrams stored in a files. \n"; - std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence " - "landscapes. If your file contains "; - std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence " - "pairs you want to use. If your input files consist only "; - std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; - std::cout << "The remaining parameters of this programs are names of files with persistence diagrams.\n"; + std::cout << "This program computes the bottleneck distance of persistence pairs in diagrams provided as " + << "an input.\n" + << "The first parameter is the dimension of persistence to be used to create persistence intervals. " + << "If your file contains the information about dimension of persistence pairs, please provide here the " + << "dimension of persistence pairs you want to use. " + << "If your input files consist only of birth-death pairs, please set this first parameter to -1.\n" + << "The remaining parameters of the program are the names of files with persistence diagrams.\n"; if (argc < 3) { std::cout << "Wrong number of parameters, the program will now terminate \n"; return 1; } - int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits::max(); + int dim = atoi(argv[1]); if (dim >= 0) { dimension = (unsigned)dim; } @@ -80,7 +79,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("distance"); + out.open("distance.itv"); for (size_t i = 0; i != distance.size(); ++i) { for (size_t j = 0; j != distance.size(); ++j) { std::cout << distance[i][j] << " "; @@ -91,5 +90,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'distance.itv' file\n"; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp index 1286ca57..b3d126f0 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp @@ -20,7 +20,6 @@ * along with this program. If not, see . */ -#include #include #include diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp index d68f4584..ccb5b645 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp @@ -20,7 +20,6 @@ * along with this program. If not, see . */ -#include #include #include @@ -31,30 +30,34 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - std::cout << "This program compute a histogram of barcode's length. A number of bins in the histogram is a parameter " - "of this program. \n"; - if (argc != 3) { + std::cout << "This program computes a histogram of barcode's length. A number of bins in the histogram is a " + << "parameter of this program. \n"; + if ((argc != 3) && (argc != 4)) { std::cout << "To run this program, please provide the name of a file with persistence diagram and number of " - "dominant intervals you would like to get \n"; - std::cout << "The third parameter of a program is the dimension of the persistence that is to be used. If your " - "file contains only birth-death pairs, you can skip this parameter\n"; + << "dominant intervals you would like to get. Set a negative number dominant intervals value " + << "If your file contains only birth-death pairs.\n" + << "The third parameter is the dimension of the persistence that is to be used. If your " + << "file contains only birth-death pairs, you can skip this parameter\n"; return 1; } - unsigned dimension = std::numeric_limits::max(); - int dim = -1; - if (argc > 2) { - dim = atoi(argv[2]); + + unsigned dominant_interval_number = std::numeric_limits::max(); + int nbr = atoi(argv[2]); + if (nbr >= 0) { + dominant_interval_number = static_cast(nbr); } - if (dim >= 0) { - dimension = (unsigned)dim; + + int persistence_dimension = -1; + if (argc == 4) { + persistence_dimension = atoi(argv[3]); } - Persistence_intervals p(argv[1], dimension); - std::vector > dominant_intervals = p.dominant_intervals(atoi(argv[2])); + Persistence_intervals p(argv[1], dominant_interval_number); + std::vector > dominant_intervals = p.dominant_intervals(persistence_dimension); std::vector histogram = p.histogram_of_lengths(10); std::stringstream gnuplot_script; - gnuplot_script << argv[1] << "_Gnuplot_script"; + gnuplot_script << argv[1] << "_GnuplotScript"; std::ofstream out; out.open(gnuplot_script.str().c_str()); @@ -66,7 +69,9 @@ int main(int argc, char** argv) { out << histogram[i] << std::endl; } out << std::endl; - std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; out.close(); + + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp index da2b9319..b433c2b3 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp @@ -20,7 +20,6 @@ * along with this program. If not, see . */ -#include #include #include @@ -31,29 +30,24 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - std::cout << "This program compute a plot of persistence Betti numbers. The input parameter is a file with " - "persistence intervals. \n"; - std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. If " - "your file contains only birth-death pairs, you can skip this parameter\n"; - if (argc < 2) { - std::cout << "To run this program, please provide the name of a file with persistence diagram and number of " - "dominant intervals you would like to get \n"; + if ((argc != 3) && (argc != 2)) { + std::cout << "This program creates a gnuplot script of Betti numbers from a single persistence diagram file" + << "(*.pers).\n" + << "To run this program, please provide the name of a file with persistence diagram.\n" + << "The second optional parameter of a program is the dimension of the persistence that is to be used. " + << "If your file contains only birth-death pairs, you can skip this parameter.\n"; return 1; } + unsigned dimension = std::numeric_limits::max(); int dim = -1; - if (argc > 2) { + if (argc == 3) { dim = atoi(argv[2]); } if (dim >= 0) { dimension = (unsigned)dim; } - std::stringstream gnuplot_script; - gnuplot_script << argv[1] << "_Gnuplot_script"; - std::ofstream out; - out.open(gnuplot_script.str().c_str()); - Persistence_intervals p(argv[1], dimension); std::vector > pbns = p.compute_persistent_betti_numbers(); @@ -69,6 +63,11 @@ int main(int argc, char** argv) { xRangeEnd += (xRangeEnd - xRangeBegin) / 100.0; yRangeEnd += yRangeEnd / 100; + std::stringstream gnuplot_script; + gnuplot_script << argv[1] << "_GnuplotScript"; + std::ofstream out; + out.open(gnuplot_script.str().c_str()); + out << "set xrange [" << xRangeBegin << " : " << xRangeEnd << "]" << std::endl; out << "set yrange [" << yRangeBegin << " : " << yRangeEnd << "]" << std::endl; out << "plot '-' using 1:2 notitle with lp " << std::endl; @@ -81,7 +80,8 @@ int main(int argc, char** argv) { out << std::endl; out.close(); - std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp index e7d29e84..33387802 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp @@ -20,9 +20,7 @@ * along with this program. If not, see . */ -#include #include -#include #include #include @@ -32,15 +30,16 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - if (argc < 2) { - std::cout << "To run this program, please provide the name of a file with persistence diagram \n"; - std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. " - "If your file contains only birth-death pairs, you can skip this parameter\n"; + if ((argc != 3) && (argc != 2)) { + std::cout << "This program creates a gnuplot script from a single persistence diagram file (*.pers).\n" + << "To run this program, please provide the name of a file with persistence diagram.\n" + << "The second optional parameter of a program is the dimension of the persistence that is to be used. " + << "If your file contains only birth-death pairs, you can skip this parameter.\n"; return 1; } unsigned dimension = std::numeric_limits::max(); int dim = -1; - if (argc > 2) { + if (argc == 3) { dim = atoi(argv[2]); } if (dim >= 0) { -- cgit v1.2.3