Question

I would like to add N random vertex to a 2D Delaunay triangulation. My code is:

template <class Kernel, class TDS>
class DT : public CGAL::Delaunay_triangulation_2<Kernel,TDS>
{
public:
typedef typename Kernel::FT FT;
typedef typename Kernel::Point_2    Point;
typedef typename CGAL::Delaunay_triangulation_2<Kernel,TDS> Dt2;

// random number between zero and max
FT r(FT max = 1.0) { return max * (FT)rand() / (FT)RAND_MAX; }

void generators_random(unsigned int nb_generators)
{
   Dt2::clear();
   Point p(r(), r());
   for(unsigned int i = 0; i < nb_generators; i++)
        insert(p);
}

But when I call the generators_random method, the compiler gives this error:

/home/lucas/Algorithmes géometriques/TP2/src/dt.h:83:12: note:
cannot convert ‘p’ (type ‘DT<CGAL::Epick,CGAL::Triangulation_data_structure_2
<My_vertex_base<CGAL::Triangulation_vertex_base_2<CGAL::Epick> >, 
CGAL::Triangulation_face_base_2<CGAL::Epick> > >::Point {aka
CGAL::Point_2<CGAL::Epick>}’) to type ‘std::ostream& {aka 
std::basic_ostream<char>&}’ insert(p);

Instead of casting FT, I tried also double, float, but nothing works. What's wrong with it?

Thanks.

Was it helpful?

Solution

I've solved the problem. Instead of using insert(), I used push_back() For the record, this is the working version:

// random number between zero and max
FT r(FT max = 1.0) { return max * (FT)rand() / (FT)RAND_MAX; }

// random (uniform)
void generators_random(unsigned int nb_generators)
{
    Dt2::clear();
    for(unsigned int i = 0; i < nb_generators; i++)
        this->push_back(Point(r(), r()));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top