Search code examples
c++meshcgaltriangulationdata-extraction

Getting -6.27744e+66 for vertex coordinate from CGAL 3D Mesh Generation: mesh_implicit_sphere example


I am extracting facet data from the generated mesh from the example code mentioned in the title with:

 vector<CGAL::Mesh_complex_3_in_triangulation_3<Tr>::Facet_iterator> Facets;
    for (CGAL::Mesh_complex_3_in_triangulation_3<Tr>::Facet_iterator it = c3t3.facets_begin(); it!=c3t3.facets_end() ; it++)
    {
        Facets.push_back(it);
    }

and now trying to display some vertex coordinate as below:

CGAL::Mesh_complex_3_in_triangulation_3<Tr>::Facet_iterator fct = Facets[0];
cout << "Vertex 0 has coordinate: \n";
    cout << fct->first->vertex(0)->point().x() << ", " 
        << fct->first->vertex(0)->point().y() << ", "
        << fct->first->vertex(0)->point().z() << endl<<endl; 

    cout<< "Vertex 1 has coordinate: \n";
    cout << fct->first->vertex(1)->point().x() << ", "
        << fct->first->vertex(1)->point().y() << ", "
        << fct->first->vertex(1)->point().z() << endl<<endl;

    cout << "Vertex 2 has coordinate: \n";
    cout << fct->first->vertex(2)->point().x() << ", "
        << fct->first->vertex(2)->point().y() << ", "
        << fct->first->vertex(2)->point().z() << endl<<endl;

    cout << "Vertex 3 has coordinate: \n";
    cout << fct->first->vertex(3)->point().x() << ", "
        << fct->first->vertex(3)->point().y() << ", "
        << fct->first->vertex(3)->point().z() << endl<<endl<<endl;

(Assuming I understand the data structure correctly)fct points to a std::pair comprising(c,i) which means: the facet denoted by fct in the cell c and the vertex indexed i both belong to cell c, and they satisfy: fct is opposite to vertex i. So my code should display vertex coordinates of the cell fct->first(it's a tetrahedron thus has four vertices).

Here is my Question

The output of the above code is:

Vertex 0 has coordinate: 0.282254, -0.638274, -0.716464

Vertex 1 has coordinate: 0.408885, -0.669831, -0.621398

Vertex 2 has coordinate: 0.24175, -0.741988, -0.625771

Vertex 3 has coordinate: -6.27744e+66, -6.27744e+66, -6.27744e+66

Vertex3's coordinate is obviously not right, and I have searched about this problem finding that -6.27744e+66 usually comes from something liking accessing uninitialized vectors. But even if this is the case, what should I do to get the correct value? Or, could anybody tell me where exactly went wrong?


Solution

  • The vertex 3 is most probably the infinite vertex. In CGAL triangulations are represented using an extra infinite vertex that is connected to all the points on the convex hull. You can use the function is_infinite() to check that.

    As pointed by Alex, you should use a Cell_in_complex_iterator to access all the finite cells of the meshed domain.