| 1 |
#include <iostream> |
| 2 |
|
| 3 |
#include <gudhi/Coxeter_triangulation.h> |
| 4 |
#include <gudhi/Functions/Function_Sm_in_Rd.h> |
| 5 |
#include <gudhi/Implicit_manifold_intersection_oracle.h> |
| 6 |
#include <gudhi/Manifold_tracing.h> |
| 7 |
#include <gudhi/Coxeter_triangulation/Cell_complex/Cell_complex.h> |
| 8 |
#include <gudhi/Functions/Linear_transformation.h> |
| 9 |
|
| 10 |
#include <gudhi/IO/build_mesh_from_cell_complex.h> |
| 11 |
#include <gudhi/IO/output_meshes_to_medit.h> |
| 12 |
|
| 13 |
using namespace Gudhi::coxeter_triangulation; |
| 14 |
|
| 15 |
/* A definition of a function that defines a 2d surface embedded in R^4, but that normally |
| 16 |
* lives on a complex projective plane. |
| 17 |
* In terms of harmonic coordinates [x:y:z] of points on the complex projective plane, |
| 18 |
* the equation of the manifold is x^3*y + y^3*z + z^3*x = 0. |
| 19 |
* The embedding consists of restricting the manifold to the affine subspace z = 1. |
| 20 |
*/ |
| 21 |
struct Function_surface_on_CP2_in_R4 { |
| 22 |
Eigen::VectorXd operator()(const Eigen::VectorXd& p) const { |
| 23 |
// The real and imaginary parts of the variables x and y |
| 24 |
double xr = p(0), xi = p(1), yr = p(2), yi = p(3); |
| 25 |
Eigen::VectorXd result(cod_d()); |
| 26 |
|
| 27 |
// Squares and cubes of real and imaginary parts used in the computations |
| 28 |
double xr2 = xr * xr, xi2 = xi * xi, yr2 = yr * yr, yi2 = yi * yi, xr3 = xr2 * xr, xi3 = xi2 * xi, yr3 = yr2 * yr, |
| 29 |
yi3 = yi2 * yi; |
| 30 |
|
| 31 |
// The first coordinate of the output is Re(x^3*y + y^3 + x) |
| 32 |
result(0) = xr3 * yr - 3 * xr * xi2 * yr - 3 * xr2 * xi * yi + xi3 * yi + yr3 - 3 * yr * yi2 + xr; |
| 33 |
// The second coordinate of the output is Im(x^3*y + y^3 + x) |
| 34 |
result(1) = 3 * xr2 * xi * yr + xr3 * yi - 3 * xr * xi2 * yi - xi3 * yr + 3 * yr2 * yi - yi3 + xi; |
| 35 |
return result; |
| 36 |
} |
| 37 |
|
| 38 |
std::size_t amb_d() const { return 4; }; |
| 39 |
std::size_t cod_d() const { return 2; }; |
| 40 |
|
| 41 |
Eigen::VectorXd seed() const { |
| 42 |
Eigen::VectorXd result = Eigen::VectorXd::Zero(4); |
| 43 |
return result; |
| 44 |
} |
| 45 |
|
| 46 |
Function_surface_on_CP2_in_R4() {} |
| 47 |
}; |
| 48 |
|
| 49 |
int main(int argc, char** argv) { |
| 50 |
// The function for the (non-compact) manifold |
| 51 |
Function_surface_on_CP2_in_R4 fun; |
| 52 |
|
| 53 |
// Seed of the function |
| 54 |
Eigen::VectorXd seed = fun.seed(); |
| 55 |
|
| 56 |
// Creating the function that defines the boundary of a compact region on the manifold |
| 57 |
double radius = 3.0; |
| 58 |
Function_Sm_in_Rd fun_sph(radius, 3, seed); |
| 59 |
|
| 60 |
// Defining the intersection oracle |
| 61 |
auto oracle = make_oracle(fun, fun_sph); |
| 62 |
|
| 63 |
// Define a Coxeter triangulation scaled by a factor lambda. |
| 64 |
// The triangulation is translated by a random vector to avoid violating the genericity hypothesis. |
| 65 |
double lambda = 0.2; |
| 66 |
Coxeter_triangulation<> cox_tr(oracle.amb_d()); |
| 67 |
cox_tr.change_offset(Eigen::VectorXd::Random(oracle.amb_d())); |
| 68 |
cox_tr.change_matrix(lambda * cox_tr.matrix()); |
| 69 |
|
| 70 |
// Manifold tracing algorithm |
| 71 |
using MT = Manifold_tracing<Coxeter_triangulation<> >; |
| 72 |
using Out_simplex_map = typename MT::Out_simplex_map; |
| 73 |
std::vector<Eigen::VectorXd> seed_points(1, seed); |
| 74 |
Out_simplex_map interior_simplex_map, boundary_simplex_map; |
| 75 |
manifold_tracing_algorithm(seed_points, cox_tr, oracle, interior_simplex_map, boundary_simplex_map); |
| 76 |
|
| 77 |
// Constructing the cell complex |
| 78 |
std::size_t intr_d = oracle.amb_d() - oracle.cod_d(); |
| 79 |
Cell_complex<Out_simplex_map> cell_complex(intr_d); |
| 80 |
cell_complex.construct_complex(interior_simplex_map, boundary_simplex_map); |
| 81 |
|
| 82 |
// Output the cell complex to a file readable by medit |
| 83 |
output_meshes_to_medit(3, "manifold_on_CP2_with_boundary", |
| 84 |
build_mesh_from_cell_complex(cell_complex, Configuration(true, true, true, 1, 5, 3), |
| 85 |
Configuration(true, true, true, 2, 13, 14))); |
| 86 |
return 0; |
| 87 |
} |