在2D三角测量中添加约束时出错

时间:2014-03-05 14:22:28

标签: c++ triangulation cgal

我有一些2D约束三角测量。当我添加约束时发生错误。这是我使用它的简单示例:

#include "stdafx.h"

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Constrained_triangulation_plus_2.h>
#include <vector>
#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K>                     Vb;
typedef CGAL::Constrained_triangulation_face_base_2<K>           Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb>              TDS;
typedef CGAL::Exact_predicates_tag                               Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> CDT;
typedef CGAL::Constrained_triangulation_plus_2<CDT> CDTPlus;
typedef CDT::Constraint Constraint; 

typedef std::vector<Constraint> Constraints;

void load_data(const char* filename, Constraints &c)
{   
    std::fstream stream(filename, std::ios::in | std::ios::binary);     
    stream.seekp(0, std::fstream::end);
    std::streamoff size = stream.tellp() / sizeof(Constraint);
    stream.seekp(0, std::fstream::beg);
    c.resize((size_t)size); 
    stream.read(reinterpret_cast<char *>(&c.front()), sizeof(Constraint) * size);
}

int _tmain(int argc, _TCHAR* argv[])
{   
    Constraints c;
    load_data("e:\\data.bin", c);

    CDTPlus cdt;
    // when i == 53376 - error      
    for (size_t i = 0; i < c.size(); ++i)       
        cdt.insert_constraint(c[i].first, c[i].second);         
    return 0;
}

这是我的data.bin文件data.bin 那是我的项目link

1 个答案:

答案 0 :(得分:0)

模板类CGAL::Constrained_Delaunay_triangulation_2有三个模板参数。第三个ITag的默认参数为CGAL::No_intersection_tag。这意味着不处理约束的交叉点。

可能你的输入约束确实相交了。