簡體   English   中英

使用OpenMesh遍歷邊緣並獲得頂點

[英]Iterating over edges and getting their vertices with OpenMesh

我開始使用OpenMesh遍歷可能具有整體的網格,並且想知道什么是實際檢索與每個邊緣關聯的頂點的好方法。

對於半邊,有網格的opposite_he_opposite_vhopposite_vh _vh方法,但是如果不存在相反的半邊(我們當前在邊界半邊上),它們會觸發錯誤。

考慮到我會經常遇到這些問題,有什么更好的方法可以遍歷所有邊緣(實際上我並不特別在意半邊,我正在獲取每個邊的數據,但是方向並不重要。需要兩個頂點)嗎?

我認為您可以使用:

  1. MyMesh::to_vertex_handle(MyMesh::HalfedgeHandle)
  2. MyMesh::from_vertex_handle(MyMesh::HalfedgeHandle)

請確認您可以找到以下方法:-)

您想要的可能是以下示例:

for ( mesh_t::EdgeIter eit   = _m.edges_begin(); eit != edgesEnd; ++eit) {
  const MeshType::Point to   = _m.point(_m.to_vertex_handle(_m.halfedge_handle(eit,0)));
  const MeshType::Point from = _m.point(_m.from_vertex_handle(_m.halfedge_handle(eit,0)));
}

其他答案之一對我不起作用b / c迭代器需要取消引用。 這就是我使用OpenMesh 4.1的方法
最佳做法可能有所改變; OpenMesh 6.2現在已經發布,但是我還沒有切換。

MyMesh mesh;    // create the mesh instance
...             // build your mesh

// use an edge iterator to iterate over all the edges
for (MyMesh::EdgeIter eit = mesh.edges_begin(); eit != mesh.edges_end(); ++eit) 
{       
    // check for boundary.  (one halfedge won't be valid if boundary)
    // note: you have to dereference the edge iterator
    if (!mesh.is_boundary(*eit))
    {
        // if you want vertex handles use:
        auto vh1 = mesh.to_vertex_handle(mesh.halfedge_handle(*eit, 0));
        auto vh2 = mesh.from_vertex_handle(mesh.halfedge_handle(*eit, 0));

        // if you want handles of faces adjacent to the edge use:
        auto fh1 = mesh.face_handle(mesh.halfedge_handle(*eit, 0));
        auto fh2 = mesh.opposite_face_handle(mesh.halfedge_handle(*eit, 0));

        // if you need normal vectors of those faces use:
        auto face1Norm = mesh.normal(fh1);
        auto face2Norm = mesh.normal(fh2);
    }
    else  // boundary.  One of the half edges won't be valid
        std::cout << "found a boundary edge.  skipping it" << std::endl;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM