예제 #1
0
        private static void FindHighVal()
        {
            //find highest value bucket to adjust color proportions accordingly.
            HighVal = 0;
            long hVal = long.MinValue;
            long lVal = long.MaxValue;

            if (MultiThreaded)
            {
                ParallelPlus.StridingFor(0, width, x =>
                {
                    for (int y = 0; y < height; y++)
                    {
                        if (pixelMatrix[x, y] > Interlocked.Read(ref hVal))
                        {
                            Interlocked.Exchange(ref hVal, pixelMatrix[x, y]);
                        }
                        if (pixelMatrix[x, y] < Interlocked.Read(ref lVal))
                        {
                            Interlocked.Exchange(ref lVal, pixelMatrix[x, y]);
                        }
                    }
                });
                HighVal = hVal;
                LowVal  = lVal;
            }
            else
            {
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        if (pixelMatrix[x, y] > HighVal)
                        {
                            HighVal = pixelMatrix[x, y];
                        }
                        if (pixelMatrix[x, y] < LowVal)
                        {
                            LowVal = pixelMatrix[x, y];
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Fill the internal pixel matrix according to the specified hash function. using numbers 0 to load limit converted to random alpha numeric strings with special characters.
        /// </summary>
        /// <param name="function">The hash function to fill according to.</param>
        public static void ApplyHashIncrementalStringSpecial(Func <string, uint, uint> function)
        {
            pixelMatrix = new long[width, height];
            MainForm.ProgressBarReset();
            long bucketCount = Range * LoadMultiplier;
            long incVal      = bucketCount / 100;

            //fill pixel matrix with number of times a bucket gets a value
            if (MultiThreaded)
            {
                ParallelPlus.StridingFor(0, bucketCount, i =>
                {
                    long position      = function(Generator.NumberToTextAlphaNumericSpecial(i), (uint)Range);
                    long y             = position / height;
                    long x             = position % width;
                    pixelMatrix[x, y] += 1;
                    if (i % incVal == 0)
                    {
                        MainForm.ProgressBarIncrement();
                    }
                });
            }
            else
            {
                for (int i = 0; i < bucketCount; i++)
                {
                    string o        = Generator.NumberToTextAlphaNumeric(i);
                    long   position = function(Generator.NumberToTextAlphaNumericSpecial(i), (uint)Range);
                    long   y        = position / height;
                    long   x        = position % width;
                    pixelMatrix[x, y] += 1;
                    if (i % incVal == 0)
                    {
                        MainForm.ProgressBarIncrement();
                    }
                }
            }
            FindHighVal();
        }
예제 #3
0
        public void RenderSurface(Graphics graphics, long[,] matrix, int adjustmentValue, bool newRender = false)
        {
            //adjust according to adjustment value as long as its not simply a rotation
            if (!newRender)
            {
                if (MultiThreaded)
                {
                    //find largest value and if it exceeds half the height, force all values into the half height range
                    long largestVal = long.MinValue;
                    long lowestVal  = long.MaxValue;
                    ParallelPlus.StridingFor(0, matrix.GetLength(0), x =>
                    {
                        for (int y = 0; y < matrix.GetLength(1); y++)
                        {
                            if (Math.Abs(matrix[x, y]) > Interlocked.Read(ref largestVal))
                            {
                                Interlocked.Exchange(ref largestVal, Math.Abs(matrix[x, y]));
                            }
                            else if (Math.Abs(matrix[x, y]) < Interlocked.Read(ref lowestVal))
                            {
                                Interlocked.Exchange(ref lowestVal, Math.Abs(matrix[x, y]));
                            }
                        }
                    });
                    if (largestVal > adjustmentValue)
                    {
                        double proportion = (double)adjustmentValue / (double)(largestVal - lowestVal);
                        ParallelPlus.StridingFor(0, matrix.GetLength(0), x =>
                        {
                            for (int y = 0; y < matrix.GetLength(1); y++)
                            {
                                matrix[x, y] = (long)(matrix[x, y] * proportion);
                            }
                        });
                    }
                }
                else
                {
                    //find largest value and if it exceeds half the height, force all values into the half height range
                    long largestVal = long.MinValue;
                    long lowestVal  = long.MaxValue;
                    for (int x = 0; x < matrix.GetLength(0); x++)
                    {
                        for (int y = 0; y < matrix.GetLength(1); y++)
                        {
                            if (Math.Abs(matrix[x, y]) > largestVal)
                            {
                                largestVal = Math.Abs(matrix[x, y]);
                            }
                            else if (Math.Abs(matrix[x, y]) < lowestVal)
                            {
                                lowestVal = Math.Abs(matrix[x, y]);
                            }
                        }
                    }
                    if (largestVal > adjustmentValue)
                    {
                        double proportion = (double)adjustmentValue / (double)(largestVal - lowestVal);
                        for (int x = 0; x < matrix.GetLength(0); x++)
                        {
                            for (int y = 0; y < matrix.GetLength(1); y++)
                            {
                                matrix[x, y] = (long)Math.Ceiling(matrix[x, y] * proportion);
                            }
                        }
                    }
                }
            }
            SolidBrush[] brushes = new SolidBrush[colorSchema.Length];
            for (int i = 0; i < brushes.Length; i++)
            {
                brushes[i] = new SolidBrush(colorSchema[i]);
            }

            double z1, z2;

            PointF[] polygon = new PointF[4];

            double minZ = double.PositiveInfinity, maxZ = double.NegativeInfinity;

            double[,] mesh  = new double[(int)((endPoint.X - startPoint.X) / density + 1), (int)((endPoint.Y - startPoint.Y) / density + 1)];
            PointF[,] meshF = new PointF[mesh.GetLength(0), mesh.GetLength(1)];

            for (int x = 0; x < mesh.GetLength(0); x++)
            {
                for (int y = 0; y < mesh.GetLength(1); y++)
                {
                    double zz = matrix[x, y];
                    mesh[x, y]  = zz;
                    meshF[x, y] = Project(x, y, zz);

                    if (minZ > zz)
                    {
                        minZ = zz;
                    }
                    if (maxZ < zz)
                    {
                        maxZ = zz;
                    }
                }
            }

            double cc = (maxZ - minZ) / (brushes.Length - 1.0);

            if (cc == 0)
            {
                cc = 1;
            }

            using (Pen pen = new Pen(penColor))
                for (int x = 0; x < mesh.GetLength(0) - 1; x++)
                {
                    for (int y = 0; y < mesh.GetLength(1) - 1; y++)
                    {
                        z1 = mesh[x, y];
                        z2 = mesh[x, y + 1];

                        polygon[0] = meshF[x, y];
                        polygon[1] = meshF[x, y + 1];
                        polygon[2] = meshF[x + 1, y + 1];
                        polygon[3] = meshF[x + 1, y];

                        graphics.SmoothingMode = SmoothingMode.None;
                        graphics.FillPolygon(brushes[(int)(((z1 + z2) / 2.0 - minZ) / cc)], polygon);

                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        graphics.DrawPolygon(pen, polygon);
                    }
                }
            for (int i = 0; i < brushes.Length; i++)
            {
                brushes[i].Dispose();
            }
        }