Porositys.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using static PaintDotNet.Base.DedicatedAnalysis.Porosity.PorositysGlobalSettings;
  5. namespace PaintDotNet.Base.DedicatedAnalysis.Porosity.Model
  6. {
  7. /// <summary>
  8. /// 孔隙(Porosity)
  9. ///
  10. /// </summary>
  11. public class Porositys
  12. {
  13. /// <summary>
  14. /// 构成孔隙的微粒集合
  15. /// </summary>
  16. public List<Particle> particles;
  17. /// <summary>
  18. /// 当前孔隙判定所使用的标准
  19. /// </summary>
  20. public PorositysStandard standard;
  21. /// <summary>
  22. /// 像素长度
  23. /// </summary>
  24. public double pixelLength;
  25. /// <summary>
  26. /// 像素宽度
  27. /// </summary>
  28. public double pixelWidth;
  29. /// <summary>
  30. /// 物理长度
  31. /// </summary>
  32. public double physicalLength;
  33. /// <summary>
  34. /// 物理宽度
  35. /// </summary>
  36. public double physicalWidth;
  37. /// <summary>
  38. /// 最小卡轨直径
  39. /// </summary>
  40. public float MinimumCaliperDiameter;
  41. /// <summary>
  42. /// 矩形轮廓
  43. /// </summary>
  44. public Rectangle rectProfile;
  45. // 排列方式
  46. public PorosityArrangement arrangement
  47. {
  48. get
  49. {
  50. return particles.Count > 1 ? PorosityArrangement.Aligned : PorosityArrangement.Scattered;
  51. }
  52. }
  53. /// <summary>
  54. /// 面积(area)
  55. /// </summary>
  56. public double area;
  57. /// <summary>
  58. /// 直径(diameter)
  59. /// </summary>
  60. public double diameter;
  61. /// <summary>
  62. /// 孔隙分类
  63. /// </summary>
  64. public ClassesOfPorositys classes;
  65. /// <summary>
  66. /// 孔隙类型
  67. /// </summary>
  68. public TypesOfPorositys type;
  69. /// <summary>
  70. /// 孔隙颜色
  71. /// </summary>
  72. private ColorOfPorositys color_;
  73. public ColorOfPorositys color
  74. {
  75. get
  76. {
  77. return color_;
  78. }
  79. set
  80. {
  81. color_ = value;
  82. this.standard.determineType(this);
  83. }
  84. }
  85. /// <summary>
  86. /// 化学特性
  87. /// </summary>
  88. public String chemicalCharacteristics = "";
  89. public bool superBig = false;
  90. /// <summary>
  91. /// 构造函数
  92. /// </summary>
  93. /// <param name="standard"></param>
  94. public Porositys(PorositysStandard standard)
  95. {
  96. this.particles = new List<Particle>();
  97. this.standard = standard;
  98. }
  99. public Porositys(PorositysStandard standard, PointF[] points)
  100. {
  101. this.particles = new List<Particle>();
  102. this.standard = standard;
  103. OpenCvSharp.Point[] cvPoints = new OpenCvSharp.Point[points.Length];
  104. for (int i = 0; i < points.Length; i++)
  105. {
  106. OpenCvSharp.Point point = new OpenCvSharp.Point(points[i].X, points[i].Y);
  107. cvPoints[i] = point;
  108. }
  109. Particle particle = new Particle(cvPoints, standard);
  110. this.addParticles(particle);
  111. }
  112. public void addParticles(Particle particle)
  113. {
  114. this.particles.Add(particle);
  115. parametersCalculation();
  116. }
  117. public void addParticles(List<Particle> particles)
  118. {
  119. this.particles.AddRange(particles);
  120. parametersCalculation();
  121. }
  122. public void removeParticles(Particle particle)
  123. {
  124. this.particles.Remove(particle);
  125. parametersCalculation();
  126. }
  127. /// <summary>
  128. /// 参数计算
  129. /// </summary>
  130. private void parametersCalculation()
  131. {
  132. if (this.particles.Count == 0)
  133. {
  134. return;
  135. }
  136. int minx = 0, miny = 0, maxx = 0, maxy = 0;
  137. int countGlobular = 0;
  138. Particle particle = this.particles[0];
  139. minx = particle.rectProfile.Left;
  140. maxx = particle.rectProfile.Right;
  141. miny = particle.rectProfile.Top;
  142. maxy = particle.rectProfile.Bottom;
  143. // 计算长度,宽度/直径,面积,形状系数,长宽比
  144. if (this.standard.globalSettings.rollingDirection == RollingDirection.PORTRAIT)
  145. {
  146. this.pixelLength = maxy - miny;
  147. this.pixelWidth = maxx - minx;
  148. }
  149. else
  150. {
  151. this.pixelWidth = maxy - miny;
  152. this.pixelLength = maxx - minx;
  153. }
  154. this.physicalLength = this.pixelLength * this.standard.globalSettings.pxPerUnit;
  155. this.physicalWidth = this.pixelWidth * this.standard.globalSettings.pxPerUnit;
  156. this.diameter = this.physicalLength > this.physicalWidth ? this.physicalLength : this.physicalWidth;
  157. this.area = this.physicalLength * this.physicalWidth * (Math.PI / 4);
  158. this.MinimumCaliperDiameter = particle.MinimumCaliperDiameter;
  159. this.rectProfile = new Rectangle(minx, miny, maxx - minx, maxy - miny);
  160. this.standard.determineType(this);
  161. //}
  162. }
  163. /// <summary>
  164. /// 排列方式
  165. /// </summary>
  166. public enum PorosityArrangement
  167. {
  168. /// <summary>
  169. /// 分散的
  170. /// </summary>
  171. Scattered,
  172. /// <summary>
  173. /// 排成行的
  174. /// </summary>
  175. Aligned
  176. }
  177. /// <summary>
  178. /// 孔隙分类
  179. /// </summary>
  180. public enum ClassesOfPorositys
  181. {
  182. D, F, S,G
  183. }
  184. }
  185. }