MPA
MPA

Reputation: 2038

CGAL Triangulation edge iterator includes origin

I'm currently learning to perform 3D triangulation using CGAL, and so far I've managed to create a regular tetrahedron by inserting and triangulating 4 vertices. But when I try to loop over the edges of the tetrahedron and obtain the vertices corresponding to that edge, I get the origin as a vertex or duplicates of previous edges. In 2D it all works fine, but in 3D things go wrong. I think this is related to an infinite/undefined vertex being included, but I don't know how to deal with this. Any help would be appreciated.

My code (modified from 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;
}

Upvotes: 1

Views: 527

Answers (1)

sloriot
sloriot

Reputation: 6263

The documentation for an edge indicates that it's a triple: (c,i,j) is the edge of cell c whose vertices indices are i and j.

So in your code you should write:

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

Upvotes: 2

Related Questions