void RefereshGrids(Ket.Spatial.Primitives.Boundary boundary)
        {
            if (this.boundary.Height == 0)
            {
                return;
            }

            this.RefereshGrids(this.canvas1, 2, boundary);
            this.RefereshGrids(this.canvas2, 2, boundary);
            this.RefereshGrids(this.canvas3, 2, boundary);
            this.RefereshGrids(this.canvas4, 2, boundary);
            this.RefereshGrids(this.canvas5, 3, boundary);
            this.RefereshGrids(this.canvas6, 3, boundary);
        }
        private void canvas1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Point newPoint = e.GetPosition(this.canvas1);

            this.points.Add(new spatial.Point(newPoint.X, newPoint.Y));

            this.boundary = IRI.Ket.Spatial.PointSorting.PointOrdering.GetBoundary(points.ToArray(), 2);

            spatial.Point[] result1 = IRI.Ket.Spatial.PointSorting.PointOrdering.HilbertSorter(points.ToArray());

            Referesh(result1, canvas1);

            spatial.Point[] result2 = IRI.Ket.Spatial.PointSorting.PointOrdering.GraySorter(points.ToArray());

            Referesh(result2, canvas2);

            spatial.Point[] result3 = IRI.Ket.Spatial.PointSorting.PointOrdering.NOrderingSorter(points.ToArray());

            Referesh(result3, canvas3);

            spatial.Point[] result4 = IRI.Ket.Spatial.PointSorting.PointOrdering.ZOrderingSorter(points.ToArray());

            Referesh(result4, canvas4);

            spatial.Point[] result5 = IRI.Ket.Spatial.PointSorting.PointOrdering.DiagonalLebesgueSorter(points.ToArray());

            Referesh(result5, canvas5);

            spatial.Point[] result6 = IRI.Ket.Spatial.PointSorting.PointOrdering.UOrderOrLebesgueSquareSorter(points.ToArray());

            Referesh(result6, canvas6);

            spatial.Point[] result7 = IRI.Ket.Spatial.PointSorting.PointOrdering.PeanoSorter(points.ToArray());

            Referesh(result7, canvas7);

            spatial.Point[] result8 = IRI.Ket.Spatial.PointSorting.PointOrdering.Peano02Sorter(points.ToArray());

            Referesh(result8, canvas8);

            //spatial.Point[] result9 = IRI.Ket.Spatial.PointSorting.PointOrdering.HosseinSorter(points.ToArray());

            //Referesh(result9, canvas9);
        }
        void RefereshGrids(Canvas canvas, int baseSize, Ket.Spatial.Primitives.Boundary boundary)
        {
            if (this.level < 0)
            {
                this.level = 0;
            }

            //double regionSize = Math.Max(canvas.ActualHeight, canvas.ActualWidth);
            double regionSize = Math.Max(boundary.Height, boundary.Width);

            ClearCanvas(canvas, "grid");

            for (int i = 1; i <= this.level; i++)
            {
                int numberOfLines = (int)Math.Pow(baseSize, i);

                double lineSpace = regionSize / numberOfLines;

                for (int j = 0; j < numberOfLines - 1; j++)
                {
                    double temp = (j + 1) * lineSpace;

                    Line verticalLine = new Line()
                    {
                        X1 = boundary.MinX + temp, Y1 = boundary.MinY, X2 = boundary.MinX + temp, Y2 = boundary.MinY + boundary.Height, Stroke = Brushes.Red, StrokeThickness = this.level - i + .5, Tag = "grid"
                    };

                    Line horizontalLine = new Line()
                    {
                        X1 = boundary.MinX, Y1 = boundary.MinY + temp, X2 = boundary.MinX + boundary.Width, Y2 = boundary.MinY + temp, Stroke = Brushes.Red, StrokeThickness = this.level - i + .5, Tag = "grid"
                    };

                    canvas.Children.Add(verticalLine);

                    canvas.Children.Add(horizontalLine);
                }
            }
        }
Beispiel #4
0
        private void Referesh()
        {
            Ket.Spatial.Primitives.Boundary b = IRI.Ket.Spatial.PointSorting.PointOrdering.GetBoundary(points.ToArray(), 2);

            Func <IRI.Ket.Geometry.Point, IRI.Ket.Geometry.Point, int> simpleFuncX = (p1, p2) => p1.X.CompareTo(p2.X);
            Func <IRI.Ket.Geometry.Point, IRI.Ket.Geometry.Point, int> simpleFuncY = (p1, p2) => p1.Y.CompareTo(p2.Y);


            IRI.Ket.DataStructure.AdvancedStructures.KdTree <IRI.Ket.Geometry.Point> kdTree =
                new IRI.Ket.DataStructure.AdvancedStructures.KdTree <IRI.Ket.Geometry.Point>(
                    points.ToArray(),
                    new List <Func <IRI.Ket.Geometry.Point, IRI.Ket.Geometry.Point, int> >()
            {
                simpleFuncX, simpleFuncY
            });

            IRI.Ket.DataStructure.AdvancedStructures.BalancedKdTree <IRI.Ket.Geometry.Point> balancedKdTree =
                new IRI.Ket.DataStructure.AdvancedStructures.BalancedKdTree <IRI.Ket.Geometry.Point>(
                    points.ToArray(),
                    new List <Func <IRI.Ket.Geometry.Point, IRI.Ket.Geometry.Point, int> >()
            {
                simpleFuncX, simpleFuncY
            },
                    new Ket.Geometry.Point(double.NaN, double.NaN),
                    i => new spatial.Point(i.X, i.Y));

            canvas1.Children.Clear(); simpleHeight  = 0;
            canvas2.Children.Clear(); rbHeight      = 0;
            canvas3.Children.Clear(); hilbertHeight = 0;

            DrawLine(kdTree.Root, 0, 0, canvas1.ActualHeight, 0, canvas1.ActualWidth);
            DrawLine02(balancedKdTree.Root, 0, 0, canvas2.ActualHeight, 0, canvas2.ActualWidth);
            //IRI.Ket.DataStructure.AdvancedStructures.BalancedKdTree<Point> kdtree02 =
            //    new IRI.Ket.DataStructure.AdvancedStructures.BalancedKdTree<Point>(points.ToArray(), new List<Func<Point, Point, int>>() { myFunc });

            List <spatial.Point> points02 = new List <spatial.Point>();

            foreach (IRI.Ket.Geometry.Point item in points)
            {
                points02.Add(new spatial.Point(item.X, item.Y));
            }

            spatial.Point[] result = IRI.Ket.Spatial.PointSorting.PointOrdering.HilbertSorter(points02.ToArray());

            Func <spatial.Point, spatial.Point, int> simpleFuncX02 = (p1, p2) => p1.X.CompareTo(p2.X);
            Func <spatial.Point, spatial.Point, int> simpleFuncY02 = (p1, p2) => p1.Y.CompareTo(p2.Y);

            IRI.Ket.DataStructure.AdvancedStructures.KdTree <spatial.Point> kdTree02 =
                new IRI.Ket.DataStructure.AdvancedStructures.KdTree <spatial.Point>(
                    result,
                    new List <Func <spatial.Point, spatial.Point, int> >()
            {
                simpleFuncX02, simpleFuncY02
            });

            DrawLine03(kdTree02.Root, 0, 0, canvas3.ActualHeight, 0, canvas3.ActualWidth);

            title1.Content = string.Format("K-d Tree (Binary Search Tree); Height={0}", simpleHeight.ToString());
            title2.Content = string.Format("K-d Tree (Red-Black Tree); Height={0}", rbHeight.ToString());
            title3.Content = string.Format("K-d Tree (Hilbert); Height={0}", hilbertHeight.ToString());
        }