# vtkCellPicker very slow

**URL:** https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881
**Category:** Web
**Created:** [October 7, 2019, 4:27pm UTC](https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881 "2019-10-07T16:27:19Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![EmileSonneveld](https://discourse.vtk.org/user_avatar/discourse.vtk.org/emilesonneveld/32/939_2.png) [@EmileSonneveld](https://discourse.vtk.org/u/EmileSonneveld)
#### Post date: [October 7, 2019, 4:27pm UTC](https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881/1 "2019-10-07T16:27:19Z")

</div>

Hi,

I am implementing some point picking on a mesh with 127000 triangles. I’d love to pick points on the mesh while the user is interacting, but picking can take up to 300ms.  
I tried with a mesh of similar size in three.js and there picking only takes 30ms.

Is there something I do wrong in the code? How can I improve performance?

```
   function cellPickOnActors(renderer, actorsToPickOn, point) {
           // Caching the picker has no performance gain
           // Ephemeral, short lived, picker
           let pointPicker = pointPicker = vtkCellPicker.newInstance(); // Alternative: vtkPointPicker
           pointPicker.setPickFromList(1);
           pointPicker.initializePickList();
           pointPicker.setTolerance(0) // https://discourse.vtk.org/t/cellpicker-example-glitch/1852
           console.assert(Array.isArray(actorsToPickOn))
           actorsToPickOn.forEach(actor => {
               pointPicker.addPickList(actor);
           });
           pointPicker.pick(point, renderer);
           return pointPicker;
       }

```

Warm greetings,  
Emile Sonneveld

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 7, 2019, 7:52pm UTC](https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881/2 "2019-10-07T19:52:01Z")

</div>

The vtkCellPicker has a method called [AddLocator()](https://vtk.org/doc/nightly/html/classvtkCellPicker.html#aa1badc20201bb8e5fcae2f5919f0b1d0) for providing a [vtkCellLocator](https://vtk.org/doc/nightly/html/classvtkCellLocator.html) that can accelerate the search.

The basic usage is:

- create a vtkCellLocator
- use SetDataSet() to put your data into the locator
- call Update() on the locator
- add the locator to the picker

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [October 7, 2019, 9:47pm UTC](https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881/3 "2019-10-07T21:47:01Z")

</div>

We don’t have a cellLocator in vtk.js. We do have a hardware selector that allow point picking but not yet cell picking (if I recall correctly). And that one is fast as it is using the pixel of the rendering which is probably what three.js is doing.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [October 7, 2019, 9:54pm UTC](https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881/4 "2019-10-07T21:54:08Z")

</div>

vtkCellPicker is indeed relatively slow but there are many other pickers in VTK. Hardware-accelerated pickers can be magnitudes faster but they have other limitations (they rely on z buffer, so transparency may cause problems).

---

<div class="post-metadata">

### Author: ![EmileSonneveld](https://discourse.vtk.org/user_avatar/discourse.vtk.org/emilesonneveld/32/939_2.png) [@EmileSonneveld](https://discourse.vtk.org/u/EmileSonneveld)
#### Post date: [October 8, 2019, 7:45am UTC](https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881/5 "2019-10-08T07:45:08Z")

</div>

Thanks for the replys. It seems that in VTK.js, the locators are not implemented yet.

The hardware point picker sounds interesting, but I can’t find it in VTK.js. Anyone knows how to use it?

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [October 8, 2019, 3:51pm UTC](https://discourse.vtk.org/t/vtkcellpicker-very-slow/1881/6 "2019-10-08T15:51:12Z")

</div>

Here are some of its usage throughout the code:

- [https://github.com/Kitware/vtk-js/tree/master/Sources/Rendering/OpenGL/HardwareSelector/test](https://github.com/Kitware/vtk-js/tree/master/Sources/Rendering/OpenGL/HardwareSelector/test)
- Widgets
  - [https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L61-L64](https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L61-L64)
  - [https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L184-L201](https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L184-L201)
  - [https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L343-L347](https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L343-L347)
  - [https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L361-L396](https://github.com/Kitware/vtk-js/blob/master/Sources/Widgets/Core/WidgetManager/index.js#L361-L396)

HTH
