Exemplo n.º 1
0
        /// <summary>
        /// Max pool layer.
        /// The max pool layers function is to progressively reduce the spatial size of the representation
        /// to reduce the amount of parameters and computation in the network.
        /// The reduction is only done on the width and height. Depth dimension is preserved.
        /// </summary>
        /// <param name="poolWidth">The width of the pool area (default is 2)</param>
        /// <param name="poolHeight">The height of the pool area (default is 2)</param>
        /// <param name="stride">Controls the distance between each neighbouring pool areas (default is 2)</param>
        /// <param name="padWidth">Zero padding for the width dimension (default is 0)</param>
        /// <param name="padHeight">Zero padding for the height dimension (default is 0)</param>
        public MaxPool2DLayer(int poolWidth, int poolHeight, int stride, int padWidth, int padHeight)
        {
            if (poolWidth < 1)
            {
                throw new ArgumentException("poolWidth is less than 1: " + poolWidth);
            }
            if (poolHeight < 1)
            {
                throw new ArgumentException("poolHeight is less than 1: " + poolHeight);
            }
            if (padWidth < 0)
            {
                throw new ArgumentException("padWidth is less than 0: " + padWidth);
            }
            if (padHeight < 0)
            {
                throw new ArgumentException("padHeight is less than 0: " + padHeight);
            }
            if (stride < 1)
            {
                throw new ArgumentException("stride is less than 0: " + stride);
            }

            m_poolWidth    = poolWidth;
            m_poolHeight   = poolHeight;
            m_stride       = stride;
            m_padWidth     = padWidth;
            m_padHeight    = padHeight;
            BorderMode     = BorderMode.Undefined;
            ActivationFunc = Activation.Undefined;
        }
Exemplo n.º 2
0
        public void CopyFrom(RectStyle other)
        {
            color = other.color;

            enableGradient = other.enableGradient;
            gradientAngle  = other.gradientAngle;

            gradient?.Clear();

            if (other.gradient != null)
            {
                if (gradient == null)
                {
                    gradient = new Gradient();
                }

                foreach (var keyPoint in other.gradient)
                {
                    gradient.Add(keyPoint);
                }
            }

            borderMode  = other.borderMode;
            borderColor = other.borderColor;
            borderWidth = other.borderWidth;

            cornerRadius = other.cornerRadius;

            enableBoxShadow     = other.enableBoxShadow;
            boxShadowColor      = other.boxShadowColor;
            boxShadowBlurRadius = other.boxShadowBlurRadius;
            boxShadowOffset     = other.boxShadowOffset;
            boxShadowInner      = other.boxShadowInner;
        }
Exemplo n.º 3
0
 public KenPanel()
 {
     this.borderMode    = BorderMode.None;
     this.borderColor   = Color.Black;
     this.border3DStyle = System.Windows.Forms.Border3DStyle.Etched;
     this.borderSide    = ToolStripStatusLabelBorderSides.All;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Max pool layer.
 /// The max pool layers function is to progressively reduce the spatial size of the representation
 /// to reduce the amount of parameters and computation in the network.
 /// The reduction is only done on the width and height. Depth dimension is preserved.
 /// </summary>
 /// <param name="poolWidth">The width of the pool area (default is 2)</param>
 /// <param name="poolHeight">The height of the pool area (default is 2)</param>
 /// <param name="stride">Controls the distance between each neighbouring pool areas (default is 2)</param>
 /// <param name="borderMode">Border mode of the max pool operation.
 /// This will set the width and height padding automatically based on the selected border mode: Valid, Same or Full (default is Valid).</param>
 public MaxPool2DLayer(int poolWidth, int poolHeight, int stride = 2, BorderMode borderMode = BorderMode.Valid)
     : this(poolWidth, poolHeight, stride,
            ConvUtils.PaddingFromBorderMode(poolWidth, borderMode),
            ConvUtils.PaddingFromBorderMode(poolHeight, borderMode))
 {
     BorderMode = borderMode;
 }
Exemplo n.º 5
0
 /// <summary>
 /// 2D Convolutional layer using GEMM implementation
 /// based on: https://petewarden.com/2015/04/20/why-gemm-is-at-the-heart-of-deep-learning/
 /// and: https://arxiv.org/pdf/1410.0759.pdf
 /// </summary>
 /// <param name="filterWidth">The width of the filters</param>
 /// <param name="filterHeight">The height of the filters</param>
 /// <param name="filterCount">The number of filters</param>
 /// <param name="stride">Controls the distance between each neighbouring filter (default is 1)</param>
 /// <param name="borderMode">Border mode of the convolutional operation.
 /// This will set the width and height padding automatically based on the selected border mode: Valid, Same or Full (default is Valid)</param>
 /// <param name="activation">Type of activation function used (default is Relu)</param>
 public Conv2DLayer(int filterWidth, int filterHeight, int filterCount, int stride = 1,
                    BorderMode borderMode = BorderMode.Valid, Activation activation = Activation.Relu)
     : this(filterWidth, filterHeight, filterCount, stride,
            ConvUtils.PaddingFromBorderMode(filterWidth, borderMode),
            ConvUtils.PaddingFromBorderMode(filterHeight, borderMode))
 {
     BorderMode = borderMode;
 }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 public CPanelPlus() : base()
 {
     InitializeComponent();
     this.borderMode    = BorderMode.None;
     this.borderColor   = Color.Black;
     this.border3DStyle = System.Windows.Forms.Border3DStyle.Etched;
     this.borderSide    = ToolStripStatusLabelBorderSides.All;
 }
Exemplo n.º 7
0
 protected void ComputeObstacles(CommandBuffer cmd, RenderTexture obstacles, BorderMode borderMode)
 {
     cmd.BeginSample("ComputeObstacles");
     cmd.SetComputeTextureParam(computeShader, SetObstaclesKernel, "_Obstacles", obstacles);
     cmd.SetComputeFloatParam(computeShader, "_BorderMode", (int)borderMode);
     DispatchCompute(cmd, SetObstaclesKernel, (int)size.x, (int)size.y, (int)size.z);
     cmd.EndSample("ComputeObstacles");
 }
Exemplo n.º 8
0
        void CalculateSpriteBased(Sprite sprite, BorderMode borderMode)
        {
            var lastSprite = _lastUsedSprite;

            _lastUsedSprite = sprite;
            var spriteErrors = Diagnostics.CheckSprite(sprite);

            if (spriteErrors != Errors.NoError)
            {
                if (lastSprite != sprite)
                {
                    WarnSpriteErrors(spriteErrors);
                }
                CalculateSolidFill();
                return;
            }
            if (!sprite)
            {
                CalculateSolidFill();
                return;
            }
            FillCommonParameters();
            var spriteRect    = Mathr.Move(Mathr.ToVector(sprite.rect), sprite.textureRect.position - sprite.rect.position - sprite.textureRectOffset);
            var textureRect   = Mathr.ToVector(sprite.textureRect);
            var textureBorder = Mathr.BorderOf(spriteRect, textureRect);
            var textureSize   = Vector2.zero;

            if (sprite.texture != null)
            {
                textureSize = new Vector2(sprite.texture.width, sprite.texture.height);
            }
            var fullMaskRect = LocalMaskRect(Vector4.zero);

            _parameters.maskRectUV = Mathr.Div(textureRect, textureSize);
            if (borderMode == BorderMode.Simple)
            {
                var textureRectInFullRect = Mathr.Div(textureBorder, Mathr.Size(spriteRect));
                _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, Mathr.Mul(textureRectInFullRect, Mathr.Size(fullMaskRect)));
            }
            else
            {
                _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, textureBorder * GraphicToCanvasScale(sprite));
                var fullMaskRectUV = Mathr.Div(spriteRect, textureSize);
                var adjustedBorder = AdjustBorders(sprite.border * GraphicToCanvasScale(sprite), fullMaskRect);
                _parameters.maskBorder   = LocalMaskRect(adjustedBorder);
                _parameters.maskBorderUV = Mathr.ApplyBorder(fullMaskRectUV, Mathr.Div(sprite.border, textureSize));
            }
            _parameters.texture    = sprite.texture;
            _parameters.borderMode = borderMode;
            if (borderMode == BorderMode.Tiled)
            {
                _parameters.tileRepeat = MaskRepeat(sprite, _parameters.maskBorder);
            }
        }
Exemplo n.º 9
0
 void Start()
 {
     try
     {
         dm         = GameObject.Find("DispensaryManager").GetComponent <DispensaryManager>();
         borderMode = BorderMode.activeOnUI;
     }
     catch (NullReferenceException)
     {
         // do nothing
     }
 }
        /// <summary>
        /// Gets the filter grid width based on input length, filter size, stride and padding.
        /// </summary>
        /// <param name="inputLength"></param>
        /// <param name="filterSize"></param>
        /// <param name="stride"></param>
        /// <param name="padding"></param>
        /// <param name="borderMode"></param>
        /// <returns></returns>
        public static int GetFilterGridLength(int inputLength, int filterSize,
                                              int stride, int padding, BorderMode borderMode)
        {
            // BorderMode.Same pads with half the filter size on both sides (one less on
            // the second side for an even filter size)
            if ((borderMode == BorderMode.Same) && ((filterSize % 2) == 0))
            {
                return((int)Math.Floor((((inputLength + ((padding + padding) - 1)) - filterSize) / (double)stride) + 1));
            }

            return((int)Math.Floor((((inputLength + (padding * 2)) - filterSize) / (double)stride) + 1));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="data_im"></param>
        /// <param name="channels"></param>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <param name="kernel_h"></param>
        /// <param name="kernel_w"></param>
        /// <param name="pad_h"></param>
        /// <param name="pad_w"></param>
        /// <param name="stride_h"></param>
        /// <param name="stride_w"></param>
        /// <param name="borderMode"></param>
        /// <param name="data_col"></param>
        public static void Batch_Im2Col(Matrix <float> data_im, int channels, int height, int width,
                                        int kernel_h, int kernel_w, int pad_h, int pad_w, int stride_h, int stride_w,
                                        BorderMode borderMode, Matrix <float> data_col)
        {
            int height_col = GetFilterGridLength(height, kernel_h, stride_h, pad_h, borderMode);
            int width_col  = GetFilterGridLength(width, kernel_w, stride_w, pad_w, borderMode);
            var batchSize  = data_im.RowCount;

            int channels_col = channels * kernel_h * kernel_w;

            var data_imData  = data_im.Data();
            var data_colData = data_col.Data();

            Parallel.For(0, batchSize, batchItem =>
            {
                var batchRowOffSet = batchItem * width_col * height_col;

                for (int c = 0; c < channels_col; ++c)
                {
                    int w_offset     = c % kernel_w;
                    int h_offset     = (c / kernel_w) % kernel_h;
                    int c_im         = c / kernel_h / kernel_w;
                    var cImRowOffSet = c_im * height;

                    for (int h = 0; h < height_col; ++h)
                    {
                        var rowOffSet = h * width_col;
                        for (int w = 0; w < width_col; ++w)
                        {
                            int h_pad = ((h * stride_h) - pad_h) + h_offset;
                            int w_pad = ((w * stride_w) - pad_w) + w_offset;

                            var outColIndex = batchRowOffSet + rowOffSet + w;
                            var outputIndex = (outColIndex * data_col.RowCount) + c;

                            var inputColIndex = ((cImRowOffSet + h_pad) * width) + w_pad;
                            var inputIndex    = (inputColIndex * batchSize) + batchItem;

                            if ((h_pad >= 0) && (h_pad < height) && (w_pad >= 0) && (w_pad < width))
                            {
                                data_colData[outputIndex] = data_imData[inputIndex];
                            }
                            else
                            {
                                data_colData[outputIndex] = 0;
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 12
0
        public I <T> AddBorder(int top, int left, int bottom, int right, BorderMode mode = BorderMode.Zero)
        {
            var r = PadZero(top, left, bottom, right);

            switch (mode)
            {
            case BorderMode.Replicate:
                r.FillBorderReplicate(top, left, bottom, right);
                break;

            case BorderMode.Reflect:
                r.FillBorderReflect(top, left, bottom, right);
                break;
            }
            return(r);
        }
Exemplo n.º 13
0
        void CalculateSpriteBased(Sprite sprite, BorderMode borderMode)
        {
            var lastSprite = _lastUsedSprite;

            _lastUsedSprite = sprite;
            var spriteErrors = Diagnostics.CheckSprite(sprite);

            if (spriteErrors != Errors.NoError)
            {
                if (lastSprite != sprite)
                {
                    WarnSpriteErrors(spriteErrors);
                }
                CalculateSolidFill();
                return;
            }
            if (!sprite)
            {
                CalculateSolidFill();
                return;
            }
            FillCommonParameters();
            var inner        = DataUtility.GetInnerUV(sprite);
            var outer        = DataUtility.GetOuterUV(sprite);
            var padding      = DataUtility.GetPadding(sprite);
            var fullMaskRect = LocalMaskRect(Vector4.zero);

            _parameters.maskRectUV = outer;
            if (borderMode == BorderMode.Simple)
            {
                var normalizedPadding = Mathr.Div(padding, sprite.rect.size);
                _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, Mathr.Mul(normalizedPadding, Mathr.Size(fullMaskRect)));
            }
            else
            {
                _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, padding * SpriteToCanvasScale(sprite));
                var adjustedBorder = AdjustBorders(sprite.border * SpriteToCanvasScale(sprite), fullMaskRect);
                _parameters.maskBorder   = LocalMaskRect(adjustedBorder);
                _parameters.maskBorderUV = inner;
            }
            _parameters.texture    = sprite.texture;
            _parameters.borderMode = borderMode;
            if (borderMode == BorderMode.Tiled)
            {
                _parameters.tileRepeat = MaskRepeat(sprite, _parameters.maskBorder);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="data_col"></param>
        /// <param name="channels"></param>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <param name="patch_h"></param>
        /// <param name="patch_w"></param>
        /// <param name="pad_h"></param>
        /// <param name="pad_w"></param>
        /// <param name="stride_h"></param>
        /// <param name="stride_w"></param>
        /// <param name="borderMode"></param>
        /// <param name="data_im"></param>
        public static void Batch_Col2Im(Matrix <float> data_col, int channels, int height, int width,
                                        int patch_h, int patch_w, int pad_h, int pad_w, int stride_h, int stride_w,
                                        BorderMode borderMode, Matrix <float> data_im)
        {
            int height_col   = GetFilterGridLength(height, patch_h, stride_h, pad_h, borderMode);
            int width_col    = GetFilterGridLength(width, patch_w, stride_w, pad_w, borderMode);
            int channels_col = channels * patch_h * patch_w;
            var batchSize    = data_im.RowCount;

            var data_colData = data_col.Data();
            var data_imData  = data_im.Data();

            Parallel.For(0, batchSize, batchItem =>
            {
                var batchRowOffSet = batchItem * width_col * height_col;

                for (int c = 0; c < channels_col; ++c)
                {
                    int w_offset      = c % patch_w;
                    int h_offset      = (c / patch_w) % patch_h;
                    int c_im          = c / patch_h / patch_w;
                    var c_ImRowOffSet = c_im * height;

                    for (int h = 0; h < height_col; ++h)
                    {
                        var rowOffSet = h * width_col;
                        int h_pad     = ((h * stride_h) - pad_h) + h_offset;

                        for (int w = 0; w < width_col; ++w)
                        {
                            int w_pad = ((w * stride_w) - pad_w) + w_offset;
                            if ((h_pad >= 0) && (h_pad < height) && (w_pad >= 0) && (w_pad < width))
                            {
                                var colColIndex = batchRowOffSet + rowOffSet + w;
                                var outIndex    = ((c_ImRowOffSet + h_pad) * width) + w_pad;

                                var imIndex  = (outIndex * batchSize) + batchItem;
                                var colIndex = (colColIndex * data_col.RowCount) + c;

                                var newValue         = data_imData[imIndex] + data_colData[colIndex];
                                data_imData[imIndex] = newValue;
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 15
0
        private void TransformAlign(float positionValue, BorderMode borderMode, Orientation orientation)
        {
            // History
            LayersTransformAddHistory history = new LayersTransformAddHistory(HistoryType.LayersTransformAdd_Move);

            // Selection
            this.SelectionViewModel.SetValue((layerage) =>
            {
                Transformer transformer = layerage.GetActualTransformer();
                float value             = transformer.GetBorderValue(borderMode);

                float distance = positionValue - value;
                if (distance == 0)
                {
                    return;
                }
                Vector2 vector = orientation == Orientation.Horizontal ?
                                 new Vector2(distance, 0) :
                                 new Vector2(0, distance);

                layerage.SetValueWithChildren((layerage2) =>
                {
                    ILayer layer = layerage2.Self;

                    // History
                    history.PushTransform(layer, vector);

                    // Refactoring
                    layer.IsRefactoringTransformer = true;
                    layer.IsRefactoringRender      = true;
                    layer.IsRefactoringIconRender  = true;
                    layerage.RefactoringParentsTransformer();
                    layerage.RefactoringParentsRender();
                    layerage.RefactoringParentsIconRender();
                    layer.CacheTransform();
                    layer.TransformAdd(vector);
                });
            });
            // Refactoring
            this.SelectionViewModel.Transformer = this.SelectionViewModel.RefactoringTransformer();

            // History
            this.ViewModel.HistoryPush(history);

            this.ViewModel.Invalidate(); // Invalidate}
        }
        /// <summary>
        /// Gets value by left, right, top, bottom.
        /// </summary>
        /// <param name="borderMode"> The border mode </param>
        /// <returns> The produced value. </returns>
        public float GetBorderValue(BorderMode borderMode)
        {
            switch (borderMode)
            {
            case BorderMode.MinX: return(0);

            case BorderMode.CenterX: return(this.Width / 2.0f);

            case BorderMode.MaxX: return(this.Width);

            case BorderMode.MinY: return(0);

            case BorderMode.CenterY: return(this.Height / 2.0f);

            case BorderMode.MaxY: return(this.Height);
            }
            return(0);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Gets value by left, right, top, bottom.
        /// </summary>
        /// <param name="borderMode"> The border mode </param>
        /// <returns> The produced value. </returns>
        public float GetBorderValue(BorderMode borderMode)
        {
            switch (borderMode)
            {
            case BorderMode.MinX: return(this.MinX);

            case BorderMode.CenterX: return(this.Center.X);

            case BorderMode.MaxX: return(this.MaxX);

            case BorderMode.MinY: return(this.MinY);

            case BorderMode.CenterY: return(this.Center.Y);

            case BorderMode.MaxY: return(this.MaxY);
            }
            return(this.MinX);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets value by left, right, top, bottom.
        /// </summary>
        /// <param name="borderMode"> The border mode </param>
        /// <returns> The produced value. </returns>
        public float GetBorderValue(BorderMode borderMode)
        {
            switch (borderMode)
            {
            case BorderMode.MinX: return(this.Left);

            case BorderMode.CenterX: return(this.CenterX);

            case BorderMode.MaxX: return(this.Right);

            case BorderMode.MinY: return(this.Top);

            case BorderMode.CenterY: return(this.CenterY);

            case BorderMode.MaxY: return(this.Bottom);
            }
            return(this.Left);
        }
Exemplo n.º 19
0
        private void TransformAlign(BorderMode borderMode, Orientation orientation)
        {
            switch (this.Mode)
            {
            case ListViewSelectionMode.Single:
            {
                float positionValue = this.ViewModel.CanvasTransformer.GetBorderValue(borderMode);
                this.TransformAlign(positionValue, borderMode, orientation);
            }
            break;

            case ListViewSelectionMode.Multiple:
            {
                Transformer transformer   = this.Transformer;
                float       positionValue = transformer.GetBorderValue(borderMode);
                this.TransformAlign(positionValue, borderMode, orientation);
            }
            break;
            }
        }
Exemplo n.º 20
0
        public static void warpAffine(Mat src, Mat dst, System.Numerics.Matrix3x2 trans, Size dSize,
                                      Interpolation inter   = Interpolation.INTER_LINEAR, bool inverseMap      = false,
                                      BorderMode borderMode = BorderMode.BORDER_CONSTANT, double[] borderValue = null)
        {
            Mat    transMat       = trans;
            int    flags          = inverseMap ? ((int)InverseMap.WARP_INVERSE_MAP | (int)inter) : (int)inter;
            Mat    matBorderValue = null;
            IntPtr ptrBorderValue = IntPtr.Zero;

            if (borderMode == BorderMode.BORDER_CONSTANT && borderValue != null && borderValue.Length > 0)
            {
                matBorderValue = new Mat(1, borderValue.Length, Mat.makeType(1, Mat.MatDepth.CV_64F));
                if (matBorderValue.Valid && matBorderValue.copyAll(borderValue, 0, borderValue.Length))
                {
                    ptrBorderValue = matBorderValue.Data;
                }
            }
            NativeInvoker.coreCvWarpAffine(src.MatObj, dst.MatObj, transMat.MatObj, (int)dSize.w, (int)dSize.h,
                                           flags, (int)borderMode, ptrBorderValue);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filterSize"></param>
        /// <param name="borderMode"></param>
        /// <returns></returns>
        public static int PaddingFromBorderMode(int filterSize, BorderMode borderMode)
        {
            switch (borderMode)
            {
            case BorderMode.Same:
                return(filterSize / 2);

            case BorderMode.Valid:
                return(0);

            case BorderMode.Full:
                return(filterSize - 1);

            case BorderMode.Undefined:
                return(0);

            default:
                throw new ArgumentException("Unsupported border mode: " + borderMode);
            }
        }
Exemplo n.º 22
0
    // 0 = Green
    // 1 = Red
    // 2 = Yellow/Orange
    public void ChangeColor(int index)
    {
        switch (index)
        {
        case 0:
            screenborder.sprite = SpriteManager.screenborder_Green;
            borderMode          = BorderMode.activeOnUI;
            break;

        case 1:
            screenborder.sprite = SpriteManager.screenborder_Red;
            borderMode          = BorderMode.alwaysActive;
            break;

        case 2:
            screenborder.sprite = SpriteManager.screenborder_Yellow;
            borderMode          = BorderMode.alwaysActive;
            break;
        }
    }
Exemplo n.º 23
0
        /// <summary>
        /// 2D Convolutional layer using GEMM implementation
        /// based on: https://petewarden.com/2015/04/20/why-gemm-is-at-the-heart-of-deep-learning/
        /// and: https://arxiv.org/pdf/1410.0759.pdf
        /// </summary>
        /// <param name="filterWidth">The width of the filters</param>
        /// <param name="filterHeight">The height of the filters</param>
        /// <param name="filterCount">The number of filters</param>
        /// <param name="stride">Controls the distance between each neighbouring filter (default is 1)</param>
        /// <param name="padWidth">Zero padding for the width dimension (default is 0)</param>
        /// <param name="padHeight">Zero padding for the height dimension (default is 0)</param>
        /// <param name="activation">Type of activation function used (default is Relu)</param>
        public Conv2DLayer(int filterWidth, int filterHeight, int filterCount, int stride,
                           int padWidth, int padHeight, Activation activation = Activation.Relu)
        {
            if (filterWidth < 1)
            {
                throw new ArgumentException("filterWidth is less than 1: " + filterWidth);
            }
            if (filterHeight < 1)
            {
                throw new ArgumentException("poolHeight is less than 1: " + filterHeight);
            }
            if (filterCount < 1)
            {
                throw new ArgumentException("filterCount is less than 1: " + filterCount);
            }
            if (padWidth < 0)
            {
                throw new ArgumentException("padWidth is less than 0: " + padWidth);
            }
            if (padHeight < 0)
            {
                throw new ArgumentException("padHeight is less than 0: " + padHeight);
            }
            if (stride < 1)
            {
                throw new ArgumentException("stride is less than 0: " + stride);
            }


            FilterWidth  = filterWidth;
            FilterHeight = filterHeight;
            FilterCount  = filterCount;

            ActivationFunc = activation;
            m_stride       = stride;
            m_padWidth     = padWidth;
            m_padHeight    = padHeight;
            BorderMode     = BorderMode.Undefined;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="data_convolutedRowMajor"></param>
        /// <param name="channels"></param>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <param name="kernel_h"></param>
        /// <param name="kernel_w"></param>
        /// <param name="pad_h"></param>
        /// <param name="pad_w"></param>
        /// <param name="stride_h"></param>
        /// <param name="stride_w"></param>
        /// <param name="borderMode"></param>
        /// <param name="convoluted"></param>
        public static void ReshapeRowMajorToConvolutionLayout(Matrix <float> data_convolutedRowMajor,
                                                              int channels, int height, int width,
                                                              int kernel_h, int kernel_w, int pad_h, int pad_w, int stride_h, int stride_w,
                                                              BorderMode borderMode, Matrix <float> convoluted)
        {
            int height_col = GetFilterGridLength(height, kernel_h, stride_h, pad_h, borderMode);
            int width_col  = GetFilterGridLength(width, kernel_w, stride_w, pad_w, borderMode);

            var columnWidth = height_col * width_col;
            var filterCount = convoluted.RowCount;
            var batchSize   = data_convolutedRowMajor.RowCount;

            var convolutedData = convoluted.Data();
            var data_convolutedRowMajorData = data_convolutedRowMajor.Data();

            Parallel.For(0, batchSize, batchItem =>
            {
                var batchOffSet = batchItem * columnWidth;

                for (int filter = 0; filter < filterCount; filter++)
                {
                    var rowOffSet = filter * columnWidth;
                    for (int column = 0; column < columnWidth; column++)
                    {
                        // get value from row major data
                        var rowMajorIndex = rowOffSet + column;
                        var index         = (rowMajorIndex * batchSize) + batchItem;
                        var rowValue      = data_convolutedRowMajorData[index];

                        // set value in conv data
                        var convIndex             = ((batchOffSet + column) * filterCount) + filter;
                        convolutedData[convIndex] = rowValue;
                    }
                }
            });
        }
Exemplo n.º 25
0
        public void CopyFromLerped(RectStyle a, RectStyle b, float t)
        {
            color = Color.Lerp(a.color, b.color, t);

            if ((a.gradient?.keyPointCount ?? 0) != (b.gradient?.keyPointCount ?? 0))
            {
                // TODO
            }
            else if (a.gradient != null && b.gradient != null && a.gradient.keyPointCount > 0)
            {
                gradientAngle = Mathf.LerpAngle(a.gradientAngle, b.gradientAngle, t);

                if (gradient == null)
                {
                    gradient = new Gradient();
                }
                else
                {
                    gradient.Clear();
                }

                for (var i = 0; i < a.gradient.keyPointCount; ++i)
                {
                    gradient.Add(new GradientKeyPoint
                    {
                        color    = Color.Lerp(a.gradient[i].color, b.gradient[i].color, t),
                        progress = Mathf.Lerp(a.gradient[i].progress, b.gradient[i].progress, t)
                    });
                }
            }

            enableGradient = a.enableGradient || b.enableGradient;
            borderMode     = a.borderMode | b.borderMode;
            borderColor    = a.HasBorder != b.HasBorder
                ? a.HasBorder
                    ? a.borderColor
                    : b.borderColor
                : Color.Lerp(a.borderColor, b.borderColor, t);
            borderWidth = Mathf.Lerp(a.HasBorder ? a.borderWidth : 0f, b.HasBorder ? b.borderWidth : 0f, t);

            cornerRadius = Mathf.Lerp(a.cornerRadius, b.cornerRadius, t);

            var boxShadowColorA = a.enableBoxShadow ? a.boxShadowColor : b.boxShadowColor;
            var boxShadowColorB = b.enableBoxShadow ? b.boxShadowColor : a.boxShadowColor;

            if (!a.enableBoxShadow)
            {
                boxShadowColorA.a = 0f;
            }
            if (!b.enableBoxShadow)
            {
                boxShadowColorB.a = 0f;
            }

            enableBoxShadow     = a.enableBoxShadow || b.enableBoxShadow;
            boxShadowColor      = Color.Lerp(boxShadowColorA, boxShadowColorB, t);
            boxShadowBlurRadius = Mathf.Lerp(
                a.enableBoxShadow ? a.boxShadowBlurRadius : b.boxShadowBlurRadius,
                b.enableBoxShadow ? b.boxShadowBlurRadius : a.boxShadowBlurRadius, t);
            boxShadowOffset = Vector2.Lerp(
                a.enableBoxShadow ? a.boxShadowOffset : b.boxShadowOffset,
                b.enableBoxShadow ? b.boxShadowOffset : a.boxShadowOffset, t);
            boxShadowInner = Mathf.Lerp(
                a.enableBoxShadow ? a.boxShadowInner : b.boxShadowInner,
                b.enableBoxShadow ? b.boxShadowInner : a.boxShadowInner, t);
        }
Exemplo n.º 26
0
        public bool SetCss(string css)
        {
            if (css == null)
            {
                return(true);
            }

            // Get rid of comments
            css = _sCssComment.Replace(css, match => new string(match.Value
                                                                .Select(x => char.IsWhiteSpace(x) ? x : ' ')
                                                                .ToArray()));

            var newColor          = color;
            var newEnableGradient = enableGradient;
            var newGradient       = new Gradient();

            if (gradient != null)
            {
                foreach (var keyPoint in gradient)
                {
                    newGradient.Add(keyPoint);
                }
            }

            var newGradientAngle = gradientAngle;

            var newBorderMode  = borderMode;
            var newBorderColor = borderColor;
            var newBorderWidth = borderWidth;

            var newCornerRadius = cornerRadius;

            var valid      = true;
            var hasOpacity = false;

            foreach (Match match in _sCssStatement.Matches(css))
            {
                var command = match.Groups["command"].Value;
                var value   = match.Groups["value"].Value;

                switch (command)
                {
                case "background":
                {
                    var colorMatch = _sCssColor.Match(value);
                    if (colorMatch.Success && colorMatch.Index == 0)
                    {
                        newColor          = ParseColor(colorMatch, hasOpacity ? newColor.a : 1f);
                        newEnableGradient = false;
                        break;
                    }

                    var gradientMatch = _sCssLinearGradient.Match(value);
                    if (gradientMatch.Success && gradientMatch.Index == 0)
                    {
                        newColor          = Color.white;
                        newGradientAngle  = float.Parse(gradientMatch.Groups["angle"].Value);
                        newEnableGradient = true;

                        newGradient.Clear();

                        foreach (Capture capture in gradientMatch.Groups["point"].Captures)
                        {
                            var pointMatch = _sCssGradientPoint.Match(capture.Value);

                            newGradient.Add(new GradientKeyPoint
                                {
                                    color    = ParseColor(pointMatch.Groups["color"].Value),
                                    progress = pointMatch.Groups["percent"].Success
                                        ? float.Parse(pointMatch.Groups["percent"].Value) / 100f : 0f
                                });
                        }

                        break;
                    }

                    valid = false;
                    break;
                }

                case "opacity":
                {
                    float opacity;
                    if (float.TryParse(value, out opacity))
                    {
                        newColor.a = opacity;
                        hasOpacity = true;
                        break;
                    }

                    valid = false;
                    break;
                }

                case "border":
                {
                    var borderMatch = _sCssBorder.Match(value);
                    if (borderMatch.Success && borderMatch.Index == 0)
                    {
                        newBorderMode  = BorderMode.All;
                        newBorderColor = ParseColor(borderMatch.Groups["color"].Value);
                        newBorderWidth = ParsePixels(borderMatch.Groups["width"].Value);

                        valid = true;
                        break;
                    }

                    valid = false;
                    break;
                }

                case "border-radius":
                {
                    var pixelsMatch = _sCssPixels.Match(value);
                    if (pixelsMatch.Success && pixelsMatch.Index == 0)
                    {
                        newCornerRadius = ParsePixels(pixelsMatch.Value);
                        valid           = true;
                        break;
                    }

                    valid = false;
                    break;
                }
                }
            }

            if (valid)
            {
                color          = newColor;
                enableGradient = newEnableGradient;
                gradientAngle  = newGradientAngle;
                borderMode     = newBorderMode;
                borderColor    = newBorderColor;
                borderWidth    = newBorderWidth;
                cornerRadius   = newCornerRadius;
                gradient       = newGradient;
            }

            return(valid);
        }