参考url:https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CellEdgeNeighbors/
1.根据指定的cellid获取周围cellid信息
void getNeighborCellID(int cellid,vtkPolyData* polydata,QList<int>& neighbors){
vtkSmartPointer<vtkIdList> cellPointIds =
vtkSmartPointer<vtkIdList>::New();
//根据cellID获取顶点索引信息
polydata->GetCellPoints(cellid, cellPointIds);
for(vtkIdType i = 0; i < cellPointIds->GetNumberOfIds(); i++){
vtkSmartPointer<vtkIdList> idList =
vtkSmartPointer<vtkIdList>::New();
idList->InsertNextId(cellPointIds->GetId(i));
//根据是否查找共享顶点或者共享边判断是否注销下面代码
//共享顶点注销
if(i+1 == cellPointIds->GetNumberOfIds()){
idList->InsertNextId(cellPointIds->GetId(0));
}else{
idList->InsertNextId(cellPointIds->GetId(i+1));
}//end
vtkSmartPointer<vtkIdList> neighborCellIds =
vtkSmartPointer<vtkIdList>::New();
polydata->GetCellNeighbors(cellid, idList, neighborCellIds);
for(vtkIdType j = 0; j < neighborCellIds->GetNumberOfIds(); j++)
{
neighbors.push_back(neighborCellIds->GetId(j));
}
}
return;
}
2.根据指定cellid改变颜色
void createSelectCellActor(vtkPolyData* polydata,QList<int>& selectCellId,vtkActor* selectActor){
if(polydata == NULL || selectActor == NULL){
return;
}
vtkSmartPointer<vtkIdTypeArray> ids =
vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);
for(int i=0;i<selectCellId.size();i++){
ids->InsertNextValue(selectCellId.at(i));
}
vtkSmartPointer<vtkSelectionNode> selectionNode =
vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::CELL);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);
// invert the selection
//selectionNode->GetProperties()->Set(vtkSelectionNode::INVERSE(),1);
vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
vtkSmartPointer<vtkExtractSelection> extractSelection =
vtkSmartPointer<vtkExtractSelection>::New();
extractSelection->SetInputData(0, polydata);
extractSelection->SetInputData(1, selection);
extractSelection->Update();
vtkSmartPointer<vtkDataSetMapper> mapper =
vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputConnection(extractSelection->GetOutputPort());
selectActor->SetMapper(mapper);
return;
}