using OpenCvSharp; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.SettingModel; using PaintDotNet.DedicatedAnalysis.GrainSize.GBT6394_2017; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Windows.Forms; using Point = System.Drawing.Point; using PaintDotNet.Base.Functionodel; using PaintDotNet.Annotation.Enum; using PaintDotNet.CustomControl; using GroupBox = System.Windows.Forms.GroupBox; using CheckBox = System.Windows.Forms.CheckBox; using Button = System.Windows.Forms.Button; using Label = System.Windows.Forms.Label; using TextBox = System.Windows.Forms.TextBox; using System.Data; using PaintDotNet.DbOpreate.DbModel; using PaintDotNet.Annotation; namespace PaintDotNet.DedicatedAnalysis.GrainSize { internal class GrainSizeAreaMethodDialog : PdnBaseForm { /// /// 晶粒度(面积法) /// #region 控件 private GroupBox groupBox1; private Button button2; private CheckBox checkBox2_0; private GroupBox groupBox2; private ListView listView1; private Button button9; private GroupBox groupBox8; private NumericUpDown numericUpDown1_0; private Button button16; private Label label5; private Button button14; private Button button13; private DataGridView dataGridView4; private Button button12; private Button button11; private Label label4; private Label label3; private GroupBox groupBox7; private GroupBox groupBox3; private GroupBox groupBox11; private ComboBox comboBox1; private CheckBox checkBox5_0; private CheckBox checkBox4_0; private CheckBox checkBox3_0; private ImageList imageList1; private IContainer components; private Button button1; #endregion /// /// 主控件 /// private AppWorkspace appWorkspace; /// /// 0,GBT6394; ; 2,GBT24177; 3,E112; 4,ISO643 /// int gbtType; /// /// 用于编号的坐标点集合 /// List massLabelPoints = new List(); /// /// 矩形内的连通域 /// int within = 0; //分析结果列表的头标题 /// /// PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), "网格面积", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.averageintercept.text"), PdnResources.GetString("Menu.Averagegrainsizegrade.text") /// List contentHead; /// /// 保存用于生成报告的图片 /// private List bitList; /// /// 储存点击保存结果后的所有原图与分析图 /// private Dictionary> bitDic = new Dictionary>(); /// /// 中间数据 /// private List tempDataModel = new List(); //二值化集成1 BinaryClass binaryClass; /// /// 调色板 /// private ColorsForm colorsFormGrid; /// /// 选中图片的bitmap /// private Bitmap bitmap; private DocumentWorkspaceWindow documentWorkspace; /// /// 公共按钮 /// private CommonControlButtons commonControlButtons; //辅助线集成 GrainSizeGuideClass guideClass = new GrainSizeGuideClass(); /// /// 是否选择了图片 /// private int selectPicture = -1; /// /// 存在视场标记 /// private bool existViewFlag = false; /// /// 当前选择的图片 /// private Mat mat; /// /// 分析结果暂存 /// private List dataTables = new List(); /// /// 全部显示 /// private bool allShow = false; /// /// 图形位置 /// private PointF loctation; /// /// 图形上所有的点 /// private List linePointList = new List(); private string oldSelectItem; private PointF m_StartPoint = Point.Empty; private bool m_canMove; private DataGridViewTextBoxColumn Column1; private DataGridViewTextBoxColumn Column2; private DataGridViewTextBoxColumn Column3; private DataGridViewTextBoxColumn Column4; private DataGridViewTextBoxColumn Column5; private DataGridViewTextBoxColumn Column6; private ListView listView2; private CheckBox checkBox11; private GroupBox groupBox4; private Label label8; private NumericUpDown numericUpDown2; private NumericUpDown numericUpDown1; private CheckBox checkBox2; private TextBox textBox6; private Label label7; private ComboBox comboBox3; private Label label6; private ComboBox comboBox2; private Label label1; private CheckBox checkBox1; private Panel panel1; private Button button3; private Button button4; private Button button8; private BinaryControlSmaller bc; public bool comboboxChange = true; /// /// /// /// /// 0,GBT6394; ; 2,GBT24177; 3,E112; 4,ISO643;5,YST347(XX) public GrainSizeAreaMethodDialog(AppWorkspace appWorkspace, int gbtType) { InitializeComponent(); this.contentHead = new List() { PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), PdnResources.GetString("Menu.Gridarea.text") + "(μm²)", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.averageintercept.text") + "(μm)", PdnResources.GetString("Menu.Averagegrainsizegrade.text") }; this.binaryClass = new BinaryClass(); InitializeCustomControl(); InitializeLanguageText(); this.appWorkspace = appWorkspace; this.gbtType = gbtType; string dialogName = "GBT6394_2017"; switch (this.gbtType) { case 2: dialogName = "GBT24177_2009"; break; case 3: dialogName = "ASTM_E112_2013"; break; case 4: dialogName = "ISO643"; break; default: break; } this.Text = dialogName + "("+ PdnResources.GetString("Menu.Areamethod.text")+ ")"; this.button11.Visible = true; this.button16.Visible = false; // //二值化相关 // this.colorsFormGrid = new ColorsForm(); this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen; this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged)); //二值化end // //初始化图像控件 // this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace); this.documentWorkspace.Dock = DockStyle.Fill; this.documentWorkspace.HookMouseEvents(); this.documentWorkspace.AuxiliaryLineEnabled = false; this.documentWorkspace.Visible = false; this.documentWorkspace.panel.MouseDown += OnMouseDown; this.documentWorkspace.panel.Paint += Panel_Paint; this.documentWorkspace.panel.MouseMove += onMouseMove; this.documentWorkspace.panel.MouseUp += onMouseUp; this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click); this.groupBox7.Controls.Add(documentWorkspace); // //初始化操作按钮 // this.commonControlButtons = new CommonControlButtons(); this.commonControlButtons.Dock = DockStyle.Top; this.commonControlButtons.Height = 30; this.commonControlButtons.HideZoomToWindowAndActualSize(); this.groupBox7.Controls.Add(commonControlButtons); //二值化集成2 bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件 binaryClass.createDocumentItemsSmaller(new string[] { PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"), PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text") } , this.bc, this.appWorkspace, this.documentWorkspace, this.listView1);//初始化相的工作结构 binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件 //初始化头 this.listView2.View = View.Details; ColumnHeader header0 = new ColumnHeader(); header0.Text = ""; header0.Width = 180; this.listView2.Columns.Add(header0); InitPicList(); InitComboboxValue(null); InitCommonButtonEvent(); string templateName = "Template.Manager.item3.GrainSizeArea6394Method"; switch (this.gbtType) { case 2: templateName = "Template.Manager.item3.GrainSizeArea24177Method"; break; case 3: templateName = "Template.Manager.item3.GrainSizeArea112Method"; break; case 4: templateName = "Template.Manager.item3.GrainSizeArea643Method"; break; default: break; } SetAnalyzeModelFromXml(templateName); } private void InitCommonButtonEvent() { this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click); this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click); this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click); this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click); this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click); this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click); } private void zoomInButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomIn(); } private void zoomOutButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomOut(); } private void zoomToWindowButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow; } private void actualSizeButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor; this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne; } private void pointerButton_Click(object sender, EventArgs e) { this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer; } private void mobileModeButton_Click(object sender, EventArgs e) { this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode; } /// /// 初始化图片列表数据 /// public void InitPicList() { //初始化图片列表 for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++) { this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail); this.listView1.Items.Add("", i); this.listView1.Items[i].ImageIndex = i; this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); } } #region 初始化 private void InitializeLanguageText() { this.checkBox1.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text"); this.label1.Text = PdnResources.GetString("Menu.Grainboundarytype.text") + ":"; this.label6.Text = PdnResources.GetString("Menu.Denoisingtype.text") + ":"; this.label7.Text = PdnResources.GetString("Menu.Image.Sigma.Text")+":"; this.checkBox2.Text = PdnResources.GetString("Menu.Grainboundaryenhancement.text"); this.label8.Text = PdnResources.GetString("Menu.Grainboundarysize.text") + ":"; this.button3.Text = PdnResources.GetString("Menu.Grainboundaryedit.text"); this.groupBox4.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text"); this.checkBox3_0.Text = PdnResources.GetString("Menu.displaygrainboundaries.text"); this.checkBox4_0.Text = PdnResources.GetString("Menu.displaygrid.text"); this.checkBox5_0.Text = PdnResources.GetString("Menu.Displaygrainnumber.text"); this.checkBox11.Text = PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text"); this.button4.Text = PdnResources.GetString("Menu.Refresh.text"); this.groupBox11.Text = PdnResources.GetString("Menu.Displayparamssettings.text"); this.groupBox3.Text = PdnResources.GetString("Menu.Tools.GridLine.Text"); this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text"); this.button11.Text = PdnResources.GetString("Menu.Showall.text"); this.button12.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.Column6.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text"); this.Column5.HeaderText = PdnResources.GetString("Menu.averageintercept.text") + "(μm)"; this.Column4.HeaderText = PdnResources.GetString("Menu.Numberofgrains.text"); this.Column2.HeaderText = PdnResources.GetString("Menu.Tools.GridLine.Text"); this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text"); this.button13.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text"); this.button14.Text = PdnResources.GetString("Menu.Exportresults.text"); this.label5.Text = PdnResources.GetString("Menu.Decimal.text") + ":"; this.button16.Text = PdnResources.GetString("Menu.Cancelshowall.text"); this.button8.Text = PdnResources.GetString("Menu.Exportproject.text"); this.groupBox8.Text = PdnResources.GetString("Menu.Analysisresult.text"); this.button9.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text"); this.groupBox2.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text"); this.button1.Text = PdnResources.GetString("Menu.Setting.Text"); this.checkBox2_0.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text"); this.button2.Text = PdnResources.GetString("Menu.Saveresult.text"); this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.Column3.HeaderText = PdnResources.GetString("Menu.Gridarea.text") + "(μm²)"; this.comboBox3.Items.AddRange(new object[] { PdnResources.GetString("Menu.Gaussiansmoothing.text"), PdnResources.GetString("Menu.directionalsmoothing.text")}); this.comboBox2.Items.AddRange(new object[] { PdnResources.GetString("Menu.Brightgrainboundary.text"), PdnResources.GetString("Menu.Darkgrainboundary.text"), PdnResources.GetString("Menu.gradient.text")}); } private void InitializeCustomControl() { // // bc // this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller(); this.bc.BinaryBackColor = System.Drawing.Color.Red; this.bc.BinaryChecked = false; this.bc.BinaryStyle = 1; this.bc.Location = new System.Drawing.Point(149, 57); this.bc.Name = "bc"; this.bc.OriginChecked = false; this.bc.scope1End = 0D; this.bc.scope1Start = 0D; this.bc.scope2End = 0D; this.bc.scope2Start = 0D; this.bc.scope3End = 0D; this.bc.scope3Start = 0D; this.bc.Size = new System.Drawing.Size(360, 247); this.bc.TabIndex = 26; this.Controls.Add(this.bc); this.Controls.SetChildIndex(this.bc, 0); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button2 = new System.Windows.Forms.Button(); this.checkBox2_0 = new System.Windows.Forms.CheckBox(); this.button1 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.listView1 = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.button9 = new System.Windows.Forms.Button(); this.groupBox8 = new System.Windows.Forms.GroupBox(); this.button8 = new System.Windows.Forms.Button(); this.listView2 = new System.Windows.Forms.ListView(); this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown(); this.button16 = new System.Windows.Forms.Button(); this.label5 = new System.Windows.Forms.Label(); this.button14 = new System.Windows.Forms.Button(); this.button13 = new System.Windows.Forms.Button(); this.dataGridView4 = new System.Windows.Forms.DataGridView(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.button12 = new System.Windows.Forms.Button(); this.button11 = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.groupBox7 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.groupBox11 = new System.Windows.Forms.GroupBox(); this.button4 = new System.Windows.Forms.Button(); this.checkBox11 = new System.Windows.Forms.CheckBox(); this.checkBox5_0 = new System.Windows.Forms.CheckBox(); this.checkBox4_0 = new System.Windows.Forms.CheckBox(); this.checkBox3_0 = new System.Windows.Forms.CheckBox(); this.panel1 = new System.Windows.Forms.Panel(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.button3 = new System.Windows.Forms.Button(); this.label8 = new System.Windows.Forms.Label(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.textBox6 = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.comboBox3 = new System.Windows.Forms.ComboBox(); this.label6 = new System.Windows.Forms.Label(); this.comboBox2 = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox8.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).BeginInit(); this.groupBox3.SuspendLayout(); this.groupBox11.SuspendLayout(); this.groupBox4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.checkBox2_0); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(14, 3); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(1081, 50); this.groupBox1.TabIndex = 2; this.groupBox1.TabStop = false; // // button2 // this.button2.BackColor = System.Drawing.SystemColors.Control; this.button2.Location = new System.Drawing.Point(985, 14); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(84, 30); this.button2.TabIndex = 3; this.button2.UseVisualStyleBackColor = false; this.button2.Click += new System.EventHandler(this.button2_Click); // // checkBox2_0 // this.checkBox2_0.AutoSize = true; this.checkBox2_0.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; this.checkBox2_0.Location = new System.Drawing.Point(138, 22); this.checkBox2_0.Name = "checkBox2_0"; this.checkBox2_0.Size = new System.Drawing.Size(132, 16); this.checkBox2_0.TabIndex = 2; this.checkBox2_0.UseVisualStyleBackColor = true; // // button1 // this.button1.BackColor = System.Drawing.SystemColors.Control; this.button1.Location = new System.Drawing.Point(15, 14); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(84, 30); this.button1.TabIndex = 0; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox2 // this.groupBox2.Controls.Add(this.listView1); this.groupBox2.Location = new System.Drawing.Point(14, 59); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(135, 561); this.groupBox2.TabIndex = 3; this.groupBox2.TabStop = false; // // listView1 // this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.listView1.HideSelection = false; this.listView1.LargeImageList = this.imageList1; this.listView1.Location = new System.Drawing.Point(5, 17); this.listView1.MultiSelect = false; this.listView1.Name = "listView1"; this.listView1.Size = new System.Drawing.Size(124, 538); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1.ImageSize = new System.Drawing.Size(64, 64); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // button9 // this.button9.BackColor = System.Drawing.SystemColors.Control; this.button9.Location = new System.Drawing.Point(241, 19); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(92, 26); this.button9.TabIndex = 10; this.button9.UseVisualStyleBackColor = false; this.button9.Click += new System.EventHandler(this.button9_Click); // // groupBox8 // this.groupBox8.Controls.Add(this.button8); this.groupBox8.Controls.Add(this.listView2); this.groupBox8.Controls.Add(this.numericUpDown1_0); this.groupBox8.Controls.Add(this.button16); this.groupBox8.Controls.Add(this.label5); this.groupBox8.Controls.Add(this.button14); this.groupBox8.Controls.Add(this.button13); this.groupBox8.Controls.Add(this.dataGridView4); this.groupBox8.Controls.Add(this.button12); this.groupBox8.Controls.Add(this.button11); this.groupBox8.Controls.Add(this.label4); this.groupBox8.Controls.Add(this.label3); this.groupBox8.Location = new System.Drawing.Point(14, 626); this.groupBox8.Name = "groupBox8"; this.groupBox8.Size = new System.Drawing.Size(1081, 204); this.groupBox8.TabIndex = 10; this.groupBox8.TabStop = false; // // button8 // this.button8.BackColor = System.Drawing.SystemColors.Control; this.button8.Location = new System.Drawing.Point(941, 109); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(128, 26); this.button8.TabIndex = 25; this.button8.UseVisualStyleBackColor = false; this.button8.Click += new System.EventHandler(this.button8_Click); // // listView2 // this.listView2.FullRowSelect = true; this.listView2.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; this.listView2.HideSelection = false; this.listView2.Location = new System.Drawing.Point(15, 56); this.listView2.Name = "listView2"; this.listView2.Size = new System.Drawing.Size(181, 140); this.listView2.TabIndex = 24; this.listView2.UseCompatibleStateImageBehavior = false; this.listView2.SelectedIndexChanged += new System.EventHandler(this.listView2_SelectedIndexChanged); // // numericUpDown1_0 // this.numericUpDown1_0.Location = new System.Drawing.Point(997, 163); this.numericUpDown1_0.Maximum = new decimal(new int[] { 10, 0, 0, 0}); this.numericUpDown1_0.Name = "numericUpDown1_0"; this.numericUpDown1_0.Size = new System.Drawing.Size(56, 21); this.numericUpDown1_0.TabIndex = 21; this.numericUpDown1_0.Value = new decimal(new int[] { 2, 0, 0, 0}); this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged); // // button16 // this.button16.BackColor = System.Drawing.SystemColors.Control; this.button16.Location = new System.Drawing.Point(15, 20); this.button16.Name = "button16"; this.button16.Size = new System.Drawing.Size(93, 26); this.button16.TabIndex = 20; this.button16.UseVisualStyleBackColor = false; this.button16.Click += new System.EventHandler(this.button16_Click); // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(955, 169); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(41, 12); this.label5.TabIndex = 18; // // button14 // this.button14.BackColor = System.Drawing.SystemColors.Control; this.button14.Location = new System.Drawing.Point(941, 71); this.button14.Name = "button14"; this.button14.Size = new System.Drawing.Size(128, 26); this.button14.TabIndex = 16; this.button14.UseVisualStyleBackColor = false; this.button14.Click += new System.EventHandler(this.button14_Click); // // button13 // this.button13.BackColor = System.Drawing.SystemColors.Control; this.button13.Location = new System.Drawing.Point(941, 34); this.button13.Name = "button13"; this.button13.Size = new System.Drawing.Size(128, 26); this.button13.TabIndex = 12; this.button13.UseVisualStyleBackColor = false; this.button13.Click += new System.EventHandler(this.button13_Click); // // dataGridView4 // this.dataGridView4.AllowUserToAddRows = false; this.dataGridView4.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView4.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F); dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridView4.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; this.dataGridView4.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView4.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column4, this.Column5, this.Column6}); this.dataGridView4.Location = new System.Drawing.Point(228, 20); this.dataGridView4.Name = "dataGridView4"; this.dataGridView4.ReadOnly = true; this.dataGridView4.RowHeadersVisible = false; this.dataGridView4.RowTemplate.Height = 23; this.dataGridView4.Size = new System.Drawing.Size(693, 176); this.dataGridView4.TabIndex = 15; // // Column1 // this.Column1.Name = "Column1"; this.Column1.ReadOnly = true; // // Column2 // this.Column2.Name = "Column2"; this.Column2.ReadOnly = true; // // Column3 // this.Column3.Name = "Column3"; this.Column3.ReadOnly = true; // // Column4 // this.Column4.Name = "Column4"; this.Column4.ReadOnly = true; // // Column5 // this.Column5.Name = "Column5"; this.Column5.ReadOnly = true; // // Column6 // this.Column6.Name = "Column6"; this.Column6.ReadOnly = true; // // button12 // this.button12.BackColor = System.Drawing.SystemColors.Control; this.button12.Location = new System.Drawing.Point(145, 20); this.button12.Name = "button12"; this.button12.Size = new System.Drawing.Size(52, 26); this.button12.TabIndex = 13; this.button12.UseVisualStyleBackColor = false; this.button12.Click += new System.EventHandler(this.button12_Click); // // button11 // this.button11.BackColor = System.Drawing.SystemColors.Control; this.button11.Location = new System.Drawing.Point(15, 20); this.button11.Name = "button11"; this.button11.Size = new System.Drawing.Size(63, 26); this.button11.TabIndex = 12; this.button11.UseVisualStyleBackColor = false; this.button11.Click += new System.EventHandler(this.button11_Click); // // label4 // this.label4.AutoSize = true; this.label4.ForeColor = System.Drawing.SystemColors.ScrollBar; this.label4.Location = new System.Drawing.Point(924, 9); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(11, 192); this.label4.TabIndex = 1; this.label4.Text = "|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|"; // // label3 // this.label3.AutoSize = true; this.label3.ForeColor = System.Drawing.SystemColors.ScrollBar; this.label3.Location = new System.Drawing.Point(214, 9); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(11, 192); this.label3.TabIndex = 0; this.label3.Text = "|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|"; // // groupBox7 // this.groupBox7.Location = new System.Drawing.Point(515, 59); this.groupBox7.Name = "groupBox7"; this.groupBox7.Size = new System.Drawing.Size(580, 561); this.groupBox7.TabIndex = 11; this.groupBox7.TabStop = false; // // groupBox3 // this.groupBox3.Controls.Add(this.button9); this.groupBox3.Controls.Add(this.comboBox1); this.groupBox3.Location = new System.Drawing.Point(153, 474); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(355, 58); this.groupBox3.TabIndex = 12; this.groupBox3.TabStop = false; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(15, 22); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(220, 20); this.comboBox1.TabIndex = 0; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // groupBox11 // this.groupBox11.Controls.Add(this.button4); this.groupBox11.Controls.Add(this.checkBox11); this.groupBox11.Controls.Add(this.checkBox5_0); this.groupBox11.Controls.Add(this.checkBox4_0); this.groupBox11.Controls.Add(this.checkBox3_0); this.groupBox11.Location = new System.Drawing.Point(152, 538); this.groupBox11.Name = "groupBox11"; this.groupBox11.Size = new System.Drawing.Size(356, 82); this.groupBox11.TabIndex = 17; this.groupBox11.TabStop = false; // // button4 // this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right; this.button4.Location = new System.Drawing.Point(259, 23); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 23); this.button4.TabIndex = 18; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // checkBox11 // this.checkBox11.AutoSize = true; this.checkBox11.Checked = true; this.checkBox11.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox11.Location = new System.Drawing.Point(139, 49); this.checkBox11.Name = "checkBox11"; this.checkBox11.Size = new System.Drawing.Size(132, 16); this.checkBox11.TabIndex = 3; this.checkBox11.UseVisualStyleBackColor = true; this.checkBox11.CheckedChanged += new System.EventHandler(this.checkBox11_CheckedChanged); // // checkBox5_0 // this.checkBox5_0.AutoSize = true; this.checkBox5_0.Checked = true; this.checkBox5_0.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox5_0.Location = new System.Drawing.Point(140, 27); this.checkBox5_0.Name = "checkBox5_0"; this.checkBox5_0.Size = new System.Drawing.Size(96, 16); this.checkBox5_0.TabIndex = 2; this.checkBox5_0.UseVisualStyleBackColor = true; this.checkBox5_0.CheckedChanged += new System.EventHandler(this.checkBox5_0_CheckedChanged); // // checkBox4_0 // this.checkBox4_0.AutoSize = true; this.checkBox4_0.Checked = true; this.checkBox4_0.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox4_0.Location = new System.Drawing.Point(15, 49); this.checkBox4_0.Name = "checkBox4_0"; this.checkBox4_0.Size = new System.Drawing.Size(72, 16); this.checkBox4_0.TabIndex = 1; this.checkBox4_0.UseVisualStyleBackColor = true; this.checkBox4_0.CheckedChanged += new System.EventHandler(this.checkBox4_0_CheckedChanged); // // checkBox3_0 // this.checkBox3_0.AutoSize = true; this.checkBox3_0.Checked = true; this.checkBox3_0.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox3_0.Location = new System.Drawing.Point(15, 27); this.checkBox3_0.Name = "checkBox3_0"; this.checkBox3_0.Size = new System.Drawing.Size(72, 16); this.checkBox3_0.TabIndex = 0; this.checkBox3_0.UseVisualStyleBackColor = true; this.checkBox3_0.CheckedChanged += new System.EventHandler(this.checkBox3_0_CheckedChanged); // // panel1 // this.panel1.BackColor = System.Drawing.Color.Red; this.panel1.Location = new System.Drawing.Point(89, 16); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(72, 21); this.panel1.TabIndex = 20; this.panel1.Click += new System.EventHandler(this.panel1_Click); // // groupBox4 // this.groupBox4.Controls.Add(this.panel1); this.groupBox4.Controls.Add(this.button3); this.groupBox4.Controls.Add(this.label8); this.groupBox4.Controls.Add(this.numericUpDown2); this.groupBox4.Controls.Add(this.numericUpDown1); this.groupBox4.Controls.Add(this.checkBox2); this.groupBox4.Controls.Add(this.textBox6); this.groupBox4.Controls.Add(this.label7); this.groupBox4.Controls.Add(this.comboBox3); this.groupBox4.Controls.Add(this.label6); this.groupBox4.Controls.Add(this.comboBox2); this.groupBox4.Controls.Add(this.label1); this.groupBox4.Controls.Add(this.checkBox1); this.groupBox4.Location = new System.Drawing.Point(153, 310); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(356, 158); this.groupBox4.TabIndex = 25; this.groupBox4.TabStop = false; // // button3 // this.button3.Anchor = System.Windows.Forms.AnchorStyles.Right; this.button3.Location = new System.Drawing.Point(259, 16); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 31; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // label8 // this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(6, 125); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(65, 12); this.label8.TabIndex = 30; // // numericUpDown2 // this.numericUpDown2.DecimalPlaces = 2; this.numericUpDown2.Location = new System.Drawing.Point(164, 121); this.numericUpDown2.Maximum = new decimal(new int[] { 1000, 0, 0, 0}); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(61, 21); this.numericUpDown2.TabIndex = 29; this.numericUpDown2.Tag = "max"; this.numericUpDown2.Value = new decimal(new int[] { 500, 0, 0, 0}); this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged_1); // // numericUpDown1 // this.numericUpDown1.DecimalPlaces = 2; this.numericUpDown1.Location = new System.Drawing.Point(85, 121); this.numericUpDown1.Maximum = new decimal(new int[] { 1000, 0, 0, 0}); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(61, 21); this.numericUpDown1.TabIndex = 28; this.numericUpDown1.Tag = "min"; this.numericUpDown1.Value = new decimal(new int[] { 1, 0, 0, 131072}); this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged_1); // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Checked = true; this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox2.Location = new System.Drawing.Point(8, 57); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(72, 16); this.checkBox2.TabIndex = 26; this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); // // textBox6 // this.textBox6.Location = new System.Drawing.Point(65, 89); this.textBox6.Name = "textBox6"; this.textBox6.Size = new System.Drawing.Size(45, 21); this.textBox6.TabIndex = 25; this.textBox6.Text = "0.5"; this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged); // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(6, 93); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(53, 12); this.label7.TabIndex = 24; // // comboBox3 // this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox3.FormattingEnabled = true; this.comboBox3.Location = new System.Drawing.Point(201, 90); this.comboBox3.Name = "comboBox3"; this.comboBox3.Size = new System.Drawing.Size(133, 20); this.comboBox3.TabIndex = 23; this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged); // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(136, 93); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(65, 12); this.label6.TabIndex = 22; // // comboBox2 // this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox2.FormattingEnabled = true; this.comboBox2.Location = new System.Drawing.Point(201, 55); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(133, 20); this.comboBox2.TabIndex = 11; this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(136, 58); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(65, 12); this.label1.TabIndex = 21; // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(8, 20); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(72, 16); this.checkBox1.TabIndex = 7; this.checkBox1.UseVisualStyleBackColor = true; this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); // // GrainSizeAreaMethodDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(1107, 835); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox11); this.Controls.Add(this.groupBox7); this.Controls.Add(this.groupBox8); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = "GrainSizeAreaMethodDialog"; this.Text = ""; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GrainSizeDialog_FormClosing); this.Load += new System.EventHandler(this.GrainSizeDialog_Load); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox8, 0); this.Controls.SetChildIndex(this.groupBox7, 0); this.Controls.SetChildIndex(this.groupBox11, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.groupBox4, 0); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox8.ResumeLayout(false); this.groupBox8.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).EndInit(); this.groupBox3.ResumeLayout(false); this.groupBox11.ResumeLayout(false); this.groupBox11.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.ResumeLayout(false); } #endregion /// /// 初始化矩形 /// private void InitRectangleF(PointF pointF) { if (this.selectPicture > -1) { bool foundItem; guideClass.RectangleFLine = guideClass.guideAreaRectLine(pointF, this.comboBox1.SelectedItem, out foundItem); if (foundItem) this.AddRectangleToRectangleFCaps();// "μm²"μm } } /// /// 刷新图形边线点集合 /// private void AddRectangleToRectangleFCaps() { GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel; if (grainSizeGuideStyleModel == null) return; this.linePointList.Clear(); // 圆形 if (grainSizeGuideStyleModel.circularGuideStyles != null) { foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles) { if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag)) { // 圆心 Point center = new Point((int)(guideClass.rectangleFLine.X + guideClass.rectangleFLine.Width / 2), (int)(guideClass.rectangleFLine.Y + guideClass.rectangleFLine.Height / 2)); for (int i = 0; i <= 360; i++) { OpenCvSharp.Point[] points = roundOutline(center, guideClass.Mat_lineDiameter / 2); foreach (var point in points) { linePointList.Add(new Point(point.X, point.Y)); } } } } } // 矩形 if (grainSizeGuideStyleModel.rectangleGuideStyles != null) { foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles) { if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag)) { for (int l = (int)guideClass.rectangleFLine.Y; l <= guideClass.rectangleFLine.Bottom; l++) { if (guideClass.rectangleFLine.X >= 0 && guideClass.RectangleFLine.X < this.documentWorkspace.CompositionSurface.Width && l >= 0 && l < this.documentWorkspace.CompositionSurface.Height) linePointList.Add(new PointF(guideClass.RectangleFLine.X, l)); } for (int t = (int)guideClass.RectangleFLine.X; t <= guideClass.RectangleFLine.Right; t++) { if (t >= 0 && t < this.documentWorkspace.CompositionSurface.Width && guideClass.RectangleFLine.Y >= 0 && guideClass.RectangleFLine.Y < this.documentWorkspace.CompositionSurface.Height) linePointList.Add(new PointF(t, guideClass.RectangleFLine.Y)); } for (int r = (int)guideClass.RectangleFLine.Y; r <= guideClass.RectangleFLine.Bottom; r++) { if (guideClass.RectangleFLine.Right >= 0 && guideClass.RectangleFLine.Right < this.documentWorkspace.CompositionSurface.Width && r >= 0 && r < this.documentWorkspace.CompositionSurface.Height) linePointList.Add(new PointF(guideClass.RectangleFLine.Right, r)); } for (int t = (int)guideClass.RectangleFLine.X; t <= guideClass.RectangleFLine.Right; t++) { if (t >= 0 && t < this.documentWorkspace.CompositionSurface.Width && guideClass.RectangleFLine.Bottom >= 0 && guideClass.RectangleFLine.Bottom < this.documentWorkspace.CompositionSurface.Height) linePointList.Add(new PointF(t, guideClass.RectangleFLine.Bottom)); } } } } this.documentWorkspace.Refresh(); } /// /// 辅助线维护 /// public void InitComboboxValue(ArrayList arrayList) { guideClass.createGuideAreaClassModels(); this.comboBox1.DataSource = null; if (arrayList != null && arrayList.Count > 0) { this.comboboxChange = false; arrayList.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text")); this.comboBox1.DataSource = arrayList; this.comboboxChange = false; int oldSelectIndex = -1; for (int i = 0; i < this.comboBox1.Items.Count; i++) { if (this.oldSelectItem.Equals(this.comboBox1.Items[i])) { oldSelectIndex = i; } } if (oldSelectIndex > -1)//0914###18839 { if (this.comboBox1.SelectedIndex != oldSelectIndex) this.comboBox1.SelectedIndex = oldSelectIndex; } else if (this.comboBox1.Items.Count > 0) this.comboBox1.SelectedIndex = 0;// this.comboBox1.Items.Count - 1; } else { ArrayList arrayList1 = new ArrayList(); List indexList1 = new List(); GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel; // 圆形 if (grainSizeGuideStyleModel.circularGuideStyles != null) { foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles) { arrayList1.Add(circularGuideStyle.tag/*" "*/); indexList1.Add(circularGuideStyle.index); } } // 矩形 if (grainSizeGuideStyleModel.rectangleGuideStyles != null) { foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles) { arrayList1.Add(rectangleGuideStyle.tag/*" "*/); indexList1.Add(rectangleGuideStyle.index); } } if (arrayList1.Count > 0)//0916###18839 { //排序算法//0914###18839 bool sortSuccess = false; while (!sortSuccess) { sortSuccess = true; int firstIndex = 0; int secondIndex = 0; for (int i = 0; i < indexList1.Count; i++) { for (int j = i + 1; j < indexList1.Count; j++) { if (indexList1[i] > indexList1[j]) { sortSuccess = false; firstIndex = i; secondIndex = j; } } if (!sortSuccess) break; } string firstValue = arrayList1[firstIndex] + ""; arrayList1[firstIndex] = arrayList1[secondIndex] + ""; arrayList1[secondIndex] = firstValue; int firstIndexV = indexList1[firstIndex] + 0; indexList1[firstIndex] = indexList1[secondIndex] + 0; indexList1[secondIndex] = firstIndexV; } arrayList1.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text")); this.comboBox1.DataSource = arrayList1; this.comboBox1.SelectedIndex = 0; } } guideClass.UpdateGuideAreaStyle(this.bitmap, this.comboBox1.SelectedItem, false/*this.comboBox1.SelectedIndex > 0*/); this.documentWorkspace.Refresh(); } /// /// ListView图片选择改变事件 /// /// /// private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected) { if (this.selectPicture == this.listView1.FocusedItem.Index) return; existViewFlag = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.IsExsitView(); this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); if (!existViewFlag) { mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap); } else { mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFullSizeWithRegion()); } //this.documentWorkspace.PhaseModels[2].mat = null;//清空前一张图的信息不遗留显示 //massLabelPoints.Clear();//1013###18808(切换图片的时候前一张图的信息不遗留显示) ////二值化相关 //Document document = Document.FromImage(bitmap); //this.documentWorkspace.Document = document; //this.documentWorkspace.Visible = true; //this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList; //this.documentWorkspace.PhaseModels = new List(); //this.documentWorkspace.PhaseModels.AddRange(this.documentItems[this.listView1.FocusedItem.Index].phaseModels); ////二值化end this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); //二值化集成4 binaryClass.listView1_SelectedIndexChanged(this.bitmap); this.documentWorkspace.PhaseModels[2].mat = null;//清空前一张图的信息不遗留显示 massLabelPoints.Clear();//1013###18808(切换图片的时候前一张图的信息不遗留显示) if (this.checkBox1.Checked) { this.applyDect(); } this.selectPicture = this.listView1.FocusedItem.Index; this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2); InitRectangleF(new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2)); AddRectangleToRectangleFCaps(); } } /// /// 辅助线样式 /// /// /// private void button9_Click(object sender, EventArgs e) { if (this.bitmap == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); return; } this.oldSelectItem = (string)this.comboBox1.SelectedItem; GrainGuideStyleSettingsDialog grainGuideStyleSettingsDialog = new GrainGuideStyleSettingsDialog(1, this.gbtType, this.bitmap); grainGuideStyleSettingsDialog.StartPosition = FormStartPosition.CenterScreen; grainGuideStyleSettingsDialog.ShowDialog(this); } /// /// 画布绘制 /// /// /// private void Panel_Paint(object sender, PaintEventArgs e) { if (this.documentWorkspace.CompositionSurface != null) { // // 以下是计算绘制图片的位置和大小并绘制图片 // System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle; int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio); int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio); int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2; int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2; // // 以下是绘制网格、标注、测量、视场等开始 // e.Graphics.TranslateTransform(x, y); e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio); //if (this.checkBox4_0.Checked)//显示网格//1009###19000 Draw(e.Graphics); e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio); e.Graphics.TranslateTransform(-x, -y); } } /// /// 绘制 /// private void Draw(Graphics graphics) { // 抗锯齿 graphics.SmoothingMode = SmoothingMode.AntiAlias; if (this.checkBox4_0.Checked) { guideClass.DrawAreaGuide(graphics, this.comboBox1.SelectedItem); } if (this.checkBox5_0.Checked && massLabelPoints.Count > 0) { int index = 0; Font myFont = new Font("宋体", 12/*, FontStyle.Bold*/); Brush bush = new SolidBrush(this.panel1.BackColor/*Color.Red*/);//填充的颜色 foreach (var item in massLabelPoints) { graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5); } } } /// /// 切换辅助线 /// /// /// private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0) { if (!(this.selectPicture > -1)) { int oldSelectIndex = -1; for (int i = 0; i < this.comboBox1.Items.Count; i++) { if (this.oldSelectItem != null && this.oldSelectItem.Equals(this.comboBox1.Items[i])) { oldSelectIndex = i; } } if (this.comboBox1.SelectedIndex > 0) MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); if (oldSelectIndex > -1) if (this.comboBox1.SelectedIndex != oldSelectIndex) this.comboBox1.SelectedIndex = oldSelectIndex; else if (this.comboBox1.Items.Count > 0) this.comboBox1.SelectedIndex = 0; return; } guideClass.UpdateGuideAreaStyle(this.bitmap, this.comboBox1.SelectedItem, this.comboBox1.SelectedIndex > 0); if (this.selectPicture > -1) { PointF pointF; if (this.comboboxChange) { pointF = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2); this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2); } else pointF = this.loctation; InitRectangleF(pointF); this.comboboxChange = true; } this.documentWorkspace.Refresh(); } } #region 矩形拖动 /// /// 鼠标按下 /// /// /// private void OnMouseDown(object sender, MouseEventArgs e) { // 换算后的点 PointF point1 = documentWorkspace.GetScalePoint(e.Location); if (e.Button == MouseButtons.Left && e.Clicks == 1) { if (guideClass.RectangleFLine.Contains(point1)) { m_canMove = true; this.m_StartPoint = point1; } } guideClass.OnMouseDown(point1, sender, e); } /// /// 移动 /// /// /// private void onMouseMove(object sender, MouseEventArgs e) { // 换算后的点 PointF point1 = documentWorkspace.GetScalePoint(e.Location); this.documentWorkspace.Refresh(); if (guideClass.onMouseAreaMove(point1, this.comboBox1.SelectedItem, e))// 矩形缩放 { this.loctation = new PointF(guideClass.RectangleFLine.X + guideClass.RectangleFLine.Width / 2, guideClass.RectangleFLine.Y + guideClass.RectangleFLine.Height / 2); this.AddRectangleToRectangleFCaps(); this.documentWorkspace.Refresh(); } else if (e.Button == MouseButtons.Left && m_canMove) { // 矩形偏移 guideClass.rectangleFLine.Offset(point1.X - this.m_StartPoint.X, point1.Y - this.m_StartPoint.Y); this.loctation = new PointF(guideClass.rectangleFLine.X + guideClass.rectangleFLine.Width / 2, guideClass.rectangleFLine.Y + guideClass.rectangleFLine.Height / 2); this.m_StartPoint = point1; this.AddRectangleToRectangleFCaps(); this.documentWorkspace.Refresh(); } } /// /// 鼠标抬起 /// /// /// private void onMouseUp(object sender, MouseEventArgs e) { m_canMove = false; guideClass.onMouseUp(sender, e); this.AddRectangleToRectangleFCaps(); } #endregion /// /// surfaceBox双击事件 /// 目前是参考AxioVision /// 应该是把每次选的点都取最高和最低的BGR /// /// /// private unsafe void pictureBox1_Click(object sender, EventArgs e) { } /// /// 移除未完成的定义物体的轮廓的对象 /// /// /// private void GrainSizeDialog_FormClosing(object sender, FormClosingEventArgs e) { this.documentWorkspace.GraphicsList.DeleteDrawClass(DrawClass.PhaseExtraction);//### this.documentWorkspace.Refresh(); } /// /// 是否显示晶粒编号 /// /// /// private void checkBox5_0_CheckedChanged(object sender, EventArgs e) { this.documentWorkspace.Refresh(); } /// /// 是否显示网格 /// /// /// private void checkBox4_0_CheckedChanged(object sender, EventArgs e) { this.documentWorkspace.Refresh(); } //二值化集成3 #region 二值化相关方法 /// /// 添加参数改变的监听 /// /// /// private void GrainSizeDialog_Load(object sender, EventArgs e) { this.comboBox3.Text = PdnResources.GetString("Menu.pdenoisingtype.Text"); this.comboBox3.SelectedIndex = 1; this.comboBox2.Text = PdnResources.GetString("Menu.electthegrainboundarytype.Text"); this.comboBox2.SelectedIndex = 1; this.binaryClass.loadParams(); this.binaryClass.guideClass = this.guideClass; this.binaryClass.comboBox1 = this.comboBox1; } private bool bcBinaryChecked() { return bc != null && bc.BinaryChecked; } private bool bcOriginChecked() { return bc != null && bc.OriginChecked; } /// /// 参数改变时,重新处理图像 /// /// /// private void bClassBinaryImplFinishAction(object sender, EventArgs e) { this.documentWorkspace.Refresh(); //AddRectangleToRectangleFCaps();//### } //private void checkBox10_CheckedChanged(object sender, EventArgs e) //{ // if (checkBox10.Checked && !checkBox5.Checked) // { // this.documentWorkspace.PhaseModels[0].choise = true; // } // else // { // this.documentWorkspace.PhaseModels[0].choise = false; // } // if (toApplyBinary) // this.applyButtonImpl(null, null); // toApplyBinary = true; // if (this.listView1.FocusedItem != null && checkBox10.Checked) // { // } // else // this.documentWorkspace.Refresh(); //} /// /// 显示原图/原图+二值图 /// /// /// private void bcOriginCheckedChanged(object sender, EventArgs e) { if (!bcOriginChecked()) { if (bcBinaryChecked()) this.documentWorkspace.PhaseModels[0].choise = true; if (checkBox1.Checked && checkBox3_0.Checked) this.documentWorkspace.PhaseModels[1].choise = true; if (checkBox11.Checked) this.documentWorkspace.PhaseModels[2].choise = true; } else { this.documentWorkspace.PhaseModels[0].choise = false; this.documentWorkspace.PhaseModels[1].choise = false; } this.documentWorkspace.Refresh(); } ///// ///// 显示原图/原图+二值图 ///// ///// ///// //private void ShowOrHideOriginPic(object sender, EventArgs e) //{ // if (!checkBox5.Checked) // { // if (checkBox10.Checked) // this.documentWorkspace.PhaseModels[0].choise = true; // if (checkBox1.Checked && checkBox3_0.Checked) //0916###18744 // this.documentWorkspace.PhaseModels[1].choise = true; // if (checkBox11.Checked) // this.documentWorkspace.PhaseModels[2].choise = true; // } // else // { // this.documentWorkspace.PhaseModels[0].choise = false; // this.documentWorkspace.PhaseModels[1].choise = false; // } // this.documentWorkspace.Refresh(); //} ///// ///// 参数改变时,重新处理图像 ///// ///// ///// //private void applyButtonImpl(object sender, EventArgs e) //{ // long start = Cv2.GetTickCount(); // if (this.listView1.FocusedItem != null && checkBox10.Checked) // { // //判断是否存在视场,如果存在视场,则把视场提取出来,进行处理 // if (this.documentWorkspace.GraphicsList.IsExsitView()) // { // this.documentWorkspace.PhaseModels[0].mat = action.PerformProcess( // OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion()), // OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap)); // this.documentWorkspace.PhaseModels[0].color = this.panel2.BackColor.ToArgb(); // this.documentWorkspace.Refresh(); // } // else // { // this.documentWorkspace.PhaseModels[0].mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap)); // this.documentWorkspace.PhaseModels[0].color = this.panel2.BackColor.ToArgb(); // this.documentWorkspace.Refresh(); // } // } // double time = (Cv2.GetTickCount() - start) / Cv2.GetTickFrequency(); // System.Console.WriteLine("执行时间:" + time); //} #endregion private void panel1_Click(object sender, EventArgs e) { this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor); this.colorsFormGrid.ShowDialog(); } /// /// Panel2的调色板颜色改变 /// /// /// private void gridColorChanged(object sender, EventArgs e) { Color color = this.colorsFormGrid.UserPrimaryColor.ToColor(); this.panel1.BackColor = color; this.documentWorkspace.PhaseModels[1].color = this.panel1.BackColor.ToArgb(); if (this.checkBox1.Checked) { this.applyDect(); this.documentWorkspace.Refresh(); } //关闭色板 this.colorsFormGrid.Close(); } /// /// 保存结果 /// /// /// private void button2_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0) { if(this.comboBox1.SelectedItem != null && !PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text").Equals(this.comboBox1.SelectedItem)) { string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName(); string tag = this.imageList1.Images.Keys[this.listView1.SelectedItems[0].Index]; System.Data.DataTable dataTable = new System.Data.DataTable(); 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) { 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); } this.dataGridView4.Rows.Clear(); DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn c in this.dataGridView4.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[0].Value = imgName; dgvr.Cells[1].Value = this.comboBox1.SelectedItem; // 是否矩形辅助线 int isRect; double aec = guideClass.guideArea(this.comboBox1.SelectedItem, out isRect, this.gbtType); dgvr.Cells[2].Value = aec; aec = aec * 0.001 * 0.001; double grainNumber = GetNumberOfGrains(linePointList, guideClass.RectangleFLine) + isRect; dgvr.Cells[3].Value = grainNumber; decimal M = 1;// this.appWorkspace.GetGainMultiple() ; decimal A = Convert.ToDecimal((double)M * (double)M * grainNumber / aec); //dgvr.Cells[4].Value = grainNumber; ////1013###19377##面积法位置,使用晶粒的实际面积去标准中的表进行对应,获取截距后,在进行平均的计算 to test double[] lengths = {3.88, 7.75 , 10.96, 15.50, 21.92, 31.0, 43.84, 62.0, 87.68, 124, 175.36, 248, 350.73, 496, 701.45, 992, 1402.9, 1984.0, 2805.8, 3968.0, 5611.6, 7936.0, 11223.2, 15872.0, 22446.4, 31744.1, 44892.9, 63488.1, 89785.8, 126976.3}; // 差值 decimal differenceNew = 0; decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 2.88, (double)A - 126977.3)));//Convert.ToDecimal(double.MaxValue);//Math.Abs(A - 160000);// Convert.ToDecimal((double)A - 2.22); double selectArea = 0; int first = -1; foreach (double item in lengths) { selectArea = item; differenceNew = Math.Abs(A - Convert.ToDecimal(item)); if (differenceNew < differenceOld) { differenceOld = Math.Abs(A - Convert.ToDecimal(item)); first++; } else break; } // string[] valueG = {"00"/*"00A"*/, "0" , "0.5", "1.0", "1.5", "2.0", "2.5", "3.0", //"3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "6.5", "7.0", "7.5", "8.0", "8.5", "9.0", "9.5", //"10.0", "10.5", "11.0", "11.5", "12.0", "12.5", "13.0", "13.5", "14.0"}; string[] valueG = {"452.5", "320.0" , "269.1", "226.3", "190.3", "160.0", "134.5", "113.1", "95.1", "80.0", "67.3", "56.6", "47.6", "40.0", "33.6", "28.3", "23.8", "20.0", "16.8", "14.1", "11.9", "10.0", "8.4", "7.1", "5.9", "5.0", "4.2", "3.5", "3.0", "2.5"};//微米## to test if (first >= valueG.Length) { first = valueG.Length - 1; } else if (first < 0) { first = 0; } dgvr.Cells[4].Value = valueG[first]; double NA = (double)M * (double)M * grainNumber / aec; if (this.gbtType == 4) dgvr.Cells[5].Value = 3.32 * Math.Log10(NA) - 2.9542; else dgvr.Cells[5].Value = 3.321928 * Math.Log10(NA) - 2.954; this.dataGridView4.Rows.Add(dgvr); dataTable.TableName = tag; foreach (System.Data.DataTable dataTable1 in dataTables) { if (dataTable1.TableName.Equals(dataTable.TableName)) { dataTables.Remove(dataTable1); break; } } foreach (DataGridViewColumn c in this.dataGridView4.Columns) { dataTable.Columns.Add(c.HeaderText); } for (int r = 0; r < this.dataGridView4.Rows.Count; r++) { DataRow dataRow = dataTable.NewRow(); for (int c = 0; c < this.dataGridView4.Rows[r].Cells.Count; c++) { dataRow[this.dataGridView4.Columns[c].HeaderText] = this.dataGridView4.Rows[r].Cells[c].Value; } dataTable.Rows.Add(dataRow); } this.dataTables.Add(dataTable); this.RefreshDataGridView4(); //保存处理后的图片 List tempBit = new List(); Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); tempBit.Add(originalBit); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null) { Mat targetMat = this.documentWorkspace.PhaseModels[0].mat; 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); } Draw(graphics); 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 (massLabelPoints.Count > 0) { int index = 0; int outMaxIndex = massLabelPoints.Count - 0 - within; foreach (var item in massLabelPoints) { List strList = new List(); strList.Add(("" + (++index)).ToString()); strList.Add(item.X.ToString()); strList.Add(item.Y.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 { ExportProjectModel newModel = new ExportProjectModel(); newModel.tagName = tag; newModel.picName = imgName; newModel.dataList = dataList; tempDataModel.Add(newModel); } } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text")+"!"); } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); } } /// /// 切换分析结果 /// /// /// private void listView2_SelectedIndexChanged(object sender, EventArgs e) { if(!this.allShow) { if (this.listView2.SelectedItems.Count <= 0) return; this.dataGridView4.Rows.Clear(); for (int i = 0; i < this.listView2.SelectedItems.Count; i++) { System.Data.DataTable dataTable1 = new System.Data.DataTable(); foreach (var dataTable in this.dataTables) { if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName)) dataTable1 = dataTable; } DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView4.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < dataTable1.Columns.Count; c++) { dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString(); } this.dataGridView4.Rows.Add(dgvr); } } } /// /// 晶界重现 /// /// /// private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (this.checkBox1.Checked && !bcOriginChecked() && checkBox3_0.Checked) { this.documentWorkspace.PhaseModels[1].choise = true; } else { this.documentWorkspace.PhaseModels[1].choise = false; this.documentWorkspace.Refresh(); } if (this.checkBox1.Checked) { this.applyDect(); } else AddRectangleToRectangleFCaps();//1009###18946 } ProgressThreadProcClass procClass; double sigma = 0.5; //string inputImageFile = "原始图片1.jpg";// "j1.JPG"; ////char[] inputImageFile2 = inputImageFile.ToCharArray(); Mat OrgImg;// = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile); int dark;// = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 int smooth_type;// = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数 int enhance;// = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1 double[] cell_size;// = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小 Mat OrgImg0; private void applyDect() { if (this.bitmap == null) { return; } if (!double.TryParse(textBox6.Text, out sigma)) { return; } //ProgressThreadProcClass.StartProgressAction(this, 100, null); //string inputImageFile = "原始图片1.jpg";// "j1.JPG"; ////char[] inputImageFile2 = inputImageFile.ToCharArray(); /*Mat */OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile); /*int */dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 /*int */smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数 /*int */enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1 /*double[] */cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小 procClass = new ProgressThreadProcClass(); procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyDectAction), PdnResources.GetString("Menu.Grainboundarytoreproduce.text")); if (OrgImg0 != null) { this.documentWorkspace.PhaseModels[1].mat = OrgImg0.Clone(); this.documentWorkspace.Refresh(); OrgImg0 = null; } if (OrgImg != null) { OrgImg.Dispose(); OrgImg = null; } } private void applyDectAction() { //double sigma = 0.5; //if (!double.TryParse(textBox6.Text, out sigma)) //{ // return; //} ////string inputImageFile = "原始图片1.jpg";// "j1.JPG"; //////char[] inputImageFile2 = inputImageFile.ToCharArray(); //Mat OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile); //int dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 //int smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 ////double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数 //int enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1 //double[] cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小 OrgImg0 = this.runDect(OrgImg, dark, smooth_type, sigma, enhance, cell_size); if (procClass != null) { procClass.DismissProgressAction(this); //procClass = null; } } private Mat runDect(Mat OrgImg0, int dark, int smooth_type, double sigma, int enhance, double[] cell_size) { Mat GryImg = new Mat(); Mat OrgImg = new Mat(); ///// if (4 == OrgImg0.Channels()) { Cv2.CvtColor(OrgImg0, OrgImg, ColorConversionCodes.BGRA2BGR); } else { OrgImg = OrgImg0.Clone(); } In5segmsurf prm = new In5segmsurf(); prm.OrgImg = OrgImg; ///// //Cv2.ImShow("src", OrgImg);//kkkkk //Cv2.WaitKey(0);//kkkkk //转为为灰度? if (3 == OrgImg.Channels() || 4 == OrgImg.Channels()) { Cv2.CvtColor(OrgImg, GryImg, ColorConversionCodes.RGB2GRAY); } else { if (1 == OrgImg.Channels()) { GryImg = OrgImg.Clone(); } else { return null; } } if (1 == dark) { int Rows = GryImg.Rows; int Cols = GryImg.Cols; int[] point = new int[2]; //单通道图像的反色 for (point[0] = 0; point[0] < Rows; point[0]++) { for (point[1] = 0; point[1] < Cols; point[1]++) { byte bTemp = (byte)(255 - GryImg.At(point[0], point[1])); GryImg.Set(point, bTemp);//mmmmm } } } if (2 == dark) { Mat TempImg = GryImg.Clone(); Cv2.Sobel(TempImg, GryImg, -1, 2, 2, 3);//mmmmm } //Cv2.ImShow("src", GryImg);//kkkkk //Cv2.WaitKey(0);//kkkkk //去噪 if (0 == smooth_type) { prm.smoothim_method = "gaussian"; } else { if (1 == smooth_type) { prm.smoothim_method = "dirced"; } else { return null; } } //晶界增强 if (1 == enhance) { prm.filterridges = 1; } else { prm.filterridges = 0; } //调用算法 prm.gaussian_stdev = sigma; prm.LEVEL = ".3"; prm.classifycells_convexarea = 0.50; prm.classifycells_convexperim = 0.45; OLDcellsegm cellsegm = new OLDcellsegm(); string[] namehere = new string[1] { "prm" }; In6segmsurf IN6BNImgs = new In6segmsurf(); OUTsegmsurf RSTss = cellsegm.mf_segmsurf_progress_auto(GryImg, cell_size[0], cell_size[1], namehere, prm, IN6BNImgs, this.panel1.BackColor, this); cell_size = null; cellsegm = null; namehere = null; Cv2.CvtColor(RSTss.wat, OrgImg0, ColorConversionCodes.BGR2BGRA); //this.documentWorkspace.PhaseModels[1].mat = OrgImg0;// RSTss.wat;// action.PerformProcess( //// OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion()), //// OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap)); //////this.documentWorkspace.PhaseModels[1].color = this.panel2.BackColor.ToArgb(); //this.documentWorkspace.Refresh(); //return RSTss.wat; //string filename = "D:\\result11.jpg"; //Cv2.ImWrite(filename, RSTss.wat); return OrgImg0/*null*/; } private void checkBox3_0_CheckedChanged(object sender, EventArgs e) { if (!bcOriginChecked() && checkBox1.Checked && checkBox3_0.Checked) { this.documentWorkspace.PhaseModels[1].choise = true; } else { this.documentWorkspace.PhaseModels[1].choise = false; } this.documentWorkspace.Refresh(); } private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } private void textBox6_TextChanged(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } private void numericUpDown1_ValueChanged_1(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } private void numericUpDown2_ValueChanged_1(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } /// /// 用不同颜色显示晶粒 /// /// /// private void checkBox11_CheckedChanged(object sender, EventArgs e) { if (!bcOriginChecked() && checkBox11.Checked) { this.documentWorkspace.PhaseModels[2].choise = true; } else { this.documentWorkspace.PhaseModels[2].choise = false; } this.documentWorkspace.Refresh(); } /// /// 设置 /// /// /// private void button1_Click(object sender, EventArgs e) { string templateName = "Template.Manager.item3.GrainSizeArea6394Method"; switch (this.gbtType) { case 2: templateName = "Template.Manager.item3.GrainSizeArea24177Method"; break; case 3: templateName = "Template.Manager.item3.GrainSizeArea112Method"; break; case 4: templateName = "Template.Manager.item3.GrainSizeArea643Method"; break; default: break; } AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, templateName); if (metallographicMethodSetDialog.hasModule) { metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen; metallographicMethodSetDialog.ShowDialog(); } else { metallographicMethodSetDialog = null; } } /// /// 导出结果 /// /// /// private void button14_Click(object sender, EventArgs e) { if (this.listView2.Items.Count > 0) { SaveFileDialog exe = new SaveFileDialog(); exe.Filter = "Execl files (*.xls)|*.xls"; exe.FilterIndex = 0; exe.RestoreDirectory = true; //exe.CreatePrompt = true; exe.Title = "Export Excel File"; exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); exe.FileName = PdnResources.GetString("Menu.DedicatedAnalysis.BlackMetal.GrainSize.Text")+"(" + PdnResources.GetString("Menu.Areamethod.text")+ ")"+ PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddHHmmss"); DialogResult dr = exe.ShowDialog(); if (dr != DialogResult.OK) { return; } DataTable dtb = new DataTable(); foreach (var item in this.contentHead) { dtb.Columns.Add(item); } for (int i = 0; i < this.dataGridView4.Rows.Count; i++) { DataRow dataRow = dtb.NewRow(); for (int k = 0; k < this.contentHead.Count; k++) { dataRow[this.contentHead[k]] = this.dataGridView4.Rows[i].Cells[k].Value; } dtb.Rows.Add(dataRow); } List list = new List(); list.Add(dtb); this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, false, false, true); } else MessageBox.Show(PdnResources.GetString("Menu.Noanalysineratereport.text")+"!"); } /// /// 生成报告 /// /// /// private void button13_Click(object sender, EventArgs e) { if (this.checkBox2_0.Checked) this.button1.PerformClick(); if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify)) { //获取word书签与excel单元格的关系,以字典方式存储 List mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify); Dictionary tagInfos = new Dictionary(); if (mic_module_infos != null && mic_module_infos.Count > 0) { foreach (mic_module_infos info in mic_module_infos) { tagInfos.Add(info.tag_name, info.cell_position); } } //分析结果 List> analysisContent = new List>(); analysisContent.Add(contentHead); foreach (DataGridViewRow item in this.dataGridView4.Rows) { List content = new List(); for (int i = 0; i < contentHead.Count; i++) { content.Add(item.Cells[i].Value.ToString()); } analysisContent.Add(content); } //图片 bitList = new List(); if (this.allShow) { foreach (KeyValuePair> kv in this.bitDic) { bitList.Add(kv.Value[0]); bitList.Add(kv.Value[1]); } } else { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { foreach (ListViewItem item in this.listView2.SelectedItems) { if (bitDic.ContainsKey(item.Name)) { bitList.Add(bitDic[item.Name][0]); bitList.Add(bitDic[item.Name][1]); } else if (bitDic.ContainsKey(item.Tag.ToString())) { bitList.Add(bitDic[item.Tag.ToString()][0]); bitList.Add(bitDic[item.Tag.ToString()][1]); } } } else if (this.listView2.Items.Count > 0) { ListViewItem item = this.listView2.Items[0]; if (bitDic.ContainsKey(item.Name)) { bitList.Add(bitDic[item.Name][0]); bitList.Add(bitDic[item.Name][1]); } else if (bitDic.ContainsKey(item.Tag.ToString())) { bitList.Add(bitDic[item.Tag.ToString()][0]); bitList.Add(bitDic[item.Tag.ToString()][1]); } } } this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos); } else MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!"); } /// /// 晶界编辑 /// /// /// private void button3_Click(object sender, EventArgs e) { if (/*this.documentWorkspace.PhaseModels[1].choise == true && */this.documentWorkspace.PhaseModels[1].mat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")); return; } //1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界) GrainBoundaryEditingDialog boundaryEditingDialog = new GrainBoundaryEditingDialog(this.appWorkspace, this.listView1.FocusedItem.Index, this.panel1.BackColor , this.documentWorkspace.PhaseModels[1].mat.Clone()); boundaryEditingDialog.GuideClass = this.guideClass; boundaryEditingDialog.SelectedItem = this.comboBox1.SelectedItem; if (boundaryEditingDialog.ShowDialog() == DialogResult.OK) { this.documentWorkspace.PhaseModels[1].mat = boundaryEditingDialog.PhaseMat.Clone(); this.documentWorkspace.Refresh(); } } /// /// 刷新晶粒编号 /// /// /// private void button4_Click(object sender, EventArgs e) { if (this.bitmap == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text")); return; } Getrains(linePointList, guideClass.RectangleFLine); } /// /// 刷新晶粒编号 /// /// /// private void Getrains(List pointFs, RectangleF rectangleF) { Mat OriginalPicture;// = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); if (this.checkBox1.Checked && this.documentWorkspace.PhaseModels[1].mat != null) { OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); Mat oldMat = 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) { OriginalPicture.Set(point, new Vec4b(0, 0, 0, 255)); } } } Cv2.Erode(OriginalPicture, OriginalPicture, null, null, 1); } else if (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null) { OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); Mat oldMat = this.documentWorkspace.PhaseModels[0].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) { OriginalPicture.Set(point, new Vec4b(0, 0, 0, 255)); } } } } else { OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); mat.CopyTo(OriginalPicture); } Mat erzhi = OriginalPicture; Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY); Cv2.Threshold(erzhi, erzhi, 100, 255, ThresholdTypes.Binary); //Cv2.AdaptiveThreshold(erzhi, erzhi, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 99, 10); 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)); // 二次轮廓 Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone); // 计算所有轮廓质点 List massPoints = new List(); foreach (OpenCvSharp.Point[] contour in contours) { OpenCvSharp.Moments moments = new OpenCvSharp.Moments(contour, false); massPoints.Add(new Point2d(moments.M10 / moments.M00, moments.M01 / moments.M00)); } Mat labelMat = new Mat(); Mat stats = new Mat(); Mat centroids = new Mat(); // 连通域数量 int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8); // 连通域质点 Dictionary keyValues = new Dictionary(); massLabelPoints.Clear(); foreach (var item in massPoints) { if (double.IsNaN(item.Y) || double.IsNaN(item.X)) { continue; } int label = labelMat.At((int)item.Y, (int)item.X); if (0 <= label && label <= nccomps) { keyValues[label] = item; } } // 矩形边线上的连通域 ArrayList nccompSelect = new ArrayList(); foreach (var pointF in pointFs) { if (labelMat.Width <= pointF.X || labelMat.Height <= pointF.Y || pointF.X < 0 || pointF.Y < 0) { continue; } ////### ////判断是否在晶界上面 //Vec4b vec4B = OriginalPicture.At((int)pointF.Y, (int)pointF.X); //if (getGrainBoundryChecked() && vec4B.Item3 != 0 || getBinaryChecked() && vec4B.Item3 != 0 || !getGrainBoundryChecked() && !getBinaryChecked() && vec4B.Item0 == 0) //{ // //temp.Set((int)pointF.Y, (int)pointF.X, new Vec4b(0, 255, 0, 255)); // continue;//0925###19106 //} int label = labelMat.At((int)pointF.Y, (int)pointF.X); if (!nccompSelect.Contains(label) && keyValues.ContainsKey(label) && keyValues[label] != null) { nccompSelect.Add(label); if (keyValues.ContainsKey(label) && keyValues[label] != null) massLabelPoints.Add(keyValues[label]); // massLabelPoints.Add(new Point2d((int)pointF.X, (int)pointF.Y/*-1, -1*/)); //else // massLabelPoints.Add(new Point2d((int)pointF.Y, (int)pointF.Y/*-1, -1*/)); } } // 矩形内的连通域 within = 0; ArrayList inccompSelect = new ArrayList(); GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel; // 圆形 if (grainSizeGuideStyleModel.circularGuideStyles != null) { foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles) { if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag)) { foreach (var keyValue in keyValues) { //求点到圆心的距离 double c = BasicCalculationHelper.GetDistance(new PointF((float)keyValue.Value.X, (float)keyValue.Value.Y), new PointF(rectangleF.X + rectangleF.Width / 2, rectangleF.Y + rectangleF.Height / 2), 10); if (!nccompSelect.Contains(keyValue.Key) && c < guideClass.Mat_lineDiameter / 2) { if (!inccompSelect.Contains(keyValue.Key)) { within++; inccompSelect.Add(keyValue.Key); if (keyValue.Value != null) massLabelPoints.Add(keyValue.Value); } } } } } } // 矩形 if (grainSizeGuideStyleModel.rectangleGuideStyles != null) { foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles) { if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag)) { foreach (var keyValue in keyValues) { if (!nccompSelect.Contains(keyValue.Key) && keyValue.Value.X > rectangleF.X && keyValue.Value.X < rectangleF.Right && keyValue.Value.Y > rectangleF.Y && keyValue.Value.Y < rectangleF.Bottom) { if (!inccompSelect.Contains(keyValue.Key)) { within++; inccompSelect.Add(keyValue.Key); if (keyValue.Value != null) massLabelPoints.Add(keyValue.Value); } } } } } } Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC4); //Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC1); Random rd = new Random(); List colors = new List(nccomps); colors.Add(new Vec4b(0, 0, 0, 0)); for (int i = 1; i < nccomps; i++) { //colors.Add(new Vec3b(255, 255, 255)); colors.Add(new Vec4b(((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), 255)); } for (int y = 0; y < temp.Rows; y++) { for (int x = 0; x < temp.Cols; x++) { int label = labelMat.At(y, x); if (nccompSelect.Contains(label)) temp.Set(y, x, colors[label]); if (inccompSelect.Contains(label)) temp.Set(y, x, colors[label]); //temp.Set(y, x, new Vec4b(127, 127, 127, 127)); ////if (0 <= label && label <= nccomps) ////{ //// temp.Set(y, x, colors[label]); ////} } } //foreach (var item in massPoints) //{ // if (double.IsNaN(item.Y) || double.IsNaN(item.X)) // { // continue; // } // temp.Set((int)item.Y, (int)item.X, new Vec4b(0, 0, 255, 255)); //} ////Cv2.ImShow("temp", temp); this.documentWorkspace.PhaseModels[2].mat = temp; this.documentWorkspace.Refresh(); } /// /// 导出项目 /// /// /// private void button8_Click(object sender, EventArgs e) { if (this.checkBox2_0.Checked) this.button1.PerformClick(); if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify)) { Instrument.ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, "Menu.DedicatedAnalysis.BlackMetal.GrainSize.Text", this.analyzeSettingModel.savePath); if (nodeItem == null) return; //获取word书签与excel单元格的关系,以字典方式存储 List mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify); Dictionary tagInfos = new Dictionary(); if (mic_module_infos != null && mic_module_infos.Count > 0) { foreach (mic_module_infos info in mic_module_infos) { tagInfos.Add(info.tag_name, info.cell_position); } } //分析结果 List> analysisContent = new List>(); analysisContent.Add(contentHead); foreach (DataGridViewRow item in this.dataGridView4.Rows) { List content = new List(); for (int i = 0; i < contentHead.Count; i++) { content.Add(item.Cells[i].Value.ToString()); } analysisContent.Add(content); } //图片 bitList = new List(); //中间数据 List exportModel = new List(); if (this.allShow) { foreach (KeyValuePair> kv in this.bitDic) { bitList.Add(kv.Value[0]); bitList.Add(kv.Value[1]); } //中间数据 foreach (ExportProjectModel model in this.tempDataModel) { ExportProjectModel tempModel = new ExportProjectModel(); tempModel.tagName = model.tagName; tempModel.picName = model.picName; tempModel.dataList = model.dataList; exportModel.Add(tempModel); } } else { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { foreach (ListViewItem item in this.listView2.SelectedItems) { if (bitDic.ContainsKey(item.Name)) { bitList.Add(bitDic[item.Name][0]); bitList.Add(bitDic[item.Name][1]); } else if (bitDic.ContainsKey(item.Tag.ToString())) { bitList.Add(bitDic[item.Tag.ToString()][0]); bitList.Add(bitDic[item.Tag.ToString()][1]); } } //中间数据 foreach (ListViewItem rowItem in this.listView2.SelectedItems) { foreach (ExportProjectModel model in this.tempDataModel) { if (model.tagName.Equals(rowItem.Name)) { ExportProjectModel tempModel = new ExportProjectModel(); tempModel.tagName = model.tagName; tempModel.picName = model.picName; tempModel.dataList = model.dataList; exportModel.Add(tempModel); break; } else if (model.tagName.Equals(rowItem.Tag.ToString())) { ExportProjectModel tempModel = new ExportProjectModel(); tempModel.tagName = model.tagName; tempModel.picName = model.picName; tempModel.dataList = model.dataList; exportModel.Add(tempModel); break; } } } } else if (this.listView2.Items.Count > 0) { ListViewItem rowItem = this.listView2.Items[0]; if (bitDic.ContainsKey(rowItem.Name)) { bitList.Add(bitDic[rowItem.Name][0]); bitList.Add(bitDic[rowItem.Name][1]); } else if (bitDic.ContainsKey(rowItem.Tag.ToString())) { bitList.Add(bitDic[rowItem.Tag.ToString()][0]); bitList.Add(bitDic[rowItem.Tag.ToString()][1]); } //中间数据 { foreach (ExportProjectModel model in this.tempDataModel) { if (model.tagName.Equals(rowItem.Name)) { ExportProjectModel tempModel = new ExportProjectModel(); tempModel.tagName = model.tagName; tempModel.picName = model.picName; tempModel.dataList = model.dataList; exportModel.Add(tempModel); break; } else if (model.tagName.Equals(rowItem.Tag.ToString())) { ExportProjectModel tempModel = new ExportProjectModel(); tempModel.tagName = model.tagName; tempModel.picName = model.picName; tempModel.dataList = model.dataList; exportModel.Add(tempModel); break; } } } } } this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, exportModel, bitList, tagInfos, nodeItem.path, nodeItem.code); //保存项目信息到数据库 this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, nodeItem); } else MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!"); } /// /// 全部显示 /// /// /// private void button11_Click(object sender, EventArgs e) { if (this.listView2.Items.Count > 0) { this.button11.Visible = false; this.button16.Visible = true; this.button16.Focus(); this.allShow = true; this.dataGridView4.Rows.Clear(); for (int i = 0; i < this.dataTables.Count; i++) { DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView4.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < this.dataTables[i].Columns.Count; c++) { dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString(); } this.dataGridView4.Rows.Add(dgvr); } } else { MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!"); } } /// /// 取消全部显示 /// /// /// private void button16_Click(object sender, EventArgs e) { this.button11.Visible = true; this.button16.Visible = false; this.button11.Focus(); this.allShow = false; if (this.listView2.SelectedItems.Count <= 0) return; this.dataGridView4.Rows.Clear(); for (int i = 0; i < this.listView2.SelectedItems.Count; i++) { System.Data.DataTable dataTable1 = new System.Data.DataTable(); foreach (var dataTable in this.dataTables) { if (this.listView2.SelectedItems.Count > 0) { if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName)) dataTable1 = dataTable; } else { if (this.listView2.Items[0].Tag.Equals(dataTable.TableName)) dataTable1 = dataTable; } } DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView4.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < dataTable1.Columns.Count; c++) { dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString(); } this.dataGridView4.Rows.Add(dgvr); } } /// /// 分析结果删除 /// /// /// private void button12_Click(object sender, EventArgs e) { if(this.listView2.Items.Count > 0) { if(this.listView2.SelectedItems.Count > 0) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { if (this.listView2.SelectedItems.Count <= 0) return; for (int i = this.listView2.SelectedItems.Count - 1; i >= 0; i--) { int selectIndex = this.listView2.SelectedItems[i].Index; foreach (var dataTable in this.dataTables) { if (dataTable.TableName.Equals(this.listView2.SelectedItems[i].Tag)) { this.dataTables.Remove(dataTable); break; } } //1009###18809 //##to test if (bitDic.ContainsKey((string)this.listView2.SelectedItems[i].Tag)) bitDic.Remove((string)this.listView2.SelectedItems[i].Tag); foreach (ExportProjectModel model in this.tempDataModel) { if (model.tagName.Equals((string)this.listView2.SelectedItems[i].Tag)) { this.tempDataModel.Remove(model); break; } } this.listView2.Items.RemoveAt(selectIndex); } if (this.listView2.Items.Count == 0) this.dataGridView4.Rows.Clear(); else { //if (selectIndex == 0) // this.listView2.Items[0].Selected = true; //else // this.listView2.Items[selectIndex - 1].Selected = true; RefreshDataGridView4(); } } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!"); } } else { MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!"); } } /// /// 刷新分析结果数据 /// private void RefreshDataGridView4() { if (!this.allShow) { if (this.listView2.SelectedItems.Count > 0) { this.dataGridView4.Rows.Clear(); for (int j = 0; j < this.listView2.SelectedItems.Count; j++) { int dataTableIndex = 0; for (int i = 0; i < this.dataTables.Count; i++) { if (this.dataTables[i].TableName.Equals(this.listView2.SelectedItems[j].Tag)) dataTableIndex = i; } if (this.dataTables[dataTableIndex].Rows.Count > 0) { for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++) { DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView4.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++) { if (c == 2 || c == 5) dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" : this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; else dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); } this.dataGridView4.Rows.Add(dgvr); } } } } else if (this.listView2.Items.Count > 0) { this.dataGridView4.Rows.Clear(); var firstTag = this.listView2.Items[0].Tag; int dataTableIndex = 0; for (int i = 0; i < this.dataTables.Count; i++) { if (this.dataTables[i].TableName.Equals(firstTag)) dataTableIndex = i; } if (this.dataTables[dataTableIndex].Rows.Count > 0) { for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++) { DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView4.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++) { if (c == 2 || c == 5) dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" : this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; else dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); } this.dataGridView4.Rows.Add(dgvr); } } } } else { this.dataGridView4.Rows.Clear(); DataTable dataTable = new DataTable(); for (int i = this.dataTables.Count - 1; i >= 0; i--) { dataTable = this.dataTables[i]; for (int r = 0; r < dataTable.Rows.Count; r++) { DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView4.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < dataTable.Columns.Count; c++) { if (c == 2 || c == 5) dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" : dataTable.Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; else dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString(); } this.dataGridView4.Rows.Add(dgvr); } } } } /// /// 小数位数 /// /// /// private void numericUpDown1_0_ValueChanged(object sender, EventArgs e) { this.RefreshDataGridView4(); //this.dec = Convert.ToInt32(this.numericUpDown1.Value); //if(this.dataTables.Count > 0) //{ // foreach (var dataTable in this.dataTables) // { // } //} } private Double GetNumberOfGrains(List pointFs, RectangleF rectangleF) { Mat OriginalPicture;// = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); if (this.checkBox1.Checked && this.documentWorkspace.PhaseModels[1].mat != null) { OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); Mat oldMat = 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) { OriginalPicture.Set(point, new Vec4b(0, 0, 0, 255)); } } } Cv2.Erode(OriginalPicture, OriginalPicture, null, null, 1); } else if (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null) { OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); Mat oldMat = this.documentWorkspace.PhaseModels[0].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) { OriginalPicture.Set(point, new Vec4b(0, 0, 0, 255)); } } } } else { OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255)); mat.CopyTo(OriginalPicture); } Mat erzhi = OriginalPicture; Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY); Cv2.Threshold(erzhi, erzhi, 100, 255, ThresholdTypes.Binary); //Cv2.AdaptiveThreshold(erzhi, erzhi, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 99, 10); OpenCvSharp.Point[][] contours; HierarchyIndex[] hierarchy; Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone); //Cv2.ImWrite("erzhi1.tif", erzhi.CvtColor(ColorConversionCodes.GRAY2BGR)); 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)); // 二次轮廓 Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone); // 计算所有轮廓质点 List massPoints = new List(); foreach (OpenCvSharp.Point[] contour in contours) { OpenCvSharp.Moments moments = new OpenCvSharp.Moments(contour, false); massPoints.Add(new Point2d(moments.M10 / moments.M00, moments.M01 / moments.M00)); } Mat labelMat = new Mat(); Mat stats = new Mat(); Mat centroids = new Mat(); // 连通域数量 int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8); //Cv2.ImWrite("erzhi2.tif", labelMat); //Cv2.ImWrite("erzhi3.tif", stats); //Cv2.ImWrite("erzhi4.tif", centroids); // 连通域质点 Dictionary keyValues = new Dictionary(); massLabelPoints.Clear(); foreach (var item in massPoints) { if (double.IsNaN(item.Y) || double.IsNaN(item.X)) { continue; } int label = labelMat.At((int)item.Y, (int)item.X); if (0 <= label && label <= nccomps) { keyValues[label] = item; } } // 矩形边线上的连通域 ArrayList nccompSelect = new ArrayList(); foreach (var pointF in pointFs) { if (labelMat.Width <= pointF.X || labelMat.Height <= pointF.Y || pointF.X < 0 || pointF.Y < 0)//0924###19092 { continue; } ////判断是否在晶界上面//### //Vec4b vec4B = OriginalPicture.At((int)pointF.Y, (int)pointF.X); //if (getGrainBoundryChecked() && vec4B.Item3 != 0 || getBinaryChecked() && vec4B.Item3 != 0 || !getGrainBoundryChecked() && !getBinaryChecked() && vec4B.Item0 == 0) //{ // //temp.Set((int)pointF.Y, (int)pointF.X, new Vec4b(0, 255, 0, 255)); // continue;//0925###19106 //} int label = labelMat.At((int)pointF.Y, (int)pointF.X); if (!nccompSelect.Contains(label) && keyValues.ContainsKey(label) && keyValues[label] != null) { nccompSelect.Add(label); if (keyValues.ContainsKey(label) && keyValues[label] != null) massLabelPoints.Add(keyValues[label]); // massLabelPoints.Add(new Point2d((int)pointF.X, (int)pointF.Y/*-1, -1*/)); //else // massLabelPoints.Add(new Point2d((int)pointF.Y, (int)pointF.Y/*-1, -1*/)); } } // 矩形内的连通域 within = 0; ArrayList inccompSelect = new ArrayList(); GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel; // 圆形 if (grainSizeGuideStyleModel.circularGuideStyles != null) { foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles) { if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag)) { foreach (var keyValue in keyValues) { //求点到圆心的距离 double c = BasicCalculationHelper.GetDistance(new PointF((float)keyValue.Value.X, (float)keyValue.Value.Y), new PointF(rectangleF.X + rectangleF.Width / 2, rectangleF.Y + rectangleF.Height / 2), 10); if (!nccompSelect.Contains(keyValue.Key) && c < guideClass.Mat_lineDiameter / 2) { if (!inccompSelect.Contains(keyValue.Key)) { within++; inccompSelect.Add(keyValue.Key); if (keyValue.Value != null) massLabelPoints.Add(keyValue.Value); } } } } } } // 矩形 if (grainSizeGuideStyleModel.rectangleGuideStyles != null) { foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles) { if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag)) { foreach (var keyValue in keyValues) { if (!nccompSelect.Contains(keyValue.Key) && keyValue.Value.X > rectangleF.X && keyValue.Value.X < rectangleF.Right && keyValue.Value.Y > rectangleF.Y && keyValue.Value.Y < rectangleF.Bottom) { if (!inccompSelect.Contains(keyValue.Key)) { within++; inccompSelect.Add(keyValue.Key); if (keyValue.Value != null) massLabelPoints.Add(keyValue.Value); } } } } } } Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC4); //Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC1); Random rd = new Random(); List colors = new List(nccomps); colors.Add(new Vec4b(0, 0, 0, 0)); for (int i = 1; i < nccomps; i++) { //colors.Add(new Vec3b(255, 255, 255)); colors.Add(new Vec4b(((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), 255)); } for (int y = 0; y < temp.Rows; y++) { for (int x = 0; x < temp.Cols; x++) { int label = labelMat.At(y, x); if (nccompSelect.Contains(label)) temp.Set(y, x, colors[label]); if (inccompSelect.Contains(label)) temp.Set(y, x, colors[label]); //temp.Set(y, x, new Vec4b(127, 127, 127, 127)); ////if (0 <= label && label <= nccomps) ////{ //// temp.Set(y, x, colors[label]); ////} } } //foreach (var item in massPoints) //{ // if (double.IsNaN(item.Y) || double.IsNaN(item.X)) // { // continue; // } // temp.Set((int)item.Y, (int)item.X, new Vec4b(0, 0, 255, 255)); //} //Cv2.ImWrite("erzhi5.tif", temp); ////Cv2.ImShow("temp", temp); this.documentWorkspace.PhaseModels[2].mat = temp; this.documentWorkspace.Refresh(); return within + (double)nccompSelect.Count / 2; } /// /// 使用圆心及半径得到圆的轮廓 /// /// 圆心 /// 半径 /// public OpenCvSharp.Point[] roundOutline(Point center, int radius) { if (radius < 1) radius = 1; Mat mat = new Mat((int)(radius * 2.1), (int)(radius * 2.1), MatType.CV_8UC1, new Scalar(0, 0, 0)); OpenCvSharp.Point point = new OpenCvSharp.Point(mat.Cols / 2, mat.Rows / 2); Cv2.Circle(mat, point, radius, new Scalar(255, 255, 255), -1); OpenCvSharp.Point[][] contours; HierarchyIndex[] hierarchy; Cv2.FindContours(mat, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone); OpenCvSharp.Point[] roundOutline = contours[0]; for (int i = 0; i < roundOutline.Length; i++) { roundOutline[i].X = roundOutline[i].X - point.X + center.X; roundOutline[i].Y = roundOutline[i].Y - point.Y + center.Y; } return roundOutline; } #region 内部类 internal class LocalListViewItem { public DocumentWorkspace Value { get; } public string Display { get; } public LocalListViewItem(DocumentWorkspace Value, string Display) { this.Value = Value; this.Display = Display; } } internal class DocumentItem { public Bitmap bitmap; public GraphicsList graphicsList; public List phaseModels; //public AnalysisResult analysisResult; public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List phaseModels) { this.bitmap = bitmap; this.graphicsList = graphicsList; this.phaseModels = phaseModels; } } #endregion } }