Simply3DScan
Extensions.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.Drawing;
3 using System.IO;
4 using System.Windows.Forms;
5 using Configuration;
6 
7 namespace SharedObjects
8 {
12  public static class Extensions
13  {
20  [Log]
21  [LogException]
22  public static ColorPoint3D Intersection(this Line line1, Line line2)
23  {
24  //intersection of the two coplanar lines
25  ColorPoint3D intersectionPoint3D = new ColorPoint3D((line2.Beta - line1.Beta)/(line1.Alpha - line2.Alpha), 0, 0);
26  intersectionPoint3D.Z = line2.Alpha * intersectionPoint3D.X + line2.Beta;
27  return intersectionPoint3D;
28  }
29 
37  [Log]
38  [LogException]
39  public static void ChevronFromPoints(this ColorPoint3D point1, ColorPoint3D point2, out double alpha, out double beta)
40  {
41  alpha = (point2.Z - point1.Z) / (point2.X - point1.X);
42  beta = point1.Z - alpha * point1.X;
43  }
44 
53  [Log]
54  [LogException]
55  public static void SaveImage(this Image image, string imageFolder, string name, int actualSteps, Information configuration)
56  {
57  if (!configuration.Places.SaveImages)
58  return;
59  string file =
60  $"Image_{name}_{(configuration.Motor.MicroStepsEnabled ? "MS" : "NS")}{(configuration.Motor.MicroStepsEnabled ? actualSteps : actualSteps*16)}.png";
61  string filePath = Path.Combine(imageFolder, file);
62  image.Save(filePath);
63  }
64 
71  [LogException]
72  public static IEnumerable<T> Descendants<T>(this Control control) where T : class
73  {
74 
75  foreach (Control child in control.Controls)
76  {
77  T childOfT = child as T;
78  if (childOfT != null)
79  {
80  yield return childOfT;
81  }
82 
83  if (!child.HasChildren)
84  continue;
85  foreach (T descendant in Descendants<T>(child))
86  {
87  yield return descendant;
88  }
89  }
90 
91  }
92  }
93 }
Class holding the configuration information
Definition: Information.cs:8
static ColorPoint3D Intersection(this Line line1, Line line2)
Intersections between line 1 and the specified line2.
Definition: Extensions.cs:22
double Z
Gets or sets the z.
Definition: ColorPoint3D.cs:30
static void SaveImage(this Image image, string imageFolder, string name, int actualSteps, Information configuration)
Saves the image.
Definition: Extensions.cs:55
static IEnumerable< T > Descendants< T >(this Control control)
Descendantses the specified control.
Definition: Extensions.cs:72
double X
Gets or sets the x.
Definition: ColorPoint3D.cs:16
Extension methods
Definition: Extensions.cs:12
Places Places
Gets or sets the places.
Definition: Information.cs:59
static void ChevronFromPoints(this ColorPoint3D point1, ColorPoint3D point2, out double alpha, out double beta)
Chevrons from points.
Definition: Extensions.cs:39
double Beta
Gets or sets the beta chevron.
Definition: Line.cs:46
bool SaveImages
Gets or sets a value indicating whether [save images].
Definition: Places.cs:15
double Alpha
Gets or sets the alpha chevron.
Definition: Line.cs:34