【问题标题】:My cgal code 3d delaunay triangulation wrong我的 cgal 代码 3d delaunay 三角测量错误
【发布时间】:2019-11-02 14:40:53
【问题描述】:

我通过点来进行三角测量并吐出单元格数据。但是返回的值是错误的,因为单元格数据违反了三角测量原则。

   typedef CGAL::Exact_predicates_exact_constructions_kernel K; 
   typedef CGAL::Delaunay_triangulation_3<K> Delaunay; 

   std::vector<K::Point_3> points; 
   std::map<Delaunay::Vertex_handle, int> index_of_vertex; 


   points.push_back(K::Point_3(-400.0, 0.0, 0.0)); 
   points.push_back(K::Point_3(200, 400.0, 0.0)); 
   points.push_back(K::Point_3(200, -400.0, 0.0)); 
   points.push_back(K::Point_3(0.0, 0.0, 600.0)); 
   points.push_back(K::Point_3(0.0, 0.0, -600.0)); 

   //And here I push the vector to Delaunay 
   Delaunay dt(points.begin(), points.end()); 

   // Keep track of vertex used 
   for (Delaunay::Finite_vertices_iterator it = t.finite_vertices_begin(); it != dt.finite_vertices_end(); ++it, ++j) 
    { 
        index_of_vertex[it.base()] = j; 
    } 

   // Iterate though and extract vertex and index in cell. 
   for (Delaunay::Finite_cells_iterator itCell = it.finite_cells_begin(), itend = dt.finite_cells_end();              itCell != itend; itCell++) 
    { 
        vector<double> verts; 
        vector<int> indx; 

        int ind0 = index_of_vertex[itCell->vertex(0)]; 
        int ind1 = index_of_vertex[itCell->vertex(1)]; 
        int ind2 = index_of_vertex[itCell->vertex(2)]; 
        int ind3 = index_of_vertex[itCell->vertex(3)]; 

        K::Point_3 v0 = points[ind0]; 
        K::Point_3 v1 = points[ind1]; 
        K::Point_3 v2 = points[ind2]; 
        K::Point_3 v3 = points[ind3]; 

        // Store the vertex 
        verts.push_back(CGAL::to_double(v0.x())); 
        ... 
        verts.push_back(CGAL::to_double(v3.z())); 

        // extract the index 
        int ind00 = Delaunay::vertex_triple_index(0, 0); 
        ... 
        int ind32 = Delaunay::vertex_triple_index(3, 2); 

        // Store the index 
        indx.push_back(ind00); 
        ... 
        indx.push_back(ind32); 
  }

// ---- 期待 ---- 正如你在上面看到的那样。我有 5 个点 (-400.0, 0.0, 0.0), (200, 400.0, 0.0), (200, -400.0, 0.0), (0.0, 0.0, 600.0), (0.0, 0.0, -600.0)。 因此,如果它正确吐出,我可能会是两个单元格,其顶点位于索引处 (0, 1,2,3) 和 (0,1,2,4)。

// ----- 结果 ---- 但是有些方法是错误的(0,1,2,3)和(0,1,3,4)。如果我减少 z 的 3 和 4 下降到 300 和 -300 它吐出 3 个细胞。 ( 0, 1, 2, 3), (4, 0, 2, 3) 和 (1, 4, 2, 3)。

//-----更新1.----

所以我改变了提取顶点的方式。我直接从 itCell->vertext->point() 转换,我得到了我认为正确的顶点。但它仍然给了我很多细胞 与其他单元格相交。我认为该集合应该是唯一的,并且不与其他单元格相交。

【问题讨论】:

    标签: 3d cgal delaunay


    【解决方案1】:

    正如here 所记录的,此函数不能保证按照 PointInputIterator 的顺序插入点。如果要设置与输入匹配的索引,最好使用this exampleThis one 也可以。

    对应函数的doc是here

    【讨论】:

    • 所以在推送到 delaunay 对象之前,您必须以某种方式对点进行排序?顺便说一句,我想要 3d delaunay。那么这个二维码会以同样的方式工作吗?
    • 排序确实在内部完成以加快插入速度。 3D 也一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 2014-03-18
    • 2014-12-23
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多