Hi,
I am doing fairly simple point matching, two know which point id of the second set is equal to the first set.
- Two sets contains the same amount of points
- The order of points differs
- Both point sets points are at exactly same positions.
I am surprised that RTree search is faster than doing Dictionary search where key is the XYZ coordinates of points:
Dictionary<string, int> cpIDDict = new Dictionary<string, int>(ptsPlines0.Length);
for (int i = 0; i < ptsPlines0.Length; i++) {
cpIDDict.Add(Math.Round(ptsPlines0[i].X, 3) + ";" + Math.Round(ptsPlines0[i].Y, 3) + ";" + Math.Round(ptsPlines0[i].Z, 3), i);
}
int[] cpID = new int[ptsPlines0.Length];
for (int i = 0; i < ptsPlines0.Length; i++) {
cpID[i] = cpIDDict[Math.Round(ptsMesh[i].X, 3) + ";" + Math.Round(ptsMesh[i].Y, 3) + ";" + Math.Round(ptsMesh[i].Z, 3)];
}
The RTree method I am using is this:
public static int[] RTreeSearchIDOnlyOne(Point3d[] pointsToSearchFrom, Point3d[] needles, double dist) {
//If not empty
if (pointsToSearchFrom.Length == 0 || needles.Length == 0)
return Enumerable.Repeat(-1, pointsToSearchFrom.Length).ToArray();
//Search
IEnumerable<int[]> found = RTree.Point3dClosestPoints(pointsToSearchFrom, needles, dist);
int[] result = new int[needles.Length];
int count = 0;
foreach (var item in found) {
result[count++] = item.Length > 0 ? item[0] : -1;
}
return result;
}
Do you know other fast search methods to find points id on the same locations?
I think there is a better and faster way to do this, but I do not know one.
SetA
SetB