| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442 |
- using OpenCvSharp;
- using PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.GBT14999
- {
- internal class MethodArea2Dialog : GrainSizeStandardDialog
- {
- /// <summary>
- /// 各个视场属性集合,索引0-横坐标,1-纵坐标,2-视场宽度,3-视场高度,4-视场面积
- /// </summary>
- protected List<List<int>> lstAttribute = new List<List<int>>();
- protected static string ParamKey_ShowCheckGrainDiameter = "ShowCheckGrainDiameter";//晶粒直径
- protected static string ParamKey_ShowGrainDiameter = "ShowGrainDiameter";//晶粒直径
- protected static string ParamKey_ShowRibbonCrystalGrain = "ShowRibbonCrystalGrain";//显示带状晶粒颜色
- protected static string ParamKey_ShowRibbonCrystalGrainColor = "ShowRibbonCrystalGrainColor";//颜色
- protected static string ParamKey_ShowRibbonCrystalGrainDiameter = "ShowRibbonCrystalGrainDiameter";//显示带状晶粒直径
- protected static string ParamKey_ShowRibbonCrystalGrainDiameterFontSize = "ShowRibbonCrystalGrainDiameterFontSize";//字号
- protected static string ParamKey_ShowRibbonCrystalGrainDiameterColor = "ShowRibbonCrystalGrainDiameterColor";//颜色
- #region 组件
- private GroupBox groupBox_AddParamSetting;
- private GroupBox groupBox_ShowParamSetting;
- private Panel panel1_1;
- private Panel panel1_2;
- private Label label2_1;
- private Label label2_2;
- private Label label2_3;
- private TextBox textBox1_1;
- private CheckBox checkBox_ShowAECLengh;
- private CheckBox checkBox_ShowAEC_Color;
- private DataGridViewTextBoxColumn ColumnTotal1;
- private DataGridViewTextBoxColumn ColumnTotal2;
- private DataGridViewTextBoxColumn ColumnTotal3;
- private DataGridViewTextBoxColumn ColumnTotal4;
- private DataGridViewTextBoxColumn ColumnTotal5;
- private DataGridViewTextBoxColumn ColumnTotal6;
- private DataGridViewTextBoxColumn ColumnTotal7;
- private DataGridViewTextBoxColumn ColumnTotal8;
- private DataGridViewTextBoxColumn Colum01;
- private DataGridViewTextBoxColumn Colum02;
- private DataGridViewTextBoxColumn Colum03;
- private DataGridViewTextBoxColumn Colum04;
- private DataGridViewTextBoxColumn Colum05;
- private DataGridViewTextBoxColumn Colum06;
- private DataGridViewTextBoxColumn Colum07;
- private DataGridViewTextBoxColumn Colum08;
- private DataGridViewTextBoxColumn Colum09;
- private DataGridViewTextBoxColumn Colum10;
- private Label label2;
- private ComboBox comboBox4;
- private Label label4;
- private Label label3;
- private TextBox textBox1;
- private Mat saveMat;
- private bool hasView;
- private Mat phaseMat;
- #endregion 组件
- #region 构造函数
- public MethodArea2Dialog(AppWorkspace appWorkspace, PdnMenuItem menuItem) : base(appWorkspace, menuItem, new Base.DedicatedAnalysis.GrainSize.Standard.GBT14999.MethodArea2())
- {
- binaryClass.processWholeMat = true;
- this.Load += new System.EventHandler(this.MethodArea2Dialog_Load);
- }
- /// <summary>
- /// 加载后控制窗口变化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MethodArea2Dialog_Load(object sender, EventArgs e)
- {
- //this.button_ApplyToAll.Visible = false;
- //this.button_SaveAll.Visible = false;
- //this.btn_Grainboundarytoreproduce.Location = new System.Drawing.Point(912, 20);
- //this.btn_saveresult.Location = new System.Drawing.Point(993, 20);
- this.panel1_1.Click += new System.EventHandler(this.panel1_1_Click);
- this.panel1_2.Click += new System.EventHandler(this.panel1_1_Click);
- this.groupBox_ShowParamSetting.Text = PdnResources.GetString("Menu.Displayparamssettings.text");
- this.checkBox_ShowAECLengh.Text = "显示带状晶粒直径";// PdnResources.GetString("Menu.displaygrid.text");
- this.checkBox_ShowAEC_Color.Text = "显示带状晶粒颜色";// PdnResources.GetString("Menu.displaygrainboundaries.text");
- this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- this.ColumnTotal1,
- this.ColumnTotal2,
- this.ColumnTotal3,
- this.ColumnTotal4,
- this.ColumnTotal5,
- this.ColumnTotal6,
- this.ColumnTotal7,
- this.ColumnTotal8});
- //
- // ColumnTotal1
- //
- this.ColumnTotal1.HeaderText = "条带平均卡规直径";
- this.ColumnTotal1.Name = "ColumnTotal1";
- this.ColumnTotal1.ReadOnly = true;
- //
- // ColumnTotal2
- //
- this.ColumnTotal2.HeaderText = "条带晶粒总面积";
- this.ColumnTotal2.Name = "ColumnTotal2";
- this.ColumnTotal2.ReadOnly = true;
- //
- // ColumnTotal3
- //
- this.ColumnTotal3.HeaderText = "面积百分数";
- this.ColumnTotal3.Name = "ColumnTotal3";
- this.ColumnTotal3.ReadOnly = true;
- //
- // ColumnTotal4
- //
- this.ColumnTotal4.HeaderText = "对应级别";
- this.ColumnTotal4.Name = "ColumnTotal4";
- this.ColumnTotal4.ReadOnly = true;
- //
- // ColumnTotal5
- //
- this.ColumnTotal5.HeaderText = "非条带平均卡规直径";
- this.ColumnTotal5.Name = "ColumnTotal5";
- this.ColumnTotal5.ReadOnly = true;
- //
- // ColumnTotal6
- //
- this.ColumnTotal6.HeaderText = "非条带晶粒总面积";
- this.ColumnTotal6.Name = "ColumnTotal6";
- this.ColumnTotal6.ReadOnly = true;
- //
- // ColumnTotal7
- //
- this.ColumnTotal7.HeaderText = "面积百分数";
- this.ColumnTotal7.Name = "ColumnTotal7";
- this.ColumnTotal7.ReadOnly = true;
- //
- // ColumnTotal8
- //
- this.ColumnTotal8.HeaderText = "对应级别";
- this.ColumnTotal8.Name = "ColumnTotal8";
- this.ColumnTotal8.ReadOnly = true;
- this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- this.Colum01,
- this.Colum02,
- this.Colum03,
- this.Colum04,
- this.Colum05,
- this.Colum06,
- this.Colum07,
- this.Colum08,
- this.Colum09,
- this.Colum10});
- //
- // Colum01
- //
- this.Colum01.HeaderText = PdnResources.GetString("Menu.picture.Text");
- this.Colum01.Name = "Colum01";
- this.Colum01.ReadOnly = true;
- //
- // Colum02
- //
- this.Colum02.HeaderText = "视场";// PdnResources.GetString("Menu.Tools.GridLine.Text");
- this.Colum02.Name = "Colum02";
- this.Colum02.ReadOnly = true;
- //
- // Colum03
- //
- this.Colum03.HeaderText = "条带平均卡规直径";
- this.Colum03.Name = "Colum03";
- this.Colum03.ReadOnly = true;
- //
- // Colum04
- //
- this.Colum04.HeaderText = "条带晶粒总面积";// PdnResources.GetString("Menu.Graisize.Text") + "(μm²)";
- this.Colum04.Name = "Colum04";
- this.Colum04.ReadOnly = true;
- //
- // Colum05
- //
- this.Colum05.HeaderText = "面积百分数";
- this.Colum05.Name = "Colum05";
- this.Colum05.ReadOnly = true;
- //
- // Colum06
- //
- this.Colum06.HeaderText = "对应级别";// PdnResources.GetString("Menu.Graingrade.Text");
- this.Colum06.Name = "Colum06";
- this.Colum06.ReadOnly = true;
- //
- // Colum07
- //
- this.Colum07.HeaderText = "非条带平均卡规直径";
- this.Colum07.Name = "Colum07";
- this.Colum07.ReadOnly = true;
- //
- // Colum08
- //
- this.Colum08.HeaderText = "非条带晶粒总面积";
- this.Colum08.Name = "Colum08";
- this.Colum08.ReadOnly = true;
- //
- // Colum09
- //
- this.Colum09.HeaderText = "面积百分数";
- this.Colum09.Name = "Colum09";
- this.Colum09.ReadOnly = true;
- //
- // Colum10
- //
- this.Colum10.HeaderText = "对应级别";
- this.Colum10.Name = "Colum10";
- this.Colum10.ReadOnly = true;
- HeaderTextUsable = false;
- DetailListStringIndex.Add(5);
- DetailListStringIndex.Add(9);
- DetailListNotDoubleIndex.Add(5);
- DetailListNotDoubleIndex.Add(9);
- IndexChangedFromIndex.Clear();
- IndexChangedToIndex.Clear();
- IndexChangedFromIndex.Add(2);
- IndexChangedFromIndex.Add(3);
- IndexChangedFromIndex.Add(4);
- IndexChangedFromIndex.Add(6);
- IndexChangedFromIndex.Add(7);
- IndexChangedFromIndex.Add(8);
- IndexChangedToIndex.Add(0, new int[] { 2, 0 });//平均
- IndexChangedToIndex.Add(1, new int[] { 1, 1 });//求和
- IndexChangedToIndex.Add(2, new int[] { 2, 2 });//平均
- IndexChangedToIndex.Add(3, new int[] { 3, 0 });//级别
- IndexChangedToIndex.Add(4, new int[] { 2, 3 });//平均
- IndexChangedToIndex.Add(5, new int[] { 1, 4 });//求和
- IndexChangedToIndex.Add(6, new int[] { 2, 5 });//平均
- IndexChangedToIndex.Add(7, new int[] { 3, 4 });//级别
- this.groupBox3.Visible = false;
- getSonData();
- }
- #endregion 构造函数
- #region 初始化组件和实现组件事件
- private void InitializeComponent()
- {
- this.groupBox_AddParamSetting = new System.Windows.Forms.GroupBox();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.comboBox4 = new System.Windows.Forms.ComboBox();
- this.label2 = new System.Windows.Forms.Label();
- this.groupBox_ShowParamSetting = new System.Windows.Forms.GroupBox();
- this.label2_1 = new System.Windows.Forms.Label();
- this.label2_2 = new System.Windows.Forms.Label();
- this.label2_3 = new System.Windows.Forms.Label();
- this.textBox1_1 = new System.Windows.Forms.TextBox();
- this.panel1_2 = new System.Windows.Forms.Panel();
- this.panel1_1 = new System.Windows.Forms.Panel();
- this.checkBox_ShowAECLengh = new System.Windows.Forms.CheckBox();
- this.checkBox_ShowAEC_Color = new System.Windows.Forms.CheckBox();
- this.ColumnTotal1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.ColumnTotal2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.ColumnTotal3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.ColumnTotal4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.ColumnTotal5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.ColumnTotal6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.ColumnTotal7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.ColumnTotal8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum01 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum02 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum03 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum04 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum05 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum06 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum07 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum08 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum09 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Colum10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.groupBox_analysisResult1.SuspendLayout();
- this.groupBox3.SuspendLayout();
- this.groupBox_AddParamSetting.SuspendLayout();
- this.groupBox_ShowParamSetting.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox_AddParamSetting
- //
- this.groupBox_AddParamSetting.Controls.Add(this.label4);
- this.groupBox_AddParamSetting.Controls.Add(this.label3);
- this.groupBox_AddParamSetting.Controls.Add(this.textBox1);
- this.groupBox_AddParamSetting.Controls.Add(this.comboBox4);
- this.groupBox_AddParamSetting.Controls.Add(this.label2);
- this.groupBox_AddParamSetting.Location = new System.Drawing.Point(179, 320);
- this.groupBox_AddParamSetting.Name = "groupBox_AddParamSetting";
- this.groupBox_AddParamSetting.Size = new System.Drawing.Size(355, 48);
- this.groupBox_AddParamSetting.TabIndex = 134;
- this.groupBox_AddParamSetting.TabStop = false;
- this.groupBox_AddParamSetting.Text = "参数设置";
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(261, 19);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(77, 12);
- this.label4.TabIndex = 35;
- this.label4.Text = "记为带状晶粒";
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(229, 19);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(23, 12);
- this.label3.TabIndex = 34;
- this.label3.Text = "μm";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(179, 15);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(45, 21);
- this.textBox1.TabIndex = 33;
- this.textBox1.Text = "0.5";
- //
- // comboBox4
- //
- this.comboBox4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox4.FormattingEnabled = true;
- this.comboBox4.Items.AddRange(new object[] {
- ">=",
- "<=",
- ">",
- "<"});
- this.comboBox4.Location = new System.Drawing.Point(72, 16);
- this.comboBox4.Name = "comboBox4";
- this.comboBox4.Size = new System.Drawing.Size(98, 20);
- this.comboBox4.TabIndex = 32;
- this.comboBox4.SelectedIndexChanged += new System.EventHandler(this.comboBox4_SelectedIndexChanged);
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(7, 20);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(59, 12);
- this.label2.TabIndex = 31;
- this.label2.Text = "卡规直径:";
- //
- // groupBox_ShowParamSetting
- //
- this.groupBox_ShowParamSetting.Controls.Add(this.label2_1);
- this.groupBox_ShowParamSetting.Controls.Add(this.label2_2);
- this.groupBox_ShowParamSetting.Controls.Add(this.label2_3);
- this.groupBox_ShowParamSetting.Controls.Add(this.textBox1_1);
- this.groupBox_ShowParamSetting.Controls.Add(this.panel1_2);
- this.groupBox_ShowParamSetting.Controls.Add(this.panel1_1);
- this.groupBox_ShowParamSetting.Controls.Add(this.checkBox_ShowAECLengh);
- this.groupBox_ShowParamSetting.Controls.Add(this.checkBox_ShowAEC_Color);
- this.groupBox_ShowParamSetting.Location = new System.Drawing.Point(178, 370);
- this.groupBox_ShowParamSetting.Name = "groupBox_ShowParamSetting";
- this.groupBox_ShowParamSetting.Size = new System.Drawing.Size(356, 74);
- this.groupBox_ShowParamSetting.TabIndex = 38;
- this.groupBox_ShowParamSetting.TabStop = false;
- //
- // label2_1
- //
- this.label2_1.AutoSize = true;
- this.label2_1.Location = new System.Drawing.Point(248, 25);
- this.label2_1.Name = "label2_1";
- this.label2_1.Size = new System.Drawing.Size(35, 12);
- this.label2_1.TabIndex = 311;
- this.label2_1.Text = "颜色:";
- //
- // label2_2
- //
- this.label2_2.AutoSize = true;
- this.label2_2.Location = new System.Drawing.Point(248, 45);
- this.label2_2.Name = "label2_2";
- this.label2_2.Size = new System.Drawing.Size(35, 12);
- this.label2_2.TabIndex = 312;
- this.label2_2.Text = "颜色:";
- //
- // label2_3
- //
- this.label2_3.AutoSize = true;
- this.label2_3.Location = new System.Drawing.Point(162, 45);
- this.label2_3.Name = "label2_3";
- this.label2_3.Size = new System.Drawing.Size(35, 12);
- this.label2_3.TabIndex = 312;
- this.label2_3.Text = "字号:";
- //
- // textBox1_1
- //
- this.textBox1_1.Location = new System.Drawing.Point(199, 41);
- this.textBox1_1.Name = "textBox1_1";
- this.textBox1_1.Size = new System.Drawing.Size(45, 21);
- this.textBox1_1.TabIndex = 33;
- this.textBox1_1.Text = "12";
- //
- // panel1_2
- //
- this.panel1_2.BackColor = System.Drawing.Color.Black;
- this.panel1_2.Location = new System.Drawing.Point(291, 42);
- this.panel1_2.Name = "panel1_2";
- this.panel1_2.Size = new System.Drawing.Size(52, 21);
- this.panel1_2.TabIndex = 18;
- //
- // panel1_1
- //
- this.panel1_1.BackColor = System.Drawing.Color.Red;
- this.panel1_1.Location = new System.Drawing.Point(291, 18);
- this.panel1_1.Name = "panel1_1";
- this.panel1_1.Size = new System.Drawing.Size(52, 21);
- this.panel1_1.TabIndex = 18;
- //
- // checkBox_ShowAECLengh
- //
- this.checkBox_ShowAECLengh.AutoSize = true;
- this.checkBox_ShowAECLengh.Location = new System.Drawing.Point(15, 44);
- this.checkBox_ShowAECLengh.Name = "checkBox_ShowAECLengh";
- this.checkBox_ShowAECLengh.Size = new System.Drawing.Size(15, 14);
- this.checkBox_ShowAECLengh.TabIndex = 1;
- this.checkBox_ShowAECLengh.UseVisualStyleBackColor = true;
- this.checkBox_ShowAECLengh.CheckedChanged += new System.EventHandler(this.checkBox_ShowAECLengh_CheckedChanged);
- //
- // checkBox_ShowAEC_Color
- //
- this.checkBox_ShowAEC_Color.AutoSize = true;
- this.checkBox_ShowAEC_Color.Location = new System.Drawing.Point(15, 22);
- this.checkBox_ShowAEC_Color.Name = "checkBox_ShowAEC_Color";
- this.checkBox_ShowAEC_Color.Size = new System.Drawing.Size(15, 14);
- this.checkBox_ShowAEC_Color.TabIndex = 0;
- this.checkBox_ShowAEC_Color.UseVisualStyleBackColor = true;
- this.checkBox_ShowAEC_Color.CheckedChanged += new System.EventHandler(this.checkBox_ShowAEC_Color_CheckedChanged);
- //
- // ColumnTotal1
- //
- this.ColumnTotal1.Name = "ColumnTotal1";
- //
- // ColumnTotal2
- //
- this.ColumnTotal2.Name = "ColumnTotal2";
- //
- // ColumnTotal3
- //
- this.ColumnTotal3.Name = "ColumnTotal3";
- //
- // ColumnTotal4
- //
- this.ColumnTotal4.Name = "ColumnTotal4";
- //
- // ColumnTotal5
- //
- this.ColumnTotal5.Name = "ColumnTotal5";
- //
- // ColumnTotal6
- //
- this.ColumnTotal6.Name = "ColumnTotal6";
- //
- // ColumnTotal7
- //
- this.ColumnTotal7.Name = "ColumnTotal7";
- //
- // ColumnTotal8
- //
- this.ColumnTotal8.Name = "ColumnTotal8";
- //
- // Colum01
- //
- this.Colum01.Name = "Colum01";
- //
- // Colum02
- //
- this.Colum02.Name = "Colum02";
- //
- // Colum03
- //
- this.Colum03.Name = "Colum03";
- //
- // Colum04
- //
- this.Colum04.Name = "Colum04";
- //
- // Colum05
- //
- this.Colum05.Name = "Colum05";
- //
- // Colum06
- //
- this.Colum06.Name = "Colum06";
- //
- // Colum07
- //
- this.Colum07.Name = "Colum07";
- //
- // Colum08
- //
- this.Colum08.Name = "Colum08";
- //
- // Colum09
- //
- this.Colum09.Name = "Colum09";
- //
- // Colum10
- //
- this.Colum10.Name = "Colum10";
- //
- // MethodArea2Dialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(1127, 810);
- this.Controls.Add(this.groupBox_AddParamSetting);
- this.Controls.Add(this.groupBox_ShowParamSetting);
- this.Name = "MethodArea2Dialog";
- this.Text = "GBT14999_2012(双重晶粒度评级)";
- this.Controls.SetChildIndex(this.groupBox3, 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.Controls.SetChildIndex(this.groupBox_ShowParamSetting, 0);
- this.Controls.SetChildIndex(this.groupBox_AddParamSetting, 0);
- this.groupBox_analysisResult1.ResumeLayout(false);
- this.groupBox3.ResumeLayout(false);
- this.groupBox_AddParamSetting.ResumeLayout(false);
- this.groupBox_AddParamSetting.PerformLayout();
- this.groupBox_ShowParamSetting.ResumeLayout(false);
- this.groupBox_ShowParamSetting.PerformLayout();
- this.ResumeLayout(false);
- }
- /// <summary>
- /// 字号改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox1_1_TextChanged(object sender, EventArgs e)
- {
- if (checkBox_ShowAECLengh.Checked)
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 输入阈值改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox1_TextChanged(object sender, EventArgs e)
- {
- GetClassNumberOfGrains();//setMat2ColorOfLabelMat
- }
- /// <summary>
- /// 显示带状晶粒颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_ShowAEC_Color_CheckedChanged(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count > 0)
- {
- this.documentWorkspace.PhaseModels[2].choise = (!bcOriginChecked() && checkBox_ShowAEC_Color.Checked);
- if (checkBox_ShowAEC_Color.Checked)
- setMat2ColorOfLabelMat/*GetClassNumberOfGrains*/();
- else
- this.documentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 显示带状晶粒直径改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox_ShowAECLengh_CheckedChanged(object sender, EventArgs e)
- {
- this.documentWorkspace.Refresh();
- }
- private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
- {
- //根据等级设置晶粒颜色
- setMat2ColorOfLabelMat(/*nccomps*/);
- }
- #endregion 初始化组件和实现组件事件
- /// <summary>
- /// 刷新晶粒编号/刷新晶粒颜色?//############
- /// </summary>
- /// <param name="pointFs"></param>
- /// <param name="rectangleF"></param>
- /// <returns>返回晶粒个数</returns>
- protected override double GetClassNumberOfGrains()
- {
- if (saveMat == null)
- return 0.1;
- bool existViewFlag = this.hasView;
- //Mat exsitViewMatOrg = null;//视场图像
- //if (existViewFlag)
- //// //matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- ////else
- // exsitViewMatOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(getCurrentWorkspace().GetFullSizeWithRegion());
- ////Bitmap bitmap = getCurrentWorkspace().GetCutSizeWithColorWhiteOrTransparentColor(false);
- ////Mat oldMap = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- Mat OrgViewMat;
- Mat analyzeMat = new Mat();
- if (getGrainBoundryChecked())
- {
- OrgViewMat = new Mat(saveMat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- Mat oldMat = PhaseModels1Mat != null ? PhaseModels1Mat : this.documentWorkspace.PhaseModels[1].mat;
- int Rows = oldMat.Rows;
- int Cols = oldMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- {
- OrgViewMat.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
- }
- }
- }
- Cv2.Erode(OrgViewMat, OrgViewMat, null, null, 1);
- oldMat.CopyTo(analyzeMat);
- }
- else if (getBinaryChecked())
- {
- OrgViewMat = new Mat(saveMat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- //Mat oldMat = this.PhaseModel0Mat;
- Mat oldMat = this.phaseMat;
- int Rows = oldMat.Rows;
- int Cols = oldMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- {
- OrgViewMat.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
- }
- }
- }
- oldMat.CopyTo(analyzeMat);
- }
- else
- {
- OrgViewMat = new Mat(saveMat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- saveMat.CopyTo(OrgViewMat);
- saveMat.CopyTo(analyzeMat);
- }
- List<Mat> OrgMatLists = new List<Mat>();
- //视场个数
- int sumFieldl = 1;
- //各个视场属性集合,索引0-横坐标,1-纵坐标,2-视场宽度,3-视场高度,4-视场面积
- if (lstAttribute.Count > 0)
- lstAttribute.Clear();
- //获取多视场图片
- if (existViewFlag)
- {
- //寻找并标记区域个数
- Mat orgLabelMat = new Mat();
- Mat orgStats = new Mat();
- Mat orgCentroids = new Mat();
- Bitmap bitmap = this.documentWorkspace.GetCutSizeWithColorWhiteOrTransparentColor(false);
- Mat oldMap = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- int nonenum = Cv2.ConnectedComponentsWithStats(BinaryClass.BGRA2GRAY(oldMap)/* //### .CvtColor(ColorConversionCodes.BGR2GRAY)*/, orgLabelMat, orgStats, orgCentroids, PixelConnectivity.Connectivity8);
- sumFieldl = nonenum/*centroids.Height*/ - 1;
- List<int> attribute;//单视场属性集合
- for (int h = 1; h < orgCentroids.Height; h++)
- {
- attribute = new List<int>();
- int x = orgStats.At<int>(h, 0);
- int y = orgStats.At<int>(h, 1);
- int width = orgStats.At<int>(h, 2);
- int height = orgStats.At<int>(h, 3);
- int areaField1 = orgStats.At<int>(h, 4);
- attribute.Add(x);
- attribute.Add(y);
- attribute.Add(width);
- attribute.Add(height);
- attribute.Add(areaField1);
- lstAttribute.Add(attribute);
- //double areaField = areaField1 * unitLength * unitLength;
- if (x < 0 || y < 0 || width > bitmap.Width || height > bitmap.Height)
- {
- continue;
- }
- Mat ImageROI1;
- try
- {
- Rect roi1 = new Rect(x, y, width, height);
- ImageROI1 = new Mat(OrgViewMat, roi1).Clone();
- for (int label_y = 0; label_y < height; label_y++)
- {
- for (int label_x = 0; label_x < width; label_x++)
- {
- if (orgLabelMat.At<int>(y + label_y, x + label_x) != h)
- {
- ImageROI1.Set(label_y, label_x, new Vec4b(0, 0, 0, 0));
- }
- }
- }
- }
- catch (Exception)
- {
- ImageROI1 = oldMap;//should never go here!
- }
- OrgMatLists.Add(ImageROI1);
- }
- }
- else
- {
- List<int> attribute = new List<int>();//单视场属性集合
- attribute.Add(0);
- attribute.Add(0);
- attribute.Add(OrgViewMat.Width);
- attribute.Add(OrgViewMat.Height);
- attribute.Add(OrgViewMat.Width * OrgViewMat.Height);
- lstAttribute.Add(attribute);
- OrgMatLists.Add(OrgViewMat);
- }
- //存储矩阵数据
- if (GSSClass.CurrentStatsArray != null && GSSClass.CurrentStatsArray.Length > 0)
- GSSClass.CurrentStatsArray = null;
- GSSClass.standardModel.currentStatsArray = new Mat[sumFieldl];
- if (GSSClass.CurrentLabelMatArray != null && GSSClass.CurrentLabelMatArray.Length > 0)
- GSSClass.CurrentLabelMatArray = null;
- GSSClass.CurrentLabelMatArray = new Mat[sumFieldl];
- if (GSSClass.standardModel.massLabelPointsList.Count > 0)
- GSSClass.standardModel.massLabelPointsList.Clear();
- int matIndex = 0;
- foreach (Mat OriginalPicture in OrgMatLists)
- {
- int offsetX = lstAttribute[matIndex][0];
- int offsetY = lstAttribute[matIndex][1];
- Mat erzhi = OriginalPicture;
- Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY);
- Cv2.Threshold(erzhi, erzhi, 100, 255, ThresholdTypes.Binary);//##
- OpenCvSharp.Point[][] contours;
- HierarchyIndex[] hierarchy;
- Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
- List<OpenCvSharp.Point[]> pointss = new List<OpenCvSharp.Point[]>();
- foreach (OpenCvSharp.Point[] contour in contours)
- {
- if (contour.Length < 100)
- {
- foreach (OpenCvSharp.Point point in contour)
- {
- erzhi.Set<byte>(point.Y, point.X, 255);
- }
- pointss.Add(contour);
- }
- }
- Cv2.FillPoly(erzhi, pointss, new Scalar(255));
- Mat labelMat = new Mat();
- Mat stats = new Mat();
- Mat centroids = new Mat();
- // 连通域数量
- int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
- GSSClass.standardModel.currentLabelMatArray[matIndex] = labelMat.Clone();
- //存储矩阵数据
- GSSClass.standardModel.currentStatsArray[matIndex] = stats.Clone();
- // 连通域质点
- Dictionary<int, Point2d> keyValues = new Dictionary<int, Point2d>();
- Dictionary<int, List<double>> massLabelPoints = new Dictionary<int, List<double>>();
- // 矩形边线上的连通域
- ArrayList nccompSelect = new ArrayList();
- double aec;
- double aec_length;
- //Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
- //选择标尺的物理长度(1倍下的 微米/像素)
- //double physical_area_length_Micron = measurementUnitDictionary[MeasurementUnit.Micron];
- double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- //if (exsitViewMatOrg == null || currentLabelMat == null || currentStats == null)
- {
- for (int label = 1; label < centroids.Height; label++)
- {
- keyValues[label] = new Point2d((int)centroids.At<double>(label, 0) + offsetX, (int)centroids.At<double>(label, 1) + offsetY);
- nccompSelect.Add(label);
- aec = stats/*currentStats*/.At<int>(label, 4) * physical_area_length_Micron * physical_area_length_Micron;//晶粒面积
- aec_length = Math.Sqrt(aec);
- massLabelPoints.Add(label, new List<double>() { aec_length, 1/*0*/, keyValues[label].X, keyValues[label].Y, aec });
- }
- }
- GSSClass.standardModel.massLabelPointsList.Add(massLabelPoints);
- matIndex++;
- }
- analyzeMat.Dispose();
- analyzeMat = null;
- // 矩形内的连通域
- GSSClass.standardModel.within = 0;
- ArrayList inccompSelect = new ArrayList();
- //根据等级设置晶粒颜色
- setMat2ColorOfLabelMat(/*nccomps*/);
- return GSSClass.standardModel.within/* + (double)nccompSelect.Count / 2*/;
- }
- /// <summary>
- /// 根据等级设置晶粒颜色,并计算复合条件的label集合到currentNccompSelectList
- /// </summary>
- /// <param name="nccomps">连通域数量</param>
- private void setMat2ColorOfLabelMat(/*int nccomps*/)
- {
- if (matOrg == null || GSSClass.standardModel.massLabelPointsList.Count == 0 || GSSClass.CurrentLabelMatArray.Length == 0 || GSSClass.standardModel.massLabelPointsList.Count != GSSClass.CurrentLabelMatArray.Length/* || currentStatsArray.Length == 0 || currentLabelMatArray.Length != currentStatsArray.Length*/)
- {
- if (matOrg != null)
- GetClassNumberOfGrains();
- return;
- }
- double lengthValue;
- if (!double.TryParse(this.textBox1.Text.ToString(), out lengthValue))
- return;
- //Mat exsitViewMatOrg = null;//视场图像
- //if (getCurrentWorkspace().GraphicsList.IsExsitView())
- // exsitViewMatOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(getCurrentWorkspace().GetFullSizeWithRegion());
- Mat temp = new Mat(matOrg.Size(), MatType.CV_8UC4, new Scalar(0, 0, 0, 0));//##
- if (GSSClass.standardModel.currentNccompSelectList.Count > 0)
- {
- GSSClass.standardModel.currentNccompSelectList.Clear();
- }
- for (int matIndex = 0; matIndex < GSSClass.CurrentLabelMatArray.Length; matIndex++)
- {
- int offsetX = lstAttribute[matIndex][0];
- int offsetY = lstAttribute[matIndex][1];
- int offsetWidth = lstAttribute[matIndex][2];
- int offsetHeight = lstAttribute[matIndex][3];
- if (offsetX < 0 || offsetY < 0 || offsetWidth > matOrg.Width || offsetHeight > matOrg.Height)
- {
- continue;//should never go here!
- }
- ArrayList currentNccompSelect = new ArrayList();//每个晶粒只计算一次
- Mat currentLabelMat = GSSClass.standardModel.currentLabelMatArray[matIndex];
- Dictionary<int, List<double>> massLabelPoints = GSSClass.standardModel.massLabelPointsList[matIndex];
- int label;
- double aec_length;
- Vec4b vec4 = new Vec4b(panel1_1.BackColor.B, panel1_1.BackColor.G, panel1_1.BackColor.R, Math.Max((byte)1, panel1_1.BackColor.A));
- for (int y = 0; y < offsetHeight; y++)
- {
- for (int x = 0; x < offsetWidth; x++)
- {
- //if (exsitViewMatOrg != null && exsitViewMatOrg.At<Vec4b>(y, x).Item3 == 0)
- // continue;//不在视场图像范围内
- label = currentLabelMat.At<int>(y, x);
- if (currentNccompSelect.Contains(label))
- {//已经找到的复合条件直接赋值颜色
- temp.Set(y + offsetY, x + offsetX, vec4);
- continue;
- }
- if (!massLabelPoints.ContainsKey(label))
- continue;
- aec_length = massLabelPoints[label][0];
- if (comboBox4.SelectedIndex == 0 && aec_length >= lengthValue || comboBox4.SelectedIndex == 2 && aec_length > lengthValue
- || comboBox4.SelectedIndex == 1 && aec_length <= lengthValue || comboBox4.SelectedIndex == 3 && aec_length < lengthValue)
- {
- if (!currentNccompSelect.Contains(label))
- currentNccompSelect.Add(label);
- temp.Set(y + offsetY, x + offsetX, vec4);
- }
- }
- }
- GSSClass.standardModel.currentNccompSelectList.Add(currentNccompSelect);
- }
- this.documentWorkspace.PhaseModels[2].mat = temp;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 面积法组织分项数据列表的内容,并返回 条带/非条带的:平均直径(μm)、汇总晶粒总面积(μm²)、面积比和对应级别
- /// </summary>
- private double[] addNewRowsToDatagridView2(GrainSizeStandardModel cal_StandardModel, string imgName, string tag, double physical_area_length_Micron,out string gradeValue_1, out string gradeValue_2)
- {
- this.dataGridView2.Rows.Clear();
- if ((cal_StandardModel.massLabelPointsList.Count == 0 && GetClassNumberOfGrains() == 0 && cal_StandardModel.massLabelPointsList.Count == 0 /* //#21108 */) || GSSClass.CurrentLabelMatArray == null || GSSClass.CurrentLabelMatArray.Length != GSSClass.standardModel.massLabelPointsList.Count
- || GSSClass.CurrentStatsArray == null || GSSClass.CurrentStatsArray.Length != cal_StandardModel.massLabelPointsList.Count)
- {
- gradeValue_1 = "00";
- gradeValue_2 = "00";
- return new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };//should never go here!
- }
- double small_l_1 = 0;//汇总直径
- int small_count_1 = 0;//汇总晶粒个数
- double area_sum_1 = 0;//汇总晶粒总面积
- double area_view_1 = 0;//面积百分数
- double small_l_2 = 0;//汇总直径
- int small_count_2 = 0;//汇总晶粒个数
- double area_sum_2 = 0;//汇总晶粒总面积
- double area_view_2 = 0;//面积百分数
- //Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
- //选择标尺的物理长度(1倍下的 微米/像素)
- //double physical_area_length_Micron = measurementUnitDictionary[MeasurementUnit.Micron];
- for (int matIndex = 0; matIndex < cal_StandardModel.massLabelPointsList.Count; matIndex++)
- {
- Dictionary<int, List<double>> massLabelPoints = cal_StandardModel.massLabelPointsList[matIndex];
- Mat currentStats = cal_StandardModel.currentStatsArray[matIndex];
- //显示编号
- if (/*massLabelPoints.Count == 0 || */ /* //#21108 */currentStats == null)
- continue;
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
- dgvr.Cells[0].Value = imgName;
- dgvr.Cells[1].Value = "视场" + (1 + matIndex);//视场编号
- double smalll_index_1 = 0.0;
- double aec_index_1 = 0.0;
- double smalll_index_2 = 0.0;
- double aec_index_2 = 0.0;
- ArrayList currentNccompSelect = new ArrayList();
- if (matIndex < cal_StandardModel.currentNccompSelectList.Count) {
- currentNccompSelect = cal_StandardModel.currentNccompSelectList[matIndex];
- }
- int grainNumber_1 = Math.Max(1, currentNccompSelect.Count);
- int grainNumber_2 = Math.Max(1, massLabelPoints.Keys.Count - currentNccompSelect.Count);
- //decimal NA;//这里计算的值可以取到
- foreach (int kvLabel in /*currentNccompSelect*/massLabelPoints.Keys)
- {
- if (currentNccompSelect.Contains(kvLabel))
- {
- smalll_index_1 += massLabelPoints[kvLabel][0];
- aec_index_1 += massLabelPoints[kvLabel][4];//晶粒面积
- }
- else
- {
- smalll_index_2 += massLabelPoints[kvLabel][0];
- aec_index_2 += massLabelPoints[kvLabel][4];//晶粒面积
- }
- }
- double area_index = lstAttribute[matIndex][4] * physical_area_length_Micron * physical_area_length_Micron;//视场总面积
- //保证两个晶粒面积相加是100%
- if (area_index > 0)
- {
- double aec_scale = (aec_index_1 + aec_index_2) / area_index;
- if (aec_scale == 0)
- aec_scale = 1.0;
- aec_index_1 = aec_index_1 / aec_scale;
- aec_index_2 = aec_index_2 / aec_scale;
- }
- smalll_index_1 = smalll_index_1 / grainNumber_1;
- small_l_1 += smalll_index_1;//汇总直径
- small_count_1 += 1;//汇总晶粒个数
- area_sum_1 += aec_index_1;//汇总晶粒总面积
- area_view_1 += (area_index == 0 ? 100.0 : (aec_index_1 * 100.0 / area_index));//面积百分数
- dgvr.Cells[2].Value = smalll_index_1;//平均晶粒直径
- dgvr.Cells[3].Value = aec_index_1;//条带晶粒总面积
- dgvr.Cells[4].Value = area_index == 0 ? 100.0 : (aec_index_1 * 100.0 / area_index);//面积百分数
- dgvr.Cells[5].Value = getGradeValue(smalll_index_1);
- smalll_index_2 = smalll_index_2 / grainNumber_2;
- small_l_2 += smalll_index_2;//汇总直径
- small_count_2 += 1;//汇总晶粒个数
- area_sum_2 += aec_index_2;//汇总晶粒总面积
- area_view_2 += (area_index == 0 ? 100.0 : (aec_index_2 * 100.0 / area_index));//面积百分数
- dgvr.Cells[6].Value = smalll_index_2;//平均晶粒直径
- dgvr.Cells[7].Value = aec_index_2;//条带晶粒总面积
- dgvr.Cells[8].Value = area_index == 0 ? 100.0 : (aec_index_2 * 100.0 / area_index);//面积百分数
- dgvr.Cells[9].Value = getGradeValue(smalll_index_2);
- this.dataGridView2.Rows.Add(dgvr);
- }
- for (int dataTableI = dataTables.Count - 1; dataTableI >= 0; dataTableI--)
- {
- System.Data.DataTable dataTable1 = dataTables[dataTableI];
- if (dataTable1.TableName.Equals(tag))/*dataTable.TableName*/
- dataTables.RemoveAt(dataTableI);
- }
- System.Data.DataTable dataTable = new System.Data.DataTable();
- dataTable.TableName = tag;
- foreach (DataGridViewColumn c in this.dataGridView2.Columns)
- {
- dataTable.Columns.Add(c.Name);
- }
- for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = dataTable.NewRow();
- for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView2.Columns[c].Name] = this.dataGridView2.Rows[r].Cells[c].Value;
- }
- dataTable.Rows.Add(dataRow);
- }
- this.dataTables.Add(dataTable);
- gradeValue_1 = getGradeValue(small_l_1 / Math.Max(1, small_count_1));
- gradeValue_2 = getGradeValue(small_l_2 / Math.Max(1, small_count_2));
- return new double[] { small_l_1 / Math.Max(1, small_count_1), area_sum_1, area_view_1 / Math.Max(1, small_count_1)/*, grade_v */
- ,small_l_2 / Math.Max(1, small_count_2), area_sum_2, area_view_2 / Math.Max(1, small_count_2)};//平均直径(μm)、汇总晶粒总面积(μm²)、面积比和对应级别
- //double small_l = 0;//汇总直径
- //int small_count = 0;//汇总晶粒个数
- //double area_sum = 0;//汇总晶粒总面积
- //double area_view = 0;//汇总视场总面积
- //double grade_v = 0;//对应级别
- }
- #region 需继承方法
- /// <summary>
- /// 保存参数
- /// </summary>
- protected override void saveSonData()
- {
- saveParamValue(ParamKey_ShowCheckGrainDiameter, comboBox4.SelectedIndex.ToString(), (int)Base.Dtryt.Interger);//晶粒直径
- saveParamValue(ParamKey_ShowGrainDiameter, Convert.ToDecimal(textBox1.Text).ToString(), (int)Base.Dtryt.Decimal);//晶粒直径
- saveParamValue(ParamKey_ShowRibbonCrystalGrain, checkBox_ShowAEC_Color.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//显示带状晶粒颜色
- saveParamValue(ParamKey_ShowRibbonCrystalGrainColor, panel1_1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Interger);//颜色
- saveParamValue(ParamKey_ShowRibbonCrystalGrainDiameter, checkBox_ShowAECLengh.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//显示带状晶粒直径
- saveParamValue(ParamKey_ShowRibbonCrystalGrainDiameterFontSize, textBox1_1.Text, (int)Base.Dtryt.Interger);//字号
- saveParamValue(ParamKey_ShowRibbonCrystalGrainDiameterColor, panel1_2.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Interger);//颜色
- }
- /// <summary>
- /// 获取参数
- /// </summary>
- protected override void getSonData()
- {
- object ShowGrainBoundry;
- if (GetParamValue1(ParamKey_ShowCheckGrainDiameter, out ShowGrainBoundry))
- comboBox4.SelectedIndex = Convert.ToInt32(ShowGrainBoundry);
- if (GetParamValue1(ParamKey_ShowGrainDiameter, out ShowGrainBoundry))
- textBox1.Text = ShowGrainBoundry.ToString();
- if (GetParamValue1(ParamKey_ShowRibbonCrystalGrain, out ShowGrainBoundry))
- checkBox_ShowAEC_Color.Checked = Convert.ToBoolean(ShowGrainBoundry);
- if (GetParamValue1(ParamKey_ShowRibbonCrystalGrainColor, out ShowGrainBoundry))
- panel1_1.BackColor = Color.FromArgb(Convert.ToInt32(ShowGrainBoundry));
- if (GetParamValue1(ParamKey_ShowRibbonCrystalGrainDiameter, out ShowGrainBoundry))
- checkBox_ShowAECLengh.Checked = Convert.ToBoolean(ShowGrainBoundry);
- if (GetParamValue1(ParamKey_ShowRibbonCrystalGrainDiameterFontSize, out ShowGrainBoundry))
- textBox1_1.Text = ShowGrainBoundry.ToString();
- if (GetParamValue1(ParamKey_ShowRibbonCrystalGrainDiameterColor, out ShowGrainBoundry))
- panel1_2.BackColor = Color.FromArgb(Convert.ToInt32(ShowGrainBoundry));
- }
- /// <summary>
- /// 获取参数
- /// </summary>
- protected override object saveRecordingData(string key)
- {
- object value = null;
- switch (key)
- {
- case "ShowCheckGrainDiameter":
- value = comboBox4.SelectedIndex;
- break;
- case "ShowGrainDiameter":
- value = textBox1.Text;
- break;
- case "ShowRibbonCrystalGrain":
- value = checkBox_ShowAEC_Color.Checked;
- break;
- case "ShowRibbonCrystalGrainColor":
- value = panel1_1.BackColor.ToArgb();
- break;
- case "ShowRibbonCrystalGrainDiameter":
- value = checkBox_ShowAECLengh.Checked;
- break;
- case "ShowRibbonCrystalGrainDiameterFontSize":
- value = textBox1_1.Text;
- break;
- case "ShowRibbonCrystalGrainDiameterColor":
- value = panel1_2.BackColor.ToArgb();
- break;
- }
- return value;
- }
- /// <summary>
- /// 保存结果
- /// </summary>
- protected override void buildListBox_analysisResult(string imagesKey, int analysisPicture, bool saveAll = false)
- {
- if (!saveAll)
- {
- if (this.matOrg == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!");
- return;
- }
- }
- string imgName = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetFriendlyName();
- string tag = imagesKey;
- bool replace = false;
- int add = 0;
- foreach (ListViewItem item in this.listView2.Items)
- {
- if (item.Tag.Equals(tag))
- {
- add++;
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- replace = true;
- }
- break;
- }
- }
- if (!replace && this.listView2.Items.Count > 0 && add > 0)
- return;
- if (!replace)
- {
- ListViewItem listViewItem = new ListViewItem();
- listViewItem.SubItems[0].Text = imgName;
- listViewItem.Tag = "" + tag;
- if (this.listView2.Items.Count == 0)
- this.listView2.Items.Add(listViewItem);
- else
- this.listView2.Items.Insert(0, listViewItem);
- }
- if (analysisPicture != this.selectPicture)//更新二值图片
- binaryClass.updateAnalysisData(imagesKey, analysisPicture);
- //组织详细数据列表的内容,获取截距和面积后,再进行平均的计算
- GrainSizeStandardModel cal_StandardModel = this.GSSClass.standardModel;
- if (imagesKey != null)
- {
- if (!this.GSSClass.standardDict.ContainsKey(imagesKey))
- {
- this.GSSClass.standardDict.Add(imagesKey, this.GSSClass.standardModel.cloneListParamModel());
- cal_StandardModel = this.GSSClass.standardDict[imagesKey];
- }
- if (analysisPicture == this.selectPicture && imagesKey.Equals(getCurrentWorkTag()))
- {
- this.GSSClass.standardModel = this.GSSClass.standardDict[imagesKey];
- cal_StandardModel = this.GSSClass.standardDict[imagesKey];
- }
- }
- Bitmap bitmap = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.CreateAliasedBitmap();
- hasView = this.appWorkspace.DocumentWorkspaces[analysisPicture].GraphicsList.IsExsitView();
- double ruler = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetRuler(MeasurementUnit.Micron);
- string gradeValue1, gradeValue2;
- double[] res_arr = addNewRowsToDatagridView2(cal_StandardModel,imgName,tag, ruler, out gradeValue1, out gradeValue2);
- //double small_l = res_arr[0];
- //double area_l = aec0;// res_arr[1];
- this.dataGridView_Total.Rows.Clear();
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = res_arr[0];
- dgvr.Cells[1].Value = res_arr[1];
- dgvr.Cells[2].Value = res_arr[2];
- dgvr.Cells[3].Value = gradeValue1;
- dgvr.Cells[4].Value = res_arr[3];
- dgvr.Cells[5].Value = res_arr[4];
- dgvr.Cells[6].Value = res_arr[5];
- dgvr.Cells[7].Value = gradeValue2;
- this.dataGridView_Total.Rows.Add(dgvr);
- System.Data.DataTable dataTable = new System.Data.DataTable();
- dataTable.TableName = tag;
- foreach (System.Data.DataTable dataTable1 in dataTable_Totals)
- {
- if (dataTable1.TableName.Equals(dataTable.TableName))
- {
- dataTable_Totals.Remove(dataTable1);
- break;
- }
- }
- foreach (DataGridViewColumn c in this.dataGridView_Total.Columns)
- {
- dataTable.Columns.Add(c.Name);
- }
- for (int r = 0; r < this.dataGridView_Total.Rows.Count; r++)
- {
- System.Data.DataRow dataRow = dataTable.NewRow();
- for (int c = 0; c < this.dataGridView_Total.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView_Total.Columns[c].Name] = this.dataGridView_Total.Rows[r].Cells[c].Value;
- }
- dataTable.Rows.Add(dataRow);
- }
- this.dataTable_Totals.Add(dataTable);
- //to youhua//###############################
- this.RefreshDataGridView4();
- //保存处理后的图片
- double pantographRatio = this.appWorkspace.DocumentWorkspaces[this.selectPicture].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
- List<Bitmap> tempBit = new List<Bitmap>();
- Bitmap originalBit = this.bitmap;// this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
- originalBit.Tag = pantographRatio;
- tempBit.Add(originalBit);
- Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
- Graphics graphics = Graphics.FromImage(newBit);
- //if (true)
- //{ }//0914###18810
- if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null)
- {
- Mat targetMat = this.PhaseModel0Mat;
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- if (this.documentWorkspace.PhaseModels[1].choise && this.documentWorkspace.PhaseModels[1].mat != null)
- {
- Mat targetMat = this.documentWorkspace.PhaseModels[1].mat;
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- if (this.documentWorkspace.PhaseModels[2].choise && this.documentWorkspace.PhaseModels[2].mat != null)
- {
- Mat targetMat = this.documentWorkspace.PhaseModels[2].mat;
- graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
- }
- graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- drawSubclass/*Draw*/(graphics);
- newBit.Tag = pantographRatio;
- tempBit.Add(newBit);
- if (bitDic.ContainsKey(tag))
- bitDic[tag] = tempBit;
- else
- bitDic.Add(tag, tempBit);
- //拼接中间数据
- 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.Xoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.Yoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.Whethertheinternal.Text"));
- dataList.Add(columnName);
- if (GSSClass.standardModel.massLabelPoints.Count > 0)
- {
- int index = 0;
- int outMaxIndex = GSSClass.standardModel.massLabelPoints.Count - 0 - GSSClass.standardModel.within;
- foreach (var item in GSSClass.standardModel.massLabelPoints.Values)//####################
- {
- List<string> strList = new List<string>();
- strList.Add(("" + (++index)).ToString());
- strList.Add(item[2].ToString());
- strList.Add(item[3].ToString());
- if (outMaxIndex < index)
- strList.Add(PdnResources.GetString("Menu.Yes.text"));
- else
- strList.Add(PdnResources.GetString("Menu.no.text"));
- dataList.Add(strList);
- }
- }
- bool isExist = false;//是否已存在进行替换
- int modelIndex = -1;//要替换的下标
- for (int j = 0; j < tempDataModel.Count; j++)
- {
- if (tempDataModel[j].tagName.Equals(tag))
- {
- isExist = true;
- modelIndex = j;
- break;
- }
- }
- if (isExist && modelIndex > -1)
- tempDataModel[modelIndex].dataList = dataList;
- else
- {
- Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel();
- newModel.tagName = tag;
- newModel.picName = imgName;
- newModel.dataList = dataList;
- tempDataModel.Add(newModel);
- }
- }
- ////数据库的name(报告模板)
- //protected override string getTemplateName()
- //{
- // return "Template.Manager.item3.GrainSizeArea214999Method";//#################################
- //}
- //语言包的name(项目工程)
- protected override string getProjectEngineeringName()
- {
- return "Menu.DedicatedAnalysis.BlackMetal.GrainSize.Text";
- }
- ////配置文件名称(辅助线)
- //protected override string getModelName()
- //{
- // return "GrainSizeGuideAreaMethodModel.xml";
- //}
- //辅助线类型名称
- protected override string[] getTypeNames()
- {
- return new string[] {
- PdnResources.GetString("Menu.circular.Text"),
- PdnResources.GetString("Menu.LabelAction.DrawRectangle.Text")};
- }
- protected override void SubclassInitialize()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 小数点位数后调用的事件
- /// </summary>
- protected override void RefreshWhileUpDown1_0ValueChanged()
- {
- this.documentWorkspace.Refresh();
- }
- //切换图片时控制前一张图的信息不遗留显示
- protected override void refreshWhileImgChanged()
- {
- if (this.bitmap != null && matOrg != null)
- {
- try
- {
- this.documentWorkspace.PhaseModels[2].choise = (!bcOriginChecked() && checkBox_ShowAEC_Color.Checked);
- if (checkBox_ShowAEC_Color.Checked || checkBox_ShowAECLengh.Checked)
- {
- Bitmap bitmap = this.documentWorkspace.CompositionSurface.CreateAliasedBitmap();
- saveMat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- if (binaryClass.PhaseModels0Mat != null)
- {
- phaseMat = binaryClass.PhaseModels0Mat;
- }
- else
- {
- phaseMat = this.documentWorkspace.phaseModels[0].mat;
- }
- GetClassNumberOfGrains();
- }
- else
- this.documentWorkspace.Refresh();
- }
- catch (Exception)
- {
- }
- }
- else
- {
- this.documentWorkspace.PhaseModels[2].mat = null;//清空前一张图的信息不遗留显示
- GSSClass.standardModel.massLabelPoints.Clear();//1013###19098(切换图片的时候前一张图的信息不遗留显示)}
- //1013###18808(切换图片的时候前一张图的信息不遗留显示)
- this.documentWorkspace.Refresh();
- }
- }
- /// <summary>
- /// 是否用不同颜色显示晶粒
- /// </summary>
- /// <returns></returns>
- protected override Boolean ShowGrainColorChecked()
- {
- return checkBox_ShowAEC_Color.Checked;
- }
- /// <summary>
- /// 是否显示视场
- /// </summary>
- /// <returns></returns>
- protected override Boolean ShowDrawClassView()
- {
- return true;
- }
- protected override void drawSubclass(Graphics graphics, string imagesKey = null, int analysisPicture = -1)
- {
- //显示带状晶粒直径
- if (!checkBox_ShowAECLengh.Checked || GSSClass.standardModel.massLabelPointsList.Count == 0 || GSSClass.standardModel.currentNccompSelectList.Count == 0 || GSSClass.standardModel.currentNccompSelectList.Count != GSSClass.standardModel.massLabelPointsList.Count)
- return;
- for (int matIndex = 0; matIndex < GSSClass.standardModel.massLabelPointsList.Count; matIndex++)
- {
- Dictionary<int, List<double>> massLabelPoints = GSSClass.standardModel.massLabelPointsList[matIndex];
- ArrayList currentNccompSelect = GSSClass.standardModel.currentNccompSelectList[matIndex];
- int index = 0;
- float fontsize;
- if (!float.TryParse(this.textBox1_1.Text.ToString(), out fontsize))
- fontsize = 12;
- Font myFont = new Font("宋体", fontsize);
- Brush bush = new SolidBrush(this.panel1_2.BackColor);//填充的颜色
- foreach (var item in massLabelPoints.Values)
- {
- index += 1;//should == label!
- if (currentNccompSelect.Contains(index))
- graphics.DrawString("" + DecnumString(item[0].ToString())/*index*/, myFont, bush, (float)item[2] - 5, (float)item[3] - 5);
- }
- }
- }
- /// <summary>
- /// PanelC的调色板颜色改变
- /// </summary>
- protected override void ColorPanelChanged(Panel panel)
- {
- //根据等级设置晶粒颜色
- if (panel == this.panel1_1)
- setMat2ColorOfLabelMat(/*nccomps*/);
- else
- this.documentWorkspace.Refresh();
- }
- #endregion
- }
- }
|