如何在 VTK 中直接访问多边形?
How to get direct access to polygons in VTK?
我发现 this post online(可追溯到 2013 年),当时我无法直接访问 vtkPolyData
中的特定单元格。我使用的是最新版本:VTK 8.1.1
似乎较新版本的 VTK 仍然存在此问题。
polys->InitTraversal();
for(int i = 0; i < polys->GetNumberOfCells(); i++)
{
polys->GetNextCell(idList); // This sequential method gets the point IDs correctly
int a = idList->GetId(0);
int b = idList->GetId(1);
int c = idList->GetId(2);
}
不过,直接访问方式好像有问题
polys->InitTraversal();
for(int i = 0; i < polys->GetNumberOfCells(); i++)
{
polys->GetCell(i, idList); // This method returns wrong ids
int a = idList->GetId(0);
int b = idList->GetId(1);
int c = idList->GetId(2);
}
如何在不遍历所有单元格的情况下获取特定单元格中的点 ID? polys->GetCell(i, idList)
不是要让您直接访问特定的单元格吗?
对于直接访问,我们可以使用vtkPolyData::GetCellPoints()方法。例如我们可以做
vtkNew<vtkIdList> idL; // or auto idL = vtkSmartPointer<vtkIdList>::New();
poly->GetCellPoints( 13, idL ); // Assuming you want the points for 13th cell
for(auto i = 0; i < idL->GetNumberOfIds(); ++i)
std::cout<< idL->GetId(i) << std::endl;
为了遍历所有单元格,我更喜欢 while
循环:
vtkNew<vtkIdList> idL;
poly->GetPolys()->InitTraversal();
while(poly->GetPolys()->GetNextCell(idL)){
for(auto i = 0; i < idL->GetNumberOfIds(); ++i)
std::cout<< idL->GetId(i) << std::endl;
}
我发现 this post online(可追溯到 2013 年),当时我无法直接访问 vtkPolyData
中的特定单元格。我使用的是最新版本:VTK 8.1.1
似乎较新版本的 VTK 仍然存在此问题。
polys->InitTraversal();
for(int i = 0; i < polys->GetNumberOfCells(); i++)
{
polys->GetNextCell(idList); // This sequential method gets the point IDs correctly
int a = idList->GetId(0);
int b = idList->GetId(1);
int c = idList->GetId(2);
}
不过,直接访问方式好像有问题
polys->InitTraversal();
for(int i = 0; i < polys->GetNumberOfCells(); i++)
{
polys->GetCell(i, idList); // This method returns wrong ids
int a = idList->GetId(0);
int b = idList->GetId(1);
int c = idList->GetId(2);
}
如何在不遍历所有单元格的情况下获取特定单元格中的点 ID? polys->GetCell(i, idList)
不是要让您直接访问特定的单元格吗?
对于直接访问,我们可以使用vtkPolyData::GetCellPoints()方法。例如我们可以做
vtkNew<vtkIdList> idL; // or auto idL = vtkSmartPointer<vtkIdList>::New();
poly->GetCellPoints( 13, idL ); // Assuming you want the points for 13th cell
for(auto i = 0; i < idL->GetNumberOfIds(); ++i)
std::cout<< idL->GetId(i) << std::endl;
为了遍历所有单元格,我更喜欢 while
循环:
vtkNew<vtkIdList> idL;
poly->GetPolys()->InitTraversal();
while(poly->GetPolys()->GetNextCell(idL)){
for(auto i = 0; i < idL->GetNumberOfIds(); ++i)
std::cout<< idL->GetId(i) << std::endl;
}