Exemple #1
0
        public SOMVisual(SOMVisualType type, int size, int width, int height, PictureSOM.SOM s)
        {
            _visualType = type;
            _boardSize = PictureSOM.SOMConstants.NUM_NODES_ACROSS; // assuming that across and down are the same
            _boardWidthFactor = (width - (2 * _border)) / size;
            _boardHeightFactor = (height - (2 * _border)) / size;

            _som = s;

            _children = new VisualCollection(this);
            DrawBoard();
            _children.Add(_boardDrawingVisual); // Render the grid

            if (_visualType == SOMVisualType.COMPETITION_LAYER_MAP)
            {
                CreateDrawingVisual_Text(s);
            }
            else if(_visualType == SOMVisualType.COMPETITION_LAYER_MAP_FIXED)
            {
                CreateDrawingVisual_Text_Fixed(s);
            }
            else if (_visualType == SOMVisualType.ERROR_MAP)
            {
                CreateDrawingVisual_ErrorMap(s);
            }
            _children.Add(_drawingVisual);

            // Add the event handler for MouseLeftButtonUp.
            this.MouseLeftButtonUp += new MouseButtonEventHandler(SOMVisual_MouseLeftButtonUp);
        }
Exemple #2
0
        public void CreateDrawingVisual_ErrorMap(PictureSOM.SOM _som)
        {
            this._som = _som;
            // Create an instance of a DrawingVisual.
            if (_drawingVisual == null)
            {
                _drawingVisual = new DrawingVisual();
            }

            // Retrieve the DrawingContext from the DrawingVisual.
            using (DrawingContext dc = _drawingVisual.RenderOpen())
            {
                for (int x = 0; x < _boardSize; x++)
                {
                    for (int y = 0; y < _boardSize; y++)
                    {
                        float[] weight = new float[] { _som.ErrorMap[x, y, 0], _som.ErrorMap[x, y, 1], _som.ErrorMap[x, y, 2] };
                        SolidColorBrush errorBrush = new SolidColorBrush(Color.FromRgb(
                            PictureSOM.SOMHelper.Convert_FloatToByte(weight[0]),
                            PictureSOM.SOMHelper.Convert_FloatToByte(weight[1]),
                            PictureSOM.SOMHelper.Convert_FloatToByte(weight[2])));
                        dc.DrawRectangle(errorBrush, null, new Rect(GetPosX(x), GetPosY(y), _boardWidthFactor, _boardHeightFactor));
                    }
                }
            }
            // Close the DrawingContext to persist changes to the DrawingVisual.
            //dc.Close();
        }
Exemple #3
0
        public void CreateDrawingVisual_Text_Fixed(PictureSOM.SOM _som)
        {
            this._som = _som;
            // Create an instance of a DrawingVisual.
            if (_drawingVisual == null)
            {
                _drawingVisual = new DrawingVisual();
            }

            // Retrieve the DrawingContext from the DrawingVisual.
            DrawingContext dc = _drawingVisual.RenderOpen();
            Typeface font = new Typeface("Verdana");
            int offsetX = Convert.ToInt32(_boardWidthFactor * .5) - 5;
            int offsetY = Convert.ToInt32(_boardHeightFactor * .5) - 5;
            for (int x = 0; x < _boardSize; x++)
            {
                for (int y = 0; y < _boardSize; y++)
                {
                    dc.DrawText(
                        new FormattedText(
                            _som.CompetitionLayer[x, y].GetImageCount().ToString(),
                            CultureInfo.GetCultureInfo("en-us"),
                            FlowDirection.LeftToRight,
                            font, 12, Brushes.Black),
                            new Point(GetPosX(x) + offsetX, GetPosY(y) + offsetY));
                }
            }
            dc.Close();
        }