GrainBinaryBoundaryEditingDialog.cs 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760
  1. using OpenCvSharp;
  2. using PaintDotNet.Adjust;
  3. using PaintDotNet.Base.Functionodel;
  4. using PaintDotNet.CustomControl;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Windows.Forms;
  10. using Point = System.Drawing.Point;
  11. using PaintDotNet.Annotation;
  12. using System.Linq;
  13. using Metis.ParameterSet;
  14. using PaintDotNet.Base.CommTool;
  15. namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
  16. {
  17. internal class GrainBinaryBoundaryEditingDialog : Form
  18. {
  19. /// <summary>
  20. /// 公共按钮
  21. /// </summary>
  22. private CommonControlButtons commonControlButtons;
  23. /// <summary>
  24. /// 主控件
  25. /// </summary>
  26. private AppWorkspace appWorkspace;
  27. private DocumentWorkspaceWindow documentWorkspace;
  28. /// <summary>
  29. /// 选中图片的mat
  30. /// </summary>
  31. private Mat imageMat;
  32. ///// <summary>
  33. ///// 用于get处理后的图像
  34. ///// </summary>
  35. //private Mat phaseMat;
  36. /// <summary>
  37. /// 辅助线集成
  38. /// </summary>
  39. private GrainSizeGuideClass guideClass;
  40. public object SelectedItem;
  41. Color phaseColor;
  42. Mat phaseMatCopy = new Mat();
  43. /// <summary>
  44. /// 当前处理的程序
  45. /// </summary>
  46. private Data.Action.Action911 action = new Data.Action.Action911();
  47. /// <summary>
  48. /// 起始点
  49. /// </summary>
  50. private Point startPoint = new Point(-1, -1);
  51. /// <summary>
  52. /// 是否绘制了起始点
  53. /// </summary>
  54. private bool drawedStartPoint = false;
  55. /// <summary>
  56. /// 结束点
  57. /// </summary>
  58. private Point endPoint = new Point(-1, -1);
  59. ///// <summary>
  60. ///// 折线点的集合
  61. ///// </summary>
  62. //public List<Point> pointArray = new List<Point>();
  63. /// <summary>
  64. /// 操作类型
  65. /// 0,没有操作 1,折线添加 2,直线添加
  66. /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
  67. /// </summary>
  68. private int pointKtype = 0;
  69. /// <summary>
  70. /// 折线点的集合
  71. /// </summary>
  72. public List<PointF> pointFloatArray = new List<PointF>();
  73. /// <summary>
  74. /// 外接矩形,或者是计算的矩形
  75. /// </summary>
  76. protected RectangleF rectangle = new RectangleF();
  77. #region 实现撤销、恢复、重置的功能
  78. /// <summary>
  79. /// 当前操作在OperationsList的位置,用于判断是否可以撤销、恢复、重置
  80. /// </summary>
  81. private int OperationIndex = -1;
  82. /// <summary>
  83. /// 将 操作类型的集合放入一个List,通过OperationIndex读取当前操作位置
  84. /// </summary>
  85. private List<int> OperationKtypeList = new List<int>();
  86. /// <summary>
  87. /// 将 折线(/直线)点的集合(/外接矩形的xywh)放入一个List,通过OperationIndex读取当前操作位置
  88. /// </summary>
  89. private List<PointF[]> OperationsList = new List<PointF[]>();
  90. /// <summary>
  91. /// 将 线宽的数据放入一个List,通过OperationIndex读取当前操作位置
  92. /// </summary>
  93. private List<int> OperationsLineWidthList = new List<int>();
  94. /// <summary>
  95. /// 保存晶界重现运算的结果
  96. /// </summary>
  97. private Mat PhaseModel0MatCopy;
  98. #endregion
  99. /// <summary>
  100. /// 一些方法用到了微米换算
  101. /// </summary>
  102. private double ruleValue = 1.0;
  103. /// <summary>
  104. /// 是否显示视场
  105. /// </summary>
  106. Boolean ShowDrawClassView = true;
  107. private GroupBox groupBox1;
  108. private GroupBox groupBox2;
  109. private Button button2;
  110. private Button button1;
  111. private Button button3;
  112. private Button button4;
  113. private Button button8;
  114. private Button button7;
  115. private Button button6;
  116. private Button button5;
  117. private TriangleTrackBar trackBar2;
  118. private TextBox textBox1;
  119. private Label label1;
  120. private TrackBar trackBar1;
  121. private GroupBox groupBox4;
  122. private Panel panel2;
  123. private RadioButton radioButton6;
  124. private RadioButton radioButton5;
  125. private TriangleTrackBar triangleTrackBar1;
  126. private Label label4;
  127. private Label label3;
  128. private Panel panel1;
  129. private RadioButton radioButton4;
  130. private RadioButton radioButton3;
  131. private RadioButton radioButton2;
  132. private RadioButton radioButton1;
  133. private Label label2;
  134. private NumericUpDown numericUpDown2;
  135. private NumericUpDown numericUpDown1;
  136. private Button button9;
  137. private Button undoButton;
  138. private Button redoButton;
  139. private Button resetButton;
  140. private GroupBox groupBox7;
  141. public GrainSizeGuideClass GuideClass
  142. {
  143. set
  144. {
  145. this.guideClass = value;
  146. }
  147. }
  148. public GrainBinaryBoundaryEditingDialog(AppWorkspace appWorkspace, int focusedItemIndex, Color phaseColor, Mat phaseMat, Boolean ShowDrawClassView = true, double ruleValue = 1.0)
  149. {
  150. this.ShowDrawClassView = ShowDrawClassView;
  151. this.appWorkspace = appWorkspace;
  152. InitializeComponent();
  153. InitializeLanguageText();
  154. //
  155. //初始化图像控件
  156. //
  157. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  158. this.documentWorkspace.Dock = DockStyle.Fill;
  159. this.documentWorkspace.HookMouseEvents();
  160. this.documentWorkspace.AuxiliaryLineEnabled = false;
  161. this.documentWorkspace.Visible = false;
  162. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  163. this.documentWorkspace.panel.Paint += Panel_Paint;
  164. this.documentWorkspace.panel.MouseMove += onMouseMove;
  165. this.documentWorkspace.panel.MouseUp += onMouseUp;
  166. this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);
  167. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;//禁止视场移动
  168. this.groupBox7.Controls.Add(documentWorkspace);
  169. //
  170. //初始化操作按钮
  171. //
  172. this.commonControlButtons = new CommonControlButtons();
  173. this.commonControlButtons.Dock = DockStyle.Top;
  174. this.commonControlButtons.Height = 30;
  175. this.commonControlButtons.HideZoomToWindowAndActualSize();
  176. this.groupBox7.Controls.Add(commonControlButtons);
  177. //获取
  178. this.ruleValue = ruleValue;//this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetRuler(MeasurementUnit.Micron)
  179. //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
  180. //double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  181. this.phaseColor = phaseColor;
  182. {
  183. //
  184. //初始化相
  185. //
  186. PhaseModel model = new PhaseModel();
  187. model.choise = true;
  188. model.mat = null;
  189. model.color = phaseColor.ToArgb();// Color.Green/*panel2.BackColor*/.ToArgb();
  190. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  191. model.name = PdnResources.GetString("Menu.Binarization.text");
  192. this.documentWorkspace.PhaseModels.Add(model);
  193. }
  194. this.documentWorkspace.PhaseModels[0].mat = phaseMat;
  195. PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
  196. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  197. this.documentWorkspace.Refresh();
  198. this.imageMat = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreatedAliasedMat();
  199. Document document = Document.FromImageMat(imageMat.Clone());
  200. this.documentWorkspace.Document = document;
  201. this.documentWorkspace.Visible = true;
  202. if (ShowDrawClassView)
  203. {
  204. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  205. }
  206. else
  207. {
  208. GraphicsList itemGraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  209. GraphicsList graphicsList = new GraphicsList();
  210. for (int j = 0; j < itemGraphicsList.Count; j++)
  211. {
  212. if (itemGraphicsList[j].objectType != Annotation.Enum.DrawClass.View)
  213. graphicsList.Add(itemGraphicsList[j]);
  214. }
  215. this.documentWorkspace.GraphicsList = graphicsList;
  216. }
  217. InitCommonButtonEvent();
  218. }
  219. /// <summary>
  220. /// 添加操作数据到List集合中,并刷新操作按钮的状态
  221. /// </summary>
  222. /// <param name="addKtype"></param>
  223. /// <param name="pointFs"></param>
  224. private void AddOperationToList(int addKtype, PointF[] pointFs)
  225. {
  226. this.RefreshOperationsToIndex();
  227. this.OperationKtypeList.Add(addKtype);
  228. this.OperationsList.Add(pointFs);
  229. this.OperationsLineWidthList.Add(this.trackBar1.Value);
  230. this.OperationIndex = this.OperationsList.Count - 1;
  231. this.RefreshOperationsButtons();
  232. }
  233. /// <summary>
  234. /// 根据OperationIndex去掉已经撤销的操作记录
  235. /// </summary>
  236. private void RefreshOperationsToIndex()
  237. {
  238. if (this.OperationIndex < this.OperationsList.Count - 1)
  239. {
  240. int operationSum = this.OperationsList.Count;
  241. for (int i = operationSum - 1; i > this.OperationIndex; i--)
  242. {
  243. this.OperationKtypeList.RemoveAt(i);
  244. this.OperationsList.RemoveAt(i);
  245. this.OperationsLineWidthList.RemoveAt(i);
  246. }
  247. }
  248. }
  249. /// <summary>
  250. /// 刷新操作按钮的状态
  251. /// </summary>
  252. private void RefreshOperationsButtons()
  253. {
  254. if (/*this.OperationIndex >= 0 && */this.OperationKtypeList.Count == this.OperationsList.Count && this.OperationKtypeList.Count > 0)
  255. this.resetButton.Enabled = true;
  256. else
  257. this.resetButton.Enabled = false;
  258. if (this.OperationIndex >= 0)
  259. this.undoButton.Enabled = true;
  260. else
  261. this.undoButton.Enabled = false;
  262. if (this.OperationIndex < this.OperationKtypeList.Count - 1)
  263. this.redoButton.Enabled = true;
  264. else
  265. this.redoButton.Enabled = false;
  266. }
  267. #region 矩形拖动
  268. /// <summary>
  269. /// 鼠标按下
  270. /// </summary>
  271. /// <param name="drawArea"></param>
  272. /// <param name="e"></param>
  273. private void OnMouseDown(object sender, MouseEventArgs e)
  274. {
  275. // 换算后的点
  276. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  277. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  278. && point1.X >= 0
  279. && point1.Y >= 0
  280. && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
  281. {
  282. if (e.Button == MouseButtons.Left/* && e.Clicks == 1*/&& this.pointKtype >= 1)
  283. {
  284. if (!drawedStartPoint)
  285. {
  286. drawedStartPoint = true;
  287. startPoint = new Point((int)point1.X, (int)point1.Y);
  288. return;
  289. }
  290. // 折线添加
  291. if (this.pointKtype == 1)
  292. {
  293. }
  294. // 直线添加
  295. else if (this.pointKtype == 2)
  296. {
  297. }
  298. // 多边形删除
  299. else if (this.pointKtype == 11)
  300. {
  301. }
  302. }
  303. }
  304. else if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
  305. {
  306. if (!drawedStartPoint)
  307. {
  308. drawedStartPoint = true;
  309. startPoint = new Point((int)point1.X, (int)point1.Y);
  310. return;
  311. }
  312. }
  313. else
  314. return;
  315. // 右键完成操作
  316. if (e.Button == MouseButtons.Right)
  317. {
  318. }
  319. }
  320. /// <summary>
  321. /// 移动
  322. /// </summary>
  323. /// <param name="sender"></param>
  324. /// <param name="e"></param>
  325. private void onMouseMove(object sender, MouseEventArgs e)
  326. {
  327. // 换算后的点
  328. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  329. if (e.Button == MouseButtons.Left)
  330. {
  331. // 椭圆删除/圆形删除
  332. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  333. {
  334. endPoint = new Point((int)point1.X, (int)point1.Y);
  335. if (this.startPoint.X < this.endPoint.X)
  336. {
  337. this.rectangle.X = this.startPoint.X;
  338. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  339. }
  340. else
  341. {
  342. this.rectangle.X = this.endPoint.X;
  343. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  344. }
  345. if (this.startPoint.Y < this.endPoint.Y)
  346. {
  347. this.rectangle.Y = this.startPoint.Y;
  348. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  349. }
  350. else
  351. {
  352. this.rectangle.Y = this.endPoint.Y;
  353. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  354. }
  355. this.documentWorkspace.Refresh();
  356. }
  357. // 矩形删除
  358. if (this.pointKtype == 13 && drawedStartPoint)
  359. {
  360. endPoint = new Point((int)point1.X, (int)point1.Y);
  361. if (this.startPoint.X < this.endPoint.X)
  362. {
  363. this.rectangle.X = this.startPoint.X;
  364. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  365. }
  366. else
  367. {
  368. this.rectangle.X = this.endPoint.X;
  369. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  370. }
  371. if (this.startPoint.Y < this.endPoint.Y)
  372. {
  373. this.rectangle.Y = this.startPoint.Y;
  374. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  375. }
  376. else
  377. {
  378. this.rectangle.Y = this.endPoint.Y;
  379. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  380. }
  381. this.documentWorkspace.Refresh();
  382. }
  383. // 直线添加
  384. if (this.pointKtype == 2 && drawedStartPoint)
  385. {
  386. endPoint = new Point((int)point1.X, (int)point1.Y);
  387. this.documentWorkspace.Refresh();
  388. }
  389. }
  390. }
  391. /// <summary>
  392. /// 鼠标抬起
  393. /// </summary>
  394. /// <param name="sender"></param>
  395. /// <param name="e"></param>
  396. private void onMouseUp(object sender, MouseEventArgs e)
  397. {
  398. // 换算后的点
  399. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  400. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  401. && point1.X >= 0
  402. && point1.Y >= 0
  403. && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { }
  404. else
  405. {
  406. if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
  407. {
  408. //if (point1.X >= this.documentWorkspace.CompositionSurface.Width)
  409. // point1.X = this.documentWorkspace.CompositionSurface.Width - 1;
  410. //if (point1.X < 0)
  411. // point1.X = 0;
  412. //if (point1.Y >= this.documentWorkspace.CompositionSurface.Height)
  413. // point1.Y = this.documentWorkspace.CompositionSurface.Height - 1;
  414. //if (point1.Y < 0)
  415. // point1.Y = 0;
  416. }
  417. else
  418. return;
  419. }
  420. if (e.Button == MouseButtons.Right)
  421. {
  422. // 折线删除
  423. if (this.pointKtype == 11 && pointFloatArray.Count > 1)
  424. {
  425. pointFloatArray.Add(new PointF(/*(int)*/point1.X, /*(int)*/point1.Y));
  426. endPoint = new Point((int)point1.X, (int)point1.Y);
  427. //List<PointF> pointFArray = new List<PointF>();
  428. //foreach (var item in pointArray)
  429. //{
  430. // pointFArray.Add(new PointF(item.X, item.Y));
  431. //}
  432. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFloatArray);
  433. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  434. this.AddOperationToList(this.pointKtype, pointFloatArray.ToArray());
  435. this.rectangle.X = -1;
  436. this.rectangle.Y = -1;
  437. this.rectangle.Width = 0;
  438. this.rectangle.Height = 0;
  439. pointFloatArray.Clear();
  440. startPoint = new Point(-1, -1);
  441. drawedStartPoint = false;
  442. endPoint = new Point(-1, -1);
  443. this.pointKtype = 0;
  444. this.documentWorkspace.Refresh();
  445. }
  446. // 折线添加
  447. if (this.pointKtype == 1 && pointFloatArray.Count > 1)
  448. {
  449. pointFloatArray.Add(new PointF(/*(int)*/point1.X, /*(int)*/point1.Y));
  450. endPoint = new Point((int)point1.X, (int)point1.Y);
  451. //保存处理后的图片
  452. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  453. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  454. Graphics graphics = Graphics.FromImage(newBit);
  455. Draw(graphics, false);
  456. this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = PaintDotNet.Camera.Tools.ToMat(newBit);
  457. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  458. this.AddOperationToList(this.pointKtype, pointFloatArray.ToArray());
  459. pointFloatArray.Clear();
  460. startPoint = new Point(-1, -1);
  461. drawedStartPoint = false;
  462. endPoint = new Point(-1, -1);
  463. this.pointKtype = 0;
  464. this.documentWorkspace.Refresh();
  465. }
  466. }
  467. if (e.Button == MouseButtons.Left)
  468. {
  469. // 圆形删除/椭圆删除
  470. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  471. {
  472. endPoint = new Point((int)point1.X, (int)point1.Y);
  473. if (this.startPoint.X < this.endPoint.X)
  474. {
  475. this.rectangle.X = this.startPoint.X;
  476. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  477. }
  478. else
  479. {
  480. this.rectangle.X = this.endPoint.X;
  481. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  482. }
  483. if (this.startPoint.Y < this.endPoint.Y)
  484. {
  485. this.rectangle.Y = this.startPoint.Y;
  486. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  487. }
  488. else
  489. {
  490. this.rectangle.Y = this.endPoint.Y;
  491. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  492. }
  493. if (this.pointKtype == 14)
  494. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  495. else
  496. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat
  497. , new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));
  498. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  499. List<PointF> pointOperationArray = new List<PointF>();
  500. pointOperationArray.Add(new PointF(this.rectangle.X, this.rectangle.Y));
  501. pointOperationArray.Add(new PointF(this.rectangle.Width, this.rectangle.Height));
  502. this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray());
  503. this.rectangle.X = -1;
  504. this.rectangle.Y = -1;
  505. this.rectangle.Width = 0;
  506. this.rectangle.Height = 0;
  507. startPoint = new Point(-1, -1);
  508. drawedStartPoint = false;
  509. endPoint = new Point(-1, -1);
  510. this.pointKtype = 0;
  511. this.documentWorkspace.Refresh();
  512. }
  513. // 矩形删除
  514. if (this.pointKtype == 13 && drawedStartPoint)
  515. {
  516. endPoint = new Point((int)point1.X, (int)point1.Y);
  517. if (this.startPoint.X < this.endPoint.X)
  518. {
  519. this.rectangle.X = this.startPoint.X;
  520. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  521. }
  522. else
  523. {
  524. this.rectangle.X = this.endPoint.X;
  525. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  526. }
  527. if (this.startPoint.Y < this.endPoint.Y)
  528. {
  529. this.rectangle.Y = this.startPoint.Y;
  530. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  531. }
  532. else
  533. {
  534. this.rectangle.Y = this.endPoint.Y;
  535. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  536. }
  537. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  538. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  539. List<PointF> pointOperationArray = new List<PointF>();
  540. pointOperationArray.Add(new PointF(this.rectangle.X, this.rectangle.Y));
  541. pointOperationArray.Add(new PointF(this.rectangle.Width, this.rectangle.Height));
  542. this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray());
  543. this.rectangle.X = -1;
  544. this.rectangle.Y = -1;
  545. this.rectangle.Width = 0;
  546. this.rectangle.Height = 0;
  547. startPoint = new Point(-1, -1);
  548. drawedStartPoint = false;
  549. endPoint = new Point(-1, -1);
  550. this.pointKtype = 0;
  551. this.documentWorkspace.Refresh();
  552. }
  553. // 折线添加/折线删除
  554. if (this.pointKtype == 1 || this.pointKtype == 11)
  555. {
  556. pointFloatArray.Add(new Point((int)point1.X, (int)point1.Y));
  557. if (!drawedStartPoint)
  558. {
  559. drawedStartPoint = true;
  560. startPoint = new Point((int)point1.X, (int)point1.Y);
  561. }
  562. this.documentWorkspace.Refresh();
  563. }
  564. // 直线添加
  565. if (this.pointKtype == 2 && drawedStartPoint)
  566. {
  567. endPoint = new Point((int)point1.X, (int)point1.Y);
  568. //保存处理后的图片
  569. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  570. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  571. Graphics graphics = Graphics.FromImage(newBit);
  572. Draw(graphics, false);
  573. this.documentWorkspace.PhaseModels[0].mat = PaintDotNet.Camera.Tools.ToMat(newBit);
  574. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  575. List<PointF> pointOperationArray = new List<PointF>();
  576. pointOperationArray.Add(new PointF(startPoint.X, startPoint.Y));
  577. pointOperationArray.Add(new PointF(endPoint.X, endPoint.Y));
  578. this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray());
  579. startPoint = new Point(-1, -1);
  580. drawedStartPoint = false;
  581. endPoint = new Point(-1, -1);
  582. this.pointKtype = 0;
  583. this.documentWorkspace.Refresh();
  584. }
  585. }
  586. }
  587. #endregion
  588. /// <summary>
  589. /// surfaceBox双击事件
  590. /// 目前是参考AxioVision
  591. /// 应该是把每次选的点都取最高和最低的BGR
  592. /// </summary>
  593. /// <param name="sender"></param>
  594. /// <param name="e"></param>
  595. private unsafe void pictureBox1_Click(object sender, EventArgs e)
  596. {
  597. }
  598. /// <summary>
  599. /// 画布绘制
  600. /// </summary>
  601. /// <param name="sender"></param>
  602. /// <param name="e"></param>
  603. private void Panel_Paint(object sender, PaintEventArgs e)
  604. {
  605. if (this.documentWorkspace.CompositionSurface != null)
  606. {
  607. //
  608. // 以下是计算绘制图片的位置和大小并绘制图片
  609. //
  610. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  611. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  612. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  613. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  614. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  615. //
  616. // 以下是绘制网格、标注、测量、视场等开始
  617. //
  618. e.Graphics.TranslateTransform(x, y);
  619. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  620. //if (this.checkBox4_0.Checked)//显示网格
  621. Draw(e.Graphics, true);
  622. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  623. e.Graphics.TranslateTransform(-x, -y);
  624. }
  625. }
  626. /// <summary>
  627. /// 绘制
  628. /// </summary>
  629. private void Draw(Graphics g, bool DrawGuideLines)
  630. {
  631. // 抗锯齿
  632. g.SmoothingMode = SmoothingMode.AntiAlias;
  633. if (DrawGuideLines)
  634. {
  635. if (guideClass != null && guideClass.GrainSizeGuideAreaMethodModel != null)
  636. guideClass.DrawAreaGuide(g, SelectedItem, guideClass.guideModel);
  637. else if (guideClass != null && guideClass.GrainSizeGuideStyleModel != null)
  638. guideClass.DrawGuideLines(g, SelectedItem, guideClass.guideModel);
  639. }
  640. //圆形删除/椭圆删除
  641. if ((this.pointKtype == 14 || this.pointKtype == 12) && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  642. {
  643. Pen pen = new Pen(this.phaseColor, 1);
  644. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  645. if (this.pointKtype == 14)
  646. g.DrawEllipse(pen, this.rectangle);
  647. else
  648. g.DrawEllipse(pen, new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));
  649. pen.Dispose();
  650. }
  651. //矩形删除
  652. if (this.pointKtype == 13 && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  653. {
  654. Pen pen = new Pen(this.phaseColor, 1);
  655. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  656. g.DrawRectangle(pen, new Rectangle((int)this.rectangle.X, (int)this.rectangle.Y, (int)this.rectangle.Width, (int)this.rectangle.Height));
  657. pen.Dispose();
  658. }
  659. // 折线删除
  660. if (this.pointKtype == 11 && pointFloatArray.Count >= 2)
  661. {
  662. Pen pen = new Pen(this.phaseColor, 1);
  663. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  664. g.DrawPolygon(pen, pointFloatArray.ToArray());
  665. pen.Dispose();
  666. }
  667. // 直线添加
  668. if (this.pointKtype == 2 && drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1)
  669. {
  670. Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
  671. //pen.DashStyle = DashStyle.Dash;
  672. g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
  673. pen.Dispose();
  674. }
  675. // 折线添加
  676. if (this.pointKtype == 1 && pointFloatArray.Count >= 2)
  677. {
  678. Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
  679. g.DrawLines(pen, pointFloatArray.ToArray());
  680. pen.Dispose();
  681. }
  682. }
  683. private void InitializeLanguageText()
  684. {
  685. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  686. this.button9.Text = PdnResources.GetString("CommonAction.Undo");
  687. this.button2.Text = PdnResources.GetString("Menu.File.Close.Text");
  688. this.button1.Text = PdnResources.GetString("Form.OkButton.Text");
  689. this.groupBox2.Text = PdnResources.GetString("Menu.BinaryAction.Text");
  690. this.button8.Text = PdnResources.GetString("Menu.Ellipsedelete.text");
  691. this.button7.Text = PdnResources.GetString("Menu.BinaryAction.RectangleDelete.Text");
  692. this.button6.Text = PdnResources.GetString("Menu.rounddelete.text");
  693. this.button5.Text = PdnResources.GetString("Menu.BinaryAction.PolygonleDelete.Text");
  694. this.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  695. this.button4.Text = PdnResources.GetString("Menu.Lineadd.text");
  696. this.button3.Text = PdnResources.GetString("Menu.Polylineadd.text");
  697. this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
  698. this.groupBox4.Text = PdnResources.GetString("Menu.Particlescreening.text");
  699. this.radioButton6.Text = PdnResources.GetString("Menu.Pixel.text");
  700. this.radioButton5.Text = PdnResources.GetString("Menu.Micron.text");
  701. this.label4.Text = PdnResources.GetString("Menu.filterunit.text") + ":";
  702. this.label3.Text = PdnResources.GetString("Menu.range.text") + ":";
  703. this.radioButton4.Text = PdnResources.GetString("Menu.Aspectratio.text");
  704. this.radioButton3.Text = PdnResources.GetString("Menu.Maximumcaliperdiameter.text");
  705. this.radioButton2.Text = PdnResources.GetString("Menu.Arearatio.text");
  706. this.radioButton1.Text = PdnResources.GetString("Menu.area.text");
  707. this.label2.Text = PdnResources.GetString("Menu.Filterparams.text") + ":";
  708. this.Text = PdnResources.GetString("Menu.filter.text");
  709. this.resetButton.Text = "重置";
  710. this.redoButton.Text = "恢复";
  711. this.undoButton.Text = "撤销";
  712. }
  713. private void InitializeComponent()
  714. {
  715. this.groupBox1 = new System.Windows.Forms.GroupBox();
  716. this.button9 = new System.Windows.Forms.Button();
  717. this.button2 = new System.Windows.Forms.Button();
  718. this.button1 = new System.Windows.Forms.Button();
  719. this.groupBox2 = new System.Windows.Forms.GroupBox();
  720. this.undoButton = new System.Windows.Forms.Button();
  721. this.redoButton = new System.Windows.Forms.Button();
  722. this.resetButton = new System.Windows.Forms.Button();
  723. this.button8 = new System.Windows.Forms.Button();
  724. this.trackBar1 = new System.Windows.Forms.TrackBar();
  725. this.button7 = new System.Windows.Forms.Button();
  726. this.trackBar2 = new PaintDotNet.CustomControl.TriangleTrackBar();
  727. this.button6 = new System.Windows.Forms.Button();
  728. this.textBox1 = new System.Windows.Forms.TextBox();
  729. this.button5 = new System.Windows.Forms.Button();
  730. this.label1 = new System.Windows.Forms.Label();
  731. this.button4 = new System.Windows.Forms.Button();
  732. this.button3 = new System.Windows.Forms.Button();
  733. this.groupBox7 = new System.Windows.Forms.GroupBox();
  734. this.groupBox4 = new System.Windows.Forms.GroupBox();
  735. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  736. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  737. this.panel2 = new System.Windows.Forms.Panel();
  738. this.radioButton6 = new System.Windows.Forms.RadioButton();
  739. this.radioButton5 = new System.Windows.Forms.RadioButton();
  740. this.triangleTrackBar1 = new PaintDotNet.CustomControl.TriangleTrackBar();
  741. this.label4 = new System.Windows.Forms.Label();
  742. this.label3 = new System.Windows.Forms.Label();
  743. this.panel1 = new System.Windows.Forms.Panel();
  744. this.radioButton4 = new System.Windows.Forms.RadioButton();
  745. this.radioButton3 = new System.Windows.Forms.RadioButton();
  746. this.radioButton2 = new System.Windows.Forms.RadioButton();
  747. this.radioButton1 = new System.Windows.Forms.RadioButton();
  748. this.label2 = new System.Windows.Forms.Label();
  749. this.groupBox1.SuspendLayout();
  750. this.groupBox2.SuspendLayout();
  751. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
  752. this.groupBox4.SuspendLayout();
  753. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  754. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  755. this.panel2.SuspendLayout();
  756. this.panel1.SuspendLayout();
  757. this.SuspendLayout();
  758. //
  759. // groupBox1
  760. //
  761. this.groupBox1.Controls.Add(this.button9);
  762. this.groupBox1.Controls.Add(this.button2);
  763. this.groupBox1.Controls.Add(this.button1);
  764. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  765. this.groupBox1.Name = "groupBox1";
  766. this.groupBox1.Size = new System.Drawing.Size(808, 45);
  767. this.groupBox1.TabIndex = 0;
  768. this.groupBox1.TabStop = false;
  769. //
  770. // button9
  771. //
  772. this.button9.Location = new System.Drawing.Point(468, 13);
  773. this.button9.Name = "button9";
  774. this.button9.Size = new System.Drawing.Size(91, 26);
  775. this.button9.TabIndex = 3;
  776. this.button9.UseVisualStyleBackColor = true;
  777. this.button9.Visible = false;
  778. //
  779. // button2
  780. //
  781. this.button2.Location = new System.Drawing.Point(694, 13);
  782. this.button2.Name = "button2";
  783. this.button2.Size = new System.Drawing.Size(91, 26);
  784. this.button2.TabIndex = 1;
  785. this.button2.UseVisualStyleBackColor = true;
  786. this.button2.Click += new System.EventHandler(this.button2_Click);
  787. //
  788. // button1
  789. //
  790. this.button1.Location = new System.Drawing.Point(582, 13);
  791. this.button1.Name = "button1";
  792. this.button1.Size = new System.Drawing.Size(91, 26);
  793. this.button1.TabIndex = 0;
  794. this.button1.UseVisualStyleBackColor = true;
  795. this.button1.Click += new System.EventHandler(this.button1_Click);
  796. //
  797. // groupBox2
  798. //
  799. this.groupBox2.Controls.Add(this.undoButton);
  800. this.groupBox2.Controls.Add(this.redoButton);
  801. this.groupBox2.Controls.Add(this.resetButton);
  802. this.groupBox2.Controls.Add(this.button8);
  803. this.groupBox2.Controls.Add(this.trackBar1);
  804. this.groupBox2.Controls.Add(this.button7);
  805. this.groupBox2.Controls.Add(this.trackBar2);
  806. this.groupBox2.Controls.Add(this.button6);
  807. this.groupBox2.Controls.Add(this.textBox1);
  808. this.groupBox2.Controls.Add(this.button5);
  809. this.groupBox2.Controls.Add(this.label1);
  810. this.groupBox2.Controls.Add(this.button4);
  811. this.groupBox2.Controls.Add(this.button3);
  812. this.groupBox2.Location = new System.Drawing.Point(12, 347);
  813. this.groupBox2.Name = "groupBox2";
  814. this.groupBox2.Size = new System.Drawing.Size(233, 218);
  815. this.groupBox2.TabIndex = 1;
  816. this.groupBox2.TabStop = false;
  817. //
  818. // undoButton
  819. //
  820. this.undoButton.Enabled = false;
  821. this.undoButton.Location = new System.Drawing.Point(153, 175);
  822. this.undoButton.Name = "undoButton";
  823. this.undoButton.Size = new System.Drawing.Size(59, 26);
  824. this.undoButton.TabIndex = 24;
  825. this.undoButton.UseVisualStyleBackColor = true;
  826. this.undoButton.Click += new System.EventHandler(this.undoButton_Click);
  827. //
  828. // redoButton
  829. //
  830. this.redoButton.Enabled = false;
  831. this.redoButton.Location = new System.Drawing.Point(85, 175);
  832. this.redoButton.Name = "redoButton";
  833. this.redoButton.Size = new System.Drawing.Size(59, 26);
  834. this.redoButton.TabIndex = 23;
  835. this.redoButton.UseVisualStyleBackColor = true;
  836. this.redoButton.Click += new System.EventHandler(this.redoButton_Click);
  837. //
  838. // resetButton
  839. //
  840. this.resetButton.Enabled = false;
  841. this.resetButton.Location = new System.Drawing.Point(18, 175);
  842. this.resetButton.Name = "resetButton";
  843. this.resetButton.Size = new System.Drawing.Size(59, 26);
  844. this.resetButton.TabIndex = 22;
  845. this.resetButton.UseVisualStyleBackColor = true;
  846. this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
  847. //
  848. // button8
  849. //
  850. this.button8.Location = new System.Drawing.Point(134, 134);
  851. this.button8.Name = "button8";
  852. this.button8.Size = new System.Drawing.Size(73, 26);
  853. this.button8.TabIndex = 7;
  854. this.button8.UseVisualStyleBackColor = true;
  855. this.button8.Click += new System.EventHandler(this.button8_Click);
  856. //
  857. // trackBar1
  858. //
  859. this.trackBar1.AutoSize = false;
  860. this.trackBar1.Location = new System.Drawing.Point(107, 52);
  861. this.trackBar1.Maximum = 50;
  862. this.trackBar1.Minimum = 1;
  863. this.trackBar1.Name = "trackBar1";
  864. this.trackBar1.Size = new System.Drawing.Size(104, 31);
  865. this.trackBar1.TabIndex = 21;
  866. this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
  867. this.trackBar1.Value = 1;
  868. this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
  869. //
  870. // button7
  871. //
  872. this.button7.Location = new System.Drawing.Point(27, 134);
  873. this.button7.Name = "button7";
  874. this.button7.Size = new System.Drawing.Size(73, 26);
  875. this.button7.TabIndex = 6;
  876. this.button7.UseVisualStyleBackColor = true;
  877. this.button7.Click += new System.EventHandler(this.button7_Click);
  878. //
  879. // trackBar2
  880. //
  881. this.trackBar2.Location = new System.Drawing.Point(108, 52);
  882. this.trackBar2.Maximum = 50;
  883. this.trackBar2.Minimum = 1;
  884. this.trackBar2.Name = "trackBar2";
  885. this.trackBar2.Size = new System.Drawing.Size(102, 24);
  886. this.trackBar2.TabIndex = 20;
  887. this.trackBar2.Value = 1;
  888. this.trackBar2.Visible = false;
  889. //
  890. // button6
  891. //
  892. this.button6.Location = new System.Drawing.Point(134, 90);
  893. this.button6.Name = "button6";
  894. this.button6.Size = new System.Drawing.Size(73, 26);
  895. this.button6.TabIndex = 5;
  896. this.button6.UseVisualStyleBackColor = true;
  897. this.button6.Click += new System.EventHandler(this.button6_Click);
  898. //
  899. // textBox1
  900. //
  901. this.textBox1.Location = new System.Drawing.Point(68, 52);
  902. this.textBox1.Name = "textBox1";
  903. this.textBox1.Size = new System.Drawing.Size(32, 21);
  904. this.textBox1.TabIndex = 19;
  905. this.textBox1.Text = "1";
  906. this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  907. //
  908. // button5
  909. //
  910. this.button5.Location = new System.Drawing.Point(27, 90);
  911. this.button5.Name = "button5";
  912. this.button5.Size = new System.Drawing.Size(73, 26);
  913. this.button5.TabIndex = 4;
  914. this.button5.UseVisualStyleBackColor = true;
  915. this.button5.Click += new System.EventHandler(this.button5_Click);
  916. //
  917. // label1
  918. //
  919. this.label1.AutoSize = true;
  920. this.label1.Location = new System.Drawing.Point(28, 56);
  921. this.label1.Name = "label1";
  922. this.label1.Size = new System.Drawing.Size(0, 12);
  923. this.label1.TabIndex = 18;
  924. //
  925. // button4
  926. //
  927. this.button4.Location = new System.Drawing.Point(135, 18);
  928. this.button4.Name = "button4";
  929. this.button4.Size = new System.Drawing.Size(73, 26);
  930. this.button4.TabIndex = 3;
  931. this.button4.UseVisualStyleBackColor = true;
  932. this.button4.Click += new System.EventHandler(this.button4_Click);
  933. //
  934. // button3
  935. //
  936. this.button3.Location = new System.Drawing.Point(28, 18);
  937. this.button3.Name = "button3";
  938. this.button3.Size = new System.Drawing.Size(73, 26);
  939. this.button3.TabIndex = 2;
  940. this.button3.UseVisualStyleBackColor = true;
  941. this.button3.Click += new System.EventHandler(this.button3_Click);
  942. //
  943. // groupBox7
  944. //
  945. this.groupBox7.Location = new System.Drawing.Point(251, 63);
  946. this.groupBox7.Name = "groupBox7";
  947. this.groupBox7.Size = new System.Drawing.Size(569, 502);
  948. this.groupBox7.TabIndex = 1;
  949. this.groupBox7.TabStop = false;
  950. //
  951. // groupBox4
  952. //
  953. this.groupBox4.Controls.Add(this.numericUpDown2);
  954. this.groupBox4.Controls.Add(this.numericUpDown1);
  955. this.groupBox4.Controls.Add(this.panel2);
  956. this.groupBox4.Controls.Add(this.triangleTrackBar1);
  957. this.groupBox4.Controls.Add(this.label4);
  958. this.groupBox4.Controls.Add(this.label3);
  959. this.groupBox4.Controls.Add(this.panel1);
  960. this.groupBox4.Controls.Add(this.label2);
  961. this.groupBox4.Location = new System.Drawing.Point(12, 63);
  962. this.groupBox4.Name = "groupBox4";
  963. this.groupBox4.Size = new System.Drawing.Size(233, 278);
  964. this.groupBox4.TabIndex = 2;
  965. this.groupBox4.TabStop = false;
  966. //
  967. // numericUpDown2
  968. //
  969. this.numericUpDown2.DecimalPlaces = 2;
  970. this.numericUpDown2.Increment = new decimal(new int[] {
  971. 1,
  972. 0,
  973. 0,
  974. 131072});
  975. this.numericUpDown2.Location = new System.Drawing.Point(131, 164);
  976. this.numericUpDown2.Maximum = new decimal(new int[] {
  977. 2147483647,
  978. 0,
  979. 0,
  980. 0});
  981. this.numericUpDown2.Name = "numericUpDown2";
  982. this.numericUpDown2.Size = new System.Drawing.Size(60, 21);
  983. this.numericUpDown2.TabIndex = 21;
  984. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
  985. //
  986. // numericUpDown1
  987. //
  988. this.numericUpDown1.DecimalPlaces = 2;
  989. this.numericUpDown1.Increment = new decimal(new int[] {
  990. 1,
  991. 0,
  992. 0,
  993. 131072});
  994. this.numericUpDown1.Location = new System.Drawing.Point(66, 164);
  995. this.numericUpDown1.Maximum = new decimal(new int[] {
  996. 2147483647,
  997. 0,
  998. 0,
  999. 0});
  1000. this.numericUpDown1.Name = "numericUpDown1";
  1001. this.numericUpDown1.Size = new System.Drawing.Size(60, 21);
  1002. this.numericUpDown1.TabIndex = 20;
  1003. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
  1004. //
  1005. // panel2
  1006. //
  1007. this.panel2.Controls.Add(this.radioButton6);
  1008. this.panel2.Controls.Add(this.radioButton5);
  1009. this.panel2.Location = new System.Drawing.Point(66, 201);
  1010. this.panel2.Name = "panel2";
  1011. this.panel2.Size = new System.Drawing.Size(127, 30);
  1012. this.panel2.TabIndex = 19;
  1013. //
  1014. // radioButton6
  1015. //
  1016. this.radioButton6.AutoSize = true;
  1017. this.radioButton6.Location = new System.Drawing.Point(60, 7);
  1018. this.radioButton6.Name = "radioButton6";
  1019. this.radioButton6.Size = new System.Drawing.Size(14, 13);
  1020. this.radioButton6.TabIndex = 2;
  1021. this.radioButton6.TabStop = true;
  1022. this.radioButton6.UseVisualStyleBackColor = true;
  1023. this.radioButton6.CheckedChanged += new System.EventHandler(this.radioButton6_CheckedChanged);
  1024. //
  1025. // radioButton5
  1026. //
  1027. this.radioButton5.AutoSize = true;
  1028. this.radioButton5.Checked = true;
  1029. this.radioButton5.Location = new System.Drawing.Point(7, 7);
  1030. this.radioButton5.Name = "radioButton5";
  1031. this.radioButton5.Size = new System.Drawing.Size(14, 13);
  1032. this.radioButton5.TabIndex = 1;
  1033. this.radioButton5.TabStop = true;
  1034. this.radioButton5.UseVisualStyleBackColor = true;
  1035. this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
  1036. //
  1037. // triangleTrackBar1
  1038. //
  1039. this.triangleTrackBar1.Location = new System.Drawing.Point(66, 164);
  1040. this.triangleTrackBar1.Maximum = 10000;
  1041. this.triangleTrackBar1.Minimum = 0;
  1042. this.triangleTrackBar1.Name = "triangleTrackBar1";
  1043. this.triangleTrackBar1.Size = new System.Drawing.Size(102, 24);
  1044. this.triangleTrackBar1.TabIndex = 18;
  1045. this.triangleTrackBar1.Value = 0;
  1046. this.triangleTrackBar1.Visible = false;
  1047. //
  1048. // label4
  1049. //
  1050. this.label4.AutoSize = true;
  1051. this.label4.Location = new System.Drawing.Point(9, 208);
  1052. this.label4.Name = "label4";
  1053. this.label4.Size = new System.Drawing.Size(0, 12);
  1054. this.label4.TabIndex = 3;
  1055. //
  1056. // label3
  1057. //
  1058. this.label3.AutoSize = true;
  1059. this.label3.Location = new System.Drawing.Point(33, 168);
  1060. this.label3.Name = "label3";
  1061. this.label3.Size = new System.Drawing.Size(0, 12);
  1062. this.label3.TabIndex = 2;
  1063. //
  1064. // panel1
  1065. //
  1066. this.panel1.Controls.Add(this.radioButton4);
  1067. this.panel1.Controls.Add(this.radioButton3);
  1068. this.panel1.Controls.Add(this.radioButton2);
  1069. this.panel1.Controls.Add(this.radioButton1);
  1070. this.panel1.Location = new System.Drawing.Point(66, 28);
  1071. this.panel1.Name = "panel1";
  1072. this.panel1.Size = new System.Drawing.Size(121, 122);
  1073. this.panel1.TabIndex = 1;
  1074. //
  1075. // radioButton4
  1076. //
  1077. this.radioButton4.AutoSize = true;
  1078. this.radioButton4.Location = new System.Drawing.Point(13, 97);
  1079. this.radioButton4.Name = "radioButton4";
  1080. this.radioButton4.Size = new System.Drawing.Size(14, 13);
  1081. this.radioButton4.TabIndex = 3;
  1082. this.radioButton4.TabStop = true;
  1083. this.radioButton4.UseVisualStyleBackColor = true;
  1084. this.radioButton4.CheckedChanged += new System.EventHandler(this.radioButton4_CheckedChanged);
  1085. //
  1086. // radioButton3
  1087. //
  1088. this.radioButton3.AutoSize = true;
  1089. this.radioButton3.Location = new System.Drawing.Point(13, 67);
  1090. this.radioButton3.Name = "radioButton3";
  1091. this.radioButton3.Size = new System.Drawing.Size(14, 13);
  1092. this.radioButton3.TabIndex = 2;
  1093. this.radioButton3.TabStop = true;
  1094. this.radioButton3.UseVisualStyleBackColor = true;
  1095. this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
  1096. //
  1097. // radioButton2
  1098. //
  1099. this.radioButton2.AutoSize = true;
  1100. this.radioButton2.Location = new System.Drawing.Point(13, 37);
  1101. this.radioButton2.Name = "radioButton2";
  1102. this.radioButton2.Size = new System.Drawing.Size(14, 13);
  1103. this.radioButton2.TabIndex = 1;
  1104. this.radioButton2.TabStop = true;
  1105. this.radioButton2.UseVisualStyleBackColor = true;
  1106. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
  1107. //
  1108. // radioButton1
  1109. //
  1110. this.radioButton1.AutoSize = true;
  1111. this.radioButton1.Checked = true;
  1112. this.radioButton1.Location = new System.Drawing.Point(13, 7);
  1113. this.radioButton1.Name = "radioButton1";
  1114. this.radioButton1.Size = new System.Drawing.Size(14, 13);
  1115. this.radioButton1.TabIndex = 0;
  1116. this.radioButton1.TabStop = true;
  1117. this.radioButton1.UseVisualStyleBackColor = true;
  1118. this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  1119. //
  1120. // label2
  1121. //
  1122. this.label2.AutoSize = true;
  1123. this.label2.Location = new System.Drawing.Point(9, 35);
  1124. this.label2.Name = "label2";
  1125. this.label2.Size = new System.Drawing.Size(0, 12);
  1126. this.label2.TabIndex = 0;
  1127. //
  1128. // GrainBinaryBoundaryEditingDialog
  1129. //
  1130. this.ClientSize = new System.Drawing.Size(832, 577);
  1131. this.Controls.Add(this.groupBox4);
  1132. this.Controls.Add(this.groupBox2);
  1133. this.Controls.Add(this.groupBox7);
  1134. this.Controls.Add(this.groupBox1);
  1135. this.MaximizeBox = false;
  1136. this.MinimizeBox = false;
  1137. this.Name = "GrainBinaryBoundaryEditingDialog";
  1138. this.Load += new System.EventHandler(this.GrainBinaryBoundaryEditingDialog_Load);
  1139. this.groupBox1.ResumeLayout(false);
  1140. this.groupBox2.ResumeLayout(false);
  1141. this.groupBox2.PerformLayout();
  1142. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
  1143. this.groupBox4.ResumeLayout(false);
  1144. this.groupBox4.PerformLayout();
  1145. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  1146. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  1147. this.panel2.ResumeLayout(false);
  1148. this.panel2.PerformLayout();
  1149. this.panel1.ResumeLayout(false);
  1150. this.panel1.PerformLayout();
  1151. this.ResumeLayout(false);
  1152. }
  1153. /// <summary>
  1154. /// 折线添加
  1155. /// </summary>
  1156. /// <param name="sender"></param>
  1157. /// <param name="e"></param>
  1158. private void button3_Click(object sender, EventArgs e)
  1159. {
  1160. pointFloatArray.Clear();
  1161. startPoint = new Point(-1, -1);
  1162. drawedStartPoint = false;
  1163. endPoint = new Point(-1, -1);
  1164. pointKtype = 1;
  1165. this.documentWorkspace.Refresh();
  1166. }
  1167. /// <summary>
  1168. /// 直线添加
  1169. /// </summary>
  1170. /// <param name="sender"></param>
  1171. /// <param name="e"></param>
  1172. private void button4_Click(object sender, EventArgs e)
  1173. {
  1174. startPoint = new Point(-1, -1);
  1175. drawedStartPoint = false;
  1176. endPoint = new Point(-1, -1);
  1177. pointKtype = 2;
  1178. this.documentWorkspace.Refresh();
  1179. }
  1180. private void InitCommonButtonEvent()
  1181. {
  1182. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  1183. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  1184. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  1185. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  1186. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  1187. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  1188. }
  1189. private void zoomInButton_Click(object sender, EventArgs e)
  1190. {
  1191. this.documentWorkspace.ZoomIn();
  1192. }
  1193. private void zoomOutButton_Click(object sender, EventArgs e)
  1194. {
  1195. this.documentWorkspace.ZoomOut();
  1196. }
  1197. private void zoomToWindowButton_Click(object sender, EventArgs e)
  1198. {
  1199. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1200. }
  1201. private void actualSizeButton_Click(object sender, EventArgs e)
  1202. {
  1203. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1204. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  1205. }
  1206. private void pointerButton_Click(object sender, EventArgs e)
  1207. {
  1208. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;
  1209. this.documentWorkspace.Cursor = Cursors.Default;
  1210. }
  1211. private void mobileModeButton_Click(object sender, EventArgs e)
  1212. {
  1213. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  1214. }
  1215. //确定按钮点击事件
  1216. private void button1_Click(object sender, EventArgs e)
  1217. {
  1218. this.phaseMatCopy = this.documentWorkspace.PhaseModels[0].mat;
  1219. this.DialogResult = DialogResult.OK;
  1220. this.Close();
  1221. }
  1222. /// <summary>
  1223. /// 用于get处理后的图像
  1224. /// </summary>
  1225. public Mat PhaseMat
  1226. {
  1227. get
  1228. {
  1229. return this.phaseMatCopy;
  1230. }
  1231. set
  1232. {
  1233. this.phaseMatCopy = value;
  1234. }
  1235. }
  1236. /// <summary>
  1237. /// 矩形删除
  1238. /// </summary>
  1239. /// <param name="sender"></param>
  1240. /// <param name="e"></param>
  1241. private void button7_Click(object sender, EventArgs e)
  1242. {
  1243. startPoint = new Point(-1, -1);
  1244. drawedStartPoint = false;
  1245. endPoint = new Point(-1, -1);
  1246. this.rectangle.X = -1;
  1247. this.rectangle.Y = -1;
  1248. this.rectangle.Width = 0;
  1249. this.rectangle.Height = 0;
  1250. this.pointKtype = 13;
  1251. this.documentWorkspace.Refresh();
  1252. }
  1253. /// <summary>
  1254. /// 椭圆删除
  1255. /// </summary>
  1256. /// <param name="sender"></param>
  1257. /// <param name="e"></param>
  1258. private void button8_Click(object sender, EventArgs e)
  1259. {
  1260. startPoint = new Point(-1, -1);
  1261. drawedStartPoint = false;
  1262. endPoint = new Point(-1, -1);
  1263. this.rectangle.X = -1;
  1264. this.rectangle.Y = -1;
  1265. this.rectangle.Width = 0;
  1266. this.rectangle.Height = 0;
  1267. this.pointKtype = 14;
  1268. this.documentWorkspace.Refresh();
  1269. }
  1270. /// <summary>
  1271. /// 圆形删除
  1272. /// </summary>
  1273. /// <param name="sender"></param>
  1274. /// <param name="e"></param>
  1275. private void button6_Click(object sender, EventArgs e)
  1276. {
  1277. startPoint = new Point(-1, -1);
  1278. drawedStartPoint = false;
  1279. endPoint = new Point(-1, -1);
  1280. this.rectangle.X = -1;
  1281. this.rectangle.Y = -1;
  1282. this.rectangle.Width = 0;
  1283. this.rectangle.Height = 0;
  1284. this.pointKtype = 12;
  1285. this.documentWorkspace.Refresh();
  1286. }
  1287. /// <summary>
  1288. /// 多边形删除
  1289. /// </summary>
  1290. /// <param name="sender"></param>
  1291. /// <param name="e"></param>
  1292. private void button5_Click(object sender, EventArgs e)
  1293. {
  1294. pointFloatArray.Clear();
  1295. startPoint = new Point(-1, -1);
  1296. drawedStartPoint = false;
  1297. endPoint = new Point(-1, -1);
  1298. this.rectangle.X = -1;
  1299. this.rectangle.Y = -1;
  1300. this.rectangle.Width = 0;
  1301. this.rectangle.Height = 0;
  1302. this.pointKtype = 11;
  1303. this.documentWorkspace.Refresh();
  1304. }
  1305. private void button2_Click(object sender, EventArgs e)
  1306. {
  1307. this.Close();
  1308. }
  1309. /// <summary>
  1310. /// 线宽改变
  1311. /// </summary>
  1312. /// <param name="sender"></param>
  1313. /// <param name="e"></param>
  1314. private void textBox1_TextChanged(object sender, EventArgs e)
  1315. {
  1316. int valueT;
  1317. if (!int.TryParse(textBox1.Text, out valueT))
  1318. return;
  1319. if (this.trackBar1.Minimum > valueT)
  1320. valueT = this.trackBar1.Minimum;
  1321. if (this.trackBar1.Maximum < valueT)
  1322. valueT = this.trackBar1.Maximum;
  1323. this.trackBar1.Value = valueT;
  1324. //this.textBox1.Text = valueT + "";
  1325. }
  1326. private void trackBar1_Scroll(object sender, EventArgs e)
  1327. {
  1328. this.textBox1.Text = this.trackBar1.Value + "";
  1329. }
  1330. /// <summary>
  1331. /// 范围改变
  1332. /// </summary>
  1333. /// <param name="sender"></param>
  1334. /// <param name="e"></param>
  1335. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  1336. {
  1337. this.applyChangedAction();
  1338. }
  1339. /// <summary>
  1340. /// 范围改变
  1341. /// </summary>
  1342. /// <param name="sender"></param>
  1343. /// <param name="e"></param>
  1344. private void numericUpDown2_ValueChanged(object sender, EventArgs e)
  1345. {
  1346. this.applyChangedAction();
  1347. }
  1348. /// <summary>
  1349. /// 筛选单位改变
  1350. /// </summary>
  1351. /// <param name="sender"></param>
  1352. /// <param name="e"></param>
  1353. private void radioButton5_CheckedChanged(object sender, EventArgs e)
  1354. {
  1355. this.applyChangedAction();
  1356. }
  1357. private void radioButton6_CheckedChanged(object sender, EventArgs e)
  1358. {
  1359. this.applyChangedAction();
  1360. }
  1361. /// <summary>
  1362. /// 筛选参数改变
  1363. /// </summary>
  1364. /// <param name="sender"></param>
  1365. /// <param name="e"></param>
  1366. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  1367. {
  1368. this.applyChangedAction();
  1369. }
  1370. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  1371. {
  1372. this.applyChangedAction();
  1373. }
  1374. private void radioButton3_CheckedChanged(object sender, EventArgs e)
  1375. {
  1376. this.applyChangedAction();
  1377. }
  1378. private void radioButton4_CheckedChanged(object sender, EventArgs e)
  1379. {
  1380. this.applyChangedAction();
  1381. }
  1382. protected static string ParamKey_FilterParameters = "FilterParameters";//筛选参数
  1383. protected static string ParamKey_UnitParameters = "UnitParameters";//筛选单位
  1384. protected static string ParamKey_Scope1 = "Scope1";//数值范围
  1385. protected static string ParamKey_Scope2 = "Scope2";//数值范围
  1386. protected static string ParamKey_LineWidth = "LineWidth";//线宽
  1387. /// <summary>
  1388. /// 保存参数的key,value和type
  1389. /// </summary>
  1390. /// <param name="param_key"></param>
  1391. /// <param name="param_value"></param>
  1392. /// <param name="param_type"></param>
  1393. private void saveParamValue(string param_key, string param_value, int param_type)
  1394. {
  1395. bool foundItem = false;
  1396. //string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryConfig\\BinaryEditModel.xml";
  1397. //GrainSizeAnalysisModel analysisModelXml;
  1398. //if (!System.IO.File.Exists(xmlFilePath))
  1399. // analysisModelXml = new GrainSizeAnalysisModel();
  1400. //else
  1401. // analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  1402. ////this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
  1403. //foreach (var item in analysisModelXml.ListParam)
  1404. // item.setValue();
  1405. //if (!foundItem)
  1406. //{
  1407. // GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
  1408. // analysisItem.menuId = this.menuId;
  1409. // analysisItem.param_key = param_key;
  1410. // analysisItem.param_type = param_type;
  1411. // analysisItem.param_value = param_value;
  1412. // analysisItem.setValue();
  1413. // this.analysisModel.ListParam.Add(analysisItem);
  1414. //}
  1415. }
  1416. private void applyChangedAction()
  1417. {
  1418. foreach (Base.Args args in action.Lists)
  1419. {
  1420. switch (args.Key)
  1421. {
  1422. case "FilterParameters"://筛选参数
  1423. {
  1424. if (radioButton1.Checked)
  1425. args.Value = Base.Enum.FilterParameters.Area;
  1426. else if (radioButton2.Checked)
  1427. args.Value = Base.Enum.FilterParameters.AreaRatio;
  1428. else if (radioButton3.Checked)
  1429. args.Value = Base.Enum.FilterParameters.LongTrail;
  1430. else if (radioButton4.Checked)
  1431. args.Value = Base.Enum.FilterParameters.AspectRatio;
  1432. }
  1433. break;
  1434. case "UnitParameters"://筛选单位
  1435. {
  1436. if (radioButton5.Checked)
  1437. args.Value = MeasurementUnit.Micron;
  1438. else if (radioButton6.Checked)
  1439. args.Value = MeasurementUnit.Pixel;
  1440. }
  1441. break;
  1442. case "Scope"://数值范围
  1443. {
  1444. List<double> oneL = new List<double>();
  1445. oneL.Add((double)this.numericUpDown1.Value);
  1446. oneL.Add((double)this.numericUpDown2.Value);
  1447. args.Value = oneL;
  1448. }
  1449. break;
  1450. default:
  1451. break;
  1452. }
  1453. }
  1454. this.applyButtonImpl(null, null);
  1455. }
  1456. /// <summary>
  1457. /// 应用
  1458. /// </summary>
  1459. /// <param name="sender"></param>
  1460. /// <param name="e"></param>
  1461. private void applyButtonImpl(object sender, EventArgs e)
  1462. {
  1463. //如果有选中的相
  1464. List<PhaseModel> phases = this.documentWorkspace.PhaseModels;
  1465. if (phases.Count > 0)
  1466. {
  1467. List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  1468. for (int i = 0; i < phases.Count; i++)
  1469. {
  1470. PhaseModel model = new PhaseModel();
  1471. model.choise = phases[i].choise;
  1472. model.color = phaseColor.ToArgb();// phases[i].color;
  1473. model.name = phases[i].name;
  1474. model.position = phases[i].position;
  1475. model.mat = new OpenCvSharp.Mat();
  1476. phaseMatCopy.CopyTo(model.mat);
  1477. //phases[i].mat.CopyTo(model.mat);//避免碎屑删除不可逆的问题
  1478. phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
  1479. this.documentWorkspace.Refresh();
  1480. }
  1481. if (PhaseModel0MatCopy != null)
  1482. {
  1483. PhaseModel0MatCopy.Dispose();
  1484. PhaseModel0MatCopy = null;
  1485. }
  1486. PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
  1487. this.resetOperationsAction();
  1488. }
  1489. else
  1490. {
  1491. OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
  1492. Document doc = Document.FromMat(mat);
  1493. this.documentWorkspace.Document = doc;
  1494. this.documentWorkspace.Refresh();
  1495. }
  1496. }
  1497. /// <summary>
  1498. /// 根据当前操作位置处理图片,并刷新操作按钮状态
  1499. /// </summary>
  1500. /// <param name="OperationTag"></param>
  1501. private void RefreshMatsToIndex(int OperationTag)
  1502. {
  1503. //...处理图片(this.OperationIndex)
  1504. this.OperationIndex = OperationTag;
  1505. ///// 操作类型
  1506. //private int pointKtype = 0;
  1507. if (PhaseModel0MatCopy != null && this.OperationIndex >= 0)
  1508. {
  1509. Mat newModel0Mat = PhaseModel0MatCopy.Clone();
  1510. for (int i = 0; i <= this.OperationIndex; i++)
  1511. {
  1512. //操作类型 0,没有操作 1,折线添加 2,直线添加 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
  1513. int opeType = this.OperationKtypeList[i];
  1514. PointF[] opePoints = this.OperationsList[i];
  1515. // 折线删除
  1516. if (opeType == 11 && opePoints.Length > 1)
  1517. {
  1518. newModel0Mat/*this.documentWorkspace.PhaseModels[0].mat*/ = PreActionIntent.PolygonDelete(newModel0Mat/*this.documentWorkspace.PhaseModels[0].mat*/, opePoints.ToList()/*pointFloatArray*/);
  1519. //this.pointKtype = 0;
  1520. //this.documentWorkspace.Refresh();
  1521. }
  1522. // 折线添加
  1523. if (opeType == 1 && opePoints.Length > 1)
  1524. {
  1525. //保存处理后的图片
  1526. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newModel0Mat);
  1527. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1528. Graphics graphics = Graphics.FromImage(newBit);
  1529. //Draw(graphics, false);
  1530. // 抗锯齿
  1531. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1532. // 折线添加
  1533. if (opeType == 1 && opePoints.Length >= 2)
  1534. {
  1535. Pen pen = new Pen(this.phaseColor, this.OperationsLineWidthList[i]);
  1536. graphics.DrawLines(pen, opePoints);
  1537. pen.Dispose();
  1538. }
  1539. newModel0Mat = PaintDotNet.Camera.Tools.ToMat(newBit);
  1540. }
  1541. // 圆形删除/椭圆删除
  1542. if ((opeType == 14 || opeType == 12) && opePoints.Length == 2)
  1543. {
  1544. RectangleF rectangleFOpe = new RectangleF(opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y);
  1545. if (this.pointKtype == 14)
  1546. newModel0Mat = PreActionIntent.OvalDelete(newModel0Mat, rectangleFOpe);
  1547. else
  1548. newModel0Mat = PreActionIntent.OvalDelete(newModel0Mat, rectangleFOpe);
  1549. }
  1550. // 矩形删除
  1551. if (opeType == 13 && opePoints.Length == 2)
  1552. {
  1553. RectangleF rectangleFOpe = new RectangleF(opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y);
  1554. newModel0Mat = PreActionIntent.RectangleDelete(newModel0Mat, rectangleFOpe);
  1555. }
  1556. // 直线添加
  1557. if (opeType == 2 && opePoints.Length == 2/*this.startPoint.X > -1 && this.startPoint.Y > -1*/)
  1558. {
  1559. //保存处理后的图片
  1560. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newModel0Mat);
  1561. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1562. Graphics graphics = Graphics.FromImage(newBit);
  1563. //Draw(graphics, false);
  1564. // 抗锯齿
  1565. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1566. // 直线添加
  1567. if (opeType == 2 && opePoints.Length == 2/*this.startPoint.X > -1 && this.startPoint.Y > -1 && this.endPoint.X > -1 && this.endPoint.Y > -1*/)
  1568. {
  1569. Pen pen = new Pen(this.phaseColor, this.OperationsLineWidthList[i]);
  1570. graphics.DrawLine(pen, opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y);
  1571. //////pen.DashStyle = DashStyle.Dash;
  1572. //g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
  1573. pen.Dispose();
  1574. }
  1575. newModel0Mat = PaintDotNet.Camera.Tools.ToMat(newBit);
  1576. }
  1577. }
  1578. this.documentWorkspace.PhaseModels[0].mat = newModel0Mat;
  1579. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  1580. this.documentWorkspace.Refresh();
  1581. }
  1582. else if (PhaseModel0MatCopy != null)
  1583. {
  1584. this.documentWorkspace.PhaseModels[0].mat = PhaseModel0MatCopy.Clone();
  1585. this.documentWorkspace.Refresh();
  1586. }
  1587. //刷新操作按钮的状态
  1588. this.RefreshOperationsButtons();
  1589. }
  1590. /// <summary>
  1591. /// 操作-重置
  1592. /// </summary>
  1593. private void resetOperationsAction()
  1594. {
  1595. this.OperationIndex = -1;
  1596. this.RefreshOperationsToIndex();
  1597. this.RefreshOperationsButtons();
  1598. }
  1599. /// <summary>
  1600. /// 重置按钮点击事件
  1601. /// </summary>
  1602. /// <param name="sender"></param>
  1603. /// <param name="e"></param>
  1604. private void resetButton_Click(object sender, EventArgs e)
  1605. {
  1606. if (PhaseModel0MatCopy != null)
  1607. {
  1608. this.documentWorkspace.PhaseModels[0].mat = PhaseModel0MatCopy.Clone();
  1609. this.documentWorkspace.Refresh();
  1610. }
  1611. this.resetOperationsAction();
  1612. }
  1613. /// <summary>
  1614. /// 恢复按钮点击事件
  1615. /// </summary>
  1616. /// <param name="sender"></param>
  1617. /// <param name="e"></param>
  1618. private void redoButton_Click(object sender, EventArgs e)
  1619. {
  1620. if (this.OperationIndex < this.OperationKtypeList.Count - 1)
  1621. {
  1622. this.RefreshMatsToIndex(this.OperationIndex + 1);
  1623. }
  1624. else
  1625. this.redoButton.Enabled = false;
  1626. }
  1627. /// <summary>
  1628. /// 撤销按钮点击事件
  1629. /// </summary>
  1630. /// <param name="sender"></param>
  1631. /// <param name="e"></param>
  1632. private void undoButton_Click(object sender, EventArgs e)
  1633. {
  1634. if (this.OperationIndex >= 0)
  1635. {
  1636. this.RefreshMatsToIndex(this.OperationIndex - 1);
  1637. }
  1638. else
  1639. this.undoButton.Enabled = false;
  1640. }
  1641. private void GrainBinaryBoundaryEditingDialog_Load(object sender, EventArgs e)
  1642. {
  1643. }
  1644. }
  1645. }