Simply3DScan
Config.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Drawing;
4 using System.IO;
5 using System.Xml.Serialization;
6 
7 namespace Configuration
8 {
12  public class Config
13  {
14  private const string fileName = "Configuration.xml";
15 
22  public Information Information { get; private set; }
23 
27  public void ReadConfiguration()
28  {
29  if (!File.Exists(fileName))
30  {
31  this.Information = CreateInitialConfiguration();
32  return;
33  }
34  this.Information = new Information();
35 
36  XmlSerializer reader = new XmlSerializer(typeof (Information));
37  StreamReader file = new StreamReader(fileName);
38  this.Information = (Information)reader.Deserialize(file);
39  file.Close();
40 
41  this.SetMissingValues();
42  }
43 
44  private void SetMissingValues()
45  {
46  if (null == this.Information.Resolutions || this.Information.Resolutions.Count == 0)
47  {
49  }
50 
51  if (this.Information.Turntable.Radius <= 0.01)
52  this.Information.Turntable.Radius = 6.25;
53 
54  if (this.Information.Turntable.SafetyDistance == 0)
56 
57  if (null == this.Information.Filter)
59  }
60 
64  public void WriteConfiguration()
65  {
66  XmlSerializer writer = new XmlSerializer(typeof(Information));
67  StreamWriter file = new StreamWriter(fileName);
68  writer.Serialize(file, this.Information);
69  file.Close();
70  }
71 
76  private static Information CreateInitialConfiguration()
77  {
78  return new Information
79  {
80  Language = Language.English,
85  VisibleLimit = CreateDefaultVisibleLimits(),
88  Resolutions = CreateDefaultResolutions(),
90  };
91  }
92 
97  public static Camera CreateDefaultCamera()
98  {
99  return new Camera
100  {
101  Name = "",
102  Moniker = "",
103  WorldCoordinates = new Coordinates {X = 0.0f, Y = 5.57f, Z = 30.9f},
104  Width = 1280,
105  Height = 960,
106  WorldWidth = 24.6f // c270, c9xx = 26.6f
107  };
108  }
109 
114  public static Motor CreateDefaultMotor()
115  {
116  return new Motor
117  {
118  Steps = 200,
119  MicroSteps = 16,
120  MicroStepsEnabled = true
121  };
122  }
123 
128  public static Laser CreateDefaultLaser()
129  {
130  return new Laser
131  {
132  WorldCoordinates = new Coordinates {X = 14.0f, Y = 6.4f, Z = 28.8f},
133  UpperRange = 0,
134  LowerRange = 30,
135  Offset = 90,
136  SwipeMin = 18.0f,
137  SwipeMax = 70.0f,
138  MotorEnabled = false
139  };
140  }
141 
147  {
148  return new Turntable
149  {
150  WorldCoordinates = new Coordinates {X = 0.0f, Y = 0.0f, Z = 7.5f},
151  Radius = 6.25f,
152  SafetyDistance = 5
153  };
154  }
155 
161  {
162  return new Line
163  {
164  PercentFromTop = 75f,
165  Color = Color.FromKnownColor(KnownColor.Blue)
166  };
167  }
168 
174  {
175  return new Arduino
176  {
177  Port = String.Empty,
178  BaudRate = 9600
179  };
180  }
181 
186  public static Places CreateDefaultPlaces()
187  {
188  return new Places
189  {
190  ImageSubPath = "Images",
191  LogSubPath = "Logs",
192  LastFilePath = String.Empty,
193  SaveImages = false,
194  FileFormat = FileFormat.Ascii
195  };
196  }
197 
202  public static List<Resolution> CreateDefaultResolutions()
203  {
204  return new List<Resolution>
205  {
206  new Resolution(Precision.Excellent, 1.125f, 10, 4),
207  new Resolution(Precision.Good, 2.25f, 20, 6),
208  new Resolution(Precision.Average, 4.5f, 40, 8),
209  new Resolution(Precision.BelowAverage, 9.0f, 80, 10),
210  new Resolution(Precision.Beasty, 18.0f, 160, 12)
211  };
212  }
213 
218  public static Filter CreateDefaultFilter()
219  {
220  return new Filter
221  {
222  UseHslFilter = true,
223  SaturationMin = 0.05f,
224  SaturationMax = 1f,
225  LuminanceMin = 0.05f,
226  LuminanceMax = 1f,
227  HueMin = 280,
228  HueMax = 340,
229  UseColorFilter = true,
230  FilterRedMin = 252,
231  FilterRedMax = 255,
232  FilterGreenMin = 0,
233  FilterGreenMax = 255,
234  FilterBlueMin = 0,
235  FilterBlueMax = 255,
236  GrayFilter = GrayFilter.BT709,
237  UseThresholdFilter = true,
238  Threshold = 40,
239  UseErosionFilter = true,
240  UseDiletationFilter = true
241  };
242  }
243  }
244 }
static List< Resolution > CreateDefaultResolutions()
Creates the default resolutions.
Definition: Config.cs:202
Path dependend configuration
Definition: Places.cs:7
Filter Filter
Gets or sets the filter.
Definition: Information.cs:89
Configuration of a scan resulution
Definition: Resolution.cs:10
Configuration of a turntable
Definition: Turntable.cs:7
Information Information
Gets the information.
Definition: Config.cs:22
static Arduino CreateDefaultArduinoSettings()
Creates the default arduino settings.
Definition: Config.cs:173
X,Y,Z - coordinates
Definition: Coordinates.cs:6
static Motor CreateDefaultMotor()
Creates the default motor.
Definition: Config.cs:114
Class holding configuration to access an arduino
Definition: Arduino.cs:7
Class holding the configuration information
Definition: Information.cs:8
Configuration of a camera
Definition: Camera.cs:7
void WriteConfiguration()
Writes the configuration to file.
Definition: Config.cs:64
Turntable Turntable
Gets or sets the turntable.
Definition: Information.cs:31
int SafetyDistance
Gets or sets the safety distance.
Definition: Turntable.cs:32
static Camera CreateDefaultCamera()
Creates the default camera.
Definition: Config.cs:97
void ReadConfiguration()
Reads the configuration from file.
Definition: Config.cs:27
static Places CreateDefaultPlaces()
Creates the default places.
Definition: Config.cs:186
static Turntable CreateDefaultTurntable()
Creates the default turntable.
Definition: Config.cs:146
Configuration regarding a laser
Definition: Laser.cs:7
static Line CreateDefaultVisibleLimits()
Creates the default visible limits.
Definition: Config.cs:160
static Laser CreateDefaultLaser()
Creates the default laser.
Definition: Config.cs:128
Configuration for motor
Definition: Motor.cs:7
FileFormat
File output format
Definition: FileFormat.cs:6
static Filter CreateDefaultFilter()
Creates the default filter.
Definition: Config.cs:218
List< Resolution > Resolutions
Gets or sets the resolutions.
Definition: Information.cs:67
Class for accessing the configuration.
Definition: Config.cs:12
Precision
Information about the precision of a scan
Definition: Precision.cs:6
double Radius
Gets or sets the radius.
Definition: Turntable.cs:23