Example #1
0
 public static async Task BatchAQ2(this UISettings ui, List <FileData> listfiles)
 {
     try {
         Directory.CreateDirectory($"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAQ2");                 // quantify with 2-dist
         using (var file = File.AppendText($"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAQ2.csv")) {
             file.Write("\n" + CalBlobAQ2.getEntryNote + "\n" + CalBlobAQ2.getDescription + "\n" + CalBlobAQ2.getHeader);
         }
         var progress = new Progress($"Analyzing {listfiles.Count} files ...", listfiles.Count);
         using (ui.cts = new CancellationTokenSource()) {
             if (!ui.MultiThreadingSwitch)                       // false - single thread
             {
                 foreach (FileData imgfile in listfiles)
                 {
                     using (var img = await Task <CalBlobAQ2> .Factory.StartNew(() => { return(new CalBlobAQ2(ui, imgfile)); })) {
                         ui.UpdateImageSource(img.BitmapOriginal, img.BitmapMarkup, img.BitmapExclude, img.BitmapGray, img.BitmapBlackWhite, img.BitmapResult);
                         ui.Export2Bitmap(img.BitmapMarkup, img.BitmapResult, $"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAQ2\\{img.OutName}.png", ui.ExportDetailSwitch);
                         progress.Increment(ui, $"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAQ2.csv", img.getResult);
                     }
                     ui.cts.Token.ThrowIfCancellationRequested();
                 }
             }
             else                         // true - open multi thread pool
             {
                 await Task.Factory.StartNew(() => {
                     Parallel.ForEach(listfiles, new ParallelOptions()
                     {
                         CancellationToken = ui.cts.Token, MaxDegreeOfParallelism = Environment.ProcessorCount
                     }, (FileData imgfile) => {
                         using (var img = new CalBlobAQ2(ui, imgfile)) {
                             ui.Export2Bitmap(img.BitmapMarkup, img.BitmapResult, $"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAQ2\\{img.OutName}.jpe", ui.ExportDetailSwitch);
                             progress.Increment(ui, $"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAQ2.csv", img.getResult);
                         }
                     });
                 });
             }
         }
     } catch { throw new Exception("Error encountered during batch airspace quantification."); }
 }
Example #2
0
        public static async Task BatchAP2(this UISettings ui, List <FileData> listfiles)
        {
            try {
                Directory.CreateDirectory($"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAP");                 // profile
                using (var file = File.AppendText($"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAP.csv")) {
                    file.Write("\n" + CalPAC.getEntryNote + "\n" + CalPAC.getDescription + "\n" + CalPAC.getHeader);
                }
                Directory.CreateDirectory($"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAQ2");                 // quantify with 2-dist
                using (var file = File.AppendText($"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAQ2.csv")) {
                    file.Write("\n" + CalBlobAQ2.getEntryNote + "\n" + CalBlobAQ2.getDescription + "\n" + CalBlobAQ2.getHeader);
                }

                switch (ui.ProfilingIndex)
                {
                case 0: foreach (FileData f in listfiles)
                    {
                        f.Grouping = "All";
                    }
                    break;

                case 1: foreach (FileData f in listfiles)
                    {
                        f.Grouping = f.Group;
                    }
                    break;

                case 2: foreach (FileData f in listfiles)
                    {
                        f.Grouping = f.Group + "-" + f.Individual;
                    }
                    break;

                case 3: foreach (FileData f in listfiles)
                    {
                        f.Grouping = f.OutName;
                    }
                    break;
                }
                var filegroups = listfiles.GroupBy(g => g.Grouping).Select(l => l.ToList()).ToList();
                var progress   = new Progress($"Analyzing {listfiles.Count} files in {filegroups.Count} groups ...", listfiles.Count * 2 + filegroups.Count); // 2X the work + additional categorization
                using (ui.cts = new CancellationTokenSource()) {
                    foreach (List <FileData> filegroup in filegroups)                                                                                         // Process each group
                    {
                        if (!ui.MultiThreadingSwitch)                                                                                                         // false - single thread
                        {
                            var areaPool = new ConcurrentBag <double>();
                            foreach (FileData imgfile in filegroup)
                            {
                                using (var img = await Task <CalPAP> .Factory.StartNew(() => { return(new CalPAP(ui, imgfile, ref areaPool)); })) {
                                    ui.UpdateImageSource(img.BitmapOriginal, img.BitmapMarkup, img.BitmapExclude, img.BitmapGray, img.BitmapBlackWhite, img.BitmapResult);
                                    ui.Export2Bitmap(img.BitmapMarkup, img.BitmapResult, $"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAP\\{img.OutName}.jpe", ui.ExportDetailSwitch);
                                    progress.Increment(ui);                                     //incremenet without writing result
                                }
                                ui.cts.Token.ThrowIfCancellationRequested();
                            }

                            var categ = await Task <CalPAC> .Factory.StartNew(() => { return(new CalPAC(ui, filegroup[0].Grouping, filegroup.Count, areaPool.ToList())); });

                            ui.Graph1 = categ.ToOxyPlot(1);
                            ui.Graph1.ExportPng($"{ui.WorkDirectory}\\{ui.ProjectName}\\{filegroup[0].Grouping}_1-Count.png");
                            ui.Graph2 = categ.ToOxyPlot(2);
                            ui.Graph2.ExportPng($"{ui.WorkDirectory}\\{ui.ProjectName}\\{filegroup[0].Grouping}_2-Area.png");
                            ui.Graph3 = categ.ToOxyPlot(3);
                            ui.Graph3.ExportPng($"{ui.WorkDirectory}\\{ui.ProjectName}\\{filegroup[0].Grouping}_3-Count&Area.png");
                            progress.Increment(ui, $"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAP.csv", categ.getResult);
                            ui.cts.Token.ThrowIfCancellationRequested();

                            foreach (FileData imgfile in filegroup)
                            {
                                using (var img = await Task <CalBlobAQ2> .Factory.StartNew(() => { return(new CalBlobAQ2(ui, imgfile, categ)); })) {
                                    ui.UpdateImageSource(img.BitmapOriginal, img.BitmapMarkup, img.BitmapExclude, img.BitmapGray, img.BitmapBlackWhite, img.BitmapResult);
                                    ui.Export2Bitmap(img.BitmapMarkup, img.BitmapResult, $"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAQ2\\{img.OutName}.png", ui.ExportDetailSwitch);
                                    progress.Increment(ui, $"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAQ2.csv", img.getResult);
                                }
                                ui.cts.Token.ThrowIfCancellationRequested();
                            }
                        }
                        else                             // true - open multi thread pool
                        {
                            var categ = await Task <CalPAC> .Factory.StartNew(() => {
                                var areaPool = new ConcurrentBag <double>();
                                Parallel.ForEach(filegroup, new ParallelOptions()
                                {
                                    CancellationToken = ui.cts.Token, MaxDegreeOfParallelism = Environment.ProcessorCount
                                }, (FileData imgfile) => {
                                    using (var img = new CalPAP(ui, imgfile, ref areaPool)) {
                                        ui.Export2Bitmap(img.BitmapMarkup, img.BitmapResult, $"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAP\\{img.OutName}.jpe", ui.ExportDetailSwitch);
                                        progress.Increment(ui);                                         //incremenet without writing result
                                    }
                                });
                                return(new CalPAC(ui, filegroup[0].Grouping, filegroup.Count, areaPool.ToList()));
                            }); ui.cts.Token.ThrowIfCancellationRequested();

                            ui.Graph1 = categ.ToOxyPlot(1);
                            ui.Graph1.ExportPng($"{ui.WorkDirectory}\\{ui.ProjectName}\\{filegroup[0].Grouping}_1-Count.png");
                            ui.Graph2 = categ.ToOxyPlot(2);
                            ui.Graph2.ExportPng($"{ui.WorkDirectory}\\{ui.ProjectName}\\{filegroup[0].Grouping}_2-Area.png");
                            ui.Graph3 = categ.ToOxyPlot(3);
                            ui.Graph3.ExportPng($"{ui.WorkDirectory}\\{ui.ProjectName}\\{filegroup[0].Grouping}_3-Count&Area.png");
                            progress.Increment(ui, $"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAP.csv", categ.getResult);
                            ui.cts.Token.ThrowIfCancellationRequested();

                            await Task.Factory.StartNew(() => {
                                Parallel.ForEach(filegroup, new ParallelOptions()
                                {
                                    CancellationToken = ui.cts.Token, MaxDegreeOfParallelism = Environment.ProcessorCount
                                }, (FileData imgfile) => {
                                    using (var img = new CalBlobAQ2(ui, imgfile, categ)) {
                                        ui.Export2Bitmap(img.BitmapMarkup, img.BitmapResult, $"{ui.WorkDirectory}\\{ui.ProjectName}\\LMAQ2\\{img.OutName}.jpe", ui.ExportDetailSwitch);
                                        progress.Increment(ui, $"{ui.WorkDirectory}\\{ui.ProjectName}\\_{ui.ProjectName}_LMAQ2.csv", img.getResult);
                                    }
                                });
                            });

                            ui.cts.Token.ThrowIfCancellationRequested();
                        }
                    }
                }
            } catch { throw new Exception("Error encountered during batch airspace profiling."); }
        }