private void OnMouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs) { if (Mouse.RightButton == MouseButtonState.Pressed) { MainWindowViewModel viewModel = (MainWindowViewModel)DataContext; var mousePosition = mouseButtonEventArgs.GetPosition(this); Vector <double> mouseVec = _vecBuilder.DenseOfArray(new[] { mousePosition.X, mousePosition.Y, 1.0f }); var featureBands = viewModel.Layers.Where(b => b.UseFeature).OrderBy(b => b.Name).ToList(); ushort[] bandPixels = new ushort[featureBands.Count]; var viewToToWorld = viewModel.ClassifierViewModel.ScreenToWorld * _scaleMat.Inverse() * _screenToViewMat.Inverse(); for (int bandIndex = 0; bandIndex < featureBands.Count; ++bandIndex) { var band = featureBands[bandIndex]; var viewToPixelMat = band.WorldToImage * viewToToWorld; var bandPixelPosition = viewToPixelMat * mouseVec; ushort bandPixelValue = band.BandImage.GetScaledToUshort((int)bandPixelPosition[0], (int)bandPixelPosition[1]); bandPixels[bandIndex] = bandPixelValue; } var worldMousePosition = viewToToWorld * mouseVec; int selectedIndex = viewModel.LandcoverTypes.Values.ToList().FindIndex(f => f.Id == viewModel.SelectedLandCoverTypeViewModel.Id); var classifiedFeatureVector = new ClassifiedFeatureVector(selectedIndex, new FeatureVector(bandPixels), new Point(worldMousePosition[0], worldMousePosition[1])); viewModel.ClassifierViewModel.FeaturesViewModel.AddFeature(new ClassifiedFeatureVectorViewModel(classifiedFeatureVector)); } }
public ClassifiedFeatureVectorViewModel(ClassifiedFeatureVector classifiedFeatureVector) { ClassifiedFeatureVector = classifiedFeatureVector; FeatureTypeViewModel = MainWindowViewModel.Default.LandcoverTypes.Values.ToList()[ClassifiedFeatureVector.FeatureClass]; }