public void AddCaptures(List <int[]> parameters, List <int> ind, List <string> folders) { MainCapture mc = new MainCapture(); List <Image> samples = new List <Image>(); samples = mc.Samples(folders, ind); for (int i = 0; i < parameters.Count; i++) { capturesList.Add(new CaptureWindow(this, samples.ElementAt(i), parameters.ElementAt(parameters.Count - 1 - i), folders.ElementAt(folders.Count - 1 - i))); capturesList.ElementAt(i).Uid = (i).ToString(); samplesList.Add(samples.ElementAt(i)); samplesList.ElementAt(i).Uid = (i).ToString(); numberCapturesRunning++; } sampleSP.Children.Clear(); sampleSP.Children.Add(samplesList.ElementAt(0)); infoLabel.Content = "1/" + capturesList.Count.ToString(); MainPage.capturesRunning = true; Border1.Visibility = Visibility.Visible; Border2.Visibility = Visibility.Visible; sampleSP.Visibility = Visibility.Visible; infoLabel.Visibility = Visibility.Visible; ShowButton.IsEnabled = true; }
// This window is responsble for handling the captures of the object that represents, and thus // manages the MainCapture thread and hosts capture taking functions public CaptureWindow(CapturePreviews capt, Image img, int[] param, string folder) { InitializeComponent(); this.Width = 1200; this.Height = 900; cp = capt; cfs = new List <captureFramework>(); // A task holds details for a capture process (See <Task> constructior definition) List <Uri> u = new List <Uri>(); t = new Task(this, param[0], param[1], param[2], param[3], u, folder); Directory.CreateDirectory(folder); file = new LogFile(t.getFolder(), t.getIndex(), t.getNumberOfCaptures()); file.BuildAndSave(); // Thread initialization MainCapture newCapture = new MainCapture(); newCaptureThread = new Thread(newCapture.StartCapture); newCaptureThread.SetApartmentState(ApartmentState.STA); newCaptureThread.Start(t); running = true; playing = false; StackPanel aux = new StackPanel(); Rectangle frame = new Rectangle(); frame.Width = 570; frame.Height = 550; frame.Stroke = Brushes.Black; frame.StrokeThickness = 4; aux.Children.Add(frame); StackPanel.SetZIndex(aux, 10); ImagesCanvas.Children.Add(aux); FirstCapture(img); Info_Init(); Logo_Init(); PlayNStop_Init(); CapturesListBox.SelectionChanged += new SelectionChangedEventHandler(listBoxClicked); speed = 1; }
// Object scan. This method can be called repeatedly private void objectShow_Button_Click(object sender, RoutedEventArgs e) { parameters = new List <int[]>(); CaptureDetailsLabel.Content = ""; // Acquisition of outlines to define existing objects MainCapture newCapture = new MainCapture(); OutlineParameters op = newCapture.ConfirmCapture(); int numberObjects = OutlineParameters.getCapacity(op); if ((op.getSize(op).ElementAt(0).X > 4000) && (op.getSize(op).ElementAt(0).Y > 3000)) { MessageBox.Show("No objects could be found"); return; } List <System.Windows.Shapes.Rectangle> outlineDefinitionList = new List <System.Windows.Shapes.Rectangle>(); // Selection border holds a definition for an object and it's showing structure. (See SelectionBorder constructor definition) List <SelectionBorder> transparentCanvasList = new List <SelectionBorder>(); System.Drawing.Point globalPicSize = op.getGlobalSize(op); ImageBorder.Visibility = Visibility.Visible; ImageCanvas.Children.Clear(); ImageCanvas.Children.Add(objectShowStackPanel); // Definiton of objects by their outlines for (int i = 0; i < numberObjects; i++) { // Rectangle definition outlineDefinitionList.Add(new System.Windows.Shapes.Rectangle()); outlineDefinitionList.ElementAt(i).Width = (op.getSize(op).ElementAt(i).X *790) / globalPicSize.X; // Window/Canvas ratio outlineDefinitionList.ElementAt(i).Height = (op.getSize(op).ElementAt(i).Y *590) / globalPicSize.Y; ImageCanvas.Children.Add(outlineDefinitionList.ElementAt(i)); outlineDefinitionList.ElementAt(i).Stroke = System.Windows.Media.Brushes.LightGreen; outlineDefinitionList.ElementAt(i).StrokeThickness = 3; outlineDefinitionList.ElementAt(i).Margin = new Thickness((op.getLocation(op).ElementAt(i).X * 790) / globalPicSize.X, (op.getLocation(op).ElementAt(i).Y * 590) / globalPicSize.Y, 0, 0); // Canvas definition transparentCanvasList.Add(new SelectionBorder(i, new Border())); transparentCanvasList.ElementAt(i).Width = (op.getSize(op).ElementAt(i).X * 790) / globalPicSize.X; // Window/Canvas ratio transparentCanvasList.ElementAt(i).Height = (op.getSize(op).ElementAt(i).Y * 590) / globalPicSize.Y; transparentCanvasList.ElementAt(i).MouseDown += new MouseButtonEventHandler(RectangleClickedHandler); ImageCanvas.Children.Add(transparentCanvasList.ElementAt(i)); transparentCanvasList.ElementAt(i).Opacity = 0; transparentCanvasList.ElementAt(i).Background = System.Windows.Media.Brushes.Green; transparentCanvasList.ElementAt(i).MouseEnter += new MouseEventHandler(BorderMouseEnterHandlerEnter); transparentCanvasList.ElementAt(i).MouseLeave += new MouseEventHandler(BorderMouseEnterHandlerLeave); transparentCanvasList.ElementAt(i).Margin = new Thickness((op.getLocation(op).ElementAt(i).X * 790) / globalPicSize.X, (op.getLocation(op).ElementAt(i).Y * 590) / globalPicSize.Y, 0, 0); } objectShowStackPanel.Visibility = Visibility.Visible; // Global scan of the mat screen acquisition System.Windows.Controls.Image globalImg = new System.Windows.Controls.Image(); BitmapImage src = new BitmapImage(); src.BeginInit(); src.UriSource = new Uri(PictureHandling.confirmPath, UriKind.Relative); src.CacheOption = BitmapCacheOption.OnLoad; src.EndInit(); globalImg.Source = src; globalImg.Stretch = Stretch.Uniform; objectShowStackPanel.Children.Clear(); objectShowStackPanel.Children.Add(globalImg); ShowButton.Content = "Scan new Layout"; ParametersBorder.Visibility = Visibility.Hidden; }
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // UI related functions // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // This window is responsble for handling the captures of the object that represents, and thus // manages the MainCapture thread and hosts capture taking functions public CaptureWindow(CapturePreviews capt, Image img, int[] param, string folder, bool[] analysis, string name, PcPhysicalPoint location, System.Drawing.Point size, bool moved, string map) { InitializeComponent(); this.Width = 1200; this.Height = 900; this.Left = 300; this.Top = 100; cp = capt; cfs = new List <captureFramework>(); // A task holds details for a capture process (See <Task> constructior definition) List <Uri> u = new List <Uri>(); t = new Task(this, param[0], param[1], param[2], param[3], u, folder, analysis[0], analysis[1], name, location, size); aw = new AnalysisWindow(this, t.getCountAnalysis(), t.getClassAnalysis(), map, folder); Directory.CreateDirectory(folder); file = new LogFile(t.getFolder(), t.getIndex(), t.getName(), t.getNumberOfCaptures()); titleLabel.Content = name; if (!analysis[0] && !analysis[1]) { generalAnalysisBut.Visibility = Visibility.Hidden; } // Thread initialization for triggering the captures MainCapture newCapture = new MainCapture(); newCaptureThread = new Thread(newCapture.StartCapture); newCaptureThread.SetApartmentState(ApartmentState.STA); newCaptureThread.Start(t); running = true; playing = false; // UI elements initialization StackPanel aux = new StackPanel(); Rectangle frame = new Rectangle(); frame.Visibility = Visibility.Hidden; frame.Width = 575; frame.Height = 400; frame.Stroke = Brushes.Black; frame.StrokeThickness = 4; aux.Children.Add(frame); StackPanel.SetZIndex(aux, 10); ImagesCanvas.Children.Add(aux); StackPanel aux2 = new StackPanel(); Rectangle frame2 = new Rectangle(); frame2.Width = 500; frame2.Height = 120; frame2.Stroke = Brushes.Black; frame2.StrokeThickness = 4; aux2.Children.Add(frame2); StackPanel.SetZIndex(aux2, 10); EventsCanvas.Children.Add(aux2); FirstCapture(img, moved); Info_Init(); Logo_Init(); PlayNStop_Init(); CapturesListBox.SelectionChanged += new SelectionChangedEventHandler(listBoxClicked); EventsListBox.SelectionChanged += new SelectionChangedEventHandler(eventClicked); if (analysis[0]) { EventsListBox.Visibility = Visibility.Visible; CountAnalysisBut.Visibility = Visibility.Visible; frame.Visibility = Visibility.Visible; } speed = 1; }
// Parameters are received from MainPage listing the features of the new captures to be built // In this method they are built and added to the UI public void AddCaptures(List <int[]> parameters, List <int> ind, List <string> folders, List <bool[]> analysis, List <string> names, List <PcPhysicalPoint> locations, List <System.Drawing.Point> sizes, List <string> maps) { MainCapture mc = new MainCapture(); List <Image> samples = new List <Image>(); List <IPcOutline> outlines; object[] returnable = new object[3]; returnable = mc.Samples(folders, ind, locations, sizes); samples = (List <Image>)returnable[0]; outlines = (List <IPcOutline>)returnable[1]; List <int> moved = (List <int>)returnable[2]; // Capture Window holds the control of a process. int previousCaptures = capturesList.Count; for (int i = 0; i < parameters.Count; i++) { if (moved[i] != 2) { PcPhysicalPoint location = new PcPhysicalPoint(outlines[i].PhysicalBoundaries.Location.X * (outlines[i].PixelDensity.X), outlines[i].PhysicalBoundaries.Location.Y * (outlines[i].PixelDensity.Y)); System.Drawing.Point size = new System.Drawing.Point(Convert.ToInt32(PictureHandling.GetOutlineWidth(outlines[i])), Convert.ToInt32(PictureHandling.GetOutlineHeight(outlines[i]))); if (moved[i] == 0) { capturesList.Add(new CaptureWindow(this, samples.ElementAt(i), parameters.ElementAt(parameters.Count - 1 - i), folders.ElementAt(folders.Count - 1 - i), analysis.ElementAt(analysis.Count - 1 - i), names.ElementAt(names.Count - 1 - i), location, size, false, maps.ElementAt(maps.Count - 1 - i))); } else { capturesList.Add(new CaptureWindow(this, samples.ElementAt(i), parameters.ElementAt(parameters.Count - 1 - i), folders.ElementAt(folders.Count - 1 - i), analysis.ElementAt(analysis.Count - 1 - i), names.ElementAt(names.Count - 1 - i), location, size, true, maps.ElementAt(maps.Count - 1 - i))); } capturesList.ElementAt(i + previousCaptures).Uid = (i + previousCaptures).ToString(); samplesList.Add(samples.ElementAt(i)); samplesList.ElementAt(i + previousCaptures).Uid = (i + previousCaptures).ToString(); capturesNames.Add(names.ElementAt(names.Count - 1 - i)); numberCapturesRunning++; } else { MessageBox.Show("Capture of process " + names.ElementAt(names.Count - 1 - i) + " could not be accomplished. Object not found."); return; } } // UI modification according to new situation sampleSP.Children.Clear(); sampleSP.Children.Add(samplesList.ElementAt(0)); infoLabel.Content = "Process 1/" + capturesList.Count.ToString(); if (capturesList.Count >= 2) { rightSp.Visibility = Visibility.Visible; leftSp.Visibility = Visibility.Visible; } MainPage.capturesRunning = true; Border1.Visibility = Visibility.Visible; Border2.Visibility = Visibility.Visible; sampleSP.Visibility = Visibility.Visible; infoLabel.Visibility = Visibility.Visible; nameLabel.Visibility = Visibility.Visible; ShowButton.IsEnabled = true; // If this is the first time if (parameters.Count == capturesList.Count) { ArtificialScroll(); } }