コード例 #1
0
        public Point MoveToNextRegion(int startIndex, Point startPoint, int subRegionSize)
        {
            SpaceFillingCurve sFC = this;

            Point firstRegionStartPoint = sFC.CalculateSubregionBMFs(startIndex).GetStartPointRelativeLocation(subRegionSize);

            Point secondRegionStartPoint = sFC.CalculateSubregionBMFs(startIndex + 1).GetStartPointRelativeLocation(subRegionSize);

            Move jumpFunc = ((p, step) => new Point(p.X + (secondRegionStartPoint.X - firstRegionStartPoint.X),
                                                    p.Y + (secondRegionStartPoint.Y - firstRegionStartPoint.Y)));

            return(jumpFunc(sFC[startIndex](startPoint, subRegionSize), 1));
        }
コード例 #2
0
        public static double[,] MemoryEfficientOverlay(List <double> firstValues, SpaceFillingCurve firstSfc,
                                                       List <double> secondValues, SpaceFillingCurve secondSfc,
                                                       int height, int width,
                                                       Func <double, double, double> func)
        {
            if (height * width != firstValues.Count || height * width != secondValues.Count)
            {
                throw new NotImplementedException();
            }

            double[,] result = new double[height, width];

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int firstIndex = TransformPointToIndex(firstSfc, new Point(i, j), height);

                    int secondIndex = TransformPointToIndex(firstSfc, new Point(i, j), height);

                    result[i, j] = func(firstValues[firstIndex], secondValues[secondIndex]);
                }
            }

            return(result);
        }
コード例 #3
0
        private static List <Point> ConstructRasterSFC(Point startPoint, int height, int width, SpaceFillingCurve sFC)
        {
            List <Point> result = new List <Point>();

            if (height * width == sFC.NumberOfSteps)
            {
                return(sFC.TraverseTheBasePath(startPoint));
            }

            int newHeight = height / sFC.BaseSize;

            int newWidth = width / sFC.BaseSize;

            Point tempPoint = startPoint;

            for (int i = 0; i < sFC.NumberOfSteps; i++)
            {
                SpaceFillingCurve temp = sFC.CalculateSubregionBMFs(i);

                result.AddRange(ConstructRasterSFC(tempPoint, newHeight, newWidth, temp));

                if (i == sFC.NumberOfSteps - 1)
                {
                    continue;
                }

                tempPoint = sFC.MoveToNextRegion(i, tempPoint, newWidth);
            }

            return(result);
        }
コード例 #4
0
        public Point GetStartPointRelativeLocation(int subregionSize)
        {
            List <Point> relativePoints = new List <Point>();

            relativePoints.Add(GetStartPointRelativeLocation());

            SpaceFillingCurve temp = this;

            while (subregionSize > this.baseSize)
            {
                subregionSize = subregionSize / this.baseSize;

                temp = temp.CalculateSubregionBMFs(0);

                relativePoints.Add(temp.GetStartPointRelativeLocation());
            }

            Point result = new Point(0, 0);

            for (int i = 0; i < relativePoints.Count; i++)
            {
                result.X = result.X + relativePoints[i].X * Math.Pow(this.baseSize, relativePoints.Count - 1 - i);

                result.Y = result.Y + relativePoints[i].Y * Math.Pow(this.baseSize, relativePoints.Count - 1 - i);
            }

            return(result);
        }
コード例 #5
0
        public static Point TransformIndexToPoint(SpaceFillingCurve sFC, int index, int size)
        {
            List <int> baseRepresentation = new List <int>();

            int baseValue = sFC.NumberOfSteps;

            int outputLength = (int)Math.Log(size, sFC.BaseSize);

            int temp = index;

            do
            {
                baseRepresentation.Add(temp % baseValue);

                temp = temp / baseValue;
            } while (temp >= 1 || baseRepresentation.Count < outputLength);

            baseRepresentation.Reverse();

            Point startPoint = sFC.GetStartPointRelativeLocation();

            startPoint = new Point(startPoint.X * (size - 1) / (sFC.BaseSize - 1), startPoint.Y * (size - 1) / (sFC.BaseSize - 1));

            for (int i = 0; i < baseRepresentation.Count; i++)
            {
                size = size / sFC.BaseSize;

                if (size == 1)
                {
                    for (int j = 0; j < baseRepresentation[i]; j++)
                    {
                        startPoint = sFC[j](startPoint, 1);
                    }
                }
                else
                {
                    for (int j = 0; j < baseRepresentation[i]; j++)
                    {
                        startPoint = sFC.MoveToNextRegion(j, startPoint, size);
                    }
                }

                sFC = sFC.CalculateSubregionBMFs(baseRepresentation[i]);
            }

            return(startPoint);
        }
コード例 #6
0
        public static List <double> Project2DDataTo1D(double[,] values, SpaceFillingCurve sFC)
        {
            int width = values.GetLength(0);

            int height = values.GetLength(1);

            Point startPoint = sFC.GetStartPointRelativeLocation(width);

            return(Project2DDataTo1D(startPoint, height, width, values, sFC));
        }
コード例 #7
0
        private void DrawTheCurve()
        {
            int level = int.Parse(this.level.SelectedValuePath.ToString()) + 1;

            int size = (int)Math.Pow(2, level);

            List <sfc.Move> moves = this.sFCControl1.GetMoves();

            if (moves.Count < 1)
            {
                return;
            }

            sfc.SpaceFillingCurve path = new sfc.SpaceFillingCurve(2, moves, this.GetMTFs());

            List <spatial.Point> pnts = IRI.Ket.Spatial.Primitives.SpaceFillingCurve.ConstructRasterSFC(size, size, path);

            this.canvas1.Children.Clear();

            //PathGeometry geo = new PathGeometry();
            //EllipseGeometry temp = new EllipseGeometry(new Point(pnts[0].X * 25 + 5, pnts[0].Y * 25 + 5), 4, 4);
            //geo.AddGeometry(temp);

            for (int i = 1; i < pnts.Count; i++)
            {
                //geo.AddGeometry(new EllipseGeometry(new Point(pnts[i].X * 25 + 5, pnts[i].Y * 25 + 5), 4, 4));

                Line line = new Line()
                {
                    Stroke          = new SolidColorBrush(Colors.Black),
                    StrokeThickness = 4,
                    X1 = pnts[i - 1].X * 25 + 5,
                    X2 = pnts[i].X * 25 + 5,
                    Y1 = pnts[i - 1].Y * 25 + 5,
                    Y2 = pnts[i].Y * 25 + 5,
                    StrokeEndLineCap   = PenLineCap.Triangle,
                    StrokeStartLineCap = PenLineCap.Round,
                    Opacity            = .4,
                    Tag = "line"
                };

                this.canvas1.Children.Add(line);

                Canvas.SetZIndex(line, 1);
            }

            //Path tempPath = new Path() { Opacity = .4, Data = geo, Fill = new SolidColorBrush(Colors.Red), Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 2, Tag = "data" };

            //this.canvas1.Children.Add(tempPath);

            //Canvas.SetZIndex(tempPath, 0);
        }
コード例 #8
0
        public int ComparePoints(Point first, Point second, Boundary mbb)
        {
            if (first.Equals(second))
            {
                return(0);
            }

            double tempUnitSize = (double)Math.Max(mbb.Height, mbb.Width);

            double deltaX = (tempUnitSize - mbb.Width) / 2.0; double deltaY = (tempUnitSize - mbb.Height) / 2.0;

            int firstX = (int)Math.Floor((first.X - mbb.MinX + deltaX) / (tempUnitSize / this.BaseSize));

            int secondX = (int)Math.Floor((second.X - mbb.MinX + deltaX) / (tempUnitSize / this.BaseSize));

            int firstY = (int)Math.Floor((first.Y - mbb.MinY + deltaY) / (tempUnitSize / this.BaseSize));

            int secondY = (int)Math.Floor((second.Y - mbb.MinY + deltaY) / (tempUnitSize / this.BaseSize));

            if (firstX.Equals(double.NaN))
            {
                throw new NotImplementedException();
            }

            if (firstX == secondX && firstY == secondY)
            {
                int index = this.GetSubRegionIndex(new Point(firstX, firstY));

                SpaceFillingCurve newSFC = this.CalculateSubregionBMFs(index);

                Boundary newMbb = mbb.GetSubboundary(firstX, firstY, tempUnitSize / this.BaseSize, tempUnitSize / this.BaseSize);

                newMbb.MoveBoundary(-deltaX, -deltaY);

                if (!newMbb.DoseContainsPoint(first) || !newMbb.DoseContainsPoint(second))
                {
                    throw new NotImplementedException();
                }

                return(newSFC.ComparePoints(first, second, newMbb));
            }
            else
            {
                return(this.ComparePoints(new Point(firstX, firstY), new Point(secondX, secondY)));
            }
        }
コード例 #9
0
        public static double[,] SpeedEfficientOverlay(List <double> firstValues, SpaceFillingCurve firstSfc,
                                                      List <double> secondValues, SpaceFillingCurve secondSfc,
                                                      int height, int width,
                                                      Func <double, double, double> func)
        {
            if (height * width != firstValues.Count || height * width != secondValues.Count)
            {
                throw new NotImplementedException();
            }

            List <Point> first = ConstructRasterSFC(height, width, firstSfc);

            List <Point> second = ConstructRasterSFC(height, width, secondSfc);

            double[,] firstGrid = new double[height, width];

            double[,] secondGrid = new double[height, width];

            for (int i = 0; i < height * width; i++)
            {
                firstGrid[(int)first[i].X, (int)first[i].Y] = firstValues[i];
            }

            for (int i = 0; i < height * width; i++)
            {
                secondGrid[(int)second[i].X, (int)second[i].Y] = secondValues[i];
            }


            double[,] result = new double[height, width];

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    result[i, j] = func(firstGrid[i, j], secondGrid[i, j]);
                }
            }

            return(result);
        }
コード例 #10
0
        private static List <double> Project2DDataTo1D(Point startPoint, int height, int width, double[,] values, SpaceFillingCurve sFC)
        {
            List <double> result = new List <double>();

            if (height * width == sFC.NumberOfSteps)
            {
                List <Point> temp = sFC.TraverseTheBasePath(startPoint);

                List <double> tempResult = new List <double>();

                foreach (Point item in temp)
                {
                    tempResult.Add(values[(int)item.X, (int)item.Y]);
                }

                return(tempResult);
            }

            int newHeight = height / sFC.BaseSize;

            int newWidth = width / sFC.BaseSize;

            Point tempPoint = startPoint;

            for (int i = 0; i < sFC.NumberOfSteps; i++)
            {
                SpaceFillingCurve temp = sFC.CalculateSubregionBMFs(i);

                result.AddRange(Project2DDataTo1D(tempPoint, newHeight, newWidth, values, temp));

                if (i == sFC.NumberOfSteps - 1)
                {
                    continue;
                }

                tempPoint = sFC.MoveToNextRegion(i, tempPoint, newWidth);
            }

            return(result);
        }
コード例 #11
0
        public static int TransformPointToIndex(SpaceFillingCurve sFC, Point point, int size)
        {
            List <Point> temp = new List <Point>();

            int level = (int)Math.Log(size, sFC.BaseSize);

            while (temp.Count < level)
            {
                temp.Add(new Point(point.X % sFC.BaseSize, point.Y % sFC.BaseSize));

                point = new Point((int)point.X / sFC.BaseSize, (int)point.Y / sFC.BaseSize);
            }

            temp.Reverse();

            List <int> indexes = new List <int>();

            for (int i = 0; i < temp.Count; i++)
            {
                int index = sFC.GetSubRegionIndex(temp[i]);

                indexes.Add(index);

                sFC = sFC.CalculateSubregionBMFs(index);
            }

            indexes.Reverse();

            int result = 0;

            for (int i = 0; i < indexes.Count; i++)
            {
                result += indexes[i] * (int)Math.Pow(sFC.NumberOfSteps, i);
            }

            return(result);
        }
コード例 #12
0
        public static List <Point> ConstructRasterSFC(int height, int width, SpaceFillingCurve sFC)
        {
            Point startPoint = sFC.GetStartPointRelativeLocation(width);

            return(ConstructRasterSFC(startPoint, height, width, sFC));
        }