# Strange behavior of vtkExtractSelection if extract cell twice in paraview.

**URL:** https://discourse.paraview.org/t/strange-behavior-of-vtkextractselection-if-extract-cell-twice-in-paraview/12695
**Category:** Development
**Created:** [August 14, 2023, 6:30am UTC](https://discourse.paraview.org/t/strange-behavior-of-vtkextractselection-if-extract-cell-twice-in-paraview/12695 "2023-08-14T06:30:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ironskinghost](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/i/f1d935/32.png) [@ironskinghost](https://discourse.paraview.org/u/ironskinghost)
#### Post date: [August 14, 2023, 6:30am UTC](https://discourse.paraview.org/t/strange-behavior-of-vtkextractselection-if-extract-cell-twice-in-paraview/12695/1 "2023-08-14T06:30:43Z")

</div>

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:

```c++
  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.

 ![1](https://discourse.paraview.org/uploads/default/original/2X/a/ae48ec6d693500071471013254ef0d25a31cf4d0.png)

Below is the result of second select.

 ![2](https://discourse.paraview.org/uploads/default/original/2X/5/594ab7b1a6bee3a60b48117369eaeb3e6d10e628.png)

---

<div class="post-metadata">

### Author: ![ironskinghost](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/i/f1d935/32.png) [@ironskinghost](https://discourse.paraview.org/u/ironskinghost)
#### Post date: [August 24, 2023, 12:44am UTC](https://discourse.paraview.org/t/strange-behavior-of-vtkextractselection-if-extract-cell-twice-in-paraview/12695/2 "2023-08-24T00:44:50Z")

</div>

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](https://gitlab.kitware.com/paraview/paraview/-/issues/21787#note_1404405)
