Exemplo n.º 1
0
    private byte[] generateTexture(int cx, int cy, int z)
    {
        byte[] tex = new byte[256 * 256 * 4];
        //var path = GISparser.getQuadPath(new Vector2Int(cx, cy), z);
        //List<GISway> waysList = null;

        Vector2d chunkLow  = new Vector2d(((double)(cx) / (double)(1 << z)), ((double)(cy) / (double)(1 << z)));
        Vector2d chunkHigh = new Vector2d(((double)(cx + 1) / (double)(1 << z)), ((double)(cy + 1) / (double)(1 << z)));

        var c = new Vector4(0f, 0f, 0f, 0f);

        for (int x = 0; x < 256; ++x)
        {
            for (int y = 0; y < 256; ++y)
            {
                setPixel(tex, x, y, c);
            }
        }

        if (gisdata == null)
        {
            return(tex);
        }

        float[] heatMap = renderFloat(cx, cy, z);

        if (heatMap != null)
        {
            for (int x = 0; x < 256; ++x)
            {
                for (int y = 0; y < 256; ++y)
                {
                    var v  = (heatMap[x + 256 * y] - minvalue) / (maxvalue - minvalue);
                    var hc = GISparser.valueToHeatColor(v);
                    setPixel(tex, x, y, hc);
                }
            }
        }

        foreach (var punkt in uzytecznePunkty)
        {
            drawPointOptimal(tex, punkt, chunkLow, chunkHigh);
        }

        /*foreach (var way in waysList)
         * {
         *  drawWayOptimal(tex, way, chunkLow, chunkHigh);
         * }*/

        return(tex);
    }
Exemplo n.º 2
0
    Texture2D generateFullViewTexture()
    {
        int width  = ch2.x - ch1.x + 1;
        int height = ch2.y - ch1.y + 1;

        Vector2d range = getCameraRange();
        Vector2d p1    = new Vector2d(-(float)range.x / 2f + cam.transform.position.x, -(float)range.y / 2f + -cam.transform.position.z);
        Vector2d p2    = new Vector2d((float)range.x / 2f + cam.transform.position.x, (float)range.y / 2f + -cam.transform.position.z);

        Texture2D tex = new Texture2D(width * 256, height * 256);

        Vector2d chunkLow  = new Vector2d(((double)(ch1.x) / (double)(1 << zoom)) * 256.0, ((double)(ch1.y) / (double)(1 << zoom)) * 256.0);
        Vector2d chunkHigh = new Vector2d(((double)(ch2.x + 1) / (double)(1 << zoom)) * 256.0, ((double)(ch2.y + 1) / (double)(1 << zoom)) * 256.0);

        var c = Color.cyan;

        //fill

        /*for (int x = 0; x < tex.width; ++x)
         * {
         *  for (int y = 0; y < tex.height; ++y)
         *  {
         *      tex.SetPixel(x, y, c);
         *  }
         * }*/
        //heatmap
        //float[,] heatmap = new float[resolution.x, resolution.y];
        float[,] heatmap = new float[tex.width, tex.height];
        foreach (var zad in zadania)
        {
            float[,] tmpheat;
            if (zad.isMax)
            {
                tmpheat = heatmapCreatorMax(ref tex, chunkLow, chunkHigh, zad.key, zad.value);
            }
            else
            {
                tmpheat = heatmapCreatorMin(ref tex, chunkLow, chunkHigh, zad.key, zad.value);
            }
            for (int x = 0; x < tex.width; ++x)
            {
                for (int y = 0; y < tex.height; ++y)
                {
                    heatmap[x, y] += tmpheat[x, y];
                }
            }
        }
        //var heat = heatmapCreatorMax(ref tex, chunkLow, chunkHigh, "amenity", "restaurant");
        //var heat2= heatmapCreatorMin(ref tex, chunkLow, chunkHigh, "emergency", "fire_hydrant");

        /*for (int x = 0; x < tex.width; ++x)
         * {
         *  for (int y = 0; y < tex.height; ++y)
         *  {
         *      heat[x,y] += heat2[x,y];
         *  }
         * }*/

        float minvalue = float.PositiveInfinity, maxvalue = float.NegativeInfinity;

        for (int x = 0; x < tex.width; ++x)
        {
            for (int y = 0; y < tex.height; ++y)
            {
                var v = heatmap[x, y];
                if (v < minvalue)
                {
                    minvalue = v;
                }
                if (v > maxvalue)
                {
                    maxvalue = v;
                }
                //tex.SetPixel(x, y, c);
            }
        }
        for (int x = 0; x < tex.width; ++x)
        {
            for (int y = 0; y < tex.height; ++y)
            {
                var v  = (heatmap[x, y] - minvalue) / (maxvalue - minvalue);
                var hc = GISparser.valueToHeatColor(v);
                tex.SetPixel(x, y, hc);
            }
        }

        //details
        foreach (var way in gisdata.wayContainer)
        {
            drawWayOptimal(ref tex, way, chunkLow, chunkHigh);
        }

        return(tex);
    }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     sr.color = GISparser.valueToHeatColor(value);
 }