【问题标题】:CGAL Triangulation edge iterator includes originCGAL 三角剖分边迭代器包括原点
【发布时间】:2016-06-23 16:48:54
【问题描述】:

我目前正在学习使用 CGAL 执行 3D 三角剖分,到目前为止,我已经设法通过插入和三角剖分 4 个顶点来创建一个正四面体。但是当我尝试遍历四面体的边缘并获得与该边缘相对应的顶点时,我将原点作为顶点或先前边缘的副本获得。在 2D 中一切正常,但在 3D 中出现问题。我认为这与包含的无限/未定义顶点有关,但我不知道如何处理。任何帮助将不胜感激。

我的代码(修改自this question):

#include <vector>
#include <iostream>
#include <cmath>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_3<K> Delaunay;
typedef K::Point_3 Point;

 void load_points(std::vector<Point>& rPoints)
 {
  rPoints.push_back(Point(1.0, 0.0, -1.0/sqrt(2)));   // first point
  rPoints.push_back(Point(-1.0, 0.0, -1.0/sqrt(2)));   // second point
  rPoints.push_back(Point(0.0, 1.0, 1.0/sqrt(2)));   // third point
  rPoints.push_back(Point(0.0, -1.0, 1.0/sqrt(2)));   // fourth point
 }

int main()
{
 std::vector<Point> points;
 load_points(points);

 Delaunay dt;
 dt.insert(points.begin(),points.end());

 for(Delaunay::Finite_edges_iterator it = dt.finite_edges_begin(); it != dt.finite_edges_end(); ++it)
 {
   Point i1= it->first->vertex( (it->second+1)%3 )->point();
   Point i2= it->first->vertex( (it->second+2)%3 )->point();
   std::cout << "i1: " << i1 << "\t i2: " << i2 << "\n";
  }

  return 0;
}

【问题讨论】:

    标签: c++ cgal


    【解决方案1】:

    edge 的文档表明它是三元组:(c,i,j) 是单元格 c 的边缘,其顶点索引为 i 和 j。

    所以在你的代码中你应该写:

    Point i1= it->first->vertex(it->second)->point(); 点 i2= it->first->vertex(it->third)->point();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 2012-03-29
      • 2014-07-12
      • 2019-09-21
      相关资源
      最近更新 更多