从CGAL 3D网格生成获取顶点坐标的-6.27744e + 66:mesh_implicit_sphere示例

问题描述 投票:0回答:1

我正在使用标题中提到的示例代码从生成的网格中提取构面数据:

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

现在尝试如下显示一些顶点坐标:

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;

(假设我正确理解了数据结构)fct指向包含(c,i)的std :: pair,这意味着:单元c中以fct表示的面和索引为i的顶点都属于单元c,它们满足:fct与顶点i相反。因此,我的代码应显示单元格fct-> first的顶点坐标(这是一个四面体,因此具有四个顶点)。

[这是我的问题

以上代码的输出是:

顶点0具有坐标:0.282254,-0.638274,-0.716464

顶点1具有坐标:0.408885,-0.669831,-0.621398

顶点2具有坐标:0.24175,-0.741988,-0.625771

顶点3具有坐标:-6.27744e + 66,-6.27744e + 66,-6.27744e + 66

Vertex3的坐标显然不正确,我搜索了这个问题,发现-6.27744e + 66通常来自喜欢访问未初始化矢量的事物。但是,即使是这种情况,我应该怎么做才能获得正确的值?或者,有人可以告诉我哪里出了问题吗?

c++ mesh cgal triangulation data-extraction
1个回答
0
投票

您正在使用在网格的二维小平面(即三角形)上进行迭代的小平面迭代器。如果要迭代四面体,请使用Cell_iterator。

请参见有关迭代器here的部分。

© www.soinside.com 2019 - 2024. All rights reserved.