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
{
///
/// 各个视场属性集合,索引0-横坐标,1-纵坐标,2-视场宽度,3-视场高度,4-视场面积
///
protected List> lstAttribute = new List>();
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);
}
///
/// 加载后控制窗口变化
///
///
///
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);
}
///
/// 字号改变
///
///
///
private void TextBox1_1_TextChanged(object sender, EventArgs e)
{
if (checkBox_ShowAECLengh.Checked)
this.documentWorkspace.Refresh();
}
///
/// 输入阈值改变
///
///
///
private void TextBox1_TextChanged(object sender, EventArgs e)
{
GetClassNumberOfGrains();//setMat2ColorOfLabelMat
}
///
/// 显示带状晶粒颜色改变
///
///
///
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();
}
}
///
/// 显示带状晶粒直径改变
///
///
///
private void checkBox_ShowAECLengh_CheckedChanged(object sender, EventArgs e)
{
this.documentWorkspace.Refresh();
}
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
//根据等级设置晶粒颜色
setMat2ColorOfLabelMat(/*nccomps*/);
}
#endregion 初始化组件和实现组件事件
///
/// 刷新晶粒编号/刷新晶粒颜色?//############
///
///
///
/// 返回晶粒个数
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(point[0], point[1]).Item3 > 0)
{
OrgViewMat.Set(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(point[0], point[1]).Item3 > 0)
{
OrgViewMat.Set(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 OrgMatLists = new List();
//视场个数
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 attribute;//单视场属性集合
for (int h = 1; h < orgCentroids.Height; h++)
{
attribute = new List();
int x = orgStats.At(h, 0);
int y = orgStats.At(h, 1);
int width = orgStats.At(h, 2);
int height = orgStats.At(h, 3);
int areaField1 = orgStats.At(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(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 attribute = new List();//单视场属性集合
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 pointss = new List();
foreach (OpenCvSharp.Point[] contour in contours)
{
if (contour.Length < 100)
{
foreach (OpenCvSharp.Point point in contour)
{
erzhi.Set(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 keyValues = new Dictionary();
Dictionary> massLabelPoints = new Dictionary>();
// 矩形边线上的连通域
ArrayList nccompSelect = new ArrayList();
double aec;
double aec_length;
//Dictionary 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(label, 0) + offsetX, (int)centroids.At(label, 1) + offsetY);
nccompSelect.Add(label);
aec = stats/*currentStats*/.At(label, 4) * physical_area_length_Micron * physical_area_length_Micron;//晶粒面积
aec_length = Math.Sqrt(aec);
massLabelPoints.Add(label, new List() { 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*/;
}
///
/// 根据等级设置晶粒颜色,并计算复合条件的label集合到currentNccompSelectList
///
/// 连通域数量
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> 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(y, x).Item3 == 0)
// continue;//不在视场图像范围内
label = currentLabelMat.At(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();
}
///
/// 面积法组织分项数据列表的内容,并返回 条带/非条带的:平均直径(μm)、汇总晶粒总面积(μm²)、面积比和对应级别
///
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 measurementUnitDictionary = Startup.instance.rules;
//选择标尺的物理长度(1倍下的 微米/像素)
//double physical_area_length_Micron = measurementUnitDictionary[MeasurementUnit.Micron];
for (int matIndex = 0; matIndex < cal_StandardModel.massLabelPointsList.Count; matIndex++)
{
Dictionary> 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 需继承方法
///
/// 保存参数
///
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);//颜色
}
///
/// 获取参数
///
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));
}
///
/// 获取参数
///
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;
}
///
/// 保存结果
///
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 tempBit = new List();
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> dataList = new List>();
List columnName = new List();
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 strList = new List();
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();
}
///
/// 小数点位数后调用的事件
///
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();
}
}
///
/// 是否用不同颜色显示晶粒
///
///
protected override Boolean ShowGrainColorChecked()
{
return checkBox_ShowAEC_Color.Checked;
}
///
/// 是否显示视场
///
///
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> 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);
}
}
}
///
/// PanelC的调色板颜色改变
///
protected override void ColorPanelChanged(Panel panel)
{
//根据等级设置晶粒颜色
if (panel == this.panel1_1)
setMat2ColorOfLabelMat(/*nccomps*/);
else
this.documentWorkspace.Refresh();
}
#endregion
}
}