public List <Vertex> FindNearest_Rednaxela(List <Vertex> pointsSource, List <Vertex> pointsTarget, int keepOnlyNearestPoints) { List <Vertex> nearestNeighbours = new List <Vertex>(); int iMax = 1; List <double> listDistances = new List <double>(); //float fThreshold = kdTreeNeighbourThreshold; for (int i = 0; i < pointsSource.Count; i++) { Vertex p = pointsSource[i]; // Perform a nearest neighbour search around that point. KDTreeRednaxela.NearestNeighbour <EllipseWrapper> pIter = null; pIter = KdTree_Rednaxela.FindNearest_EuclidDistance(new double[] { p.Vector.X, p.Vector.Y, p.Vector.Z }, iMax, -1); while (pIter.MoveNext()) { EllipseWrapper wr = pIter.Current; listDistances.Add(pIter.CurrentDistance); nearestNeighbours.Add(wr.Vertex); break; } } if (keepOnlyNearestPoints > 0) { RemovePointsWithDistanceGreaterThanAverage(listDistances, pointsSource, nearestNeighbours); } return(nearestNeighbours); }
public void FindNearest_Rednaxela_Helper() { NeighboursFound = false; listNeighbours = new List <List <Neighbours> >(); for (int i = 0; i < pointsSource.Count; i++) { Vertex vSource = pointsSource[i]; // Perform a nearest neighbour search around that point. KDTreeRednaxela.NearestNeighbour <EllipseWrapper> nearestNeighbor = null; nearestNeighbor = KdTree_Rednaxela.FindNearest_EuclidDistance(new float[] { Convert.ToSingle(vSource.Vector.X), Convert.ToSingle(vSource.Vector.Y), Convert.ToSingle(vSource.Vector.Z) }, 1, -1); List <Neighbours> neighboursForVertex = new List <Neighbours>(); lock (listNeighbours) { listNeighbours.Add(neighboursForVertex); } while (nearestNeighbor.MoveNext()) { Vertex vTarget = nearestNeighbor.CurrentPoint.Vertex; Neighbours kv = new Neighbours(); kv.IndexSource = vSource.IndexInModel; kv.Distance = nearestNeighbor.CurrentDistance; kv.IndexTarget = vTarget.IndexInModel; if (Normals_SortPoints && NormalsSource != null) { Vector3 nSource = NormalsSource[vSource.IndexInModel]; Vector3 nTarget = NormalsTarget[vTarget.IndexInModel]; float angle = nSource.AngleInDegrees(nTarget); kv.Angle = angle; } neighboursForVertex.Add(kv); } } ; if (DistanceOptimization) { RemovePointsWithDistanceGreaterThanAverage(pointsSource, pointsTarget, listNeighbours); } NeighboursFound = true; }