| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723 |
- using Metis.ParameterSet;
- using OpenCvSharp;
- using PaintDotNet.Base.CommTool;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- namespace PaintDotNet.DedicatedAnalysis.NonferrousMetals.YYT098814_2016
- {
- internal class TABM1Dialog : NonFMetalsStandardDialog
- {
- #region 属性
- ///// <summary>
- ///// 调色板
- ///// </summary>
- //private ColorsForm colorsFormGrid;
- //private Panel panelC;
- /// <summary>
- /// 是否调用了灰度化的算法
- /// </summary>
- private bool grayBitmap = false;
- /// <summary>
- /// 记录鼠标最后所在的点的y坐标
- /// </summary>
- int lineNum = 0;
- /// <summary>
- /// 竖直的辅助线
- /// </summary>
- List<Line> vlines = new List<Line>();
- /// <summary>
- /// 基体平行线
- /// </summary>
- Line line;
- /// <summary>
- /// 1显示基体界面 2移动基体界面 0隐藏基体界面
- /// </summary>
- int btnflag = 0;
- /// <summary>
- /// 轮廓的线
- /// </summary>
- System.Drawing.Point[][] tempLine;
- /// <summary>
- /// 平均涂层厚度
- /// </summary>
- double res_perL;
- /// <summary>
- /// 标准偏差
- /// </summary>
- double res_s1;
- /// <summary>
- /// 置信区间
- /// </summary>
- double res_c1;
- /// <summary>
- /// 选择标尺的物理长度(微米/像素)
- /// </summary>
- double physical_length = 1;
- // <summary>
- /// 保存窗口参数
- /// </summary>
- private GrainSizeAnalysisModel analysisModel;
- private const string ParamKey_Report = "report";//报告设置
- private const string ParamKey_OutlineColour = "outlineColour";//轮廓颜色
- private const string ParamKey_OutlineWidth = "outlineWidth";//轮廓线宽
- private const string ParamKey_BaseColour = "baseColour";//基线颜色
- private const string ParamKey_BaseWidth = "baseWidth";//基线线宽
- private const string ParamKey_GuideColour = "guideColour";//辅助线颜色
- private const string ParamKey_GuideWidth = "guideWidth";//辅助线线宽
- private const string ParamKey_GuideNumber = "guideNumber";//辅助线条数
- private const string ParamKey_DecimalPlace = "decimalPlace";//保留小数位数
- #endregion 属性
- #region 组件
- private GroupBox groupBox_Basicoperation;
- private Button button14;
- private Button button17;
- private Button button2;
- private Button button15;
- private Button button13;
- private Button button10;
- private Button button3;
- private Button button4;
- private GroupBox groupBox10;
- private Panel panel1;
- private TrackBar trackBar5;
- private TextBox textBox9;
- private Label label3;
- private Label label5;
- private GroupBox groupBox6;
- private Panel panel3;
- private TrackBar trackBar4;
- private TextBox textBox10;
- private Label label4;
- private Label label6;
- private GroupBox groupBox7;
- private Panel panel4;
- private TextBox textBox6;
- private TextBox textBox4;
- private TrackBar trackBar3;
- private TextBox textBox3;
- private Label label15;
- private Label label16;
- private Label label17;
- private Label label18;
- private GroupBox groupBox8;
- private Label label14;
- private Label label7;
- private Label label2;
- private Label label13;
- private Label label12;
- private Label label11;
- private Button button5;
- #endregion 组件
- #region 构造函数
- public TABM1Dialog(AppWorkspace appWorkspace, int menuId) : base(appWorkspace, menuId)
- {
- Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
- this.physical_length = measurementUnitDictionary[MeasurementUnit.Micron];
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
- GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
- this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
- foreach (var item in this.analysisModel.ListParam)
- item.setValue();
- GetListParamModel();
- ////
- ////初始化色板
- ////
- //this.colorsFormGrid = new ColorsForm();
- //this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
- //this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
- InitGridHeader();
- }
- /// <summary>
- /// 初始化表头
- /// </summary>
- private void InitGridHeader()
- {
- DataGridViewTextBoxColumn Column2_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column3_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column4_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
- Column2_total.Name = "Column2_total";
- Column2_total.ReadOnly = true;
- Column3_total.Name = "Column3_total";
- Column3_total.ReadOnly = true;
- Column4_total.Name = "Column4_total";
- Column4_total.ReadOnly = true;
- Column2_total.HeaderText = PdnResources.GetString("Menu.Averagethickness(μm).text");;
- Column3_total.HeaderText = PdnResources.GetString("Menu.standarddeviation.text");
- Column4_total.HeaderText = PdnResources.GetString("Menu.confidencebound.text");
- this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- Column2_total,
- Column3_total,
- Column4_total});
- this.dataGridView_Total.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView_Total.Columns[0].ReadOnly = true;
- this.dataGridView_Total.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView_Total.Columns[1].ReadOnly = true;
- this.dataGridView_Total.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView_Total.Columns[2].ReadOnly = true;
- DataGridViewTextBoxColumn Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- Column1.Name = "Column1";
- Column1.ReadOnly = true;
- Column2.Name = "Column2";
- Column2.ReadOnly = true;
- Column3.Name = "Column3";
- Column3.ReadOnly = true;
- Column4.Name = "Column4";
- Column4.ReadOnly = true;
- Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
- Column2.HeaderText = PdnResources.GetString("Menu.Averagethickness(μm).text");
- Column3.HeaderText = PdnResources.GetString("Menu.standarddeviation.text");
- Column4.HeaderText = PdnResources.GetString("Menu.confidencebound.text");
- this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- Column1,
- Column2,
- Column3,
- Column4});
- Column1.Width = 195;
- Column2.Width = 165;
- Column3.Width = 165;
- Column4.Width = 165;
- this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[0].ReadOnly = true;
- this.dataGridView2.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[1].ReadOnly = true;
- this.dataGridView2.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[2].ReadOnly = true;
- this.dataGridView2.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[3].ReadOnly = true;
- }
- #endregion 构造函数
- #region 初始化组件和实现组件事件
- private void InitializeLanguageText()
- {
- this.label16.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.label15.Text = PdnResources.GetString("Menu.spacing.text") + ":";
- this.groupBox7.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text");
- this.label6.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.label4.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.groupBox6.Text = PdnResources.GetString("Menu.Baselinesettings.text");
- this.label5.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.label3.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.groupBox10.Text = PdnResources.GetString("Menu.contour.text");
- this.button2.Text = PdnResources.GetString("Menu.reinformation.text");
- this.button4.Text = PdnResources.GetString("Menu.Image.Grayscale.Text");
- this.button3.Text = PdnResources.GetString("Menu.BinaryAction.ErosionExtraction.Text");
- this.button10.Text = PdnResources.GetString("Menu.BinaryAction.DilationExtraction.Text");
- this.button13.Text = PdnResources.GetString("Menu.Drawauxiliarylines.text");
- this.button15.Text = PdnResources.GetString("Menu.searchcontour.text");
- this.button17.Text = PdnResources.GetString("Menu.auto-adjust.text");
- this.button14.Text = PdnResources.GetString("Menu.easemodifytheoutline.Text");
- this.button5.Text = PdnResources.GetString("Menu.reinformation.text");
- this.groupBox_Basicoperation.Text = PdnResources.GetString("Menu.Basicoperation.text");
- this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.veragecoatingthickness.Text") + ")";
- this.label11.Text = PdnResources.GetString("Menu.Averagethickness(μm).text") + ":";
- this.label12.Text = PdnResources.GetString("Menu.standarddeviation.text") + ":";
- this.label13.Text = PdnResources.GetString("Menu.confidencebound.text") + ":";
- this.groupBox8.Text = PdnResources.GetString("Menu.result.text");
- this.label18.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.label17.Text = PdnResources.GetString("Menu.Numberof.text") + ":";
- }
- private void InitializeComponent()
- {
- this.groupBox_Basicoperation = new System.Windows.Forms.GroupBox();
- this.button5 = new System.Windows.Forms.Button();
- this.button14 = new System.Windows.Forms.Button();
- this.button17 = new System.Windows.Forms.Button();
- this.button15 = new System.Windows.Forms.Button();
- this.button13 = new System.Windows.Forms.Button();
- this.button10 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.groupBox10 = new System.Windows.Forms.GroupBox();
- this.panel1 = new System.Windows.Forms.Panel();
- this.trackBar5 = new System.Windows.Forms.TrackBar();
- this.textBox9 = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.groupBox6 = new System.Windows.Forms.GroupBox();
- this.panel3 = new System.Windows.Forms.Panel();
- this.trackBar4 = new System.Windows.Forms.TrackBar();
- this.textBox10 = new System.Windows.Forms.TextBox();
- this.label4 = new System.Windows.Forms.Label();
- this.label6 = new System.Windows.Forms.Label();
- this.groupBox7 = new System.Windows.Forms.GroupBox();
- this.panel4 = new System.Windows.Forms.Panel();
- this.textBox6 = new System.Windows.Forms.TextBox();
- this.textBox4 = new System.Windows.Forms.TextBox();
- this.trackBar3 = new System.Windows.Forms.TrackBar();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.label15 = new System.Windows.Forms.Label();
- this.label16 = new System.Windows.Forms.Label();
- this.label17 = new System.Windows.Forms.Label();
- this.label18 = new System.Windows.Forms.Label();
- this.groupBox8 = new System.Windows.Forms.GroupBox();
- this.label14 = new System.Windows.Forms.Label();
- this.label7 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label13 = new System.Windows.Forms.Label();
- this.label12 = new System.Windows.Forms.Label();
- this.label11 = new System.Windows.Forms.Label();
- this.groupBox_img.SuspendLayout();
- this.groupBox_report.SuspendLayout();
- this.groupBox_analysisResult1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
- this.groupBox_Basicoperation.SuspendLayout();
- this.groupBox10.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar5)).BeginInit();
- this.groupBox6.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit();
- this.groupBox7.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
- this.groupBox8.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox_Basicoperation
- //
- this.groupBox_Basicoperation.Controls.Add(this.button5);
- this.groupBox_Basicoperation.Controls.Add(this.button14);
- this.groupBox_Basicoperation.Controls.Add(this.button17);
- this.groupBox_Basicoperation.Controls.Add(this.button15);
- this.groupBox_Basicoperation.Controls.Add(this.button13);
- this.groupBox_Basicoperation.Controls.Add(this.button10);
- this.groupBox_Basicoperation.Controls.Add(this.button3);
- this.groupBox_Basicoperation.Controls.Add(this.button4);
- this.groupBox_Basicoperation.Location = new System.Drawing.Point(180, 317);
- this.groupBox_Basicoperation.Name = "groupBox_Basicoperation";
- this.groupBox_Basicoperation.Size = new System.Drawing.Size(353, 66);
- this.groupBox_Basicoperation.TabIndex = 39;
- this.groupBox_Basicoperation.TabStop = false;
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(12, 39);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 9;
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // button14
- //
- this.button14.Location = new System.Drawing.Point(270, 39);
- this.button14.Name = "button14";
- this.button14.Size = new System.Drawing.Size(75, 23);
- this.button14.TabIndex = 8;
- this.button14.UseVisualStyleBackColor = true;
- this.button14.Click += new System.EventHandler(this.button14_Click);
- //
- // button17
- //
- this.button17.Location = new System.Drawing.Point(183, 39);
- this.button17.Name = "button17";
- this.button17.Size = new System.Drawing.Size(75, 23);
- this.button17.TabIndex = 7;
- this.button17.UseVisualStyleBackColor = true;
- this.button17.Click += new System.EventHandler(this.button17_Click);
- //
- // button15
- //
- this.button15.Location = new System.Drawing.Point(270, 16);
- this.button15.Name = "button15";
- this.button15.Size = new System.Drawing.Size(75, 23);
- this.button15.TabIndex = 5;
- this.button15.UseVisualStyleBackColor = true;
- this.button15.Click += new System.EventHandler(this.button15_Click);
- //
- // button13
- //
- this.button13.Location = new System.Drawing.Point(96, 39);
- this.button13.Name = "button13";
- this.button13.Size = new System.Drawing.Size(75, 23);
- this.button13.TabIndex = 3;
- this.button13.UseVisualStyleBackColor = true;
- this.button13.Click += new System.EventHandler(this.button13_Click);
- //
- // button10
- //
- this.button10.Location = new System.Drawing.Point(183, 16);
- this.button10.Name = "button10";
- this.button10.Size = new System.Drawing.Size(75, 23);
- this.button10.TabIndex = 2;
- this.button10.UseVisualStyleBackColor = true;
- this.button10.Click += new System.EventHandler(this.button10_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(96, 16);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 1;
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(12, 16);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 0;
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(96, 39);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 6;
- this.button2.UseVisualStyleBackColor = true;
- //
- // groupBox10
- //
- this.groupBox10.Controls.Add(this.panel1);
- this.groupBox10.Controls.Add(this.trackBar5);
- this.groupBox10.Controls.Add(this.textBox9);
- this.groupBox10.Controls.Add(this.label3);
- this.groupBox10.Controls.Add(this.label5);
- this.groupBox10.Location = new System.Drawing.Point(178, 383);
- this.groupBox10.Name = "groupBox10";
- this.groupBox10.Size = new System.Drawing.Size(354, 41);
- this.groupBox10.TabIndex = 42;
- this.groupBox10.TabStop = false;
- //
- // panel1
- //
- this.panel1.BackColor = System.Drawing.Color.Red;
- this.panel1.Location = new System.Drawing.Point(63, 15);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(105, 21);
- this.panel1.TabIndex = 21;
- this.panel1.Click += new System.EventHandler(this.panelC_Click);
- //
- // trackBar5
- //
- this.trackBar5.AutoSize = false;
- this.trackBar5.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar5.Location = new System.Drawing.Point(214, 16);
- this.trackBar5.Maximum = 50;
- this.trackBar5.Minimum = 1;
- this.trackBar5.Name = "trackBar5";
- this.trackBar5.Size = new System.Drawing.Size(84, 21);
- this.trackBar5.TabIndex = 7;
- this.trackBar5.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar5.Value = 3;
- this.trackBar5.Scroll += new System.EventHandler(this.trackBar5_Scroll);
- this.trackBar5.ValueChanged += new System.EventHandler(this.trackBar5_ValueChanged);
- //
- // textBox9
- //
- this.textBox9.Location = new System.Drawing.Point(304, 15);
- this.textBox9.Name = "textBox9";
- this.textBox9.Size = new System.Drawing.Size(35, 21);
- this.textBox9.TabIndex = 6;
- this.textBox9.Text = "3";
- this.textBox9.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
- this.textBox9.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox9_KeyUp);
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(173, 20);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(0, 12);
- this.label3.TabIndex = 2;
- //
- // label5
- //
- this.label5.AutoSize = true;
- this.label5.Location = new System.Drawing.Point(15, 20);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(0, 12);
- this.label5.TabIndex = 0;
- //
- // groupBox6
- //
- this.groupBox6.Controls.Add(this.panel3);
- this.groupBox6.Controls.Add(this.trackBar4);
- this.groupBox6.Controls.Add(this.textBox10);
- this.groupBox6.Controls.Add(this.label4);
- this.groupBox6.Controls.Add(this.label6);
- this.groupBox6.Location = new System.Drawing.Point(178, 426);
- this.groupBox6.Name = "groupBox6";
- this.groupBox6.Size = new System.Drawing.Size(354, 41);
- this.groupBox6.TabIndex = 41;
- this.groupBox6.TabStop = false;
- //
- // panel3
- //
- this.panel3.BackColor = System.Drawing.Color.Yellow;
- this.panel3.Location = new System.Drawing.Point(62, 14);
- this.panel3.Name = "panel3";
- this.panel3.Size = new System.Drawing.Size(105, 21);
- this.panel3.TabIndex = 22;
- this.panel3.Click += new System.EventHandler(this.panelC_Click);
- //
- // trackBar4
- //
- this.trackBar4.AutoSize = false;
- this.trackBar4.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar4.Location = new System.Drawing.Point(214, 16);
- this.trackBar4.Maximum = 50;
- this.trackBar4.Minimum = 1;
- this.trackBar4.Name = "trackBar4";
- this.trackBar4.Size = new System.Drawing.Size(84, 21);
- this.trackBar4.TabIndex = 7;
- this.trackBar4.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar4.Value = 3;
- this.trackBar4.Scroll += new System.EventHandler(this.trackBar4_Scroll);
- this.trackBar4.ValueChanged += new System.EventHandler(this.trackBar5_ValueChanged);
- //
- // textBox10
- //
- this.textBox10.Location = new System.Drawing.Point(304, 15);
- this.textBox10.Name = "textBox10";
- this.textBox10.Size = new System.Drawing.Size(35, 21);
- this.textBox10.TabIndex = 6;
- this.textBox10.Text = "3";
- this.textBox10.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
- this.textBox10.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox10_KeyUp);
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(173, 20);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(0, 12);
- this.label4.TabIndex = 2;
- //
- // label6
- //
- this.label6.AutoSize = true;
- this.label6.Location = new System.Drawing.Point(15, 20);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(0, 12);
- this.label6.TabIndex = 0;
- //
- // groupBox7
- //
- this.groupBox7.Controls.Add(this.panel4);
- this.groupBox7.Controls.Add(this.textBox6);
- this.groupBox7.Controls.Add(this.textBox4);
- this.groupBox7.Controls.Add(this.trackBar3);
- this.groupBox7.Controls.Add(this.textBox3);
- this.groupBox7.Controls.Add(this.label15);
- this.groupBox7.Controls.Add(this.label16);
- this.groupBox7.Controls.Add(this.label17);
- this.groupBox7.Controls.Add(this.label18);
- this.groupBox7.Location = new System.Drawing.Point(178, 469);
- this.groupBox7.Name = "groupBox7";
- this.groupBox7.Size = new System.Drawing.Size(354, 64);
- this.groupBox7.TabIndex = 40;
- this.groupBox7.TabStop = false;
- //
- // panel4
- //
- this.panel4.BackColor = System.Drawing.Color.Green;
- this.panel4.Location = new System.Drawing.Point(62, 15);
- this.panel4.Name = "panel4";
- this.panel4.Size = new System.Drawing.Size(105, 21);
- this.panel4.TabIndex = 23;
- this.panel4.Click += new System.EventHandler(this.panelC_Click);
- //
- // textBox6
- //
- this.textBox6.Location = new System.Drawing.Point(62, 39);
- this.textBox6.Name = "textBox6";
- this.textBox6.Size = new System.Drawing.Size(105, 21);
- this.textBox6.TabIndex = 10;
- this.textBox6.Text = "10";
- this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);
- this.textBox6.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox6_KeyUp);
- //
- // textBox4
- //
- this.textBox4.Location = new System.Drawing.Point(218, 39);
- this.textBox4.Name = "textBox4";
- this.textBox4.Size = new System.Drawing.Size(121, 21);
- this.textBox4.TabIndex = 8;
- this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
- this.textBox4.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox4_KeyUp);
- //
- // trackBar3
- //
- this.trackBar3.AutoSize = false;
- this.trackBar3.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar3.Location = new System.Drawing.Point(214, 16);
- this.trackBar3.Maximum = 50;
- this.trackBar3.Minimum = 1;
- this.trackBar3.Name = "trackBar3";
- this.trackBar3.Size = new System.Drawing.Size(84, 21);
- this.trackBar3.TabIndex = 7;
- this.trackBar3.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar3.Value = 3;
- this.trackBar3.Scroll += new System.EventHandler(this.trackBar3_Scroll);
- this.trackBar3.ValueChanged += new System.EventHandler(this.trackBar5_ValueChanged);
- //
- // textBox3
- //
- this.textBox3.Location = new System.Drawing.Point(304, 15);
- this.textBox3.Name = "textBox3";
- this.textBox3.Size = new System.Drawing.Size(35, 21);
- this.textBox3.TabIndex = 6;
- this.textBox3.Text = "3";
- this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
- this.textBox3.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyUp);
- //
- // label15
- //
- this.label15.AutoSize = true;
- this.label15.Location = new System.Drawing.Point(173, 44);
- this.label15.Name = "label15";
- this.label15.Size = new System.Drawing.Size(0, 12);
- this.label15.TabIndex = 3;
- //
- // label16
- //
- this.label16.AutoSize = true;
- this.label16.Location = new System.Drawing.Point(173, 20);
- this.label16.Name = "label16";
- this.label16.Size = new System.Drawing.Size(0, 12);
- this.label16.TabIndex = 2;
- //
- // label17
- //
- this.label17.AutoSize = true;
- this.label17.Location = new System.Drawing.Point(15, 44);
- this.label17.Name = "label17";
- this.label17.Size = new System.Drawing.Size(0, 12);
- this.label17.TabIndex = 1;
- //
- // label18
- //
- this.label18.AutoSize = true;
- this.label18.Location = new System.Drawing.Point(15, 20);
- this.label18.Name = "label18";
- this.label18.Size = new System.Drawing.Size(0, 12);
- this.label18.TabIndex = 0;
- //
- // groupBox8
- //
- this.groupBox8.Controls.Add(this.label14);
- this.groupBox8.Controls.Add(this.label7);
- this.groupBox8.Controls.Add(this.label2);
- this.groupBox8.Controls.Add(this.label13);
- this.groupBox8.Controls.Add(this.label12);
- this.groupBox8.Controls.Add(this.label11);
- this.groupBox8.Location = new System.Drawing.Point(179, 533);
- this.groupBox8.Name = "groupBox8";
- this.groupBox8.Size = new System.Drawing.Size(353, 53);
- this.groupBox8.TabIndex = 43;
- this.groupBox8.TabStop = false;
- //
- // label14
- //
- this.label14.AutoSize = true;
- this.label14.Location = new System.Drawing.Point(243, 32);
- this.label14.Name = "label14";
- this.label14.Size = new System.Drawing.Size(0, 12);
- this.label14.TabIndex = 11;
- //
- // label7
- //
- this.label7.AutoSize = true;
- this.label7.Location = new System.Drawing.Point(86, 32);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(0, 12);
- this.label7.TabIndex = 10;
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(135, 15);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(0, 12);
- this.label2.TabIndex = 9;
- //
- // label13
- //
- this.label13.AutoSize = true;
- this.label13.Location = new System.Drawing.Point(172, 32);
- this.label13.Name = "label13";
- this.label13.Size = new System.Drawing.Size(0, 12);
- this.label13.TabIndex = 8;
- //
- // label12
- //
- this.label12.AutoSize = true;
- this.label12.Location = new System.Drawing.Point(15, 32);
- this.label12.Name = "label12";
- this.label12.Size = new System.Drawing.Size(0, 12);
- this.label12.TabIndex = 7;
- //
- // label11
- //
- this.label11.AutoSize = true;
- this.label11.Location = new System.Drawing.Point(16, 15);
- this.label11.Name = "label11";
- this.label11.Size = new System.Drawing.Size(0, 12);
- this.label11.TabIndex = 6;
- //
- // TABM1Dialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(1127, 810);
- this.Controls.Add(this.groupBox8);
- this.Controls.Add(this.groupBox10);
- this.Controls.Add(this.groupBox6);
- this.Controls.Add(this.groupBox7);
- this.Controls.Add(this.groupBox_Basicoperation);
- this.Name = "TABM1Dialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TABM1Dialog_FormClosing);
- this.Controls.SetChildIndex(this.groupBox_img, 0);
- this.Controls.SetChildIndex(this.groupBox_review, 0);
- this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
- this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
- this.Controls.SetChildIndex(this.groupBox_report, 0);
- this.Controls.SetChildIndex(this.groupBox_Basicoperation, 0);
- this.Controls.SetChildIndex(this.groupBox7, 0);
- this.Controls.SetChildIndex(this.groupBox6, 0);
- this.Controls.SetChildIndex(this.groupBox10, 0);
- this.Controls.SetChildIndex(this.groupBox8, 0);
- this.groupBox_img.ResumeLayout(false);
- this.groupBox_report.ResumeLayout(false);
- this.groupBox_report.PerformLayout();
- this.groupBox_analysisResult1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
- this.groupBox_Basicoperation.ResumeLayout(false);
- this.groupBox10.ResumeLayout(false);
- this.groupBox10.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar5)).EndInit();
- this.groupBox6.ResumeLayout(false);
- this.groupBox6.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).EndInit();
- this.groupBox7.ResumeLayout(false);
- this.groupBox7.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
- this.groupBox8.ResumeLayout(false);
- this.groupBox8.PerformLayout();
- this.ResumeLayout(false);
- }
- #endregion 初始化组件和实现组件事件
- #region 需继承的一部分方法
- protected override void drawSubclass(Graphics graphics)
- {
- if (vlines.Count() > 0)
- {
- Pen bluePen = new Pen(this.panel4.BackColor, this.trackBar3.Value);
- int index = 0;
- Font myFont = new Font("宋体", 12);
- Brush bush = new SolidBrush(this.panel4.BackColor);//填充的颜色
- foreach (Line temp in vlines)
- {
- graphics.DrawLine(bluePen, temp.startPoint, temp.endPoint);
- graphics.DrawString("" + (++index), myFont, bush, temp.endPoint.X - 1 + this.trackBar3.Value / 2, temp.endPoint.Y - 16 - this.trackBar4.Value / 2);
- }
- }
- if (tempLine != null && tempLine.Length > 0/* && !bcOriginChecked()*/)//###19575 【用户反馈】点击显示原图后,二值化和绘制轮廓功能都取消了,需要显示原图功能为在原图和处理好的图片之间可以进行相互的切换
- {
- Pen lineColor = new Pen(this.panel1.BackColor, this.trackBar5.Value);
- for (int index = 0; index < tempLine.Length; index++)
- {
- System.Drawing.Point[] tempLine1 = tempLine[index];
- graphics.DrawLines(lineColor, tempLine1);
- }
- }
- //###19400 【客户反馈】专用分析-钛合金,平均涂层厚度,基线的涂层显示在最上边
- //画笔
- Pen yellowPen = new Pen(this.panel3.BackColor, this.trackBar4.Value);
- if (line == null)
- {
- btnflag = 0;
- //System.Drawing.Point point1 = new System.Drawing.Point(0, lab1Img.Height - 130);
- //System.Drawing.Point point2 = new System.Drawing.Point(lab1Img.Width, lab1Img.Height - 130);
- //line = new Line(point1, point2);
- //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
- }
- else
- {
- if (btnflag == 0)
- btnflag = 1;
- graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
- }
- }
- //数据库的name(报告模板)
- protected override string getTemplateName()
- {
- return "Template.Manager.item3.TitaniumAlloyBio1Method";
- }
- //语言包的name(项目工程)
- protected override string getProjectEngineeringName()
- {
- return "Menu.DedicatedAnalysis.NonferrousMetal.TitaniumAlloyBiomaterial.Text";
- }
- protected override void SubclassInitialize()
- {
- InitializeComponent();
- InitializeLanguageText();
- this.panel1.Click += new System.EventHandler(this.panel1_Click);
- this.panel3.Click += new System.EventHandler(this.panel1_Click);
- this.panel4.Click += new System.EventHandler(this.panel1_Click);
- }
- //切换图片时控制前一张图的信息不遗留显示
- protected override void refreshWhileImgChanged()
- {
- this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
-
- calculate1d = false;
- this.label2.Text = "";
- this.label7.Text = "";
- this.label14.Text = "";
- vlines.Clear();
- if (line != null)
- {
- btnflag = 0;
- line = null;
- }
- tempLine = new System.Drawing.Point[][] { };
- //if (this.documentWorkspace.PhaseModels.Count() == 0 || this.documentWorkspace.PhaseModels[0].mat == null || !this.documentWorkspace.PhaseModels[0].choise)
- //{
- // binaryClass.performClickBinaryCheck(false);
- //}
- this.grayBitmap = false;
- if (this.bitmap == null)
- {
- return;
- }
- if (textBoxChanged == 1)
- {
- textBoxChanged = -1;
- return;
- }
- if (string.IsNullOrWhiteSpace(this.textBox6.Text) || textBox6.Text == "")
- {
- return;
- }
- int w;
- try
- {
- w = int.Parse(this.textBox6.Text);
- textBoxChanged = 2;
- }
- catch (Exception b)
- {
- MessageBox.Show(b.Message);
- return;
- }
- int per_w = (int)((this.bitmap/*lab1Img*/.Width / Math.Max(1, (w + 1))) * physical_length);
- textBox4.Text = per_w.ToString();
- }
- #endregion
- #region 基础操作
- /// <summary>
- /// 灰度化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
- return;
- }
- if (this.grayBitmap) {
- MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
- return;
- }
- this.grayBitmap = true;
- Mat lab1Img = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);
- if (lab1Img.Type() != MatType.CV_8UC1)
- {
- lab1Img = lab1Img.CvtColor(ColorConversionCodes.BGR2GRAY);
- Bitmap bitmap2 = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1Img);
- Document document = Document.FromImage(bitmap2);
- this.documentWorkspace.Document = document;
- }
- else
- MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
- lab1Img.Dispose();
- lab1Img = null;
- }
- /// <summary>
- /// 腐蚀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- return;
- }
- Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
- Cv2.Erode(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
- this.documentWorkspace.PhaseModels[0].mat = lab1Img;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 膨胀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button10_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- return;
- }
- Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
- Cv2.Dilate(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
- this.documentWorkspace.PhaseModels[0].mat = lab1Img;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 寻找轮廓
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button15_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise/* //###21424 */
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- return;
- }
- Mat analyzeMat = this.documentWorkspace.PhaseModels[0].mat;
- bool findTempLineSuccess;
- int Rows = analyzeMat.Rows;
- int Cols = analyzeMat.Cols;
- int[] point = new int[2];
- List<System.Drawing.Point> tempPointList = new List<System.Drawing.Point>();
- //多通道图像的格式化
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- findTempLineSuccess = false;
- for (point[0] = 1; point[0] < Rows; point[0]++)
- {
- if (analyzeMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- {
- tempPointList.Add(new System.Drawing.Point(point[1], point[0]));
- findTempLineSuccess = true;//找到了最上边的交点
- break;
- }
- }
- if (!findTempLineSuccess)//如果没有找到最上边的交点,设置交点为图像的最高点
- {
- point[0] = 0;
- tempPointList.Add(new System.Drawing.Point(point[1], point[0]));
- }
- }
- tempLine = new System.Drawing.Point[][] { tempPointList.ToArray() };
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 自动调整
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button17_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1/* || !this.documentWorkspace.PhaseModels[0].choise*/
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- binaryClass.performClickBinaryCheck(true);
- }
- this.button15.PerformClick();
- }
- /// <summary>
- /// 绘制辅助线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button13_Click(object sender, EventArgs e)
- {
- if (!(tempLine != null && tempLine.Length > 0))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseclicktodrawtheoutlinefirst.text"));
- return;
- }
- //this.showPhaseMat();
- Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
- if (lab1Img != null)// && line == null
- {
- if (string.IsNullOrWhiteSpace(this.textBox4.Text) || textBox4.Text == "")
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseentertheauxiliarylinespacingfirst.text"));
- return;
- }
- //if (string.IsNullOrWhiteSpace(this.textBox2.Text) || textBox2.Text == "")
- //{
- // return;
- //}
- int per_w;
- try
- {
- per_w = (int)(float.Parse(this.textBox4.Text) / physical_length);
- }
- catch (Exception b)
- {
- MessageBox.Show(b.Message);
- return;
- }
- per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- if (line == null)
- {
- btnflag = 1;
- System.Drawing.Point point1 = new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130);
- System.Drawing.Point point2 = new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130);
- line = new Line(point1, point2);
- //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
- }
- //画均匀垂直于基体平行线的线
- int y = lineNum = line.endPoint.Y;
- //trackBar1.Value = lineNum;
- int w = (lab1Img.Width / per_w) - 1;
- w = Math.Max(1, w);
- //textBox4.Text = w.ToString();//##条数XXXXXXXXXXX//0914###18438
- vlines.Clear();
- for (int i = 0; i < w; i++)
- {
- int temp_y = -1;
- //找轮廓内所有跟线的x相交的点,取y最大(//###################最小)的值进行计算
- for (int n = 0; n < tempLine.Length; n++)
- {
- System.Drawing.Point[] pointsL = tempLine[n];
- for (int m = 0; m < pointsL.Length; m++)
- {
- if (pointsL[m].X == per_w * (i + 1))
- {
- if (temp_y == -1)
- {
- temp_y = pointsL[m].Y;
- }
- else
- {
- if (pointsL[m].Y < temp_y)
- {
- temp_y = pointsL[m].Y;
- }
- }
- }
- }
- }
- System.Drawing.Point tpoint1 = new System.Drawing.Point(per_w * (i + 1), temp_y);
- System.Drawing.Point tpoint2 = new System.Drawing.Point(per_w * (i + 1), y);
- Line temp = new Line(tpoint1, tpoint2);
- vlines.Add(temp);
- }
- int w11 = vlines.Count();// (this.bitmap/*lab1Img*/.Width / per_w) - 1;
- w11 = Math.Max(1, w11);
- textBox6.Text = w11.ToString();//0914###18438//#########################这个是遗留的深层问题,后续优化。
- this.documentWorkspace.Refresh();
- //calculated = false;
- //pictureBox1.Image = this.bitmap;// map;//#####
- }
- else
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- }
- }
- /// <summary>
- /// 重置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
- return;
- }
- calculate1d = false;
- this.label2.Text = "";
- this.label7.Text = "";
- this.label14.Text = "";
- vlines.Clear();
- if (line == null)
- {
- }
- else
- {
- btnflag = 0;
- line = null;
- }
- tempLine = new System.Drawing.Point[][] { };
- if (this.documentWorkspace.PhaseModels.Count() > 0)
- {
- this.documentWorkspace.PhaseModels[0].mat = null;
- }
- this.documentWorkspace.PhaseModels[0].choise = false;
- binaryClass.performClickBinaryCheck(false);
- //this.checkBox10.Checked = false;//PdnResources.GetString("Menu.Binarization.text");//####################
- this.grayBitmap = false;
- Document document = Document.FromImage(this.bitmap);
- this.documentWorkspace.Document = document;
- }
- /// <summary>
- /// 修改轮廓
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button14_Click(object sender, EventArgs e)
- {
- if (!(tempLine != null && tempLine.Length > 0))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseclicktodrawtheoutlinefirst.text"));
- //MessageBox.Show("请先进行寻找轮廓操作"/*PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")*/);
- return;
- }
- IntegrationClass.MetalsBoundaryEditingDialog boundaryEditingDialog = new IntegrationClass.MetalsBoundaryEditingDialog(this.appWorkspace, this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index, this.panel1.BackColor
- , tempLine.ToList());
- if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
- {
- tempLine = boundaryEditingDialog.AnalyzePoints.ToArray();
- this.documentWorkspace.Refresh();
- }
- }
- #endregion 基础操作
- #region 控件监听事件
- /// <summary>
- /// 相颜色点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panelC_Click(object sender, EventArgs e)
- {
- //this.panelC = (Panel)sender;
- //this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
- //this.colorsFormGrid.ShowDialog();
- }
- ///// <summary>
- ///// PanelC的调色板颜色改变
- ///// </summary>
- ///// <param name="sender"></param>
- ///// <param name="e"></param>
- //private void gridColorChanged(object sender, EventArgs e)
- //{
- // Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
- // //更改背景色,触发事件
- // this.panelC.BackColor = color;
- // this.documentWorkspace.Refresh();
- // //关闭色板
- // this.colorsFormGrid.Close();
- //}
- /// <summary>
- /// 线宽条控件改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void trackBar5_ValueChanged(object sender, EventArgs e)
- {
- this.documentWorkspace.Refresh();
- }
- private void trackBar5_Scroll(object sender, EventArgs e)
- {
- this.textBox9.Text = "" + this.trackBar5.Value;
- }
- private void trackBar4_Scroll(object sender, EventArgs e)
- {
- this.textBox10.Text = "" + this.trackBar4.Value;
- }
- private void trackBar3_Scroll(object sender, EventArgs e)
- {
- this.textBox3.Text = "" + this.trackBar3.Value;
- }
- /// <summary>
- /// 线宽输入框 对输入值做限制
- /// </summary>
- /// <param name="sender"></param>
- private void varifyTextBoxValue(object sender)
- {
- if (string.IsNullOrEmpty(((TextBox)sender)/*this.textBox2*/.Text))
- ((TextBox)sender)/*this.textBox2*/.Text = "1";
- if (Convert.ToInt32(((TextBox)sender)/*this.textBox2*/.Text) > 50)
- ((TextBox)sender)/*this.textBox2*/.Text = "50";
- }
- /// <summary>
- /// 限制只可以输入0-9数字以及退格键
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBoxWidth_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != '\b')//这是允许输入退格键
- {
- int len = ((TextBox)sender)/*this.textBox1*/.Text.Length;
- if (len < 1 && e.KeyChar == '0')
- {
- e.Handled = true;
- }
- else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字
- {
- e.Handled = true;
- }
- }
- }
- private void textBox9_KeyUp(object sender, KeyEventArgs e)
- {
- this.varifyTextBoxValue(sender);
- this.trackBar5.Value = Convert.ToInt32(this.textBox9.Text);
- }
- private void textBox10_KeyUp(object sender, KeyEventArgs e)
- {
- this.varifyTextBoxValue(sender);
- this.trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
- }
- private void textBox3_KeyUp(object sender, KeyEventArgs e)
- {
- this.varifyTextBoxValue(sender);
- this.trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
- }
- /// <summary>
- /// 记录输入文字改变的状态
- /// </summary>
- int textBoxChanged = -1;
- /// <summary>
- /// 辅助线间距改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox4_TextChanged(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 辅助线数量改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox6_TextChanged(object sender, EventArgs e)
- {
- }
- #endregion 控件监听事件
- #region 矩形拖动
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- protected override void OnMouseDown(object sender, MouseEventArgs e)
- {
- if (!CanUseMouseFunctions())
- return;
- if (btnflag == 1)
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
- if (mouse_y < line.startPoint.Y + 10 && mouse_y > line.startPoint.Y - 10)
- {
- //移动基体
- btnflag = 2;//已经按下
- this.documentWorkspace/*pictureBox1*/.Cursor = Cursors.SizeNS;
- }
- }
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void onMouseMove(object sender, MouseEventArgs e)
- {
- if (!CanUseMouseFunctions())
- return;
- if (btnflag == 2)
- {
- //Mat ImageROI = null;
- try
- {
- if (line == null)
- {
- btnflag = 1;
- System.Drawing.Point point1 = new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130);
- System.Drawing.Point point2 = new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130);
- line = new Line(point1, point2);
- //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
- }
- //float mouse_y = ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
- //mouse_y = Math.Min(lab1Img.Height - 10, mouse_y);
- //mouse_y = Math.Max(10, mouse_y);
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- //移动基体
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- line.startPoint.Y = (int)point.Y;// mouse_y;
- line.endPoint.Y = (int)point.Y;// mouse_y;
- //drawg.DrawLine(yellowPen, line.startPoint, line.endPoint);
- //pictureBox1.Image = map;
- this.documentWorkspace.Refresh();
- }
- catch
- {
- }
- finally
- {
- //ImageROI.Dispose();
- //GC.Collect();
- }
- return;
- }
- if (btnflag == 1)
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
- if (mouse_y < line.startPoint.Y + 10 && mouse_y > line.startPoint.Y - 10)
- {
- this.documentWorkspace.Cursor = Cursors.SizeNS;
- //pictureBox1.Cursor = Cursors.SizeNS;
- }
- else
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- ////图片平移,在MouseMove处添加拖动函数操作
- //if (isSelected && IsMouseInPanel()) //确定已经激发MouseDown事件,和鼠标在picturebox的范围内
- //{
- // this.pictureBox1.Left = this.pictureBox1.Left + (Cursor.Position.X - mouseDownPoint.X);
- // this.pictureBox1.Top = this.pictureBox1.Top + (Cursor.Position.Y - mouseDownPoint.Y);
- // mouseDownPoint.X = Cursor.Position.X;
- // mouseDownPoint.Y = Cursor.Position.Y;
- //}
- //else
- //{
- // pictureBox1.Cursor = Cursors.Default;
- //}
- }
- }
- }
- /// <summary>
- /// 鼠标抬起
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void onMouseUp(object sender, MouseEventArgs e)
- {
- if (!CanUseMouseFunctions())
- return;
- if (btnflag == 2)
- {
- btnflag = 1;
- }
- }
- #endregion
- #region 分析结果的方法
- /// <summary>
- /// 点击保存结果按钮,用来返回需要新增的一行数据
- /// </summary>
- /// <param name="tag"></param>
- /// <param name="imgName"></param>
- /// <returns></returns>
- protected override DataTable toInsertTableRow(string tag, string imgName)
- {
- DataTable dt = new DataTable(tag);
- dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
- dt.Columns.Add(PdnResources.GetString("Menu.Averagethickness(μm).text"));
- dt.Columns.Add(PdnResources.GetString("Menu.standarddeviation.text"));
- dt.Columns.Add(PdnResources.GetString("Menu.confidencebound.text"));
- DataRow dataRow = dt.NewRow();
- dataRow[PdnResources.GetString("Menu.picture.Text")] = imgName;
- dataRow[PdnResources.GetString("Menu.Averagethickness(μm).text")] = res_perL;
- dataRow[PdnResources.GetString("Menu.standarddeviation.text")] = res_s1;
- dataRow[PdnResources.GetString("Menu.confidencebound.text")] = res_c1;
- dt.Rows.Add(dataRow);
- return dt;
- }
- /// <summary>
- /// 计算结果是否存在
- /// </summary>
- /// <returns>返回是否可以计算和保存结果</returns>
- protected override bool resultCalculateExist()
- {
- return vlines.Count > 0;
- }
- /// <summary>
- /// 拼接中间数据
- /// </summary>
- /// <returns></returns>
- protected override List<List<string>> buildTempDataList()
- {
- List<List<string>> dataList = new List<List<string>>();
- List<string> columnName = new List<string>();
- columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
- columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.Xoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.ToYcoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.ToYcoonate.Text"));
- columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.MeasureAction.MeasureLength.Text"));
- columnName.Add(PdnResources.GetString("Menu.Physicallength.text"));//addAction:这里
- dataList.Add(columnName);
- int index = 0;
- ////厚度的数组
- //int[] thickness = new int[vlines.Count()];
- //循环辅助线的集合
- if (this.vlines.Count > 0)
- {
- //循环每条线,找到和轮廓的交点
- for (int i = 0; i < vlines.Count(); i++)
- {
- ////计算厚度,像素
- //thickness[i] = lineNum - vlines[i].startPoint.Y;
- List<string> strList = new List<string>();
- strList.Add((++index).ToString());
- strList.Add(vlines[i].startPoint.X.ToString());
- strList.Add(vlines[i].startPoint.Y.ToString());
- strList.Add(lineNum.ToString());
- strList.Add((lineNum - vlines[i].startPoint.Y).ToString());
- strList.Add(((lineNum - vlines[i].startPoint.Y) * physical_length).ToString());
- dataList.Add(strList);
- }
- }
- return dataList;
- }
- /// <summary>
- /// 计算结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void buttonCalculate_Click(object sender, EventArgs e)
- {
- if (!resultCalculateExist())
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
- return;
- }
- //厚度的数组
- int[] thickness = new int[vlines.Count()];
- //循环每条线,找到和轮廓的交点
- for (int i = 0; i < vlines.Count(); i++)
- {
- //计算厚度,像素
- thickness[i] = lineNum - vlines[i].startPoint.Y;
- }
- //平均涂层厚度
- res_perL = thickness.Sum() * physical_length / Math.Max(1, thickness.Length);//考虑使用 thickness.Average
- //计算偏差
- double sqrtSum = 0;
- for (int i = 0; i < vlines.Count(); i++)
- {
- sqrtSum += Math.Pow(thickness[i] * physical_length - res_perL, 2.0);
- }
- //标准偏差
- res_s1 = Math.Sqrt(sqrtSum / Math.Max(1, vlines.Count() - 1));
- //置信区间
- res_c1 = 2 * res_s1 / Math.Sqrt(Math.Max(1, vlines.Count()));
- this.label2.Text = this.resShow(res_perL.ToString());
- this.label7.Text = this.resShow(res_s1.ToString());
- this.label14.Text = this.resShow(res_c1.ToString());
- calculate1d = true;
- }
- /// <summary>
- /// 小数点位数变化时刷新界面的数据
- /// </summary>
- protected override void RefreshDataGridView1()
- {
- if (calculate1d)
- {
- this.label2.Text = this.resShow(res_perL.ToString());
- this.label7.Text = this.resShow(res_s1.ToString());
- this.label14.Text = this.resShow(res_c1.ToString());
- }
- }
- #endregion 分析结果的方法
- #region 参数保存及提取
- /// <summary>
- /// 保存参数的key,value和type
- /// </summary>
- /// <param name="param_key"></param>
- /// <param name="param_value"></param>
- /// <param name="param_type"></param>
- private void saveParamValue(string param_key, string param_value, int param_type)
- {
- bool foundItem = false;
- foreach (var item in this.analysisModel.ListParam)
- {
- if (item.param_key.Equals(param_key) && item.menuId == this.menuId)
- {
- item.param_value = param_value;
- item.setValue();
- foundItem = true;
- break;
- }
- }
- if (!foundItem)
- {
- GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
- analysisItem.menuId = this.menuId;
- analysisItem.param_key = param_key;
- analysisItem.param_type = param_type;
- analysisItem.param_value = param_value;
- analysisItem.setValue();
- this.analysisModel.ListParam.Add(analysisItem);
- }
- }
- /// <summary>
- /// 保存界面中的参数到model
- /// </summary>
- private void saveDialogParamValues()
- {
- saveParamValue(ParamKey_Report, checkBox_generateReport_opensetting.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//报告设置
- saveParamValue(ParamKey_OutlineColour, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//轮廓颜色
- saveParamValue(ParamKey_OutlineWidth, textBox9.Text, (int)Base.Dtryt.ItemString);//轮廓线宽
- saveParamValue(ParamKey_BaseColour, panel3.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//基线颜色
- saveParamValue(ParamKey_BaseWidth, textBox10.Text, (int)Base.Dtryt.ItemString);//基线线宽
- saveParamValue(ParamKey_GuideColour, panel4.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//辅助线颜色
- saveParamValue(ParamKey_GuideWidth, textBox3.Text, (int)Base.Dtryt.ItemString);//辅助线线宽
- saveParamValue(ParamKey_GuideNumber, textBox6.Text, (int)Base.Dtryt.ItemString);//辅助线条数
- saveParamValue(ParamKey_DecimalPlace, numericUpDown1_0 != null ? numericUpDown1_0.Value.ToString() : "", (int)Base.Dtryt.Decimal);//保留小数位数
- }
- /// <summary>
- /// 获取保存的参数
- /// </summary>
- private void GetListParamModel()
- {
- if (this.analysisModel != null)
- {
- for (int i = 0; i < this.analysisModel.ListParam.Count; i++)
- {
- switch (this.analysisModel.ListParam[i].param_key)
- {
- case ParamKey_Report:
- checkBox_generateReport_opensetting.Checked = (Boolean)this.analysisModel.ListParam[i].value;
- break;
- case ParamKey_OutlineColour:
- panel1.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_OutlineWidth:
- textBox9.Text = this.analysisModel.ListParam[i].value.ToString();
- trackBar5.Value = Convert.ToInt32(this.textBox9.Text);
- break;
- case ParamKey_BaseColour:
- panel3.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_BaseWidth:
- textBox10.Text = this.analysisModel.ListParam[i].value.ToString();
- trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
- break;
- case ParamKey_GuideColour:
- panel4.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_GuideWidth:
- textBox3.Text = this.analysisModel.ListParam[i].value.ToString();
- trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
- break;
- case ParamKey_GuideNumber:
- textBox6.Text = this.analysisModel.ListParam[i].value.ToString();
- break;
- case ParamKey_DecimalPlace:
- numericUpDown1_0.Value = decimal.Parse(this.analysisModel.ListParam[i].param_value);
- break;
- }
- }
- }
- }
- /// <summary>
- /// 关闭窗体时保存参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TABM1Dialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- this.saveDialogParamValues();
- //xml保存路径
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
- GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
- foreach (var analysisItem in this.analysisModel.ListParam)
- {
- bool foundItem = false;
- foreach (var item in analysisModelXml.ListParam)
- {
- if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId)
- {
- item.param_value = analysisItem.param_value;
- foundItem = true;
- break;
- }
- }
- if (!foundItem)
- analysisModelXml.ListParam.Add(analysisItem.cloneModel());
- }
- //按路径和名称保存xml文件
- string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainSizeAnalysisModel>(analysisModelXml);
- //保存xml
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create);
- }
- #endregion
- private void textBox6_KeyUp(object sender, KeyEventArgs e)
- {
- if (this.bitmap == null)
- {
- return;
- }
- if (textBoxChanged == 1)
- {
- textBoxChanged = -1;
- return;
- }
- if (string.IsNullOrWhiteSpace(this.textBox6.Text) || textBox6.Text == "")
- {
- return;
- }
- int w;
- try
- {
- w = int.Parse(this.textBox6.Text);
- textBoxChanged = 2;
- }
- catch (Exception b)
- {
- MessageBox.Show(b.Message);
- return;
- }
- double per_w = (this.bitmap/*lab1Img*/.Width / Math.Max(1, (w + 1))) * physical_length;
- textBox4.Text = per_w.ToString();
- }
- private void textBox4_KeyUp(object sender, KeyEventArgs e)
- {
- if (this.bitmap == null)
- {
- return;
- }
- if (textBoxChanged == 2 && textBox6.Focused)
- {
- textBoxChanged = -1;
- return;
- }
- if (string.IsNullOrWhiteSpace(this.textBox4.Text) || textBox4.Text == "")
- {
- return;
- }
- try
- {
- int per_w;
- try
- {
- per_w = (int)(float.Parse(this.textBox4.Text) / physical_length);
- textBoxChanged = 1;
- }
- catch (Exception b)
- {
- MessageBox.Show(b.Message);
- return;
- }
- per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- int w = (this.bitmap/*lab1Img*/.Width / per_w) - 1;
- w = Math.Max(1, w);
- textBox6.Text = w.ToString();
- }
- catch (Exception b)
- {
- MessageBox.Show(b.Message);
- }
- }
- }
- }
|