mirror of https://github.com/CGAL/cgal
Added an example of Alpha Shapes 3D with a regular periodic triangulation
This commit is contained in:
parent
a1c57031ba
commit
31c5540cd5
|
|
@ -0,0 +1,103 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Alpha_shape_3.h>
|
||||
#include <CGAL/Periodic_3_regular_triangulation_traits_3.h>
|
||||
#include <CGAL/Periodic_3_regular_triangulation_3.h>
|
||||
|
||||
#include <CGAL/Random.h>
|
||||
#include <CGAL/point_generators_3.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// Traits
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef CGAL::Periodic_3_regular_triangulation_traits_3<K> PK;
|
||||
|
||||
// Vertex type
|
||||
typedef CGAL::Periodic_3_triangulation_ds_vertex_base_3<> DsVb;
|
||||
typedef CGAL::Regular_triangulation_vertex_base_3<PK,DsVb> Vb;
|
||||
typedef CGAL::Alpha_shape_vertex_base_3<PK,Vb> AsVb;
|
||||
// Cell type
|
||||
typedef CGAL::Periodic_3_triangulation_ds_cell_base_3<> DsCb;
|
||||
typedef CGAL::Regular_triangulation_cell_base_3<PK,DsCb> Cb;
|
||||
typedef CGAL::Alpha_shape_cell_base_3<PK,Cb> AsCb;
|
||||
|
||||
typedef CGAL::Triangulation_data_structure_3<AsVb,AsCb> Tds;
|
||||
typedef CGAL::Periodic_3_regular_triangulation_3<PK,Tds> P3RT3;
|
||||
typedef CGAL::Alpha_shape_3<P3RT3> Alpha_shape_3;
|
||||
|
||||
typedef P3RT3::Bare_point Bare_point;
|
||||
typedef P3RT3::Weighted_point Weighted_point;
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef CGAL::Creator_uniform_3<double, Bare_point> Creator;
|
||||
CGAL::Random random(8);
|
||||
CGAL::Random_points_in_cube_3<Bare_point, Creator> in_cube(1, random);
|
||||
std::vector<Weighted_point> pts;
|
||||
|
||||
// read input
|
||||
std::ifstream is("./data/bunny_1000");
|
||||
int n;
|
||||
is >> n;
|
||||
std::cout << "Reading " << n << " points " << std::endl;
|
||||
Bare_point bp;
|
||||
for( ; n>0 ; n--) {
|
||||
is >> bp;
|
||||
Weighted_point p(bp, 0.01 * random.get_double(0., 0.015625));
|
||||
pts.push_back(p);
|
||||
}
|
||||
|
||||
/*
|
||||
// Generating 1000 random points
|
||||
for(int i=0; i<1000 ; i++) {
|
||||
Weighted_point p(*in_cube++, random.get_double(0., 0.015625));
|
||||
// Weighted_point p(*in_cube++, 0.);
|
||||
std::cout << "inserting: " << i << " || " << p << std::endl;
|
||||
pts.push_back(p);
|
||||
}
|
||||
*/
|
||||
|
||||
// Define the periodic cube
|
||||
P3RT3 prt(PK::Iso_cuboid_3(-0.1,0.,-0.1, 0.1,0.2,0.1));
|
||||
|
||||
// Heuristic for inserting large point sets (if pts is reasonably large)
|
||||
prt.insert(pts.begin(), pts.end(), true);
|
||||
|
||||
// As prt won't be modified anymore switch to 1-sheeted cover if possible
|
||||
if(prt.is_triangulation_in_1_sheet())
|
||||
{
|
||||
std::cout << "Switching to 1-sheeted covering" << std::endl;
|
||||
prt.convert_to_1_sheeted_covering();
|
||||
}
|
||||
|
||||
std::cout << "Periodic Regular computed." << std::endl;
|
||||
|
||||
// compute alpha shape
|
||||
Alpha_shape_3 as(prt);
|
||||
std::cout << "Alpha shape computed in REGULARIZED mode by default." << std::endl;
|
||||
|
||||
// find optimal alpha values
|
||||
Alpha_shape_3::NT alpha_solid = as.find_alpha_solid();
|
||||
Alpha_shape_3::Alpha_iterator opt = as.find_optimal_alpha(1);
|
||||
std::cout << "Smallest alpha value to get a solid through data points is " << alpha_solid << std::endl;
|
||||
std::cout << "Optimal alpha value to get one connected component is " << *opt << std::endl;
|
||||
as.set_alpha(*opt);
|
||||
// assert(as.number_of_solid_components() == 1);
|
||||
|
||||
CGAL::Geomview_stream gv(CGAL::Bbox_3(-0.1,0.,-0.1, 0.1,0.2,0.1));
|
||||
gv.set_bg_color(CGAL::Color(0, 200, 200));
|
||||
gv.clear();
|
||||
|
||||
gv << as;
|
||||
gv.set_wired(true);
|
||||
gv << as;
|
||||
|
||||
char ch;
|
||||
std::cout << "Enter any character to quit" << std::endl;
|
||||
std::cin >> ch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue