|
| 1 | +#include <pybind11/pybind11.h> |
| 2 | +#include <pybind11/stl.h> |
| 3 | +#include <pybind11/complex.h> |
| 4 | +#include <pybind11/numpy.h> |
| 5 | +#include <boost/lexical_cast.hpp> |
| 6 | + |
| 7 | +#include <fstream> |
| 8 | +#include <vector> |
| 9 | +#include <string> |
| 10 | +#include <sstream> |
| 11 | +#include <algorithm> |
| 12 | +#include <iostream> |
| 13 | + |
| 14 | + |
| 15 | +#include <CGAL/Surface_mesh_default_triangulation_3.h> |
| 16 | +#include <CGAL/Complex_2_in_triangulation_3.h> |
| 17 | +#include <CGAL/make_surface_mesh.h> |
| 18 | +#include <CGAL/Implicit_surface_3.h> |
| 19 | + |
| 20 | +// default triangulation for Surface_mesher |
| 21 | +typedef CGAL::Surface_mesh_default_triangulation_3 Tr; |
| 22 | +// c2t3 |
| 23 | +typedef CGAL::Complex_2_in_triangulation_3<Tr> C2t3; |
| 24 | +typedef Tr::Geom_traits GT; |
| 25 | +typedef GT::Sphere_3 Sphere_3; |
| 26 | +typedef GT::Point_3 Point_3; |
| 27 | +typedef GT::FT FT; |
| 28 | +typedef FT (*Function)(Point_3); |
| 29 | +typedef CGAL::Implicit_surface_3<GT, Function> Surface_3; |
| 30 | +//typedef C2t3::Vertex_handle vertex_descriptor; |
| 31 | +//using vertex_descriptor = boost::graph_traits<C2t3>::vertex_descriptor; |
| 32 | + |
| 33 | + |
| 34 | +FT sphere_function (Point_3 p) { |
| 35 | + const FT x2=p.x()*p.x(), y2=p.y()*p.y(), z2=p.z()*p.z(); |
| 36 | + return x2+y2+z2-1; |
| 37 | +} |
| 38 | + |
| 39 | +namespace py = pybind11; |
| 40 | + |
| 41 | +std::vector<std::tuple<double, double, double>> make_spherical(double num_points) { |
| 42 | + Tr tr; // 3D-Delaunay triangulation |
| 43 | + C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation |
| 44 | + // defining the surface |
| 45 | + Surface_3 surface(sphere_function, // pointer to function |
| 46 | + Sphere_3(CGAL::ORIGIN, 2.)); // bounding sphere |
| 47 | + // Note that "2." above is the *squared* radius of the bounding sphere! |
| 48 | + // defining meshing criteria |
| 49 | + double r_max = std::sqrt(1 / (num_points * 0.12)); |
| 50 | + CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30, r_max, r_max); |
| 51 | + // meshing surface |
| 52 | + CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); |
| 53 | + std::vector<std::tuple<double, double, double>> points; |
| 54 | + Tr::Finite_vertices_iterator it; |
| 55 | + for (it = tr.finite_vertices_begin(); it != tr.finite_vertices_end(); it++) |
| 56 | + { |
| 57 | + Point_3 p = tr.point(it); |
| 58 | + std::tuple<double, double, double> tmp = std::make_tuple(p.x(), p.y(), p.z()); |
| 59 | + points.push_back(tmp); |
| 60 | + } |
| 61 | + return points; |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +PYBIND11_MODULE(mesh_generation, m) |
| 66 | +{ |
| 67 | + m.def("make_spherical", &make_spherical); |
| 68 | +} |
0 commit comments