Exemple #1
0
 public static double GetDistance(IVectorPoint a, IVectorPoint b, Distance.GetDistance measure = null)
 {
     if (a is DoubleVectorPoint && b is DoubleVectorPoint)
     {
         return(measure(((DoubleVectorPoint)a).Vector, ((DoubleVectorPoint)b).Vector));
     }
     else if (a is StringVectorPoint && b is StringVectorPoint)
     {
         return(Distance.Levenshtein(((StringVectorPoint)a).Vector, ((StringVectorPoint)b).Vector));
     }
     else
     {
         throw new ArrayTypeMismatchException(string.Format("Cannot calculate distance between type {0} and type {1}", a.GetType(), b.GetType()));
     }
 }
Exemple #2
0
        public static Bitmap Generate(int numberOfPoints, Size size, Distance.GetDistance distance)
        {
            Random rnd = new Random(19761016);

            #region Generate Voronoi diagrams randomly
            var points = CellUtilities.CreatePoints(rnd, numberOfPoints, size);
            var colors = CellUtilities.CreateCellColorMap(rnd, numberOfPoints);
            var bitmap = new Bitmap(size.Width, size.Height);

            bitmap.Fill(Color.White);

            CellUtilities.SetCellCenters(bitmap, points);
            CellUtilities.CreateCell(bitmap, points, colors, distance);
            CellUtilities.SetCellCenters(bitmap, points);
            #endregion

            return(bitmap);
        }
Exemple #3
0
 public static double DistanceFrom(this IVectorPoint a, IVectorPoint b, Distance.GetDistance measrue = null)
 {
     return(GetDistance(a, b, measrue));
 }
Exemple #4
0
        public static void CreateCell(Bitmap bitmap, List <Point> points, List <Color> colors, Distance.GetDistance distance)
        {
            for (int hh = 0; hh < bitmap.Height; hh++)
            {
                for (int ww = 0; ww < bitmap.Width; ww++)
                {
                    int    ind  = -1;
                    double dist = int.MaxValue;
                    for (int it = 0; it < points.Count; it++)
                    {
                        var p = points[it];
                        var d = distance(p, new Point(ww, hh));
                        if (d < dist)
                        {
                            dist = d;
                            ind  = it;
                        }
                    }

                    if (ind > 0)
                    {
                        bitmap.SetPixel(ww, hh, colors[ind]);
                    }
                }
            }
        }