From 47b98207fa51f6a05094334ebf4471968a1bc526 Mon Sep 17 00:00:00 2001 From: mcarrier Date: Sat, 13 May 2017 16:14:33 +0000 Subject: git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Nerve_GIC@2415 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 24964dc19f3bf6646ac5c8218b12714f4821cadc --- src/Nerve_GIC/doc/Intro_graph_induced_complex.h | 8 +- src/Nerve_GIC/example/CMakeLists.txt | 3 - src/Nerve_GIC/example/GIC.cpp | 10 +- src/Nerve_GIC/example/GIC.txt | 125 +++++++++++------ src/Nerve_GIC/example/GICvoronoi.cpp | 8 +- src/Nerve_GIC/example/MapperDeltaCoord.cpp | 10 +- src/Nerve_GIC/example/MapperDeltaCoord.txt | 173 +++++++++++++----------- src/Nerve_GIC/example/MapperDeltaFunc.cpp | 6 +- src/Nerve_GIC/example/MapperDeltaFunc.txt | 7 +- src/Nerve_GIC/example/Nerve.cpp | 8 +- src/Nerve_GIC/example/Nerve.txt | 49 +++---- src/Nerve_GIC/include/gudhi/GIC.h | 105 +++++++++++--- src/Nerve_GIC/test/test_GIC.cpp | 17 ++- 13 files changed, 324 insertions(+), 205 deletions(-) diff --git a/src/Nerve_GIC/doc/Intro_graph_induced_complex.h b/src/Nerve_GIC/doc/Intro_graph_induced_complex.h index f30d51a4..9d7883e0 100644 --- a/src/Nerve_GIC/doc/Intro_graph_induced_complex.h +++ b/src/Nerve_GIC/doc/Intro_graph_induced_complex.h @@ -93,9 +93,9 @@ namespace graph_induced_complex { * \subsection gicexample Example * * This example builds the GIC of a point cloud sampled on a 3D human shape (human.off). - * The cover C comes from the preimages of intervals (with length 0.1 and gain 0) + * The cover C comes from the preimages of intervals (with length 0.075 and gain 0) * covering the height function (coordinate 2), - * and the graph G comes from a Rips complex built with threshold 0.1. + * and the graph G comes from a Rips complex built with threshold 0.075. * Note that if the gain is too big, the number of cliques increases a lot, * which make the computation time much larger. * @@ -103,7 +103,7 @@ namespace graph_induced_complex { * * When launching: * - * \code $> ./GIC ../../../data/points/human.off 0.1 2 0.1 0 + * \code $> ./GIC ../../../data/points/human.off 0.075 2 0.075 0 * \endcode * * the program output is: @@ -159,7 +159,7 @@ namespace graph_induced_complex { * Kepler-Mapper library. * One can visualize data by launching: * - * \code python visu.py && firefox SC_visu.html + * \code python visu.py && firefox SC.html * \endcode * * \copyright GNU General Public License v3. diff --git a/src/Nerve_GIC/example/CMakeLists.txt b/src/Nerve_GIC/example/CMakeLists.txt index a4cb0f03..a2e4efe5 100644 --- a/src/Nerve_GIC/example/CMakeLists.txt +++ b/src/Nerve_GIC/example/CMakeLists.txt @@ -13,9 +13,6 @@ target_link_libraries(MapperDeltaCoord ${Boost_SYSTEM_LIBRARY}) add_executable ( MapperDeltaFunc MapperDeltaFunc.cpp ) target_link_libraries(MapperDeltaFunc ${Boost_SYSTEM_LIBRARY}) -add_executable ( GICvoronoi GICvoronoi.cpp ) -target_link_libraries(GICvoronoi ${Boost_SYSTEM_LIBRARY}) - file(COPY visu.py km.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) if (TBB_FOUND) diff --git a/src/Nerve_GIC/example/GIC.cpp b/src/Nerve_GIC/example/GIC.cpp index 1ab15ecc..cae0d55d 100644 --- a/src/Nerve_GIC/example/GIC.cpp +++ b/src/Nerve_GIC/example/GIC.cpp @@ -3,7 +3,7 @@ void usage(int nbArgs, char * const progName) { std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; std::cerr << "Usage: " << progName << " filename.off threshold coordinate resolution gain\n"; - std::cerr << " i.e.: " << progName << " ../../../data/points/human.off 0.075 2 10 0.3 \n"; + std::cerr << " i.e.: " << progName << " ../../../../data/points/human.off 0.075 2 0.075 0 \n"; exit(-1); // ----- >> } @@ -24,10 +24,12 @@ int main(int argc, char **argv) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; GIC.set_verbose(verb); - GIC.set_color_from_coordinate(off_file_name, coord); - GIC.set_function_from_coordinate(coord, off_file_name); + GIC.read_point_cloud(off_file_name); - GIC.set_graph_from_rips(threshold, off_file_name); + GIC.set_color_from_coordinate(coord); + GIC.set_function_from_coordinate(coord); + + GIC.set_graph_from_rips(threshold); GIC.set_resolution_double(resolution); GIC.set_gain(gain); GIC.set_cover_from_function(1); diff --git a/src/Nerve_GIC/example/GIC.txt b/src/Nerve_GIC/example/GIC.txt index 9871cf41..6d9f07f5 100644 --- a/src/Nerve_GIC/example/GIC.txt +++ b/src/Nerve_GIC/example/GIC.txt @@ -1,57 +1,92 @@ -Cloud -Function -0 0 -27 26 -0 -0.949318 240 -1 -0.949346 240 -2 -0.822129 50 -3 -0.822037 51 -4 -0.723847 48 -5 -0.722679 48 -6 -0.625409 57 -7 -0.625771 57 -8 -0.528161 99 -9 -0.528188 99 -10 -0.436343 126 -11 -0.436356 126 -12 -0.330775 194 -13 -0.233638 98 -14 -0.116276 100 -15 -0.129017 144 -16 -0.116513 103 -17 -0.0213554 243 -18 -0.0301512 65 -19 -0.0315443 66 -20 0.0750623 308 -21 0.166778 305 -22 0.270037 307 -23 0.371609 380 -24 0.468078 306 -25 0.567395 312 -26 0.721079 534 +../../../../data/points/human.off +coordinate 2 +coordinate 2 +0.075 0 +44 43 +0 -0.954369 220 +1 -0.954377 220 +2 -0.869559 45 +3 -0.869405 45 +4 -0.794255 25 +5 -0.795222 26 +6 -0.723847 48 +7 -0.722679 48 +8 -0.633796 48 +9 -0.634232 48 +10 -0.564455 48 +11 -0.564428 48 +12 -0.491837 98 +13 -0.491864 98 +14 -0.422733 88 +15 -0.422739 88 +16 -0.343376 74 +17 -0.343367 74 +18 -0.271635 96 +19 -0.190912 96 +20 -0.158869 3 +21 -0.158905 3 +22 -0.114958 97 +23 -0.108561 96 +24 -0.115241 100 +25 -0.0317845 185 +26 -0.041866 50 +27 -0.0429161 51 +28 0.0353033 158 +29 0.0275106 31 +30 0.0252492 30 +31 0.107097 170 +32 0.110226 51 +33 0.110952 50 +34 0.186188 57 +35 0.176564 97 +36 0.186215 57 +37 0.256898 232 +38 0.338811 268 +39 0.406299 273 +40 0.481925 220 +41 0.555454 241 +42 0.632415 198 +43 0.744473 407 0 3 1 2 -2 5 -3 4 +2 4 +3 5 4 7 5 6 6 9 7 8 8 10 9 11 -10 12 +10 13 11 12 -12 13 +12 14 13 15 -14 19 +14 16 15 17 16 18 -17 20 -18 20 -19 20 -20 21 -21 22 -22 23 -23 24 -24 25 -25 26 +17 18 +18 19 +19 23 +20 22 +21 24 +22 27 +23 25 +24 26 +25 28 +26 29 +27 30 +28 31 +29 33 +30 32 +31 35 +32 34 +33 36 +34 37 +35 37 +36 37 +37 38 +38 39 +39 40 +40 41 +41 42 +42 43 diff --git a/src/Nerve_GIC/example/GICvoronoi.cpp b/src/Nerve_GIC/example/GICvoronoi.cpp index 2d50ab4d..141268a5 100644 --- a/src/Nerve_GIC/example/GICvoronoi.cpp +++ b/src/Nerve_GIC/example/GICvoronoi.cpp @@ -22,15 +22,17 @@ int main(int argc, char **argv) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; GIC.set_verbose(verb); - GIC.set_color_from_coordinate(off_file_name); + GIC.read_point_cloud(off_file_name); + + GIC.set_color_from_coordinate(); GIC.set_graph_from_OFF(off_file_name); - GIC.set_cover_from_Voronoi(m, off_file_name); + GIC.set_cover_from_Voronoi(m); GIC.find_GIC_simplices(); - GIC.plot_with_KeplerMapper(); + GIC.plot_with_Geomview(); Simplex_tree stree; GIC.create_complex(stree); diff --git a/src/Nerve_GIC/example/MapperDeltaCoord.cpp b/src/Nerve_GIC/example/MapperDeltaCoord.cpp index 950ee58a..c4d86caf 100644 --- a/src/Nerve_GIC/example/MapperDeltaCoord.cpp +++ b/src/Nerve_GIC/example/MapperDeltaCoord.cpp @@ -3,7 +3,7 @@ void usage(int nbArgs, char * const progName) { std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; std::cerr << "Usage: " << progName << " filename.off coordinate \n"; - std::cerr << " i.e.: " << progName << " ../../../data/points/human.off 2 --v \n"; + std::cerr << " i.e.: " << progName << " ../../../../data/points/human.off 2 --v \n"; exit(-1); // ----- >> } @@ -21,10 +21,12 @@ int main(int argc, char **argv) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; GIC.set_verbose(verb); - GIC.set_color_from_coordinate(off_file_name, coord); - GIC.set_function_from_coordinate(coord, off_file_name); + GIC.read_point_cloud(off_file_name); - GIC.set_graph_from_automatic_rips(off_file_name); + GIC.set_color_from_coordinate(coord); + GIC.set_function_from_coordinate(coord); + + GIC.set_graph_from_automatic_rips(); GIC.set_automatic_resolution_for_GICMAP(); GIC.set_gain(); GIC.set_cover_from_function(1); diff --git a/src/Nerve_GIC/example/MapperDeltaCoord.txt b/src/Nerve_GIC/example/MapperDeltaCoord.txt index 2c2296ea..c1ead814 100644 --- a/src/Nerve_GIC/example/MapperDeltaCoord.txt +++ b/src/Nerve_GIC/example/MapperDeltaCoord.txt @@ -1,68 +1,73 @@ -Cloud -Function -0 0 -61 60 -0 -0.954369 220 -1 -0.954377 220 -2 -0.902361 54 -3 -0.901235 55 +../../../../data/points/human.off +coordinate 2 +coordinate 2 +0.072934 0.3 +65 64 +0 -0.954816 218 +1 -0.954824 218 +2 -0.903705 57 +3 -0.9035 57 4 -0.84796 27 -5 -0.844637 29 -6 -0.777883 37 -7 -0.778882 39 -8 -0.72868 42 -9 -0.72734 42 -10 -0.677728 48 -11 -0.676848 48 +5 -0.847937 27 +6 -0.794255 25 +7 -0.791001 29 +8 -0.73369 36 +9 -0.733071 35 +10 -0.683795 40 +11 -0.682735 40 12 -0.633796 48 13 -0.634232 48 -14 -0.567924 52 -15 -0.567897 52 -16 -0.52287 77 -17 -0.522897 77 -18 -0.467859 105 -19 -0.467886 105 -20 -0.422377 87 -21 -0.422383 87 -22 -0.363537 80 -23 -0.363508 80 -24 -0.312836 126 -25 -0.267775 84 -26 -0.197152 78 -27 -0.149293 96 -28 -0.134636 48 -29 -0.134463 51 -30 -0.104389 93 -31 -0.108561 96 -32 -0.105219 93 -33 -0.0362235 183 -34 -0.0498358 53 -35 -0.050197 51 -36 -0.000444973 187 -37 0.000472738 42 -38 -0.000214643 42 -39 0.0616246 164 -40 0.0590725 29 -41 0.0590271 31 -42 0.108834 170 -43 0.110991 50 -44 0.110952 50 -45 0.158372 129 -46 0.161945 54 -47 0.161972 54 -48 0.210958 76 -49 0.221521 73 -50 0.221548 73 -51 0.263419 220 -52 0.324345 241 -53 0.371963 311 -54 0.422902 272 -55 0.476693 223 -56 0.530461 246 -57 0.58285 217 -58 0.63636 203 -59 0.690953 230 -60 0.76296 309 +14 -0.585137 64 +15 -0.585197 64 +16 -0.527997 66 +17 -0.528025 66 +18 -0.478646 93 +19 -0.478673 93 +20 -0.43674 99 +21 -0.436761 99 +22 -0.380976 70 +23 -0.380955 70 +24 -0.33528 72 +25 -0.335279 72 +26 -0.277496 112 +27 -0.232679 96 +28 -0.1842 77 +29 -0.149795 16 +30 -0.150304 16 +31 -0.119698 90 +32 -0.122291 74 +33 -0.119626 94 +34 -0.0849586 74 +35 -0.0681724 107 +36 -0.0856915 73 +37 -0.0263688 211 +38 -0.025358 49 +39 -0.025088 50 +40 0.0287585 146 +41 0.022349 34 +42 0.0213867 34 +43 0.0768417 175 +44 0.081987 34 +45 0.0819086 34 +46 0.128047 150 +47 0.129348 53 +48 0.128561 54 +49 0.173705 104 +50 0.180884 53 +51 0.180911 53 +52 0.229553 68 +53 0.233083 77 +54 0.23311 77 +55 0.283572 215 +56 0.338574 266 +57 0.381249 299 +58 0.433627 244 +59 0.485309 214 +60 0.535849 237 +61 0.588559 193 +62 0.638771 196 +63 0.692993 222 +64 0.763344 307 0 3 1 2 2 4 @@ -86,40 +91,44 @@ Function 20 22 21 23 22 24 -23 24 -24 25 +23 25 +24 26 25 26 26 27 -27 31 -28 30 -29 32 -30 35 -31 33 -32 34 +27 28 +28 32 +29 31 +30 33 +31 34 +32 35 33 36 -34 37 -35 38 -36 39 -37 41 -38 40 +34 39 +35 37 +36 38 +37 40 +38 41 39 42 40 43 -41 44 -42 45 +41 45 +42 44 43 46 44 47 45 48 46 49 47 50 48 51 -49 51 -50 51 -51 52 -52 53 -53 54 +49 52 +50 53 +51 54 +52 55 +53 55 54 55 55 56 56 57 57 58 58 59 59 60 +60 61 +61 62 +62 63 +63 64 diff --git a/src/Nerve_GIC/example/MapperDeltaFunc.cpp b/src/Nerve_GIC/example/MapperDeltaFunc.cpp index 658b0273..1c3a77a5 100644 --- a/src/Nerve_GIC/example/MapperDeltaFunc.cpp +++ b/src/Nerve_GIC/example/MapperDeltaFunc.cpp @@ -3,7 +3,7 @@ void usage(int nbArgs, char * const progName) { std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; std::cerr << "Usage: " << progName << " filename.off coordinate \n"; - std::cerr << " i.e.: " << progName << " ../../../data/points/human.off 2 --v \n"; + std::cerr << " i.e.: " << progName << " ../../../../data/points/COIL_database/lucky_cat.off ../../../../data/points/COIL_database/lucky_cat_PCA1 --v \n"; exit(-1); // ----- >> } @@ -21,10 +21,12 @@ int main(int argc, char **argv) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; GIC.set_verbose(verb); + GIC.read_point_cloud(off_file_name); + GIC.set_color_from_file(func_file_name); GIC.set_function_from_file(func_file_name); - GIC.set_graph_from_automatic_rips(off_file_name); + GIC.set_graph_from_automatic_rips(); GIC.set_automatic_resolution_for_GICMAP(); GIC.set_gain(); GIC.set_cover_from_function(1); diff --git a/src/Nerve_GIC/example/MapperDeltaFunc.txt b/src/Nerve_GIC/example/MapperDeltaFunc.txt index 046d2278..01b0fbea 100644 --- a/src/Nerve_GIC/example/MapperDeltaFunc.txt +++ b/src/Nerve_GIC/example/MapperDeltaFunc.txt @@ -1,6 +1,7 @@ -Cloud -Function -0 0 +../../../../data/points/COIL_database/lucky_cat.off +../../../../data/points/COIL_database/lucky_cat_PCA1 +../../../../data/points/COIL_database/lucky_cat_PCA1 +2592.99 0.3 6 6 0 -1382.24 20 1 385.162 3 diff --git a/src/Nerve_GIC/example/Nerve.cpp b/src/Nerve_GIC/example/Nerve.cpp index a0de31ae..a549f544 100644 --- a/src/Nerve_GIC/example/Nerve.cpp +++ b/src/Nerve_GIC/example/Nerve.cpp @@ -3,7 +3,7 @@ void usage(int nbArgs, char * const progName) { std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; std::cerr << "Usage: " << progName << " filename.off coordinate resolution gain --v \n"; - std::cerr << " i.e.: " << progName << " ../../../data/points/human.off 2 10 0.3 --v \n"; + std::cerr << " i.e.: " << progName << " ../../../../data/human.off 2 10 0.3 --v \n"; exit(-1); // ----- >> } @@ -23,8 +23,10 @@ int main(int argc, char **argv) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; GIC.set_verbose(verb); - GIC.set_color_from_coordinate(off_file_name, coord); - GIC.set_function_from_coordinate(coord, off_file_name); + GIC.read_point_cloud(off_file_name); + + GIC.set_color_from_coordinate(coord); + GIC.set_function_from_coordinate(coord); GIC.set_graph_from_OFF(off_file_name); diff --git a/src/Nerve_GIC/example/Nerve.txt b/src/Nerve_GIC/example/Nerve.txt index 9ebb2fbb..a6fad665 100644 --- a/src/Nerve_GIC/example/Nerve.txt +++ b/src/Nerve_GIC/example/Nerve.txt @@ -1,28 +1,29 @@ -Cloud -Function -0 0 +../../../../data/points/human.off +coordinate 2 +coordinate 2 +0 0.3 21 20 -0 -0.0149926 290 -1 -0.0152551 291 -2 -0.0695028 127 -3 -0.0700955 128 -4 -0.0449554 250 -5 -0.045006 251 -6 -0.0130144 247 -7 -0.0131973 247 -8 0.0766414 127 -9 -0.0118972 165 -10 -0.0121551 165 -11 0.0785204 128 -12 0.0559145 183 -13 -0.0298394 542 -14 0.0569878 181 -15 -0.0201742 388 -16 -0.00110905 208 -17 -0.00131087 208 -18 0.0228028 854 -19 0.0181739 764 -20 0.0307483 597 +0 -0.927412 290 +1 -0.927011 291 +2 -0.708477 127 +3 -0.709946 128 +4 -0.513775 250 +5 -0.514319 251 +6 -0.376304 247 +7 -0.376315 247 +8 -0.104886 127 +9 -0.168391 165 +10 -0.16871 165 +11 -0.105984 128 +12 -0.0174106 183 +13 0.0197303 542 +14 -0.0161482 181 +15 0.159925 388 +16 0.204922 208 +17 0.204892 208 +18 0.368798 854 +19 0.542323 764 +20 0.709288 597 0 2 1 3 2 5 diff --git a/src/Nerve_GIC/include/gudhi/GIC.h b/src/Nerve_GIC/include/gudhi/GIC.h index 205aa87e..7be71df3 100644 --- a/src/Nerve_GIC/include/gudhi/GIC.h +++ b/src/Nerve_GIC/include/gudhi/GIC.h @@ -67,6 +67,7 @@ typedef gss::Kd_tree_search Points_ds; std::map func; std::map func_color; +Gudhi::Points_off_reader off_reader("tmp"); namespace Gudhi { @@ -110,6 +111,10 @@ class Graph_induced_complex { int resolution_int; double resolution_double; double gain; + std::vector subsamples; + std::string cover_name; + std::string point_cloud_name; + std::string color_name; // Simplex comparator private: @@ -160,6 +165,12 @@ class Graph_induced_complex { public: void set_verbose(bool verb = 0){verbose = verb;} + public: + void read_point_cloud(const std::string& off_file_name){ + off_reader = Points_off_reader(off_file_name); + point_cloud_name = off_file_name; + } + // ******************************************************************************************************************* // Graphs. // ******************************************************************************************************************* @@ -230,8 +241,7 @@ class Graph_induced_complex { * @param[in] off_file_name name of the input .OFF file. * */ - void set_graph_from_rips(const double& threshold, const std::string& off_file_name){ - Points_off_reader off_reader(off_file_name); + void set_graph_from_rips(const double& threshold){ Rips_complex rips_complex_from_points(off_reader.get_point_cloud(), threshold, Euclidean_distance()); rips_complex_from_points.create_complex(st, 1); data_dimension = off_reader.get_point_cloud()[0].size(); @@ -254,9 +264,8 @@ class Graph_induced_complex { * @param[in] N number of subsampling iteration (default value 100). * */ - void set_graph_from_automatic_rips(const std::string& off_file_name, int N = 100){ + void set_graph_from_automatic_rips(int N = 100){ - Points_off_reader off_reader(off_file_name); int n = off_reader.get_point_cloud().size(); int m = floor(n/pow(log(n)/log(CONSTANT),1+ETA)); m = std::min(m,n-1); std::vector samples(m); double delta = 0; int dim = off_reader.get_point_cloud()[0].size(); data_dimension = dim; @@ -268,7 +277,7 @@ class Graph_induced_complex { for(int i = 0; i < n; i++) dist[i] = dumb; double d; - char distances[100]; sprintf(distances,"%s_dist",(char*) off_file_name.c_str()); + char distances[100]; sprintf(distances,"%s_dist",(char*) point_cloud_name.c_str()); std::ifstream input(distances, std::ios::out | std::ios::binary); if(input.good()){ @@ -347,6 +356,7 @@ class Graph_induced_complex { std::stringstream stream(line); stream >> f; func.insert(std::pair(vertex_id, f)); vertex_id++; } + cover_name = func_file_name; } public: // Set function from kth coordinate @@ -356,10 +366,11 @@ class Graph_induced_complex { * @param[in] off_file_name name of the input .OFF file. * */ - void set_function_from_coordinate(const int& k, const std::string& off_file_name){ - Points_off_reader off_reader(off_file_name); + void set_function_from_coordinate(const int& k){ int n = off_reader.get_point_cloud().size(); for(int i = 0; i < n; i++) func.insert(std::pair(i,off_reader.get_point_cloud()[i][k])); + char coordinate[100]; sprintf(coordinate, "coordinate %d", k); + cover_name = coordinate; } public: // Set function from vector. @@ -399,20 +410,23 @@ class Graph_induced_complex { std::sort(cov_number.begin(),cov_number.end()); it = std::unique(cov_number.begin(),cov_number.end()); cov_number.resize(std::distance(cov_number.begin(),it)); maximal_dim = cov_number.size()-1; for(int i = 0; i <= maximal_dim; i++) cover_color[i].second /= cover_color[i].first; + cover_name = cover_file_name; } + /* TODO: complete method with nearest geodesic neighbor + public: // Set cover from Voronoi /** \brief Creates the cover C from the Voronoï cells of a subsampling of the point cloud. * * @param[in] m number of points in the subsample. * @param[in] off_file_name name of the input .OFF file. * - */ - void set_cover_from_Voronoi(const int& m, const std::string& off_file_name){ - Points_off_reader off_reader(off_file_name); + + void set_cover_from_Voronoi(const int& m){ + int n = off_reader.get_point_cloud().size(); data_dimension = off_reader.get_point_cloud()[0].size(); Pointsd pointsd(m+1); std::vector samples(m); SampleWithoutReplacement(n,m,samples); - double* coord = new double[data_dimension]; + double* coord = new double[data_dimension]; subsamples = samples; for(int i = 1; i <= m; i++){ for(int j = 0; j < data_dimension; j++) coord[j] = off_reader.get_point_cloud()[samples[i-1]][j]; @@ -424,7 +438,7 @@ class Graph_induced_complex { for(int j = 0; j < data_dimension; j++) coord[j] = off_reader.get_point_cloud()[i][j]; pointsd[0] = Pointd(data_dimension, coord+0, coord + data_dimension); Points_ds points_ds(pointsd); auto knn_range = points_ds.query_k_nearest_neighbors(pointsd[0], 2, true); - Cover_t cluster = (knn_range.begin()+1)->first-1; + Cover_t cluster; // = nearest geodesic neighbor. if(cluster >= 0){ // Case where i is not a subsample point. cover[i].push_back(cluster); cover_color[cluster].second += func_color[i]; cover_color[cluster].first++; } @@ -437,9 +451,10 @@ class Graph_induced_complex { for(int i = 0; i < m; i++) cover_color[i].second /= cover_color[i].first; delete [] coord; - maximal_dim = m-1; + maximal_dim = m-1; cover_name = "Voronoi"; } + */ public: // Automatic tuning of resolution for Mapper Delta. /** \brief Computes the optimal length of intervals for a Mapper Delta. @@ -627,6 +642,7 @@ class Graph_induced_complex { std::stringstream stream(line); stream >> f; func_color.insert(std::pair(vertex_id, f)); vertex_id++; } + color_name = color_file_name; } public: // Set color from kth coordinate @@ -636,10 +652,11 @@ class Graph_induced_complex { * @param[in] off_file_name name of the input .OFF file. * */ - void set_color_from_coordinate(const std::string& off_file_name, int k = 0){ - Points_off_reader off_reader(off_file_name); + void set_color_from_coordinate(int k = 0){ int n = off_reader.get_point_cloud().size(); for(int i = 0; i < n; i++) func_color[i] = off_reader.get_point_cloud()[i][k]; + char coordinate[100]; sprintf(coordinate, "coordinate %d", k); + color_name = coordinate; } public: // Set color from vector. @@ -652,8 +669,9 @@ class Graph_induced_complex { for(unsigned int i = 0; i < color.size(); i++) func_color.insert(std::pair(i, color[i])); } - public: // Create a .dot file that can be compiled with neato to produce a .pdf file + public: // Create a .dot file that can be compiled with neato to produce a .pdf file. /** \brief Creates a .dot file for neato once the simplicial complex is computed to get a .pdf output. + * For Mapper Delta only. */ void plot_with_neato(){ char mapp[11] = "SC.dot"; std::ofstream graphic(mapp); graphic << "graph Mapper {" << std::endl; @@ -682,8 +700,9 @@ class Graph_induced_complex { if(systemRet == -1) std::cout << "Visualization failed. Do you have neato?" << std::endl; } - public: // Create a .txt file that can be compiled with KeplerMapper to produce a .html file - /** \brief Creates a .html file for KeplerMapper once the simplicial complex is computed to get a nice visualization in browser. + public: // Create a .txt file that can be compiled with KeplerMapper to produce a .html file. + /** \brief Creates a .html file for KeplerMapper once the simplicial complex is computed to get a nice visualization + * of its 1_skeleton in browser. */ void plot_with_KeplerMapper(){ @@ -694,9 +713,10 @@ class Graph_induced_complex { if (cover_color[simplices[i][0]].first > MASK && cover_color[simplices[i][1]].first > MASK) num_edges++; - graphic << "Cloud" << std::endl; - graphic << "Function" << std::endl; - graphic << 0 << " " << 0 << std::endl; + graphic << point_cloud_name << std::endl; + graphic << cover_name << std::endl; + graphic << color_name << std::endl; + graphic << resolution_double << " " << gain << std::endl; graphic << cover_color.size() << " " << num_edges << std::endl; for (std::map >::iterator iit = cover_color.begin(); iit != cover_color.end(); iit++) @@ -707,11 +727,52 @@ class Graph_induced_complex { if (cover_color[simplices[i][0]].first > MASK && cover_color[simplices[i][1]].first > MASK) graphic << simplices[i][0] << " " << simplices[i][1] << std::endl; graphic.close(); - char command[100]; sprintf(command, "python visu.py && firefox SC_visu.html"); + char command[100]; sprintf(command, "python visu.py && firefox SC.html"); int systemRet = system(command); if(systemRet == -1) std::cout << "Visualization failed. Do you have python and firefox?" << std::endl; } + /* + public: // Create a .off file that can be visualized with Geomview. + /** \brief Creates a .off file for visualization with Geomview. + * For GIC computed with Voronoi only. + * + void plot_with_Geomview(){ + + assert(data_dimension <= 3); + char mapp[11] = "SC.off"; std::ofstream graphic(mapp); + graphic << "OFF" << std::endl; int m = subsamples.size(); int numedges = 0; int numfaces = 0; + std::vector > edges, faces; int numsimplices = simplices.size(); + for (int i = 0; i < numsimplices; i++) { + if(simplices[i].size() == 2){ numedges++; + edges.push_back(simplices[i]); + } + if(simplices[i].size() == 3){ numfaces++; + faces.push_back(simplices[i]); + } + } + graphic << m << " " << numedges + numfaces << std::endl; + for(int i = 0; i < m; i++) graphic << off_reader.get_point_cloud()[subsamples[i]][0] << " " \ + << off_reader.get_point_cloud()[subsamples[i]][1] << " " \ + << off_reader.get_point_cloud()[subsamples[i]][2] << std::endl; + for(int i = 0; i < numedges; i++) graphic << 2 << " " << edges[i][0] << " " << edges[i][1] << std::endl; + for(int i = 0; i < numfaces; i++) graphic << 3 << " " << faces[i][0] << " " << faces[i][1] << " " << faces[i][2] << std::endl; + graphic.close(); + + char cl[11] = "cloud.off"; std::ofstream cloud(cl); + cloud << "COFF" << std::endl << 4706 << " " << 9408 << std::endl; + for(int i = 0; i < off_reader.get_point_cloud().size(); i++) + cloud << off_reader.get_point_cloud()[i][0] << " " << off_reader.get_point_cloud()[i][1] << " " << off_reader.get_point_cloud()[i][2] << " " <<\ + cover[i][0]*1.0/(maximal_dim+1) << " " <<\ + 0 << " " <<\ + cover[i][0]*1.0/(maximal_dim+1) << " " << 0.5 << std::endl; + + char command[100]; sprintf(command, "geomview SC.off"); + int systemRet = system(command); + if(systemRet == -1) std::cout << "Visualization failed. Do you have geomview?" << std::endl; + + }*/ + // ******************************************************************************************************************* // ******************************************************************************************************************* diff --git a/src/Nerve_GIC/test/test_GIC.cpp b/src/Nerve_GIC/test/test_GIC.cpp index 1ca44f19..baf494e3 100644 --- a/src/Nerve_GIC/test/test_GIC.cpp +++ b/src/Nerve_GIC/test/test_GIC.cpp @@ -40,9 +40,10 @@ bool are_almost_the_same(float a, float b) { BOOST_AUTO_TEST_CASE(check_nerve) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; + std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name); std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name); std::string cover_file_name("data/cover"); GIC.set_cover_from_file(cover_file_name); - std::string cloud_file_name("data/cloud"); GIC.set_color_from_file(cloud_file_name); + GIC.set_color_from_coordinate(); GIC.find_Nerve_simplices(); Simplex_tree stree; GIC.create_complex(stree); BOOST_CHECK(stree.num_vertices() == 3); @@ -53,9 +54,10 @@ BOOST_AUTO_TEST_CASE(check_nerve) { BOOST_AUTO_TEST_CASE(check_GICMAP) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; GIC.set_verbose(1); + std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name); std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name); std::string cover_file_name("data/cover"); GIC.set_cover_from_file(cover_file_name); - std::string cloud_file_name("data/cloud"); GIC.set_color_from_file(cloud_file_name); + GIC.set_color_from_coordinate(); GIC.find_GICMAP_simplices_with_functional_minimal_cover(); Simplex_tree stree; GIC.create_complex(stree); BOOST_CHECK(stree.num_vertices() == 3); @@ -66,9 +68,10 @@ BOOST_AUTO_TEST_CASE(check_GICMAP) { BOOST_AUTO_TEST_CASE(check_GICcover) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; + std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name); std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name); std::string cover_file_name("data/cover"); GIC.set_cover_from_file(cover_file_name); - std::string cloud_file_name("data/cloud"); GIC.set_color_from_file(cloud_file_name); + GIC.set_color_from_coordinate(); GIC.find_GIC_simplices(); Simplex_tree stree; GIC.create_complex(stree); BOOST_CHECK(stree.num_vertices() == 3); @@ -76,17 +79,19 @@ BOOST_AUTO_TEST_CASE(check_GICcover) { BOOST_CHECK(stree.dimension() == 2); } +/* BOOST_AUTO_TEST_CASE(check_GICvoronoi) { Gudhi::graph_induced_complex::Graph_induced_complex GIC; - std::string cloud_file_name("data/cloud"); GIC.set_color_from_coordinate(cloud_file_name); + std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name); + GIC.set_color_from_coordinate(); std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name); - GIC.set_cover_from_Voronoi(2,cloud_file_name); + GIC.set_cover_from_Voronoi(2); GIC.find_GIC_simplices(); Simplex_tree stree; GIC.create_complex(stree); BOOST_CHECK(stree.num_vertices() == 2); BOOST_CHECK((stree.num_simplices()-stree.num_vertices()) == 1); BOOST_CHECK(stree.dimension() == 1); } - +*/ -- cgit v1.2.3