TABM2Dialog.cs 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  1. using Metis.ParameterSet;
  2. using OpenCvSharp;
  3. using PaintDotNet.Base.CommTool;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Windows.Forms;
  10. namespace PaintDotNet.DedicatedAnalysis.NonferrousMetals.YYT098814_2016
  11. {
  12. internal class TABM2Dialog : NonFMetalsStandardDialog
  13. {
  14. #region 属性
  15. /// <summary>
  16. /// 是否调用了灰度化的算法
  17. /// </summary>
  18. private bool grayBitmap = false;
  19. /// <summary>
  20. /// 记录鼠标最后所在的点的y坐标
  21. /// </summary>
  22. int lineNum = 0;
  23. /// <summary>
  24. /// 竖直的辅助线
  25. /// </summary>
  26. List<Line> vlines = new List<Line>();
  27. /// <summary>
  28. /// 基体平行线
  29. /// </summary>
  30. Line line;
  31. /// <summary>
  32. /// 1显示基体界面 2移动基体界面 0隐藏基体界面
  33. /// </summary>
  34. int btnflag = 0;
  35. ///// <summary>
  36. ///// 轮廓的线
  37. ///// </summary>
  38. //System.Drawing.Point[][] tempLine;
  39. /// <summary>
  40. /// 孔隙的mat
  41. /// </summary>
  42. Mat tempHoleMat;
  43. Bitmap tempHoleBitmap;
  44. /// <summary>
  45. /// 定义变量存储鼠标操作状态 1拖动上辅助线 2拖动下辅助线 /* 3拖动平行辅助线*/
  46. /// </summary>
  47. int mouseFlag = 0;
  48. ///// <summary>
  49. ///// 1显示辅助线 2移动辅助线 0隐藏辅助线
  50. ///// </summary>
  51. //int btnflag = 0;
  52. int contoursTop = 0;
  53. /// <summary>
  54. /// 辅助线
  55. /// </summary>
  56. Line top, bottom;
  57. /// <summary>
  58. /// 孔隙面积
  59. /// </summary>
  60. double res_area1;
  61. /// <summary>
  62. /// 选中区域面积
  63. /// </summary>
  64. double res_areaTotal;
  65. /// <summary>
  66. /// 孔隙体积百分比
  67. /// </summary>
  68. double res_percent;
  69. /// <summary>
  70. /// 选择标尺的物理长度(微米/像素)
  71. /// </summary>
  72. double physical_length = 1;
  73. // <summary>
  74. /// 保存窗口参数
  75. /// </summary>
  76. private GrainSizeAnalysisModel analysisModel;
  77. private const string ParamKey_Report = "report";//报告设置
  78. private const string ParamKey_PoreColour = "poreColour";//孔隙颜色
  79. private const string ParamKey_UpperRegionColour = "upperRegionColour";//上区颜色
  80. private const string ParamKey_UpperRegionWidth = "upperRegionWidth";//上区颜色线宽
  81. private const string ParamKey_LowerRegionColour = "lowerRegionColour";//下区颜色
  82. private const string ParamKey_LowerRegionWidth = "lowerRegionWidth";//下区颜色线宽
  83. private const string ParamKey_DecimalPlace = "decimalPlace";//保留小数位数
  84. #endregion 属性
  85. #region 组件
  86. private Button button2;
  87. private GroupBox groupBox10;
  88. private Panel panel1;
  89. private Label label5;
  90. private GroupBox groupBox8;
  91. private Label label14;
  92. private Label label7;
  93. private Label label2;
  94. private Label label13;
  95. private Label label12;
  96. private GroupBox groupBox5;
  97. private Button button14;
  98. private Button button17;
  99. private Button button3;
  100. private Button button15;
  101. private Button button13;
  102. private Button button10;
  103. private Button button4;
  104. private Button button5;
  105. private GroupBox groupBox6;
  106. private Label label19;
  107. private TextBox textBox4;
  108. private Panel panel3;
  109. private TrackBar trackBar4;
  110. private TextBox textBox10;
  111. private Label label4;
  112. private Label label6;
  113. private GroupBox groupBox7;
  114. private Panel panel4;
  115. private TextBox textBox6;
  116. private TrackBar trackBar3;
  117. private TextBox textBox3;
  118. private Label label16;
  119. private Label label17;
  120. private Label label18;
  121. private TextBox textBox1;
  122. private Label label1;
  123. private Label label11;
  124. #endregion 组件
  125. #region 构造函数
  126. public TABM2Dialog(AppWorkspace appWorkspace, int menuId) : base(appWorkspace, menuId)
  127. {
  128. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
  129. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  130. this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
  131. foreach (var item in this.analysisModel.ListParam)
  132. item.setValue();
  133. //Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
  134. //this.physical_length = measurementUnitDictionary[MeasurementUnit.Micron];
  135. GetListParamModel();
  136. InitGridHeader();
  137. }
  138. /// <summary>
  139. /// 初始化表头
  140. /// </summary>
  141. private void InitGridHeader()
  142. {
  143. DataGridViewTextBoxColumn Column2_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  144. DataGridViewTextBoxColumn Column3_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  145. DataGridViewTextBoxColumn Column4_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  146. Column2_total.Name = "Column2_total";
  147. Column2_total.ReadOnly = true;
  148. Column3_total.Name = "Column3_total";
  149. Column3_total.ReadOnly = true;
  150. Column4_total.Name = "Column4_total";
  151. Column4_total.ReadOnly = true;
  152. Column2_total.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.holearea.text");
  153. Column3_total.HeaderText = PdnResources.GetString("Menu.Areaofselectedarea.text");
  154. Column4_total.HeaderText = PdnResources.GetString("Menu.Percentageofholevolume.text");
  155. this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  156. Column2_total,
  157. Column3_total,
  158. Column4_total});
  159. this.dataGridView_Total.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  160. this.dataGridView_Total.Columns[0].ReadOnly = true;
  161. this.dataGridView_Total.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  162. this.dataGridView_Total.Columns[1].ReadOnly = true;
  163. this.dataGridView_Total.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  164. this.dataGridView_Total.Columns[2].ReadOnly = true;
  165. DataGridViewTextBoxColumn Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  166. DataGridViewTextBoxColumn Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  167. DataGridViewTextBoxColumn Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  168. DataGridViewTextBoxColumn Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  169. Column1.Name = "Column1";
  170. Column1.ReadOnly = true;
  171. Column2.Name = "Column2";
  172. Column2.ReadOnly = true;
  173. Column3.Name = "Column3";
  174. Column3.ReadOnly = true;
  175. Column4.Name = "Column4";
  176. Column4.ReadOnly = true;
  177. Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
  178. Column2.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.holearea.text");
  179. Column3.HeaderText = PdnResources.GetString("Menu.Areaofselectedarea.text");
  180. Column4.HeaderText = PdnResources.GetString("Menu.Percentageofholevolume.text");
  181. this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  182. Column1,
  183. Column2,
  184. Column3,
  185. Column4});
  186. Column1.Width = 195;
  187. Column2.Width = 165;
  188. Column3.Width = 165;
  189. Column4.Width = 165;
  190. this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  191. this.dataGridView2.Columns[0].ReadOnly = true;
  192. this.dataGridView2.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  193. this.dataGridView2.Columns[1].ReadOnly = true;
  194. this.dataGridView2.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  195. this.dataGridView2.Columns[2].ReadOnly = true;
  196. this.dataGridView2.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
  197. this.dataGridView2.Columns[3].ReadOnly = true;
  198. }
  199. #endregion 构造函数
  200. #region 初始化组件和实现组件事件
  201. private void InitializeLanguageText()
  202. {
  203. this.label16.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  204. this.label19.Text = PdnResources.GetString("Menu.Distancefromtop.text") + ":";
  205. //this.label19.Text = PdnResources.GetString("Menu.spacing.text") + ":";
  206. this.groupBox7.Text = PdnResources.GetString("Menu.LowerarealineSettings.text");
  207. this.label6.Text = PdnResources.GetString("Menu.color.text") + ":";
  208. this.label4.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  209. this.groupBox6.Text = PdnResources.GetString("Menu.Upperarea-lineSettings.text");
  210. this.label5.Text = PdnResources.GetString("Menu.color.text") + ":";
  211. //this.label3.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  212. this.groupBox10.Text = "孔隙";// PdnResources.GetString("Menu.contour.text");
  213. this.button2.Text = PdnResources.GetString("Menu.reinformation.text");
  214. this.button5.Text = PdnResources.GetString("Menu.Image.Grayscale.Text");
  215. this.button4/*button3*/.Text = PdnResources.GetString("Menu.BinaryAction.ErosionExtraction.Text");
  216. this.button10.Text = PdnResources.GetString("Menu.BinaryAction.DilationExtraction.Text");
  217. this.button13.Text = PdnResources.GetString("Menu.Drawarea.text");
  218. //this.button13.Text = PdnResources.GetString("Menu.Drawauxiliarylines.text");
  219. this.button3.Text = PdnResources.GetString("Menu.reinformation.text");
  220. this.button15.Text = "寻找孔隙";// PdnResources.GetString("Menu.searchcontour.text");
  221. this.button17.Text = PdnResources.GetString("Menu.auto-adjust.text");
  222. this.button14.Text = "修改孔隙";// PdnResources.GetString("Menu.easemodifytheoutline.Text");
  223. //this.button5.Text = PdnResources.GetString("Menu.reinformation.text");
  224. this.groupBox5.Text = PdnResources.GetString("Menu.Basicoperation.text");
  225. this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.Percentageofholevolume.text") + ")";
  226. //this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.veragecoatingthickness.Text") + ")";
  227. this.label11.Text = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.holearea.text") + ":";
  228. this.label12.Text = PdnResources.GetString("Menu.Areaofselectedarea.text") + ":";
  229. this.label13.Text = PdnResources.GetString("Menu.Percentageofholevolume.text") + ":";
  230. //this.label11.Text = PdnResources.GetString("Menu.Averagethickness(μm).text") + ":";
  231. //this.label12.Text = PdnResources.GetString("Menu.standarddeviation.text") + ":";
  232. //this.label13.Text = PdnResources.GetString("Menu.confidencebound.text") + ":";
  233. this.groupBox8.Text = PdnResources.GetString("Menu.result.text");
  234. this.label18.Text = PdnResources.GetString("Menu.color.text") + ":";
  235. this.label17.Text = PdnResources.GetString("Menu.Distancefrombottom.text") + ":";
  236. this.label1.Text = "辅助线间距";// PdnResources.GetString("Menu.spacing.text") + ":";
  237. }
  238. private void InitializeComponent()
  239. {
  240. this.button2 = new System.Windows.Forms.Button();
  241. this.groupBox10 = new System.Windows.Forms.GroupBox();
  242. this.textBox1 = new System.Windows.Forms.TextBox();
  243. this.label1 = new System.Windows.Forms.Label();
  244. this.panel1 = new System.Windows.Forms.Panel();
  245. this.label5 = new System.Windows.Forms.Label();
  246. this.groupBox8 = new System.Windows.Forms.GroupBox();
  247. this.label14 = new System.Windows.Forms.Label();
  248. this.label7 = new System.Windows.Forms.Label();
  249. this.label2 = new System.Windows.Forms.Label();
  250. this.label13 = new System.Windows.Forms.Label();
  251. this.label12 = new System.Windows.Forms.Label();
  252. this.label11 = new System.Windows.Forms.Label();
  253. this.groupBox5 = new System.Windows.Forms.GroupBox();
  254. this.button14 = new System.Windows.Forms.Button();
  255. this.button17 = new System.Windows.Forms.Button();
  256. this.button3 = new System.Windows.Forms.Button();
  257. this.button15 = new System.Windows.Forms.Button();
  258. this.button13 = new System.Windows.Forms.Button();
  259. this.button10 = new System.Windows.Forms.Button();
  260. this.button4 = new System.Windows.Forms.Button();
  261. this.button5 = new System.Windows.Forms.Button();
  262. this.groupBox6 = new System.Windows.Forms.GroupBox();
  263. this.label19 = new System.Windows.Forms.Label();
  264. this.textBox4 = new System.Windows.Forms.TextBox();
  265. this.panel3 = new System.Windows.Forms.Panel();
  266. this.trackBar4 = new System.Windows.Forms.TrackBar();
  267. this.textBox10 = new System.Windows.Forms.TextBox();
  268. this.label4 = new System.Windows.Forms.Label();
  269. this.label6 = new System.Windows.Forms.Label();
  270. this.groupBox7 = new System.Windows.Forms.GroupBox();
  271. this.panel4 = new System.Windows.Forms.Panel();
  272. this.textBox6 = new System.Windows.Forms.TextBox();
  273. this.trackBar3 = new System.Windows.Forms.TrackBar();
  274. this.textBox3 = new System.Windows.Forms.TextBox();
  275. this.label16 = new System.Windows.Forms.Label();
  276. this.label17 = new System.Windows.Forms.Label();
  277. this.label18 = new System.Windows.Forms.Label();
  278. this.groupBox_img.SuspendLayout();
  279. this.groupBox_report.SuspendLayout();
  280. this.groupBox_analysisResult1.SuspendLayout();
  281. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
  282. this.groupBox10.SuspendLayout();
  283. this.groupBox8.SuspendLayout();
  284. this.groupBox5.SuspendLayout();
  285. this.groupBox6.SuspendLayout();
  286. ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit();
  287. this.groupBox7.SuspendLayout();
  288. ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
  289. this.SuspendLayout();
  290. //
  291. // button2
  292. //
  293. this.button2.Location = new System.Drawing.Point(96, 39);
  294. this.button2.Name = "button2";
  295. this.button2.Size = new System.Drawing.Size(75, 23);
  296. this.button2.TabIndex = 6;
  297. this.button2.UseVisualStyleBackColor = true;
  298. //
  299. // groupBox10
  300. //
  301. this.groupBox10.Controls.Add(this.textBox1);
  302. this.groupBox10.Controls.Add(this.label1);
  303. this.groupBox10.Controls.Add(this.panel1);
  304. this.groupBox10.Controls.Add(this.label5);
  305. this.groupBox10.Location = new System.Drawing.Point(178, 383);
  306. this.groupBox10.Name = "groupBox10";
  307. this.groupBox10.Size = new System.Drawing.Size(354, 41);
  308. this.groupBox10.TabIndex = 42;
  309. this.groupBox10.TabStop = false;
  310. //
  311. // textBox1
  312. //
  313. this.textBox1.Location = new System.Drawing.Point(246, 15);
  314. this.textBox1.Name = "textBox1";
  315. this.textBox1.Size = new System.Drawing.Size(101, 21);
  316. this.textBox1.TabIndex = 27;
  317. this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  318. this.textBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyUp);
  319. //
  320. // label1
  321. //
  322. this.label1.AutoSize = true;
  323. this.label1.Location = new System.Drawing.Point(175, 20);
  324. this.label1.Name = "label1";
  325. this.label1.Size = new System.Drawing.Size(0, 12);
  326. this.label1.TabIndex = 26;
  327. //
  328. // panel1
  329. //
  330. this.panel1.BackColor = System.Drawing.Color.Orange;
  331. this.panel1.Location = new System.Drawing.Point(63, 15);
  332. this.panel1.Name = "panel1";
  333. this.panel1.Size = new System.Drawing.Size(105, 21);
  334. this.panel1.TabIndex = 21;
  335. //
  336. // label5
  337. //
  338. this.label5.AutoSize = true;
  339. this.label5.Location = new System.Drawing.Point(15, 20);
  340. this.label5.Name = "label5";
  341. this.label5.Size = new System.Drawing.Size(0, 12);
  342. this.label5.TabIndex = 0;
  343. //
  344. // groupBox8
  345. //
  346. this.groupBox8.Controls.Add(this.label14);
  347. this.groupBox8.Controls.Add(this.label7);
  348. this.groupBox8.Controls.Add(this.label2);
  349. this.groupBox8.Controls.Add(this.label13);
  350. this.groupBox8.Controls.Add(this.label12);
  351. this.groupBox8.Controls.Add(this.label11);
  352. this.groupBox8.Location = new System.Drawing.Point(179, 563);
  353. this.groupBox8.Name = "groupBox8";
  354. this.groupBox8.Size = new System.Drawing.Size(353, 53);
  355. this.groupBox8.TabIndex = 43;
  356. this.groupBox8.TabStop = false;
  357. //
  358. // label14
  359. //
  360. this.label14.AutoSize = true;
  361. this.label14.Location = new System.Drawing.Point(279, 32);
  362. this.label14.Name = "label14";
  363. this.label14.Size = new System.Drawing.Size(0, 12);
  364. this.label14.TabIndex = 11;
  365. //
  366. // label7
  367. //
  368. this.label7.AutoSize = true;
  369. this.label7.Location = new System.Drawing.Point(110, 32);
  370. this.label7.Name = "label7";
  371. this.label7.Size = new System.Drawing.Size(0, 12);
  372. this.label7.TabIndex = 10;
  373. //
  374. // label2
  375. //
  376. this.label2.AutoSize = true;
  377. this.label2.Location = new System.Drawing.Point(87, 15);
  378. this.label2.Name = "label2";
  379. this.label2.Size = new System.Drawing.Size(0, 12);
  380. this.label2.TabIndex = 9;
  381. //
  382. // label13
  383. //
  384. this.label13.AutoSize = true;
  385. this.label13.Location = new System.Drawing.Point(172, 32);
  386. this.label13.Name = "label13";
  387. this.label13.Size = new System.Drawing.Size(0, 12);
  388. this.label13.TabIndex = 8;
  389. //
  390. // label12
  391. //
  392. this.label12.AutoSize = true;
  393. this.label12.Location = new System.Drawing.Point(15, 32);
  394. this.label12.Name = "label12";
  395. this.label12.Size = new System.Drawing.Size(0, 12);
  396. this.label12.TabIndex = 7;
  397. //
  398. // label11
  399. //
  400. this.label11.AutoSize = true;
  401. this.label11.Location = new System.Drawing.Point(16, 15);
  402. this.label11.Name = "label11";
  403. this.label11.Size = new System.Drawing.Size(0, 12);
  404. this.label11.TabIndex = 6;
  405. //
  406. // groupBox5
  407. //
  408. this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  409. | System.Windows.Forms.AnchorStyles.Right)));
  410. this.groupBox5.Controls.Add(this.button14);
  411. this.groupBox5.Controls.Add(this.button17);
  412. this.groupBox5.Controls.Add(this.button3);
  413. this.groupBox5.Controls.Add(this.button15);
  414. this.groupBox5.Controls.Add(this.button13);
  415. this.groupBox5.Controls.Add(this.button10);
  416. this.groupBox5.Controls.Add(this.button4);
  417. this.groupBox5.Controls.Add(this.button5);
  418. this.groupBox5.Location = new System.Drawing.Point(180, 317);
  419. this.groupBox5.Name = "groupBox5";
  420. this.groupBox5.Size = new System.Drawing.Size(353, 66);
  421. this.groupBox5.TabIndex = 44;
  422. this.groupBox5.TabStop = false;
  423. //
  424. // button14
  425. //
  426. this.button14.Location = new System.Drawing.Point(267, 40);
  427. this.button14.Name = "button14";
  428. this.button14.Size = new System.Drawing.Size(75, 23);
  429. this.button14.TabIndex = 8;
  430. this.button14.UseVisualStyleBackColor = true;
  431. this.button14.Click += new System.EventHandler(this.button14_Click);
  432. //
  433. // button17
  434. //
  435. this.button17.Location = new System.Drawing.Point(180, 40);
  436. this.button17.Name = "button17";
  437. this.button17.Size = new System.Drawing.Size(75, 23);
  438. this.button17.TabIndex = 7;
  439. this.button17.UseVisualStyleBackColor = true;
  440. this.button17.Click += new System.EventHandler(this.button17_Click);
  441. //
  442. // button3
  443. //
  444. this.button3.Location = new System.Drawing.Point(93, 40);
  445. this.button3.Name = "button3";
  446. this.button3.Size = new System.Drawing.Size(75, 23);
  447. this.button3.TabIndex = 6;
  448. this.button3.UseVisualStyleBackColor = true;
  449. this.button3.Click += new System.EventHandler(this.button3_Click);
  450. //
  451. // button15
  452. //
  453. this.button15.Location = new System.Drawing.Point(267, 15);
  454. this.button15.Name = "button15";
  455. this.button15.Size = new System.Drawing.Size(75, 23);
  456. this.button15.TabIndex = 5;
  457. this.button15.UseVisualStyleBackColor = true;
  458. this.button15.Click += new System.EventHandler(this.button15_Click);
  459. //
  460. // button13
  461. //
  462. this.button13.Location = new System.Drawing.Point(9, 40);
  463. this.button13.Name = "button13";
  464. this.button13.Size = new System.Drawing.Size(75, 23);
  465. this.button13.TabIndex = 3;
  466. this.button13.UseVisualStyleBackColor = true;
  467. this.button13.Click += new System.EventHandler(this.button13_Click);
  468. //
  469. // button10
  470. //
  471. this.button10.Location = new System.Drawing.Point(180, 15);
  472. this.button10.Name = "button10";
  473. this.button10.Size = new System.Drawing.Size(75, 23);
  474. this.button10.TabIndex = 2;
  475. this.button10.UseVisualStyleBackColor = true;
  476. this.button10.Click += new System.EventHandler(this.button10_Click);
  477. //
  478. // button4
  479. //
  480. this.button4.Location = new System.Drawing.Point(93, 15);
  481. this.button4.Name = "button4";
  482. this.button4.Size = new System.Drawing.Size(75, 23);
  483. this.button4.TabIndex = 1;
  484. this.button4.UseVisualStyleBackColor = true;
  485. this.button4.Click += new System.EventHandler(this.button4_Click);
  486. //
  487. // button5
  488. //
  489. this.button5.Location = new System.Drawing.Point(9, 15);
  490. this.button5.Name = "button5";
  491. this.button5.Size = new System.Drawing.Size(75, 23);
  492. this.button5.TabIndex = 0;
  493. this.button5.UseVisualStyleBackColor = true;
  494. this.button5.Click += new System.EventHandler(this.button5_Click);
  495. //
  496. // groupBox6
  497. //
  498. this.groupBox6.Controls.Add(this.label19);
  499. this.groupBox6.Controls.Add(this.textBox4);
  500. this.groupBox6.Controls.Add(this.panel3);
  501. this.groupBox6.Controls.Add(this.trackBar4);
  502. this.groupBox6.Controls.Add(this.textBox10);
  503. this.groupBox6.Controls.Add(this.label4);
  504. this.groupBox6.Controls.Add(this.label6);
  505. this.groupBox6.Location = new System.Drawing.Point(178, 426);
  506. this.groupBox6.Name = "groupBox6";
  507. this.groupBox6.Size = new System.Drawing.Size(354, 66);
  508. this.groupBox6.TabIndex = 45;
  509. this.groupBox6.TabStop = false;
  510. //
  511. // label19
  512. //
  513. this.label19.AutoSize = true;
  514. this.label19.Location = new System.Drawing.Point(15, 47);
  515. this.label19.Name = "label19";
  516. this.label19.Size = new System.Drawing.Size(0, 12);
  517. this.label19.TabIndex = 23;
  518. //
  519. // textBox4
  520. //
  521. this.textBox4.Location = new System.Drawing.Point(86, 42);
  522. this.textBox4.Name = "textBox4";
  523. this.textBox4.Size = new System.Drawing.Size(95, 21);
  524. this.textBox4.TabIndex = 8;
  525. this.textBox4.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBox4_TextChanged);
  526. //
  527. // panel3
  528. //
  529. this.panel3.BackColor = System.Drawing.Color.Yellow;
  530. this.panel3.Location = new System.Drawing.Point(62, 14);
  531. this.panel3.Name = "panel3";
  532. this.panel3.Size = new System.Drawing.Size(105, 21);
  533. this.panel3.TabIndex = 22;
  534. //
  535. // trackBar4
  536. //
  537. this.trackBar4.AutoSize = false;
  538. this.trackBar4.Cursor = System.Windows.Forms.Cursors.Hand;
  539. this.trackBar4.Location = new System.Drawing.Point(214, 16);
  540. this.trackBar4.Maximum = 50;
  541. this.trackBar4.Minimum = 1;
  542. this.trackBar4.Name = "trackBar4";
  543. this.trackBar4.Size = new System.Drawing.Size(84, 21);
  544. this.trackBar4.TabIndex = 7;
  545. this.trackBar4.TickStyle = System.Windows.Forms.TickStyle.None;
  546. this.trackBar4.Value = 3;
  547. this.trackBar4.Scroll += new System.EventHandler(this.trackBar4_Scroll);
  548. this.trackBar4.ValueChanged += new System.EventHandler(this.trackBar4_ValueChanged);
  549. //
  550. // textBox10
  551. //
  552. this.textBox10.Location = new System.Drawing.Point(304, 15);
  553. this.textBox10.Name = "textBox10";
  554. this.textBox10.Size = new System.Drawing.Size(35, 21);
  555. this.textBox10.TabIndex = 6;
  556. this.textBox10.Text = "3";
  557. this.textBox10.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  558. this.textBox10.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox10_KeyUp);
  559. //
  560. // label4
  561. //
  562. this.label4.AutoSize = true;
  563. this.label4.Location = new System.Drawing.Point(173, 20);
  564. this.label4.Name = "label4";
  565. this.label4.Size = new System.Drawing.Size(0, 12);
  566. this.label4.TabIndex = 2;
  567. //
  568. // label6
  569. //
  570. this.label6.AutoSize = true;
  571. this.label6.Location = new System.Drawing.Point(15, 20);
  572. this.label6.Name = "label6";
  573. this.label6.Size = new System.Drawing.Size(0, 12);
  574. this.label6.TabIndex = 0;
  575. //
  576. // groupBox7
  577. //
  578. this.groupBox7.Controls.Add(this.panel4);
  579. this.groupBox7.Controls.Add(this.textBox6);
  580. this.groupBox7.Controls.Add(this.trackBar3);
  581. this.groupBox7.Controls.Add(this.textBox3);
  582. this.groupBox7.Controls.Add(this.label16);
  583. this.groupBox7.Controls.Add(this.label17);
  584. this.groupBox7.Controls.Add(this.label18);
  585. this.groupBox7.Location = new System.Drawing.Point(178, 495);
  586. this.groupBox7.Name = "groupBox7";
  587. this.groupBox7.Size = new System.Drawing.Size(354, 67);
  588. this.groupBox7.TabIndex = 46;
  589. this.groupBox7.TabStop = false;
  590. //
  591. // panel4
  592. //
  593. this.panel4.BackColor = System.Drawing.Color.Green;
  594. this.panel4.Location = new System.Drawing.Point(63, 14);
  595. this.panel4.Name = "panel4";
  596. this.panel4.Size = new System.Drawing.Size(105, 21);
  597. this.panel4.TabIndex = 23;
  598. //
  599. // textBox6
  600. //
  601. this.textBox6.Location = new System.Drawing.Point(86, 41);
  602. this.textBox6.Name = "textBox6";
  603. this.textBox6.Size = new System.Drawing.Size(95, 21);
  604. this.textBox6.TabIndex = 10;
  605. this.textBox6.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBox6_TextChanged);
  606. //
  607. // trackBar3
  608. //
  609. this.trackBar3.AutoSize = false;
  610. this.trackBar3.Cursor = System.Windows.Forms.Cursors.Hand;
  611. this.trackBar3.Location = new System.Drawing.Point(214, 15);
  612. this.trackBar3.Maximum = 50;
  613. this.trackBar3.Minimum = 1;
  614. this.trackBar3.Name = "trackBar3";
  615. this.trackBar3.Size = new System.Drawing.Size(84, 21);
  616. this.trackBar3.TabIndex = 7;
  617. this.trackBar3.TickStyle = System.Windows.Forms.TickStyle.None;
  618. this.trackBar3.Value = 3;
  619. this.trackBar3.Scroll += new System.EventHandler(this.trackBar3_Scroll);
  620. this.trackBar3.ValueChanged += new System.EventHandler(this.trackBar3_ValueChanged);
  621. //
  622. // textBox3
  623. //
  624. this.textBox3.Location = new System.Drawing.Point(304, 14);
  625. this.textBox3.Name = "textBox3";
  626. this.textBox3.Size = new System.Drawing.Size(35, 21);
  627. this.textBox3.TabIndex = 6;
  628. this.textBox3.Text = "3";
  629. this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  630. this.textBox3.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyUp);
  631. //
  632. // label16
  633. //
  634. this.label16.AutoSize = true;
  635. this.label16.Location = new System.Drawing.Point(173, 19);
  636. this.label16.Name = "label16";
  637. this.label16.Size = new System.Drawing.Size(0, 12);
  638. this.label16.TabIndex = 2;
  639. //
  640. // label17
  641. //
  642. this.label17.AutoSize = true;
  643. this.label17.Location = new System.Drawing.Point(15, 47);
  644. this.label17.Name = "label17";
  645. this.label17.Size = new System.Drawing.Size(0, 12);
  646. this.label17.TabIndex = 1;
  647. //
  648. // label18
  649. //
  650. this.label18.AutoSize = true;
  651. this.label18.Location = new System.Drawing.Point(15, 19);
  652. this.label18.Name = "label18";
  653. this.label18.Size = new System.Drawing.Size(0, 12);
  654. this.label18.TabIndex = 0;
  655. //
  656. // TABM2Dialog
  657. //
  658. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  659. this.ClientSize = new System.Drawing.Size(1127, 822);
  660. this.Controls.Add(this.groupBox7);
  661. this.Controls.Add(this.groupBox6);
  662. this.Controls.Add(this.groupBox5);
  663. this.Controls.Add(this.groupBox8);
  664. this.Controls.Add(this.groupBox10);
  665. this.Name = "TABM2Dialog";
  666. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TABM2Dialog_FormClosing);
  667. this.Controls.SetChildIndex(this.groupBox10, 0);
  668. this.Controls.SetChildIndex(this.groupBox8, 0);
  669. this.Controls.SetChildIndex(this.groupBox5, 0);
  670. this.Controls.SetChildIndex(this.groupBox6, 0);
  671. this.Controls.SetChildIndex(this.groupBox7, 0);
  672. this.Controls.SetChildIndex(this.groupBox_img, 0);
  673. this.Controls.SetChildIndex(this.groupBox_review, 0);
  674. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  675. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  676. this.Controls.SetChildIndex(this.groupBox_report, 0);
  677. this.groupBox_img.ResumeLayout(false);
  678. this.groupBox_report.ResumeLayout(false);
  679. this.groupBox_report.PerformLayout();
  680. this.groupBox_analysisResult1.ResumeLayout(false);
  681. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
  682. this.groupBox10.ResumeLayout(false);
  683. this.groupBox10.PerformLayout();
  684. this.groupBox8.ResumeLayout(false);
  685. this.groupBox8.PerformLayout();
  686. this.groupBox5.ResumeLayout(false);
  687. this.groupBox6.ResumeLayout(false);
  688. this.groupBox6.PerformLayout();
  689. ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).EndInit();
  690. this.groupBox7.ResumeLayout(false);
  691. this.groupBox7.PerformLayout();
  692. ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
  693. this.ResumeLayout(false);
  694. }
  695. #endregion 初始化组件和实现组件事件
  696. #region 需继承的一部分方法
  697. protected override void drawSubclass(Graphics graphics)
  698. {
  699. if (tempHoleMat != null && tempHoleBitmap != null)
  700. {
  701. graphics.DrawImage(tempHoleBitmap, new PointF(0, 0));
  702. }
  703. if (top != null && bottom != null)
  704. {
  705. Pen topLinePen = new Pen(this.panel3.BackColor/*Color.FromArgb(255, 0, 208, 202)*/, this.trackBar4.Value/*5*/);
  706. Pen blueLinePen = new Pen(this.panel4.BackColor/*Color.FromArgb(255, 0, 208, 202)*/, this.trackBar3.Value/*5*/);
  707. graphics.DrawLine(topLinePen, top.startPoint, top.endPoint);
  708. graphics.DrawLine(blueLinePen, bottom.startPoint, bottom.endPoint);
  709. }
  710. //if (tempLine != null && tempLine.Length > 0 && !bcOriginChecked())
  711. //{
  712. // Pen lineColor = new Pen(this.panel1.BackColor, this.trackBar5.Value);
  713. // for (int index = 0; index < tempLine.Length; index++)
  714. // {
  715. // System.Drawing.Point[] tempLine1 = tempLine[index];
  716. // graphics.DrawLines(lineColor, tempLine1);
  717. // }
  718. //}
  719. ////画笔
  720. //Pen yellowPen = new Pen(this.panel3.BackColor, this.trackBar4.Value);
  721. //if (line == null)
  722. //{
  723. // btnflag = 0;
  724. // //System.Drawing.Point point1 = new System.Drawing.Point(0, lab1Img.Height - 130);
  725. // //System.Drawing.Point point2 = new System.Drawing.Point(lab1Img.Width, lab1Img.Height - 130);
  726. // //line = new Line(point1, point2);
  727. // //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
  728. //}
  729. //else
  730. //{
  731. // if (btnflag == 0)
  732. // btnflag = 1;
  733. // graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
  734. //}
  735. //if (vlines.Count() > 0)
  736. //{
  737. // Pen bluePen = new Pen(this.panel4.BackColor, this.trackBar3.Value);
  738. // foreach (Line temp in vlines)
  739. // graphics.DrawLine(bluePen, temp.startPoint, temp.endPoint);
  740. //}
  741. }
  742. //数据库的name(报告模板)
  743. protected override string getTemplateName()
  744. {
  745. return "Template.Manager.item3.TitaniumAlloyBio2Method";
  746. }
  747. //语言包的name(项目工程)
  748. protected override string getProjectEngineeringName()
  749. {
  750. return "Menu.DedicatedAnalysis.NonferrousMetal.TitaniumAlloyBiomaterial.Text";
  751. }
  752. protected override void SubclassInitialize()
  753. {
  754. InitializeComponent();
  755. InitializeLanguageText();
  756. this.panel1.Click += new System.EventHandler(this.panel1_Click);
  757. this.panel3.Click += new System.EventHandler(this.panel1_Click);
  758. this.panel4.Click += new System.EventHandler(this.panel1_Click);
  759. //this.groupBox_img.Size = new System.Drawing.Size(158, 544/*514*/);
  760. //this.groupBox_review.Size = new System.Drawing.Size(575, 544/*514*/);
  761. //this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 622/*592*/);
  762. //this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 622/*592*/);
  763. //this.groupBox_report.Location = new System.Drawing.Point(974, 622/*592*/);
  764. this.ClientSize = new System.Drawing.Size(1127, 852);///*822*/
  765. }
  766. //切换图片时控制前一张图的信息不遗留显示
  767. protected override void refreshWhileImgChanged()
  768. {
  769. //this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  770. this.textBox1_KeyUp(null, null);
  771. calculate1d = false;
  772. this.label2.Text = "";
  773. this.label7.Text = "";
  774. this.label14.Text = "";
  775. vlines.Clear();
  776. if (line != null)
  777. {
  778. btnflag = 0;
  779. line = null;
  780. }
  781. if (tempHoleMat != null)
  782. {
  783. tempHoleMat.Dispose();
  784. tempHoleMat = null;
  785. }
  786. //if (this.documentWorkspace.PhaseModels.Count() == 0 || this.documentWorkspace.PhaseModels[0].mat == null || !this.documentWorkspace.PhaseModels[0].choise)
  787. //{
  788. // binaryClass.performClickBinaryCheck(false);
  789. //}
  790. this.grayBitmap = false;
  791. //if (this.bitmap == null)
  792. //{
  793. // return;
  794. //}
  795. //if (textBoxChanged == 1)
  796. //{
  797. // textBoxChanged = -1;
  798. // return;
  799. //}
  800. //if (string.IsNullOrWhiteSpace(this.textBox6.Text) || textBox6.Text == "")
  801. //{
  802. // return;
  803. //}
  804. //int w;
  805. //try
  806. //{
  807. // w = int.Parse(this.textBox6.Text);
  808. // textBoxChanged = 2;
  809. //}
  810. //catch (Exception b)
  811. //{
  812. // MessageBox.Show(b.Message);
  813. // return;
  814. //}
  815. //int per_w = (int)((this.bitmap/*lab1Img*/.Width / Math.Max(1, (w + 1))) * physical_length);
  816. //textBox4.Text = per_w.ToString();
  817. }
  818. #endregion
  819. #region 基础操作
  820. /// <summary>
  821. /// 灰度化
  822. /// </summary>
  823. /// <param name="sender"></param>
  824. /// <param name="e"></param>
  825. private void button5_Click(object sender, EventArgs e)
  826. {
  827. if (this.bitmap == null)
  828. {
  829. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
  830. return;
  831. }
  832. if (this.grayBitmap) {
  833. MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
  834. return;
  835. }
  836. this.grayBitmap = true;
  837. Mat lab1Img = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);
  838. if (lab1Img.Type() != MatType.CV_8UC1)
  839. {
  840. lab1Img = lab1Img.CvtColor(ColorConversionCodes.BGR2GRAY);
  841. Bitmap bitmap2 = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1Img);
  842. Document document = Document.FromImage(bitmap2);
  843. this.documentWorkspace.Document = document;
  844. }
  845. else
  846. MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
  847. lab1Img.Dispose();
  848. lab1Img = null;
  849. }
  850. /// <summary>
  851. /// 腐蚀
  852. /// </summary>
  853. /// <param name="sender"></param>
  854. /// <param name="e"></param>
  855. private void button4_Click(object sender, EventArgs e)
  856. {
  857. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
  858. || this.documentWorkspace.PhaseModels[0].mat == null)
  859. {
  860. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  861. return;
  862. }
  863. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  864. Cv2.Erode(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
  865. this.documentWorkspace.PhaseModels[0].mat = lab1Img;
  866. this.documentWorkspace.Refresh();
  867. }
  868. /// <summary>
  869. /// 膨胀
  870. /// </summary>
  871. /// <param name="sender"></param>
  872. /// <param name="e"></param>
  873. private void button10_Click(object sender, EventArgs e)
  874. {
  875. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
  876. || this.documentWorkspace.PhaseModels[0].mat == null)
  877. {
  878. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  879. return;
  880. }
  881. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  882. Cv2.Dilate(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
  883. this.documentWorkspace.PhaseModels[0].mat = lab1Img;
  884. this.documentWorkspace.Refresh();
  885. }
  886. /// <summary>
  887. /// 寻找孔隙 (寻找轮廓)
  888. /// </summary>
  889. /// <param name="sender"></param>
  890. /// <param name="e"></param>
  891. private void button15_Click(object sender, EventArgs e)
  892. {
  893. findContour();
  894. }
  895. private void findContour(bool showMessageBox = true)
  896. {
  897. if (top == null || bottom == null)
  898. {
  899. if (showMessageBox)//#21396
  900. MessageBox.Show("请先绘制区域"/*PdnResources.GetString("Menu.Pleasedrawtheareafirst.text")*/);//选取区域
  901. return;
  902. }
  903. if (bottom.endPoint.Y - top.startPoint.Y <= 0)//0914###18506
  904. {
  905. if (showMessageBox)
  906. MessageBox.Show(PdnResources.GetString("Menu.Theupperguinthelowerone.text"));
  907. return;
  908. }
  909. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise/* //###21476 */
  910. || this.documentWorkspace.PhaseModels[0].mat == null)
  911. {
  912. if (showMessageBox)
  913. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  914. return;
  915. }
  916. Mat analyzeMat = this.documentWorkspace.PhaseModels[0].mat;
  917. Color tempHoleColor = this.panel1.BackColor;
  918. Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
  919. Vec4b vec4B2 = new Vec4b(0, 0, 0, 0);
  920. if (tempHoleMat != null)
  921. {
  922. tempHoleMat.Dispose();
  923. tempHoleMat = null;
  924. }
  925. tempHoleMat = new Mat(analyzeMat.Size(), MatType.CV_8UC4);
  926. int Rows = analyzeMat.Rows;
  927. int Cols = analyzeMat.Cols;
  928. int[] point = new int[2];
  929. //多通道图像的格式化
  930. for (point[1] = 0; point[1] < Cols; point[1]++)
  931. {
  932. for (point[0] = top.startPoint.Y/*0*/; point[0] < bottom.endPoint.Y/*Rows*/; point[0]++)
  933. {
  934. if (analyzeMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  935. tempHoleMat.Set(point, vec4B2);
  936. else
  937. tempHoleMat.Set(point, vec4B1);
  938. }
  939. }
  940. tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
  941. this.documentWorkspace.Refresh();
  942. //return true;
  943. }
  944. /// <summary>
  945. /// PanelC的调色板颜色改变
  946. /// </summary>
  947. /// <param name="sender"></param>
  948. /// <param name="e"></param>
  949. protected override void gridColorChanged(object sender, EventArgs e)
  950. {
  951. base.gridColorChanged(sender, e);
  952. if (this.panelC != this.panel1)
  953. return;
  954. Color tempHoleColor = this.panel1.BackColor;
  955. Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
  956. if (tempHoleMat == null)
  957. {
  958. return;
  959. }
  960. int Rows = tempHoleMat.Rows;
  961. int Cols = tempHoleMat.Cols;
  962. int[] point = new int[2];
  963. //多通道图像的格式化
  964. for (point[1] = 0; point[1] < Cols; point[1]++)
  965. {
  966. for (point[0] = 0; point[0] < Rows; point[0]++)
  967. {
  968. if (tempHoleMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  969. tempHoleMat.Set(point, vec4B1);
  970. }
  971. }
  972. tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
  973. this.documentWorkspace.Refresh();
  974. }
  975. /// <summary>
  976. /// 自动调整
  977. /// </summary>
  978. /// <param name="sender"></param>
  979. /// <param name="e"></param>
  980. private void button17_Click(object sender, EventArgs e)
  981. {
  982. if (top == null || bottom == null)
  983. {
  984. this.button13.PerformClick();
  985. //MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawtheareafirst.text"));//选取区域
  986. //return;
  987. }
  988. if (this.documentWorkspace.PhaseModels.Count < 1/* || !this.documentWorkspace.PhaseModels[0].choise*/
  989. || this.documentWorkspace.PhaseModels[0].mat == null)
  990. {
  991. binaryClass.performClickBinaryCheck(true);
  992. }
  993. this.button15.PerformClick();
  994. }
  995. /// <summary>
  996. /// 绘制区域 (绘制辅助线)
  997. /// </summary>
  998. /// <param name="sender"></param>
  999. /// <param name="e"></param>
  1000. private void button13_Click(object sender, EventArgs e)
  1001. {
  1002. //this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  1003. int result = 0;
  1004. if (int.TryParse(textBox4.Text, out result))
  1005. {
  1006. top = new Line(new System.Drawing.Point(0, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)));
  1007. }
  1008. else
  1009. {
  1010. top = new Line(new System.Drawing.Point(0, 50), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, 50));
  1011. textBox4.Text = (top.startPoint.Y * physical_length) + "";
  1012. }
  1013. if (int.TryParse(textBox6.Text, out result))
  1014. {
  1015. bottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)));
  1016. }
  1017. else
  1018. {
  1019. bottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 30), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 30));
  1020. textBox6.Text = ((this.bitmap/*lab1Img*/.Height - bottom.startPoint.Y) * physical_length) + "";
  1021. }
  1022. if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
  1023. textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
  1024. btnflag = 1;
  1025. this.documentWorkspace.Refresh();
  1026. textBox4.Enabled = true;
  1027. textBox6.Enabled = true;
  1028. }
  1029. /// <summary>
  1030. /// 重置
  1031. /// </summary>
  1032. /// <param name="sender"></param>
  1033. /// <param name="e"></param>
  1034. private void button3_Click(object sender, EventArgs e)
  1035. {
  1036. if (this.bitmap == null)
  1037. {
  1038. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  1039. return;
  1040. }
  1041. calculate1d = false;
  1042. this.label2.Text = "";
  1043. this.label7.Text = "";
  1044. this.label14.Text = "";
  1045. vlines.Clear();
  1046. if (line == null)
  1047. {
  1048. }
  1049. else
  1050. {
  1051. btnflag = 0;
  1052. line = null;
  1053. }
  1054. if (top != null)
  1055. top = null;
  1056. if (bottom != null)
  1057. bottom = null;
  1058. if (tempHoleMat != null)
  1059. {
  1060. tempHoleMat.Dispose();
  1061. tempHoleMat = null;
  1062. }
  1063. if (this.documentWorkspace.PhaseModels.Count() > 0)
  1064. {
  1065. this.documentWorkspace.PhaseModels[0].mat = null;
  1066. }
  1067. this.documentWorkspace.PhaseModels[0].choise = false;
  1068. binaryClass.performClickBinaryCheck(false);
  1069. //this.checkBox10.Checked = false;//PdnResources.GetString("Menu.Binarization.text");//####################
  1070. this.grayBitmap = false;
  1071. Document document = Document.FromImage(this.bitmap);
  1072. this.documentWorkspace.Document = document;
  1073. }
  1074. /// <summary>
  1075. /// 修改孔隙 (修改轮廓)
  1076. /// </summary>
  1077. /// <param name="sender"></param>
  1078. /// <param name="e"></param>
  1079. private void button14_Click(object sender, EventArgs e)
  1080. {
  1081. if (this.bitmap == null)
  1082. {
  1083. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
  1084. return;
  1085. }
  1086. if (tempHoleMat == null)
  1087. {
  1088. MessageBox.Show("请先进行寻找孔隙操作");
  1089. return;
  1090. }
  1091. IntegrationClass.MetalsHoleAreaEditingDialog boundaryEditingDialog = new IntegrationClass.MetalsHoleAreaEditingDialog(this.appWorkspace, this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index, this.panel1.BackColor
  1092. , tempHoleMat);
  1093. if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
  1094. {
  1095. tempHoleMat = boundaryEditingDialog.PhaseMat.Clone();
  1096. tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
  1097. this.documentWorkspace.Refresh();
  1098. }
  1099. }
  1100. #endregion 基础操作
  1101. #region 控件监听事件
  1102. private void trackBar4_ValueChanged(object sender, EventArgs e)
  1103. {
  1104. this.documentWorkspace.Refresh();
  1105. }
  1106. private void trackBar4_Scroll(object sender, EventArgs e)
  1107. {
  1108. this.textBox10.Text = "" + this.trackBar4.Value;
  1109. }
  1110. private void trackBar3_ValueChanged(object sender, EventArgs e)
  1111. {
  1112. this.documentWorkspace.Refresh();
  1113. }
  1114. private void trackBar3_Scroll(object sender, EventArgs e)
  1115. {
  1116. this.textBox3.Text = "" + this.trackBar3.Value;
  1117. }
  1118. /// <summary>
  1119. /// 线宽输入框 对输入值做限制
  1120. /// </summary>
  1121. /// <param name="sender"></param>
  1122. private void varifyTextBoxValue(object sender)
  1123. {
  1124. if (string.IsNullOrEmpty(((TextBox)sender)/*this.textBox2*/.Text))
  1125. ((TextBox)sender)/*this.textBox2*/.Text = "1";
  1126. if (Convert.ToInt32(((TextBox)sender)/*this.textBox2*/.Text) > 50)
  1127. ((TextBox)sender)/*this.textBox2*/.Text = "50";
  1128. }
  1129. /// <summary>
  1130. /// 限制只可以输入0-9数字以及退格键
  1131. /// </summary>
  1132. /// <param name="sender"></param>
  1133. /// <param name="e"></param>
  1134. private void textBoxWidth_KeyPress(object sender, KeyPressEventArgs e)
  1135. {
  1136. if (e.KeyChar != '\b')//这是允许输入退格键 
  1137.             {
  1138. int len = ((TextBox)sender)/*this.textBox1*/.Text.Length;
  1139. if (len < 1 && e.KeyChar == '0')
  1140. {
  1141. e.Handled = true;
  1142. }
  1143. else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 
  1144.                 {
  1145. e.Handled = true;
  1146. }
  1147. }
  1148. }
  1149. private void textBox10_KeyUp(object sender, KeyEventArgs e)
  1150. {
  1151. this.varifyTextBoxValue(sender);
  1152. this.trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
  1153. }
  1154. private void textBox3_KeyUp(object sender, KeyEventArgs e)
  1155. {
  1156. this.varifyTextBoxValue(sender);
  1157. this.trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
  1158. }
  1159. #endregion 控件监听事件
  1160. #region 矩形拖动
  1161. /// <summary>
  1162. /// 鼠标按下
  1163. /// </summary>
  1164. /// <param name="drawArea"></param>
  1165. /// <param name="e"></param>
  1166. protected override void OnMouseDown(object sender, MouseEventArgs e)
  1167. {
  1168. if (!CanUseMouseFunctions())
  1169. return;
  1170. try
  1171. {
  1172. //判断
  1173. //画上下辅助线
  1174. if (top == null || bottom == null)
  1175. {
  1176. this.documentWorkspace.Cursor = Cursors.Default;
  1177. ////在MouseDown处获知鼠标是否按下,并记录下此时的鼠标坐标值;
  1178. //if (e.Button == MouseButtons.Left)
  1179. //{
  1180. // mouseDownPoint.X = Cursor.Position.X; //注:全局变量mouseDownPoint前面已定义为Point类型
  1181. // mouseDownPoint.Y = Cursor.Position.Y;
  1182. // isSelected = true;
  1183. //}
  1184. return;
  1185. }
  1186. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1187. float mouse_x = point.X;
  1188. float mouse_y = point.Y;
  1189. if (mouse_y < top.startPoint.Y + 10 && mouse_y > top.startPoint.Y - 10)
  1190. {
  1191. //拖动上辅助线
  1192. mouseFlag = 1;
  1193. }
  1194. else if (mouse_y < bottom.startPoint.Y + 10 && mouse_y > bottom.startPoint.Y - 10)
  1195. {
  1196. //拖动下辅助线
  1197. mouseFlag = 2;
  1198. }
  1199. else
  1200. {
  1201. this.documentWorkspace.Cursor = Cursors.Default;
  1202. ////在MouseDown处获知鼠标是否按下,并记录下此时的鼠标坐标值;
  1203. //if (e.Button == MouseButtons.Left)
  1204. //{
  1205. // mouseDownPoint.X = Cursor.Position.X; //注:全局变量mouseDownPoint前面已定义为Point类型
  1206. // mouseDownPoint.Y = Cursor.Position.Y;
  1207. // isSelected = true;
  1208. //}
  1209. }
  1210. }
  1211. catch (Exception ex)
  1212. {
  1213. MessageBox.Show(ex.Message);
  1214. }
  1215. //if (operationK >= 0 && e.Button == MouseButtons.Left)
  1216. //{
  1217. // if (operationK == 0)
  1218. // {
  1219. // startPoint = endPoint = this.documentWorkspace.GetScalePoint(e.Location);
  1220. // //nowLine = new PointF[4];
  1221. // //nowLine[0] = startPoint;
  1222. // //nowLine[1] = endPoint;
  1223. // //pointList.Add(nowLine);
  1224. // }
  1225. //}
  1226. ////if (btnflag == 1)
  1227. ////{
  1228. //// System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1229. //// float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
  1230. //// if (mouse_y < line.startPoint.Y + 10 && mouse_y > line.startPoint.Y - 10)
  1231. //// {
  1232. //// //移动基体
  1233. //// btnflag = 2;//已经按下
  1234. //// this.documentWorkspace/*pictureBox1*/.Cursor = Cursors.SizeNS;
  1235. //// }
  1236. ////}
  1237. }
  1238. /// <summary>
  1239. /// 移动
  1240. /// </summary>
  1241. /// <param name="sender"></param>
  1242. /// <param name="e"></param>
  1243. protected override void onMouseMove(object sender, MouseEventArgs e)
  1244. {
  1245. if (!CanUseMouseFunctions())
  1246. return;
  1247. //拖动上下辅助线
  1248. if (mouseFlag == 1 || mouseFlag == 2)
  1249. {
  1250. //Mat ImageROI = null;
  1251. try
  1252. {
  1253. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1254. float mouse_x = point.X;
  1255. float mouse_y = point.Y;
  1256. ////移动上下辅助线
  1257. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1258. int margin = (int)mouse_y;
  1259. margin = Math.Min(this.bitmap.Height - 10, margin);
  1260. margin = Math.Max(10, margin);
  1261. if (mouseFlag == 1)
  1262. {
  1263. textBox4.Text = "" + margin;
  1264. top = new Line(new System.Drawing.Point(0, margin), new System.Drawing.Point(this.bitmap.Width, margin));
  1265. }
  1266. else if (mouseFlag == 2)
  1267. {
  1268. textBox6.Text = "" + (this.bitmap.Height - margin);
  1269. bottom = new Line(new System.Drawing.Point(0, margin), new System.Drawing.Point(this.bitmap.Width, margin));
  1270. }
  1271. if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
  1272. textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
  1273. if (tempHoleMat != null)
  1274. {
  1275. tempHoleMat.Dispose();
  1276. tempHoleMat = null;
  1277. }
  1278. //contours = null;//###########################################################################
  1279. ////pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
  1280. ////Pen blueLinePen = new Pen(Color.Blue, zoom);
  1281. ////drawg.DrawLine(blueLinePen, top.startPoint, top.endPoint);
  1282. ////drawg.DrawLine(blueLinePen, bottom.startPoint, bottom.endPoint);
  1283. ////pictureBox1.Image = map;
  1284. this.documentWorkspace.Refresh();
  1285. }
  1286. catch
  1287. {
  1288. }
  1289. finally
  1290. {
  1291. //ImageROI.Dispose();
  1292. //GC.Collect();
  1293. }
  1294. return;
  1295. }
  1296. if (btnflag == 2)
  1297. {
  1298. ////Mat ImageROI = null;
  1299. //try
  1300. //{
  1301. // //float mouse_y = ((e.Y - panel1.Location.Y + 12) * zoom - imgY); //to test at 20191231
  1302. // //移动辅助线
  1303. // drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1304. //}
  1305. //catch (Exception b)
  1306. //{
  1307. // //MessageBox.Show(b.Message);//解决不断弹出提示语的bug
  1308. //}
  1309. //finally
  1310. //{
  1311. // //ImageROI.Dispose();
  1312. // //GC.Collect();
  1313. //}
  1314. return;
  1315. }
  1316. if (btnflag == 1)
  1317. {
  1318. try
  1319. {
  1320. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1321. float mouse_x = point.X;
  1322. float mouse_y = point.Y;
  1323. if ((mouse_y < top.startPoint.Y + 10 && mouse_y > top.startPoint.Y - 10) || (mouse_y < bottom.startPoint.Y + 10 && mouse_y > bottom.startPoint.Y - 10))
  1324. {
  1325. //移动辅助线
  1326. this.documentWorkspace.Cursor = Cursors.SizeNS;
  1327. }
  1328. else
  1329. {
  1330. this.documentWorkspace.Cursor = Cursors.Default;
  1331. }
  1332. }
  1333. catch (Exception ex)
  1334. {
  1335. //MessageBox.Show(ex.Message);//解决不断弹出提示语的bug
  1336. }
  1337. }
  1338. else
  1339. {
  1340. this.documentWorkspace.Cursor = Cursors.Default;
  1341. }
  1342. //if (operationK >= 0 && e.Button == MouseButtons.Left)
  1343. //{
  1344. // if (operationK == 0)
  1345. // {
  1346. // //this.endPoint = this.documentWorkspace.GetScalePoint(e.Location);
  1347. // //pointList[lineCount][1] = endPoint;
  1348. // }
  1349. // //this.documentWorkspace.Refresh();
  1350. //}
  1351. ////if (btnflag == 2)
  1352. ////{
  1353. //// //Mat ImageROI = null;
  1354. //// try
  1355. //// {
  1356. //// if (line == null)
  1357. //// {
  1358. //// btnflag = 1;
  1359. //// System.Drawing.Point point1 = new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130);
  1360. //// System.Drawing.Point point2 = new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130);
  1361. //// line = new Line(point1, point2);
  1362. //// //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
  1363. //// }
  1364. //// //float mouse_y = ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
  1365. //// //mouse_y = Math.Min(lab1Img.Height - 10, mouse_y);
  1366. //// //mouse_y = Math.Max(10, mouse_y);
  1367. //// System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1368. //// //移动基体
  1369. //// //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1370. //// line.startPoint.Y = (int)point.Y;// mouse_y;
  1371. //// line.endPoint.Y = (int)point.Y;// mouse_y;
  1372. //// //drawg.DrawLine(yellowPen, line.startPoint, line.endPoint);
  1373. //// //pictureBox1.Image = map;
  1374. //// this.documentWorkspace.Refresh();
  1375. //// }
  1376. //// catch
  1377. //// {
  1378. //// }
  1379. //// finally
  1380. //// {
  1381. //// //ImageROI.Dispose();
  1382. //// //GC.Collect();
  1383. //// }
  1384. //// return;
  1385. ////}
  1386. ////if (btnflag == 1)
  1387. ////{
  1388. //// System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1389. //// float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
  1390. //// if (mouse_y < line.startPoint.Y + 10 && mouse_y > line.startPoint.Y - 10)
  1391. //// {
  1392. //// this.documentWorkspace.Cursor = Cursors.SizeNS;
  1393. //// //pictureBox1.Cursor = Cursors.SizeNS;
  1394. //// }
  1395. //// else
  1396. //// {
  1397. //// this.documentWorkspace.Cursor = Cursors.Default;
  1398. //// ////图片平移,在MouseMove处添加拖动函数操作
  1399. //// //if (isSelected && IsMouseInPanel()) //确定已经激发MouseDown事件,和鼠标在picturebox的范围内
  1400. //// //{
  1401. //// // this.pictureBox1.Left = this.pictureBox1.Left + (Cursor.Position.X - mouseDownPoint.X);
  1402. //// // this.pictureBox1.Top = this.pictureBox1.Top + (Cursor.Position.Y - mouseDownPoint.Y);
  1403. //// // mouseDownPoint.X = Cursor.Position.X;
  1404. //// // mouseDownPoint.Y = Cursor.Position.Y;
  1405. //// //}
  1406. //// //else
  1407. //// //{
  1408. //// // pictureBox1.Cursor = Cursors.Default;
  1409. //// //}
  1410. //// }
  1411. ////}
  1412. }
  1413. /// <summary>
  1414. /// 鼠标抬起
  1415. /// </summary>
  1416. /// <param name="sender"></param>
  1417. /// <param name="e"></param>
  1418. protected override void onMouseUp(object sender, MouseEventArgs e)
  1419. {
  1420. if (!CanUseMouseFunctions())
  1421. return;
  1422. mouseFlag = 0;
  1423. //if (operationK == 0)
  1424. //{
  1425. // if (startPoint != null && endPoint != null && startPoint != endPoint)
  1426. // {
  1427. // // lineCount++;
  1428. // // AddContentToDataGridView();
  1429. // //}
  1430. // //else
  1431. // //{
  1432. // // pointList.RemoveAt(pointList.Count - 1);
  1433. // }
  1434. // //this.documentWorkspace.Refresh();
  1435. //}
  1436. //if (btnflag == 2)
  1437. //{
  1438. // btnflag = 1;
  1439. //}
  1440. }
  1441. #endregion
  1442. #region 分析结果的方法
  1443. /// <summary>
  1444. /// 点击保存结果按钮,用来返回需要新增的一行数据
  1445. /// </summary>
  1446. /// <param name="tag"></param>
  1447. /// <param name="imgName"></param>
  1448. /// <returns></returns>
  1449. protected override DataTable toInsertTableRow(string tag, string imgName)
  1450. {
  1451. DataTable dt = new DataTable(tag);
  1452. dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
  1453. dt.Columns.Add(PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.holearea.text"));
  1454. dt.Columns.Add(PdnResources.GetString("Menu.Areaofselectedarea.text"));
  1455. dt.Columns.Add(PdnResources.GetString("Menu.Percentageofholevolume.text"));
  1456. //dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
  1457. //dt.Columns.Add(PdnResources.GetString("Menu.Averagethickness(μm).text"));
  1458. //dt.Columns.Add(PdnResources.GetString("Menu.standarddeviation.text"));
  1459. //dt.Columns.Add(PdnResources.GetString("Menu.confidencebound.text"));
  1460. DataRow dataRow = dt.NewRow();
  1461. dataRow[PdnResources.GetString("Menu.picture.Text")] = imgName;
  1462. dataRow[PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.holearea.text")] = res_area1;
  1463. dataRow[PdnResources.GetString("Menu.Areaofselectedarea.text")] = res_areaTotal;
  1464. dataRow[PdnResources.GetString("Menu.Percentageofholevolume.text")] = res_percent;
  1465. //dataRow[PdnResources.GetString("Menu.Averagethickness(μm).text")] = res_perL;
  1466. //dataRow[PdnResources.GetString("Menu.standarddeviation.text")] = res_s1;
  1467. //dataRow[PdnResources.GetString("Menu.confidencebound.text")] = res_c1;
  1468. dt.Rows.Add(dataRow);
  1469. return dt;
  1470. }
  1471. /// <summary>
  1472. /// 计算结果是否存在
  1473. /// </summary>
  1474. /// <returns>返回是否可以计算和保存结果</returns>
  1475. protected override bool resultCalculateExist()
  1476. {
  1477. return tempHoleMat != null;// vlines.Count > 0;
  1478. }
  1479. /// <summary>
  1480. /// 拼接中间数据
  1481. /// </summary>
  1482. /// <returns></returns>
  1483. protected override List<List<string>> buildTempDataList()
  1484. {
  1485. return null;
  1486. //List<List<string>> dataList = new List<List<string>>();
  1487. //List<string> columnName = new List<string>();
  1488. //columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  1489. //columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.Xoordinate.Text"));
  1490. //columnName.Add(PdnResources.GetString("Menu.ToYcoordinate.Text"));
  1491. //columnName.Add(PdnResources.GetString("Menu.ToYcoonate.Text"));
  1492. //columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.MeasureAction.MeasureLength.Text"));
  1493. //columnName.Add(PdnResources.GetString("Menu.Physicallength.text"));//addAction:这里
  1494. //dataList.Add(columnName);
  1495. //int index = 0;
  1496. //////厚度的数组
  1497. ////int[] thickness = new int[vlines.Count()];
  1498. ////循环辅助线的集合
  1499. //if (this.vlines.Count > 0)
  1500. //{
  1501. // //循环每条线,找到和轮廓的交点
  1502. // for (int i = 0; i < vlines.Count(); i++)
  1503. // {
  1504. // ////计算厚度,像素
  1505. // //thickness[i] = lineNum - vlines[i].startPoint.Y;
  1506. // List<string> strList = new List<string>();
  1507. // strList.Add((++index).ToString());
  1508. // strList.Add(vlines[i].startPoint.X.ToString());
  1509. // strList.Add(vlines[i].startPoint.Y.ToString());
  1510. // strList.Add(lineNum.ToString());
  1511. // strList.Add((lineNum - vlines[i].startPoint.Y).ToString());
  1512. // strList.Add(((lineNum - vlines[i].startPoint.Y) * physical_length).ToString());
  1513. // dataList.Add(strList);
  1514. // }
  1515. //}
  1516. //return dataList;
  1517. }
  1518. /// <summary>
  1519. /// 计算结果
  1520. /// </summary>
  1521. /// <param name="sender"></param>
  1522. /// <param name="e"></param>
  1523. protected override void buttonCalculate_Click(object sender, EventArgs e)
  1524. {
  1525. if (top == null || bottom == null)
  1526. {//#21396
  1527. MessageBox.Show("请先绘制区域"/*PdnResources.GetString("Menu.Pleaseselectareafirst.text")*/);
  1528. return;
  1529. }
  1530. int result = 0;
  1531. if (!int.TryParse(textBox4.Text, out result))
  1532. {
  1533. MessageBox.Show(PdnResources.GetString("Menu.Topauxiliarylinetopdistanceinputformaterror.text"));
  1534. return;
  1535. }
  1536. if (int.Parse(textBox4.Text) > this.bitmap/*lab1Img*/.Height * this.physical_length)
  1537. {
  1538. MessageBox.Show(PdnResources.GetString("Menu.Thetopdistanceoftghtoftheimage.text"));
  1539. return;
  1540. }
  1541. int result1 = 0;
  1542. if (!int.TryParse(textBox6.Text, out result1))
  1543. {
  1544. MessageBox.Show(PdnResources.GetString("Menu.Errorininputedistance.text"));
  1545. return;
  1546. }
  1547. if (int.Parse(textBox6.Text) > this.bitmap.Height * this.physical_length)
  1548. {
  1549. MessageBox.Show(PdnResources.GetString("Menu.Thebottomdistanheightoftheimage.text"));
  1550. return;
  1551. }
  1552. if (int.Parse(textBox4.Text) > this.bitmap/*lab1Img*/.Height * this.physical_length - int.Parse(textBox6.Text))
  1553. {
  1554. MessageBox.Show(PdnResources.GetString("Menu.Thelowerauxiliaryluxiliaryline.text"));
  1555. return;
  1556. }
  1557. if (!resultCalculateExist())
  1558. {
  1559. MessageBox.Show("请先进行寻找孔隙操作");//PdnResources.GetString("Menu.Pleaselookfortheoutlinefirst.text") ;//点击绘制轮廓
  1560. return;
  1561. //MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
  1562. //return;
  1563. }
  1564. try
  1565. {
  1566. res_areaTotal = this.bitmap.Width * (bottom.endPoint.Y - top.startPoint.Y);
  1567. //简单计算孔隙面积和总面积等
  1568. res_area1 = 0;
  1569. int Rows = tempHoleMat.Rows;
  1570. int Cols = tempHoleMat.Cols;
  1571. int[] point = new int[2];
  1572. //多通道图像的格式化
  1573. for (point[1] = 0; point[1] < Cols; point[1]++)
  1574. {
  1575. for (point[0] = top.startPoint.Y/*0*/; point[0] < bottom.endPoint.Y/*Rows*/; point[0]++)
  1576. {
  1577. if (tempHoleMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  1578. res_area1 += 1;
  1579. }
  1580. }
  1581. res_percent = res_area1 * 100 / res_areaTotal;
  1582. calculate1d = true;
  1583. this.documentWorkspace.Refresh();
  1584. double physical_length11 = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  1585. res_area1 = res_area1 * physical_length11 * physical_length11;
  1586. res_areaTotal = res_areaTotal * physical_length11 * physical_length11;
  1587. this.label2.Text = this.resShow(res_area1.ToString());
  1588. this.label7.Text = this.resShow(res_areaTotal.ToString());
  1589. this.label14.Text = this.resShow(res_percent.ToString()) + " %";
  1590. }
  1591. catch (Exception eb)
  1592. {
  1593. MessageBox.Show(eb.Message);
  1594. }
  1595. finally
  1596. {
  1597. }
  1598. ////厚度的数组
  1599. //int[] thickness = new int[vlines.Count()];
  1600. ////循环每条线,找到和轮廓的交点
  1601. //for (int i = 0; i < vlines.Count(); i++)
  1602. //{
  1603. // //计算厚度,像素
  1604. // thickness[i] = lineNum - vlines[i].startPoint.Y;
  1605. //}
  1606. ////平均涂层厚度
  1607. //res_perL = thickness.Sum() * physical_length / Math.Max(1, thickness.Length);//考虑使用 thickness.Average
  1608. ////计算偏差
  1609. //double sqrtSum = 0;
  1610. //for (int i = 0; i < vlines.Count(); i++)
  1611. //{
  1612. // sqrtSum += Math.Pow(thickness[i] * physical_length - res_perL, 2.0);
  1613. //}
  1614. ////标准偏差
  1615. //res_s1 = Math.Sqrt(sqrtSum / Math.Max(1, vlines.Count() - 1));
  1616. ////置信区间
  1617. //res_c1 = 2 * res_s1 / Math.Sqrt(Math.Max(1, vlines.Count()));
  1618. //this.label2.Text = this.resShow(res_perL.ToString());
  1619. //this.label7.Text = this.resShow(res_s1.ToString());
  1620. //this.label14.Text = this.resShow(res_c1.ToString());
  1621. //calculate1d = true;
  1622. }
  1623. /// <summary>
  1624. /// 记录输入文字改变的状态
  1625. /// </summary>
  1626. int textBoxChanged = -1;
  1627. /// <summary>
  1628. /// 上辅助线居顶距离改变
  1629. /// </summary>
  1630. /// <param name="sender"></param>
  1631. /// <param name="e"></param>
  1632. private void TextBox4_TextChanged(object sender, KeyEventArgs e)
  1633. {
  1634. if (this.bitmap == null)
  1635. {
  1636. return;
  1637. }
  1638. if (top == null || bottom == null)
  1639. {
  1640. return;
  1641. }
  1642. int result = 0;
  1643. if (!int.TryParse(textBox4.Text, out result))
  1644. {
  1645. return;
  1646. }
  1647. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1648. //drawrectflag = 0;
  1649. //contours = null;//##
  1650. if (tempHoleMat != null)
  1651. {
  1652. tempHoleMat.Dispose();
  1653. tempHoleMat = null;
  1654. }
  1655. //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
  1656. if ((int)(Convert.ToInt32(textBox4.Text) / this.physical_length) > bottom.endPoint.Y)
  1657. {
  1658. textBox4.Text = (bottom.endPoint.Y * this.physical_length).ToString();
  1659. }
  1660. top = new Line(new System.Drawing.Point(0, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)));
  1661. if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
  1662. textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
  1663. this.documentWorkspace.Refresh();
  1664. }
  1665. /// <summary>
  1666. /// 下辅助线居底距离改变
  1667. /// </summary>
  1668. /// <param name="sender"></param>
  1669. /// <param name="e"></param>
  1670. private void TextBox6_TextChanged(object sender, KeyEventArgs e)
  1671. {
  1672. if (this.bitmap == null)
  1673. {
  1674. return;
  1675. }
  1676. if (top == null || bottom == null)
  1677. {
  1678. return;
  1679. }
  1680. int result = 0;
  1681. if (!int.TryParse(textBox6.Text, out result))
  1682. {
  1683. return;
  1684. }
  1685. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1686. //drawrectflag = 0;
  1687. //contours = null;//##
  1688. if (tempHoleMat != null)
  1689. {
  1690. tempHoleMat.Dispose();
  1691. tempHoleMat = null;
  1692. }
  1693. //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
  1694. if (this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length) < top.endPoint.Y)
  1695. {
  1696. textBox6.Text = ((this.bitmap/*lab1Img*/.Height - top.endPoint.Y) * this.physical_length).ToString();
  1697. }
  1698. bottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap.Width, this.bitmap.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)));
  1699. if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
  1700. textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
  1701. //Pen blueLinePen = new Pen(Color.Blue, zoom);
  1702. //drawg.DrawLine(blueLinePen, top.startPoint, top.endPoint);
  1703. //drawg.DrawLine(blueLinePen, bottom.startPoint, bottom.endPoint);
  1704. //pictureBox1.Image = map;
  1705. this.documentWorkspace.Refresh();
  1706. }
  1707. /// <summary>
  1708. /// 辅助线间距改变
  1709. /// </summary>
  1710. /// <param name="sender"></param>
  1711. /// <param name="e"></param>
  1712. private void textBox1_KeyUp(object sender, KeyEventArgs e)
  1713. {
  1714. if (this.bitmap == null)
  1715. {
  1716. return;
  1717. }
  1718. if (top == null || bottom == null)
  1719. {
  1720. return;
  1721. }
  1722. int result = 0;
  1723. if (!int.TryParse(textBox1.Text, out result))
  1724. {
  1725. return;
  1726. }
  1727. if (this.bitmap.Height * this.physical_length < result)
  1728. {
  1729. result = (int)(this.bitmap.Height * this.physical_length);
  1730. textBox1.Text = ((int)result).ToString();
  1731. textBox4.Text = "0";
  1732. textBox6.Text = "0";
  1733. if (tempHoleMat != null)
  1734. {
  1735. tempHoleMat.Dispose();
  1736. tempHoleMat = null;
  1737. }
  1738. //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
  1739. top = new Line(new System.Drawing.Point(0, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)));
  1740. bottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)));
  1741. this.documentWorkspace.Refresh();
  1742. return;
  1743. }
  1744. textBox1.Text = ((int)result).ToString();
  1745. textBox4.Text = ((int)((this.bitmap.Height * this.physical_length - result) / 2)).ToString();
  1746. textBox6.Text = ((int)((this.bitmap.Height * this.physical_length - result) / 2)).ToString();
  1747. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1748. //drawrectflag = 0;
  1749. //contours = null;//##
  1750. if (tempHoleMat != null)
  1751. {
  1752. tempHoleMat.Dispose();
  1753. tempHoleMat = null;
  1754. }
  1755. //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
  1756. top = new Line(new System.Drawing.Point(0, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, (int)(Convert.ToInt32(textBox4.Text) / this.physical_length)));
  1757. bottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length)));
  1758. this.documentWorkspace.Refresh();
  1759. }
  1760. /// <summary>
  1761. /// 小数点位数变化时刷新界面的数据
  1762. /// </summary>
  1763. protected override void RefreshDataGridView1()
  1764. {
  1765. if (calculate1d)
  1766. {
  1767. this.label2.Text = this.resShow(res_area1.ToString());
  1768. this.label7.Text = this.resShow(res_areaTotal.ToString());
  1769. this.label14.Text = this.resShow(res_percent.ToString());
  1770. }
  1771. }
  1772. #endregion 分析结果的方法
  1773. #region 参数保存及提取
  1774. /// <summary>
  1775. /// 保存参数的key,value和type
  1776. /// </summary>
  1777. /// <param name="param_key"></param>
  1778. /// <param name="param_value"></param>
  1779. /// <param name="param_type"></param>
  1780. private void saveParamValue(string param_key, string param_value, int param_type)
  1781. {
  1782. bool foundItem = false;
  1783. foreach (var item in this.analysisModel.ListParam)
  1784. {
  1785. if (item.param_key.Equals(param_key) && item.menuId == this.menuId)
  1786. {
  1787. item.param_value = param_value;
  1788. item.setValue();
  1789. foundItem = true;
  1790. break;
  1791. }
  1792. }
  1793. if (!foundItem)
  1794. {
  1795. GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
  1796. analysisItem.menuId = this.menuId;
  1797. analysisItem.param_key = param_key;
  1798. analysisItem.param_type = param_type;
  1799. analysisItem.param_value = param_value;
  1800. analysisItem.setValue();
  1801. this.analysisModel.ListParam.Add(analysisItem);
  1802. }
  1803. }
  1804. /// <summary>
  1805. /// 保存界面中的参数到model
  1806. /// </summary>
  1807. private void saveDialogParamValues()
  1808. {
  1809. saveParamValue(ParamKey_Report, checkBox_generateReport_opensetting.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//报告设置
  1810. saveParamValue(ParamKey_PoreColour, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//轮廓颜色
  1811. saveParamValue(ParamKey_UpperRegionColour, panel3.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//上区颜色
  1812. saveParamValue(ParamKey_UpperRegionWidth, textBox10.Text, (int)Base.Dtryt.ItemString);//上区颜色线宽
  1813. saveParamValue(ParamKey_LowerRegionColour, panel4.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//下区颜色
  1814. saveParamValue(ParamKey_LowerRegionWidth, textBox3.Text, (int)Base.Dtryt.ItemString);//下区颜色线宽
  1815. saveParamValue(ParamKey_DecimalPlace, numericUpDown1_0 != null ? numericUpDown1_0.Value.ToString() : "", (int)Base.Dtryt.Decimal);//保留小数位数
  1816. }
  1817. /// <summary>
  1818. /// 获取保存的参数
  1819. /// </summary>
  1820. private void GetListParamModel()
  1821. {
  1822. if (this.analysisModel != null)
  1823. {
  1824. for (int i = 0; i < this.analysisModel.ListParam.Count; i++)
  1825. {
  1826. switch (this.analysisModel.ListParam[i].param_key)
  1827. {
  1828. case ParamKey_Report:
  1829. checkBox_generateReport_opensetting.Checked = (Boolean)this.analysisModel.ListParam[i].value;
  1830. break;
  1831. case ParamKey_PoreColour:
  1832. panel1.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1833. break;
  1834. case ParamKey_UpperRegionColour:
  1835. panel3.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1836. break;
  1837. case ParamKey_UpperRegionWidth:
  1838. textBox10.Text = this.analysisModel.ListParam[i].value.ToString();
  1839. trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
  1840. break;
  1841. case ParamKey_LowerRegionColour:
  1842. panel4.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1843. break;
  1844. case ParamKey_LowerRegionWidth:
  1845. textBox3.Text = this.analysisModel.ListParam[i].value.ToString();
  1846. trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
  1847. break;
  1848. case ParamKey_DecimalPlace:
  1849. numericUpDown1_0.Value = decimal.Parse(this.analysisModel.ListParam[i].param_value);
  1850. break;
  1851. }
  1852. }
  1853. }
  1854. }
  1855. /// <summary>
  1856. /// 关闭窗体时保存参数
  1857. /// </summary>
  1858. /// <param name="sender"></param>
  1859. /// <param name="e"></param>
  1860. private void TABM2Dialog_FormClosing(object sender, FormClosingEventArgs e)
  1861. {
  1862. this.saveDialogParamValues();
  1863. //xml保存路径
  1864. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
  1865. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  1866. foreach (var analysisItem in this.analysisModel.ListParam)
  1867. {
  1868. bool foundItem = false;
  1869. foreach (var item in analysisModelXml.ListParam)
  1870. {
  1871. if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId)
  1872. {
  1873. item.param_value = analysisItem.param_value;
  1874. foundItem = true;
  1875. break;
  1876. }
  1877. }
  1878. if (!foundItem)
  1879. analysisModelXml.ListParam.Add(analysisItem.cloneModel());
  1880. }
  1881. //按路径和名称保存xml文件
  1882. string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainSizeAnalysisModel>(analysisModelXml);
  1883. //保存xml
  1884. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create);
  1885. }
  1886. #endregion
  1887. }
  1888. }