Esempio n. 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));
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }