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;
  selector->SetRenderer(this->Renderer);
  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]);

  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.

I found root case of this problem that is a bug of paraview.
For detail, https://gitlab.kitware.com/paraview/paraview/-/issues/21787#note_1404405

1 Like