diff options
author | Gard Spreemann <gspreemann@gmail.com> | 2017-02-07 17:33:01 +0100 |
---|---|---|
committer | Gard Spreemann <gspreemann@gmail.com> | 2017-02-07 17:33:01 +0100 |
commit | 55c7181126aa7defce38c9b82872d14223d4c1dd (patch) | |
tree | 7c683f014709459f066fd87a21da7f74cfc31a53 /data/points/generator |
Initial import of upstream's 1.3.1.upstream/1.3.1
Diffstat (limited to 'data/points/generator')
-rw-r--r-- | data/points/generator/CMakeLists.txt | 18 | ||||
-rw-r--r-- | data/points/generator/README | 44 | ||||
-rwxr-xr-x | data/points/generator/aurelien_alvarez_surfaces_in_R8.py | 90 | ||||
-rw-r--r-- | data/points/generator/hypergenerator.cpp | 135 |
4 files changed, 287 insertions, 0 deletions
diff --git a/data/points/generator/CMakeLists.txt b/data/points/generator/CMakeLists.txt new file mode 100644 index 00000000..f559610c --- /dev/null +++ b/data/points/generator/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 2.6) +project(Data_points_generator) + +if(CGAL_FOUND) + if (NOT CGAL_VERSION VERSION_LESS 4.6.0) + if (EIGEN3_FOUND) + add_executable ( hypergenerator hypergenerator.cpp ) + target_link_libraries(hypergenerator ${Boost_SYSTEM_LIBRARY}) + add_test(hypergenerator_on_sphere_3000_10_5.0 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator on sphere onSphere.off 3000 10 5.0) + add_test(hypergenerator_on_sphere_10000_3 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator on sphere onSphere.off 10000 3) + add_test(hypergenerator_in_sphere_7000_12_10.8 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator in sphere inSphere.off 7000 12 10.8) + add_test(hypergenerator_in_sphere_50000_2 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator in sphere inSphere.off 50000 2) + # on cube is not available in CGAL + add_test(hypergenerator_in_cube_7000_12_10.8 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator in cube inCube.off 7000 12 10.8) + add_test(hypergenerator_in_cube_50000_2 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator in cube inCube.off 50000 3) + endif(EIGEN3_FOUND) + endif(NOT CGAL_VERSION VERSION_LESS 4.6.0) +endif(CGAL_FOUND) diff --git a/data/points/generator/README b/data/points/generator/README new file mode 100644 index 00000000..41cb9165 --- /dev/null +++ b/data/points/generator/README @@ -0,0 +1,44 @@ +=========================== C++ generators ===================================== + +To build the C++ generators, run in a Terminal: + +cd /path-to-gudhi/ +cmake . +cd /path-to-data-generator/ +make + +=========================== hypergenerator ===================================== + +Example of use : + +*** Hyper sphere|cube generator + +./hypergenerator 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 + +./hypergenerator 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) + +./hypergenerator 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 !! + +===================== aurelien_alvarez_surfaces_in_R8 ========================== + +This generator is written in Python. + +This code generates points on a family of surfaces living in CP^2. You can move +in the family thanks to the parameter "degre". The parameter "nombrePoints" +allows to choose the number of points on the chosen surface. Finally, to compute +the points, we choose a chart in C^2 and take points randomly in the x-variable, +so that you may also modify the window for x in the complex plane (parameter +"module_x"). + +After that, the program computes points in C^2, then maps them in R^8, so that +the points live on a surface which is compact (which is not the case for the +intersection of the surface with C^2). We end off with a bunch of points on a +compact surface in R^8. diff --git a/data/points/generator/aurelien_alvarez_surfaces_in_R8.py b/data/points/generator/aurelien_alvarez_surfaces_in_R8.py new file mode 100755 index 00000000..57773c4c --- /dev/null +++ b/data/points/generator/aurelien_alvarez_surfaces_in_R8.py @@ -0,0 +1,90 @@ +# 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): Aurélien Alvarez +# +# Copyright (C) 2016 Université d'Orléans (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/>. + +import numpy as np +import random +from math import factorial + +I = complex(0,1) + +################################################# +################################################# + +#Surface réelle d'équation x.conj(y)^d + y.conj(z)^d + z.conj(x)^d = 0 dans P2(C) +#Équation affine (z=1) multipliée par sa conjuguée (d = 2) : x.conj(x)^2.y^4 + 2x^3.conj(x).y^2 + y + conj(x)^2 + x^5 = 0 +def equationAffineSurfaceReelle(x): + polynome = [0]*(degre**2+1) + for k in range(degre+1): + polynome[k*degre] = (-1)**degre*x*factorial(degre)/(factorial(k)*factorial(degre-k))*x**(k*degre)*np.conjugate(x)**(degre-k) + polynome[-2] += 1 + polynome[-1] += np.conjugate(x)**degre + return polynome + +################################################# +################################################# + +def calculRacines(equation,nombrePoints,module_x): + racines = [[1,0,0],[0,1,0],[0,0,1]] + for _ in range(nombrePoints): + x = module_x*(2*random.random()-1+I*(2*random.random()-1)) + fool = [[[x,y,1],[y,1,x],[1,x,y]] for y in np.roots(equation(x)) if abs(x*np.conjugate(y)**degre+y+np.conjugate(x)**degre) < 0.0001] + for bar in fool: + racines += bar + return racines + +################################################# +################################################# + +def plongementDansR8(pointDansCP2): + z0 = pointDansCP2[0] + z1 = pointDansCP2[1] + z2 = pointDansCP2[2] + a = z0*np.conjugate(z0) + b = z1*np.conjugate(z1) + c = z2*np.conjugate(z2) + normeCarree = a+b+c + a = a/normeCarree + b = b/normeCarree + u = z0*np.conjugate(z1)/normeCarree + v = z0*np.conjugate(z2)/normeCarree + w = z1*np.conjugate(z2)/normeCarree + return [a.real,b.real,u.real,u.imag,v.real,v.imag,w.real,w.imag] + +def plongementListeDansR8(listePointsDansCP2): + listePointsDansR8 = [] + for point in listePointsDansCP2: + listePointsDansR8 += [plongementDansR8(point)] + return listePointsDansR8 + +################################################# +################################################# + +degre = 3 +nombrePoints = 10**4 +module_x = 10 + +with open("surface.txt","w") as fichier: + bar = calculRacines(equationAffineSurfaceReelle,nombrePoints,module_x) + listePoints = plongementListeDansR8(bar) + fichier.write(str(len(bar)) + "\n") + for point in listePoints: + fichier.write(str(point[0]) + " " + str(point[1]) + " " + str(point[2]) + " " + str(point[3]) + " " + str(point[4]) + " " + str(point[5]) + " " + str(point[6]) + " " + str(point[7]) + "\n") + diff --git a/data/points/generator/hypergenerator.cpp b/data/points/generator/hypergenerator.cpp new file mode 100644 index 00000000..60890b44 --- /dev/null +++ b/data/points/generator/hypergenerator.cpp @@ -0,0 +1,135 @@ +/* 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 <CGAL/Epick_d.h> +#include <CGAL/point_generators_d.h> +#include <CGAL/algorithm.h> +#include <CGAL/assertions.h> + +#include <iostream> +#include <iterator> +#include <vector> +#include <fstream> // for std::ofstream + + +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 = 0; + int returnedScanValue = sscanf(argv[4], "%d", &points_number); + if ((returnedScanValue == EOF) || (points_number <= 0)) { + std::cerr << "Error: " << argv[4] << " is not correct" << std::endl; + usage(argv[0]); + } + + int dimension = 0; + returnedScanValue = sscanf(argv[5], "%d", &dimension); + if ((returnedScanValue == EOF) || (dimension <= 0)) { + std::cerr << "Error: " << argv[5] << " is not correct" << std::endl; + usage(argv[0]); + } + + double radius = 1.0; + if (argc == 7) { + returnedScanValue = sscanf(argv[6], "%lf", &radius); + if ((returnedScanValue == EOF) || (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]); + } + + bool sphere = false; + if (memcmp(argv[2], "sphere", sizeof("sphere")) == 0) { + sphere = true; + } else if (memcmp(argv[2], "cube", sizeof("cube")) != 0) { + 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()) { + // Instanciate a random point generator + CGAL::Random rng(0); + // Generate "points_number" random points in a vector + std::vector<Point> points; + if (in) { + if (sphere) { + CGAL::Random_points_in_ball_d<Point> rand_it(dimension, radius, rng); + CGAL::cpp11::copy_n(rand_it, points_number, std::back_inserter(points)); + } else { + CGAL::Random_points_in_cube_d<Point> rand_it(dimension, radius, rng); + CGAL::cpp11::copy_n(rand_it, points_number, std::back_inserter(points)); + } + } else { // means "on" + if (sphere) { + CGAL::Random_points_on_sphere_d<Point> rand_it(dimension, radius, rng); + CGAL::cpp11::copy_n(rand_it, points_number, std::back_inserter(points)); + } else { + std::cerr << "Sorry: on cube is not available" << std::endl; + usage(argv[0]); + } + } + + 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; +} + |