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

4 months ago by
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]), 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, 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?


Community: FEniCS Project

1 Answer

4 months ago by

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])


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

Similar posts:
Search »