summaryrefslogtreecommitdiff
path: root/utilities
diff options
context:
space:
mode:
authorGard Spreemann <gspreemann@gmail.com>2017-10-08 11:15:17 +0200
committerGard Spreemann <gspreemann@gmail.com>2017-10-08 11:15:17 +0200
commit866f6ce614e9c09c97fed12c8c0c2c9fb84fad3f (patch)
tree0c90eb9bab09ccc9785cdf2dc59f0ec861670b85 /utilities
parent8d7329f3e5ad843e553c3c5503cecc28ef2eead6 (diff)
GUDHI 2.0.1 as released by upstream in a tarball.upstream/2.0.1
Diffstat (limited to 'utilities')
-rw-r--r--utilities/common/CMakeLists.txt17
-rw-r--r--utilities/common/README19
-rw-r--r--utilities/common/off_file_from_shape_generator.cpp189
3 files changed, 225 insertions, 0 deletions
diff --git a/utilities/common/CMakeLists.txt b/utilities/common/CMakeLists.txt
new file mode 100644
index 00000000..b3e4b436
--- /dev/null
+++ b/utilities/common/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 2.6)
+project(off_file_from_shape_generator)
+
+if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0)
+ add_executable ( off_file_from_shape_generator off_file_from_shape_generator.cpp )
+ add_test(NAME off_file_from_shape_generator_on_sphere_1000_3_15.2 COMMAND $<TARGET_FILE:off_file_from_shape_generator>
+ "on" "sphere" "onSphere.off" "1000" "3" "15.2")
+ add_test(NAME off_file_from_shape_generator_in_sphere_100_2 COMMAND $<TARGET_FILE:off_file_from_shape_generator>
+ "in" "sphere" "inSphere.off" "100" "2")
+
+ # on cube is not available in CGAL
+ add_test(NAME off_file_from_shape_generator_in_cube_10000_3_5.8 COMMAND $<TARGET_FILE:off_file_from_shape_generator>
+ "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/utilities/common/README b/utilities/common/README
new file mode 100644
index 00000000..dc841521
--- /dev/null
+++ b/utilities/common/README
@@ -0,0 +1,19 @@
+======================= off_file_from_shape_generator ==================================
+
+Example of use :
+
+*** on|in sphere|cube|curve|torus|klein generator
+
+./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
+
+./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)
+
+./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
+
+!! Warning: hypegenerator on cube is not available !!
diff --git a/utilities/common/off_file_from_shape_generator.cpp b/utilities/common/off_file_from_shape_generator.cpp
new file mode 100644
index 00000000..afcd558c
--- /dev/null
+++ b/utilities/common/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 <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;
+}
+