using Microsoft.Office.Interop.Excel; using OpenCvSharp; using PaintDotNet.Annotation; using PaintDotNet.Annotation.Enum; using PaintDotNet.Base; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.Functionodel; using PaintDotNet.Base.SettingModel; using PaintDotNet.CustomControl; using PaintDotNet.Data.Action; using PaintDotNet.Data.Param; using PaintDotNet.DbOpreate.DbModel; using PaintDotNet.Instrument; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Linq; using System.Windows.Forms; using Application = System.Windows.Forms.Application; using Button = System.Windows.Forms.Button; using CheckBox = System.Windows.Forms.CheckBox; using DataTable = System.Data.DataTable; using Font = System.Drawing.Font; using GroupBox = System.Windows.Forms.GroupBox; using Label = System.Windows.Forms.Label; using Point = System.Drawing.Point; using Rectangle = System.Drawing.Rectangle; namespace PaintDotNet.DedicatedAnalysis.PetroleumGeology.SYT6103 { internal class PetroleumGeologyStandardDialog : PdnBaseForm { #region 属性 /// /// 主控件 /// protected AppWorkspace appWorkspace; /// /// 公共按钮 /// private CommonControlButtons commonControlButtons; /// /// 图像面板 /// protected DocumentWorkspaceWindow documentWorkspace; /// /// 当前选择的图片 /// protected Bitmap bitmap; /// /// 当前选择的图片 /// protected Mat matOrg; protected Mat matGeology; /// /// 选择标尺的物理长度(1倍下的 微米/像素) /// double physical_length = 1; protected string oldSelectItem; public bool comboboxChange = true; /// /// 图形位置 /// private PointF m_StartPoint = Point.Empty; private PointF m_EndPoint = Point.Empty; protected bool m_canMove; private bool addPoint = false; //二值化集成1 protected BinaryClass binaryClass; protected int menuId; protected string menuName; /// /// 调色板 /// private ColorsForm colorsFormGrid; /// /// 当前选择的颜色块 /// private Panel colorsPanel; //分析结果列表的头标题 /// /// PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), "网格面积", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.Averagegrainsizegrade.text") /// List contentHead; /// /// 保存用于生成报告的图片 /// protected List bitList; /// /// 储存点击保存结果后的所有原图与分析图 /// protected Dictionary> bitDic = new Dictionary>(); /// /// 中间数据 /// protected List tempDataModel = new List(); /// /// 分析结果暂存 /// protected List dataTables = new List(); /// /// 孔隙的面积周边长等数据 /// protected List> lstAttribute = new List>(); /// /// 孔隙的面积周边长等数据与tag绑定关系并缓存起来 /// protected Dictionary>> lstAttriDict = new Dictionary>>(); /// /// 多图平均结果暂存 /// protected List dataPerTables = new List(); /// /// 全部显示 /// protected bool allShow = false; protected int defaultIndex = -1; #endregion #region 组件 private GroupBox groupBox_operating; protected GroupBox groupBox_img; private ListView lstView_img; private ImageList imageList_img; private IContainer components; protected GroupBox groupBox_review; protected GroupBox groupBox_report; private Label label_resultPrecision; private Button button_exportResults; private Button button_generateReport; protected GroupBox groupBox6groupBox_analysisResult2; protected GroupBox groupBox_analysisResult1; private ToolTip toolTip_GrainSizeDetails; private Button button_setting; protected CheckBox checkBox_generateReport_opensetting; protected DataGridView dataGridView2; protected ListView listView2; private Button button16; private Button button12; private Button button11; protected NumericUpDown numericUpDown1_0; private Button button1; protected DataGridView dataGridView1; private DataGridViewTextBoxColumn Column1; private DataGridViewTextBoxColumn Column2; private DataGridViewTextBoxColumn Column3; private DataGridViewTextBoxColumn Column4; private DataGridViewTextBoxColumn Column5; private DataGridViewTextBoxColumn Column6; private DataGridViewTextBoxColumn Column7; private DataGridViewTextBoxColumn Column8; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn6; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn7; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn8; private BinaryControl bc; private Button btn_saveresult; #endregion #region 构造函数 public PetroleumGeologyStandardDialog(AppWorkspace appWorkspace, string dialogText, bool isAreaType, PdnMenuItem menuItem) { this.appWorkspace = appWorkspace; this.Text = dialogText; this.Icon = PdnInfo.AppIcon; this.Load += new System.EventHandler(this.PetroleumGeologyStandardDialog_Load); this.colorsFormGrid = new ColorsForm(); this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen; this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged)); //Dictionary measurementUnitDictionary = Startup.instance.rules; //physical_length = measurementUnitDictionary[MeasurementUnit.Micron]; InitializeComponent(); InitializeLanguageText(); InitializeBC(); contentHead = new List() { PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.view.text"), PdnResources.GetString("Menu.Dedicatedanalysis.Non-ferrousmetals.serialnumber.text"), PdnResources.GetString("Menu.Theporediameter.text"), PdnResources.GetString("Menu.Apparentporeratiosurface.text"), PdnResources.GetString("Menu.Shapefactor.text"), PdnResources.GetString("Menu.Porethroatthan.text"), PdnResources.GetString("Menu.Coordinationnumber.text") }; this.menuId = menuItem.MenuId; this.menuName = menuItem.Text; binaryClass = new BinaryClass(menuId); Initialize(); SubclassInitialize(); //二值化集成2 bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件 binaryClass.createDocumentItems(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.lstView_img);//初始化相的工作结构 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); this.button11.Visible = true; this.button16.Visible = false; SetAnalyzeModelFromXml(getTemplateName()); } public PetroleumGeologyStandardDialog() { //this.Icon = PdnInfo.AppIcon; InitializeComponent(); /*InitializeLanguageText(); InitializeBC(); binaryClass = new BinaryClass();*/ } #endregion private void InitializeLanguageText() { this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text"); this.dataGridViewTextBoxColumn8.HeaderText = PdnResources.GetString("Menu.Averageporecoordinationnumber.text"); this.dataGridViewTextBoxColumn7.HeaderText = PdnResources.GetString("Menu.Porediameterseparationcoefficient.text"); this.dataGridViewTextBoxColumn6.HeaderText = PdnResources.GetString("Menu.Homogeneouscoefficient.text"); this.dataGridViewTextBoxColumn5.HeaderText = PdnResources.GetString("Menu.Meanporethroatratio.text"); this.dataGridViewTextBoxColumn4.HeaderText = PdnResources.GetString("Menu.Averageporeshapefactor.text"); this.dataGridViewTextBoxColumn3.HeaderText = PdnResources.GetString("Menu.Meanapparentporeratiosurface.text"); this.dataGridViewTextBoxColumn2.HeaderText = PdnResources.GetString("Menu.Meanporediameter.text"); this.dataGridViewTextBoxColumn1.HeaderText = PdnResources.GetString("Menu.Facerate.text"); this.button_generateReport.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text"); this.button_exportResults.Text = PdnResources.GetString("Menu.Exportresults.text"); this.label_resultPrecision.Text = PdnResources.GetString("Menu.Decimal.text")+":"; this.button1.Text = PdnResources.GetString("Menu.Exportproject.text"); this.groupBox_review.Text = PdnResources.GetString("Menu.Preview.text"); this.groupBox_img.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text"); this.btn_saveresult.Text = PdnResources.GetString("Menu.Saveresult.text"); this.button_setting.Text = PdnResources.GetString("Menu.Setting.Text"); this.checkBox_generateReport_opensetting.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text"); this.groupBox_operating.Text = PdnResources.GetString("Menu.operation.text"); this.button12.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.button16.Text = PdnResources.GetString("Menu.Cancelshowall.text"); this.button11.Text = PdnResources.GetString("Menu.Showall.text"); this.groupBox_analysisResult1.Text = PdnResources.GetString("Menu.Analysisresult.text"); this.Column8.HeaderText = PdnResources.GetString("Menu.Coordinationnumber.text"); this.Column7.HeaderText = PdnResources.GetString("Menu.Porethroatthan.text"); this.Column6.HeaderText = PdnResources.GetString("Menu.Shapefactor.text"); this.Column5.HeaderText = PdnResources.GetString("Menu.Apparentporeratiosurface.text"); this.Column4.HeaderText = PdnResources.GetString("Menu.Theporediameter.text"); this.Column3.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Non-ferrousmetals.serialnumber.text"); this.Column2.HeaderText = PdnResources.GetString("Menu.view.text"); } private void InitializeBC() { this.bc = new PaintDotNet.CustomControl.BinaryControl(); // // bc // this.bc.BinaryBackColor = System.Drawing.Color.Red; this.bc.BinaryChecked = false; this.bc.BinaryStyle = 1; this.bc.Location = new System.Drawing.Point(179, 70); 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, 292); this.bc.TabIndex = 34; this.Controls.Add(this.bc); this.Controls.SetChildIndex(this.bc, 0); } #region 初始化组件 private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); this.groupBox_operating = new System.Windows.Forms.GroupBox(); this.checkBox_generateReport_opensetting = new System.Windows.Forms.CheckBox(); this.button_setting = new System.Windows.Forms.Button(); this.btn_saveresult = new System.Windows.Forms.Button(); this.groupBox_img = new System.Windows.Forms.GroupBox(); this.lstView_img = new System.Windows.Forms.ListView(); this.imageList_img = new System.Windows.Forms.ImageList(this.components); this.groupBox_review = new System.Windows.Forms.GroupBox(); this.groupBox_report = new System.Windows.Forms.GroupBox(); this.button1 = new System.Windows.Forms.Button(); this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown(); this.label_resultPrecision = new System.Windows.Forms.Label(); this.button_exportResults = new System.Windows.Forms.Button(); this.button_generateReport = new System.Windows.Forms.Button(); this.groupBox6groupBox_analysisResult2 = new System.Windows.Forms.GroupBox(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridView2 = 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.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox_analysisResult1 = new System.Windows.Forms.GroupBox(); this.button11 = new System.Windows.Forms.Button(); this.listView2 = new System.Windows.Forms.ListView(); this.button16 = new System.Windows.Forms.Button(); this.button12 = new System.Windows.Forms.Button(); this.toolTip_GrainSizeDetails = new System.Windows.Forms.ToolTip(this.components); this.groupBox_operating.SuspendLayout(); this.groupBox_img.SuspendLayout(); this.groupBox_report.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit(); this.groupBox6groupBox_analysisResult2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); this.groupBox_analysisResult1.SuspendLayout(); this.SuspendLayout(); // // groupBox_operating // this.groupBox_operating.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox_operating.Controls.Add(this.checkBox_generateReport_opensetting); this.groupBox_operating.Controls.Add(this.button_setting); this.groupBox_operating.Controls.Add(this.btn_saveresult); this.groupBox_operating.Location = new System.Drawing.Point(13, 12); this.groupBox_operating.Name = "groupBox_operating"; this.groupBox_operating.Size = new System.Drawing.Size(1102, 53); this.groupBox_operating.TabIndex = 12; this.groupBox_operating.TabStop = false; // // checkBox_generateReport_opensetting // this.checkBox_generateReport_opensetting.AutoSize = true; this.checkBox_generateReport_opensetting.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; this.checkBox_generateReport_opensetting.Location = new System.Drawing.Point(91, 24); this.checkBox_generateReport_opensetting.Name = "checkBox_generateReport_opensetting"; this.checkBox_generateReport_opensetting.Size = new System.Drawing.Size(15, 14); this.checkBox_generateReport_opensetting.TabIndex = 6; this.checkBox_generateReport_opensetting.UseVisualStyleBackColor = true; // // button_setting // this.button_setting.Location = new System.Drawing.Point(6, 20); this.button_setting.Name = "button_setting"; this.button_setting.Size = new System.Drawing.Size(75, 23); this.button_setting.TabIndex = 4; this.button_setting.UseVisualStyleBackColor = true; this.button_setting.Click += new System.EventHandler(this.button_setting_Click); // // btn_saveresult // this.btn_saveresult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_saveresult.Location = new System.Drawing.Point(992, 20); this.btn_saveresult.Name = "btn_saveresult"; this.btn_saveresult.Size = new System.Drawing.Size(75, 23); this.btn_saveresult.TabIndex = 2; this.btn_saveresult.UseVisualStyleBackColor = true; this.btn_saveresult.Click += new System.EventHandler(this.btn_saveresult_Click); // // groupBox_img // this.groupBox_img.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.groupBox_img.Controls.Add(this.lstView_img); this.groupBox_img.Location = new System.Drawing.Point(13, 72); this.groupBox_img.Margin = new System.Windows.Forms.Padding(4); this.groupBox_img.Name = "groupBox_img"; this.groupBox_img.Padding = new System.Windows.Forms.Padding(4); this.groupBox_img.Size = new System.Drawing.Size(158, 522); this.groupBox_img.TabIndex = 13; this.groupBox_img.TabStop = false; // // lstView_img // this.lstView_img.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.lstView_img.HideSelection = false; this.lstView_img.LargeImageList = this.imageList_img; this.lstView_img.Location = new System.Drawing.Point(8, 26); this.lstView_img.Margin = new System.Windows.Forms.Padding(4); this.lstView_img.MultiSelect = false; this.lstView_img.Name = "lstView_img"; this.lstView_img.Size = new System.Drawing.Size(140, 488); this.lstView_img.TabIndex = 0; this.lstView_img.UseCompatibleStateImageBehavior = false; this.lstView_img.SelectedIndexChanged += new System.EventHandler(this.lstView_img_SelectedIndexChanged); // // imageList_img // this.imageList_img.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList_img.ImageSize = new System.Drawing.Size(64, 64); this.imageList_img.TransparentColor = System.Drawing.Color.Transparent; // // groupBox_review // this.groupBox_review.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.groupBox_review.Location = new System.Drawing.Point(545, 72); this.groupBox_review.Name = "groupBox_review"; this.groupBox_review.Size = new System.Drawing.Size(571, 522); this.groupBox_review.TabIndex = 30; this.groupBox_review.TabStop = false; // // groupBox_report // this.groupBox_report.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBox_report.Controls.Add(this.button1); this.groupBox_report.Controls.Add(this.numericUpDown1_0); this.groupBox_report.Controls.Add(this.label_resultPrecision); this.groupBox_report.Controls.Add(this.button_exportResults); this.groupBox_report.Controls.Add(this.button_generateReport); this.groupBox_report.Location = new System.Drawing.Point(974, 600); this.groupBox_report.Name = "groupBox_report"; this.groupBox_report.Size = new System.Drawing.Size(142, 218); this.groupBox_report.TabIndex = 33; this.groupBox_report.TabStop = false; // // button1 // this.button1.Location = new System.Drawing.Point(29, 108); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 23; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // numericUpDown1_0 // this.numericUpDown1_0.Location = new System.Drawing.Point(63, 170); 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 = 22; this.numericUpDown1_0.Value = new decimal(new int[] { 2, 0, 0, 0}); this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged); // // label_resultPrecision // this.label_resultPrecision.AutoSize = true; this.label_resultPrecision.Location = new System.Drawing.Point(17, 174); this.label_resultPrecision.Name = "label_resultPrecision"; this.label_resultPrecision.Size = new System.Drawing.Size(35, 12); this.label_resultPrecision.TabIndex = 3; this.label_resultPrecision.Text = "小数:"; // // button_exportResults // this.button_exportResults.Location = new System.Drawing.Point(29, 69); this.button_exportResults.Name = "button_exportResults"; this.button_exportResults.Size = new System.Drawing.Size(75, 23); this.button_exportResults.TabIndex = 1; this.button_exportResults.UseVisualStyleBackColor = true; this.button_exportResults.Click += new System.EventHandler(this.button_exportResults_Click); // // button_generateReport // this.button_generateReport.Location = new System.Drawing.Point(29, 30); this.button_generateReport.Name = "button_generateReport"; this.button_generateReport.Size = new System.Drawing.Size(75, 23); this.button_generateReport.TabIndex = 0; this.button_generateReport.UseVisualStyleBackColor = true; this.button_generateReport.Click += new System.EventHandler(this.button_generateReport_Click); // // groupBox6groupBox_analysisResult2 // this.groupBox6groupBox_analysisResult2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView1); this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView2); this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 601); this.groupBox6groupBox_analysisResult2.Name = "groupBox6groupBox_analysisResult2"; this.groupBox6groupBox_analysisResult2.Size = new System.Drawing.Size(719, 217); this.groupBox6groupBox_analysisResult2.TabIndex = 32; this.groupBox6groupBox_analysisResult2.TabStop = false; // // dataGridView1 // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle3.Font = new System.Drawing.Font("宋体", 9F); dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle3; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn2, this.dataGridViewTextBoxColumn3, this.dataGridViewTextBoxColumn4, this.dataGridViewTextBoxColumn5, this.dataGridViewTextBoxColumn6, this.dataGridViewTextBoxColumn7, this.dataGridViewTextBoxColumn8}); this.dataGridView1.Location = new System.Drawing.Point(13, 115); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.ReadOnly = true; this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.Size = new System.Drawing.Size(693, 98); this.dataGridView1.TabIndex = 17; // // dataGridViewTextBoxColumn1 // this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; this.dataGridViewTextBoxColumn1.ReadOnly = true; // // dataGridViewTextBoxColumn2 // this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; this.dataGridViewTextBoxColumn2.ReadOnly = true; // // dataGridViewTextBoxColumn3 // this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; this.dataGridViewTextBoxColumn3.ReadOnly = true; // // dataGridViewTextBoxColumn4 // this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; this.dataGridViewTextBoxColumn4.ReadOnly = true; // // dataGridViewTextBoxColumn5 // this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5"; this.dataGridViewTextBoxColumn5.ReadOnly = true; // // dataGridViewTextBoxColumn6 // this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6"; this.dataGridViewTextBoxColumn6.ReadOnly = true; // // dataGridViewTextBoxColumn7 // this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7"; this.dataGridViewTextBoxColumn7.ReadOnly = true; // // dataGridViewTextBoxColumn8 // this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8"; this.dataGridViewTextBoxColumn8.ReadOnly = true; // // dataGridView2 // this.dataGridView2.AllowUserToAddRows = false; this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGridView2.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView2.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle4.Font = new System.Drawing.Font("宋体", 9F); dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4; this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column4, this.Column5, this.Column6, this.Column7, this.Column8}); this.dataGridView2.Location = new System.Drawing.Point(13, 11); this.dataGridView2.Name = "dataGridView2"; this.dataGridView2.ReadOnly = true; this.dataGridView2.RowHeadersVisible = false; this.dataGridView2.RowTemplate.Height = 23; this.dataGridView2.Size = new System.Drawing.Size(693, 98); this.dataGridView2.TabIndex = 16; // // 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; // // Column7 // this.Column7.Name = "Column7"; this.Column7.ReadOnly = true; // // Column8 // this.Column8.Name = "Column8"; this.Column8.ReadOnly = true; // // groupBox_analysisResult1 // this.groupBox_analysisResult1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.groupBox_analysisResult1.Controls.Add(this.button11); this.groupBox_analysisResult1.Controls.Add(this.listView2); this.groupBox_analysisResult1.Controls.Add(this.button16); this.groupBox_analysisResult1.Controls.Add(this.button12); this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 601); this.groupBox_analysisResult1.Name = "groupBox_analysisResult1"; this.groupBox_analysisResult1.Size = new System.Drawing.Size(224, 217); this.groupBox_analysisResult1.TabIndex = 31; this.groupBox_analysisResult1.TabStop = false; // // button11 // this.button11.BackColor = System.Drawing.SystemColors.Control; this.button11.Location = new System.Drawing.Point(19, 22); this.button11.Name = "button11"; this.button11.Size = new System.Drawing.Size(63, 26); this.button11.TabIndex = 27; this.button11.UseVisualStyleBackColor = false; this.button11.Click += new System.EventHandler(this.button11_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(19, 58); this.listView2.Name = "listView2"; this.listView2.Size = new System.Drawing.Size(181, 153); this.listView2.TabIndex = 26; this.listView2.UseCompatibleStateImageBehavior = false; this.listView2.SelectedIndexChanged += new System.EventHandler(this.listview2_SelectedIndexChanged); // // button16 // this.button16.BackColor = System.Drawing.SystemColors.Control; this.button16.Location = new System.Drawing.Point(19, 21); this.button16.Name = "button16"; this.button16.Size = new System.Drawing.Size(93, 26); this.button16.TabIndex = 25; this.button16.UseVisualStyleBackColor = false; this.button16.Click += new System.EventHandler(this.button16_Click); // // button12 // this.button12.BackColor = System.Drawing.SystemColors.Control; this.button12.Location = new System.Drawing.Point(149, 21); this.button12.Name = "button12"; this.button12.Size = new System.Drawing.Size(52, 26); this.button12.TabIndex = 24; this.button12.UseVisualStyleBackColor = false; this.button12.Click += new System.EventHandler(this.button12_Click); // // PetroleumGeologyStandardDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(1127, 830); this.Controls.Add(this.groupBox_report); this.Controls.Add(this.groupBox6groupBox_analysisResult2); this.Controls.Add(this.groupBox_analysisResult1); this.Controls.Add(this.groupBox_review); this.Controls.Add(this.groupBox_img); this.Controls.Add(this.groupBox_operating); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Location = new System.Drawing.Point(0, 0); this.Name = "PetroleumGeologyStandardDialog"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.InclusionsStandardDialog_FormClosing); this.Shown += new System.EventHandler(this.ShownChoiseItemAndInitData); this.Controls.SetChildIndex(this.groupBox_operating, 0); this.Controls.SetChildIndex(this.groupBox_img, 0); this.Controls.SetChildIndex(this.groupBox_review, 0); this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0); this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0); this.Controls.SetChildIndex(this.groupBox_report, 0); this.groupBox_operating.ResumeLayout(false); this.groupBox_operating.PerformLayout(); this.groupBox_img.ResumeLayout(false); this.groupBox_report.ResumeLayout(false); this.groupBox_report.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit(); this.groupBox6groupBox_analysisResult2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); this.groupBox_analysisResult1.ResumeLayout(false); this.ResumeLayout(false); } private void ShowImgEvent(object sender, EventArgs e) { lstView_img.Focus(); if (this.defaultIndex != -1) { this.lstView_img.Items[defaultIndex].Focused = true; this.lstView_img.Items[defaultIndex].Selected = true; } } public void Initialize() { //初始化图片列表 for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++) { this.imageList_img.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail); this.lstView_img.Items.Add("", i); this.lstView_img.Items[i].ImageIndex = i; this.lstView_img.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); this.lstView_img.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace)) { defaultIndex = i; } } this.Shown += ShowImgEvent; // //初始化图像控件 // this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace); this.documentWorkspace.Cursor = Cursors.Default; this.documentWorkspace.Dock = DockStyle.Fill; this.documentWorkspace.HookMouseEvents(); this.documentWorkspace.AuxiliaryLineEnabled = false; this.documentWorkspace.Visible = true; this.documentWorkspace.panel.MouseDown += OnMouseDown; this.documentWorkspace.panel.Paint += Panel_Paint; this.documentWorkspace.panel.MouseMove += onMouseMove; this.documentWorkspace.panel.MouseUp += onMouseUp; this.groupBox_review.Controls.Add(this.documentWorkspace); // //初始化操作按钮 // this.commonControlButtons = new CommonControlButtons(); this.commonControlButtons.Dock = DockStyle.Top; this.commonControlButtons.Height = 30; this.commonControlButtons.HideZoomToWindowAndActualSize(); 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); groupBox_review.Controls.Add(this.commonControlButtons); } #endregion #region 事件 #region 公共按钮 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.InclusionNoEffect; } private void mobileModeButton_Click(object sender, EventArgs e) { this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode; } #endregion /// /// 设置 /// /// /// private void button_setting_Click(object sender, EventArgs e) { string templateName = getTemplateName(); AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, templateName); if (metallographicMethodSetDialog.hasModule) { metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen; metallographicMethodSetDialog.ShowDialog(); } else { metallographicMethodSetDialog = null; } } private void btn_saveresult_Click(object sender, EventArgs e) { buildListBox_analysisResult(); } private void lstView_img_SelectedIndexChanged(object sender, EventArgs e) { if (this.lstView_img.FocusedItem != null && this.lstView_img.FocusedItem.Selected) { this.physical_length = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetRuler(MeasurementUnit.Micron); //double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron); //this.documentWorkspace.Document = Document.FromImage(this.documentItems[this.lstView_img.FocusedItem.Index].bitmap); //this.documentWorkspace.Visible = true; //this.documentWorkspace.activeTool = DrawToolType.InclusionNoEffect; //this.documentWorkspace.GraphicsList = this.documentItems[this.lstView_img.FocusedItem.Index].graphicsList; //this.documentWorkspace.PhaseModels = new List(); //this.documentWorkspace.PhaseModels.AddRange(this.documentItems[this.lstView_img.FocusedItem.Index].phaseModels); this.bitmap = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); //if (!this.documentWorkspace.PhaseModels[0].choise) // this.checkBox10.Checked = false; bool existViewFlag = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GraphicsList.IsExsitView(); if (!existViewFlag) { matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap); } else { matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetFullSizeWithRegion()); } //二值化集成4 binaryClass.listView1_SelectedIndexChanged(this.bitmap); if (bcOriginChecked()) { this.documentWorkspace.PhaseModels[0].choise = false; this.documentWorkspace.Refresh(); } //if (this.checkBox1.Checked) //{ // this.applyDect(); //} if (segmentedHolesMat != null) { segmentedHolesMat.Dispose(); segmentedHolesMat = null; } lstAttribute.Clear(); minLinePoints.Clear(); refreshWhileImgChanged(); } } #region 矩形拖动 /// /// 鼠标按下 /// /// /// protected virtual void OnMouseDown(object sender, MouseEventArgs e) { // 换算后的点 //PointF point1 = documentWorkspace.GetScalePoint(e.Location); if (addPoint) { m_StartPoint = documentWorkspace.GetScalePoint(e.Location); } } /// /// 移动 /// /// /// protected virtual void onMouseMove(object sender, MouseEventArgs e) { //this.documentWorkspace.Refresh(); // 换算后的点 //PointF point1 = documentWorkspace.GetScalePoint(e.Location); if (addPoint && m_StartPoint.X > 0 && m_StartPoint.Y > 0) { m_EndPoint = documentWorkspace.GetScalePoint(e.Location); this.documentWorkspace.Refresh(); } } /// /// 鼠标抬起 /// /// /// private void onMouseUp(object sender, MouseEventArgs e) { if (this.bitmap != null && m_StartPoint.X > 0 && m_StartPoint.Y > 0 && m_StartPoint.X < this.bitmap.Width && m_StartPoint.Y < this.bitmap.Height && m_EndPoint.X > 0 && m_EndPoint.Y > 0 && m_EndPoint.X < this.bitmap.Width && m_EndPoint.Y < this.bitmap.Height) { Line lineI = new Line(new Point((int)m_StartPoint.X, (int)m_StartPoint.Y), new Point((int)m_EndPoint.X, (int)m_EndPoint.Y)); minLinePoints.Add(new Point2d((int)((m_StartPoint.X + m_EndPoint.X) / 2), (int)((m_StartPoint.Y + m_EndPoint.Y) / 2)), lineI); if (segmentedHolesMat != null) { segmentedHolesMat.Dispose(); segmentedHolesMat = null; } if (segmentedHolesMat == null && createSegmentedHoldsMat() || segmentedHolesMat != null) { m_StartPoint = Point.Empty; m_EndPoint = Point.Empty; m_canMove = false; //addPoint = false; return; } else //图像分割 this.documentWorkspace.Refresh(); } m_StartPoint = Point.Empty; m_EndPoint = Point.Empty; m_canMove = false; addPoint = false; this.documentWorkspace.Refresh(); } #endregion /// /// 画布绘制 /// /// /// 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); 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; drawSubclass(graphics); } #endregion #region 内部方法 /// /// 从末梢的点开始寻找截线的极小值点 /// /// 阈值的平方 /// 从枝干末梢的坐标点根据抽骨架路径往里走 /// 抽骨架的mat /// 距离变换的mat /// 已经找到的极小值点 /// point点的距离 /// point前面的点的距离 /// private Dictionary GetMinLabelPoint(int threshold_2, Point point, Mat mat, Mat distance_temp, Dictionary foundList, float former1Distance, float former2Distance) { //if (routePoints.FindAll(a => a.X == point.X && a.Y == point.Y).Count > 0) if (routePoints.Contains(point)) return foundList; routePoints.Add(new Point(point.X, point.Y)); bool firstValueOnBoundry; bool lastValueOnBoundry; Point lastPoint = new Point(point.X, point.Y); Point nextPoint = new Point(point.X - 1, point.Y - 1); float currDistance; int count; do { count = 0; if (point.X > mat.Width - 2 || point.X < 1 || point.Y > mat.Height - 2 || point.Y < 1) { } else { if (!routePoints.Contains(new Point(point.X - 1, point.Y - 1)) && mat.At(point.Y - 1, point.X - 1).Item3 != 0) { nextPoint = new Point(point.X - 1, point.Y - 1); count++; firstValueOnBoundry = true; lastValueOnBoundry = true; } else { firstValueOnBoundry = false; lastValueOnBoundry = false; } if (!routePoints.Contains(new Point(point.X, point.Y - 1)) && mat.At(point.Y - 1, point.X).Item3 != 0) { if (!lastValueOnBoundry) { nextPoint = new Point(point.X, point.Y - 1); count++; } lastValueOnBoundry = true; } else lastValueOnBoundry = false; if (!routePoints.Contains(new Point(point.X + 1, point.Y - 1)) && mat.At(point.Y - 1, point.X + 1).Item3 != 0) { if (!lastValueOnBoundry) { nextPoint = new Point(point.X + 1, point.Y - 1); count++; } lastValueOnBoundry = true; } else lastValueOnBoundry = false; if (!routePoints.Contains(new Point(point.X + 1, point.Y)) && mat.At(point.Y, point.X + 1).Item3 != 0) { if (!lastValueOnBoundry) { nextPoint = new Point(point.X + 1, point.Y); count++; } lastValueOnBoundry = true; } else lastValueOnBoundry = false; if (!routePoints.Contains(new Point(point.X + 1, point.Y + 1)) && mat.At(point.Y + 1, point.X + 1).Item3 != 0) { if (!lastValueOnBoundry) { nextPoint = new Point(point.X + 1, point.Y + 1); count++; } lastValueOnBoundry = true; } else lastValueOnBoundry = false; if (!routePoints.Contains(new Point(point.X, point.Y + 1)) && mat.At(point.Y + 1, point.X).Item3 != 0) { if (!lastValueOnBoundry) { nextPoint = new Point(point.X, point.Y + 1); count++; } lastValueOnBoundry = true; } else lastValueOnBoundry = false; if (!routePoints.Contains(new Point(point.X - 1, point.Y + 1)) && mat.At(point.Y + 1, point.X - 1).Item3 != 0) { if (!lastValueOnBoundry) { nextPoint = new Point(point.X - 1, point.Y + 1); count++; } lastValueOnBoundry = true; } else lastValueOnBoundry = false; if (!routePoints.Contains(new Point(point.X - 1, point.Y)) && mat.At(point.Y, point.X - 1).Item3 != 0) { if (!lastValueOnBoundry && !firstValueOnBoundry) { nextPoint = new Point(point.X - 1, point.Y); count++; } lastValueOnBoundry = true; } else lastValueOnBoundry = false; } if (count == 1) { //if (routePoints.Count > 0) // routePoints.RemoveAt(routePoints.Count - 1); routePoints.Add(new Point(nextPoint.X, nextPoint.Y)); } else if (count > 1) { routePoints.Add(new Point(nextPoint.X, nextPoint.Y)); } if (count == 1) { //走到其中一条路径 currDistance = distance_temp.At(nextPoint.Y, nextPoint.X); if ((currDistance - former1Distance >= 0) && (former1Distance - former2Distance) <= 0 && former2Distance != float.MinValue) { if (/*foundList.Count == 0 || foundList.Count > 0 && */Math.Max(10, currDistance * currDistance * 9)/*threshold_2*/ < ((lastPoint.X - nextPoint.X) * (lastPoint.X - nextPoint.X) + (lastPoint.Y - nextPoint.Y) * (lastPoint.Y - nextPoint.Y))) { foundList.Add(new Point2d(point.X, point.Y), (int)(Math.Round(former1Distance * former1Distance))); lastPoint.X = nextPoint.X; lastPoint.Y = nextPoint.Y; } } point.X = nextPoint.X; point.Y = nextPoint.Y; former2Distance = former1Distance; former1Distance = currDistance; } } while (count == 1); return foundList; } /// /// 导出项目 /// /// /// private void button1_Click(object sender, EventArgs e) { if (this.listView2.Items.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Noresults.text")); return; } if (this.checkBox_generateReport_opensetting.Checked) this.button_setting.PerformClick(); if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify)) { //获取项目工程内的文件夹路径 ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, getProjectEngineeringName(), 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.dataGridView2.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 button_exportResults_Click(object sender, EventArgs e) { if (this.listView2.Items.Count > 0) { System.Data.DataSet ds = new DataSet(); DataTable table1 = new DataTable(); table1.TableName = PdnResources.GetString("Menu.breakdown.text"); foreach (DataGridViewColumn c in this.dataGridView2.Columns) { table1.Columns.Add(c.HeaderText); } for (int r = 0; r < this.dataGridView2.Rows.Count; r++) { DataRow dataRow = table1.NewRow(); if (r == 0) { for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++) { dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Columns[c].HeaderText; } table1.Rows.Add(dataRow); } dataRow = table1.NewRow(); for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++) { dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Rows[r].Cells[c].Value; } table1.Rows.Add(dataRow); } DataTable table2 = new DataTable(); table2.TableName = PdnResources.GetString("Menu.statisaatics.text"); foreach (DataGridViewColumn c in this.dataGridView1.Columns) { table2.Columns.Add(c.HeaderText); } for (int r = 0; r < this.dataGridView1.Rows.Count; r++) { DataRow dataRow = table2.NewRow(); if (r == 0) { for (int c = 0; c < this.dataGridView1.Rows[r].Cells.Count; c++) { dataRow[this.dataGridView1.Columns[c].HeaderText] = this.dataGridView1.Columns[c].HeaderText; } table2.Rows.Add(dataRow); } dataRow = table2.NewRow(); for (int c = 0; c < this.dataGridView1.Rows[r].Cells.Count; c++) { dataRow[this.dataGridView1.Columns[c].HeaderText] = this.dataGridView1.Rows[r].Cells[c].Value; } table2.Rows.Add(dataRow); } if (table1.Rows.Count > 0) ds.Tables.Add(table1); if (table2.Rows.Count > 0) ds.Tables.Add(table2); if (ds.Tables.Count > 0) DataToExcle(ds); } else { MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text")+"!"); } } /// /// 导出多 Sheet 报表 /// /// 要导出的数据 public void DataToExcle(System.Data.DataSet ds) { try { if (ds.Tables == null || ds.Tables.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Nonedata.Text")+"!"); return; } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.DefaultExt = "xlsx"; saveFileDialog.Title = PdnResources.GetString("Menu.ExportdatatoEXECLtable.Text"); saveFileDialog.FileName = PdnResources.GetString("Menu.estructurecharacteristics.text") + DateTime.Now.ToString("yyyyMMddhhmmss"); saveFileDialog.Filter = "microsoft office execl files (*.xlsx)|*.xlsx"; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { List list = new List(); foreach (System.Data.DataTable itemTable in ds.Tables) list.Add(itemTable); this.appWorkspace.ExportDataToExcelWithProgress(list, saveFileDialog.FileName, true, false, true); } } catch (Exception e) { throw e; } } #endregion //二值化集成3 #region 二值化相关方法 private void InclusionsStandardDialog_FormClosing(object sender, FormClosingEventArgs e) { #region [开启脚本录制] if (appWorkspace.startScriptRecording) { getScriptRecording(); } #endregion binaryClass.saveParams(); } private void ShownChoiseItemAndInitData(object sender, EventArgs e) { binaryClass.RefreshHistogramControl1Values(); } /// /// 添加参数改变的监听 /// /// /// private void PetroleumGeologyStandardDialog_Load(object sender, EventArgs e) { this.binaryClass.loadParams(); } 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(); } /// /// 显示原图/原图+二值图 /// /// /// private void bcOriginCheckedChanged(object sender, EventArgs e) { if (!bcOriginChecked()) { if (bcBinaryChecked()) this.documentWorkspace.PhaseModels[0].choise = true; } else { this.documentWorkspace.PhaseModels[0].choise = false; } this.documentWorkspace.Refresh(); } #endregion protected void panelColor_Click(object sender, EventArgs e) { this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor); this.colorsPanel = (Panel)sender; this.colorsFormGrid.ShowDialog(); } /// /// Panel2的调色板颜色改变 /// /// /// private void gridColorChanged(object sender, EventArgs e) { Color color = this.colorsFormGrid.UserPrimaryColor.ToColor(); if (colorsPanel != null) { colorsPanel.BackColor = color; //刷新显示页面文字颜色 this.documentWorkspace.Refresh(); } //关闭色板 this.colorsFormGrid.Close(); } #region 可调用方法 /// /// 是否显示原图 /// /// protected Boolean showOrimat() { return bcOriginChecked(); } /// /// 是否能取到二值的结果 /// /// protected Boolean getBinaryChecked() { return (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null); } /// /// 返回当前选择的图片内容 /// /// protected DocumentWorkspace getCurrentWorkspace() { return this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index]; } /// /// 返回当前选择的图片tag /// /// protected string getCurrentWorkTag() { return this.imageList_img.Images.Keys[this.lstView_img.FocusedItem.Index/*lstView_img.SelectedItems[0].Index*/]; } protected bool holeNumberVisible = false; /// /// 喉道分割后的图片 /// private Mat segmentedHolesMat; /// /// 显示、隐藏孔隙编号 /// /// protected void controlHoleNumberVisible(bool visible) { holeNumberVisible = visible; if (holeNumberVisible && minLinePoints.Count > 0 && /*成功获取喉道分割后的图片*/(segmentedHolesMat == null && createSegmentedHoldsMat() || segmentedHolesMat != null)) { //this.documentWorkspace.PhaseModels[0].choise = false; //this.documentWorkspace.PhaseModels[1].choise = true; //this.documentWorkspace.PhaseModels[2].choise = true; } else { //this.documentWorkspace.PhaseModels[0].choise = true; //this.documentWorkspace.PhaseModels[1].choise = false; //this.documentWorkspace.PhaseModels[2].choise = false; holeNumberVisible = false; } this.documentWorkspace.PhaseModels[0].choise = true; this.documentWorkspace.Refresh(); } /// /// 获取喉道分割后的图片 /// private bool createSegmentedHoldsMat() { if (this.documentWorkspace.PhaseModels.Count > 0 && this.documentWorkspace.PhaseModels[0].choise == true && this.documentWorkspace.PhaseModels[0].mat != null) { } else return false; Mat src = this.documentWorkspace.PhaseModels[0].mat; Mat distance_temp = new Mat(); //灰度图 Mat Inmat = BinaryClass.BGRA2GRAY(this.documentWorkspace.PhaseModels[0].mat)/* //### .CvtColor(ColorConversionCodes.BGR2GRAY)*/; Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise); Mat newMat = new Mat(src.Height, src.Width, MatType.CV_8UC4, new Scalar(0, 0, 0, 0)); Bitmap newBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newMat); Graphics graphics = Graphics.FromImage(newBit); Pen linePen = new Pen(Color.FromArgb(this.documentWorkspace.PhaseModels[0].color), 2/*1*/); foreach (var itemLine in minLinePoints.Values) { graphics.DrawLine(linePen, itemLine.startPoint, itemLine.endPoint); } Mat dst = new Mat(); Mat mat1 = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit); int w = src.Width; int h = src.Height; int w1 = mat1.Width; int h1 = mat1.Height; Mat mat2 = new Mat(h, w, src.Type(), Scalar.All(0)); Rect rect = new Rect(0, 0, Math.Min(w, w1), Math.Min(h, h1)); Mat tempMat = mat1.Clone(rect); //复制用户选中的区域到原图像 Mat mask = tempMat.CvtColor(ColorConversionCodes.RGBA2GRAY); Mat pos = new Mat(mat2, rect); tempMat.CopyTo(pos, mask); //Cv2.CopyMakeBorder(src, src, 0, maxh - src.Height, 0, maxw - src.Width, BorderTypes.Isolated); //Cv2.CopyMakeBorder(mat1, mat1, 0, maxh - mat1.Height, 0, maxw - mat1.Width, BorderTypes.Isolated); Mat tempMat0 = src.Clone(rect); //复制用户选中的区域到原图像 Mat mask0 = tempMat0.CvtColor(ColorConversionCodes.RGBA2GRAY); Mat mat0 = new Mat(h, w, src.Type(), Scalar.All(/*255*/0)); Mat pos0 = new Mat(mat0, rect); tempMat0.CopyTo(pos0, mask0); Cv2.Subtract(src/*待确认效果:mat0*/, mat2, dst); //Cv2.Subtract(src, mat1, dst); if (segmentedHolesMat != null) { segmentedHolesMat.Dispose(); segmentedHolesMat = null; } segmentedHolesMat = dst.Clone(); //this.documentWorkspace.PhaseModels[1].mat = dst; //显示连通域和编号信息 Mat erzhi = dst;//.Clone(); //Cv2.ImShow("erzhi1", erzhi); //Cv2.WaitKey(); Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY); //Cv2.ImShow("erzhi2", erzhi); //Cv2.WaitKey(); Cv2.Threshold(erzhi, erzhi, 10, 255, ThresholdTypes.Binary); //Cv2.ImShow("erzhi3", erzhi); //Cv2.WaitKey(); 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 < 10000/*100*/) { foreach (OpenCvSharp.Point point in contour) { erzhi.Set(point.Y, point.X, 255); } pointss.Add(contour); } } //Cv2.ImShow("dst", dst); //Cv2.ImShow("erzhi", erzhi); //Cv2.WaitKey(); 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)); ////} lstAttribute.Clear(); Mat labelMat = new Mat(); Mat stats = new Mat(); Mat centroids = new Mat(); // 连通域数量 int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8); List attribute; for (int hcomp = 1; hcomp < centroids.Height; hcomp++) { //double a = centroids.At(h, 0); //double b = centroids.At(h, 1); int x = (int)centroids.At(hcomp, 0);// stats.At(hcomp, 0); int y = (int)centroids.At(hcomp, 1);// stats.At(hcomp, 1); int width = stats.At(hcomp, 2); int height = stats.At(hcomp, 3); if (x < 0 || y < 0 || width > bitmap.Width || height > bitmap.Height || x >= bitmap.Width || y >= bitmap.Height) { continue; } int areaField1 = stats.At(hcomp, 4); attribute = new List(); //int label = labelMat.At(y, x); attribute.Add(hcomp); attribute.Add(x); attribute.Add(y); attribute.Add(width); attribute.Add(height); attribute.Add(areaField1); attribute.Add(0);//喉道数量 attribute.Add(hcomp);//编号 attribute.Add(0);//孔隙周边长,单位是像素 attribute.Add(0);//与该空腔连通的喉道总宽度,单位是像素 //attribute.Add(0);//长径 //attribute.Add(0);//短径 //attribute.Add(0);//平均径 //lstAttribute.Add(attribute); ////double areaField = areaField1 * unitLength * unitLength; Point centerRadiusPoint = new Point(x, y); Point startPoint; Point endPoint; bool notFound; int matHeight = erzhi.Height; int matWidth = erzhi.Width; int step = -1; List d2list = new List(); for (int rotateAngleV = 0; rotateAngleV < 360; rotateAngleV += 15) { notFound = true; startPoint = new Point(x, y); while (notFound) { startPoint.X += step; Point itemP11 = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, startPoint.X, startPoint.Y, centerRadiusPoint.X, centerRadiusPoint.Y); if (itemP11.Y < 0 || itemP11.X < 0 || itemP11.Y >= matHeight || itemP11.X >= matWidth) { startPoint.X = itemP11.X; startPoint.Y = itemP11.Y; notFound = false; break; } Vec4b vec4B = erzhi/*binary_temp*/.At(itemP11.Y, itemP11.X); if (vec4B.Item3 == 0) { startPoint.X = itemP11.X; startPoint.Y = itemP11.Y; notFound = false; break; } } notFound = true; endPoint = new Point(x, y); while (notFound) { endPoint.X -= step; Point itemP11 = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, endPoint.X, endPoint.Y, centerRadiusPoint.X, centerRadiusPoint.Y); if (itemP11.Y < 0 || itemP11.X < 0 || itemP11.Y >= matHeight || itemP11.X >= matWidth) { endPoint.X = itemP11.X; endPoint.Y = itemP11.Y; notFound = false; break; } Vec4b vec4B = erzhi/*binary_temp*/.At(itemP11.Y, itemP11.X); if (vec4B.Item3 == 0) { endPoint.X = itemP11.X; endPoint.Y = itemP11.Y; notFound = false; break; } } //int d2Value = (startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) + (startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y); d2list.Add((startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) + (startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y)); //int insertIndex = 0; //for (int id2Index = 0; id2Index < d2list.Count; id2Index++) //{ // if (d2Value > d2list[id2Index]) // ++insertIndex; // else // break; //} //d2list.Insert(insertIndex, d2Value); } d2list.Sort(); attribute.Add(d2list[d2list.Count-1]);//长径 attribute.Add(d2list[0]);//短径 attribute.Add(d2list.ToArray().Sum() / d2list.Count());//平均径 lstAttribute.Add(attribute); } // 计算所有轮廓周边长(即孔隙周边长,单位是像素) int labelP2; int labelP3; //Mat dismat = new Mat(distance_temp.Height, distance_temp.Width, MatType.CV_8UC4, new Scalar(0, 0, 0, 0)); Point[] offsetPoints1 = new Point[] { new Point(-1, -1), new Point(0, -1), new Point(1, -1), new Point(1, 0), new Point(1, 1), new Point(0, 1), new Point(-1, 1), new Point(-1, 0) }; //float currDistance; for (int int_Y = 1; int_Y < distance_temp.Height - 1; int_Y++) { for (int int_X = 1; int_X < distance_temp.Width - 1; int_X++) { labelP2 = labelMat.At(int_Y, int_X); if (labelP2 > 0) { //循环找内圈的轮廓点 foreach (var itemOffset in offsetPoints1) { labelP3 = labelMat.At(int_Y + itemOffset.Y, int_X + itemOffset.X); if (labelP3 == 0) { //dismat.Set(int_Y, int_X, new Vec4b(0, 255, 0, 255)); lstAttribute[labelP2 - 1][8] += 1; } } } else { //循环找外圈的轮廓点 foreach (var itemOffset in offsetPoints1) { labelP2 = labelMat.At(int_Y + itemOffset.Y, int_X + itemOffset.X); if (labelP2 > 0) { //dismat.Set(int_Y, int_X, new Vec4b(0, 255, 0, 255)); lstAttribute[labelP2 - 1][8] += 1; } } } //currDistance = distance_temp.At(int_Y, int_X); //if (currDistance == 1 || int_Y == 0 || int_X == 0 || int_X == distance_temp.Width - 1 || int_Y == distance_temp.Height - 1) //{ // dismat.Set(int_Y, int_X, new Vec4b(0, 255, 0, 255)); // labelP2 = labelMat.At(int_Y, int_X); // if (labelP2 > 0) // { // lstAttribute[labelP2 - 1][8] += 1; // } //} } } foreach (var itemAttri in lstAttribute) { itemAttri[8] /= 6/*2*/; } for (int int_Y = 0; int_Y < distance_temp.Height; int_Y++) { int int_X = 0; labelP2 = labelMat.At(int_Y, int_X); if (labelP2 > 0) lstAttribute[labelP2 - 1][8] += 1; } for (int int_Y = 0; int_Y < distance_temp.Height; int_Y++) { int int_X = distance_temp.Width - 1; labelP2 = labelMat.At(int_Y, int_X); if (labelP2 > 0) lstAttribute[labelP2 - 1][8] += 1; } for (int int_X = 1; int_X < distance_temp.Width - 1; int_X++) { int int_Y = 0; labelP2 = labelMat.At(int_Y, int_X); if (labelP2 > 0) lstAttribute[labelP2 - 1][8] += 1; } for (int int_X = 1; int_X < distance_temp.Width - 1; int_X++) { int int_Y = distance_temp.Height - 1; labelP2 = labelMat.At(int_Y, int_X); if (labelP2 > 0) lstAttribute[labelP2 - 1][8] += 1; } //Cv2.ImShow("dis", dismat); //Cv2.WaitKey(); //foreach (OpenCvSharp.Point[] contour in contours) //{ // labelP2 = -1; // foreach (var itemP2 in contour) // { // labelP2 = labelMat.At(itemP2.Y, itemP2.X); // if (labelP2 > 0 && lstAttribute[labelP2 - 1][8] == 0) // { // lstAttribute[labelP2 - 1][8] += contour.Length; // break; // } // } //} Point itemP; int matW = labelMat.Width; int matH = labelMat.Height; int countP; int labelP1; //int labelP2; Point[] offsetPoints = new Point[] { new Point(-1, -1), new Point(0, -1), new Point(1, -1), new Point(1, 0), new Point(1, 1), new Point(0, 1), new Point(-1, 1), new Point(-1, 0) , new Point(0, -2), new Point(2, 0), new Point(0, 2), new Point(-2, 0), new Point(-2, -2), new Point(-2, 2), new Point(2, 2), new Point(2, -2) }; //获取连通域的喉道信息 foreach (var itemLine in minLinePoints.Values) { itemP = new Point((itemLine.startPoint.X + itemLine.endPoint.X) / 2, (itemLine.startPoint.Y + itemLine.endPoint.Y) / 2); if (itemP.Y < 2 || itemP.X < 2 || itemP.Y >= matH - 1 || itemP.X >= matW - 1) continue; countP = 0; labelP1 = -1; labelP2 = -1; foreach (var itemOffset in offsetPoints) { labelP2 = labelMat.At(itemP.Y + itemOffset.Y, itemP.X + itemOffset.X); if (labelP2 > 0 && labelP2 != labelP1) { List attributeP = lstAttribute[labelP2 - 1]; attributeP[6] = attributeP[6] + 1; attributeP[9] = attributeP[9] + (int)Math.Sqrt((itemLine.startPoint.Y - itemLine.endPoint.Y) * (itemLine.startPoint.Y - itemLine.endPoint.Y) + (itemLine.startPoint.X - itemLine.endPoint.X) * (itemLine.startPoint.X - itemLine.endPoint.X)); labelP1 = labelP2; if (++countP > 1) break; } } //graphics.DrawLine(linePen, itemLine.startPoint, itemLine.endPoint); } //// 连通域质点 //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(); //Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC4); //Random rd = new Random(); //List colors = new List(nccomps); ////colors.Add(new Vec4b(0, 0, 0, 0)); //for (int i = 0; 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 (label > 0) // 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(); return true; } /// /// 用于枝干相交的坐标点集合 /// List massLabelPoints = new List(); /// /// 用于枝干末梢的坐标点集合 /// List sideLabelPoints = new List(); /// /// 用于枝干与轮廓截线长度为极小值的坐标点集合 key为点 value为距离值 /// Dictionary minLabelPoints = new Dictionary(); /// /// 用于枝干与轮廓截线长度为极小值的坐标点集合 key为点 value为线的坐标 /// Dictionary minLinePoints = new Dictionary(); /// /// 寻找极小值的坐标点集合,用来记录已经走过的点,避免路径重复 /// List routePoints = new List(); /// /// 手动分割 /// protected void menuSegmentAction(Button sender) { addPoint = !addPoint; sender.Text = addPoint ? PdnResources.GetString("Menu.segmented.text") : PdnResources.GetString("Menu.Manualsegmentation.text"); } /// /// 将多颜色图像转换为单颜色图像,避免抽骨架算不出结果 /// /// /// private Mat getBinaryOneColorPicture(PhaseModel phaseModel) { if (phaseModel.mat == null) return null; Mat phaseModelMat = phaseModel.mat.Clone(); Mat multipleMat = new Mat(phaseModelMat.Height/*Width*/, phaseModelMat.Width/*Height*/, MatType.CV_8UC4, new Scalar(0, 0, 0, 0)); for (int int_Y = 0; int_Y < phaseModelMat.Height; int_Y++) { for (int int_X = 0; int_X < phaseModelMat.Width; int_X++) { if (phaseModelMat.At(int_Y, int_X).Item3 > 0) multipleMat.Set(int_Y, int_X, new Vec4b(0, 255, 0, 255)); } } phaseModelMat.Dispose(); phaseModelMat = null; return multipleMat; } ProgressThreadProcClass procClass; private int thresholdValue; /// /// 自动分割 /// /// 阈值(μm) protected void autoSegmentAction(int thresholdValue) { if (this.matOrg == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); return; } if (this.documentWorkspace.PhaseModels.Count > 0 && this.documentWorkspace.PhaseModels[0].choise == true && this.documentWorkspace.PhaseModels[0].mat != null) { //PhaseModel phasesCopy = new PhaseModel(); //phasesCopy.mat = this.getBinaryOneColorPicture(this.documentWorkspace.PhaseModels[0]);// this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//################# ////phasesCopy.mat = this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//################# //phasesCopy.color = Color.Green/*panel2.BackColor*/.ToArgb(); //action912.PerformProcess(phasesCopy, 1).CopyTo(matGeology); ////灰度图 //Mat Inmat = this.documentWorkspace.PhaseModels[0].mat.CvtColor(ColorConversionCodes.BGR2GRAY); ////Cv2.ImShow("Inmat", Inmat); //Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise); ////Cv2.ImShow("distance_temp", distance_temp); //binary_temp = this.documentWorkspace.PhaseModels[0].mat.Clone(); } else { MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text")); return; } this.thresholdValue = thresholdValue; procClass = new ProgressThreadProcClass(); procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyAutoSegAction), "自动分割"); if (segmentedHolesMat != null) { segmentedHolesMat.Dispose(); segmentedHolesMat = null; } if (segmentedHolesMat == null && createSegmentedHoldsMat() || segmentedHolesMat != null) { } else //图像分割 this.documentWorkspace.Refresh(); } private void applyAutoSegAction() { //int matValue = 10;// (int)(thresholdValue / this.physical_length); Action912 action912 = new Action912(); if (matGeology != null) matGeology.Dispose(); matGeology = new Mat(); Mat distance_temp = new Mat(); Mat binary_temp = null; if (this.documentWorkspace.PhaseModels.Count > 0 && this.documentWorkspace.PhaseModels[0].choise == true && this.documentWorkspace.PhaseModels[0].mat != null) { PhaseModel phasesCopy = new PhaseModel(); phasesCopy.mat = this.getBinaryOneColorPicture(this.documentWorkspace.PhaseModels[0]);// this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//################# //phasesCopy.mat = this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//################# phasesCopy.color = Color.Green/*panel2.BackColor*/.ToArgb(); action912.PerformProcess(phasesCopy, 1).CopyTo(matGeology); //灰度图 Mat Inmat = BinaryClass.BGRA2GRAY(this.documentWorkspace.PhaseModels[0].mat)/* //### .CvtColor(ColorConversionCodes.BGR2GRAY)*/; //Cv2.ImShow("Inmat", Inmat); Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise); //Cv2.ImShow("distance_temp", distance_temp); binary_temp = this.documentWorkspace.PhaseModels[0].mat.Clone(); } else { MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text")); return; OpenCvSharp.Mat mat = action912.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap)); if (mat != null) { mat.CopyTo(matGeology); //灰度图 Mat Inmat = this.documentWorkspace.PhaseModels[0].mat.CvtColor(ColorConversionCodes.BGR2GRAY); Cv2.ImShow("Inmat", Inmat); Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise); } //Document doc = Document.FromMat(mat); //this.documentWorkspace.Document = doc; //this.documentWorkspace.Refresh(); } //标记所有相交和末梢的点 massLabelPoints.Clear(); sideLabelPoints.Clear(); for (int index_x = 1; index_x < matGeology.Width - 1; index_x++) { for (int index_y = 1; index_y < matGeology.Height - 1; index_y++) { int countSideLines = GetBoundryCountDOfBinary(new Point(index_x, index_y), matGeology); if (countSideLines > 2) massLabelPoints.Add(new Point2d(index_x, index_y)); else if (countSideLines == 1) sideLabelPoints.Add(new Point2d(index_x, index_y)); } } //从末梢的点开始寻找截线的极小值点 routePoints.Clear(); minLabelPoints.Clear(); foreach (Point2d pointSide in sideLabelPoints) { Dictionary minPoint = GetMinLabelPoint(thresholdValue * thresholdValue, new Point((int)pointSide.X, (int)pointSide.Y), matGeology, distance_temp, new Dictionary(), float.MinValue, float.MinValue); if (minPoint != null && minPoint.Count > 0) foreach (var item in minPoint) minLabelPoints.Add(item.Key, item.Value); } foreach (Point2d pointSide in massLabelPoints) { Dictionary minPoint = GetMinLabelPoint(thresholdValue * thresholdValue, new Point((int)pointSide.X, (int)pointSide.Y), matGeology, distance_temp, new Dictionary(), float.MinValue, float.MinValue); if (minPoint != null && minPoint.Count > 0) foreach (var item in minPoint) minLabelPoints.Add(item.Key, item.Value); } //根据极小值点获取截线 minLinePoints.Clear(); if (minLabelPoints.Count > 0 && binary_temp != null) { foreach (var item in minLabelPoints.Keys) { int radius = (int)(Math.Sqrt(minLabelPoints[new Point2d((int)item.X, (int)item.Y)]) + 1); Point line1Point = GetMinRadiusPoint(new Point((int)item.X, (int)item.Y), radius, matGeology, binary_temp); if (line1Point.X > 0 && line1Point.Y > 0) { Point line2Point = GetMinAnotherPoint(thresholdValue * thresholdValue, new Point((int)item.X, (int)item.Y), line1Point, radius, binary_temp); if (line2Point.X > 0 && line2Point.Y > 0) { Line lineI = new Line(line1Point, line2Point/*new Point((int)item.X, (int)item.Y)*/); if ((lineI.startPoint.X - lineI.endPoint.X) * (lineI.startPoint.X - lineI.endPoint.X) + (lineI.startPoint.Y - lineI.endPoint.Y) * (lineI.startPoint.Y - lineI.endPoint.Y) <= thresholdValue * thresholdValue / (this.physical_length * this.physical_length)) minLinePoints.Add(new Point2d((int)item.X, (int)item.Y), lineI); } else { Line lineI = GetMinLinePoint(thresholdValue * thresholdValue, new Point((int)item.X, (int)item.Y), radius, binary_temp); if (lineI != null && (lineI.startPoint.X - lineI.endPoint.X) * (lineI.startPoint.X - lineI.endPoint.X) + (lineI.startPoint.Y - lineI.endPoint.Y) * (lineI.startPoint.Y - lineI.endPoint.Y) <= thresholdValue * thresholdValue / (this.physical_length * this.physical_length)) { minLinePoints.Add(new Point2d((int)item.X, (int)item.Y), lineI); } } } } } //for (int lineIndex = minLinePoints.Count - 1; lineIndex >= 0; lineIndex--) //{ // Line lineI = minLinePoints.Values[lineIndex]; // if ((lineI.startPoint.X - lineI.endPoint.X) * (lineI.startPoint.X - lineI.endPoint.X) + (lineI.startPoint.Y - lineI.endPoint.Y) * (lineI.startPoint.Y - lineI.endPoint.Y) // <= thresholdValue * thresholdValue / (this.physical_length * this.physical_length)) // { // } //} if (procClass != null) procClass.DismissProgressAction(this); } #endregion /// /// 根据圆心得到截线与轮廓的截线 /// /// 阈值的平方 /// 圆心 /// 半径 /// 二值提取的mat /// private Line GetMinLinePoint(int threshold_2, Point center, int radius, Mat binary_temp) { Line line = null;// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue)); int matW = binary_temp.Width; int matH = binary_temp.Height; int luntimes = radius * 10; int step = -1; int length_2 = 0; Point startPoint = new Point(center.X, center.Y); Point endPoint = new Point(center.X, center.Y); for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15) { startPoint = new Point(center.X, center.Y); step = -1; for (int i = 1; i < luntimes; i++) { startPoint.X += step; Point itemP = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, startPoint.X, startPoint.Y, center.X, center.Y); if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW) continue; Vec4b vec4B = binary_temp.At(itemP.Y, itemP.X); if (vec4B.Item3 == 0) { startPoint.X = itemP.X; startPoint.Y = itemP.Y; break; } } endPoint = new Point(center.X, center.Y); step = 1; for (int i = 1; i < luntimes; i++) { endPoint.X += step; Point itemP = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, endPoint.X, endPoint.Y, center.X, center.Y); if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW) continue; Vec4b vec4B = binary_temp.At(itemP.Y, itemP.X); if (vec4B.Item3 == 0) { endPoint.X = itemP.X; endPoint.Y = itemP.Y; break; } } if (line == null || ((startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) + (startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y)) < length_2) { line = new Line(new Point(startPoint.X, startPoint.Y), new Point(endPoint.X, endPoint.Y)); length_2 = (line.startPoint.X - line.endPoint.X) * (line.startPoint.X - line.endPoint.X) + (line.startPoint.Y - line.endPoint.Y) * (line.startPoint.Y - line.endPoint.Y); } } if (radius > 1 && length_2 > radius * radius * 50 && length_2 < 10) { return null; } return line; } /// /// 根据圆心和其中一个交点得到截线与轮廓的另一个交点 /// /// 阈值的平方 /// 圆心 /// 其中一个交点 /// 半径 /// 二值提取的mat /// private Point GetMinAnotherPoint(int threshold_2, Point center, Point startP, int radius, Mat binary_temp) { Point line1Point = new Point(-1, -1); bool rotateFromY = true; Point startRotateFormerPoint = new Point(startP.X, startP.Y); if (Math.Abs(center.X - startP.X) > Math.Abs(center.Y - startP.Y)) { startRotateFormerPoint.Y = center.Y; rotateFromY = false; } else { startRotateFormerPoint.X = center.X; rotateFromY = true; } int length = rotateFromY ? (center.Y - startP.Y) : (center.X - startP.X); if (length == 0) return line1Point; int count = Math.Abs(length); int step = length / count; int length_2 = 0; int matW = binary_temp.Width; int matH = binary_temp.Height; double rotateAngle = AngleText(new PointF(center.X, center.Y), new PointF(startRotateFormerPoint.X, startRotateFormerPoint.Y), new PointF(startP.X, startP.Y)); Point endRotateFormerPoint = new Point(center.X, center.Y); int luntimes; if (count < 3) { luntimes = 4; } else { luntimes = count * 3; } if (rotateFromY) { for (int i = 1; i < luntimes; i++) { endRotateFormerPoint.Y += step; Point itemP = rotatedVPaiPoint(rotateAngle, endRotateFormerPoint.X, endRotateFormerPoint.Y, center.X, center.Y); if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW) continue; Vec4b vec4B = binary_temp.At(itemP.Y, itemP.X); if (vec4B.Item3 == 0) { length_2 = (itemP.X - startP.X) * (itemP.X - startP.X) + (itemP.Y - startP.Y) * (itemP.Y - startP.Y); if (length_2 > 9) { line1Point = new Point(itemP.X, itemP.Y); } break; } } } else { for (int i = 1; i < luntimes; i++) { endRotateFormerPoint.X += step; Point itemP = rotatedVPaiPoint(rotateAngle, endRotateFormerPoint.X, endRotateFormerPoint.Y, center.X, center.Y); if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW) continue; Vec4b vec4B = binary_temp.At(itemP.Y, itemP.X); if (vec4B.Item3 == 0) { length_2 = (itemP.X - startP.X) * (itemP.X - startP.X) + (itemP.Y - startP.Y) * (itemP.Y - startP.Y); if (length_2 > 9) { line1Point = new Point(itemP.X, itemP.Y); } break; } } } return line1Point; } /// /// 根据圆心和半径得到截线与其中一端轮廓的交点 /// /// 圆心 /// 半径 /// 抽骨架的mat /// 二值提取的mat /// private Point GetMinRadiusPoint(Point center, int radius, Mat mat, Mat binary_temp) { Point line1Point = new Point(-1, -1);// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue)); // 圆上的点集合 Point[] points1 = roundOutline(center, radius); int matW = binary_temp.Width; int matH = binary_temp.Height; foreach (var itemP in points1) { if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW) continue; Vec4b vec4B = binary_temp.At(itemP.Y, itemP.X); if (vec4B.Item3 == 0) { line1Point = new Point(itemP.X, itemP.Y); break; } } //for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15) //{ // Point startPoint = new Point(-1, -1); // while (startPoint.X < -10) // { // } // for (int length = 0; length < 100; length++) // { // } //} return line1Point; } /// /// 根据圆心和半径得到截线与其中一端轮廓的交点 /// /// 圆心 /// 半径 /// 抽骨架的mat /// 二值提取的mat /// private Line GetMinRadiusLine(Point point, int radius, Mat mat, Mat binary_temp) { Line line = null;// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue)); for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15) { Point startPoint = new Point(-1, -1); while (startPoint.X < -10) { } for (int length = 0; length < 100; length++) { } } return line; } /// /// /// /// /// 抽骨架的mat /// 二值提取的mat /// private Line GetMinLabelLine(Point point, Mat mat, Mat binary_temp) { Line line = null;// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue)); for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15) { Point startPoint = new Point(-1, -1); while (startPoint.X < 0) { } for (int length = 0; length < 100; length++) { } } return line; } /// /// 三点角计算 /// /// /// /// /// public double AngleText(PointF cen, PointF first, PointF second) { double ma_x = first.X - cen.X; double ma_y = first.Y - cen.Y; double mb_x = second.X - cen.X; double mb_y = second.Y - cen.Y; double v1 = (ma_x * mb_x) + (ma_y * mb_y); double ma_val = Math.Sqrt(ma_x * ma_x + ma_y * ma_y); double mb_val = Math.Sqrt(mb_x * mb_x + mb_y * mb_y); double cosM = v1 / (ma_val * mb_val); double angleAMB = Math.Acos(cosM);// * 180 / M_PI; return angleAMB; } /// /// 获取旋转后的坐标点 /// /// 旋转角度 /// 旋转前的X坐标 /// 旋转前的Y坐标 /// 旋转中心点X坐标 /// 旋转中心点Y坐标 /// private Point rotatedVPaiPoint(double rotatedVPai, float point_X, float point_Y, float centerX, float centerY) { //double rotatedVPai = rotateAngleV * Math.PI / 180.0; double disX = point_X - centerX; double disY = point_Y - centerY; double outX = disX * Math.Cos(rotatedVPai) - disY * Math.Sin(rotatedVPai); double outY = disX * Math.Sin(rotatedVPai) + disY * Math.Cos(rotatedVPai); return new Point((int)(outX + centerX), (int)(outY + centerY)); //return new PointF((float)outX + centerX, (float)outY + centerY); } /// /// 获取旋转后的坐标点 /// /// 旋转角度 /// 旋转前的X坐标 /// 旋转前的Y坐标 /// 旋转中心点X坐标 /// 旋转中心点Y坐标 /// private PointF rotatedPoint(int rotateAngleV, float point_X, float point_Y, float centerX, float centerY) { double rotatedVPai = rotateAngleV * Math.PI / 180.0; double disX = point_X - centerX; double disY = point_Y - centerY; double outX = disX * Math.Cos(rotatedVPai) - disY * Math.Sin(rotatedVPai); double outY = disX * Math.Sin(rotatedVPai) + disY * Math.Cos(rotatedVPai); return new PointF((float)outX + centerX, (float)outY + centerY); } #region 需继承方法 protected virtual void drawSubclass(Graphics graphics) { if (showOrimat()) return; ////if (matGeology != null && matGeology.Width > 0 && matGeology.Height > 0) ////{ //// graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(matGeology), 0, 0); ////} //if (sideLabelPoints.Count > 0 && false) //{ // Pen pointsPen = new Pen(Color.Yellow, 2); // foreach (var item in sideLabelPoints) // { // graphics.DrawEllipse(pointsPen, new RectangleF((float)item.X - 1, (float)item.Y - 1, 3, 3)); // } //} ////if (minLabelPoints.Count > 0) ////{ //// Pen pointsPen = new Pen(Color.Yellow, 1); //// foreach (var item in minLabelPoints.Keys) //// { //// graphics.DrawEllipse(pointsPen, new RectangleF((float)item.X, (float)item.Y, 1, 1)); //// } ////} if (addPoint && m_StartPoint.X > 0 && m_StartPoint.Y > 0 && m_EndPoint.X > 0 && m_EndPoint.Y > 0) { Pen pointsPen = new Pen(Color.Blue, 1); graphics.DrawLine(pointsPen, new Point((int)m_StartPoint.X, (int)m_StartPoint.Y), new Point((int)m_EndPoint.X, (int)m_EndPoint.Y)); } if (minLinePoints.Count > 0/* && !holeNumberVisible*/) { Pen pointsPen = new Pen(Color.Blue, 1); foreach (var item in minLinePoints.Values) { graphics.DrawLine(pointsPen, item.startPoint, item.endPoint); } } //if (lstAttribute.Count > 0 && holeNumberVisible) //{ // Font myFont = new Font("宋体", 8/*, FontStyle.Bold*/); // Brush bush = new SolidBrush(/*this.panel1.BackColor*/Color.Black);//填充的颜色 // foreach (var attribute in lstAttribute) // { // if (attribute[7] == 27) // { // graphics.DrawString(/*attribute[0] + */"" + attribute[7], myFont, new SolidBrush(/*this.panel1.BackColor*/Color.Green), (float)attribute[1] - 3, (float)attribute[2] - 3); // } // else // graphics.DrawString(/*attribute[0] + */"" + attribute[7], myFont, bush, (float)attribute[1] - 3, (float)attribute[2] - 3); // } //} //if (massLabelPoints.Count > 0 && false) //{ // //int index = 0; // Pen pointsPen = new Pen(Color.Yellow, 2); // //Font myFont = new Font("宋体", 12/*, FontStyle.Bold*/); // //Brush bush = new SolidBrush(this.panel1.BackColor/*Color.Red*/);//填充的颜色 // foreach (var item in massLabelPoints) // { // graphics.DrawEllipse(pointsPen, new RectangleF((float)item.X - 1, (float)item.Y - 1, 3, 3)); // //graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5); // } //} } /// /// 图片索引改变后调用的事件 /// protected virtual void refreshWhileImgChanged() { } protected virtual void refreshPhaseModelChoise() { } /// /// 获取孔隙直径计算类型 1长径 2短径 3平均径 4等效圆直径 5φ值 /// /// protected virtual int getHolesType() { return 4; } /// /// 获取孔隙直径 /// /// /// protected double getHolesD(List attribute) { int holesType = getHolesType(); switch (holesType) { case 1: return Math.Sqrt(attribute[10] * this.physical_length * this.physical_length); break; case 2: return Math.Sqrt(attribute[11] * this.physical_length * this.physical_length); break; case 3: return Math.Sqrt(attribute[12] * this.physical_length * this.physical_length); break; case 4: return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2; break; case 5: return 0.3815 + 0.9027 * Math.Sqrt(attribute[10] * this.physical_length * this.physical_length); //{ // double longD = Math.Sqrt(attribute[10] * this.physical_length * this.physical_length); // return 0.3815 + 0.9027 * Math.Sqrt(attribute[10] * this.physical_length * this.physical_length); //} //return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2; break; default: return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2; } //return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2; } /// /// 获取视孔隙比表面 /// /// /// private double getHolesS0(List attribute) { return 4 * attribute[8] / (attribute[5] * this.physical_length * Math.PI); } /// /// 获取形状因子 /// /// /// private double getHolesF(List attribute) { return Math.Min(1.0, 4 * Math.PI * (attribute[5] - 0) / (attribute[8] * attribute[8])); } /// /// 获取孔喉比 /// /// /// private string getHolesRpt(List attribute) { return attribute[9] == 0 ? "无" : "" + Math.Sqrt(attribute[5] / Math.PI) * 2 * attribute[6] / attribute[9]; } /// /// 获取孔喉比 /// /// /// private double getHolesRptValue(List attribute) { return attribute[9] == 0 ? 0 : Math.Sqrt(attribute[5] / Math.PI) * 2 * attribute[6] / attribute[9]; } /// /// 保存结果 /// protected virtual void buildListBox_analysisResult() { if (this.matOrg == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); return; } if (lstAttribute.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text")); return; } string imgName = getCurrentWorkspace().GetFriendlyName(); string tag = getCurrentWorkTag(); DataTable 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.dataGridView2.Rows.Clear(); //this.dataTables.Clear(); for (int dataTableI = dataTables.Count - 1; dataTableI >= 0; dataTableI--) { System.Data.DataTable dataTable1 = dataTables[dataTableI]; if (dataTable1.TableName.Equals(tag)) dataTables.RemoveAt(dataTableI); } if (lstAttriDict.ContainsKey(tag)) lstAttriDict.Remove(tag); List> attriValues = new List>(); List listValues; //添加视域的面积信息 listValues = new List(); listValues.Add(this.bitmap.Width * this.bitmap.Height); //foreach (var itemInt in attribute) // listValues.Add(itemInt); attriValues.Add(listValues); DataGridViewRow dgvr;// = new DataGridViewRow(); //attribute = new List(); //attribute.Add(hcomp); //attribute.Add(x); //attribute.Add(y); //attribute.Add(width); //attribute.Add(height); //attribute.Add(areaField1); //attribute.Add(0);//喉道数量 //attribute.Add(hcomp);//编号 //attribute.Add(0);//孔隙周边长,单位是像素 //attribute.Add(0);//与该空腔连通的喉道总宽度,单位是像素 //lstAttribute.Add(attribute); string value0 = imgName; string value1 = PdnResources.GetString("Menu.view.text")+"0";//视场 //string value2;// = firRow.Cells[1].Value;//编号 //int value3;// = firRow.Cells[2].Value;//孔隙直径 //视孔隙比表面 //形状因子 //孔喉比 //配位数 foreach (var attribute in lstAttribute) { //if (attribute[5] < 5) // continue; listValues = new List(); foreach (var itemInt in attribute) listValues.Add(itemInt); attriValues.Add(listValues); dgvr = new DataGridViewRow(); dgvr.Tag = tag; foreach (DataGridViewColumn c in this.dataGridView2.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[0].Value = value0; dgvr.Cells[1].Value = value1; dgvr.Cells[2].Value = attribute[7];//编号 dgvr.Cells[3].Value = this.getHolesD(attribute);//孔隙直径 dgvr.Cells[4].Value = this.getHolesS0(attribute);//视孔隙比表面(<--4/* * this.physical_length*/ * attribute[8] / (attribute[5]/* * this.physical_length*/ * this.physical_length * Math.PI);) dgvr.Cells[5].Value = this.getHolesF(attribute);//形状因子 dgvr.Cells[6].Value = this.getHolesRpt(attribute);//孔喉比(<--Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2 / (attribute[9] * this.physical_length / attribute[6])) dgvr.Cells[7].Value = attribute[6];//配位数 this.dataGridView2.Rows.Add(dgvr); dataTable = new DataTable(); dataTable.TableName = tag; for (int i = 0; i < this.dataGridView2.Columns.Count; i++) { dataTable.Columns.Add("" + i); } DataRow dataRow = dataTable.NewRow(); dataRow["0"] = value0; dataRow["1"] = dgvr.Cells[1].Value; dataRow["2"] = dgvr.Cells[2].Value; dataRow["3"] = dgvr.Cells[3].Value; dataRow["4"] = dgvr.Cells[4].Value; dataRow["5"] = dgvr.Cells[5].Value; dataRow["6"] = dgvr.Cells[6].Value; dataRow["7"] = dgvr.Cells[7].Value; dataTable.Rows.Add(dataRow); this.dataTables.Add(dataTable); } lstAttriDict.Add(tag, attriValues); //if (this.allShow) // AllShow(); this.RefreshDataGridView4(); //保存处理后的图片 double pantographRatio = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数 List tempBit = new List(); Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); originalBit.Tag = pantographRatio; tempBit.Add(originalBit); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); if (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); } Draw(graphics); newBit.Tag = pantographRatio; tempBit.Add(newBit); if (bitDic.ContainsKey(tag)) bitDic[tag] = tempBit; else bitDic.Add(tag, tempBit); //中间数据-拼接中间数据 List> dataList = new List>(); //string value0 = imgName;//图片 //string value1 = "视场0";//视场 ////string value2;// = firRow.Cells[1].Value;//编号 ////int value3;// = firRow.Cells[2].Value;//孔隙直径 ////视孔隙比表面 ////形状因子 ////孔喉比 ////配位数 List columnName = new List(); columnName.Add(PdnResources.GetString("Menu.picture.Text")); columnName.Add(PdnResources.GetString("Menu.view.text")); columnName.Add(PdnResources.GetString("Menu.Dedicatedanalysis.Non-ferrousmetals.serialnumber.text")); columnName.Add(PdnResources.GetString("Menu.Theporediameter.text")); columnName.Add(PdnResources.GetString("Menu.Apparentporeratiosurface.text")); columnName.Add(PdnResources.GetString("Menu.Shapefactor.text")); columnName.Add(PdnResources.GetString("Menu.Porethroatthan.text")); columnName.Add(PdnResources.GetString("Menu.Coordinationnumber.text")); dataList.Add(columnName); foreach (DataGridViewRow Row in this.dataGridView2/*dataGridView1*/.Rows) { List strList = new List(); strList.Add(Row.Cells[0].Value.ToString()); strList.Add(Row.Cells[1].Value.ToString()); strList.Add(Row.Cells[2].Value.ToString()); strList.Add(Row.Cells[3].Value.ToString()); strList.Add(Row.Cells[4].Value.ToString()); strList.Add(Row.Cells[5].Value.ToString()); strList.Add(Row.Cells[6].Value.ToString()); strList.Add(Row.Cells[7].Value.ToString()); dataList.Add(strList); } bool isExist = false;//是否已存在进行替换 int modelIndex = -1;//要替换的下标 for (int j = 0; j < tempDataModel.Count; j++) { if (tempDataModel[j].tagName.Equals(tag)) { isExist = true; modelIndex = j; break; } } if (isExist && modelIndex > -1) tempDataModel[modelIndex].dataList = dataList; else { Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel(); newModel.tagName = tag; newModel.picName = imgName; newModel.dataList = dataList; tempDataModel.Add(newModel); } } //this.listBox_analysisResult.Items.Clear(); ////foreach (var item in analysisResults.Keys) ////{ //// this.listBox_analysisResult.Items.Add(new LocalListViewItem(item, item.GetFriendlyName())); ////} ////buildListView_analysisResult(); } protected virtual void SubclassInitialize() { throw new NotImplementedException(); } /// /// 报告模板命名 /// /// protected virtual string getTemplateName() { throw new NotImplementedException(); } /// /// 项目工程内的文件夹路径名称 /// /// protected virtual string getProjectEngineeringName() { throw new NotImplementedException(); } protected virtual void getScriptRecording() { } #endregion #region 内部类 private int GetBoundryCountDOfBinary(Point point, Mat mat) { int count = 0; if (point.X > mat.Width - 2 || point.X < 1 || point.Y > mat.Height - 2 || point.Y < 1) { return count; } bool firstValueOnBoundry = false; bool lastValueOnBoundry = false; Vec4b vec4B = mat.At(point.Y, point.X); if (vec4B.Item3 == 0) return -1; vec4B = mat.At(point.Y - 1, point.X - 1); if (vec4B.Item3 != 0) { count++; firstValueOnBoundry = true; lastValueOnBoundry = true; } vec4B = mat.At(point.Y - 1, point.X); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y - 1, point.X + 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y, point.X + 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X + 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y + 1, point.X - 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry) count++; lastValueOnBoundry = true; } else lastValueOnBoundry = false; vec4B = mat.At(point.Y, point.X - 1); if (vec4B.Item3 != 0) { if (!lastValueOnBoundry && !firstValueOnBoundry) count++; } return count; } 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; } } internal class Line { /// /// 直线的起点 /// public System.Drawing.Point startPoint; /// /// 直线的终点 /// public System.Drawing.Point endPoint; /// /// 构造方法 /// /// /// public Line(System.Drawing.Point s, System.Drawing.Point e) { this.startPoint = s; this.endPoint = e; } } #endregion /// /// 使用圆心及半径得到圆的轮廓 /// /// 圆心 /// 半径 /// public 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); if (contours.Length > 0) { OpenCvSharp.Point[] roundOutline = contours[0]; Point[] roundOutPoints = new Point[roundOutline.Length]; for (int i = 0; i < roundOutline.Length; i++) { roundOutPoints[i].X = roundOutline[i].X - point.X + center.X; roundOutPoints[i].Y = roundOutline[i].Y - point.Y + center.Y; } return roundOutPoints; } return new Point[0]; } 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.dataGridView2.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.dataGridView2.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.dataGridView2.Rows.Add(dgvr); } this.RefreshDataGridView4(); } /// /// 添加显示并刷新dataGridView1的数据 /// /// protected void AddRowDataGridView1(List> tempsAttribute) { DataTable dataTable; this.dataGridView1.Rows.Clear(); DataGridViewRow dgvr = new DataGridViewRow(); //获取视域面积 List areaInt = tempsAttribute[0]; //attribute = new List(); //attribute.Add(hcomp); //attribute.Add(x); //attribute.Add(y); //attribute.Add(width); //attribute.Add(height); //attribute.Add(areaField1); //attribute.Add(0);//喉道数量 //attribute.Add(hcomp);//编号 //attribute.Add(0);//孔隙周边长,单位是像素 //attribute.Add(0);//与该空腔连通的喉道总宽度,单位是像素 //lstAttribute.Add(attribute); double value0 = 0;//面孔率(第i个孔隙的面积) double value1_0 = 0;//第i个孔隙直径 double value1 = 0;//平均孔隙直径 double value2 = 0;//平均视孔隙比表面 double value3 = 0;//平均孔隙形状因子 double value4 = 0;//平均孔喉比 double value5 = 0;//均质系数(最大孔隙直径) double value6 = 0;//孔隙直径分选系数 double value7 = 0;//平均孔隙配位数 for (int attributeI = 1; attributeI < lstAttribute.Count; attributeI++) { var attribute = lstAttribute[attributeI]; //if (attribute[5] < 5) // continue; value0 += attribute[5]; value1_0 = this.getHolesD(attribute); value1 += value1_0 * attribute[5] * 100.0 / areaInt[0]; value2 += this.getHolesS0(attribute); value3 += this.getHolesF(attribute); value4 += this.getHolesRptValue(attribute); if (value1_0 > value5) value5 = value1_0; value7 += attribute[6]; } dgvr.Tag = "tag";//<--tag foreach (DataGridViewColumn c in this.dataGridView1.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } double outValue; //面孔率 value0 = value0 * 100.0 / areaInt[0]; if (double.TryParse(string.IsNullOrEmpty(value0.ToString()) ? "0" : value0.ToString(), out outValue)) { dgvr.Cells[0].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[0].Value = value0.ToString(); //平均孔隙直径 value1 = value1 / 100.0;// areaInt[0]/*(lstAttribute.Count - 1)*/; if (double.TryParse(string.IsNullOrEmpty(value1.ToString()) ? "0" : value1.ToString(), out outValue)) { dgvr.Cells[1].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[1].Value = value1.ToString(); //平均视孔隙比表面 value2 = value2 / (lstAttribute.Count - 1); if (double.TryParse(string.IsNullOrEmpty(value2.ToString()) ? "0" : value2.ToString(), out outValue)) { dgvr.Cells[2].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[2].Value = value2.ToString(); //平均孔隙形状因子 value3 = 4 * Math.PI * value3 / (lstAttribute.Count - 1); if (double.TryParse(string.IsNullOrEmpty(value3.ToString()) ? "0" : value3.ToString(), out outValue)) { dgvr.Cells[3].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[3].Value = value3.ToString(); //平均孔喉比 value4 = value4 / (lstAttribute.Count - 1); if (double.TryParse(string.IsNullOrEmpty(value4.ToString()) ? "0" : value4.ToString(), out outValue)) { dgvr.Cells[4].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[4].Value = value4.ToString(); //均质系数 value5 = value1 / value5; if (double.TryParse(string.IsNullOrEmpty(value5.ToString()) ? "0" : value5.ToString(), out outValue)) { dgvr.Cells[5].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[5].Value = value5.ToString(); //孔隙直径分选系数 value6 = 0; for (int attributeI = 1; attributeI < lstAttribute.Count; attributeI++) { var attribute = lstAttribute[attributeI]; ////if (attribute[5] < 5) //// continue; //value0 += attribute[5]; value1_0 = this.getHolesD(attribute) - value1; value1_0 = value1_0 * value1_0 * attribute[5] * 100.0 / areaInt[0]; value6 += value1_0; } value6 = Math.Sqrt(value6 / 100.0); if (double.TryParse(string.IsNullOrEmpty(value6.ToString()) ? "0" : value6.ToString(), out outValue)) { dgvr.Cells[6].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[6].Value = value6.ToString(); //平均孔隙配位数 value7 = value7 * 1.0 / (lstAttribute.Count - 1); if (double.TryParse(string.IsNullOrEmpty(value7.ToString()) ? "0" : value7.ToString(), out outValue)) { dgvr.Cells[7].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[7].Value = value7.ToString(); this.dataGridView1.Rows.Add(dgvr); //DataGridViewRow dgvr = new DataGridViewRow(); //foreach (DataGridViewColumn Column in this.dataGridView2.Columns) //{ // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); //} //for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++) //{ // //if (c == 2 || c == 3) // // 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 // if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7) // { // double outValue; // if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" : // this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue)) // { // dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; // } // else // dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); // } // else // dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); //} //this.dataGridView2.Rows.Add(dgvr); } /// /// 刷新分析结果数据 /// protected void RefreshDataGridView4()//#### { if (!this.allShow) { if (this.listView2.SelectedItems.Count > 0) { this.dataGridView1.Rows.Clear(); this.dataGridView2.Rows.Clear(); for (int j = 0; j < this.listView2.SelectedItems.Count; j++) { int dataTableIndex = 0; if (lstAttriDict.ContainsKey(this.listView2.SelectedItems[j].Tag.ToString())) this.AddRowDataGridView1(lstAttriDict[this.listView2.SelectedItems[j].Tag.ToString()]); 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.Count > dataTableIndex && 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.dataGridView2.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++) { //if (c == 2 || c == 3) // 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 if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7) { double outValue; if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" : this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue)) { dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); } else dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); } this.dataGridView2.Rows.Add(dgvr); } } } } } } else if (this.listView2.Items.Count > 0) { this.dataGridView1.Rows.Clear(); this.dataGridView2.Rows.Clear(); var firstTag = this.listView2.Items[0].Tag; if (lstAttriDict.ContainsKey(this.listView2.Items[0].Tag.ToString())) this.AddRowDataGridView1(lstAttriDict[this.listView2.Items[0].Tag.ToString()]); 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.dataGridView2.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++) { //if (c == 2 || c == 3) // 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 if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7) { double outValue; if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" : this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue)) { dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); } else dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString(); } this.dataGridView2.Rows.Add(dgvr); } } } } } } else { this.dataGridView1.Rows.Clear(); this.dataGridView2.Rows.Clear(); foreach (var itemlist in lstAttriDict.Values) { this.AddRowDataGridView1(itemlist); } //if (lstAttriDict.ContainsKey(this.listView2.Items[0].Tag.ToString())) // this.AddRowDataGridView1(lstAttriDict[this.listView2.Items[0].Tag.ToString()]); 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.dataGridView2.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < dataTable.Columns.Count; c++) { //if (c == 2 || c == 3) // 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 if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7) { double outValue; if (double.TryParse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" : dataTable.Rows[r][c].ToString(), out outValue)) { dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + ""; } else dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString(); } else dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString(); } this.dataGridView2.Rows.Add(dgvr); } } } } /// /// 切换分析结果 /// /// /// private void listview2_SelectedIndexChanged(object sender, EventArgs e) { if (!this.allShow) { if (this.listView2.SelectedItems.Count <= 0) return; this.dataGridView1.Rows.Clear(); this.dataGridView2.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 (lstAttriDict.ContainsKey(this.listView2.SelectedItems[i].Tag.ToString())) this.AddRowDataGridView1(lstAttriDict[this.listView2.SelectedItems[i].Tag.ToString()]); if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName)) dataTable1 = dataTable; } DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView2.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.dataGridView2.Rows.Add(dgvr); } this.RefreshDataGridView4(); } } /// /// 全部显示 /// /// /// 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.dataGridView1.Rows.Clear(); this.dataGridView2.Rows.Clear(); foreach (var itemlist in lstAttriDict.Values) { this.AddRowDataGridView1(itemlist); } for (int i = 0; i < this.dataTables.Count; i++) { DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView2.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.dataGridView2.Rows.Add(dgvr); } this.RefreshDataGridView4(); } else { MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!"); } } 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; } } 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.dataGridView1.Rows.Clear(); this.dataGridView2.Rows.Clear(); } else RefreshDataGridView4(); } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!"); } } else { MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!"); } } private void numericUpDown1_0_ValueChanged(object sender, EventArgs e) { this.RefreshDataGridView4(); } /// /// 生成报告 /// /// /// private void button_generateReport_Click(object sender, EventArgs e) { if (this.listView2.Items.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Noresults.text")); return; } if (this.checkBox_generateReport_opensetting.Checked) this.button_setting.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.dataGridView2.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")+"!"); } } }