Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Bug in "find_optimal_alpha" function of the class "Alpha_shape_2"

Subject: CGAL users discussion list

List archive

[cgal-discuss] Bug in "find_optimal_alpha" function of the class "Alpha_shape_2"


Chronological Thread 
  • From: Benoît Presles <>
  • To:
  • Subject: [cgal-discuss] Bug in "find_optimal_alpha" function of the class "Alpha_shape_2"
  • Date: Fri, 30 Jul 2010 14:25:41 +0200

Hello Everybody,

I use the latest version of CGAL and I think a bug could be present in the function "find_optimal_alpha" of the class "Alpha_shape_2".
- First, I use the function "find_optimal_alpha" to find the best alpha to get 1 connected component.
- Second, I set this alpha.
- Third, I use the function "number_of_solid_components" to get the number of solid components of A.

Sometimes, the program gives me 2 connected components instead of 1.

Attached, you can fine the c++ code (basically the same as in the example) and a list of points for which the program doesn't work as expected.


Thank you for your help,
Best Regards,
Ben_P
10
0.5144 0.5341
0.8843 0.0900
0.5880 0.1117
0.1548 0.1363
0.1999 0.6787
0.4070 0.4952
0.7487 0.1897
0.8256 0.4950
0.7900 0.1476
0.3185 0.0550
/***********************************************************************

Takes a list of points and returns a list of segments corresponding to the
Alpha shape.

************************************************************************/

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/algorithm.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Alpha_shape_2.h>

#include <iostream>
#include <fstream>
#include <vector>
#include <list>


typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

typedef K::FT FT;

typedef K::Point_2 Point;
typedef K::Segment_2 Segment;


typedef CGAL::Alpha_shape_vertex_base_2<K> Vb;
typedef CGAL::Alpha_shape_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Triangulation_2;

typedef CGAL::Alpha_shape_2<Triangulation_2> Alpha_shape_2;

typedef Alpha_shape_2::Face Face;
typedef Alpha_shape_2::Vertex Vertex;
typedef Alpha_shape_2::Edge Edge;
typedef Alpha_shape_2::Face_handle Face_handle;
typedef Alpha_shape_2::Vertex_handle Vertex_handle;

typedef Alpha_shape_2::Face_circulator Face_circulator;
typedef Alpha_shape_2::Vertex_circulator Vertex_circulator;

typedef Alpha_shape_2::Locate_type Locate_type;

typedef Alpha_shape_2::Face_iterator Face_iterator;
typedef Alpha_shape_2::Vertex_iterator Vertex_iterator;
typedef Alpha_shape_2::Edge_iterator Edge_iterator;
typedef Alpha_shape_2::Edge_circulator Edge_circulator;

typedef Alpha_shape_2::Alpha_iterator Alpha_iterator;
typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator;

//---------------------------------------------------------------------

template <class OutputIterator>
void
alpha_edges( const Alpha_shape_2& A,
OutputIterator out)
{

for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin();
it != A.alpha_shape_edges_end();
++it){
*out++ = A.segment(*it);
}
}

template <class OutputIterator>
bool
file_input(OutputIterator out)
{
std::ifstream is("./fin", std::ios::in);

if(is.fail()){
std::cerr << "unable to open file for input" << std::endl;
return false;
}

int n;
is >> n;
std::cout << "Reading " << n << " points from file" << std::endl;
CGAL::copy_n(std::istream_iterator<Point>(is), n, out);

return true;
}

//------------------ main -------------------------------------------

int main()
{
std::list<Point> points;
if(! file_input(std::back_inserter(points))){
return -1;
}

Alpha_shape_2 A(points.begin(), points.end(),
FT(10000),
Alpha_shape_2::REGULARIZED);

Alpha_iterator optAlpha = A.find_optimal_alpha(1);
std::cout << "Optimal alpha: " << *optAlpha<<std::endl;
A.set_alpha(*optAlpha);
std::cout<<A.number_of_solid_components()<<std::endl;

return 0;
}



Archive powered by MHonArc 2.6.16.

Top of Page