ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

获取对象边及边对应的顶点索引

2026/8/12 2:45:54 拓冰建站 浏览量
获取对象边及边对应的顶点索引

开发环境:

  1. Windows 11 家庭中文版
  2. Microsoft Visual Studio Community 2019
  3. VTK-9.3.0.rc0
  4. vtk-example

demo解决问题:获取对象边及边对应的顶点索引


prj name: CellEdges

#include <vtkIdList.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkTriangle.h>int main(int, char*[])
{vtkNew<vtkTriangle> triangle;triangle->GetPoints()->SetPoint(0, 1.0, 0.0, 0.0);triangle->GetPoints()->SetPoint(1, 0.0, 0.0, 0.0);triangle->GetPoints()->SetPoint(2, 0.0, 1.0, 0.0);triangle->GetPointIds()->SetId(0, 0);triangle->GetPointIds()->SetId(1, 1);triangle->GetPointIds()->SetId(2, 2);std::cout << "The cell has " << triangle->GetNumberOfEdges() << " edges."<< std::endl;for (vtkIdType i = 0; i < triangle->GetNumberOfEdges(); i++){vtkCell* edge = triangle->GetEdge(i);vtkIdList* pointIdList = edge->GetPointIds();std::cout << "Edge " << i << " has " << pointIdList->GetNumberOfIds()<< " points." << std::endl;for (vtkIdType p = 0; p < pointIdList->GetNumberOfIds(); p++){std::cout << "Edge " << i << " uses point " << pointIdList->GetId(p)<< std::endl;}}return EXIT_SUCCESS;
}