I wrote a representation of a source, selecting an area by vtkCommand::LeftButtonReleaseEvent.
In EndWidgetInteraction of representation, the code flow is as below:
- Generate an area by vtkCellPicker.
- Select cells in area by vtkHardwareSelector.
- Extract polydata selected by vtkExtractSelection.
- Create a vtkDataSetSurfaceFilter to handle the output of vtkExtractSelection.
- Create relative mapper and actor from output of vtkDataSetSurfaceFilter.
- Set color of actor as red.
The code worked fine when selected area by mouse firstly.
If selected secondly, it made a chaos result.
The strange is that it worked perfect every times, if I selected “surface with edges” mode for base model in properties panel.
In addition, the code works fine in pure vtk program too.
Can someone show me the root cause of this problem? Thanks a lot.
Core code is as below:
vtkNew<vtkHardwareSelector> selector; selector->SetRenderer(this->Renderer); unsigned int size; size = std::min(this->startScreenPos, this->endScreenPos); size = std::min(this->startScreenPos, this->endScreenPos); size = std::max(this->startScreenPos, this->endScreenPos); size = std::max(this->startScreenPos, this->endScreenPos); selector->SetArea(size); selector->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_CELLS); vtkSelection* selection = selector->Select(); vtkNew<vtkExtractSelection> visibleExtractSelection; visibleExtractSelection->SetInputData(0, this->pickPolydata); visibleExtractSelection->SetInputData(1, selection); visibleExtractSelection->Update(); vtkNew<vtkDataSetSurfaceFilter> surfaceFilter; surfaceFilter->SetInputConnection(visibleExtractSelection->GetOutputPort()); surfaceFilter->Update(); vtkSmartPointer<vtkPolyData> selectedPolyData = surfaceFilter->GetOutput(); selectedMapper->SetInputData(selectedPolyData); selectedMapper->Update(); selectedActor->SetMapper(selectedMapper); selectedActor->GetProperty()->SetColor(1, 0, 0);
Below is the result of first select.
Below is the result of second select.