2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using AForge.Video.DirectShow;
13 using Syncfusion.Windows.Forms.Tools;
27 protected readonly BackgroundWorker ScanWorker =
new BackgroundWorker();
42 protected readonly Dictionary<string, string> VideoSources =
new Dictionary<string, string>();
47 public delegate
void StartScan();
58 public delegate
void StopScan();
74 this.InitializeComponent();
83 private void ScanControl_Load(
object sender, EventArgs e)
86 this.InitiateCameraDropdown();
98 this.
Arduino.ActivateLaser(
false);
101 this.ToggleButtonCapture.Renderer = styleRenderer;
103 this.RadialSliderPrecision.ValueChanged += this.RadialSliderPrecision_ValueChanged;
114 FilterInfoCollection filterInfoCollection =
new FilterInfoCollection(FilterCategory.VideoInputDevice);
117 foreach (FilterInfo filterInfo
in filterInfoCollection)
119 this.ComboBoxCameras.Items.Add(filterInfo.Name);
120 this.VideoSources.Add(filterInfo.Name, filterInfo.MonikerString);
121 if (!String.IsNullOrEmpty(
this.ConfigurationInformation.Camera.Name) &&
122 filterInfo.Name == this.ConfigurationInformation.Camera.Name)
123 this.ComboBoxCameras.SelectedIndex = i;
135 private void buttonRefreshCams_Click(
object sender, EventArgs e)
137 this.ComboBoxCameras.Items.Clear();
138 this.VideoSources.Clear();
139 this.InitiateCameraDropdown();
140 this.ConfigurationInformation.Camera.Name = this.ComboBoxCameras.SelectedItem.ToString();
141 this.ImagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
153 protected override void Dispose(
bool disposing)
155 if (disposing && (this.components != null))
157 this.components.Dispose();
159 this.ImagingControl.StopImaging();
161 base.Dispose(disposing);
165 #region background job
175 if (this.StartScanning != null)
176 this.StartScanning();
179 string imageFolder = ResetImageFolder(this.ConfigurationInformation);
181 int numberOfTotalSteps;
183 GetResolutionAndSteps(precision, this.ConfigurationInformation, out numberOfTotalSteps, out resolution);
185 MoveLaserToLeftStartPosition(this.
Arduino, this.ImagingControl, this.ConfigurationInformation);
188 if (!this.InitiateWriter(this.
Arduino, this.ConfigurationInformation, out writer))
191 if (this.PerformScan(this.
Arduino, this.ImagingControl, this.ConfigurationInformation, numberOfTotalSteps, resolution, imageFolder, writer))
return;
193 if (this.ConfigurationInformation.Places.FileFormat ==
FileFormat.Ascii)
194 this.
Arduino.ActivateLaser(
false);
196 SavePoints(
this, writer, this.ConfigurationInformation);
207 this.RadialGaugeProgress.Value = e.ProgressPercentage;
219 if (this.StopScanning != null)
222 this.ToggleButtonCapture.ToggleState = ToggleButtonState.Inactive;
223 this.ScanWorker.DoWork -= this.ScanWorker_DoWork;
224 this.ScanWorker.ProgressChanged -= this.ScanWorker_ProgressChanged;
225 this.ScanWorker.RunWorkerCompleted -= this.ScanWorker_RunWorkerCompleted;
226 this.
Arduino.ActivateLaser(
false);
241 this.RadialGaugeProgress.Value = 0;
243 if (this.ScanWorker.IsBusy !=
true)
245 this.ScanWorker.DoWork += this.ScanWorker_DoWork;
246 this.ScanWorker.ProgressChanged += this.ScanWorker_ProgressChanged;
247 this.ScanWorker.RunWorkerCompleted += this.ScanWorker_RunWorkerCompleted;
248 this.ScanWorker.WorkerReportsProgress =
true;
249 this.ScanWorker.WorkerSupportsCancellation =
true;
250 this.ScanWorker.RunWorkerAsync((
Precision)this.RadialSliderPrecision.Value);
253 this.ScanWorker.CancelAsync();
265 if (!this.VideoSources.ContainsKey(
this.ComboBoxCameras.SelectedItem.ToString()))
268 this.ConfigurationInformation.Camera.Name = this.ComboBoxCameras.SelectedItem.ToString();
269 this.ConfigurationInformation.Camera.Moniker = this.VideoSources[this.ComboBoxCameras.SelectedItem.ToString()];
271 this.SetMaxFrameSizes(this.ConfigurationInformation.Camera.Moniker);
273 this.ImagingControl.LaserMotorEnabled = this.ConfigurationInformation.Laser.MotorEnabled;
274 this.ImagingControl.LaserLeftPosition = this.ConfigurationInformation.Laser.SwipeMin * this.ConfigurationInformation.Camera.Width / 100;
275 this.ImagingControl.LaserRightPosition = this.ConfigurationInformation.Laser.SwipeMax * this.ConfigurationInformation.Camera.Width / 100;
277 this.ImagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
282 private void SetMaxFrameSizes(
string monikerString)
284 VideoCaptureDevice source =
new VideoCaptureDevice(monikerString);
286 if (source.VideoCapabilities.Length > 0)
288 VideoCapabilities max = source.VideoCapabilities.OrderBy(p => p.FrameSize.Width).Last();
289 source.VideoResolution = max;
291 if (null != source.VideoResolution)
293 this.ConfigurationInformation.Camera.Height = source.VideoResolution.FrameSize.Height;
294 this.ConfigurationInformation.Camera.Width = source.VideoResolution.FrameSize.Width;
318 Image imageOff = null;
319 List<ColorPoint3D> points =
new List<ColorPoint3D>();
329 imageOff = (
Image) image.Clone();
330 imageOff.SaveImage(imageFolder,
"OffLaserLight", actualSteps, configuration);
340 image.SaveImage(imageFolder,
"OnLaserLight", actualSteps, configuration);
343 image.SaveImage(imageFolder,
"LaserLight", actualSteps, configuration);
346 skeletonImage.SaveImage(imageFolder,
"Skeleton", actualSteps, configuration);
367 if (this.ScanWorker.CancellationPending)
372 image = CaptureSweepImage(actualSteps, imaging, configuration, ref points);
380 if (this.ScanWorker.CancellationPending)
385 image = CaptureSweepImage(actualSteps, imaging, configuration, ref points);
423 for (
int actualSteps = 0; actualSteps <= numberOfTotalSteps; actualSteps += resolution.
Steps)
425 if (this.ScanWorker.CancellationPending)
428 int percentage = actualSteps*100/numberOfTotalSteps;
430 IEnumerable<ColorPoint3D> points = this.ScanImage(actualSteps, imageFolder, resolution.
Steps, resolution.
SweepSteps, arduino, cameraControl, configuration);
436 this.ScanWorker.ReportProgress(percentage);
489 resolution = configuration.
Resolutions.First(x => x.Precision == precision);
505 string imageFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
551 control.Invoke((MethodInvoker) delegate
553 SaveFileDialog saveDialog =
new SaveFileDialog();
561 saveDialog.DefaultExt =
".PLY";
562 saveDialog.Filter =
"PLY (.ply)|*.ply";
563 saveDialog.FileName =
"ColoredPoints" + DateTime.Now.ToFileTime();
566 saveDialog.DefaultExt =
".asc";
567 saveDialog.Filter =
"Ascii (.asc)|*.asc";
568 saveDialog.FileName =
"Points" + DateTime.Now.ToFileTime();
572 DialogResult result = saveDialog.ShowDialog();
574 if (result != DialogResult.OK)
577 string filename = saveDialog.FileName;
579 writer.
Write(filename);
593 this.ImagingControl.StopImaging();
594 if (this.ScanWorker.IsBusy)
595 this.ScanWorker.CancelAsync();
605 this.ImagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
608 private void RadialSliderPrecision_ValueChanged(
object sender, RadialSlider.ValueChangedEventArgs args)
610 this.RadialSliderPrecision.ValueChanged -= this.RadialSliderPrecision_ValueChanged;
612 int testValue = (int)Math.Round(
this.RadialSliderPrecision.Value);
613 this.RadialSliderPrecision.Value = testValue;
615 this.RadialSliderPrecision.ValueChanged += this.RadialSliderPrecision_ValueChanged;
static void CreatePathIfNotExisting(string folder)
Creates the path if not existing.
FileFormat FileFormat
Gets or sets the file format.
ScanControl()
Initializes a new instance of the ScanControl class.
Configuration of a scan resulution
void ToggleButtonCapture_Click(object sender, EventArgs e)
Handles the Click event of the toggleButtonCapture control.
Class for detecting an arduino and sending commands to it
string LastFilePath
Gets or sets the last file path.
void RotateLaserCw(int steps)
Rotates the laser clockwise.
void Start()
Starts this instance.
void ScanWorker_DoWork(object sender, DoWorkEventArgs e)
Handles the DoWork event of the scanWorker control.
void Init(ArduinoCommands arduino)
Initializes the control.
Class holding configuration to access an arduino
static string ResetImageFolder(Information configuration)
Resets the image folder.
override void Dispose(bool disposing)
Verwendete Ressourcen bereinigen.
void Write(string fileName)
Writes to specified file name.
int Steps
Gets or sets the steps.
static void MoveLaserToLeftStartPosition(ArduinoCommands arduino, CameraControl cameraControl, Information configuration)
Moves the laser to left start position.
float SwipeMax
Gets or sets the swipe maximum.
string ImageSubPath
Gets or sets the image sub path.
Control for accessing a camera
void AddPoint(ColorPoint3D point)
Adds the point.
bool MicroStepsEnabled
Gets or sets a value indicating whether [micro steps enabled].
Class for creating a singleton for a generic class
void InitiateCameraDropdown()
Initiates the camera dropdown.
IEnumerable< ColorPoint3D > ScanImage(int actualSteps, string imageFolder, int steps, int sweep, ArduinoCommands arduino, CameraControl imaging, Information configuration)
Scans the image.
void ComboBoxCameras_SelectedIndexChanged(object sender, EventArgs e)
Handles the SelectedIndexChanged event of the comboBoxCameras control.
void RotateTurnTableCw(int steps)
Rotates the turn table clockwise.
FileFormat
File output format
static T Instance
Gets the instance.
void ActivateLaser(bool on=true)
Activates the laser.
int MicroSteps
Gets or sets the number of micro steps.
Image GetNextPicture()
Gets the next picture.
void RotateLaserCcw(int steps)
Rotates the laser counter clockwise.
bool PerformScan(ArduinoCommands arduino, CameraControl cameraControl, Information configuration, int numberOfTotalSteps, Resolution resolution, string imageFolder, IPointWriter writer)
Performs the scan.
Interface for writing points to file
int Width
Gets or sets the width.
void ScanWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
Handles the ProgressChanged event of the ScanWorker control.
static void DeleteAllFilesInFolder(string imageFolder)
Deletes all files in folder.
int SweepSteps
Gets or sets the sweep steps.
static void GetResolutionAndSteps(Precision precision, Information configuration, out int numberOfTotalSteps, out Resolution resolution)
Gets the resolution and steps.
StartScan StartScanning
Occurs when [start scanning].
Precision
Information about the precision of a scan
int Steps
Gets or sets the number of steps.
float SwipeMin
Gets or sets the swipe minimum.
static void SavePoints(Control control, IPointWriter writer, Information configuration)
Saves the points.
StopScan StopScanning
Occurs when [stop scanning].
virtual void ScanWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Handles the RunWorkerCompleted event of the ScanWorker control.
void Stop()
Stops this instance.
bool MotorEnabled
Gets or sets a value indicating whether [motor enabled].
bool InitiateWriter(ArduinoCommands arduino, Information configuration, out IPointWriter writer)
Initiates the writer.