Esempio n. 1
0
        /// <summary>
        /// A step in building the attention map
        /// </summary>
        /// <param name="position">The location shown</param>
        /// <param name="size">The size of the visible part</param>
        /// <param name="duration">Duration at that point</param>
        /// <param name="shouldRemove">Is positive or negative change, for UNDO</param>
        public void BuildActivationMap(PointF position,
                                       SizeF size,
                                       TimeSpan duration,
                                       bool shouldRemove)
        {
            if (AttentionMap != null)
            {
                ImageProxy <double> imageProxy = AttentionMap?.Proxy(
                    new Rectangle((int)(position.X - size.Width / 2), (int)(position.Y - size.Height / 2),
                                  (int)size.Width, (int)size.Height));
                //Apply a change to every pixel
                imageProxy?.ApplyFilter((value, location) =>
                {
                    var ix = (location.X / size.Width) * 2 - 1;
                    var iy = (location.Y / size.Height) * 2 - 1;
                    if (ix * ix + iy * iy > 1)//out of circle = original pixel
                    {
                        return(value);
                    }
                    var distance = Math.Pow((ix * ix + iy * iy), 0.5);

                    //=2*(1- 1.5^(8*dist-1) / (1.5^(8*dist-1)+1))
                    const double _base      = 1.5d;
                    const double _mult_dist = 8;
                    const double _off       = -1;
                    const double _mult      = 2;

                    var distanceFactor = _mult * (1 - Math.Pow(_base, _mult_dist * distance + _off) / (Math.Pow(_base, _mult_dist * distance + _off) + 1));

                    //If remove(subtract) multiply by minus one
                    var removeFactor = shouldRemove ? -1 : 1;
                    return(value += duration.TotalMilliseconds * distanceFactor * removeFactor);
                });
            }
        }