Exemple #1
0
        private async Task Generate()
        {
            SimplexNoise noise = new SimplexNoise((uint)items.Find(r => r.Name == "Seed").Value, (double)items.Find(r => r.Name == "Scale").Value, (double)items.Find(r => r.Name == "Persistance").Value);

            Bitmap src = new Bitmap((int)VisualElement.ResultImage.Width, (int)VisualElement.ResultImage.Height);

            double[,] t = await Heatmap.GenerateHeatmap(noise, (int)VisualElement.ResultImage.Height, (int)VisualElement.ResultImage.Width, await noise.NoiseMap((int)items.Find(r => r.Name == "Octaves").Value, FractalType.FBM, new int[2] {
                (int)VisualElement.ResultImage.Width, (int)VisualElement.ResultImage.Height
            }));

            for (int y = 0; y < VisualElement.ResultImage.Height; y++)
            {
                for (int x = 0; x < VisualElement.ResultImage.Width; x++)
                {
                    int val = (int)((t[y, x] + 1) * 127.5);
                    if (val > 255)
                    {
                        val = 225;
                    }
                    else if (val < 0)
                    {
                        val = 0;
                    }
                    src.SetPixel(x, y, System.Drawing.Color.FromArgb(val, val, val));
                }
            }

            VisualElement.Image = Utilities.BitmapToImageSource(src);
        }
Exemple #2
0
    private void GenerateHeatmap(string filename)
    {
        if (cyclists == null)
        {
            cyclists    = new AssetType[1];
            cyclists[0] = AssetType.Cyclist;
        }

        if (area == null)
        {
            Debug.LogError("Can't generate heatmap with unassigned area");
            return;
        }

        Bounds aabb = new Bounds(area.position, area.localScale);

        if (filename.EndsWith(TrafficIO.VISSIM_VEHICLES_EXTENSION))
        {
            TrafficData data = TrafficIO.Load(filename, columnSeparator, vectorSeparator, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Vehicles_Heatmap", cyclists, false);
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Cyclists_Heatmap", cyclists, true);
        }
        else if (filename.EndsWith(TrafficIO.VISSIM_PEDESTRIANS_EXTENSION))
        {
            TrafficData data = TrafficIO.Load(filename, columnSeparator, vectorSeparator, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Pedestrians_Heatmap");
        }
        else if (filename.EndsWith(TrafficIO.BINARY_VEHICLES_EXTENSION))
        {
            TrafficData data = TrafficIO.LoadBinary(filename, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Vehicles_Heatmap", cyclists, false);
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Cyclists_Heatmap", cyclists, true);
        }
        else if (filename.EndsWith(TrafficIO.BINARY_PEDESTRIANS_EXTENSION))
        {
            TrafficData data = TrafficIO.LoadBinary(filename, true);
            if (data == null)
            {
                return;
            }
            Heatmap.GenerateHeatmap(data, trafficMgr.transform.position, resolution, pointSize * 0.5f, aabb, logarithmic, "Pedestrians_Heatmap");
        }
        AssetDatabase.Refresh();
    }
Exemple #3
0
    void GenerateHeatMap()
    {
        Bounds aabb = new Bounds(area.position, area.localScale);

        if (heatmapPasses == null || heatmapPasses.Length == 0)
        {
            Heatmap.GenerateHeatmap(data, transform.position, heatmapResolution, pointRadius, aabb, logarithmic, name + "-Heatmap");
        }
        else
        {
            for (int i = 0; i < heatmapPasses.Length; i++)
            {
                Heatmap.GenerateHeatmap(data, transform.position, heatmapResolution, pointRadius, aabb, logarithmic, name + "-Heatmap" + (i + 1), heatmapPasses[i].assetTypes, heatmapPasses[i].include);
            }
        }
    }
        //private bool correctionFlag = false;

        public void ProcessFrame(ProcessVideoFrameContext context)
        {
            using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, context.InputFrame.Direct3DSurface))
                using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, context.OutputFrame.Direct3DSurface))
                    using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
                        using (var scaleEffect = new ScaleEffect())
                            using (CanvasSolidColorBrush solidColorBrush = new CanvasSolidColorBrush(_canvasDevice, _backgroundColor))
                            {
                                solidColorBrush.Opacity = _backgroundOpacity;
                                double rel = context.InputFrame.RelativeTime.Value.Ticks / (double)TimeSpan.TicksPerMillisecond;

                                //context.OutputFrame.Duration = new TimeSpan( (long)(frameLength * TimeSpan.TicksPerMillisecond));



                                int frameTimeCounter = (int)Math.Round(rel / _frameLength, 0);

                                int[] pitch = new int[_count];
                                int[] yaw   = new int[_count];
                                int[] fov   = new int[_count];

                                for (int i = 0; i < _count; i++)
                                {
                                    try
                                    {
                                        //pitch[i] = this.pitch[ (frameTimeCounter + (int)Math.Round(offset, 0)) * (count) + i];
                                        //fov[i] = this.fov[ (frameTimeCounter + (int)Math.Round(offset, 0)) * (count) + i];
                                        //yaw[i] = this.yaw[ (frameTimeCounter + (int)Math.Round(offset, 0)) * (count) + i];

                                        pitch[i] = this._pitch[(frameTimeCounter + (int)_offset) * (_count) + i];
                                        fov[i]   = this._fov[(frameTimeCounter + (int)_offset) * (_count) + i];
                                        yaw[i]   = this._yaw[(frameTimeCounter + (int)_offset) * (_count) + i];
                                    }
                                    catch (ArgumentOutOfRangeException ex)
                                    {
                                        Debug.WriteLine(ex.Message);
                                        pitch[i] = 0;
                                        fov[i]   = 0;
                                        yaw[i]   = 0;
                                    }
                                }

                                byte[]       tab = Heatmap.GenerateHeatmap(pitch, yaw, fov);
                                CanvasBitmap cb  = CanvasBitmap.CreateFromBytes(_canvasDevice, tab, 64, 64, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, 96, CanvasAlphaMode.Premultiplied);
                                scaleEffect.Source            = cb;
                                scaleEffect.Scale             = new System.Numerics.Vector2((float)_width / 64, (float)_height / 64);
                                scaleEffect.InterpolationMode = CanvasImageInterpolation.Cubic;
                                scaleEffect.BorderMode        = EffectBorderMode.Hard;


                                if (_graysclaleVideoFlag)
                                {
                                    var grayScaleEffect = new GrayscaleEffect
                                    {
                                        BufferPrecision = CanvasBufferPrecision.Precision8UIntNormalized,
                                        CacheOutput     = false,
                                        Source          = inputBitmap
                                    };
                                    ds.DrawImage(grayScaleEffect);
                                }
                                else
                                {
                                    ds.DrawImage(inputBitmap);
                                }

                                ds.DrawImage(scaleEffect, 0, 0, new Windows.Foundation.Rect {
                                    Height = _height, Width = _width
                                }, _heatmapOpacity);



                                if (_generateDots)
                                {
                                    for (int i = 0; i < _count; i++)
                                    {
                                        ds.FillCircle(yaw[i] * _width / 64, pitch[i] * _height / 64, _dotsRadius, _colors[i % 5]);
                                    }
                                }



                                ds.FillRectangle(new Windows.Foundation.Rect {
                                    Height = _height, Width = _width
                                }, solidColorBrush);

                                ds.Flush();
                            }
        }