예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        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_Rednaxela_HelperParallel()
        {
            NeighboursFound = false;

            listNeighbours = new List <List <Neighbours> >();
            //for (int i = 0; i < pointsSource.Count; i++)
            System.Threading.Tasks.Parallel.For(0, 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;
                    vSource.IndexKDTreeTarget = vTarget.IndexInModel;
                }
            });

            if (DistanceOptimization)
            {
                RemovePointsWithDistanceGreaterThanAverage(pointsSource, pointsTarget, listNeighbours);
            }


            NeighboursFound = true;
        }
예제 #5
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);
        }
예제 #6
0
        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;
        }
예제 #7
0
        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);
        }