简体   繁体   English

在2D Delaunay三角剖分中插入顶点时出错

[英]Error inserting a vertex in a 2D Delaunay triangulation

I would like to add N random vertex to a 2D Delaunay triangulation. 我想将N个随机顶点添加到2D Delaunay三角剖分中。 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: 但是,当我调用generators_random方法时,编译器会出现以下错误:

/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. 除了尝试使用FT,我还尝试了double,float,但没有任何效果。 What's wrong with it? 它出什么问题了?

Thanks. 谢谢。

I've solved the problem. 我已经解决了问题。 Instead of using insert() , I used push_back() For the record, this is the working version: 我没有使用insert() ,而是使用push_back()进行记录,这是工作版本:

// 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()));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM