From d6bb19de457fa74c84dbd6d8afa63074fefb4552 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 18 May 2017 08:47:16 +0000 Subject: Modify the way cmake handles utilities, examples, test and benchmarks with new options to activate/desactivate them. Move hypergenerator as a common utility. Move random point generation from hypergenerator in src/common/include/gudhi/random_point_generators.h git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/cmake_modules_for_gudhi@2442 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e2d13e4b0c09455fb604b684f6d71530352271eb --- CMakeLists.txt | 76 ++++++++++++++++++++-------------------------------------- 1 file changed, 26 insertions(+), 50 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 324f8648..360eb87a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,6 @@ message("CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}") enable_testing() -# For "make user_version" -include("${CMAKE_MODULE_PATH}/GUDHI_user_version_target.txt") -# For "make doxygen" -include(GUDHI_doxygen_target) # This variable is used by Cython CMakeLists.txt to know its path set(GUDHI_CYTHON_PATH "src/cython") # For third parties libraries management - To be done last as CGAL updates CMAKE_MODULE_PATH @@ -38,54 +34,34 @@ if (DEBUG_TRACES) add_definitions(-DDEBUG_TRACES) endif() -include_directories(src/common/include/) -include_directories(src/Alpha_complex/include/) -include_directories(src/Bitmap_cubical_complex/include/) -include_directories(src/Bottleneck_distance/include/) -include_directories(src/Contraction/include/) -include_directories(src/Hasse_complex/include/) -include_directories(src/Persistent_cohomology/include/) -include_directories(src/Rips_complex/include/) -include_directories(src/Simplex_tree/include/) -include_directories(src/Skeleton_blocker/include/) -include_directories(src/Spatial_searching/include/) -include_directories(src/Subsampling/include/) -include_directories(src/Tangential_complex/include/) -include_directories(src/Witness_complex/include/) +# Modules list can be found in CMAKE_MODULE_PATH/GUDHI_modules.cmake +include(GUDHI_modules) -add_subdirectory(src/common/example) -add_subdirectory(src/common/test) -add_subdirectory(src/Simplex_tree/test) -add_subdirectory(src/Simplex_tree/example) -add_subdirectory(src/Persistent_cohomology/test) -add_subdirectory(src/Persistent_cohomology/example) -add_subdirectory(src/Persistent_cohomology/benchmark) -add_subdirectory(src/Skeleton_blocker/test) -add_subdirectory(src/Skeleton_blocker/example) -add_subdirectory(src/Contraction/example) -add_subdirectory(src/Witness_complex/test) -add_subdirectory(src/Witness_complex/example) -add_subdirectory(src/Bitmap_cubical_complex/test) -add_subdirectory(src/Bitmap_cubical_complex/example) -add_subdirectory(src/Alpha_complex/example) -add_subdirectory(src/Alpha_complex/test) -add_subdirectory(src/Spatial_searching/example) -add_subdirectory(src/Spatial_searching/test) -add_subdirectory(src/Subsampling/example) -add_subdirectory(src/Subsampling/test) -add_subdirectory(src/Tangential_complex/example) -add_subdirectory(src/Tangential_complex/test) -add_subdirectory(src/Tangential_complex/benchmark) -add_subdirectory(src/Bottleneck_distance/example) -add_subdirectory(src/Bottleneck_distance/test) -add_subdirectory(src/Bottleneck_distance/benchmark) -add_subdirectory(src/Rips_complex/example) -add_subdirectory(src/Rips_complex/test) +# Include module headers +foreach(GUDHI_MODULE ${GUDHI_MODULES}) + if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/src/${GUDHI_MODULE}/include/) + include_directories(src/${GUDHI_MODULE}/include/) + endif() +endforeach() -# data points generator -add_subdirectory(data/points/generator) +# Include module CMake subdirectories +# GUDHI_SUB_DIRECTORIES is managed in CMAKE_MODULE_PATH/GUDHI_modules.cmake +foreach(GUDHI_MODULE ${GUDHI_MODULES}) + foreach(GUDHI_SUB_DIRECTORY ${GUDHI_SUB_DIRECTORIES}) + if(EXISTS ${CMAKE_SOURCE_DIR}/src/${GUDHI_MODULE}/${GUDHI_SUB_DIRECTORY}/CMakeLists.txt) + add_subdirectory(src/${GUDHI_MODULE}/${GUDHI_SUB_DIRECTORY}/) + endif() + endforeach() +endforeach() add_subdirectory(src/GudhUI) -# specific for cython module -add_subdirectory(${GUDHI_CYTHON_PATH}) +if (NOT WITHOUT_GUDHI_PYTHON) + # specific for cython module + add_subdirectory(${GUDHI_CYTHON_PATH}) +endif() + +# For "make user_version" - Requires GUDHI_modules to be performed +include(GUDHI_user_version_target) +# For "make doxygen" - Requires GUDHI_user_version_target to be performed +include(GUDHI_doxygen_target) -- cgit v1.2.3 From ec3f93103f5a1937d3f8bbf37af3837a1089bf03 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 19 May 2017 16:13:50 +0000 Subject: Move src/common/utilities/hypergenerator.cpp in src/common/utilities Management of Python distribution packages make install is now installing utilities and GUDHI python module git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/cmake_modules_for_gudhi@2453 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a85576c7ae062718900f0db2bfb0dd3f26e87177 --- CMakeLists.txt | 19 ++- src/CMakeLists.txt | 27 ++- src/GudhUI/CMakeLists.txt | 2 + src/cmake/modules/GUDHI_modules.cmake | 17 -- .../modules/GUDHI_third_party_libraries.cmake | 7 +- src/cmake/modules/GUDHI_user_version_target.cmake | 2 +- src/common/utilities/CMakeLists.txt | 15 +- src/common/utilities/README | 10 +- src/common/utilities/hypergenerator.cpp | 189 --------------------- .../utilities/off_file_from_shape_generator.cpp | 189 +++++++++++++++++++++ src/cython/CMakeLists.txt | 10 +- 11 files changed, 260 insertions(+), 227 deletions(-) delete mode 100644 src/common/utilities/hypergenerator.cpp create mode 100644 src/common/utilities/off_file_from_shape_generator.cpp (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 360eb87a..c9ceb92b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,23 @@ endif() # Modules list can be found in CMAKE_MODULE_PATH/GUDHI_modules.cmake include(GUDHI_modules) +# Add your new module in the list, order is not important + +add_gudhi_module(common) +add_gudhi_module(Alpha_complex) +add_gudhi_module(Bitmap_cubical_complex) +add_gudhi_module(Bottleneck_distance) +add_gudhi_module(Contraction) +add_gudhi_module(Hasse_complex) +add_gudhi_module(Persistent_cohomology) +add_gudhi_module(Rips_complex) +add_gudhi_module(Simplex_tree) +add_gudhi_module(Skeleton_blocker) +add_gudhi_module(Spatial_searching) +add_gudhi_module(Subsampling) +add_gudhi_module(Tangential_complex) +add_gudhi_module(Witness_complex) + # Include module headers foreach(GUDHI_MODULE ${GUDHI_MODULES}) if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/src/${GUDHI_MODULE}/include/) @@ -63,5 +80,5 @@ endif() # For "make user_version" - Requires GUDHI_modules to be performed include(GUDHI_user_version_target) -# For "make doxygen" - Requires GUDHI_user_version_target to be performed +# For "make doxygen" - Requires GUDHI_USER_VERSION_DIR to be set - Done in GUDHI_user_version_target for dev version include(GUDHI_doxygen_target) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77a03c17..8abfcf44 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,24 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") # To be done first - Modules list can be found in CMAKE_MODULE_PATH/GUDHI_modules.cmake include(GUDHI_modules) -# For "make doxygen" +# Add your new module in the list, order is not important + +add_gudhi_module(common) +add_gudhi_module(Alpha_complex) +add_gudhi_module(Bitmap_cubical_complex) +add_gudhi_module(Bottleneck_distance) +add_gudhi_module(Contraction) +add_gudhi_module(Hasse_complex) +add_gudhi_module(Persistent_cohomology) +add_gudhi_module(Rips_complex) +add_gudhi_module(Simplex_tree) +add_gudhi_module(Skeleton_blocker) +add_gudhi_module(Spatial_searching) +add_gudhi_module(Subsampling) +add_gudhi_module(Tangential_complex) +add_gudhi_module(Witness_complex) + +# For "make doxygen" - Requires GUDHI_USER_VERSION_DIR to be set set(GUDHI_USER_VERSION_DIR ${CMAKE_SOURCE_DIR}) include(GUDHI_doxygen_target) @@ -47,10 +64,10 @@ include_directories(include) foreach(GUDHI_MODULE ${GUDHI_MODULES}) foreach(GUDHI_SUB_DIRECTORY ${GUDHI_SUB_DIRECTORIES}) if(EXISTS ${CMAKE_SOURCE_DIR}/${GUDHI_SUB_DIRECTORY}/${GUDHI_MODULE}/CMakeLists.txt) - add_subdirectory(src/${GUDHI_MODULE}/${GUDHI_SUB_DIRECTORY}/) - endif(EXISTS ${CMAKE_SOURCE_DIR}/${GUDHI_SUB_DIRECTORY}/${GUDHI_MODULE}/CMakeLists.txt) - endforeach(GUDHI_SUB_DIRECTORY ${GUDHI_SUB_DIRECTORIES}) -endforeach(GUDHI_MODULE ${GUDHI_MODULES}) + add_subdirectory(${CMAKE_SOURCE_DIR}/${GUDHI_SUB_DIRECTORY}/${GUDHI_MODULE}/) + endif() + endforeach() +endforeach() add_subdirectory(GudhUI) diff --git a/src/GudhUI/CMakeLists.txt b/src/GudhUI/CMakeLists.txt index ca2e47c1..57861946 100644 --- a/src/GudhUI/CMakeLists.txt +++ b/src/GudhUI/CMakeLists.txt @@ -56,6 +56,8 @@ if (TBB_FOUND) target_link_libraries( GudhUI ${TBB_LIBRARIES}) endif() + install(TARGETS GudhUI DESTINATION bin) + ############################################################################### else() diff --git a/src/cmake/modules/GUDHI_modules.cmake b/src/cmake/modules/GUDHI_modules.cmake index 6a26d7bf..20fc8d17 100644 --- a/src/cmake/modules/GUDHI_modules.cmake +++ b/src/cmake/modules/GUDHI_modules.cmake @@ -5,23 +5,6 @@ function(add_gudhi_module file_path) set(GUDHI_MODULES ${GUDHI_MODULES} ${file_path} PARENT_SCOPE) endfunction(add_gudhi_module) -# Add your new module in the list, order is not important - -add_gudhi_module(common) -add_gudhi_module(Alpha_complex) -add_gudhi_module(Bitmap_cubical_complex) -add_gudhi_module(Bottleneck_distance) -add_gudhi_module(Contraction) -add_gudhi_module(Hasse_complex) -add_gudhi_module(Persistent_cohomology) -add_gudhi_module(Rips_complex) -add_gudhi_module(Simplex_tree) -add_gudhi_module(Skeleton_blocker) -add_gudhi_module(Spatial_searching) -add_gudhi_module(Subsampling) -add_gudhi_module(Tangential_complex) -add_gudhi_module(Witness_complex) - # message("++ GUDHI_MODULES list is:\"${GUDHI_MODULES}\"") if (WITH_GUDHI_BENCHMARK) diff --git a/src/cmake/modules/GUDHI_third_party_libraries.cmake b/src/cmake/modules/GUDHI_third_party_libraries.cmake index 5f84c602..8cb01d3c 100644 --- a/src/cmake/modules/GUDHI_third_party_libraries.cmake +++ b/src/cmake/modules/GUDHI_third_party_libraries.cmake @@ -135,10 +135,15 @@ if(PYTHONINTERP_FOUND AND CYTHON_FOUND) # Documentation generation is available through sphinx find_program( SPHINX_PATH sphinx-build ) elseif(PYTHON_VERSION_MAJOR EQUAL 3) - # Documentation generation is available through sphinx + # No sphinx-build in Pyton3, just hack it set(SPHINX_PATH "${CMAKE_SOURCE_DIR}/${GUDHI_CYTHON_PATH}/doc/python3-sphinx-build") else() message(FATAL_ERROR "ERROR: Try to compile the Cython interface. Python version ${PYTHON_VERSION_STRING} is not valid.") endif(PYTHON_VERSION_MAJOR EQUAL 2) + # get PYTHON_SITE_PACKAGES relative path from a python command line + execute_process( + COMMAND "${PYTHON_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib; print (get_python_lib(prefix='', plat_specific=True))" + OUTPUT_VARIABLE PYTHON_SITE_PACKAGES + OUTPUT_STRIP_TRAILING_WHITESPACE) endif(PYTHONINTERP_FOUND AND CYTHON_FOUND) diff --git a/src/cmake/modules/GUDHI_user_version_target.cmake b/src/cmake/modules/GUDHI_user_version_target.cmake index a764e88a..8642d3bf 100644 --- a/src/cmake/modules/GUDHI_user_version_target.cmake +++ b/src/cmake/modules/GUDHI_user_version_target.cmake @@ -47,7 +47,7 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11) add_custom_command(TARGET user_version PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/GudhUI ${GUDHI_USER_VERSION_DIR}/GudhUI) - set(GUDHI_DIRECTORIES "doc;example;concept") + set(GUDHI_DIRECTORIES "doc;example;concept;utilities") set(GUDHI_INCLUDE_DIRECTORIES "include/gudhi;include/gudhi_patches") foreach(GUDHI_MODULE ${GUDHI_MODULES}) diff --git a/src/common/utilities/CMakeLists.txt b/src/common/utilities/CMakeLists.txt index 88d377a7..c2e07e7e 100644 --- a/src/common/utilities/CMakeLists.txt +++ b/src/common/utilities/CMakeLists.txt @@ -1,15 +1,18 @@ cmake_minimum_required(VERSION 2.6) -project(data_points_generator) +project(off_file_from_shape_generator) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) - add_executable ( data_points_generator hypergenerator.cpp ) - target_link_libraries(data_points_generator ${Boost_SYSTEM_LIBRARY}) - add_test(NAME data_points_generator_on_sphere_1000_3_15.2 COMMAND $ + add_executable ( off_file_from_shape_generator off_file_from_shape_generator.cpp ) + target_link_libraries(off_file_from_shape_generator ${Boost_SYSTEM_LIBRARY}) + add_test(NAME off_file_from_shape_generator_on_sphere_1000_3_15.2 COMMAND $ "on" "sphere" "onSphere.off" "1000" "3" "15.2") - add_test(NAME data_points_generator_in_sphere_100_2 COMMAND $ + add_test(NAME off_file_from_shape_generator_in_sphere_100_2 COMMAND $ "in" "sphere" "inSphere.off" "100" "2") # on cube is not available in CGAL - add_test(NAME data_points_generator_in_cube_10000_3_5.8 COMMAND $ + add_test(NAME off_file_from_shape_generator_in_cube_10000_3_5.8 COMMAND $ "in" "cube" "inCube.off" "10000" "3" "5.8") + + install(TARGETS off_file_from_shape_generator DESTINATION bin) + endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) diff --git a/src/common/utilities/README b/src/common/utilities/README index f2ece556..dc841521 100644 --- a/src/common/utilities/README +++ b/src/common/utilities/README @@ -1,18 +1,18 @@ -======================= data_points_generator ================================== +======================= off_file_from_shape_generator ================================== Example of use : -*** Hyper sphere|cube generator +*** on|in sphere|cube|curve|torus|klein generator -./data_points_generator on sphere onSphere.off 1000 3 15.2 +./off_file_from_shape_generator on sphere onSphere.off 1000 3 15.2 => generates a onSphere.off file with 1000 points randomized on a sphere of dimension 3 and radius 15.2 -./data_points_generator in sphere inSphere.off 100 2 +./off_file_from_shape_generator in sphere inSphere.off 100 2 => generates a inSphere.off file with 100 points randomized in a sphere of dimension 2 (circle) and radius 1.0 (default) -./data_points_generator in cube inCube.off 10000 3 5.8 +./off_file_from_shape_generator in cube inCube.off 10000 3 5.8 => generates a inCube.off file with 10000 points randomized in a cube of dimension 3 and side 5.8 diff --git a/src/common/utilities/hypergenerator.cpp b/src/common/utilities/hypergenerator.cpp deleted file mode 100644 index 0f310a13..00000000 --- a/src/common/utilities/hypergenerator.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Vincent Rouvreau - * - * Copyright (C) 2014 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include -#include - -#include -#include -#include -#include // for std::ofstream -#include - -typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > K; -typedef K::Point_d Point; - -void usage(char * const progName) { - std::cerr << "Usage: " << progName << " in|on sphere|cube off_file_name points_number[integer > 0] " << - "dimension[integer > 1] radius[double > 0.0 | default = 1.0]" << std::endl; - exit(-1); -} - -int main(int argc, char **argv) { - // program args management - if ((argc != 6) && (argc != 7)) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct" << std::endl; - usage(argv[0]); - } - - int points_number = atoi(argv[4]); - if (points_number <= 0) { - std::cerr << "Error: " << argv[4] << " is not correct" << std::endl; - usage(argv[0]); - } - - int dimension = atoi(argv[5]); - if (dimension <= 0) { - std::cerr << "Error: " << argv[5] << " is not correct" << std::endl; - usage(argv[0]); - } - - double radius = 1.0; - if (argc == 7) { - radius = atof(argv[6]); - if (radius <= 0.0) { - std::cerr << "Error: " << argv[6] << " is not correct" << std::endl; - usage(argv[0]); - } - } - - bool in = false; - if (strcmp(argv[1], "in") == 0) { - in = true; - } else if (strcmp(argv[1], "on") != 0) { - std::cerr << "Error: " << argv[1] << " is not correct" << std::endl; - usage(argv[0]); - } - - enum class Data_shape { sphere, cube, curve, torus, klein, undefined } ; - - Data_shape shape = Data_shape::undefined; - if (memcmp(argv[2], "sphere", sizeof("sphere")) == 0) { - shape = Data_shape::sphere; - } else if (memcmp(argv[2], "cube", sizeof("cube")) == 0) { - shape = Data_shape::cube; - } else if (memcmp(argv[2], "curve", sizeof("curve")) == 0) { - shape = Data_shape::curve; - } else if (memcmp(argv[2], "torus", sizeof("torus")) == 0) { - shape = Data_shape::torus; - } else if (memcmp(argv[2], "klein", sizeof("klein")) == 0) { - shape = Data_shape::klein; - } else { - std::cerr << "Error: " << argv[2] << " is not correct" << std::endl; - usage(argv[0]); - } - - std::ofstream diagram_out(argv[3]); - if (dimension == 3) { - diagram_out << "OFF" << std::endl; - diagram_out << points_number << " 0 0" << std::endl; - } else { - diagram_out << "nOFF" << std::endl; - diagram_out << dimension << " " << points_number << " 0 0" << std::endl; - } - - if (diagram_out.is_open()) { - // Generate "points_number" random points in a vector - std::vector points; - if (in) { - switch (shape) { - case Data_shape::sphere: - points = Gudhi::generate_points_in_ball_d(points_number, dimension, radius); - break; - case Data_shape::cube: - points = Gudhi::generate_points_in_ball_d(points_number, dimension, radius); - break; - case Data_shape::curve: - std::cerr << "Sorry: in curve is not available" << std::endl; - usage(argv[0]); - break; - case Data_shape::torus: - std::cerr << "Sorry: in torus is not available" << std::endl; - usage(argv[0]); - break; - case Data_shape::klein: - std::cerr << "Sorry: in klein is not available" << std::endl; - usage(argv[0]); - break; - default: - usage(argv[0]); - break; - } - } else { // means "on" - switch (shape) { - case Data_shape::sphere: - points = Gudhi::generate_points_on_sphere_d(points_number, dimension, radius); - break; - case Data_shape::cube: - std::cerr << "Sorry: on cube is not available" << std::endl; - usage(argv[0]); - break; - case Data_shape::curve: - points = Gudhi::generate_points_on_moment_curve(points_number, dimension, -radius/2., radius/2.); - break; - case Data_shape::torus: - if (dimension == 3) - points = Gudhi::generate_points_on_torus_3D(points_number, dimension, radius, radius/2.); - else - points = Gudhi::generate_points_on_torus_d(points_number, dimension, true); - break; - case Data_shape::klein: - switch (dimension) { - case 3: - points = Gudhi::generate_points_on_klein_bottle_3D(points_number, radius, radius/2., true); - break; - case 4: - points = Gudhi::generate_points_on_klein_bottle_4D(points_number, radius, radius/2., 0., true); - break; - case 5: - points = Gudhi::generate_points_on_klein_bottle_variant_5D(points_number, radius, radius/2., true); - break; - default: - std::cerr << "Sorry: on klein is only available for dimension 3, 4 and 5" << std::endl; - usage(argv[0]); - break; - } - break; - default: - usage(argv[0]); - break; - } - } - - for (auto thePoint : points) { - int i = 0; - for (; i < dimension - 1; i++) { - diagram_out << thePoint[i] << " "; - } - diagram_out << thePoint[i] << std::endl; // last point + Carriage Return - } - } else { - std::cerr << "Error: " << argv[3] << " cannot be opened" << std::endl; - usage(argv[0]); - } - - return 0; -} - diff --git a/src/common/utilities/off_file_from_shape_generator.cpp b/src/common/utilities/off_file_from_shape_generator.cpp new file mode 100644 index 00000000..0f310a13 --- /dev/null +++ b/src/common/utilities/off_file_from_shape_generator.cpp @@ -0,0 +1,189 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2014 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include // for std::ofstream +#include + +typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > K; +typedef K::Point_d Point; + +void usage(char * const progName) { + std::cerr << "Usage: " << progName << " in|on sphere|cube off_file_name points_number[integer > 0] " << + "dimension[integer > 1] radius[double > 0.0 | default = 1.0]" << std::endl; + exit(-1); +} + +int main(int argc, char **argv) { + // program args management + if ((argc != 6) && (argc != 7)) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct" << std::endl; + usage(argv[0]); + } + + int points_number = atoi(argv[4]); + if (points_number <= 0) { + std::cerr << "Error: " << argv[4] << " is not correct" << std::endl; + usage(argv[0]); + } + + int dimension = atoi(argv[5]); + if (dimension <= 0) { + std::cerr << "Error: " << argv[5] << " is not correct" << std::endl; + usage(argv[0]); + } + + double radius = 1.0; + if (argc == 7) { + radius = atof(argv[6]); + if (radius <= 0.0) { + std::cerr << "Error: " << argv[6] << " is not correct" << std::endl; + usage(argv[0]); + } + } + + bool in = false; + if (strcmp(argv[1], "in") == 0) { + in = true; + } else if (strcmp(argv[1], "on") != 0) { + std::cerr << "Error: " << argv[1] << " is not correct" << std::endl; + usage(argv[0]); + } + + enum class Data_shape { sphere, cube, curve, torus, klein, undefined } ; + + Data_shape shape = Data_shape::undefined; + if (memcmp(argv[2], "sphere", sizeof("sphere")) == 0) { + shape = Data_shape::sphere; + } else if (memcmp(argv[2], "cube", sizeof("cube")) == 0) { + shape = Data_shape::cube; + } else if (memcmp(argv[2], "curve", sizeof("curve")) == 0) { + shape = Data_shape::curve; + } else if (memcmp(argv[2], "torus", sizeof("torus")) == 0) { + shape = Data_shape::torus; + } else if (memcmp(argv[2], "klein", sizeof("klein")) == 0) { + shape = Data_shape::klein; + } else { + std::cerr << "Error: " << argv[2] << " is not correct" << std::endl; + usage(argv[0]); + } + + std::ofstream diagram_out(argv[3]); + if (dimension == 3) { + diagram_out << "OFF" << std::endl; + diagram_out << points_number << " 0 0" << std::endl; + } else { + diagram_out << "nOFF" << std::endl; + diagram_out << dimension << " " << points_number << " 0 0" << std::endl; + } + + if (diagram_out.is_open()) { + // Generate "points_number" random points in a vector + std::vector points; + if (in) { + switch (shape) { + case Data_shape::sphere: + points = Gudhi::generate_points_in_ball_d(points_number, dimension, radius); + break; + case Data_shape::cube: + points = Gudhi::generate_points_in_ball_d(points_number, dimension, radius); + break; + case Data_shape::curve: + std::cerr << "Sorry: in curve is not available" << std::endl; + usage(argv[0]); + break; + case Data_shape::torus: + std::cerr << "Sorry: in torus is not available" << std::endl; + usage(argv[0]); + break; + case Data_shape::klein: + std::cerr << "Sorry: in klein is not available" << std::endl; + usage(argv[0]); + break; + default: + usage(argv[0]); + break; + } + } else { // means "on" + switch (shape) { + case Data_shape::sphere: + points = Gudhi::generate_points_on_sphere_d(points_number, dimension, radius); + break; + case Data_shape::cube: + std::cerr << "Sorry: on cube is not available" << std::endl; + usage(argv[0]); + break; + case Data_shape::curve: + points = Gudhi::generate_points_on_moment_curve(points_number, dimension, -radius/2., radius/2.); + break; + case Data_shape::torus: + if (dimension == 3) + points = Gudhi::generate_points_on_torus_3D(points_number, dimension, radius, radius/2.); + else + points = Gudhi::generate_points_on_torus_d(points_number, dimension, true); + break; + case Data_shape::klein: + switch (dimension) { + case 3: + points = Gudhi::generate_points_on_klein_bottle_3D(points_number, radius, radius/2., true); + break; + case 4: + points = Gudhi::generate_points_on_klein_bottle_4D(points_number, radius, radius/2., 0., true); + break; + case 5: + points = Gudhi::generate_points_on_klein_bottle_variant_5D(points_number, radius, radius/2., true); + break; + default: + std::cerr << "Sorry: on klein is only available for dimension 3, 4 and 5" << std::endl; + usage(argv[0]); + break; + } + break; + default: + usage(argv[0]); + break; + } + } + + for (auto thePoint : points) { + int i = 0; + for (; i < dimension - 1; i++) { + diagram_out << thePoint[i] << " "; + } + diagram_out << thePoint[i] << std::endl; // last point + Carriage Return + } + } else { + std::cerr << "Error: " << argv[3] << " cannot be opened" << std::endl; + usage(argv[0]); + } + + return 0; +} + diff --git a/src/cython/CMakeLists.txt b/src/cython/CMakeLists.txt index 96c2acb3..62f8d368 100644 --- a/src/cython/CMakeLists.txt +++ b/src/cython/CMakeLists.txt @@ -168,17 +168,23 @@ if(CYTHON_FOUND) configure_file(gudhi.pyx.in "${CMAKE_CURRENT_BINARY_DIR}/gudhi.pyx" @ONLY) add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gudhi.so" + OUTPUT gudhi.so WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/cythonize_gudhi.py" "build_ext" "--inplace") - add_custom_target(cython ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gudhi.so" + add_custom_target(cython ALL DEPENDS gudhi.so COMMENT "Do not forget to add ${CMAKE_CURRENT_BINARY_DIR}/ to your PYTHONPATH before using examples or tests") if(UNIX) set( ENV{PYTHONPATH} $ENV{PYTHONPATH}:${CMAKE_CURRENT_BINARY_DIR}/ ) endif(UNIX) + # For installation purpose + install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" DESTINATION "${PYTHON_SITE_PACKAGES}/" FILES_MATCHING + PATTERN "*.so" + PATTERN "*.dylib" + PATTERN "*.pyd") + # Test examples add_test(NAME alpha_complex_from_points_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -- cgit v1.2.3