CGAL 2D alpha contour

My problem is probably new to the C ++ CGAL library, but a task that I hide all the time. Namely, I want to find the alpha shape of a set of points, but I don't seem to understand the iterators available for 2D alpha shapes.

This is what I tried:

Alpha_shape_2 alpha(pointsVec.begin(), pointsVec.end(), FT(1000), Alpha_shape_2::GENERAL);
//which compiles nicely and provides the regular output where pointsVec is the list of Point_2

//Then I saw the edge iterator at the CGAL documentation

template <class OutputIterator> //Method-iterator for CGAL alpha shapes in order to get the edges from alpha shape object
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);
    }
}

//Then when using the following code:

std::vector<Segment> segments;
alpha_edges(alpha, std::back_inserter(segments));

//I get the list of all the edges in the triangulation used for alpha shapes.

      

The thing is, I need a border like in the following graph (obtained with the R alphahull library)

Alphahull

Instead, I get the edges of the triangulation in the segment vector. Another thing I've tried is using vertex iterators:

for (Alpha_shape_2::Alpha_shape_vertices_iterator it = alpha.Alpha_shape_vertices_begin(); it != alpha.Alpha_shape_vertices_end(); ++it)
      {
          int xalpha = (*it)->point().x();
          int yalpha = (*it)->point().y();
          alphaCoords.push_back(cv::Point(xalpha, yalpha)); //this for openCV
      }

      

but the result is the same. It outputs all the vertices so that the drawing only connects them, without an outline (draw lines on the image).

I know there is a function for 3D to find the vertices of a boundary shape:

as.get_alpha_shape_vertices(back_inserter(al_vs), Alpha_shape_3::REGULAR); 

      

but it doesn't exist for 2D. Also I'm curious to know where you can specify the alpha value used for the radius of the circular circle, for example in the Windows demo provided in the 2D CGAL Shapes tutorial. In the meantime, there is no need to worry about it.

+3


source to share


1 answer


Alpha_shape_edges_iterator gives you edges that are not EXTERIOR. You are probably interested in REGULAR and SINGULAR edge.



Look Classification_type

and at classify

to filter out the edges.

+3


source







All Articles