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;
 
  115             foreach (FilterInfo filterInfo 
in new FilterInfoCollection(FilterCategory.VideoInputDevice))
 
  117                 this.ComboBoxCameras.Items.Add(filterInfo.Name);
 
  118                 this.VideoSources.Add(filterInfo.Name, filterInfo.MonikerString);
 
  119                 if (!String.IsNullOrEmpty(
this.ConfigurationInformation.Camera.Name) &&
 
  120                     filterInfo.Name == this.ConfigurationInformation.Camera.Name)
 
  121                     this.ComboBoxCameras.SelectedIndex = i;
 
  133         private void buttonRefreshCams_Click(
object sender, EventArgs e)
 
  135             this.ComboBoxCameras.Items.Clear();
 
  136             this.VideoSources.Clear();
 
  137             this.InitiateCameraDropdown();
 
  138             this.ConfigurationInformation.Camera.Name = this.ComboBoxCameras.SelectedItem.ToString();
 
  139             this.ImagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
 
  151         protected override void Dispose(
bool disposing)
 
  155                 this.components?.Dispose();
 
  157             this.ImagingControl.StopImaging();
 
  159             base.Dispose(disposing);
 
  163         #region background job 
  173             this.StartScanning?.Invoke();
 
  176             string imageFolder = ResetImageFolder(this.ConfigurationInformation);
 
  178             int numberOfTotalSteps;
 
  180             GetResolutionAndSteps(precision, this.ConfigurationInformation, out numberOfTotalSteps, out resolution);
 
  182             MoveLaserToLeftStartPosition(this.
Arduino, this.ImagingControl, this.ConfigurationInformation);
 
  185             if (!this.InitiateWriter(this.
Arduino, this.ConfigurationInformation, out writer))
 
  188             if (this.PerformScan(this.
Arduino, this.ImagingControl, this.ConfigurationInformation, numberOfTotalSteps, resolution, imageFolder, writer)) 
return;
 
  190             if (this.ConfigurationInformation.Places.FileFormat == 
FileFormat.Ascii)
 
  191                 this.
Arduino.ActivateLaser(
false);
 
  193             SavePoints(
this, writer, this.ConfigurationInformation);
 
  204             this.RadialGaugeProgress.Value = e.ProgressPercentage;
 
  216             this.StopScanning?.Invoke();
 
  218             this.ToggleButtonCapture.ToggleState = ToggleButtonState.Inactive;
 
  219             this.ScanWorker.DoWork -= this.ScanWorker_DoWork;
 
  220             this.ScanWorker.ProgressChanged -= this.ScanWorker_ProgressChanged;
 
  221             this.ScanWorker.RunWorkerCompleted -= this.ScanWorker_RunWorkerCompleted;
 
  222             this.
Arduino.ActivateLaser(
false);
 
  237             this.RadialGaugeProgress.Value = 0;
 
  239             if (this.ScanWorker.IsBusy != 
true)
 
  241                 this.ScanWorker.DoWork += this.ScanWorker_DoWork;
 
  242                 this.ScanWorker.ProgressChanged += this.ScanWorker_ProgressChanged;
 
  243                 this.ScanWorker.RunWorkerCompleted += this.ScanWorker_RunWorkerCompleted;
 
  244                 this.ScanWorker.WorkerReportsProgress = 
true;
 
  245                 this.ScanWorker.WorkerSupportsCancellation = 
true;
 
  246                 this.ScanWorker.RunWorkerAsync((
Precision)this.RadialSliderPrecision.Value);
 
  249                 this.ScanWorker.CancelAsync();
 
  261             if (!this.VideoSources.ContainsKey(
this.ComboBoxCameras.SelectedItem.ToString()))
 
  264             this.ConfigurationInformation.Camera.Name = this.ComboBoxCameras.SelectedItem.ToString();
 
  265             this.ConfigurationInformation.Camera.Moniker = this.VideoSources[this.ComboBoxCameras.SelectedItem.ToString()];
 
  267             this.SetMaxFrameSizes(this.ConfigurationInformation.Camera.Moniker);
 
  269             this.ImagingControl.LaserMotorEnabled = this.ConfigurationInformation.Laser.MotorEnabled;
 
  270             this.ImagingControl.LaserLeftPosition = this.ConfigurationInformation.Laser.SwipeMin * this.ConfigurationInformation.Camera.Width / 100;
 
  271             this.ImagingControl.LaserRightPosition = this.ConfigurationInformation.Laser.SwipeMax * this.ConfigurationInformation.Camera.Width / 100;
 
  273             this.ImagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
 
  278         private void SetMaxFrameSizes(
string monikerString)
 
  280             VideoCaptureDevice source = 
new VideoCaptureDevice(monikerString);
 
  282             if (source.VideoCapabilities.Length > 0)
 
  284                 VideoCapabilities max = source.VideoCapabilities.OrderBy(p => p.FrameSize.Width).Last();
 
  285                 source.VideoResolution = max;
 
  287             if (null != source.VideoResolution)
 
  289                 this.ConfigurationInformation.Camera.Height = source.VideoResolution.FrameSize.Height;
 
  290                 this.ConfigurationInformation.Camera.Width = source.VideoResolution.FrameSize.Width;
 
  314             Image imageOff = null;
 
  315             List<ColorPoint3D> points = 
new List<ColorPoint3D>();
 
  325                     imageOff = (
Image) image.Clone();
 
  326                     imageOff.SaveImage(imageFolder, 
"OffLaserLight", actualSteps, configuration); 
 
  336                 image.SaveImage(imageFolder, 
"OnLaserLight", actualSteps, configuration);
 
  339                 image.SaveImage(imageFolder, 
"LaserLight", actualSteps, configuration);
 
  342                 skeletonImage.SaveImage(imageFolder, 
"Skeleton", actualSteps, configuration);
 
  363                         if (this.ScanWorker.CancellationPending)
 
  368                         image = CaptureSweepImage(actualSteps, imaging, configuration, ref points);
 
  376                         if (this.ScanWorker.CancellationPending)
 
  381                         image = CaptureSweepImage(actualSteps, imaging, configuration, ref points);
 
  419             for (
int actualSteps = 0; actualSteps <= numberOfTotalSteps; actualSteps += resolution.
Steps)
 
  421                 if (this.ScanWorker.CancellationPending)
 
  424                 int percentage = actualSteps*100/numberOfTotalSteps;
 
  426                 IEnumerable<ColorPoint3D> points = this.ScanImage(actualSteps, imageFolder, resolution.
Steps, resolution.
SweepSteps, arduino, cameraControl, configuration);
 
  432                 this.ScanWorker.ReportProgress(percentage);
 
  485             resolution = configuration.
Resolutions.First(x => x.Precision == precision);
 
  501             string imageFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
 
  547             control.Invoke((MethodInvoker) delegate
 
  549                 SaveFileDialog saveDialog = 
new SaveFileDialog();
 
  557                         saveDialog.DefaultExt = 
".PLY";
 
  558                         saveDialog.Filter = 
"PLY (.ply)|*.ply";
 
  559                         saveDialog.FileName = 
"ColoredPoints" + DateTime.Now.ToFileTime();
 
  562                         saveDialog.DefaultExt = 
".asc";
 
  563                         saveDialog.Filter = 
"Ascii (.asc)|*.asc";
 
  564                         saveDialog.FileName = 
"Points" + DateTime.Now.ToFileTime();
 
  568                 DialogResult result = saveDialog.ShowDialog();
 
  570                 if (result != DialogResult.OK)
 
  573                 string filename = saveDialog.FileName;
 
  575                 writer.
Write(filename);
 
  589             this.ImagingControl.StopImaging();
 
  590             if (this.ScanWorker.IsBusy)
 
  591                 this.ScanWorker.CancelAsync();
 
  601             this.ImagingControl.StartImaging(this.ConfigurationInformation.Camera.Name);
 
  604         private void RadialSliderPrecision_ValueChanged(
object sender, RadialSlider.ValueChangedEventArgs args)
 
  606             this.RadialSliderPrecision.ValueChanged -= this.RadialSliderPrecision_ValueChanged;
 
  608             int testValue = (int)Math.Round(
this.RadialSliderPrecision.Value);
 
  609             this.RadialSliderPrecision.Value = testValue;
 
  611             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.