MTExample1_8.ColorMap.Jet C# (CSharp) Méthode

Jet() public méthode

public Jet ( ) : ].int[
Résultat ].int[
        public int[,] Jet()
        {
            int[,] cmap = new int[colormapLength, 4];
            float[,] cMatrix = new float[colormapLength, 3];
            var n = (int)Math.Ceiling(colormapLength / 4.0f);
            int nMod = 0;
            float[] fArray = new float[3 * n - 1];
            int[] red = new int[fArray.Length];
            int[] green = new int[fArray.Length];
            int[] blue = new int[fArray.Length];

            if (colormapLength % 4 == 1)
                nMod = 1;

            for (int i = 0; i <fArray.Length; i++) {
                if (i < n)
                    fArray[i] = (float)(i + 1) / n;
                else if (i >= n && i < 2 * n - 1)
                    fArray[i] = 1.0f;
                else if (i >= 2 * n - 1)
                    fArray[i] = (float)(3 * n - 1 - i) / n;
                green[i] = (int)Math.Ceiling(n / 2.0f) - nMod + i;
                red[i] = green[i] + n;
                blue[i] = green[i] - n;
            }

            int nb = 0;
            for (int i = 0; i < blue.Length; i++) {
                if (blue[i] > 0)
                    nb++;
            }

            for (int i = 0; i < colormapLength; i++) {
                for (int j = 0; j < red.Length; j++) {
                    if (i == red[j] && red[j] < colormapLength)
                        cMatrix[i, 0] = fArray[i - red[0]];
                }
                for (int j = 0; j < green.Length; j++) {
                    if (i == green[j] && green[j] < colormapLength)
                        cMatrix[i, 1] = fArray[i - green[0]];
                }
                for (int j = 0; j < blue.Length; j++) {
                    if (i == blue[j] && blue[j] >= 0)
                        cMatrix[i, 2] = fArray[fArray.Length - 1 - nb + i];
                }
            }

            for (int i = 0; i < colormapLength; i++) {
                cmap[i, 0] = alphaValue;
                for (int j = 0; j < 3; j++) {
                    cmap[i, j+1] = (int)(cMatrix[i, j] * 255);
                }
            }
            return cmap;
        }

Usage Example

        private void DrawColorBar(Graphics g, int x, int y, int width, int height,
                                  ColorMap map, string str)
        {
            int[,] cmap = new int[64, 4];
            switch (str)
            {
            case "Jet":
                cmap = map.Jet();
                break;

            case "Hot":
                cmap = map.Hot();
                break;

            case "Gray":
                cmap = map.Gray();
                break;

            case "Cool":
                cmap = map.Cool();
                break;

            case "Summer":
                cmap = map.Summer();
                break;

            case "Autumn":
                cmap = map.Autumn();
                break;

            case "Spring":
                cmap = map.Spring();
                break;

            case "Winter":
                cmap = map.Winter();
                break;
            }

            int ymin = 0;
            int ymax = 32;
            int dy   = height / (ymax - ymin);
            int m    = 64;

            for (int i = 0; i < 32; i++)
            {
                int        colorIndex = (int)((i - ymin) * m / (ymax - ymin));
                SolidBrush aBrush     = new SolidBrush(Color.FromArgb(
                                                           cmap[colorIndex, 0], cmap[colorIndex, 1],
                                                           cmap[colorIndex, 2], cmap[colorIndex, 3]));
                g.FillRectangle(aBrush, x, y + i * dy, width, dy);
            }
        }
All Usage Examples Of MTExample1_8.ColorMap::Jet