| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020 |
- 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 TABM2Dialog : NonFMetalsStandardDialog
- {
- #region 属性
- /// <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>
- /// 孔隙的mat
- /// </summary>
- Mat tempHoleMat;
- Bitmap tempHoleBitmap;
- /// <summary>
- /// 定义变量存储鼠标操作状态 1拖动上辅助线 2拖动下辅助线 /* 3拖动平行辅助线*/
- /// </summary>
- int mouseFlag = 0;
- ///// <summary>
- ///// 1显示辅助线 2移动辅助线 0隐藏辅助线
- ///// </summary>
- //int btnflag = 0;
- int contoursTop = 0;
- /// <summary>
- /// 辅助线
- /// </summary>
- Line top, bottom;
- /// <summary>
- /// 孔隙面积
- /// </summary>
- double res_area1;
- /// <summary>
- /// 选中区域面积
- /// </summary>
- double res_areaTotal;
- /// <summary>
- /// 孔隙体积百分比
- /// </summary>
- double res_percent;
- /// <summary>
- /// 选择标尺的物理长度(微米/像素)
- /// </summary>
- double physical_length = 1;
- // <summary>
- /// 保存窗口参数
- /// </summary>
- private GrainSizeAnalysisModel analysisModel;
- private const string ParamKey_Report = "report";//报告设置
- private const string ParamKey_PoreColour = "poreColour";//孔隙颜色
- private const string ParamKey_UpperRegionColour = "upperRegionColour";//上区颜色
- private const string ParamKey_UpperRegionWidth = "upperRegionWidth";//上区颜色线宽
- private const string ParamKey_LowerRegionColour = "lowerRegionColour";//下区颜色
- private const string ParamKey_LowerRegionWidth = "lowerRegionWidth";//下区颜色线宽
- private const string ParamKey_DecimalPlace = "decimalPlace";//保留小数位数
- #endregion 属性
- #region 组件
- private Button button2;
- private GroupBox groupBox10;
- private Panel panel1;
- private Label label5;
- private GroupBox groupBox8;
- private Label label14;
- private Label label7;
- private Label label2;
- private Label label13;
- private Label label12;
- private GroupBox groupBox5;
- private Button button14;
- private Button button17;
- private Button button3;
- private Button button15;
- private Button button13;
- private Button button10;
- private Button button4;
- private Button button5;
- private GroupBox groupBox6;
- private Label label19;
- private TextBox textBox4;
- 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 TrackBar trackBar3;
- private TextBox textBox3;
- private Label label16;
- private Label label17;
- private Label label18;
- private TextBox textBox1;
- private Label label1;
- private Label label11;
- #endregion 组件
- #region 构造函数
- public TABM2Dialog(AppWorkspace appWorkspace, int menuId) : base(appWorkspace, menuId)
- {
- 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();
- //Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
- //this.physical_length = measurementUnitDictionary[MeasurementUnit.Micron];
- GetListParamModel();
- 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.Dedicatedanalysis.Nmetals.holearea.text");
- Column3_total.HeaderText = PdnResources.GetString("Menu.Areaofselectedarea.text");
- Column4_total.HeaderText = PdnResources.GetString("Menu.Percentageofholevolume.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.Dedicatedanalysis.Nmetals.holearea.text");
- Column3.HeaderText = PdnResources.GetString("Menu.Areaofselectedarea.text");
- Column4.HeaderText = PdnResources.GetString("Menu.Percentageofholevolume.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.label19.Text = PdnResources.GetString("Menu.Distancefromtop.text") + ":";
- //this.label19.Text = PdnResources.GetString("Menu.spacing.text") + ":";
- this.groupBox7.Text = PdnResources.GetString("Menu.LowerarealineSettings.text");
- this.label6.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.label4.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.groupBox6.Text = PdnResources.GetString("Menu.Upperarea-lineSettings.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.button5.Text = PdnResources.GetString("Menu.Image.Grayscale.Text");
- this.button4/*button3*/.Text = PdnResources.GetString("Menu.BinaryAction.ErosionExtraction.Text");
- this.button10.Text = PdnResources.GetString("Menu.BinaryAction.DilationExtraction.Text");
- this.button13.Text = PdnResources.GetString("Menu.Drawarea.text");
- //this.button13.Text = PdnResources.GetString("Menu.Drawauxiliarylines.text");
- this.button3.Text = PdnResources.GetString("Menu.reinformation.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.groupBox5.Text = PdnResources.GetString("Menu.Basicoperation.text");
- this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.Percentageofholevolume.text") + ")";
- //this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.veragecoatingthickness.Text") + ")";
- this.label11.Text = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.holearea.text") + ":";
- this.label12.Text = PdnResources.GetString("Menu.Areaofselectedarea.text") + ":";
- this.label13.Text = PdnResources.GetString("Menu.Percentageofholevolume.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.Distancefrombottom.text") + ":";
- this.label1.Text = "辅助线间距";// PdnResources.GetString("Menu.spacing.text") + ":";
- }
- private void InitializeComponent()
- {
- this.button2 = new System.Windows.Forms.Button();
- this.groupBox10 = new System.Windows.Forms.GroupBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.panel1 = new System.Windows.Forms.Panel();
- this.label5 = 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.groupBox5 = new System.Windows.Forms.GroupBox();
- this.button14 = new System.Windows.Forms.Button();
- this.button17 = new System.Windows.Forms.Button();
- this.button3 = 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.button4 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.groupBox6 = new System.Windows.Forms.GroupBox();
- this.label19 = new System.Windows.Forms.Label();
- this.textBox4 = new System.Windows.Forms.TextBox();
- 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.trackBar3 = new System.Windows.Forms.TrackBar();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.label16 = new System.Windows.Forms.Label();
- this.label17 = new System.Windows.Forms.Label();
- this.label18 = 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.groupBox10.SuspendLayout();
- this.groupBox8.SuspendLayout();
- this.groupBox5.SuspendLayout();
- this.groupBox6.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit();
- this.groupBox7.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
- this.SuspendLayout();
- //
- // 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.textBox1);
- this.groupBox10.Controls.Add(this.label1);
- this.groupBox10.Controls.Add(this.panel1);
- 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;
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(246, 15);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(101, 21);
- this.textBox1.TabIndex = 27;
- this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
- this.textBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyUp);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(175, 20);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(0, 12);
- this.label1.TabIndex = 26;
- //
- // panel1
- //
- this.panel1.BackColor = System.Drawing.Color.Orange;
- 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;
- //
- // 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;
- //
- // 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, 563);
- 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(279, 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(110, 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(87, 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;
- //
- // groupBox5
- //
- this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox5.Controls.Add(this.button14);
- this.groupBox5.Controls.Add(this.button17);
- this.groupBox5.Controls.Add(this.button3);
- this.groupBox5.Controls.Add(this.button15);
- this.groupBox5.Controls.Add(this.button13);
- this.groupBox5.Controls.Add(this.button10);
- this.groupBox5.Controls.Add(this.button4);
- this.groupBox5.Controls.Add(this.button5);
- this.groupBox5.Location = new System.Drawing.Point(180, 317);
- this.groupBox5.Name = "groupBox5";
- this.groupBox5.Size = new System.Drawing.Size(353, 66);
- this.groupBox5.TabIndex = 44;
- this.groupBox5.TabStop = false;
- //
- // button14
- //
- this.button14.Location = new System.Drawing.Point(267, 40);
- 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(180, 40);
- 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);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(93, 40);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 6;
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button15
- //
- this.button15.Location = new System.Drawing.Point(267, 15);
- 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(9, 40);
- 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(180, 15);
- 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);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(93, 15);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 1;
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(9, 15);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 0;
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // groupBox6
- //
- this.groupBox6.Controls.Add(this.label19);
- this.groupBox6.Controls.Add(this.textBox4);
- 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, 66);
- this.groupBox6.TabIndex = 45;
- this.groupBox6.TabStop = false;
- //
- // label19
- //
- this.label19.AutoSize = true;
- this.label19.Location = new System.Drawing.Point(15, 47);
- this.label19.Name = "label19";
- this.label19.Size = new System.Drawing.Size(0, 12);
- this.label19.TabIndex = 23;
- //
- // textBox4
- //
- this.textBox4.Location = new System.Drawing.Point(86, 42);
- this.textBox4.Name = "textBox4";
- this.textBox4.Size = new System.Drawing.Size(95, 21);
- this.textBox4.TabIndex = 8;
- this.textBox4.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBox4_TextChanged);
- //
- // 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;
- //
- // 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.trackBar4_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.trackBar3);
- this.groupBox7.Controls.Add(this.textBox3);
- 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, 495);
- this.groupBox7.Name = "groupBox7";
- this.groupBox7.Size = new System.Drawing.Size(354, 67);
- this.groupBox7.TabIndex = 46;
- this.groupBox7.TabStop = false;
- //
- // panel4
- //
- this.panel4.BackColor = System.Drawing.Color.Green;
- this.panel4.Location = new System.Drawing.Point(63, 14);
- this.panel4.Name = "panel4";
- this.panel4.Size = new System.Drawing.Size(105, 21);
- this.panel4.TabIndex = 23;
- //
- // textBox6
- //
- this.textBox6.Location = new System.Drawing.Point(86, 41);
- this.textBox6.Name = "textBox6";
- this.textBox6.Size = new System.Drawing.Size(95, 21);
- this.textBox6.TabIndex = 10;
- this.textBox6.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBox6_TextChanged);
- //
- // trackBar3
- //
- this.trackBar3.AutoSize = false;
- this.trackBar3.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar3.Location = new System.Drawing.Point(214, 15);
- 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.trackBar3_ValueChanged);
- //
- // textBox3
- //
- this.textBox3.Location = new System.Drawing.Point(304, 14);
- 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);
- //
- // label16
- //
- this.label16.AutoSize = true;
- this.label16.Location = new System.Drawing.Point(173, 19);
- 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, 47);
- 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, 19);
- this.label18.Name = "label18";
- this.label18.Size = new System.Drawing.Size(0, 12);
- this.label18.TabIndex = 0;
- //
- // TABM2Dialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(1127, 822);
- this.Controls.Add(this.groupBox7);
- this.Controls.Add(this.groupBox6);
- this.Controls.Add(this.groupBox5);
- this.Controls.Add(this.groupBox8);
- this.Controls.Add(this.groupBox10);
- this.Name = "TABM2Dialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TABM2Dialog_FormClosing);
- this.Controls.SetChildIndex(this.groupBox10, 0);
- this.Controls.SetChildIndex(this.groupBox8, 0);
- this.Controls.SetChildIndex(this.groupBox5, 0);
- this.Controls.SetChildIndex(this.groupBox6, 0);
- this.Controls.SetChildIndex(this.groupBox7, 0);
- 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.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.groupBox10.ResumeLayout(false);
- this.groupBox10.PerformLayout();
- this.groupBox8.ResumeLayout(false);
- this.groupBox8.PerformLayout();
- this.groupBox5.ResumeLayout(false);
- 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.ResumeLayout(false);
- }
- #endregion 初始化组件和实现组件事件
- #region 需继承的一部分方法
- protected override void drawSubclass(Graphics graphics)
- {
- if (tempHoleMat != null && tempHoleBitmap != null)
- {
- graphics.DrawImage(tempHoleBitmap, new PointF(0, 0));
- }
- if (top != null && bottom != null)
- {
- Pen topLinePen = new Pen(this.panel3.BackColor/*Color.FromArgb(255, 0, 208, 202)*/, this.trackBar4.Value/*5*/);
- Pen blueLinePen = new Pen(this.panel4.BackColor/*Color.FromArgb(255, 0, 208, 202)*/, this.trackBar3.Value/*5*/);
- graphics.DrawLine(topLinePen, top.startPoint, top.endPoint);
- graphics.DrawLine(blueLinePen, bottom.startPoint, bottom.endPoint);
- }
- //if (tempLine != null && tempLine.Length > 0 && !bcOriginChecked())
- //{
- // 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);
- // }
- //}
- ////画笔
- //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);
- //}
- //if (vlines.Count() > 0)
- //{
- // Pen bluePen = new Pen(this.panel4.BackColor, this.trackBar3.Value);
- // foreach (Line temp in vlines)
- // graphics.DrawLine(bluePen, temp.startPoint, temp.endPoint);
- //}
- }
- //数据库的name(报告模板)
- protected override string getTemplateName()
- {
- return "Template.Manager.item3.TitaniumAlloyBio2Method";
- }
- //语言包的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);
- //this.groupBox_img.Size = new System.Drawing.Size(158, 544/*514*/);
- //this.groupBox_review.Size = new System.Drawing.Size(575, 544/*514*/);
- //this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 622/*592*/);
- //this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 622/*592*/);
- //this.groupBox_report.Location = new System.Drawing.Point(974, 622/*592*/);
- this.ClientSize = new System.Drawing.Size(1127, 852);///*822*/
- }
- //切换图片时控制前一张图的信息不遗留显示
- protected override void refreshWhileImgChanged()
- {
- //this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- this.textBox1_KeyUp(null, null);
- calculate1d = false;
- this.label2.Text = "";
- this.label7.Text = "";
- this.label14.Text = "";
- vlines.Clear();
- if (line != null)
- {
- btnflag = 0;
- line = null;
- }
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- //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 button5_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 button4_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)
- {
- findContour();
- }
- private void findContour(bool showMessageBox = true)
- {
- if (top == null || bottom == null)
- {
- if (showMessageBox)//#21396
- MessageBox.Show("请先绘制区域"/*PdnResources.GetString("Menu.Pleasedrawtheareafirst.text")*/);//选取区域
- return;
- }
- if (bottom.endPoint.Y - top.startPoint.Y <= 0)//0914###18506
- {
- if (showMessageBox)
- MessageBox.Show(PdnResources.GetString("Menu.Theupperguinthelowerone.text"));
- return;
- }
- if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise/* //###21476 */
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- if (showMessageBox)
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- return;
- }
- Mat analyzeMat = this.documentWorkspace.PhaseModels[0].mat;
- Color tempHoleColor = this.panel1.BackColor;
- Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
- Vec4b vec4B2 = new Vec4b(0, 0, 0, 0);
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- tempHoleMat = new Mat(analyzeMat.Size(), MatType.CV_8UC4);
- int Rows = analyzeMat.Rows;
- int Cols = analyzeMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- for (point[0] = top.startPoint.Y/*0*/; point[0] < bottom.endPoint.Y/*Rows*/; point[0]++)
- {
- if (analyzeMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- tempHoleMat.Set(point, vec4B2);
- else
- tempHoleMat.Set(point, vec4B1);
- }
- }
- tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
- this.documentWorkspace.Refresh();
- //return true;
- }
- /// <summary>
- /// PanelC的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void gridColorChanged(object sender, EventArgs e)
- {
- base.gridColorChanged(sender, e);
- if (this.panelC != this.panel1)
- return;
- Color tempHoleColor = this.panel1.BackColor;
- Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
- if (tempHoleMat == null)
- {
- return;
- }
- int Rows = tempHoleMat.Rows;
- int Cols = tempHoleMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- if (tempHoleMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- tempHoleMat.Set(point, vec4B1);
- }
- }
- tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 自动调整
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button17_Click(object sender, EventArgs e)
- {
- if (top == null || bottom == null)
- {
- this.button13.PerformClick();
- //MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawtheareafirst.text"));//选取区域
- //return;
- }
- 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)
- {
- //this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- int result = 0;
- if (int.TryParse(textBox4.Text, out result))
- {
- 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)));
- }
- else
- {
- top = new Line(new System.Drawing.Point(0, 50), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, 50));
- textBox4.Text = (top.startPoint.Y * physical_length) + "";
- }
- if (int.TryParse(textBox6.Text, out result))
- {
- 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)));
- }
- else
- {
- 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));
- textBox6.Text = ((this.bitmap/*lab1Img*/.Height - bottom.startPoint.Y) * physical_length) + "";
- }
- if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
- textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
- btnflag = 1;
- this.documentWorkspace.Refresh();
- textBox4.Enabled = true;
- textBox6.Enabled = true;
- }
- /// <summary>
- /// 重置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_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;
- }
- if (top != null)
- top = null;
- if (bottom != null)
- bottom = null;
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- 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 (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
- return;
- }
- if (tempHoleMat == null)
- {
- MessageBox.Show("请先进行寻找孔隙操作");
- return;
- }
- 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
- , tempHoleMat);
- if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
- {
- tempHoleMat = boundaryEditingDialog.PhaseMat.Clone();
- tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
- this.documentWorkspace.Refresh();
- }
- }
- #endregion 基础操作
- #region 控件监听事件
- private void trackBar4_ValueChanged(object sender, EventArgs e)
- {
- this.documentWorkspace.Refresh();
- }
- private void trackBar4_Scroll(object sender, EventArgs e)
- {
- this.textBox10.Text = "" + this.trackBar4.Value;
- }
- private void trackBar3_ValueChanged(object sender, EventArgs e)
- {
- this.documentWorkspace.Refresh();
- }
- 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 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);
- }
- #endregion 控件监听事件
- #region 矩形拖动
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- protected override void OnMouseDown(object sender, MouseEventArgs e)
- {
- if (!CanUseMouseFunctions())
- return;
- try
- {
- //判断
- //画上下辅助线
- if (top == null || bottom == null)
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- ////在MouseDown处获知鼠标是否按下,并记录下此时的鼠标坐标值;
- //if (e.Button == MouseButtons.Left)
- //{
- // mouseDownPoint.X = Cursor.Position.X; //注:全局变量mouseDownPoint前面已定义为Point类型
- // mouseDownPoint.Y = Cursor.Position.Y;
- // isSelected = true;
- //}
- return;
- }
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;
- float mouse_y = point.Y;
- if (mouse_y < top.startPoint.Y + 10 && mouse_y > top.startPoint.Y - 10)
- {
- //拖动上辅助线
- mouseFlag = 1;
- }
- else if (mouse_y < bottom.startPoint.Y + 10 && mouse_y > bottom.startPoint.Y - 10)
- {
- //拖动下辅助线
- mouseFlag = 2;
- }
- else
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- ////在MouseDown处获知鼠标是否按下,并记录下此时的鼠标坐标值;
- //if (e.Button == MouseButtons.Left)
- //{
- // mouseDownPoint.X = Cursor.Position.X; //注:全局变量mouseDownPoint前面已定义为Point类型
- // mouseDownPoint.Y = Cursor.Position.Y;
- // isSelected = true;
- //}
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //if (operationK >= 0 && e.Button == MouseButtons.Left)
- //{
- // if (operationK == 0)
- // {
- // startPoint = endPoint = this.documentWorkspace.GetScalePoint(e.Location);
- // //nowLine = new PointF[4];
- // //nowLine[0] = startPoint;
- // //nowLine[1] = endPoint;
- // //pointList.Add(nowLine);
- // }
- //}
- ////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 (mouseFlag == 1 || mouseFlag == 2)
- {
- //Mat ImageROI = null;
- try
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;
- float mouse_y = point.Y;
- ////移动上下辅助线
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- int margin = (int)mouse_y;
- margin = Math.Min(this.bitmap.Height - 10, margin);
- margin = Math.Max(10, margin);
- if (mouseFlag == 1)
- {
- textBox4.Text = "" + margin;
- top = new Line(new System.Drawing.Point(0, margin), new System.Drawing.Point(this.bitmap.Width, margin));
- }
- else if (mouseFlag == 2)
- {
- textBox6.Text = "" + (this.bitmap.Height - margin);
- bottom = new Line(new System.Drawing.Point(0, margin), new System.Drawing.Point(this.bitmap.Width, margin));
- }
- if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
- textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- //contours = null;//###########################################################################
- ////pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
- ////Pen blueLinePen = new Pen(Color.Blue, zoom);
- ////drawg.DrawLine(blueLinePen, top.startPoint, top.endPoint);
- ////drawg.DrawLine(blueLinePen, bottom.startPoint, bottom.endPoint);
- ////pictureBox1.Image = map;
- this.documentWorkspace.Refresh();
- }
- catch
- {
- }
- finally
- {
- //ImageROI.Dispose();
- //GC.Collect();
- }
- return;
- }
- if (btnflag == 2)
- {
- ////Mat ImageROI = null;
- //try
- //{
- // //float mouse_y = ((e.Y - panel1.Location.Y + 12) * zoom - imgY); //to test at 20191231
- // //移动辅助线
- // drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- //}
- //catch (Exception b)
- //{
- // //MessageBox.Show(b.Message);//解决不断弹出提示语的bug
- //}
- //finally
- //{
- // //ImageROI.Dispose();
- // //GC.Collect();
- //}
- return;
- }
- if (btnflag == 1)
- {
- try
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;
- float mouse_y = point.Y;
- 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))
- {
- //移动辅助线
- this.documentWorkspace.Cursor = Cursors.SizeNS;
- }
- else
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- }
- }
- catch (Exception ex)
- {
- //MessageBox.Show(ex.Message);//解决不断弹出提示语的bug
- }
- }
- else
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- }
- //if (operationK >= 0 && e.Button == MouseButtons.Left)
- //{
- // if (operationK == 0)
- // {
- // //this.endPoint = this.documentWorkspace.GetScalePoint(e.Location);
- // //pointList[lineCount][1] = endPoint;
- // }
- // //this.documentWorkspace.Refresh();
- //}
- ////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;
- mouseFlag = 0;
- //if (operationK == 0)
- //{
- // if (startPoint != null && endPoint != null && startPoint != endPoint)
- // {
- // // lineCount++;
- // // AddContentToDataGridView();
- // //}
- // //else
- // //{
- // // pointList.RemoveAt(pointList.Count - 1);
- // }
- // //this.documentWorkspace.Refresh();
- //}
- //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.Dedicatedanalysis.Nmetals.holearea.text"));
- dt.Columns.Add(PdnResources.GetString("Menu.Areaofselectedarea.text"));
- dt.Columns.Add(PdnResources.GetString("Menu.Percentageofholevolume.text"));
- //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.Dedicatedanalysis.Nmetals.holearea.text")] = res_area1;
- dataRow[PdnResources.GetString("Menu.Areaofselectedarea.text")] = res_areaTotal;
- dataRow[PdnResources.GetString("Menu.Percentageofholevolume.text")] = res_percent;
- //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 tempHoleMat != null;// vlines.Count > 0;
- }
- /// <summary>
- /// 拼接中间数据
- /// </summary>
- /// <returns></returns>
- protected override List<List<string>> buildTempDataList()
- {
- return null;
- //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 (top == null || bottom == null)
- {//#21396
- MessageBox.Show("请先绘制区域"/*PdnResources.GetString("Menu.Pleaseselectareafirst.text")*/);
- return;
- }
- int result = 0;
- if (!int.TryParse(textBox4.Text, out result))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Topauxiliarylinetopdistanceinputformaterror.text"));
- return;
- }
- if (int.Parse(textBox4.Text) > this.bitmap/*lab1Img*/.Height * this.physical_length)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Thetopdistanceoftghtoftheimage.text"));
- return;
- }
- int result1 = 0;
- if (!int.TryParse(textBox6.Text, out result1))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Errorininputedistance.text"));
- return;
- }
- if (int.Parse(textBox6.Text) > this.bitmap.Height * this.physical_length)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Thebottomdistanheightoftheimage.text"));
- return;
- }
- if (int.Parse(textBox4.Text) > this.bitmap/*lab1Img*/.Height * this.physical_length - int.Parse(textBox6.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Thelowerauxiliaryluxiliaryline.text"));
- return;
- }
- if (!resultCalculateExist())
- {
- MessageBox.Show("请先进行寻找孔隙操作");//PdnResources.GetString("Menu.Pleaselookfortheoutlinefirst.text") ;//点击绘制轮廓
- return;
- //MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
- //return;
- }
- try
- {
- res_areaTotal = this.bitmap.Width * (bottom.endPoint.Y - top.startPoint.Y);
- //简单计算孔隙面积和总面积等
- res_area1 = 0;
- int Rows = tempHoleMat.Rows;
- int Cols = tempHoleMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- for (point[0] = top.startPoint.Y/*0*/; point[0] < bottom.endPoint.Y/*Rows*/; point[0]++)
- {
- if (tempHoleMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- res_area1 += 1;
- }
- }
- res_percent = res_area1 * 100 / res_areaTotal;
- calculate1d = true;
- this.documentWorkspace.Refresh();
- double physical_length11 = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- res_area1 = res_area1 * physical_length11 * physical_length11;
- res_areaTotal = res_areaTotal * physical_length11 * physical_length11;
- this.label2.Text = this.resShow(res_area1.ToString());
- this.label7.Text = this.resShow(res_areaTotal.ToString());
- this.label14.Text = this.resShow(res_percent.ToString()) + " %";
- }
- catch (Exception eb)
- {
- MessageBox.Show(eb.Message);
- }
- finally
- {
- }
- ////厚度的数组
- //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>
- int textBoxChanged = -1;
- /// <summary>
- /// 上辅助线居顶距离改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox4_TextChanged(object sender, KeyEventArgs e)
- {
- if (this.bitmap == null)
- {
- return;
- }
- if (top == null || bottom == null)
- {
- return;
- }
- int result = 0;
- if (!int.TryParse(textBox4.Text, out result))
- {
- return;
- }
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- //drawrectflag = 0;
- //contours = null;//##
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
- if ((int)(Convert.ToInt32(textBox4.Text) / this.physical_length) > bottom.endPoint.Y)
- {
- textBox4.Text = (bottom.endPoint.Y * this.physical_length).ToString();
- }
- 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)));
- if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
- textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 下辅助线居底距离改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox6_TextChanged(object sender, KeyEventArgs e)
- {
- if (this.bitmap == null)
- {
- return;
- }
- if (top == null || bottom == null)
- {
- return;
- }
- int result = 0;
- if (!int.TryParse(textBox6.Text, out result))
- {
- return;
- }
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- //drawrectflag = 0;
- //contours = null;//##
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
- if (this.bitmap/*lab1Img*/.Height - (int)(Convert.ToInt32(textBox6.Text) / this.physical_length) < top.endPoint.Y)
- {
- textBox6.Text = ((this.bitmap/*lab1Img*/.Height - top.endPoint.Y) * this.physical_length).ToString();
- }
- 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)));
- if (top != null && bottom != null/* && ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length) - int.Parse(textBox1.Text.ToString())) > 1*/)
- textBox1.Text = ((int)((bottom.startPoint.Y - top.startPoint.Y) * this.physical_length)).ToString();
- //Pen blueLinePen = new Pen(Color.Blue, zoom);
- //drawg.DrawLine(blueLinePen, top.startPoint, top.endPoint);
- //drawg.DrawLine(blueLinePen, bottom.startPoint, bottom.endPoint);
- //pictureBox1.Image = map;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 辅助线间距改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox1_KeyUp(object sender, KeyEventArgs e)
- {
- if (this.bitmap == null)
- {
- return;
- }
- if (top == null || bottom == null)
- {
- return;
- }
- int result = 0;
- if (!int.TryParse(textBox1.Text, out result))
- {
- return;
- }
- if (this.bitmap.Height * this.physical_length < result)
- {
- result = (int)(this.bitmap.Height * this.physical_length);
- textBox1.Text = ((int)result).ToString();
- textBox4.Text = "0";
- textBox6.Text = "0";
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
- 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)));
- 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)));
- this.documentWorkspace.Refresh();
- return;
- }
- textBox1.Text = ((int)result).ToString();
- textBox4.Text = ((int)((this.bitmap.Height * this.physical_length - result) / 2)).ToString();
- textBox6.Text = ((int)((this.bitmap.Height * this.physical_length - result) / 2)).ToString();
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- //drawrectflag = 0;
- //contours = null;//##
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- //pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1NoneContourImg);
- 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)));
- 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)));
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 小数点位数变化时刷新界面的数据
- /// </summary>
- protected override void RefreshDataGridView1()
- {
- if (calculate1d)
- {
- this.label2.Text = this.resShow(res_area1.ToString());
- this.label7.Text = this.resShow(res_areaTotal.ToString());
- this.label14.Text = this.resShow(res_percent.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_PoreColour, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//轮廓颜色
- saveParamValue(ParamKey_UpperRegionColour, panel3.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//上区颜色
- saveParamValue(ParamKey_UpperRegionWidth, textBox10.Text, (int)Base.Dtryt.ItemString);//上区颜色线宽
- saveParamValue(ParamKey_LowerRegionColour, panel4.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//下区颜色
- saveParamValue(ParamKey_LowerRegionWidth, textBox3.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_PoreColour:
- panel1.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_UpperRegionColour:
- panel3.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_UpperRegionWidth:
- textBox10.Text = this.analysisModel.ListParam[i].value.ToString();
- trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
- break;
- case ParamKey_LowerRegionColour:
- panel4.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_LowerRegionWidth:
- textBox3.Text = this.analysisModel.ListParam[i].value.ToString();
- trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
- 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 TABM2Dialog_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
- }
- }
|