Subject: CGAL users discussion list
List archive
- From: Claudia Werner <>
- To: <>
- Subject: [cgal-discuss] Alpha_Shapes_3 Bunny
- Date: Mon, 25 Nov 2013 20:28:07 +0100 (CET)
Dear all,
I am working on Alpha_Shapes for triangulating a point cloud. As a first
example I tried the example "Alpha_shapes_3/ex_alpha_shapes_3.cpp"
(http://doc.cgal.org/latest/Alpha_shapes_3/Alpha_shapes_3_2ex_alpha_shapes_3_8cpp-example.html)
and wrote the result to an off-File as descirbed
here:http://stackoverflow.com/questions/15905833/saving-cgal-alpha-shape-surface-mesh.
Displaying the result with MeshLab (using the off-file), I was wondering
about the result (see attached picture).
Has anybody an idea why I don't get a better result? As in the example I used
the optimal alpha.
I also attached the cpp-file.
Best Regards and thanks for your help,
Claudia
Attachment:
snapshot_bunny.png
Description: PNG image
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Alpha_shape_3.h>
#include <fstream>
#include <list>
#include <cassert>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Gt;
typedef CGAL::Alpha_shape_vertex_base_3<Gt> Vb;
typedef CGAL::Alpha_shape_cell_base_3<Gt> Fb;
typedef CGAL::Triangulation_data_structure_3<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_3<Gt,Tds> Triangulation_3;
typedef CGAL::Alpha_shape_3<Triangulation_3> Alpha_shape_3;
typedef Gt::Point_3 Point;
typedef Alpha_shape_3::Alpha_iterator Alpha_iterator;
int main()
{
std::list<Point> lp;
//read input
std::ifstream is("./bunny_1000");
int n;
is >> n;
std::cout << "Reading " << n << " points " << std::endl;
Point p;
for( ; n>0 ; n--) {
is >> p;
lp.push_back(p);
}
// compute alpha shape
Alpha_shape_3 as(lp.begin(),lp.end());
std::cout << "Alpha shape computed in REGULARIZED mode by default"
<< std::endl;
// find optimal alpha value
Alpha_iterator opt = as.find_optimal_alpha(1);
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);
std::vector<Alpha_shape_3::Facet> facets;
as.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR);
std::stringstream pts;
std::stringstream ind;
std::size_t nbf=facets.size();
for (std::size_t i=0;i<nbf;++i)
{
//To have a consistent orientation of the facet, always consider an
exterior cell
if ( as.classify( facets[i].first )!=Alpha_shape_3::EXTERIOR )
facets[i]=as.mirror_facet( facets[i] );
CGAL_assertion( as.classify( facets[i].first )==Alpha_shape_3::EXTERIOR );
int indices[3]={
(facets[i].second+1)%4,
(facets[i].second+2)%4,
(facets[i].second+3)%4,
};
/// according to the encoding of vertex indices, this is needed to get
/// a consistent orienation
if ( facets[i].second%2==0 ) std::swap(indices[0], indices[1]);
pts <<
facets[i].first->vertex(indices[0])->point() << "\n" <<
facets[i].first->vertex(indices[1])->point() << "\n" <<
facets[i].first->vertex(indices[2])->point() << "\n";
ind << "3 " << 3*i << " " << 3*i+1 << " " << 3*i+2 << "\n";
}
std::fstream file;
file.open("./bunnyTest.off");
file << "OFF "<< 3*nbf << " " << nbf << " 0\n";
file << pts.str();
file << ind.str();
return 0;
}
- [cgal-discuss] Alpha_Shapes_3 Bunny, Claudia Werner, 11/25/2013
- Re: [cgal-discuss] Alpha_Shapes_3 Bunny, Mariette Yvinec, 11/26/2013
- Re: [cgal-discuss] Alpha_Shapes_3 Bunny, Daniel Duque, 11/26/2013
- Re: [cgal-discuss] Alpha_Shapes_3 Bunny, Mariette Yvinec, 11/26/2013
Archive powered by MHonArc 2.6.18.