| 1 |
// workaround for the annoying boost message in boost 1.69 |
| 2 |
#define BOOST_PENDING_INTEGER_LOG2_HPP |
| 3 |
#include <boost/integer/integer_log2.hpp> |
| 4 |
// end workaround |
| 5 |
|
| 6 |
#include <iostream> |
| 7 |
|
| 8 |
#include <gudhi/Coxeter_triangulation.h> |
| 9 |
#include <gudhi/Functions/Function_affine_plane_in_Rd.h> |
| 10 |
#include <gudhi/Functions/Function_Sm_in_Rd.h> |
| 11 |
#include <gudhi/Functions/Cartesian_product.h> |
| 12 |
#include <gudhi/Functions/Linear_transformation.h> |
| 13 |
#include <gudhi/Implicit_manifold_intersection_oracle.h> |
| 14 |
#include <gudhi/Manifold_tracing.h> |
| 15 |
#include <gudhi/Coxeter_triangulation/Cell_complex/Cell_complex.h> |
| 16 |
#include <gudhi/Functions/random_orthogonal_matrix.h> // requires CGAL |
| 17 |
|
| 18 |
#include <gudhi/IO/build_mesh_from_cell_complex.h> |
| 19 |
#include <gudhi/IO/output_meshes_to_medit.h> |
| 20 |
|
| 21 |
using namespace Gudhi::coxeter_triangulation; |
| 22 |
|
| 23 |
int main(int argc, char** argv) { |
| 24 |
// Creating a circle S1 in R2 of specified radius |
| 25 |
double radius = 1.0; |
| 26 |
Function_Sm_in_Rd fun_circle(radius, 1); |
| 27 |
|
| 28 |
// Creating a flat torus S1xS1 in R4 from two circle functions |
| 29 |
auto fun_flat_torus = make_product_function(fun_circle, fun_circle); |
| 30 |
|
| 31 |
// Apply a random rotation in R4 |
| 32 |
auto matrix = random_orthogonal_matrix(4); |
| 33 |
auto fun_flat_torus_rotated = make_linear_transformation(fun_flat_torus, matrix); |
| 34 |
|
| 35 |
// Computing the seed of the function fun_flat_torus |
| 36 |
Eigen::VectorXd seed = fun_flat_torus_rotated.seed(); |
| 37 |
|
| 38 |
// Defining a domain function that defines the boundary, which is a hyperplane passing by the origin and orthogonal to |
| 39 |
// x. |
| 40 |
Eigen::MatrixXd normal_matrix = Eigen::MatrixXd::Zero(4, 1); |
| 41 |
for (std::size_t i = 0; i < 4; i++) normal_matrix(i, 0) = -seed(i); |
| 42 |
Function_affine_plane_in_Rd fun_bound(normal_matrix, -seed / 2); |
| 43 |
|
| 44 |
// Defining the intersection oracle |
| 45 |
auto oracle = make_oracle(fun_flat_torus_rotated, fun_bound); |
| 46 |
|
| 47 |
// Define a Coxeter triangulation scaled by a factor lambda. |
| 48 |
// The triangulation is translated by a random vector to avoid violating the genericity hypothesis. |
| 49 |
double lambda = 0.2; |
| 50 |
Coxeter_triangulation<> cox_tr(oracle.amb_d()); |
| 51 |
cox_tr.change_offset(Eigen::VectorXd::Random(oracle.amb_d())); |
| 52 |
cox_tr.change_matrix(lambda * cox_tr.matrix()); |
| 53 |
|
| 54 |
// Manifold tracing algorithm |
| 55 |
using MT = Manifold_tracing<Coxeter_triangulation<> >; |
| 56 |
using Out_simplex_map = typename MT::Out_simplex_map; |
| 57 |
std::vector<Eigen::VectorXd> seed_points(1, seed); |
| 58 |
Out_simplex_map interior_simplex_map, boundary_simplex_map; |
| 59 |
manifold_tracing_algorithm(seed_points, cox_tr, oracle, interior_simplex_map, boundary_simplex_map); |
| 60 |
|
| 61 |
// Constructing the cell complex |
| 62 |
std::size_t intr_d = oracle.amb_d() - oracle.cod_d(); |
| 63 |
Cell_complex<Out_simplex_map> cell_complex(intr_d); |
| 64 |
cell_complex.construct_complex(interior_simplex_map, boundary_simplex_map); |
| 65 |
|
| 66 |
// Output the cell complex to a file readable by medit |
| 67 |
output_meshes_to_medit(3, "flat_torus_with_boundary", |
| 68 |
build_mesh_from_cell_complex(cell_complex, Configuration(true, true, true, 1, 5, 3), |
| 69 |
Configuration(true, true, true, 2, 13, 14))); |
| 70 |
|
| 71 |
return 0; |
| 72 |
} |