Exemple #1
0
        private void AddBands()
        {
            AddLayersDialog dialog = new AddLayersDialog();

            if (dialog.ShowAddBandsDialog() == true && dialog.DialogViewModel.Layers.Count > 0)
            {
                var loadBandsTask = new LoadBandsTask(this, dialog.DialogViewModel);
                ExecuteLongRunningTask(loadBandsTask);
            }
        }
Exemple #2
0
        private void ImportTrainingSet()
        {
            // Create an instance of the open file dialog box.
            var openFileDialog = new OpenFileDialog
            {
                Filter      = @"Txt Files (.txt)|*.txt",
                FilterIndex = 1
            };

            // Call the ShowDialog method to show the dialog box.
            var userClickedOk = openFileDialog.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOk == DialogResult.OK)
            {
                FeaturesViewModel.RemoveAllFeatures();

                using (var file = new StreamReader(openFileDialog.FileName))
                {
                    int numLandcoverTypes = int.Parse(file.ReadLine());
                    Dictionary <int, LandcoverTypeViewModel> landCoverTypes = new Dictionary <int, LandcoverTypeViewModel>();
                    for (int i = 0; i < numLandcoverTypes; ++i)
                    {
                        int    id    = int.Parse(file.ReadLine());
                        string name  = file.ReadLine();
                        Color  color = (Color)ColorConverter.ConvertFromString(file.ReadLine());
                        LandcoverTypeViewModel landcoverType = new LandcoverTypeViewModel(id, name, color);
                        landCoverTypes.Add(id, landcoverType);
                    }


                    int numLayers = int.Parse(file.ReadLine());
                    var layers    = new List <CreateLayerViewModel>();
                    for (int i = 0; i < numLayers; ++i)
                    {
                        string        path = file.ReadLine();
                        bool          contrastEnhancement = bool.Parse(file.ReadLine());
                        SatelliteType satelliteType       = (SatelliteType)Enum.Parse(typeof(SatelliteType), file.ReadLine());
                        bool          isRed            = bool.Parse(file.ReadLine());
                        bool          isGreen          = bool.Parse(file.ReadLine());
                        bool          isBlue           = bool.Parse(file.ReadLine());
                        double        minCutPercentage = double.Parse(file.ReadLine());
                        double        maxCutPercentage = double.Parse(file.ReadLine());
                        layers.Add(new CreateLayerViewModel(path, contrastEnhancement, satelliteType, isRed, isGreen, isBlue, minCutPercentage, maxCutPercentage));;
                    }

                    var missingLayers = layers.Where(s => _mainWindowViewModel.Layers.All(b => b.Path != s.Path)).ToList();

                    // Check if some bands have to be added.
                    if (missingLayers.Count > 0)
                    {
                        var dialog = new AddLayersDialog();

                        if (dialog.ShowImportMissingBandsDialog(missingLayers) == true && dialog.DialogViewModel.Layers.Count > 0)
                        {
                            var loadBandsTask = new LoadBandsTask(_mainWindowViewModel, dialog.DialogViewModel);
                            _mainWindowViewModel.ExecuteLongRunningTask(loadBandsTask);
                        }
                        else
                        {
                            // Abort import
                            return;
                        }
                    }

                    _mainWindowViewModel.LandcoverTypes = landCoverTypes.ToImmutableDictionary();
                    _mainWindowViewModel.SelectedLandCoverTypeViewModel = _mainWindowViewModel.LandcoverTypes.Values.FirstOrDefault();

                    string featureLine;

                    while ((featureLine = file.ReadLine()) != null)
                    {
                        string[] positionTypeIntensities = featureLine.Split(' ');
                        string   position      = positionTypeIntensities[0];
                        string[] coordinates   = position.Split(',');
                        var      landCoverType = _mainWindowViewModel.LandcoverTypes.Values.ToList().FindIndex(t => t.Id == int.Parse(positionTypeIntensities[1]));
                        var      intensities   = positionTypeIntensities[2].Split(';').Select(ushort.Parse).ToArray();

                        FeaturesViewModel.AddFeature(new ClassifiedFeatureVectorViewModel(new ClassifiedFeatureVector(landCoverType, new FeatureVector(intensities), new Point(double.Parse(coordinates[0]), double.Parse(coordinates[1])))));
                    }
                }
            }
        }