CGAL: How to create a sphere mesh?

64 Views Asked by At

How can I build a sphere mesh by cgal? I want to use SurfaceMesh data structure to store a sphere

I tried to use the example: Surface_mesher_2mesh_an_implicit_function_8cpp-example But the sphere is irregular in shape. irregular_sphere And I want to generate a sphere like this, what should I do? regular_sphere

2

There are 2 best solutions below

0
Andreas Fabri On BEST ANSWER

I found this blog post by Daniel Sieger.
Note that CGAL offers the subdivision functions, as well as the function to construct an isocahedron So you have to assemble this and add the projection to the sphere.

0
Stéphane Laurent On

The iterated Loop subdivision of an icosahedron produces a sphere (the icosphere).

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Subdivision_method_3/subdivision_methods_3.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3                                          Point3;
typedef CGAL::Surface_mesh<Point3>                          Mesh3;

Mesh3 icosphere(Point3 center, double radius, unsigned int iterations) {
  Mesh3 mesh;
  CGAL::make_icosahedron<Mesh3, Point3>(mesh, center, radius);
  CGAL::Subdivision_method_3::Loop_subdivision(
    mesh, CGAL::parameters::number_of_iterations(iterations)
  );
  return mesh;
}