public IActionResult ColorInterpolator(ColorInterpolation color)
        {
            ColorInterpolation output         = new ColorInterpolation();
            List <string>      colorList      = new List <string>();
            string             firstColorHex  = color.FirstColor;
            string             secondColorHex = color.SecondColor;
            int   steps          = color.NumberOfColors;
            Color firstColorRGB  = System.Drawing.ColorTranslator.FromHtml(firstColorHex);
            Color secondColorRGB = System.Drawing.ColorTranslator.FromHtml(secondColorHex);

            ColorToHSV(firstColorRGB, out double hue1, out double saturation1, out double value1);
            ColorToHSV(secondColorRGB, out double hue2, out double saturation2, out double value2);
            double dist  = Math.Abs(hue1 - hue2);
            int    count = 0;

            if (steps > 0)
            {
                count = (int)dist / steps;
            }
            colorList.Add(firstColorHex);
            for (int i = 0; i < steps; i++)
            {
                hue1 += count;
                Color  color1 = ColorFromHSV(hue1, saturation1, value1);
                string hex    = color1.R.ToString("X2") + color1.G.ToString("X2") + color1.B.ToString("X2");
                colorList.Add("#" + hex);
            }
            colorList.Add(secondColorHex);
            //ViewBag.ColorList = colorList;
            output.ColorList = colorList;
            return(View(output));
        }
        public IActionResult RGBInterpolator(ColorInterpolation c)
        {
            if (ModelState.IsValid)
            {
                Debug.WriteLine("model state valid");
                Debug.WriteLine(c);

                List <string> myList = new List <string>();

                for (int i = 0; i < c.NumberOfColors + 1; i++)
                {
                    if (i == 0)
                    {
                        myList.Add(c.FirstColor);
                    }
                    else
                    {
                        myList.Add("#000000");
                    }
                }
                myList.Add(c.LastColor);
                c.ColorList = myList;

                for (int i = 0; i < c.ColorList.Count(); i++)
                {
                    Debug.WriteLine(c.ColorList[i]);
                }
                return(View("RGBInterpolator", c));
            }
            else
            {
                Debug.WriteLine("model state NOT valid");
                return(View("RGBInterpolator", c));
            }
        }
Example #3
0
 public IActionResult create(ColorInterpolation c)
 {
     if (ModelState.IsValid)
     {
         c.ColorSet = ColorList(c);
         Debug.WriteLine("Model is OK");
         return(View("create", c));
     }
     else
     {
         Debug.WriteLine("Model is INVALID");
         return(View("create", c));
     }
 }
Example #4
0
        private static IInterpolation GetInterpolator(ColorInterpolation interpolation, double[] x, double[] y)
        {
            switch (interpolation)
            {
            case ColorInterpolation.Akima:
                return(CubicSpline.InterpolateAkimaSorted(x, y));

            case ColorInterpolation.Spline:
                return(CubicSpline.InterpolateNaturalSorted(x, y));

            case ColorInterpolation.Linear:
                return(LinearSpline.InterpolateSorted(x, y));

            default:
                throw new ArgumentException("interpolation");
            }
        }
Example #5
0
        public static List <string> ColorList(ColorInterpolation c)
        {
            //create colors from model
            Color firstColor  = ColorTranslator.FromHtml(c.FirstColor);
            Color secondColor = ColorTranslator.FromHtml(c.SecondColor);
            //create list and arrays to hold values
            List <string> colorList = new List <string>();

            double[] hue = new double[c.NumberOfColors];
            double[] sat = new double[c.NumberOfColors];
            double[] val = new double[c.NumberOfColors];
            //create variable to hold values of first and second hsv
            double firstColorHue, firstColorSat, firstColorVal;
            double secondColorHue, secondColorSat, secondColorVal;

            ColorToHSV(firstColor, out firstColorHue, out firstColorSat, out firstColorVal);
            ColorToHSV(secondColor, out secondColorHue, out secondColorSat, out secondColorVal);
            //create value steps for hue, sat, and val
            double hueStep = (secondColorHue - firstColorHue) / (c.NumberOfColors - 1);
            double satStep = (secondColorSat - firstColorSat) / (c.NumberOfColors - 1);
            double valStep = (secondColorVal - firstColorVal) / (c.NumberOfColors - 1);

            //fill arrays with values
            for (int i = 0; i < c.NumberOfColors; i++)
            {
                hue[i] = firstColorHue + (hueStep * i);
                sat[i] = firstColorSat + (satStep * i);
                val[i] = firstColorVal + (valStep * i);
            }
            //add individual colors to list
            Color color; string htmlColor;

            for (int i = 0; i < c.NumberOfColors; i++)
            {
                color     = ColorFromHSV(hue[i], sat[i], val[i]);
                htmlColor = ColorTranslator.ToHtml(color);
                colorList.Add(htmlColor);
            }
            return(colorList);
        }
        public static void Create(List <ISqlGeometryAware> points, Func <ISqlGeometryAware, double> valueFunc, int width, int height, Color minColor, Color maxColor, Color midColor, double?maxDistance)
        {
            var boundingBox = SqlGeometryExtensions.GetBoundingBox(points.Select(p => p.TheSqlGeometry).ToList());

            //scale
            var scaleX = width / boundingBox.Width;
            var scaleY = height / boundingBox.Height;
            var scale  = Math.Min(scaleX, scaleY);

            width  = (int)(scale * boundingBox.Width);
            height = (int)(scale * boundingBox.Height);

            //create empty raster
            Bitmap result = new Bitmap(width, height);

            List <Point3D> pointSet = points.Select(p => new Point3D(p.TheSqlGeometry.STX.Value, p.TheSqlGeometry.STY.Value, valueFunc(p))).ToList();

            var maxValue   = pointSet.Max(p => p.Z);
            var minValue   = pointSet.Min(p => p.Z);
            var rangeValue = maxValue - minValue;
            var midValue   = rangeValue / 2.0 + minValue;
            //var minR = minColor.R;
            //var maxR = maxColor.R;
            //var rangeR = maxR - minR;

            //var minG = minColor.G;
            //var maxG = maxColor.G;
            //var rangeG = maxG - minG;

            //var minB = minColor.B;
            //var maxB = maxColor.B;
            //var rangeB = maxB - minB;
            ColorInterpolation step1 = new ColorInterpolation(minColor, midColor);

            ColorInterpolation step2 = new ColorInterpolation(midColor, maxColor);

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    var x     = boundingBox.XMin + j / scale;
                    var y     = boundingBox.YMax - i / scale;
                    var value = IRI.Msh.Common.Analysis.Interpolation.Idw.Calculate(pointSet, new Msh.Common.Primitives.Point(x, y), maxDistance);

                    //map value to color
                    //var r = (int)(minR + rangeR / rangeValue * (value - minValue));
                    //var g = (int)(minG + rangeG / rangeValue * (value - minValue));
                    //var b = (int)(minB + rangeB / rangeValue * (value - minValue));

                    Color color;

                    if (value.HasValue)
                    {
                        if (value < midValue)
                        {
                            color = step1.Interpolate(value.Value, minValue, maxValue);
                        }
                        else
                        {
                            color = step2.Interpolate(value.Value, minValue, maxValue);
                        }

                        //var color = Color.FromArgb(r, g, b);

                        result.SetPixel(j, i + 0, color); //result.SetPixel(j + 1, i + 0, color);
                    }

                    //result.SetPixel(j, i + 1, color); result.SetPixel(j + 1, i + 1, color);
                    //result.SetPixel(j, i + 2, color); result.SetPixel(j + 1, i + 2, color);
                    //result.SetPixel(j, i + 3, color); result.SetPixel(j + 1, i + 3, color);
                    //result.SetPixel(j, i + 4, color); result.SetPixel(j + 1, i + 4, color);

                    //result.SetPixel(j + 2, i + 0, color); result.SetPixel(j + 3, i + 0, color);
                    //result.SetPixel(j + 2, i + 1, color); result.SetPixel(j + 3, i + 1, color);
                    //result.SetPixel(j + 2, i + 2, color); result.SetPixel(j + 3, i + 2, color);
                    //result.SetPixel(j + 2, i + 3, color); result.SetPixel(j + 3, i + 3, color);
                    //result.SetPixel(j + 2, i + 4, color); result.SetPixel(j + 3, i + 4, color);

                    //result.SetPixel(j + 4, i + 0, color);
                    //result.SetPixel(j + 4, i + 1, color);
                    //result.SetPixel(j + 4, i + 2, color);
                    //result.SetPixel(j + 4, i + 3, color);
                    //result.SetPixel(j + 4, i + 4, color);
                }
            }

            result.Save("result.bmp");

            //return result;
        }