我想在模型中选择视点ID(这是一个bdf文件,并显示使用unstructuregrid)。我复制一个人的代码。但是我无法使用vtkHardwareSelector获取数据。我不知道为什么。
使用vtk8.2; vtkInteractorStyleRubberBandPick和vtkHardwareSelector。
void vtkRubberBandPickInteractorStyle::OnLeftButtonUp()
{
vtkSmartPointer<vtkWarpVector> warpVector = vtkSmartPointer<vtkWarpVector>::New();
warpVector->SetInputData(m_Grid);
// Forward events
vtkInteractorStyleRubberBandPick::OnLeftButtonUp();
int* posUp = this->GetInteractor()->GetEventPosition();
SetEndPos(posUp);
vtkSmartPointer<vtkHardwareSelector> selector = vtkSmartPointer<vtkHardwareSelector>::New();
selector->SetRenderer(this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
unsigned int windowSize[4]
windowSize[0] = m_StartPosition[0] < m_EndPosition[0] ? m_StartPosition[0] : m_EndPosition[0]; // xmin
windowSize[1] = m_StartPosition[1] < m_EndPosition[1] ? m_StartPosition[1] : m_EndPosition[1]; // ymin
windowSize[2] = m_StartPosition[0] < m_EndPosition[0] ? m_EndPosition[0] : m_StartPosition[0]; // xmax
windowSize[3] = m_StartPosition[1] < m_EndPosition[1] ? m_EndPosition[1] : m_StartPosition[1]; // ymax
selector->SetArea(windowSize);
selector->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_CELLS);
selector->CaptureBuffers();
vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New();
selection = selector->GenerateSelection();
vtkSmartPointer<vtkExtractSelection> extractSelection = vtkSmartPointer<vtkExtractSelection>::New();
extractSelection->SetInputData(selection);
extractSelection->Update();
vtkSmartPointer<vtkUnstructuredGrid> selected1 = vtkSmartPointer<vtkUnstructuredGrid>::New();
selected1->ShallowCopy(extractSelection->GetOutput());
vtkSmartPointer<vtkPolyData> selected2 = vtkSmartPointer<vtkPolyData>::New();
selected2->ShallowCopy(extractSelection->GetOutput());
vtkIdType type = selected2->GetNumberOfCells();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(selected2);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetPointSize(10.0);
actor->GetProperty()->SetColor(1,0,0);
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(actor);
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->Render();
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
vtkIdType type = selected2->GetNumberOfCells();
该值为0;所以我找不到选择的任何数据。