コード例 #1
0
        /// <summary>
        /// Shifts values (the new margins get zero)
        /// </summary>
        /// <param name="sweep">The other axis (if x's are getting shifted, then do it for each y)</param>
        /// <param name="shift">The row/column that has values changing. ex: [x] = [x+1]</param>
        private void TranslateValues(AxisFor sweep, AxisFor shift)
        {
            int amount;
            if (!int.TryParse(txtMoveAmount.Text, out amount))
            {
                amount = 1;
            }

            amount *= shift.IsPos ? 1 : -1;

            foreach (int sweepIndex in sweep.Iterate())
            {
                foreach (int shiftIndex in shift.Iterate())
                {
                    int toX = -1;
                    int toY = -1;
                    sweep.Set2DIndex(ref toX, ref toY, sweepIndex);
                    shift.Set2DIndex(ref toX, ref toY, shiftIndex);

                    int fromX = -1;
                    int fromY = -1;
                    sweep.Set2DIndex(ref fromX, ref fromY, sweepIndex);
                    shift.Set2DIndex(ref fromX, ref fromY, shiftIndex + amount);

                    double value = 0;
                    if (fromX >= 0 && fromX < _width && fromY >= 0 && fromY < _height)
                    {
                        value = _values[fromY * _width + fromX];
                    }

                    _values[toY * _width + toX] = value;
                }
            }

            RebuildBars();
            PixelValueChanged();
        }
コード例 #2
0
        private static void OverlayRow(double[] values, int width, int orthIndex, double[] overlay, AxisFor orth, AxisFor edge, /*double opacity,*/ bool isLeftToRight)
        {
            int x = -1;
            int y = -1;
            orth.Set2DIndex(ref x, ref y, orthIndex);

            for (int cntr = 0; cntr < overlay.Length; cntr++)
            {
                int edgeIndex = -1;
                if (isLeftToRight)
                {
                    //edgeIndex = edge.Start + (cntr * edge.Increment);
                    edgeIndex = edge.Start + ((cntr + 1) * edge.Increment);
                }
                else
                {
                    //edgeIndex = edge.Stop - (cntr * edge.Increment);
                    edgeIndex = edge.Stop - ((cntr + 1) * edge.Increment);
                }

                edge.Set2DIndex(ref x, ref y, edgeIndex);

                int index = (y * width) + x;
                //values[index] = UtilityCore.GetScaledValue(values[index], overlay[cntr], 0d, 1d, opacity);
                values[index] = overlay[cntr];
            }
        }
コード例 #3
0
        /// <summary>
        /// For each pixel in this row, pick a random pixel from a box above
        /// </summary>
        /// <remarks>
        /// At each pixel, this draws from a box of size orthDepth x (edgeDepth*2)+1
        /// </remarks>
        /// <param name="orthIndex">The row being copied to</param>
        private static void CopyRandomPixels(double[] values, int width, int orthIndex, int orthInc, int orthDepth, int edgeDepth, AxisFor orth, AxisFor edge, Random rand)
        {
            // See how many rows to randomly pull from
            int orthDepthStart = orthIndex + orthInc;
            int orthDepthStop = orthIndex + (orthDepth * orthInc);
            UtilityCore.MinMax(ref orthDepthStart, ref orthDepthStop);
            int orthAdd = orthInc < 0 ? 1 : 0;

            foreach (int edgeIndex in edge.Iterate())
            {
                // Figure out which column to pull from
                int toEdge = -1;
                do
                {
                    toEdge = rand.Next(edgeIndex - edgeDepth, edgeIndex + edgeDepth + 1);
                } while (!edge.IsBetween(toEdge));

                // Figure out which row to pull from
                int toOrth = rand.Next(orthDepthStart, orthDepthStop) + orthAdd;

                // From XY
                int fromX = -1;
                int fromY = -1;
                orth.Set2DIndex(ref fromX, ref fromY, toOrth);
                edge.Set2DIndex(ref fromX, ref fromY, toEdge);

                // To XY
                int toX = -1;
                int toY = -1;
                orth.Set2DIndex(ref toX, ref toY, orthIndex);
                edge.Set2DIndex(ref toX, ref toY, edgeIndex);

                // Copy pixel
                values[(toY * width) + toX] = values[(fromY * width) + fromX];
            }
        }
コード例 #4
0
        private static Convolution2D CopyRect(double[] values, int width, AxisFor edge, AxisFor orth, bool shouldRotate180)
        {
            if (shouldRotate180)
            {
                return CopyRect(values, width, new AxisFor(edge.Axis, edge.Stop, edge.Start), new AxisFor(orth.Axis, orth.Stop, orth.Start), false);
            }

            double[] retVal = new double[edge.Length * orth.Length];

            int index = 0;

            foreach (int orthIndex in orth.Iterate())
            {
                int x = -1;
                int y = -1;
                orth.Set2DIndex(ref x, ref y, orthIndex);

                foreach (int edgeIndex in edge.Iterate())
                {
                    edge.Set2DIndex(ref x, ref y, edgeIndex);

                    retVal[index] = values[(y * width) + x];

                    index++;
                }
            }

            return new Convolution2D(retVal, edge.Length, orth.Length, false);
        }
コード例 #5
0
        //TODO: Implement this properly
        private static void ExtendCorner(double[] values, int width, AxisFor orth, AxisFor edge)
        {
            Random rand = StaticRandom.GetRandomForThread();

            foreach (int edgeIndex in edge.Iterate())
            {
                foreach (int orthIndex in orth.Iterate())
                {
                    int x = -1;
                    int y = -1;
                    orth.Set2DIndex(ref x, ref y, orthIndex);
                    edge.Set2DIndex(ref x, ref y, edgeIndex);

                    values[(y * width) + x] = rand.Next(256);
                }
            }
        }