Beispiel #1
0
        private void picImage_Click(object sender, EventArgs e)
        {
            MouseEventArgs me = (MouseEventArgs)e;

            if (me.Button == MouseButtons.Left)
            {
                if (centroidList.Count < colors.Length)
                {
                    centroidList.Add(new double[] { Convert.ToDouble(me.X - 7), Convert.ToDouble(me.Y - 7) });
                }
            }
            else if (me.Button == MouseButtons.Right)
            {
                var poz = centroidList.FindIndex(c => c[0] <= me.X + 8 && c[0] >= me.X - 8 && c[1] <= me.Y + 8 && c[1] >= me.Y - 8);
                if (poz != -1)
                {
                    centroidList.RemoveAt(poz);
                }
            }

            if (dataSetList.Count > 0 && centroidList.Count > 0)
            {
                clustering = KMeansManager.Cluster(dataSetList.ToArray(), centroidList.Count, centroidList.ToArray()).ToList();
            }

            picImage.Invalidate();
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            Random objRandom = new Random();

            dataSetList = new List <double[]>();
            for (int i = 0; i < (int)numericUpDown1.Value; i++)
            {
                double[] point = new double[2];
                for (int j = 0; j < 2; j++)
                {
                    point[j] = KMeansManager.GenerateRandomDouble(objRandom, 0, 400);
                }
                dataSetList.Add(point);
            }

            if (dataSetList.Count > 0 && centroidList.Count > 0)
            {
                clustering = KMeansManager.Cluster(dataSetList.ToArray(), centroidList.Count, centroidList.ToArray()).ToList();
            }

            picImage.Invalidate();
        }