#include <iostream>
using namespace std;
#include <vtkCellArray.h>
#include <vtkIdList.h>
#include <vtkNew.h>
#include <vtkPolyData.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++)
{
auto pointId = pointIdList->GetId(p);
auto point = triangle->GetPoints()->GetPoint(pointId);
std::cout << "Edge " << i << " uses point " << pointIdList->GetId(p)
<<" [" << point[0] << ", " << point[1] << ", " << point[2] << "]"
<< std::endl;
}
}
return EXIT_SUCCESS;
}
输出:
The cell has 3 edges.
Edge 0 has 2 points.
Edge 0 uses point 0 [1, 0, 0]
Edge 0 uses point 1 [0, 0, 0]
Edge 1 has 2 points.
Edge 1 uses point 1 [0, 0, 0]
Edge 1 uses point 2 [0, 1, 0]
Edge 2 has 2 points.
Edge 2 uses point 2 [0, 1, 0]
Edge 2 uses point 0 [1, 0, 0]
本文详细探讨了在C++中使用vtkTriangle库进行三角形处理的方法,包括其原理和应用示例。
1826

被折叠的 条评论
为什么被折叠?



