public PointCloud FindClosestPointCloud_Parallel(PointCloud source) { this.source = source; this.ResetTaken(); VertexKDTree[] resultArray = new VertexKDTree[source.Count]; System.Threading.Tasks.Parallel.For(0, source.Count, i => //for (int i = 0; i < source.Count; i++) { VertexKDTree vSource = new VertexKDTree(source.Vectors[i], i); int nearest_index = 0; float nearest_distance = 0f; VertexKDTree vTargetFound = FindClosestPoint(vSource, ref nearest_distance, ref nearest_index); //resultArray[i] = vTargetFound.Clone(); resultArray[i] = vTargetFound; }); List <VertexKDTree> resultList = new List <VertexKDTree>(resultArray); result = PointCloud.FromListVertexKDTree(resultList); return(result); }
/// <summary> /// returns the target (tree) points found for the input (source) points /// </summary> /// <param name="source"></param> /// <returns></returns> public PointCloud FindClosestPointCloud_Parallel(PointCloud source) { this.source = source; this.ResetTaken(); VertexKDTree[] resultArray = new VertexKDTree[source.Count]; //shuffle points for the "Taken" algorithm PointCloud sourceShuffled; if (this.TakenAlgorithm) { sourceShuffled = source.Clone(); sourceShuffled.SetDefaultIndices(); sourceShuffled = PointCloud.Shuffle(sourceShuffled); } else { sourceShuffled = source; } int nearest_index = 0; float nearest_distance = 0f; System.Threading.Tasks.Parallel.For(0, source.Count, i => //for (int i = 0; i < sourceShuffled.Count; i++) { VertexKDTree vSource = new VertexKDTree(sourceShuffled.Vectors[i], i); VertexKDTree vTargetFound = FindClosestPoint(vSource, ref nearest_distance, ref nearest_index); //resultArray[i] = vTargetFound.Clone(); resultArray[i] = vTargetFound; }); List <VertexKDTree> resultList = new List <VertexKDTree>(resultArray); result = PointCloud.FromListVertexKDTree(resultList); //shuffle back PointCloud pcResultShuffledBack; if (this.TakenAlgorithm) { pcResultShuffledBack = result.Clone(); for (int i = 0; i < pcResultShuffledBack.Count; i++) { //pcResultShuffled.Vectors[i] = pcResult.Vectors[Convert.ToInt32(sourceShuffled.Indices[i])]; pcResultShuffledBack.Vectors[Convert.ToInt32(sourceShuffled.Indices[i])] = result.Vectors[i]; } } else { pcResultShuffledBack = result; } //this.MeanDistance = PointCloud.MeanDistance(source, pcResultShuffledBack); return(pcResultShuffledBack); }
/// <summary> /// the parallel method is not working - no time to find reason for that /// </summary> /// <param name="source"></param> /// <returns></returns> public PointCloud FindClosestPointCloud_NotParallel(PointCloud source) { this.source = source; this.ResetTaken(); /// the parallel method is not working - no time to find reason for that, calling normal method List <VertexKDTree> resultList = FindClosestPoint_List_NotParallel(source.VectorsWithIndex); return(PointCloud.FromListVertexKDTree(resultList)); }
public static PointCloud Shuffle(PointCloud pc) { List <VertexKDTree> lNew = pc.VectorsWithIndex; lNew.Shuffle(); PointCloud pcReturn = PointCloud.FromListVertexKDTree(lNew); return(pcReturn); }
private PointCloud FindClosestPointCloud(List <VertexKDTree> source) { return(FindClosestPointCloud_Parallel(PointCloud.FromListVertexKDTree(source))); }