GrainPointStyleModel.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. using OpenCvSharp;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.Base.SettingModel;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Windows.Forms;
  8. using Point = System.Drawing.Point;
  9. namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
  10. {
  11. class GrainPointStyleModel
  12. {
  13. /// <summary>
  14. /// 直线图形上所有的点
  15. /// </summary>
  16. public List<List<PointF>> straightLinePointList = new List<List<PointF>>();
  17. /// <summary>
  18. /// 圆圈图形上所有的点,其中第一个点为圆心坐标
  19. /// </summary>
  20. public List<List<PointF>> roundLinePointList = new List<List<PointF>>();
  21. /// <summary>
  22. /// 图形上所有的两个截点和计算的截距值(像素)
  23. /// </summary>
  24. public Dictionary<Line, int> lineValueList = new Dictionary<Line, int>();
  25. /// <summary>
  26. /// 0.5截点矩形集合
  27. /// </summary>
  28. private List<RectangleF> rectangleFCaps1 = new List<RectangleF>();
  29. private List<Point> rectangleCaps1 = new List<Point>();
  30. /// <summary>
  31. /// 1截点矩形集合
  32. /// </summary>
  33. private List<RectangleF> rectangleFCaps2 = new List<RectangleF>();
  34. private List<Point> rectangleCaps2 = new List<Point>();
  35. /// <summary>
  36. /// 1.5/2截点矩形集合(1.5)
  37. /// </summary>
  38. private List<RectangleF> rectangleFCaps3_1 = new List<RectangleF>();
  39. private List<Point> rectangleCaps3_1 = new List<Point>();
  40. /// <summary>
  41. /// 1.5/2截点矩形集合(2)
  42. /// </summary>
  43. private List<RectangleF> rectangleFCaps3_2 = new List<RectangleF>();
  44. private List<Point> rectangleCaps3_2 = new List<Point>();
  45. #region 截点样式
  46. /// <summary>
  47. /// 颜色(0.5)
  48. /// </summary>
  49. private int pointColor1;
  50. /// <summary>
  51. /// 线宽(0.5)
  52. /// </summary>
  53. private int pointWidth1;
  54. /// <summary>
  55. /// 点样式 0:空心 1:实心(0.5)
  56. /// </summary>
  57. private int pointStyle1;
  58. /// <summary>
  59. /// 大小(0.5)
  60. /// </summary>
  61. private int pointDiameter1;
  62. /// <summary>
  63. /// 截点误差(0.5)
  64. /// </summary>
  65. private int pointError1;
  66. /// <summary>
  67. /// 形状 0:圆形 1:方形(0.5)
  68. /// </summary>
  69. private int pointshape1;
  70. /// <summary>
  71. /// 颜色(1)
  72. /// </summary>
  73. private int pointColor2;
  74. /// <summary>
  75. /// 线宽(1)
  76. /// </summary>
  77. private int pointWidth2;
  78. /// <summary>
  79. /// 点样式 0:空心 1:实心(1)
  80. /// </summary>
  81. private int pointStyle2;
  82. /// <summary>
  83. /// 大小(1)
  84. /// </summary>
  85. private int pointDiameter2;
  86. /// <summary>
  87. /// 截点误差(1)
  88. /// </summary>
  89. private int pointError2;
  90. /// <summary>
  91. /// 形状 0:圆形 1:方形(1)
  92. /// </summary>
  93. private int pointshape2;
  94. /// <summary>
  95. /// 颜色(1.5/2)
  96. /// </summary>
  97. private int pointColor3;
  98. /// <summary>
  99. /// 线宽(1.5/2)
  100. /// </summary>
  101. private int pointWidth3;
  102. /// <summary>
  103. /// 点样式 0:空心 1:实心(1.5/2)
  104. /// </summary>
  105. private int pointStyle3;
  106. /// <summary>
  107. /// 大小(1.5/2)
  108. /// </summary>
  109. private int pointDiameter3;
  110. /// <summary>
  111. /// 截点误差(1.5/2)
  112. /// </summary>
  113. private int pointError3;
  114. /// <summary>
  115. /// 形状 0:圆形 1:方形(1.5/2)
  116. /// </summary>
  117. private int pointshape3;
  118. #endregion
  119. /// <summary>
  120. /// 找到当前的参数数据
  121. /// </summary>
  122. /// <param name="menuId"></param>
  123. /// <returns></returns>
  124. public GrainPointStyleModel cloneListParamModel()
  125. {
  126. GrainPointStyleModel newMod = new GrainPointStyleModel();
  127. newMod.pointColor1 = this.pointColor1;
  128. newMod.pointWidth1 = this.pointWidth1;
  129. newMod.pointStyle1 = this.pointStyle1;
  130. newMod.pointDiameter1 = this.pointDiameter1;
  131. newMod.pointError1 = this.pointError1;
  132. newMod.pointshape1 = this.pointshape1;
  133. newMod.pointColor2 = this.pointColor2;
  134. newMod.pointWidth2 = this.pointWidth2;
  135. newMod.pointStyle2 = this.pointStyle2;
  136. newMod.pointDiameter2 = this.pointDiameter2;
  137. newMod.pointError2 = this.pointError2;
  138. newMod.pointshape2 = this.pointshape2;
  139. newMod.pointColor3 = this.pointColor3;
  140. newMod.pointWidth3 = this.pointWidth3;
  141. newMod.pointStyle3 = this.pointStyle3;
  142. newMod.pointDiameter3 = this.pointDiameter3;
  143. newMod.pointError3 = this.pointError3;
  144. newMod.pointshape3 = this.pointshape3;
  145. return newMod;
  146. }
  147. public GrainPointStyleModel cloneModel()
  148. {
  149. GrainPointStyleModel newMod = new GrainPointStyleModel();
  150. //newMod.straightLinePointList = new List<List<PointF>>();
  151. //newMod.straightLinePointList.AddRange(this.straightLinePointList);//#####
  152. //newMod.roundLinePointList = new List<List<PointF>>();
  153. //newMod.roundLinePointList.AddRange(this.roundLinePointList);//
  154. ////newMod.lineValueList = new Dictionary<Line, int>();
  155. newMod.pointColor1 = this.pointColor1;
  156. newMod.pointWidth1 = this.pointWidth1;
  157. newMod.pointStyle1 = this.pointStyle1;
  158. newMod.pointDiameter1 = this.pointDiameter1;
  159. newMod.pointError1 = this.pointError1;
  160. newMod.pointshape1 = this.pointshape1;
  161. newMod.pointColor2 = this.pointColor2;
  162. newMod.pointWidth2 = this.pointWidth2;
  163. newMod.pointStyle2 = this.pointStyle2;
  164. newMod.pointDiameter2 = this.pointDiameter2;
  165. newMod.pointError2 = this.pointError2;
  166. newMod.pointshape2 = this.pointshape2;
  167. newMod.pointColor3 = this.pointColor3;
  168. newMod.pointWidth3 = this.pointWidth3;
  169. newMod.pointStyle3 = this.pointStyle3;
  170. newMod.pointDiameter3 = this.pointDiameter3;
  171. newMod.pointError3 = this.pointError3;
  172. newMod.pointshape3 = this.pointshape3;
  173. return newMod;
  174. }
  175. /// <summary>
  176. /// 更新图形上所有的两个截点和计算的截距值
  177. /// </summary>
  178. public void ReloadLineValueList()
  179. {
  180. this.lineValueList.Clear();
  181. for (int i = 0; i < straightLinePointList.Count; i++)
  182. {
  183. Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
  184. List<PointF> linePointList = straightLinePointList[i];
  185. AddLineValueList(false, linePointList, out lineValueList1);
  186. foreach (var itemKey in lineValueList1.Keys)
  187. this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
  188. }
  189. for (int i = 0; i < roundLinePointList.Count; i++)
  190. {
  191. Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
  192. List<PointF> linePointList = roundLinePointList[i];
  193. AddLineValueList(true, linePointList, out lineValueList1);
  194. foreach (var itemKey in lineValueList1.Keys)
  195. this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
  196. }
  197. }
  198. private void AddLineValueList(bool isRound, List<PointF> linePointList, out Dictionary<Line, int> lineValueList1)
  199. {
  200. List<Point> rectangleCapsTotal = new List<Point>();
  201. rectangleCapsTotal.AddRange(this.rectangleCaps1);
  202. rectangleCapsTotal.AddRange(this.rectangleCaps2);
  203. rectangleCapsTotal.AddRange(this.rectangleCaps3_1);
  204. rectangleCapsTotal.AddRange(this.rectangleCaps3_2);
  205. lineValueList1 = new Dictionary<Line, int>();
  206. Point lastCap_Point = new Point(-1, -1);
  207. foreach (var point in linePointList)
  208. {
  209. if (rectangleCapsTotal.Contains(new Point((int)point.X, (int)point.Y)))
  210. {
  211. if (lastCap_Point.X >= 0)
  212. lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
  213. (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
  214. lastCap_Point = new Point((int)point.X, (int)point.Y);
  215. }
  216. }
  217. if (isRound && lineValueList1.Count > 0)
  218. {
  219. PointF point = new PointF(0, 0);
  220. foreach (var itemkey in lineValueList1.Keys)
  221. {
  222. point = new PointF(itemkey.startPoint.X, itemkey.startPoint.Y);
  223. break;
  224. }
  225. lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
  226. (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
  227. }
  228. }
  229. /// <summary>
  230. /// 刷新截点集合,并赋值截距列表
  231. /// </summary>
  232. /// <param name="linePointList">图形上所有的点</param>
  233. public void AddRectangleToRectangleFCapsAndLine(Mat mat, int matLevel, bool vGuideStylesOrHGuideStyles, int surfaceWidth, int surfaceHeight)
  234. {
  235. this.lineValueList.Clear();
  236. this.rectangleFCaps1.Clear();
  237. this.rectangleFCaps2.Clear();
  238. this.rectangleFCaps3_1.Clear();
  239. this.rectangleFCaps3_2.Clear();
  240. this.rectangleCaps1.Clear();
  241. this.rectangleCaps2.Clear();
  242. this.rectangleCaps3_1.Clear();
  243. this.rectangleCaps3_2.Clear();
  244. for (int i = 0; i < straightLinePointList.Count; i++)
  245. {
  246. Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
  247. List<PointF> linePointList = straightLinePointList[i];
  248. AddRectangleCapsAndLine(false, mat, matLevel, linePointList, vGuideStylesOrHGuideStyles, surfaceWidth, surfaceHeight, out lineValueList1);
  249. foreach (var itemKey in lineValueList1.Keys)
  250. this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
  251. }
  252. for (int i = 0; i < roundLinePointList.Count; i++)
  253. {
  254. Dictionary<Line, int> lineValueList1 = new Dictionary<Line, int>();
  255. List<PointF> linePointList = roundLinePointList[i];
  256. AddRectangleCapsAndLine(true, mat, matLevel, linePointList, vGuideStylesOrHGuideStyles, surfaceWidth, surfaceHeight, out lineValueList1);
  257. foreach (var itemKey in lineValueList1.Keys)
  258. this.lineValueList.Add(itemKey, lineValueList1[itemKey]);
  259. }
  260. }
  261. private void AddRectangleCapsAndLine(bool isRound, Mat mat, int matLevel, List<PointF> linePointList, bool vGuideStylesOrHGuideStyles, int surfaceWidth, int surfaceHeight, out Dictionary<Line, int> lineValueList1)
  262. {
  263. lineValueList1 = new Dictionary<Line, int>();
  264. Point lastCap_s1 = new Point(0, 0);//###
  265. Point lastCap_s2 = new Point(0, 0);
  266. Point lastCap_s3 = new Point(0, 0);
  267. Point lastCap_Point = new Point(-1, -1);
  268. RectangleF rectangleFCap = new RectangleF();
  269. for (int iguidePoint = isRound ? 1 : 0; iguidePoint < linePointList.Count; iguidePoint++)
  270. {
  271. PointF point = linePointList[iguidePoint];
  272. if (point.X > 0 && point.X < surfaceWidth - 1
  273. && point.Y > 0 && point.Y < surfaceHeight - 1)
  274. {
  275. Vec4b vec4B = mat.At<Vec4b>((int)point.Y, (int)point.X);
  276. if (matLevel == 2 && vec4B.Item3 != 0 || matLevel == 1 && vec4B.Item3 != 0 || matLevel == 0 && false/*vec4B.Item0 == 0*/)
  277. {
  278. rectangleFCap = new RectangleF();
  279. int count = GetBoundryCountD(mat, matLevel, new Point((int)point.X, (int)point.Y));
  280. if (count > 2)
  281. {
  282. if (pointStyle3 == 0)
  283. {
  284. rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter3 / 2 - this.pointWidth3 / 2, (int)point.Y - this.pointDiameter3 / 2 - this.pointWidth3 / 2);
  285. rectangleFCap.Width = this.pointDiameter3 + this.pointWidth3 * 2;
  286. rectangleFCap.Height = this.pointDiameter3 + this.pointWidth3 * 2;
  287. }
  288. else
  289. {
  290. rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter3 / 2, (int)point.Y - this.pointDiameter3 / 2);
  291. rectangleFCap.Width = this.pointDiameter3;
  292. rectangleFCap.Height = this.pointDiameter3;
  293. }
  294. // 垂直辅助线/ 水平辅助线
  295. if (BasicCalculationHelper.GetDistance(lastCap_s3, point, 0) > this.pointError3)
  296. {
  297. if (vGuideStylesOrHGuideStyles)
  298. {
  299. this.rectangleFCaps3_1.Add(rectangleFCap);
  300. this.rectangleCaps3_1.Add(new Point((int)point.X, (int)point.Y));
  301. }
  302. else
  303. {
  304. this.rectangleFCaps3_2.Add(rectangleFCap);
  305. this.rectangleCaps3_2.Add(new Point((int)point.X, (int)point.Y));
  306. }
  307. lastCap_s3 = new Point((int)point.X, (int)point.Y);
  308. if (lastCap_Point.X >= 0)
  309. lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
  310. (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
  311. lastCap_Point = new Point((int)point.X, (int)point.Y);
  312. }
  313. }
  314. else
  315. {
  316. if (pointStyle2 == 0)
  317. {
  318. rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter2 / 2 - this.pointWidth2 / 2, (int)point.Y - this.pointDiameter2 / 2 - this.pointWidth2 / 2);
  319. rectangleFCap.Width = this.pointDiameter2 + this.pointWidth2 * 2;
  320. rectangleFCap.Height = this.pointDiameter2 + this.pointWidth2 * 2;
  321. }
  322. else
  323. {
  324. rectangleFCap.Location = new PointF((int)point.X - this.pointDiameter2 / 2, (int)point.Y - this.pointDiameter2 / 2);
  325. rectangleFCap.Width = this.pointDiameter2;
  326. rectangleFCap.Height = this.pointDiameter2;
  327. }
  328. if (BasicCalculationHelper.GetDistance(lastCap_s2, point, 0) > this.pointError2)
  329. {
  330. this.rectangleFCaps2.Add(rectangleFCap);
  331. this.rectangleCaps2.Add(new Point((int)point.X, (int)point.Y));
  332. lastCap_s2 = new Point((int)point.X, (int)point.Y);
  333. if (lastCap_Point.X >= 0)
  334. lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
  335. (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
  336. lastCap_Point = new Point((int)point.X, (int)point.Y);
  337. }
  338. }
  339. }
  340. }
  341. }
  342. if (isRound && lineValueList1.Count > 0)
  343. {
  344. PointF point = new PointF(0, 0);
  345. foreach (var itemkey in lineValueList1.Keys)
  346. {
  347. point = new PointF(itemkey.startPoint.X, itemkey.startPoint.Y);
  348. break;
  349. }
  350. lineValueList1.Add(new Line(new Point(lastCap_Point.X, lastCap_Point.Y), new Point((int)point.X, (int)point.Y)),
  351. (int)BasicCalculationHelper.GetDistance(lastCap_Point, point, 0));
  352. }
  353. }
  354. //################################################
  355. private int GetBoundryCountD(Mat mat, int matLevel, Point point)
  356. {
  357. if (matLevel == 1)
  358. {
  359. return this.GetBoundryCountDOfBinary(point, mat);
  360. }
  361. int count = 0;
  362. bool firstValueOnBoundry = false;
  363. bool lastValueOnBoundry = false;
  364. Vec4b vec4B = mat.At<Vec4b>(point.Y - 1, point.X - 1);
  365. if (vec4B.Item0 == 0)
  366. {
  367. count++;
  368. firstValueOnBoundry = true;
  369. lastValueOnBoundry = true;
  370. }
  371. vec4B = mat.At<Vec4b>(point.Y - 1, point.X);
  372. if (vec4B.Item0 == 0)
  373. {
  374. if (!lastValueOnBoundry)
  375. count++;
  376. lastValueOnBoundry = true;
  377. }
  378. else lastValueOnBoundry = false;
  379. vec4B = mat.At<Vec4b>(point.Y - 1, point.X + 1);
  380. if (vec4B.Item0 == 0)
  381. {
  382. if (!lastValueOnBoundry)
  383. count++;
  384. lastValueOnBoundry = true;
  385. }
  386. else lastValueOnBoundry = false;
  387. vec4B = mat.At<Vec4b>(point.Y, point.X + 1);
  388. if (vec4B.Item0 == 0)
  389. {
  390. if (!lastValueOnBoundry)
  391. count++;
  392. lastValueOnBoundry = true;
  393. }
  394. else lastValueOnBoundry = false;
  395. vec4B = mat.At<Vec4b>(point.Y + 1, point.X + 1);
  396. if (vec4B.Item0 == 0)
  397. {
  398. if (!lastValueOnBoundry)
  399. count++;
  400. lastValueOnBoundry = true;
  401. }
  402. else lastValueOnBoundry = false;
  403. vec4B = mat.At<Vec4b>(point.Y + 1, point.X);
  404. if (vec4B.Item0 == 0)
  405. {
  406. if (!lastValueOnBoundry)
  407. count++;
  408. lastValueOnBoundry = true;
  409. }
  410. else lastValueOnBoundry = false;
  411. vec4B = mat.At<Vec4b>(point.Y + 1, point.X - 1);
  412. if (vec4B.Item0 == 0)
  413. {
  414. if (!lastValueOnBoundry)
  415. count++;
  416. lastValueOnBoundry = true;
  417. }
  418. else lastValueOnBoundry = false;
  419. vec4B = mat.At<Vec4b>(point.Y, point.X - 1);
  420. if (vec4B.Item0 == 0)
  421. {
  422. if (!lastValueOnBoundry && !firstValueOnBoundry)
  423. count++;
  424. }
  425. return count;
  426. }
  427. private int GetBoundryCountDOfBinary(Point point, Mat mat)
  428. {
  429. int count = 0;
  430. bool firstValueOnBoundry = false;
  431. bool lastValueOnBoundry = false;
  432. Vec4b vec4B = mat.At<Vec4b>(point.Y - 1, point.X - 1);
  433. if (vec4B.Item3 != 0)
  434. {
  435. count++;
  436. firstValueOnBoundry = true;
  437. lastValueOnBoundry = true;
  438. }
  439. vec4B = mat.At<Vec4b>(point.Y - 1, point.X);
  440. if (vec4B.Item3 != 0)
  441. {
  442. if (!lastValueOnBoundry)
  443. count++;
  444. lastValueOnBoundry = true;
  445. }
  446. else lastValueOnBoundry = false;
  447. vec4B = mat.At<Vec4b>(point.Y - 1, point.X + 1);
  448. if (vec4B.Item3 != 0)
  449. {
  450. if (!lastValueOnBoundry)
  451. count++;
  452. lastValueOnBoundry = true;
  453. }
  454. else lastValueOnBoundry = false;
  455. vec4B = mat.At<Vec4b>(point.Y, point.X + 1);
  456. if (vec4B.Item3 != 0)
  457. {
  458. if (!lastValueOnBoundry)
  459. count++;
  460. lastValueOnBoundry = true;
  461. }
  462. else lastValueOnBoundry = false;
  463. vec4B = mat.At<Vec4b>(point.Y + 1, point.X + 1);
  464. if (vec4B.Item3 != 0)
  465. {
  466. if (!lastValueOnBoundry)
  467. count++;
  468. lastValueOnBoundry = true;
  469. }
  470. else lastValueOnBoundry = false;
  471. vec4B = mat.At<Vec4b>(point.Y + 1, point.X);
  472. if (vec4B.Item3 != 0)
  473. {
  474. if (!lastValueOnBoundry)
  475. count++;
  476. lastValueOnBoundry = true;
  477. }
  478. else lastValueOnBoundry = false;
  479. vec4B = mat.At<Vec4b>(point.Y + 1, point.X - 1);
  480. if (vec4B.Item3 != 0)
  481. {
  482. if (!lastValueOnBoundry)
  483. count++;
  484. lastValueOnBoundry = true;
  485. }
  486. else lastValueOnBoundry = false;
  487. vec4B = mat.At<Vec4b>(point.Y, point.X - 1);
  488. if (vec4B.Item3 != 0)
  489. {
  490. if (!lastValueOnBoundry && !firstValueOnBoundry)
  491. count++;
  492. }
  493. return count;
  494. }
  495. /// <summary>
  496. /// 更新截点样式
  497. /// </summary>
  498. public void UpdateCupOffPointStyle()
  499. {
  500. GrainCutOffPointStyleModel grainCutOffPointStyleModel = XmlSerializeHelper.DESerializer<GrainCutOffPointStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainCutOffPointStyleModel.xml", FileMode.Open));
  501. // 0.5截点
  502. this.pointColor1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointColor;
  503. this.pointWidth1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointWidth;
  504. this.pointStyle1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointStyle;
  505. this.pointDiameter1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointDiameter;
  506. this.pointError1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointError;
  507. this.pointshape1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointshape;
  508. // 1截点
  509. this.pointColor2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointColor;
  510. this.pointWidth2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointWidth;
  511. this.pointStyle2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointStyle;
  512. this.pointDiameter2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointDiameter;
  513. this.pointError2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointError;
  514. this.pointshape2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointshape;
  515. // 1.5/2截点
  516. this.pointColor3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointColor;
  517. this.pointWidth3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointWidth;
  518. this.pointStyle3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointStyle;
  519. this.pointDiameter3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointDiameter;
  520. this.pointError3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointError;
  521. this.pointshape3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointshape;
  522. }
  523. /// <summary>
  524. /// 实现手动添加在原图情况下的截点位置跟随辅助线的移动而移动
  525. /// </summary>
  526. /// <param name="offsetX"></param>
  527. /// <param name="offsetY"></param>
  528. public void MoveOriginCutOffPoints(int offsetX, int offsetY, float offsetXF, float offsetYF)
  529. {
  530. //##21247
  531. foreach (var item in this.lineValueList)
  532. {
  533. item.Key.startPoint.X = item.Key.startPoint.X + offsetX;
  534. item.Key.startPoint.Y = item.Key.startPoint.Y + offsetY;
  535. item.Key.endPoint.X = item.Key.endPoint.X + offsetX;
  536. item.Key.endPoint.Y = item.Key.endPoint.Y + offsetY;
  537. }
  538. for (int i = 0; i < this.rectangleFCaps1.Count; i++)
  539. {
  540. var item = this.rectangleFCaps1[i];
  541. this.rectangleFCaps1[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
  542. }
  543. for (int i = 0; i < this.rectangleFCaps2.Count; i++)
  544. {
  545. var item = this.rectangleFCaps2[i];
  546. this.rectangleFCaps2[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
  547. //item.Location = new PointF(item.Location.X + offsetXF, item.Location.Y + offsetYF);
  548. }
  549. for (int i = 0; i < this.rectangleFCaps3_1.Count; i++)
  550. {
  551. var item = this.rectangleFCaps3_1[i];
  552. this.rectangleFCaps3_1[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
  553. //item.Location = new PointF(item.Location.X + offsetXF, item.Location.Y + offsetYF);
  554. }
  555. for (int i = 0; i < this.rectangleFCaps3_2.Count; i++)
  556. {
  557. var item = this.rectangleFCaps3_2[i];
  558. this.rectangleFCaps3_2[i] = new RectangleF(item.Location.X + offsetXF, item.Location.Y + offsetYF, item.Width, item.Height);
  559. }
  560. for (int i = 0; i < this.rectangleCaps1.Count; i++)
  561. {
  562. var item = this.rectangleCaps1[i];
  563. item.X = item.X + offsetX;
  564. item.Y = item.Y + offsetY;
  565. }
  566. for (int i = 0; i < this.rectangleCaps2.Count; i++)
  567. {
  568. var item = this.rectangleCaps2[i];
  569. item.X = item.X + offsetX;
  570. item.Y = item.Y + offsetY;
  571. }
  572. for (int i = 0; i < this.rectangleCaps3_1.Count; i++)
  573. {
  574. var item = this.rectangleCaps3_1[i];
  575. item.X = item.X + offsetX;
  576. item.Y = item.Y + offsetY;
  577. }
  578. for (int i = 0; i < this.rectangleCaps3_2.Count; i++)
  579. {
  580. var item = this.rectangleCaps3_2[i];
  581. item.X = item.X + offsetX;
  582. item.Y = item.Y + offsetY;
  583. }
  584. this.ReloadLineValueList();
  585. }
  586. /// <summary>
  587. /// 绘制截点
  588. /// </summary>
  589. public void DrawGuidePoints(Graphics graphics)
  590. {
  591. // 以下为绘制样式
  592. Pen pointPen1 = new Pen(Color.FromArgb(this.pointColor1), this.pointWidth1);
  593. Pen pointPen2 = new Pen(Color.FromArgb(this.pointColor2), this.pointWidth2);
  594. Pen pointPen3 = new Pen(Color.FromArgb(this.pointColor3), this.pointWidth3);
  595. SolidBrush brush1 = new SolidBrush(Color.FromArgb(this.pointColor1));
  596. SolidBrush brush2 = new SolidBrush(Color.FromArgb(this.pointColor2));
  597. SolidBrush brush3 = new SolidBrush(Color.FromArgb(this.pointColor3));
  598. if (this.rectangleFCaps1 != null && this.rectangleFCaps1.Count > 0)
  599. {
  600. foreach (var rectangleF in this.rectangleFCaps1)
  601. {
  602. if (pointStyle1 == 0)
  603. {
  604. if (this.pointshape1 == 0)
  605. graphics.DrawEllipse(pointPen1, rectangleF.X + (float)this.pointWidth1 / 2, rectangleF.Y + (float)this.pointWidth1 / 2, rectangleF.Width - (float)this.pointWidth1 * 2, rectangleF.Height - this.pointWidth1 * 2);
  606. else
  607. graphics.DrawRectangle(pointPen1, rectangleF.X + (float)this.pointWidth1 / 2, rectangleF.Y + (float)this.pointWidth1 / 2, rectangleF.Width - this.pointWidth1 * 2, rectangleF.Height - this.pointWidth1 * 2);
  608. }
  609. else
  610. {
  611. if (this.pointshape1 == 0)
  612. graphics.FillEllipse(brush1, rectangleF);
  613. else
  614. graphics.FillRectangle(brush1, rectangleF);
  615. }
  616. }
  617. }
  618. if (this.rectangleFCaps2 != null && this.rectangleFCaps2.Count > 0)
  619. {
  620. foreach (var rectangleF in this.rectangleFCaps2)
  621. {
  622. if (pointStyle2 == 0)
  623. {
  624. if (this.pointshape2 == 0)
  625. graphics.DrawEllipse(pointPen2, rectangleF.X + this.pointWidth2 / 2, rectangleF.Y + this.pointWidth2 / 2, rectangleF.Width - this.pointWidth2 * 2, rectangleF.Height - this.pointWidth2 * 2);
  626. else
  627. graphics.DrawRectangle(pointPen2, rectangleF.X + this.pointWidth2 / 2, rectangleF.Y + this.pointWidth2 / 2, rectangleF.Width - this.pointWidth2 * 2, rectangleF.Height - this.pointWidth2 * 2);
  628. }
  629. else
  630. {
  631. if (this.pointshape2 == 0)
  632. graphics.FillEllipse(brush2, rectangleF);
  633. else
  634. graphics.FillRectangle(brush2, rectangleF);
  635. }
  636. }
  637. }
  638. if (this.rectangleFCaps3_1 != null && this.rectangleFCaps3_1.Count > 0)
  639. {
  640. foreach (var rectangleF in this.rectangleFCaps3_1)
  641. {
  642. if (pointStyle3 == 0)
  643. {
  644. if (this.pointshape3 == 0)
  645. graphics.DrawEllipse(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
  646. else
  647. graphics.DrawRectangle(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
  648. }
  649. else
  650. {
  651. if (this.pointshape3 == 0)
  652. graphics.FillEllipse(brush3, rectangleF);
  653. else
  654. graphics.FillRectangle(brush3, rectangleF);
  655. }
  656. }
  657. }
  658. if (this.rectangleFCaps3_2 != null && this.rectangleFCaps3_2.Count > 0)
  659. {
  660. foreach (var rectangleF in this.rectangleFCaps3_2)
  661. {
  662. if (pointStyle3 == 0)
  663. {
  664. if (this.pointshape3 == 0)
  665. graphics.DrawEllipse(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
  666. else
  667. graphics.DrawRectangle(pointPen3, rectangleF.X + this.pointWidth3 / 2, rectangleF.Y + this.pointWidth3 / 2, rectangleF.Width - this.pointWidth3 * 2, rectangleF.Height - this.pointWidth3 * 2);
  668. }
  669. else
  670. {
  671. if (this.pointshape3 == 0)
  672. graphics.FillEllipse(brush3, rectangleF);
  673. else
  674. graphics.FillRectangle(brush3, rectangleF);
  675. }
  676. }
  677. }
  678. }
  679. /// <summary>
  680. /// 获取截点数量
  681. /// </summary>
  682. /// <returns></returns>
  683. public double getCountPoints()
  684. {
  685. return this.rectangleFCaps1.Count * 0.5 + this.rectangleFCaps2.Count * 1.0 + this.rectangleFCaps3_1.Count * 1.5 + this.rectangleFCaps3_2.Count * 2.0;
  686. }
  687. /// <summary>
  688. /// 手动添加截点
  689. /// </summary>
  690. /// <param name="pointFAdd">要添加的截点坐标</param>
  691. /// <param name="pointKb">节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2)</param>
  692. public void manualAddPoint(PointF pointFAdd, int pointKb)
  693. {
  694. if (pointKb == 1)
  695. {
  696. if (pointStyle1 == 0)
  697. {
  698. this.rectangleFCaps1.Add(new RectangleF(pointFAdd.X - this.pointDiameter1 / 2 - this.pointWidth1 / 2,
  699. pointFAdd.Y - this.pointDiameter1 / 2 - this.pointWidth1 / 2, this.pointDiameter1 + this.pointWidth1 * 2,
  700. this.pointDiameter1 + this.pointWidth1 * 2));
  701. this.rectangleCaps1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  702. }
  703. else
  704. {
  705. this.rectangleFCaps1.Add(new RectangleF(pointFAdd.X - this.pointDiameter1 / 2, pointFAdd.Y - this.pointDiameter1 / 2,
  706. this.pointDiameter1, this.pointDiameter1));
  707. this.rectangleCaps1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  708. }
  709. }
  710. else if (pointKb == 2)
  711. {
  712. if (pointStyle2 == 0)
  713. {
  714. this.rectangleFCaps2.Add(new RectangleF(pointFAdd.X - this.pointDiameter2 / 2 - this.pointWidth2 / 2,
  715. pointFAdd.Y - this.pointDiameter2 / 2 - this.pointWidth2 / 2, this.pointDiameter2 + this.pointWidth2 * 2,
  716. this.pointDiameter2 + this.pointWidth2 * 2));
  717. this.rectangleCaps2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  718. }
  719. else
  720. {
  721. this.rectangleFCaps2.Add(new RectangleF(pointFAdd.X - this.pointDiameter2 / 2, pointFAdd.Y - this.pointDiameter2 / 2,
  722. this.pointDiameter2, this.pointDiameter2));
  723. this.rectangleCaps2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  724. }
  725. }
  726. else if (pointKb == 3)
  727. {
  728. if (pointStyle3 == 0)
  729. {
  730. this.rectangleFCaps3_1.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2 - this.pointWidth3 / 2,
  731. pointFAdd.Y - this.pointDiameter3 / 2 - this.pointWidth3 / 2, this.pointDiameter3 + this.pointWidth3 * 2,
  732. this.pointDiameter3 + this.pointWidth3 * 2));
  733. this.rectangleCaps3_1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  734. }
  735. else
  736. {
  737. this.rectangleFCaps3_1.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2, pointFAdd.Y - this.pointDiameter3 / 2,
  738. this.pointDiameter3, this.pointDiameter3));
  739. this.rectangleCaps3_1.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  740. }
  741. }
  742. else if (pointKb == 4)
  743. {
  744. if (pointStyle3 == 0)
  745. {
  746. this.rectangleFCaps3_2.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2 - this.pointWidth3 / 2,
  747. pointFAdd.Y - this.pointDiameter3 / 2 - this.pointWidth3 / 2, this.pointDiameter3 + this.pointWidth3 * 2,
  748. this.pointDiameter3 + this.pointWidth3 * 2));
  749. this.rectangleCaps3_2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  750. }
  751. else
  752. {
  753. this.rectangleFCaps3_2.Add(new RectangleF(pointFAdd.X - this.pointDiameter3 / 2, pointFAdd.Y - this.pointDiameter3 / 2,
  754. this.pointDiameter3, this.pointDiameter3));
  755. this.rectangleCaps3_2.Add(new Point((int)pointFAdd.X, (int)pointFAdd.Y));
  756. }
  757. }
  758. }
  759. /// <summary>
  760. /// 手动删除截点
  761. /// </summary>
  762. /// <param name="point1"></param>
  763. /// <param name="toAddPoint"></param>
  764. public void manualRemovePoint(PointF point1, out bool toAddPoint)
  765. {
  766. toAddPoint = true;
  767. for (int removeI = this.rectangleFCaps1.Count - 1; removeI >= 0; removeI--)
  768. {
  769. if (this.rectangleFCaps1[removeI].Contains(point1))
  770. {
  771. this.rectangleFCaps1.RemoveAt(removeI);
  772. this.rectangleCaps1.RemoveAt(removeI);
  773. toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
  774. break;
  775. }
  776. }
  777. for (int removeI = this.rectangleFCaps2.Count - 1; removeI >= 0; removeI--)
  778. {
  779. if (this.rectangleFCaps2[removeI].Contains(point1))
  780. {
  781. this.rectangleFCaps2.RemoveAt(removeI);
  782. this.rectangleCaps2.RemoveAt(removeI);
  783. toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
  784. break;
  785. }
  786. }
  787. for (int removeI = this.rectangleFCaps3_1.Count - 1; removeI >= 0; removeI--)
  788. {
  789. if (this.rectangleFCaps3_1[removeI].Contains(point1))
  790. {
  791. this.rectangleFCaps3_1.RemoveAt(removeI);
  792. this.rectangleCaps3_1.RemoveAt(removeI);
  793. toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
  794. break;
  795. }
  796. }
  797. for (int removeI = this.rectangleFCaps3_2.Count - 1; removeI >= 0; removeI--)
  798. {
  799. if (this.rectangleFCaps3_2[removeI].Contains(point1))
  800. {
  801. this.rectangleFCaps3_2.RemoveAt(removeI);
  802. this.rectangleCaps3_2.RemoveAt(removeI);
  803. toAddPoint = false;//左键点击在截点上则不进行删除截点操作,不再添加
  804. break;
  805. }
  806. }
  807. }
  808. }
  809. }