GrainBinaryBoundaryEditingDialog.cs 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. using OpenCvSharp;
  2. using PaintDotNet.Adjust;
  3. using PaintDotNet.Base.Functionodel;
  4. using PaintDotNet.CustomControl;
  5. using PaintDotNet;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Drawing.Drawing2D;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using Point = System.Drawing.Point;
  17. namespace PaintDotNet.DedicatedAnalysis.GrainSize.GBT6394_2017
  18. {
  19. internal class GrainBinaryBoundaryEditingDialog : Form
  20. {
  21. /// <summary>
  22. /// 公共按钮
  23. /// </summary>
  24. private CommonControlButtons commonControlButtons;
  25. /// <summary>
  26. /// 主控件
  27. /// </summary>
  28. private AppWorkspace appWorkspace;
  29. private DocumentWorkspaceWindow documentWorkspace;
  30. /// <summary>
  31. /// 外接矩形,或者是计算的矩形
  32. /// </summary>
  33. protected RectangleF rectangle = new RectangleF();
  34. /// <summary>
  35. /// 存在视场标记
  36. /// </summary>
  37. private bool existViewFlag = false;
  38. /// <summary>
  39. /// 选中图片的bitmap
  40. /// </summary>
  41. private Bitmap bitmap;
  42. /// <summary>
  43. /// 当前选择的图片
  44. /// </summary>
  45. private Mat mat;
  46. ///// <summary>
  47. ///// 用于get处理后的图像
  48. ///// </summary>
  49. //private Mat phaseMat;
  50. /// <summary>
  51. /// 辅助线集成
  52. /// </summary>
  53. private GrainSizeGuideClass guideClass;
  54. public object SelectedItem;
  55. Color phaseColor;
  56. Mat phaseMatCopy = new Mat();
  57. /// <summary>
  58. /// 当前处理的程序
  59. /// </summary>
  60. private Data.Action.Action911 action = new Data.Action.Action911();
  61. /// <summary>
  62. /// 操作类型
  63. /// 0,没有操作 1,折线添加 2,直线添加
  64. /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
  65. /// </summary>
  66. private int pointKtype = 0;
  67. /// <summary>
  68. /// 起始点
  69. /// </summary>
  70. private Point startPoint = new Point(-1, -1);
  71. /// <summary>
  72. /// 是否绘制了起始点
  73. /// </summary>
  74. private bool drawedStartPoint = false;
  75. /// <summary>
  76. /// 结束点
  77. /// </summary>
  78. private Point endPoint = new Point(-1, -1);
  79. /// <summary>
  80. /// 折线点的集合
  81. /// </summary>
  82. public List<Point> pointArray = new List<Point>();
  83. /// <summary>
  84. /// 一些方法用到了微米换算
  85. /// </summary>
  86. private double ruleValue = 1.0;
  87. private GroupBox groupBox1;
  88. private GroupBox groupBox2;
  89. private Button button2;
  90. private Button button1;
  91. private Button button3;
  92. private Button button4;
  93. private Button button8;
  94. private Button button7;
  95. private Button button6;
  96. private Button button5;
  97. private TriangleTrackBar trackBar2;
  98. private TextBox textBox1;
  99. private Label label1;
  100. private TrackBar trackBar1;
  101. private GroupBox groupBox4;
  102. private Panel panel2;
  103. private RadioButton radioButton6;
  104. private RadioButton radioButton5;
  105. private TriangleTrackBar triangleTrackBar1;
  106. private Label label4;
  107. private Label label3;
  108. private Panel panel1;
  109. private RadioButton radioButton4;
  110. private RadioButton radioButton3;
  111. private RadioButton radioButton2;
  112. private RadioButton radioButton1;
  113. private Label label2;
  114. private NumericUpDown numericUpDown2;
  115. private NumericUpDown numericUpDown1;
  116. private Button button9;
  117. private GroupBox groupBox7;
  118. public GrainSizeGuideClass GuideClass
  119. {
  120. set
  121. {
  122. this.guideClass = value;
  123. }
  124. }
  125. public GrainBinaryBoundaryEditingDialog(AppWorkspace appWorkspace, int focusedItemIndex, Color phaseColor, Mat phaseMat)
  126. {
  127. this.appWorkspace = appWorkspace;
  128. InitializeComponent();
  129. InitializeLanguageText();
  130. //
  131. //初始化图像控件
  132. //
  133. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  134. this.documentWorkspace.Dock = DockStyle.Fill;
  135. this.documentWorkspace.HookMouseEvents();
  136. this.documentWorkspace.AuxiliaryLineEnabled = false;
  137. this.documentWorkspace.Visible = false;
  138. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  139. this.documentWorkspace.panel.Paint += Panel_Paint;
  140. this.documentWorkspace.panel.MouseMove += onMouseMove;
  141. this.documentWorkspace.panel.MouseUp += onMouseUp;
  142. this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);
  143. this.groupBox7.Controls.Add(documentWorkspace);
  144. //
  145. //初始化操作按钮
  146. //
  147. this.commonControlButtons = new CommonControlButtons();
  148. this.commonControlButtons.Dock = DockStyle.Top;
  149. this.commonControlButtons.Height = 30;
  150. this.commonControlButtons.HideZoomToWindowAndActualSize();
  151. this.groupBox7.Controls.Add(commonControlButtons);
  152. //获取
  153. Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
  154. this.phaseColor = phaseColor;
  155. {
  156. //
  157. //初始化相
  158. //
  159. PhaseModel model = new PhaseModel();
  160. model.choise = true;
  161. model.mat = null;
  162. model.color = phaseColor.ToArgb();// Color.Green/*panel2.BackColor*/.ToArgb();
  163. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  164. model.name = PdnResources.GetString("Menu.Binarization.text");
  165. this.documentWorkspace.PhaseModels.Add(model);
  166. }
  167. this.documentWorkspace.PhaseModels[0].mat = phaseMat;
  168. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  169. this.documentWorkspace.Refresh();
  170. existViewFlag = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList.IsExsitView();
  171. this.bitmap = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreateAliasedBitmap();
  172. if (!existViewFlag)
  173. {
  174. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
  175. }
  176. else
  177. {
  178. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GetFullSizeWithRegion());
  179. }
  180. Document document = Document.FromImage(bitmap);
  181. this.documentWorkspace.Document = document;
  182. this.documentWorkspace.Visible = true;
  183. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  184. InitCommonButtonEvent();
  185. }
  186. #region 矩形拖动
  187. /// <summary>
  188. /// 鼠标按下
  189. /// </summary>
  190. /// <param name="drawArea"></param>
  191. /// <param name="e"></param>
  192. private void OnMouseDown(object sender, MouseEventArgs e)
  193. {
  194. // 换算后的点
  195. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  196. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  197. && point1.X >= 0
  198. && point1.Y >= 0
  199. && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
  200. {
  201. if (e.Button == MouseButtons.Left/* && e.Clicks == 1*/&& this.pointKtype >= 1)
  202. {
  203. if (!drawedStartPoint)
  204. {
  205. drawedStartPoint = true;
  206. startPoint = new Point((int)point1.X, (int)point1.Y);
  207. return;
  208. }
  209. // 折线添加
  210. if (this.pointKtype == 1)
  211. {
  212. }
  213. // 直线添加
  214. else if (this.pointKtype == 2)
  215. {
  216. }
  217. // 多边形删除
  218. else if (this.pointKtype == 11)
  219. {
  220. }
  221. }
  222. }
  223. else if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
  224. {
  225. if (!drawedStartPoint)
  226. {
  227. drawedStartPoint = true;
  228. startPoint = new Point((int)point1.X, (int)point1.Y);
  229. return;
  230. }
  231. }
  232. else
  233. return;
  234. // 右键完成操作
  235. if (e.Button == MouseButtons.Right)
  236. {
  237. }
  238. }
  239. /// <summary>
  240. /// 移动
  241. /// </summary>
  242. /// <param name="sender"></param>
  243. /// <param name="e"></param>
  244. private void onMouseMove(object sender, MouseEventArgs e)
  245. {
  246. // 换算后的点
  247. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  248. if (e.Button == MouseButtons.Left)
  249. {
  250. // 椭圆删除/圆形删除
  251. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  252. {
  253. endPoint = new Point((int)point1.X, (int)point1.Y);
  254. if (this.startPoint.X < this.endPoint.X)
  255. {
  256. this.rectangle.X = this.startPoint.X;
  257. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  258. }
  259. else
  260. {
  261. this.rectangle.X = this.endPoint.X;
  262. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  263. }
  264. if (this.startPoint.Y < this.endPoint.Y)
  265. {
  266. this.rectangle.Y = this.startPoint.Y;
  267. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  268. }
  269. else
  270. {
  271. this.rectangle.Y = this.endPoint.Y;
  272. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  273. }
  274. this.documentWorkspace.Refresh();
  275. }
  276. // 矩形删除
  277. if (this.pointKtype == 13 && drawedStartPoint)
  278. {
  279. endPoint = new Point((int)point1.X, (int)point1.Y);
  280. if (this.startPoint.X < this.endPoint.X)
  281. {
  282. this.rectangle.X = this.startPoint.X;
  283. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  284. }
  285. else
  286. {
  287. this.rectangle.X = this.endPoint.X;
  288. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  289. }
  290. if (this.startPoint.Y < this.endPoint.Y)
  291. {
  292. this.rectangle.Y = this.startPoint.Y;
  293. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  294. }
  295. else
  296. {
  297. this.rectangle.Y = this.endPoint.Y;
  298. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  299. }
  300. this.documentWorkspace.Refresh();
  301. }
  302. // 直线添加
  303. if (this.pointKtype == 2 && drawedStartPoint)
  304. {
  305. endPoint = new Point((int)point1.X, (int)point1.Y);
  306. this.documentWorkspace.Refresh();
  307. }
  308. }
  309. }
  310. /// <summary>
  311. /// 鼠标抬起
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void onMouseUp(object sender, MouseEventArgs e)
  316. {
  317. // 换算后的点
  318. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  319. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  320. && point1.X >= 0
  321. && point1.Y >= 0
  322. && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { }
  323. else
  324. {
  325. if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
  326. {
  327. //if (point1.X >= this.documentWorkspace.CompositionSurface.Width)
  328. // point1.X = this.documentWorkspace.CompositionSurface.Width - 1;
  329. //if (point1.X < 0)
  330. // point1.X = 0;
  331. //if (point1.Y >= this.documentWorkspace.CompositionSurface.Height)
  332. // point1.Y = this.documentWorkspace.CompositionSurface.Height - 1;
  333. //if (point1.Y < 0)
  334. // point1.Y = 0;
  335. }
  336. else
  337. return;
  338. }
  339. if (e.Button == MouseButtons.Right)
  340. {
  341. // 折线删除
  342. if (this.pointKtype == 11 && pointArray.Count > 1)
  343. {
  344. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  345. endPoint = new Point((int)point1.X, (int)point1.Y);
  346. List<PointF> pointFArray = new List<PointF>();
  347. foreach (var item in pointArray)
  348. {
  349. pointFArray.Add(new PointF(item.X, item.Y));
  350. }
  351. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFArray);
  352. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  353. ////保存处理后的图片
  354. //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  355. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  356. //Graphics graphics = Graphics.FromImage(newBit);
  357. //Draw(graphics);
  358. //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  359. this.rectangle.X = -1;
  360. this.rectangle.Y = -1;
  361. this.rectangle.Width = 0;
  362. this.rectangle.Height = 0;
  363. pointArray.Clear();
  364. startPoint = new Point(-1, -1);
  365. drawedStartPoint = false;
  366. endPoint = new Point(-1, -1);
  367. this.pointKtype = 0;
  368. this.documentWorkspace.Refresh();
  369. }
  370. // 折线添加
  371. if (this.pointKtype == 1 && pointArray.Count > 1)
  372. {
  373. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  374. endPoint = new Point((int)point1.X, (int)point1.Y);
  375. //保存处理后的图片
  376. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  377. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  378. Graphics graphics = Graphics.FromImage(newBit);
  379. Draw(graphics, false);
  380. this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  381. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  382. pointArray.Clear();
  383. startPoint = new Point(-1, -1);
  384. drawedStartPoint = false;
  385. endPoint = new Point(-1, -1);
  386. this.pointKtype = 0;
  387. this.documentWorkspace.Refresh();
  388. }
  389. }
  390. if (e.Button == MouseButtons.Left)
  391. {
  392. // 圆形删除/椭圆删除
  393. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  394. {
  395. endPoint = new Point((int)point1.X, (int)point1.Y);
  396. if (this.startPoint.X < this.endPoint.X)
  397. {
  398. this.rectangle.X = this.startPoint.X;
  399. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  400. }
  401. else
  402. {
  403. this.rectangle.X = this.endPoint.X;
  404. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  405. }
  406. if (this.startPoint.Y < this.endPoint.Y)
  407. {
  408. this.rectangle.Y = this.startPoint.Y;
  409. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  410. }
  411. else
  412. {
  413. this.rectangle.Y = this.endPoint.Y;
  414. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  415. }
  416. if (this.pointKtype == 14)
  417. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  418. else
  419. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat
  420. , new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));
  421. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  422. this.rectangle.X = -1;
  423. this.rectangle.Y = -1;
  424. this.rectangle.Width = 0;
  425. this.rectangle.Height = 0;
  426. startPoint = new Point(-1, -1);
  427. drawedStartPoint = false;
  428. endPoint = new Point(-1, -1);
  429. this.pointKtype = 0;
  430. this.documentWorkspace.Refresh();
  431. }
  432. // 矩形删除
  433. if (this.pointKtype == 13 && drawedStartPoint)
  434. {
  435. endPoint = new Point((int)point1.X, (int)point1.Y);
  436. if (this.startPoint.X < this.endPoint.X)
  437. {
  438. this.rectangle.X = this.startPoint.X;
  439. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  440. }
  441. else
  442. {
  443. this.rectangle.X = this.endPoint.X;
  444. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  445. }
  446. if (this.startPoint.Y < this.endPoint.Y)
  447. {
  448. this.rectangle.Y = this.startPoint.Y;
  449. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  450. }
  451. else
  452. {
  453. this.rectangle.Y = this.endPoint.Y;
  454. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  455. }
  456. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  457. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  458. ////保存处理后的图片
  459. //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  460. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  461. //Graphics graphics = Graphics.FromImage(newBit);
  462. //Draw(graphics);
  463. //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  464. this.rectangle.X = -1;
  465. this.rectangle.Y = -1;
  466. this.rectangle.Width = 0;
  467. this.rectangle.Height = 0;
  468. startPoint = new Point(-1, -1);
  469. drawedStartPoint = false;
  470. endPoint = new Point(-1, -1);
  471. this.pointKtype = 0;
  472. this.documentWorkspace.Refresh();
  473. }
  474. // 折线添加/折线删除
  475. if (this.pointKtype == 1 || this.pointKtype == 11)
  476. {
  477. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  478. if (!drawedStartPoint)
  479. {
  480. drawedStartPoint = true;
  481. startPoint = new Point((int)point1.X, (int)point1.Y);
  482. }
  483. this.documentWorkspace.Refresh();
  484. }
  485. // 直线添加
  486. if (this.pointKtype == 2 && drawedStartPoint)
  487. {
  488. endPoint = new Point((int)point1.X, (int)point1.Y);
  489. //保存处理后的图片
  490. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  491. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  492. Graphics graphics = Graphics.FromImage(newBit);
  493. Draw(graphics, false);
  494. this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  495. this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  496. startPoint = new Point(-1, -1);
  497. drawedStartPoint = false;
  498. endPoint = new Point(-1, -1);
  499. this.pointKtype = 0;
  500. this.documentWorkspace.Refresh();
  501. }
  502. }
  503. }
  504. #endregion
  505. /// <summary>
  506. /// surfaceBox双击事件
  507. /// 目前是参考AxioVision
  508. /// 应该是把每次选的点都取最高和最低的BGR
  509. /// </summary>
  510. /// <param name="sender"></param>
  511. /// <param name="e"></param>
  512. private unsafe void pictureBox1_Click(object sender, EventArgs e)
  513. {
  514. }
  515. /// <summary>
  516. /// 画布绘制
  517. /// </summary>
  518. /// <param name="sender"></param>
  519. /// <param name="e"></param>
  520. private void Panel_Paint(object sender, PaintEventArgs e)
  521. {
  522. if (this.documentWorkspace.CompositionSurface != null)
  523. {
  524. //
  525. // 以下是计算绘制图片的位置和大小并绘制图片
  526. //
  527. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  528. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  529. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  530. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  531. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  532. //
  533. // 以下是绘制网格、标注、测量、视场等开始
  534. //
  535. e.Graphics.TranslateTransform(x, y);
  536. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  537. //if (this.checkBox4_0.Checked)//显示网格
  538. Draw(e.Graphics, true);
  539. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  540. e.Graphics.TranslateTransform(-x, -y);
  541. }
  542. }
  543. /// <summary>
  544. /// 绘制
  545. /// </summary>
  546. private void Draw(Graphics g, bool DrawGuideLines)
  547. {
  548. // 抗锯齿
  549. g.SmoothingMode = SmoothingMode.AntiAlias;
  550. if (DrawGuideLines)
  551. {
  552. if (guideClass != null && guideClass.GrainSizeGuideAreaMethodModel != null)
  553. guideClass.DrawAreaGuide(g, SelectedItem);
  554. else if (guideClass != null && guideClass.GrainSizeGuideStyleModel != null)
  555. guideClass.DrawGuideLines(g, SelectedItem);
  556. }
  557. //圆形删除/椭圆删除
  558. if ((this.pointKtype == 14 || this.pointKtype == 12) && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  559. {
  560. Pen pen = new Pen(this.phaseColor, 1);
  561. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  562. if (this.pointKtype == 14)
  563. g.DrawEllipse(pen, this.rectangle);
  564. else
  565. 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)));
  566. pen.Dispose();
  567. }
  568. //矩形删除
  569. if (this.pointKtype == 13 && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  570. {
  571. Pen pen = new Pen(this.phaseColor, 1);
  572. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  573. g.DrawRectangle(pen, new Rectangle((int)this.rectangle.X, (int)this.rectangle.Y, (int)this.rectangle.Width, (int)this.rectangle.Height));
  574. pen.Dispose();
  575. }
  576. // 折线删除
  577. if (this.pointKtype == 11 && pointArray.Count >= 2)
  578. {
  579. Pen pen = new Pen(this.phaseColor, 1);
  580. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  581. g.DrawPolygon(pen, pointArray.ToArray());
  582. pen.Dispose();
  583. }
  584. // 直线添加
  585. if (this.pointKtype == 2 && drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1)
  586. {
  587. Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
  588. //pen.DashStyle = DashStyle.Dash;
  589. g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
  590. pen.Dispose();
  591. }
  592. // 折线添加
  593. if (this.pointKtype == 1 && pointArray.Count >= 2)
  594. {
  595. Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
  596. g.DrawLines(pen, pointArray.ToArray());
  597. pen.Dispose();
  598. }
  599. //// 以下为绘制样式
  600. //Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
  601. //Pen pointPen1 = new Pen(Color.Yellow, this.pointWidth1);
  602. //Pen pointPen2 = new Pen(Color.FromArgb(this.pointColor2), this.pointWidth2);
  603. //Pen pointPen3 = new Pen(Color.FromArgb(this.pointColor3), this.pointWidth3);
  604. //SolidBrush brush1 = new SolidBrush(Color.FromArgb(this.pointColor1));
  605. //SolidBrush brush2 = new SolidBrush(Color.FromArgb(this.pointColor2));
  606. //SolidBrush brush3 = new SolidBrush(Color.FromArgb(this.pointColor3));
  607. //// 圆形
  608. //if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
  609. //{
  610. // foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
  611. // {
  612. // if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
  613. // {
  614. // graphics.DrawEllipse(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
  615. // }
  616. // }
  617. //}
  618. //// 矩形
  619. //if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
  620. //{
  621. // foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
  622. // {
  623. // if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
  624. // {
  625. // graphics.DrawRectangle(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
  626. // }
  627. // }
  628. //}
  629. //if (this.checkBox5_0.Checked && massLabelPoints.Count > 0)
  630. //{
  631. // int index = 0;
  632. // Font myFont = new Font("宋体", 12/*, FontStyle.Bold*/);
  633. // Brush bush = new SolidBrush(this.panel1.BackColor/*Color.Red*/);//填充的颜色
  634. // foreach (var item in massLabelPoints)
  635. // {
  636. // graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5);
  637. // }
  638. //}
  639. }
  640. private void InitializeLanguageText()
  641. {
  642. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  643. this.button9.Text = PdnResources.GetString("CommonAction.Undo");
  644. this.button2.Text = PdnResources.GetString("Menu.File.Close.Text");
  645. this.button1.Text = PdnResources.GetString("Form.OkButton.Text");
  646. this.groupBox2.Text = PdnResources.GetString("Menu.BinaryAction.Text");
  647. this.button8.Text = PdnResources.GetString("Menu.Ellipsedelete.text");
  648. this.button7.Text = PdnResources.GetString("Menu.BinaryAction.RectangleDelete.Text");
  649. this.button6.Text = PdnResources.GetString("Menu.rounddelete.text");
  650. this.button5.Text = PdnResources.GetString("Menu.BinaryAction.PolygonleDelete.Text");
  651. this.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  652. this.button4.Text = PdnResources.GetString("Menu.Lineadd.text");
  653. this.button3.Text = PdnResources.GetString("Menu.Polylineadd.text");
  654. this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
  655. this.groupBox4.Text = PdnResources.GetString("Menu.Particlescreening.text");
  656. this.radioButton6.Text = PdnResources.GetString("Menu.Pixel.text");
  657. this.radioButton5.Text = PdnResources.GetString("Menu.Micron.text");
  658. this.label4.Text = PdnResources.GetString("Menu.filterunit.text") + ":";
  659. this.label3.Text = PdnResources.GetString("Menu.range.text") + ":";
  660. this.radioButton4.Text = PdnResources.GetString("Menu.Aspectratio.text");
  661. this.radioButton3.Text = PdnResources.GetString("Menu.Maximumcaliperdiameter.text");
  662. this.radioButton2.Text = PdnResources.GetString("Menu.Arearatio.text");
  663. this.radioButton1.Text = PdnResources.GetString("Menu.area.text");
  664. this.label2.Text = PdnResources.GetString("Menu.Filterparams.text") + ":";
  665. this.Text = PdnResources.GetString("Menu.filter.text");
  666. }
  667. private void InitializeComponent()
  668. {
  669. this.groupBox1 = new System.Windows.Forms.GroupBox();
  670. this.button9 = new System.Windows.Forms.Button();
  671. this.button2 = new System.Windows.Forms.Button();
  672. this.button1 = new System.Windows.Forms.Button();
  673. this.groupBox2 = new System.Windows.Forms.GroupBox();
  674. this.button8 = new System.Windows.Forms.Button();
  675. this.trackBar1 = new System.Windows.Forms.TrackBar();
  676. this.button7 = new System.Windows.Forms.Button();
  677. this.trackBar2 = new PaintDotNet.CustomControl.TriangleTrackBar();
  678. this.button6 = new System.Windows.Forms.Button();
  679. this.textBox1 = new System.Windows.Forms.TextBox();
  680. this.button5 = new System.Windows.Forms.Button();
  681. this.label1 = new System.Windows.Forms.Label();
  682. this.button4 = new System.Windows.Forms.Button();
  683. this.button3 = new System.Windows.Forms.Button();
  684. this.groupBox7 = new System.Windows.Forms.GroupBox();
  685. this.groupBox4 = new System.Windows.Forms.GroupBox();
  686. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  687. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  688. this.panel2 = new System.Windows.Forms.Panel();
  689. this.radioButton6 = new System.Windows.Forms.RadioButton();
  690. this.radioButton5 = new System.Windows.Forms.RadioButton();
  691. this.triangleTrackBar1 = new PaintDotNet.CustomControl.TriangleTrackBar();
  692. this.label4 = new System.Windows.Forms.Label();
  693. this.label3 = new System.Windows.Forms.Label();
  694. this.panel1 = new System.Windows.Forms.Panel();
  695. this.radioButton4 = new System.Windows.Forms.RadioButton();
  696. this.radioButton3 = new System.Windows.Forms.RadioButton();
  697. this.radioButton2 = new System.Windows.Forms.RadioButton();
  698. this.radioButton1 = new System.Windows.Forms.RadioButton();
  699. this.label2 = new System.Windows.Forms.Label();
  700. this.groupBox1.SuspendLayout();
  701. this.groupBox2.SuspendLayout();
  702. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
  703. this.groupBox4.SuspendLayout();
  704. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  705. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  706. this.panel2.SuspendLayout();
  707. this.panel1.SuspendLayout();
  708. this.SuspendLayout();
  709. //
  710. // groupBox1
  711. //
  712. this.groupBox1.Controls.Add(this.button9);
  713. this.groupBox1.Controls.Add(this.button2);
  714. this.groupBox1.Controls.Add(this.button1);
  715. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  716. this.groupBox1.Name = "groupBox1";
  717. this.groupBox1.Size = new System.Drawing.Size(808, 45);
  718. this.groupBox1.TabIndex = 0;
  719. this.groupBox1.TabStop = false;
  720. //
  721. // button9
  722. //
  723. this.button9.Location = new System.Drawing.Point(468, 13);
  724. this.button9.Name = "button9";
  725. this.button9.Size = new System.Drawing.Size(91, 26);
  726. this.button9.TabIndex = 3;
  727. this.button9.UseVisualStyleBackColor = true;
  728. this.button9.Visible = false;
  729. //
  730. // button2
  731. //
  732. this.button2.Location = new System.Drawing.Point(694, 13);
  733. this.button2.Name = "button2";
  734. this.button2.Size = new System.Drawing.Size(91, 26);
  735. this.button2.TabIndex = 1;
  736. this.button2.UseVisualStyleBackColor = true;
  737. this.button2.Click += new System.EventHandler(this.button2_Click);
  738. //
  739. // button1
  740. //
  741. this.button1.Location = new System.Drawing.Point(582, 13);
  742. this.button1.Name = "button1";
  743. this.button1.Size = new System.Drawing.Size(91, 26);
  744. this.button1.TabIndex = 0;
  745. this.button1.UseVisualStyleBackColor = true;
  746. this.button1.Click += new System.EventHandler(this.button1_Click);
  747. //
  748. // groupBox2
  749. //
  750. this.groupBox2.Controls.Add(this.button8);
  751. this.groupBox2.Controls.Add(this.trackBar1);
  752. this.groupBox2.Controls.Add(this.button7);
  753. this.groupBox2.Controls.Add(this.trackBar2);
  754. this.groupBox2.Controls.Add(this.button6);
  755. this.groupBox2.Controls.Add(this.textBox1);
  756. this.groupBox2.Controls.Add(this.button5);
  757. this.groupBox2.Controls.Add(this.label1);
  758. this.groupBox2.Controls.Add(this.button4);
  759. this.groupBox2.Controls.Add(this.button3);
  760. this.groupBox2.Location = new System.Drawing.Point(12, 63);
  761. this.groupBox2.Name = "groupBox2";
  762. this.groupBox2.Size = new System.Drawing.Size(233, 199);
  763. this.groupBox2.TabIndex = 1;
  764. this.groupBox2.TabStop = false;
  765. //
  766. // button8
  767. //
  768. this.button8.Location = new System.Drawing.Point(134, 151);
  769. this.button8.Name = "button8";
  770. this.button8.Size = new System.Drawing.Size(73, 26);
  771. this.button8.TabIndex = 7;
  772. this.button8.UseVisualStyleBackColor = true;
  773. this.button8.Click += new System.EventHandler(this.button8_Click);
  774. //
  775. // trackBar1
  776. //
  777. this.trackBar1.AutoSize = false;
  778. this.trackBar1.Location = new System.Drawing.Point(107, 69);
  779. this.trackBar1.Maximum = 50;
  780. this.trackBar1.Minimum = 1;
  781. this.trackBar1.Name = "trackBar1";
  782. this.trackBar1.Size = new System.Drawing.Size(104, 31);
  783. this.trackBar1.TabIndex = 21;
  784. this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
  785. this.trackBar1.Value = 1;
  786. this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
  787. //
  788. // button7
  789. //
  790. this.button7.Location = new System.Drawing.Point(27, 151);
  791. this.button7.Name = "button7";
  792. this.button7.Size = new System.Drawing.Size(73, 26);
  793. this.button7.TabIndex = 6;
  794. this.button7.UseVisualStyleBackColor = true;
  795. this.button7.Click += new System.EventHandler(this.button7_Click);
  796. //
  797. // trackBar2
  798. //
  799. this.trackBar2.Location = new System.Drawing.Point(108, 69);
  800. this.trackBar2.Maximum = 50;
  801. this.trackBar2.Minimum = 1;
  802. this.trackBar2.Name = "trackBar2";
  803. this.trackBar2.Size = new System.Drawing.Size(102, 24);
  804. this.trackBar2.TabIndex = 20;
  805. this.trackBar2.Value = 1;
  806. this.trackBar2.Visible = false;
  807. //
  808. // button6
  809. //
  810. this.button6.Location = new System.Drawing.Point(134, 107);
  811. this.button6.Name = "button6";
  812. this.button6.Size = new System.Drawing.Size(73, 26);
  813. this.button6.TabIndex = 5;
  814. this.button6.UseVisualStyleBackColor = true;
  815. this.button6.Click += new System.EventHandler(this.button6_Click);
  816. //
  817. // textBox1
  818. //
  819. this.textBox1.Location = new System.Drawing.Point(68, 69);
  820. this.textBox1.Name = "textBox1";
  821. this.textBox1.Size = new System.Drawing.Size(32, 21);
  822. this.textBox1.TabIndex = 19;
  823. this.textBox1.Text = "1";
  824. this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  825. //
  826. // button5
  827. //
  828. this.button5.Location = new System.Drawing.Point(27, 107);
  829. this.button5.Name = "button5";
  830. this.button5.Size = new System.Drawing.Size(73, 26);
  831. this.button5.TabIndex = 4;
  832. this.button5.UseVisualStyleBackColor = true;
  833. this.button5.Click += new System.EventHandler(this.button5_Click);
  834. //
  835. // label1
  836. //
  837. this.label1.AutoSize = true;
  838. this.label1.Location = new System.Drawing.Point(28, 73);
  839. this.label1.Name = "label1";
  840. this.label1.Size = new System.Drawing.Size(41, 12);
  841. this.label1.TabIndex = 18;
  842. //
  843. // button4
  844. //
  845. this.button4.Location = new System.Drawing.Point(135, 31);
  846. this.button4.Name = "button4";
  847. this.button4.Size = new System.Drawing.Size(73, 26);
  848. this.button4.TabIndex = 3;
  849. this.button4.UseVisualStyleBackColor = true;
  850. this.button4.Click += new System.EventHandler(this.button4_Click);
  851. //
  852. // button3
  853. //
  854. this.button3.Location = new System.Drawing.Point(28, 31);
  855. this.button3.Name = "button3";
  856. this.button3.Size = new System.Drawing.Size(73, 26);
  857. this.button3.TabIndex = 2;
  858. this.button3.UseVisualStyleBackColor = true;
  859. this.button3.Click += new System.EventHandler(this.button3_Click);
  860. //
  861. // groupBox7
  862. //
  863. this.groupBox7.Location = new System.Drawing.Point(251, 63);
  864. this.groupBox7.Name = "groupBox7";
  865. this.groupBox7.Size = new System.Drawing.Size(569, 502);
  866. this.groupBox7.TabIndex = 1;
  867. this.groupBox7.TabStop = false;
  868. //
  869. // groupBox4
  870. //
  871. this.groupBox4.Controls.Add(this.numericUpDown2);
  872. this.groupBox4.Controls.Add(this.numericUpDown1);
  873. this.groupBox4.Controls.Add(this.panel2);
  874. this.groupBox4.Controls.Add(this.triangleTrackBar1);
  875. this.groupBox4.Controls.Add(this.label4);
  876. this.groupBox4.Controls.Add(this.label3);
  877. this.groupBox4.Controls.Add(this.panel1);
  878. this.groupBox4.Controls.Add(this.label2);
  879. this.groupBox4.Location = new System.Drawing.Point(12, 287);
  880. this.groupBox4.Name = "groupBox4";
  881. this.groupBox4.Size = new System.Drawing.Size(233, 278);
  882. this.groupBox4.TabIndex = 2;
  883. this.groupBox4.TabStop = false;
  884. //
  885. // numericUpDown2
  886. //
  887. this.numericUpDown2.Location = new System.Drawing.Point(131, 164);
  888. this.numericUpDown2.DecimalPlaces = 2;
  889. this.numericUpDown2.Increment = 0.01M;
  890. this.numericUpDown2.Maximum = new decimal(new int[] {//1009###19003 //##to test
  891. int.MaxValue,
  892. 0,
  893. 0,
  894. 0});
  895. this.numericUpDown2.Name = "numericUpDown2";
  896. this.numericUpDown2.Size = new System.Drawing.Size(60, 21);
  897. this.numericUpDown2.TabIndex = 21;
  898. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
  899. //
  900. // numericUpDown1
  901. //
  902. this.numericUpDown1.Location = new System.Drawing.Point(66, 164);
  903. this.numericUpDown1.DecimalPlaces = 2;
  904. this.numericUpDown1.Increment = 0.01M;
  905. this.numericUpDown1.Maximum = new decimal(new int[] {
  906. int.MaxValue,
  907. 0,
  908. 0,
  909. 0});
  910. this.numericUpDown1.Name = "numericUpDown1";
  911. this.numericUpDown1.Size = new System.Drawing.Size(60, 21);
  912. this.numericUpDown1.TabIndex = 20;
  913. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
  914. //
  915. // panel2
  916. //
  917. this.panel2.Controls.Add(this.radioButton6);
  918. this.panel2.Controls.Add(this.radioButton5);
  919. this.panel2.Location = new System.Drawing.Point(66, 201);
  920. this.panel2.Name = "panel2";
  921. this.panel2.Size = new System.Drawing.Size(127, 30);
  922. this.panel2.TabIndex = 19;
  923. //
  924. // radioButton6
  925. //
  926. this.radioButton6.AutoSize = true;
  927. this.radioButton6.Location = new System.Drawing.Point(60, 7);
  928. this.radioButton6.Name = "radioButton6";
  929. this.radioButton6.Size = new System.Drawing.Size(47, 16);
  930. this.radioButton6.TabIndex = 2;
  931. this.radioButton6.TabStop = true;
  932. this.radioButton6.UseVisualStyleBackColor = true;
  933. this.radioButton6.CheckedChanged += new System.EventHandler(this.radioButton6_CheckedChanged);
  934. //
  935. // radioButton5
  936. //
  937. this.radioButton5.AutoSize = true;
  938. this.radioButton5.Checked = true;
  939. this.radioButton5.Location = new System.Drawing.Point(7, 7);
  940. this.radioButton5.Name = "radioButton5";
  941. this.radioButton5.Size = new System.Drawing.Size(47, 16);
  942. this.radioButton5.TabIndex = 1;
  943. this.radioButton5.TabStop = true;
  944. this.radioButton5.UseVisualStyleBackColor = true;
  945. this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
  946. //
  947. // triangleTrackBar1
  948. //
  949. this.triangleTrackBar1.Location = new System.Drawing.Point(66, 164);
  950. this.triangleTrackBar1.Maximum = 10000;
  951. this.triangleTrackBar1.Minimum = 0;
  952. this.triangleTrackBar1.Name = "triangleTrackBar1";
  953. this.triangleTrackBar1.Size = new System.Drawing.Size(102, 24);
  954. this.triangleTrackBar1.TabIndex = 18;
  955. this.triangleTrackBar1.Value = 0;
  956. this.triangleTrackBar1.Visible = false;
  957. //
  958. // label4
  959. //
  960. this.label4.AutoSize = true;
  961. this.label4.Location = new System.Drawing.Point(9, 208);
  962. this.label4.Name = "label4";
  963. this.label4.Size = new System.Drawing.Size(65, 12);
  964. this.label4.TabIndex = 3;
  965. //
  966. // label3
  967. //
  968. this.label3.AutoSize = true;
  969. this.label3.Location = new System.Drawing.Point(33, 168);
  970. this.label3.Name = "label3";
  971. this.label3.Size = new System.Drawing.Size(41, 12);
  972. this.label3.TabIndex = 2;
  973. //
  974. // panel1
  975. //
  976. this.panel1.Controls.Add(this.radioButton4);
  977. this.panel1.Controls.Add(this.radioButton3);
  978. this.panel1.Controls.Add(this.radioButton2);
  979. this.panel1.Controls.Add(this.radioButton1);
  980. this.panel1.Location = new System.Drawing.Point(66, 28);
  981. this.panel1.Name = "panel1";
  982. this.panel1.Size = new System.Drawing.Size(121, 122);
  983. this.panel1.TabIndex = 1;
  984. //
  985. // radioButton4
  986. //
  987. this.radioButton4.AutoSize = true;
  988. this.radioButton4.Location = new System.Drawing.Point(13, 97);
  989. this.radioButton4.Name = "radioButton4";
  990. this.radioButton4.Size = new System.Drawing.Size(59, 16);
  991. this.radioButton4.TabIndex = 3;
  992. this.radioButton4.TabStop = true;
  993. this.radioButton4.UseVisualStyleBackColor = true;
  994. this.radioButton4.CheckedChanged += new System.EventHandler(this.radioButton4_CheckedChanged);
  995. //
  996. // radioButton3
  997. //
  998. this.radioButton3.AutoSize = true;
  999. this.radioButton3.Location = new System.Drawing.Point(13, 67);
  1000. this.radioButton3.Name = "radioButton3";
  1001. this.radioButton3.Size = new System.Drawing.Size(95, 16);
  1002. this.radioButton3.TabIndex = 2;
  1003. this.radioButton3.TabStop = true;
  1004. this.radioButton3.UseVisualStyleBackColor = true;
  1005. this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
  1006. //
  1007. // radioButton2
  1008. //
  1009. this.radioButton2.AutoSize = true;
  1010. this.radioButton2.Location = new System.Drawing.Point(13, 37);
  1011. this.radioButton2.Name = "radioButton2";
  1012. this.radioButton2.Size = new System.Drawing.Size(59, 16);
  1013. this.radioButton2.TabIndex = 1;
  1014. this.radioButton2.TabStop = true;
  1015. this.radioButton2.UseVisualStyleBackColor = true;
  1016. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
  1017. //
  1018. // radioButton1
  1019. //
  1020. this.radioButton1.AutoSize = true;
  1021. this.radioButton1.Checked = true;
  1022. this.radioButton1.Location = new System.Drawing.Point(13, 7);
  1023. this.radioButton1.Name = "radioButton1";
  1024. this.radioButton1.Size = new System.Drawing.Size(47, 16);
  1025. this.radioButton1.TabIndex = 0;
  1026. this.radioButton1.TabStop = true;
  1027. this.radioButton1.UseVisualStyleBackColor = true;
  1028. this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  1029. //
  1030. // label2
  1031. //
  1032. this.label2.AutoSize = true;
  1033. this.label2.Location = new System.Drawing.Point(9, 35);
  1034. this.label2.Name = "label2";
  1035. this.label2.Size = new System.Drawing.Size(65, 12);
  1036. this.label2.TabIndex = 0;
  1037. //
  1038. // GrainBinaryBoundaryEditingDialog
  1039. //
  1040. this.ClientSize = new System.Drawing.Size(832, 577);
  1041. this.Controls.Add(this.groupBox4);
  1042. this.Controls.Add(this.groupBox2);
  1043. this.Controls.Add(this.groupBox7);
  1044. this.Controls.Add(this.groupBox1);
  1045. this.MaximizeBox = false;
  1046. this.MinimizeBox = false;
  1047. this.Name = "GrainBinaryBoundaryEditingDialog";
  1048. this.groupBox1.ResumeLayout(false);
  1049. this.groupBox2.ResumeLayout(false);
  1050. this.groupBox2.PerformLayout();
  1051. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
  1052. this.groupBox4.ResumeLayout(false);
  1053. this.groupBox4.PerformLayout();
  1054. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  1055. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  1056. this.panel2.ResumeLayout(false);
  1057. this.panel2.PerformLayout();
  1058. this.panel1.ResumeLayout(false);
  1059. this.panel1.PerformLayout();
  1060. this.ResumeLayout(false);
  1061. }
  1062. /// <summary>
  1063. /// 折线添加
  1064. /// </summary>
  1065. /// <param name="sender"></param>
  1066. /// <param name="e"></param>
  1067. private void button3_Click(object sender, EventArgs e)
  1068. {
  1069. pointArray.Clear();
  1070. startPoint = new Point(-1, -1);
  1071. drawedStartPoint = false;
  1072. endPoint = new Point(-1, -1);
  1073. pointKtype = 1;
  1074. this.documentWorkspace.Refresh();
  1075. }
  1076. /// <summary>
  1077. /// 直线添加
  1078. /// </summary>
  1079. /// <param name="sender"></param>
  1080. /// <param name="e"></param>
  1081. private void button4_Click(object sender, EventArgs e)
  1082. {
  1083. startPoint = new Point(-1, -1);
  1084. drawedStartPoint = false;
  1085. endPoint = new Point(-1, -1);
  1086. pointKtype = 2;
  1087. this.documentWorkspace.Refresh();
  1088. }
  1089. private void InitCommonButtonEvent()
  1090. {
  1091. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  1092. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  1093. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  1094. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  1095. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  1096. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  1097. }
  1098. private void zoomInButton_Click(object sender, EventArgs e)
  1099. {
  1100. this.documentWorkspace.ZoomIn();
  1101. }
  1102. private void zoomOutButton_Click(object sender, EventArgs e)
  1103. {
  1104. this.documentWorkspace.ZoomOut();
  1105. }
  1106. private void zoomToWindowButton_Click(object sender, EventArgs e)
  1107. {
  1108. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1109. }
  1110. private void actualSizeButton_Click(object sender, EventArgs e)
  1111. {
  1112. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1113. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  1114. }
  1115. private void pointerButton_Click(object sender, EventArgs e)
  1116. {
  1117. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  1118. }
  1119. private void mobileModeButton_Click(object sender, EventArgs e)
  1120. {
  1121. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  1122. }
  1123. //确定按钮点击事件
  1124. private void button1_Click(object sender, EventArgs e)
  1125. {
  1126. this.phaseMatCopy = this.documentWorkspace.PhaseModels[0].mat;
  1127. this.DialogResult = DialogResult.OK;
  1128. this.Close();
  1129. }
  1130. /// <summary>
  1131. /// 用于get处理后的图像
  1132. /// </summary>
  1133. public Mat PhaseMat
  1134. {
  1135. get
  1136. {
  1137. return this.phaseMatCopy;
  1138. }
  1139. set
  1140. {
  1141. this.phaseMatCopy = value;
  1142. }
  1143. }
  1144. /// <summary>
  1145. /// 矩形删除
  1146. /// </summary>
  1147. /// <param name="sender"></param>
  1148. /// <param name="e"></param>
  1149. private void button7_Click(object sender, EventArgs e)
  1150. {
  1151. startPoint = new Point(-1, -1);
  1152. drawedStartPoint = false;
  1153. endPoint = new Point(-1, -1);
  1154. this.rectangle.X = -1;
  1155. this.rectangle.Y = -1;
  1156. this.rectangle.Width = 0;
  1157. this.rectangle.Height = 0;
  1158. this.pointKtype = 13;
  1159. this.documentWorkspace.Refresh();
  1160. }
  1161. /// <summary>
  1162. /// 椭圆删除
  1163. /// </summary>
  1164. /// <param name="sender"></param>
  1165. /// <param name="e"></param>
  1166. private void button8_Click(object sender, EventArgs e)
  1167. {
  1168. startPoint = new Point(-1, -1);
  1169. drawedStartPoint = false;
  1170. endPoint = new Point(-1, -1);
  1171. this.rectangle.X = -1;
  1172. this.rectangle.Y = -1;
  1173. this.rectangle.Width = 0;
  1174. this.rectangle.Height = 0;
  1175. this.pointKtype = 14;
  1176. this.documentWorkspace.Refresh();
  1177. }
  1178. /// <summary>
  1179. /// 圆形删除
  1180. /// </summary>
  1181. /// <param name="sender"></param>
  1182. /// <param name="e"></param>
  1183. private void button6_Click(object sender, EventArgs e)
  1184. {
  1185. startPoint = new Point(-1, -1);
  1186. drawedStartPoint = false;
  1187. endPoint = new Point(-1, -1);
  1188. this.rectangle.X = -1;
  1189. this.rectangle.Y = -1;
  1190. this.rectangle.Width = 0;
  1191. this.rectangle.Height = 0;
  1192. this.pointKtype = 12;
  1193. this.documentWorkspace.Refresh();
  1194. }
  1195. /// <summary>
  1196. /// 多边形删除
  1197. /// </summary>
  1198. /// <param name="sender"></param>
  1199. /// <param name="e"></param>
  1200. private void button5_Click(object sender, EventArgs e)
  1201. {
  1202. pointArray.Clear();
  1203. startPoint = new Point(-1, -1);
  1204. drawedStartPoint = false;
  1205. endPoint = new Point(-1, -1);
  1206. this.rectangle.X = -1;
  1207. this.rectangle.Y = -1;
  1208. this.rectangle.Width = 0;
  1209. this.rectangle.Height = 0;
  1210. this.pointKtype = 11;
  1211. this.documentWorkspace.Refresh();
  1212. }
  1213. private void button2_Click(object sender, EventArgs e)
  1214. {
  1215. this.Close();
  1216. }
  1217. /// <summary>
  1218. /// 线宽改变
  1219. /// </summary>
  1220. /// <param name="sender"></param>
  1221. /// <param name="e"></param>
  1222. private void textBox1_TextChanged(object sender, EventArgs e)
  1223. {
  1224. int valueT;
  1225. if (!int.TryParse(textBox1.Text, out valueT))
  1226. return;
  1227. if (this.trackBar1.Minimum > valueT)
  1228. valueT = this.trackBar1.Minimum;
  1229. if (this.trackBar1.Maximum < valueT)
  1230. valueT = this.trackBar1.Maximum;
  1231. this.trackBar1.Value = valueT;
  1232. //this.textBox1.Text = valueT + "";
  1233. }
  1234. private void trackBar1_Scroll(object sender, EventArgs e)
  1235. {
  1236. this.textBox1.Text = this.trackBar1.Value + "";
  1237. }
  1238. /// <summary>
  1239. /// 范围改变
  1240. /// </summary>
  1241. /// <param name="sender"></param>
  1242. /// <param name="e"></param>
  1243. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  1244. {
  1245. this.applyChangedAction();
  1246. }
  1247. /// <summary>
  1248. /// 范围改变
  1249. /// </summary>
  1250. /// <param name="sender"></param>
  1251. /// <param name="e"></param>
  1252. private void numericUpDown2_ValueChanged(object sender, EventArgs e)
  1253. {
  1254. this.applyChangedAction();
  1255. }
  1256. /// <summary>
  1257. /// 筛选单位改变
  1258. /// </summary>
  1259. /// <param name="sender"></param>
  1260. /// <param name="e"></param>
  1261. private void radioButton5_CheckedChanged(object sender, EventArgs e)
  1262. {
  1263. this.applyChangedAction();
  1264. }
  1265. private void radioButton6_CheckedChanged(object sender, EventArgs e)
  1266. {
  1267. this.applyChangedAction();
  1268. }
  1269. /// <summary>
  1270. /// 筛选参数改变
  1271. /// </summary>
  1272. /// <param name="sender"></param>
  1273. /// <param name="e"></param>
  1274. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  1275. {
  1276. this.applyChangedAction();
  1277. }
  1278. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  1279. {
  1280. this.applyChangedAction();
  1281. }
  1282. private void radioButton3_CheckedChanged(object sender, EventArgs e)
  1283. {
  1284. this.applyChangedAction();
  1285. }
  1286. private void radioButton4_CheckedChanged(object sender, EventArgs e)
  1287. {
  1288. this.applyChangedAction();
  1289. }
  1290. private void applyChangedAction()
  1291. {
  1292. foreach (Base.Args args in action.Lists)
  1293. {
  1294. switch (args.Key)
  1295. {
  1296. case "FilterParameters"://筛选参数
  1297. {
  1298. if (radioButton1.Checked)
  1299. args.Value = Base.Enum.FilterParameters.Area;
  1300. else if (radioButton2.Checked)
  1301. args.Value = Base.Enum.FilterParameters.AreaRatio;
  1302. else if (radioButton3.Checked)
  1303. args.Value = Base.Enum.FilterParameters.LongTrail;
  1304. else if (radioButton4.Checked)
  1305. args.Value = Base.Enum.FilterParameters.AspectRatio;
  1306. }
  1307. break;
  1308. case "UnitParameters"://筛选单位
  1309. {
  1310. if (radioButton5.Checked)
  1311. args.Value = MeasurementUnit.Micron;
  1312. else if (radioButton6.Checked)
  1313. args.Value = MeasurementUnit.Pixel;
  1314. }
  1315. break;
  1316. case "Scope"://数值范围
  1317. {
  1318. List<double> oneL = new List<double>();
  1319. oneL.Add((double)this.numericUpDown1.Value);
  1320. oneL.Add((double)this.numericUpDown2.Value);
  1321. args.Value = oneL;
  1322. }
  1323. break;
  1324. default:
  1325. break;
  1326. }
  1327. }
  1328. this.applyButtonImpl(null, null);
  1329. }
  1330. /// <summary>
  1331. /// 应用
  1332. /// </summary>
  1333. /// <param name="sender"></param>
  1334. /// <param name="e"></param>
  1335. private void applyButtonImpl(object sender, EventArgs e)
  1336. {
  1337. //如果有选中的相
  1338. List<PhaseModel> phases = this.documentWorkspace.PhaseModels;
  1339. if (phases.Count > 0)
  1340. {
  1341. List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  1342. for (int i = 0; i < phases.Count; i++)
  1343. {
  1344. PhaseModel model = new PhaseModel();
  1345. model.choise = phases[i].choise;
  1346. model.color = phaseColor.ToArgb();// phases[i].color;
  1347. model.name = phases[i].name;
  1348. model.position = phases[i].position;
  1349. model.mat = new OpenCvSharp.Mat();
  1350. phaseMatCopy.CopyTo(model.mat);
  1351. //phases[i].mat.CopyTo(model.mat);//避免碎屑删除不可逆的问题
  1352. phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
  1353. this.documentWorkspace.Refresh();
  1354. }
  1355. }
  1356. else
  1357. {
  1358. OpenCvSharp.Mat mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
  1359. Document doc = Document.FromMat(mat);
  1360. this.documentWorkspace.Document = doc;
  1361. this.documentWorkspace.Refresh();
  1362. }
  1363. }
  1364. }
  1365. }