# vtkPointPicker very slow

**URL:** https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507
**Category:** Support
**Created:** [December 27, 2021, 1:17pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507 "2021-12-27T13:17:54Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [December 27, 2021, 1:17pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/1 "2021-12-27T13:17:54Z")

</div>

Hello !  
I have a vtkPoints and I am trying to peak points from my pointcloud with cursor… so for now I am using vtkPointPicker… but with a large number of points, it is clearly too slow… The idea will be to use a vtkOctreePointLocator (or vtkKdTreePointLocator). Unfortunately we can’t give a locator to a vtkPointPicker (whereas we can with a vtkCellPicker 😢).  
Is there a class to do picking with a vtkOctreePointLocator or do I create this class myself?

Thanks for your help

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [December 27, 2021, 2:06pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/2 "2021-12-27T14:06:01Z")

</div>

Some comments:

- Check out the code in vtkPointCloudRepresentation which uses software picking (vtkPointPicker) or hardware picking (vtkHardwareSelector). This representation class can be paired with vtkPointCloudWidget.

- Yes, point picker needs a refresh, it should probably use a locator to accelerate picking (beyond a certain #points threshold).

- The point locators (vtkPointLocator and vtkStaticPointLocator) have IntersectWithLine() methods that you could probably use.

- I rarely use vtkOctreePointLocator or vtkKdTreePointLocator unless there is a lot of dynamic range in point density. They are slow to build, slow to delete, and not threaded. For most applications the vtkStaticPointLocator can be an order of magnitude faster (if built threaded with TBB etc.)

---

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [December 27, 2021, 2:24pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/3 "2021-12-27T14:24:27Z")

</div>

vtkPointLocator does not have an IntersectWithLine() method, octree and kdtree neither… unfortunately.

In my case there is a lot of dynamic range in point density, that is why octree or kdtree seems better but if I understood correctly I have to implement my own IntersectWithLine() method with those classes ?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [December 27, 2021, 2:28pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/4 "2021-12-27T14:28:28Z")

</div>

if you want to use these classes (octree, kdtree) then yes you’ll have to write your own method. Why wouldn’t you use hardware selection? It’s going to be faster than anything you do in software…

---

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [December 27, 2021, 2:36pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/5 "2021-12-27T14:36:05Z")

</div>

I forgot this part, I don’t want a structure just to pick points but also to calculate the nearest neighbors of a point from coordinates and I can’t do that with hardware selection (but yes hardware selection seems to be an amazing tool)

---

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [December 27, 2021, 2:45pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/6 "2021-12-27T14:45:19Z")

</div>

Have you ever experienced the speed difference between vtkStaticPointLocator and vtkOctreePointLocator and/or vtkKdTreePointLocator ?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [December 27, 2021, 3:20pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/7 "2021-12-27T15:20:10Z")

</div>

I suggest you experiment with this test: ./bin/vtkCommonDataModelCxxTests TimePointLocators  
Admittedly, this is a lousy test of points with high density variation. If you feel up to contributing a new test, it would be nice to have a test that creates a point cloud with high density variation. I can imagine doing this with some sort of analytic function.

Running unchanged the output is (in my 20-core system, built release):  
Timing for 100000 points, 10000 queries  
Build and delete tree  
Uniform: 0.0233409  
Static: 0.00440001  
Octree: 0.015322  
KD Tree: 0.010422  
Closest point queries  
Uniform: 0.0119779  
Static: 0.0113399  
Octree: 0.0296822  
KD Tree: 0.0164299  
Closest N points queries  
Uniform: 0.051096  
Static: 0.0308821  
Octree: 0.116065  
KD Tree: 0.0845001  
Closest points within radius queries  
Uniform: 0.00304818  
Static: 0.00191879  
Octree: 0.010278  
KD Tree: 0.0102541  
Total time  
Uniform: 0.089463  
Static: 0.0485408  
Octree: 0.171347  
KD Tree: 0.121606

If you edit the test and change the number of points to something larger:  
Timing for 10000000 points, 1000000 queries  
Build and delete tree  
Uniform: 3.8035  
Static: 0.177384  
Octree: 2.35506  
KD Tree: 4.64083  
Closest point queries  
Uniform: 3.62174  
Static: 2.36916  
Octree: 4.82664  
KD Tree: 3.62797  
Closest N points queries  
Uniform: 12.0197  
Static: 7.05107  
Octree: 12.9393  
KD Tree: 11.8128  
Closest points within radius queries  
Uniform: 5.51731  
Static: 3.51151  
Octree: 3.96433  
KD Tree: 4.40001  
Total time  
Uniform: 24.9623  
Static: 13.1091  
Octree: 24.0853  
KD Tree: 24.4816

---

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [December 27, 2021, 3:55pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/8 "2021-12-27T15:55:59Z")

</div>

That’s very interesting, vtkStaticPointLocator seems to be very efficient. MaybeI I should start by testing this class eventually. Depending on the results I get I would do other tests, Thanks a lot for your help

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [January 12, 2022, 3:46pm UTC](https://discourse.vtk.org/t/vtkpointpicker-very-slow/7507/9 "2022-01-12T15:46:58Z")

</div>

Hello Julien! I am in the process of developing the following Picker

[https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/8740](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8740)

Let me know if that helps you, in any way.
