About creating the RTree from the list of points without looping through each point in the list: I read in the documentation as comment in the examples it’s not yet in RhinoCommon. Is there a plan for this to be included in, at least, the WIP?
The good about not understanding how RTree works is that it lead me to implementing CPython and numpy ran from standard GhPython component Respectively implementing the algorithm with numpy.
@menno is is possible to give different radius for each point?
while executing this line: IEnumerable<int[]> found = RTree.Point3dClosestPoints(pointsToSearchFrom, needles, dist);
public static List<Point3d> RTreeSearch(List<Point3d> pointsToSearchFrom, List<Point3d> needles, double dist, ref object A) {
//If not empty
if (pointsToSearchFrom.Count == 0 || needles.Count == 0)
return new List<Point3d>();
//Search
IEnumerable<int[]> found = RTree.Point3dClosestPoints(pointsToSearchFrom, needles, dist);
List<Point3d> result = new List<Point3d>();
foreach (var item in found) {
int[] data = item;
for (int j = 0; j < data.Length; ++j)
result.Add(pointsToSearchFrom[data[j]]);
}
return result;
}
Hi Ivelin,
do you have the code with serchPoint as a list input?
It would be super appreciate if you can share
Edit:
sorry. I was being dumb.
import Rhino.Geometry as rg
__author__ = "david.leon_Review_MP"
__version__ = "2020.03.19"
#build the tree
tree = rg.RTree()
#add the points to the tree
for i in range(len(pointList)):
tree.Insert(pointList[i], i)
closestPoints = []
closestIndices = []
#event handler of type RTreeEventArgs
def SearchCallback(sender, e):
closestPoints.Add(pointList[e.Id])
closestIndices.Add(e.Id)
for item in searchPoint:
tree.Search(rg.Sphere(item, radius), SearchCallback)
pts = closestPoints
ind = closestIndices