コード例 #1
0
        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);
        }
コード例 #2
0
        public List <Vertex> FindNearest_BruteForceOld(List <Vertex> vSource, List <Vertex> vTarget)
        {
            List <Vertex> nearestNeighbours = new List <Vertex>();
            int           iMax       = 10;
            List <Vertex> tempTarget = Vertices.CopyVertices(vTarget);

            for (int i = 0; i < vSource.Count; i++)
            {
                //BuildKDTree_Standard(tempTarget);

                Vertex p = vSource[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())
                {
                    // Get the ellipse.
                    //var pEllipse = pIter.Current;
                    EllipseWrapper wr = pIter.Current;
                    nearestNeighbours.Add(wr.Vertex);
                    tempTarget.RemoveAt(pIter.CurrentIndex);
                    break;
                }
            }
            return(nearestNeighbours);
        }
コード例 #3
0
ファイル: KDTreeVertex.cs プロジェクト: 0000duck/IM-Solutions
        public PointCloudVertices FindNearest_BruteForceOld(PointCloudVertices vSource, PointCloudVertices vTarget)
        {
            PointCloudVertices nearestNeighbours = new PointCloudVertices();
            int iMax = 10;
            PointCloudVertices tempTarget = PointCloudVertices.CopyVertices(vTarget);

            for (int i = 0; i < vSource.Count; i++)
            {
                //BuildKDTree_Standard(tempTarget);

                Vertex p = vSource[i];
                // Perform a nearest neighbour search around that point.
                KDTreeRednaxela.NearestNeighbour <EllipseWrapper> pIter = null;
                pIter = KdTree_Rednaxela.FindNearest_EuclidDistance(new float[] { Convert.ToSingle(p.Vector.X), Convert.ToSingle(p.Vector.Y), Convert.ToSingle(p.Vector.Z) }, iMax, -1);
                while (pIter.MoveNext())
                {
                    // Get the ellipse.
                    //var pEllipse = pIter.Current;
                    EllipseWrapper wr = pIter.CurrentPoint;
                    nearestNeighbours.Add(wr.Vertex);
                    tempTarget.RemoveAt(pIter.CurrentIndex);
                    break;
                }
            }
            return(nearestNeighbours);
        }
コード例 #4
0
        public void FindNearest_Points_Rednaxela(List <Vertex> vertices)
        {
            //float fThreshold = kdTreeNeighbourThreshold;
            List <Vertex> nearestNeighbours = new List <Vertex>();

            for (int i = vertices.Count - 1; i >= 0; i--)
            {
                Vertex vToCheck = vertices[i];

                // Perform a nearest neighbour search around that point.
                KDTreeRednaxela.NearestNeighbour <EllipseWrapper> pIter = null;
                KDTreeVertex kv = KDTreeVertex.Instance;

                pIter = kv.KdTree_Rednaxela.FindNearest_EuclidDistance(new double[] { vToCheck.Vector.X, vToCheck.Vector.Y, vToCheck.Vector.Z }, NumberOfNeighboursToSearch, -1);
                int neighboursFound = 0;

                while (pIter.MoveNext())
                {
                    EllipseWrapper wr         = pIter.Current;
                    Vertex         vNeighbour = wr.Vertex;
                    if (vToCheck != vNeighbour)
                    {
                        if (!vToCheck.IndexNeighbours.Contains(vNeighbour.IndexInModel))
                        {
                            vToCheck.IndexNeighbours.Add(vNeighbour.IndexInModel);
                            vToCheck.DistanceNeighbours.Add(pIter.CurrentDistance);
                        }
                        for (int j = vNeighbour.IndexNeighbours.Count - 1; j >= 0; j--)
                        {
                            if (vNeighbour.IndexNeighbours[j] == vToCheck.IndexInModel)
                            {
                                vNeighbour.IndexNeighbours.RemoveAt(j);
                                vNeighbour.DistanceNeighbours.RemoveAt(j);
                            }
                        }
                        neighboursFound = vToCheck.DistanceNeighbours.Count;
                        //if (!vNeighbour.IndexNeighbours.Contains(vToCheck.IndexInModel))
                        //{
                        //    vNeighbour.IndexNeighbours.Add(vToCheck.IndexInModel);
                        //    vNeighbour.DistanceNeighbours.Add(pIter.CurrentDistance);
                        //}
                        if ((neighboursFound) > NumberOfNeighboursToSearch)
                        {
                            break;
                        }
                    }
                }
            }

            TimeCalc.ShowLastTimeSpan("Find neighbours");

            //RemoveAllVerticesBasedOnRadius(vertices);
        }
コード例 #5
0
ファイル: KDTreeVertex.cs プロジェクト: 0000duck/IM-Solutions
        public void FindNearest_NormalsCheck_Rednaxela(PointCloudVertices pointCloud, bool normalsCheck)
        {
            PointCloudVertices nearestNeighbours = new PointCloudVertices();

            //for (int i = pointCloud.Count - 1; i >= 0; i--)
            for (int i = 0; i < pointCloud.Count; i++)
            {
                Vertex vSource = pointCloud[i];

                // Perform a nearest neighbour search around that point.
                KDTreeRednaxela.NearestNeighbour <EllipseWrapper> nearestNeighbor = null;

                if (normalsCheck)
                {
                    nearestNeighbor = KdTree_Rednaxela.FindNearest_EuclidDistance(new float[] { Convert.ToSingle(vSource.Vector.X), Convert.ToSingle(vSource.Vector.Y), Convert.ToSingle(vSource.Vector.Z) }, NumberOfNeighboursToSearch + 1, -1);
                }
                else
                {
                    nearestNeighbor = KdTree_Rednaxela.FindNearest_EuclidDistance(new float[] { Convert.ToSingle(vSource.Vector.X), Convert.ToSingle(vSource.Vector.Y), Convert.ToSingle(vSource.Vector.Z) }, NumberOfNeighboursToSearch, -1);
                }

                while (nearestNeighbor.MoveNext())
                {
                    EllipseWrapper wr      = nearestNeighbor.CurrentPoint;
                    Vertex         vTarget = wr.Vertex;

                    if (vSource != vTarget)
                    {
                        if (!vSource.KDTreeSearch.Contains(vTarget.IndexInModel))
                        {
                            if (!vTarget.TakenInTree)
                            {
                                vTarget.TakenInTree = true;
                                KeyValuePair <int, float> el = new KeyValuePair <int, float>(vTarget.IndexInModel, nearestNeighbor.CurrentDistance);
                                vSource.KDTreeSearch.Add(el);
                                break;
                            }
                        }

                        if ((vSource.KDTreeSearch.Count) >= 1)
                        {
                            break;
                        }
                    }
                }
                //if (vSource.KDTreeSearch.Count == 0)
                //{
                //    System.Windows.Forms.MessageBox.Show("Error in finding neighbour for index " + i.ToString());
                //}
            }

            if (KdTree_Rednaxela.pLeft != null)
            {
                SetRecursive(KdTree_Rednaxela.pLeft);
            }
            if (KdTree_Rednaxela.pRight != null)
            {
                SetRecursive(KdTree_Rednaxela.pRight);
            }

            GlobalVariables.ShowLastTimeSpan("Find neighbours");

            //RemoveAllVerticesBasedOnRadius(pointCloud);
        }