summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-05-18 08:47:16 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-05-18 08:47:16 +0000
commitd6bb19de457fa74c84dbd6d8afa63074fefb4552 (patch)
treea206d3464a26585615b902f4b5d12208dcae2b7a /src
parent170b4936bf883edb40268a8fac650971a26e46bf (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt34
-rw-r--r--src/cmake/modules/GUDHI_modules.cmake43
-rw-r--r--src/cmake/modules/GUDHI_user_version_target.cmake (renamed from src/cmake/modules/GUDHI_user_version_target.txt)1
-rw-r--r--src/common/include/gudhi/random_point_generators.h32
-rw-r--r--src/common/utilities/CMakeLists.txt15
-rw-r--r--src/common/utilities/README19
-rw-r--r--src/common/utilities/hypergenerator.cpp189
7 files changed, 314 insertions, 19 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ebcb6888..77a03c17 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,9 @@ enable_testing()
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"
set(GUDHI_USER_VERSION_DIR ${CMAKE_SOURCE_DIR})
include(GUDHI_doxygen_target)
@@ -39,27 +42,22 @@ endif()
# Gudhi compilation part
include_directories(include)
-add_subdirectory(example/common)
-add_subdirectory(example/Simplex_tree)
-add_subdirectory(example/Persistent_cohomology)
-add_subdirectory(example/Skeleton_blocker)
-add_subdirectory(example/Contraction)
-add_subdirectory(example/Bitmap_cubical_complex)
-add_subdirectory(example/Witness_complex)
-add_subdirectory(example/Alpha_complex)
-add_subdirectory(example/Rips_complex)
-add_subdirectory(example/Spatial_searching)
-add_subdirectory(example/Subsampling)
-add_subdirectory(example/Tangential_complex)
-add_subdirectory(example/Bottleneck_distance)
-
-# 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}/${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(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()
#---------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------
diff --git a/src/cmake/modules/GUDHI_modules.cmake b/src/cmake/modules/GUDHI_modules.cmake
new file mode 100644
index 00000000..6a26d7bf
--- /dev/null
+++ b/src/cmake/modules/GUDHI_modules.cmake
@@ -0,0 +1,43 @@
+# A function to add a new module in GUDHI
+
+set(GUDHI_MODULES "")
+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)
+ set(GUDHI_SUB_DIRECTORIES "${GUDHI_SUB_DIRECTORIES};benchmark")
+endif()
+if (WITH_GUDHI_EXAMPLE)
+ set(GUDHI_SUB_DIRECTORIES "${GUDHI_SUB_DIRECTORIES};example")
+endif()
+if (NOT WITHOUT_GUDHI_TEST)
+ set(GUDHI_SUB_DIRECTORIES "${GUDHI_SUB_DIRECTORIES};test")
+endif()
+if (NOT WITHOUT_GUDHI_UTILITIES)
+ set(GUDHI_SUB_DIRECTORIES "${GUDHI_SUB_DIRECTORIES};utilities")
+endif()
+
+message("++ GUDHI_SUB_DIRECTORIES list is:\"${GUDHI_SUB_DIRECTORIES}\"")
+
+
+
diff --git a/src/cmake/modules/GUDHI_user_version_target.txt b/src/cmake/modules/GUDHI_user_version_target.cmake
index ca6bcd34..a764e88a 100644
--- a/src/cmake/modules/GUDHI_user_version_target.txt
+++ b/src/cmake/modules/GUDHI_user_version_target.cmake
@@ -47,7 +47,6 @@ 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_MODULES "common;Alpha_complex;Bitmap_cubical_complex;Bottleneck_distance;Contraction;Hasse_complex;Persistent_cohomology;Rips_complex;Simplex_tree;Skeleton_blocker;Spatial_searching;Subsampling;Tangential_complex;Witness_complex")
set(GUDHI_DIRECTORIES "doc;example;concept")
set(GUDHI_INCLUDE_DIRECTORIES "include/gudhi;include/gudhi_patches")
diff --git a/src/common/include/gudhi/random_point_generators.h b/src/common/include/gudhi/random_point_generators.h
index 2ec465ef..9df77760 100644
--- a/src/common/include/gudhi/random_point_generators.h
+++ b/src/common/include/gudhi/random_point_generators.h
@@ -282,6 +282,38 @@ std::vector<typename Kernel::Point_d> generate_points_on_sphere_d(std::size_t nu
}
template <typename Kernel>
+std::vector<typename Kernel::Point_d> generate_points_in_ball_d(std::size_t num_points, int dim, double radius) {
+ typedef typename Kernel::Point_d Point;
+ Kernel k;
+ CGAL::Random rng;
+ CGAL::Random_points_in_ball_d<Point> generator(dim, radius);
+ std::vector<Point> points;
+ points.reserve(num_points);
+ for (std::size_t i = 0; i < num_points;) {
+ Point p = *generator++;
+ points.push_back(p);
+ ++i;
+ }
+ return points;
+}
+
+template <typename Kernel>
+std::vector<typename Kernel::Point_d> generate_points_in_cube_d(std::size_t num_points, int dim, double radius) {
+ typedef typename Kernel::Point_d Point;
+ Kernel k;
+ CGAL::Random rng;
+ CGAL::Random_points_in_cube_d<Point> generator(dim, radius);
+ std::vector<Point> points;
+ points.reserve(num_points);
+ for (std::size_t i = 0; i < num_points;) {
+ Point p = *generator++;
+ points.push_back(p);
+ ++i;
+ }
+ return points;
+}
+
+template <typename Kernel>
std::vector<typename Kernel::Point_d> generate_points_on_two_spheres_d(std::size_t num_points, int dim, double radius,
double distance_between_centers,
double radius_noise_percentage = 0.) {
diff --git a/src/common/utilities/CMakeLists.txt b/src/common/utilities/CMakeLists.txt
new file mode 100644
index 00000000..88d377a7
--- /dev/null
+++ b/src/common/utilities/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.6)
+project(data_points_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 $<TARGET_FILE:data_points_generator>
+ "on" "sphere" "onSphere.off" "1000" "3" "15.2")
+ add_test(NAME data_points_generator_in_sphere_100_2 COMMAND $<TARGET_FILE:data_points_generator>
+ "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 $<TARGET_FILE:data_points_generator>
+ "in" "cube" "inCube.off" "10000" "3" "5.8")
+endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0)
diff --git a/src/common/utilities/README b/src/common/utilities/README
new file mode 100644
index 00000000..f2ece556
--- /dev/null
+++ b/src/common/utilities/README
@@ -0,0 +1,19 @@
+======================= data_points_generator ==================================
+
+Example of use :
+
+*** Hyper sphere|cube generator
+
+./data_points_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
+
+ => 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
+
+ => generates a inCube.off file with 10000 points randomized in a cube of dimension 3 and side 5.8
+
+!! Warning: hypegenerator on cube is not available !!
diff --git a/src/common/utilities/hypergenerator.cpp b/src/common/utilities/hypergenerator.cpp
new file mode 100644
index 00000000..0f310a13
--- /dev/null
+++ b/src/common/utilities/hypergenerator.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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <gudhi/random_point_generators.h>
+
+#include <CGAL/Epick_d.h>
+#include <CGAL/algorithm.h>
+#include <CGAL/assertions.h>
+
+#include <iostream>
+#include <iterator>
+#include <vector>
+#include <fstream> // for std::ofstream
+#include <cstdlib>
+
+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<Point> points;
+ if (in) {
+ switch (shape) {
+ case Data_shape::sphere:
+ points = Gudhi::generate_points_in_ball_d<K>(points_number, dimension, radius);
+ break;
+ case Data_shape::cube:
+ points = Gudhi::generate_points_in_ball_d<K>(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<K>(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<K>(points_number, dimension, -radius/2., radius/2.);
+ break;
+ case Data_shape::torus:
+ if (dimension == 3)
+ points = Gudhi::generate_points_on_torus_3D<K>(points_number, dimension, radius, radius/2.);
+ else
+ points = Gudhi::generate_points_on_torus_d<K>(points_number, dimension, true);
+ break;
+ case Data_shape::klein:
+ switch (dimension) {
+ case 3:
+ points = Gudhi::generate_points_on_klein_bottle_3D<K>(points_number, radius, radius/2., true);
+ break;
+ case 4:
+ points = Gudhi::generate_points_on_klein_bottle_4D<K>(points_number, radius, radius/2., 0., true);
+ break;
+ case 5:
+ points = Gudhi::generate_points_on_klein_bottle_variant_5D<K>(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;
+}
+