Пример #1
0
 public DisplayReadySlice(MapDataSlice slice, int lod) : base(slice)
 {
     this.baseSlice        = slice;
     this.lod              = lod;
     this.neighbors        = slice.GetNeighbors();
     this.displayNeighbors = new List <DisplayNeighborRelation>(expectedNumberOfNeighbors);
 }
Пример #2
0
    public static ColorMap ColorMapForSatelliteImage(MapData mapData)
    {
        SatelliteImage satelliteImage = SatelliteImageService.getSatelliteImage();
        double         scale          = satelliteImage.getScale();

        int textureWidth  = (int)(mapData.GetWidth() * scale);
        int textureHeight = (int)(mapData.GetHeight() * scale);

        Color[] colorArray = new Color[textureWidth * textureHeight];
        if (!satelliteImage.hasSatelliteImage())
        {
            return(new ColorMap(colorArray, textureWidth, textureHeight));
        }

        MapDataSlice slice = mapData.AsSlice();

        for (int y = 0; y < textureHeight; y++)
        {
            int sliceY   = (int)(slice.GetY() * scale);
            int flippedY = satelliteImage.texture.height - (int)(sliceY + y) - 1;
            Array.ConstrainedCopy(satelliteImage.texture.GetPixels((int)(slice.GetX() * scale), flippedY, textureWidth, 1), 0, colorArray, (y * textureWidth), textureWidth);
        }

        return(new ColorMap(colorArray, textureWidth, textureHeight));
    }
Пример #3
0
    public void GetSlices_NeighborRelationsCorrect()
    {
        List <MapDataSlice> slices = mapdata.GetSlices(0, 0, 2, 3, 2, 2);

        Assert.True(slices[0].GetNeighbors().Count == 2);
        MapData rightNeighsBottomNeigh = null, bottomNeighsRightNeigh = null;

        foreach (MapNeighborRelation rel in slices[0].GetNeighbors())
        {
            Assert.True(rel.IsFirstMember(slices[0]));
            MapDataSlice other = (MapDataSlice)rel.GetOther(slices[0]);
            Assert.True(other.GetNeighbors().Contains(rel));
            Assert.False(rel.IsFirstMember(other));
            if (rel.neighborType == NeighborType.LeftRight)
            {
                rightNeighsBottomNeigh = other.GetNeighbors()
                                         .Where((nr) => nr.neighborType == NeighborType.TopBottom)
                                         .Where((nr) => nr.IsFirstMember(other))
                                         .First().GetOther(other);
            }
            else
            {
                bottomNeighsRightNeigh = other.GetNeighbors()
                                         .Where((nr) => nr.neighborType == NeighborType.LeftRight)
                                         .Where((nr) => nr.IsFirstMember(other))
                                         .First().GetOther(other);
            }
        }
        Assert.True(rightNeighsBottomNeigh == bottomNeighsRightNeigh);
    }
Пример #4
0
    public void SimplificationIncrementForXCorrect()
    {
        DisplayReadySlice slice = new MapDataSlice(data, 1, 0, 5, 3).AsDisplayReadySlice(1);
        Action <int, int> check = (expected, x) => {
            Assert.True(expected == slice.SimplificationIncrementForX(x),
                        "SimplificationIncrementForX wrong at " + x + "; should be " + expected + ", was " + slice.SimplificationIncrementForX(x));
        };

        check(2, 0); check(2, 1); check(1, 2); check(1, 3);
    }
Пример #5
0
    public void SimplificationIncrementForYCorrect()
    {
        DisplayReadySlice slice = new MapDataSlice(data, 0, 0, 4, 5).AsDisplayReadySlice(2);
        Action <int, int> check = (expected, y) => {
            Assert.True(expected == slice.SimplificationIncrementForY(y),
                        "SimplificationIncrementForY wrong at " + y + "; should be " + expected + ", was " + slice.SimplificationIncrementForY(y));
        };

        check(4, 0); check(3, 1); check(2, 2); check(1, 3); check(1, 4);
    }
Пример #6
0
    public static ColorMap ColorMapForHeightAndAreas(MapData mapData, int lod = 0)
    {
        lod = lod == 0 ? 1 : lod * 2;
        int          width  = mapData.GetWidth();
        int          height = mapData.GetHeight();
        MapDataSlice slice  = mapData.AsSlice();

        Color[] colorArray = new Color[width * height];
        if (areaDisplay == null)
        {
            areaDisplay = GameObject.FindObjectOfType <AreaDisplay>();
        }

        for (int y = 0; y < height; y += lod)
        {
            for (int x = 0; x < width; x += lod)
            {
                float currentHeight = mapData.GetSquished(x, y);
                float scaledPosX    = (slice.GetX() + x);
                float scaledPosY    = (slice.GetY() + y);
                Color areaColor     = areaDisplay.GetPointColor(scaledPosX, scaledPosY);
                Color regionColor   = GetRegionColour(currentHeight);

                if (areaColor != Color.clear)
                {
                    regionColor = Color.Lerp(areaColor, regionColor, colorLerpValue);
                }

                for (int actualY = y; actualY < y + lod && actualY < height; actualY++)
                {
                    for (int actualX = x; actualX < x + lod && actualX < width; actualX++)
                    {
                        colorArray[actualY * width + actualX] = regionColor;
                    }
                }
            }
        }
        return(new ColorMap(colorArray, width, height));
    }
Пример #7
0
    public List <MapDataSlice> GetSlices(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY, int sliceWidth, int sliceHeight, bool doOffset = true)
    {
        if (sliceHeight <= (doOffset ? 1 : 0) || sliceWidth <= (doOffset ? 1 : 0))
        {
            throw new System.ArgumentException("Too small slice width (" + sliceWidth + ") or height (" + sliceHeight + ")");
        }
        List <MapDataSlice> slices = new List <MapDataSlice>();
        int rowLen = 0, i = 0;

        for (int y = topLeftY; y < bottomRightY; y += sliceHeight - (doOffset ? 1 : 0))
        {
            for (int x = topLeftX; x < bottomRightX; x += sliceWidth - (doOffset ? 1 : 0))
            {
                MapDataSlice slice = new MapDataSlice(this, x, y, sliceWidth, sliceHeight);
                if (x > topLeftX)
                {
                    MapDataSlice        other    = slices.Last();
                    MapNeighborRelation relation = new MapNeighborRelation(other, slice, NeighborType.LeftRight);
                    slice.AddNeighbor(relation);
                    other.AddNeighbor(relation);
                }
                if (y > topLeftY)
                {
                    MapDataSlice        other    = slices[i - rowLen];
                    MapNeighborRelation relation = new MapNeighborRelation(other, slice, NeighborType.TopBottom);
                    slice.AddNeighbor(relation);
                    other.AddNeighbor(relation);
                }
                else
                {
                    rowLen++;
                }
                i++;
                slices.Add(slice);
            }
        }
        return(slices);
    }
Пример #8
0
 public MapDataSlice(MapDataSlice slice) : this(slice, slice.topLeftX, slice.topLeftY, slice.width, slice.height)
 {
 }