Strange behavior of vtkExtractSelection if extract cell twice in paraview.

I wrote a representation of a source, selecting an area by vtkCommand::LeftButtonReleaseEvent.
In EndWidgetInteraction of representation, the code flow is as below:

  1. Generate an area by vtkCellPicker.
  2. Select cells in area by vtkHardwareSelector.
  3. Extract polydata selected by vtkExtractSelection.
  4. Create a vtkDataSetSurfaceFilter to handle the output of vtkExtractSelection.
  5. Create relative mapper and actor from output of vtkDataSetSurfaceFilter.
  6. 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;
  unsigned int size[4];
  size[0] = std::min(this->startScreenPos[0], this->endScreenPos[0]);
  size[1] = std::min(this->startScreenPos[1], this->endScreenPos[1]);
  size[2] = std::max(this->startScreenPos[0], this->endScreenPos[0]);
  size[3] = std::max(this->startScreenPos[1], this->endScreenPos[1]);

  vtkSelection* selection = selector->Select();

  vtkNew<vtkExtractSelection> visibleExtractSelection;
  visibleExtractSelection->SetInputData(0, this->pickPolydata);
  visibleExtractSelection->SetInputData(1, selection);

  vtkNew<vtkDataSetSurfaceFilter> surfaceFilter;
  vtkSmartPointer<vtkPolyData> selectedPolyData = surfaceFilter->GetOutput();

  selectedActor->GetProperty()->SetColor(1, 0, 0);

Below is the result of first select.

Below is the result of second select.

I found root case of this problem that is a bug of paraview.
For detail,

1 Like