Kien Nguyen
Kien Nguyen

Reputation: 11

My cgal code 3d delaunay triangulation wrong

I pass in the point to get triangulate and spit out cell data. But the value spit back is wrong as the cell data is violate the principle of triangulation.

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

// ---- Expect ---- As you see up there. I have 5 point (-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). So if it spit out correctly, I will likely be two cell with vertex at index of (0, 1,2,3) and (0,1,2,4).

// ----- Result ---- But some how it split out wrong ( 0, 1, 2, 3) and (0,1,3,4). If I reduce the z of 3 and 4 down to 300 and -300 it spit out 3 cell. ( 0, 1, 2, 3), (4, 0, 2, 3) and (1, 4, 2, 3).

//------ update 1.----

So I change the way of extract the vertex. I convert directly from itCell->vertext->point() and I get the vertex I think correctly. But it still give me lot of cell that intersect with other cell. I thought the set supposed to be unique and not intersect with other cell.

Upvotes: 0

Views: 317

Answers (1)

sloriot
sloriot

Reputation: 6303

As documented here, this function is not guaranteed to insert the points following the order of PointInputIterator. You better use this example if you want to set indices that match your input. This one works too.

The doc of the corresponding function is here.

Upvotes: 2

Related Questions