Ejemplo n.º 1
0
        public void PaintDend()
        {
            dend        = new Dendrogram();
            dend.Height = imglist.Count * 30 + 100;
            dend.Width  = max * 10 + 50;
            Line vertL = new Line();

            vertL.X1     = 20; vertL.X2 = 20;
            vertL.Y1     = imglist.Count * 30; vertL.Y2 = 10;
            vertL.Stroke = System.Windows.Media.Brushes.Black;
            dend.cnvs.Children.Add(vertL);
            Line horL = new Line();

            horL.X1     = 20; horL.X2 = 20 + max * 10;
            horL.Y1     = imglist.Count * 30; horL.Y2 = imglist.Count * 30;
            horL.Stroke = System.Windows.Media.Brushes.Black;
            dend.cnvs.Children.Add(horL);
            double h  = (imglist.Count * 30 - 20) / imglist.Count;
            double h1 = (max * 10) / imglist.Count;
            double h2 = max / imglist.Count;
            var    p  = order.FindAll(i => i.Count != 0);
            Dictionary <int, double> dd = new Dictionary <int, double>();

            for (byte i = 0; i < imglist.Count; i++)
            {
                dd.Add(p[0][i], imglist.Count * 30 - (i + 1) * h);
                Line      a    = new Line();
                TextBlock txtb = new TextBlock();
                txtb.Height = 25; txtb.Width = 15;
                txtb.Text   = p[0][i].ToString();
                a.X1        = 15; a.X2 = 25;
                a.Y1        = imglist.Count * 30 - (i + 1) * h;
                a.Y2        = imglist.Count * 30 - (i + 1) * h;
                a.Stroke    = System.Windows.Media.Brushes.Black;
                Canvas.SetTop(txtb, imglist.Count * 30 - (i + 1) * h);
                Canvas.SetLeft(txtb, 10);
                dend.cnvs.Children.Add(a); dend.cnvs.Children.Add(txtb);
            }

            for (byte i = 0; i < imglist.Count; i++)
            {
                Line a = new Line();
                a.X1     = (20 + max * 10) - i * h1; a.X2 = (20 + max * 10) - i * h1;
                a.Y1     = imglist.Count * 30 - 5;
                a.Y2     = imglist.Count * 30 + 5;
                a.Stroke = System.Windows.Media.Brushes.Black;
                TextBlock txtb1 = new TextBlock();
                txtb1.Height = 25; txtb1.Width = 30;
                Canvas.SetTop(txtb1, imglist.Count * 30 + 10);
                Canvas.SetLeft(txtb1, max * 10 - i * h1);
                txtb1.Text = (Math.Round(max - i * h2, 2)).ToString();
                dend.cnvs.Children.Add(txtb1);
                dend.cnvs.Children.Add(a);
            }

            for (int i = 0; i < orderlist.Count; i++)
            {
                Line l1 = new Line(); Line l2 = new Line();
                if ((orderlist[i].set1.Count == 1) && (orderlist[i].set2.Count == 1))
                {
                    l1.X1              = 20; l2.X1 = 20;
                    l1.Y1              = dd[orderlist[i].set1[0]]; l2.Y1 = dd[orderlist[i].set2[0]];
                    l1.Y2              = (l1.Y1 + l2.Y1) / 2; l2.Y2 = (l1.Y1 + l2.Y1) / 2;
                    l1.X2              = l1.X1 + orderlist[i].dist * 10;
                    l2.X2              = l2.X1 + orderlist[i].dist * 10;
                    l1.Stroke          = System.Windows.Media.Brushes.Red;
                    l2.Stroke          = System.Windows.Media.Brushes.Red;
                    l1.StrokeThickness = 2; l2.StrokeThickness = 2;
                }
                else
                {
                    int size1 = orderlist[i].set1.Count;
                    int size2 = orderlist[i].set2.Count;
                    if (size1 == 1)
                    {
                        l1.X1 = 20;
                        l1.Y1 = dd[orderlist[i].set1[0]];
                        double w = Dend(0, l2, dd, l1, l2, orderlist[i].dist, orderlist[i].set1, orderlist[i].set2, orderlist, dend);
                    }
                    if (size2 == 1)
                    {
                        l1.X1 = 20;
                        l1.Y1 = dd[orderlist[i].set2[0]];
                        double w = Dend(0, l2, dd, l1, l2, orderlist[i].dist, orderlist[i].set2, orderlist[i].set1, orderlist, dend);
                    }
                    if ((size1 > 1) && (size2 > 1))
                    {
                        double w  = Dend(0, l1, dd, l1, l2, orderlist[i].dist, orderlist[i].set2, orderlist[i].set1, orderlist, dend);
                        double w1 = Dend(w, l2, dd, l1, l2, orderlist[i].dist, orderlist[i].set1, orderlist[i].set2, orderlist, dend);
                    }
                }
                dend.cnvs.Children.Add(l1); dend.cnvs.Children.Add(l2);
            }
            dend.btnclust.Click += ButtonCluster_Click;
            dend.Show();
        }
Ejemplo n.º 2
0
        public double Dend(double t, Line dif, Dictionary <int, double> dd, Line l1, Line l2, double dist, List <int> set1, List <int> set2, List <Order> orderlist, Dendrogram dend)
        {
            double t1 = 0;

            l1.X2              = 20 + dist * 10;
            l2.X2              = 20 + dist * 10;
            l1.Stroke          = System.Windows.Media.Brushes.Red;
            l2.Stroke          = System.Windows.Media.Brushes.Red;
            l1.StrokeThickness = 2; l2.StrokeThickness = 2;
            var c = orderlist.FindAll(z => (z.set1.Count + z.set2.Count == set2.Count));
            int counter = 0; int tmp = 0;

            foreach (var k in c)
            {
                foreach (var d in set2)
                {
                    tmp = counter;
                    foreach (var z in k.set1)
                    {
                        if (d == z)
                        {
                            counter++;
                        }
                    }
                    if (tmp == counter)
                    {
                        foreach (var z in k.set2)
                        {
                            if (d == z)
                            {
                                counter++;
                            }
                        }
                    }
                }
                if (counter == set2.Count)
                {
                    dif.X1 = 20 + k.dist * 10;
                    foreach (var f in k.set1)
                    {
                        t1 += dd[f];
                    }
                    foreach (var f in k.set2)
                    {
                        t1 += dd[f];
                    }
                    dif.Y1 = t1 / (k.set1.Count + k.set2.Count);
                    if (t != 0)
                    {
                        l1.Y2 = (t1 + t) / (set2.Count + set1.Count); l2.Y2 = (t1 + t) / (set2.Count + set1.Count);
                    }
                    else
                    {
                        l1.Y2 = (t1 + l1.Y1) / (set2.Count + set1.Count); l2.Y2 = (t1 + l1.Y1) / (set2.Count + set1.Count);
                    }
                    break;
                }
            }
            return(t1);
        }