### How can I build a bounding box tree using a point cloud in FEniCS 2017.2?

156

views

0

Hi,

according to the manuals building a bounding box tree with a point cloud was possible using 2016.2 but this functionality seems to be removed in 2017.2

To demonstrate:

I know I can use

but then I get the Error for "compute_closest_point" that "Search tree has not been built for point cloud"

When I use

according to the manuals building a bounding box tree with a point cloud was possible using 2016.2 but this functionality seems to be removed in 2017.2

To demonstrate:

```
from __future__ import print_function
from fenics import *
mesh = UnitSquareMesh(8, 8)
tree = mesh.bounding_box_tree()
point_cloud = [Point(point) for point in mesh.coordinates()]
p1 = Point(mesh.coordinates()[0])
tree.build(point_cloud, 2)
p_idx, distance = tree.compute_closest_point(p1)
print(p_idx, distance)
```

is working with 2016.2 but with 2017.2 I get a TypeError.I know I can use

```
tree.build(mesh, 2)
```

but then I get the Error for "compute_closest_point" that "Search tree has not been built for point cloud"

When I use

`p_idx, distance = tree.compute_closest_entity(p1)`

it works, but I get a different result for p_idx. Presumably it found another entity first.

Is there a new way to generate a bounding box tree using a point cloud?

Thanks,

Christoph

Community: FEniCS Project

### 1 Answer

0

Hi,

I couldn't solve this problem with FEniCS and for some of my cases

I couldn't solve this problem with FEniCS and for some of my cases

`p_idx, distance = tree.compute_closest_point(p1)`

wasn't working reliably. Sometimes it gave me p_idx=0 althought p1 wasn't even close to p_idx 0.

I could solve my initial problem using scipy.

```
from scipy import spatial
tree = spatial.KDTree(mesh.coordinates())
distance, p_idx = tree.query(bmesh_sim.coordinates()[0])
```

Best,

Christoph

Please login to add an answer/comment or follow this question.