Beispiel #1
0
 private void btnDeletePoint_Click(object sender, RoutedEventArgs e)
 {
     if (_mode == 0 && _dt?.IsEnabled == false)
     {
         KMeans.Point p = (KMeans.Point)dtgPoints.SelectedItem;
         _points.Remove(p);
         _pointsNumber--;
         dtgPoints.Items.Refresh();
     }
 }
Beispiel #2
0
        private void cnvGraphic_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                double x = e.GetPosition((Canvas)sender).X;
                double y = e.GetPosition((Canvas)sender).Y;
                if (_calculatedAndSet)
                {
                    KMeans.Point p = new KMeans.Point("Evaluated point " + (++_evaluatedCounter), new ObservableCollection <double> {
                        x, y
                    });
                    Centroid ddd = _knnAlg.GetPointFeature(p);
                    int      ccc = 0;
                    foreach (Centroid c in _centroids)
                    {
                        if (c == ddd)
                        {
                            Ellipse ell = new Ellipse {
                                Width = _pointRadius, Height = _pointRadius, Fill = _pointsColorList[ccc], StrokeThickness = _pointThickness, Stroke = _pointsColorList[ccc]
                            };
                            cnvGraphic.Children.Add(ell);
                            Canvas.SetTop(ell, y - 5);
                            Canvas.SetLeft(ell, x - 5);
                            c.MyPoints.Add(p);
                        }
                        ccc++;
                    }
                }
                else
                {
                    _points.Add(new KMeans.Point("Point " + (++_pointsNumber), new ObservableCollection <double> {
                        x, y
                    }));

                    Ellipse ell = new Ellipse {
                        Width = _pointRadius, Height = _pointRadius, Fill = _pointFillColor, StrokeThickness = _pointThickness, Stroke = _pointStrokeColor
                    };
                    cnvGraphic.Children.Add(ell);
                    Canvas.SetTop(ell, y - 5);
                    Canvas.SetLeft(ell, x - 5);

                    _points[_pointsNumber - 1].Coordinates.CollectionChanged += (s, args) =>
                    {
                        ObservableCollection <double> d = (ObservableCollection <double>)s;
                        Canvas.SetTop(ell, d[1] - 5);
                        Canvas.SetLeft(ell, d[0] - 5);
                    };

                    dtgPoints.Items.Refresh();
                }
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                if (!_calculatedAndSet)
                {
                    double x = e.GetPosition((Canvas)sender).X;
                    double y = e.GetPosition((Canvas)sender).Y;

                    _centroids.Add(new Centroid("Centroid " + (++_centroidsNumber), new ObservableCollection <double> {
                        x, y
                    }));

                    Ellipse ell = new Ellipse {
                        Width = _centroidRadius, Height = _centroidRadius, Fill = _centroidFillColor, StrokeThickness = _centroidThickness, Stroke = _centroidStrokeColor
                    };
                    cnvGraphic.Children.Add(ell);
                    Canvas.SetTop(ell, y - 5);
                    Canvas.SetLeft(ell, x - 5);

                    _centroids[_centroidsNumber - 1].Coordinates.CollectionChanged += (s, args) =>
                    {
                        ObservableCollection <double> d = (ObservableCollection <double>)s;
                        Canvas.SetTop(ell, d[1] - 5);
                        Canvas.SetLeft(ell, d[0] - 5);
                    };

                    dtgCentroids.Items.Refresh();

                    txtCentroidN.Text = _centroidsNumber.ToString();
                }
            }
        }