using OpenCvSharp; using PaintDotNet.Adjust; using PaintDotNet.Annotation; using PaintDotNet.Base.Functionodel; using PaintDotNet.CustomControl; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Windows.Forms; using Point = System.Drawing.Point; namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass { internal class GrainBoundaryEditingDialog : Form { public static string ParamKey_GrainApplygrainboundaries = "GrainApplygrainboundaries";//是否应用(计算晶界) public static string ParamKey_GrainM_iStandardImage = "GrainM_iStandardImage";//标准图像 this.radioButton1.Checked? 1 : 0; public static string ParamKey_GrainIConnect = "GrainIConnect";//强制连接 this.checkBox4.Checked? 1 : 0; public static string ParamKey_GrainSigma = "GrainSigma";//西格玛 如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数 double.TryParse(textBox6.Text, out sigma) public static string ParamKey_GrainDark = "GrainDark";//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 dark = this.comboBox2.SelectedIndex; public static string ParamKey_GrainSmooth_type = "GrainSmooth_type";//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 smooth_type = this.comboBox3.SelectedIndex; public static string ParamKey_GrainEnhance = "GrainDisplaysections";//是否增强晶界?不增强:enhance=0; 增强: enhance=1 enhance = this.checkBox2.Checked? 1 : 0 public static string ParamKey_GrainCell_size1 = "GrainCell_size1";//晶界大小 public static string ParamKey_GrainCell_size2 = "GrainCell_size2";//晶界大小 cell_size = new double[2] { (double) numericUpDown1.Value, (double) numericUpDown2.Value } /// /// 调色板 /// private ColorsForm colorsFormGrid; private Panel panelC; /// /// 公共按钮 /// private CommonControlButtons commonControlButtons; /// /// 主控件 /// private AppWorkspace appWorkspace; private DocumentWorkspaceWindow documentWorkspace; /// /// 存在视场标记 /// private bool existViewFlag = false; /// /// 选中图片的bitmap /// private Bitmap bitmap; /// /// 当前选择的图片 /// private Mat mat; /// /// 用于get处理后的图像 /// private Mat phaseMat; /// /// 用于get处理后的图像的颜色 /// private Color phaseColor; private int menuId; /// /// 是否显示视场 /// Boolean ShowDrawClassView = false; /// /// 起始点 /// private Point startPoint = new Point(-1, -1); /// /// 是否绘制了起始点 /// private bool drawedStartPoint = false; /// /// 结束点 /// private Point endPoint = new Point(-1, -1); //1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界) /// /// 辅助线集成 20720 【专用分析-晶粒度】4290-仲裁法,晶界重现后,在晶界编辑页面没有把网格带过去 /// private GrainSize.GuideSizeArLawClass guide2Class; /// /// 辅助线集成 /// private GrainSizeGuideClass guideClass; public object SelectedItem; /// /// 操作类型 /// 0,没有操作 1,折线添加 2,直线添加 /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除 /// private int pointKtype = 0; /// /// 折线点的集合 /// public List pointFloatArray = new List(); /// /// 外接矩形,或者是计算的矩形 /// protected RectangleF rectangle = new RectangleF(/*pointFloatArray 0, 1,,,, 2, 3*/); #region 实现撤销、恢复、重置的功能 /// /// 当前操作在OperationsList的位置,用于判断是否可以撤销、恢复、重置 /// private int OperationIndex = -1; /// /// 将 操作类型的集合放入一个List,通过OperationIndex读取当前操作位置 /// private List OperationKtypeList = new List(); /// /// 将 折线(/直线)点的集合(/外接矩形的xywh)放入一个List,通过OperationIndex读取当前操作位置 /// private List OperationsList = new List(); /// /// 保存晶界重现运算的结果 /// private Mat PhaseModel0MatCopy; #endregion private GroupBox groupBox1; private GroupBox groupBox2; private GroupBox groupBox3; private Button button2; private Button button1; private Button button3; private Button button4; private Button button8; private Button button7; private Button button6; private Button button5; private Button button9; private GroupBox groupBox4; private Panel panel1; private Label label8; private NumericUpDown numericUpDown2; private NumericUpDown numericUpDown1; private CheckBox checkBox2; private CheckBox checkBox3; private CheckBox checkBox4; private TextBox textBox6; private Label label7; private Label label9; private Label label17; private ComboBox comboBox3; private Label label6; private ComboBox comboBox2; private Label label1; private CheckBox checkBox1; private GroupBox groupBox7; private RadioButton radioButton2; private RadioButton radioButton1; private GroupBox itemsGroupBox; private Button undoButton; private Button redoButton; private Button resetButton; private Panel panel2; private RadioButton applyRadioButton2; private RadioButton applyRadioButton1; private Label applyLabel; private int focusedItemIndex; /// /// 返回当前选择的图片内容 /// /// private DocumentWorkspace getCurrentWorkspace() { return this.appWorkspace.DocumentWorkspaces[focusedItemIndex]; } public GrainSize.GuideSizeArLawClass Guide2Class { set { this.guide2Class = value; } } public GrainSizeGuideClass GuideClass { set { this.guideClass = value; } } /// /// PanelC的调色板颜色改变 /// /// /// private void gridColorChanged(object sender, EventArgs e) { Color color = this.colorsFormGrid.UserPrimaryColor.ToColor(); ////更改背景色,触发事件 //if (this.panelC != null) //{ // this.panelC.BackColor = color; // //this.ColorPanelChanged(this.panelC); // this.panelC = null; // //关闭色板 // this.colorsFormGrid.Close(); // this.PhaseColor = this.panel1.BackColor; // return; //} //更改背景色,触发事件 this.panel1.BackColor = color; this.documentWorkspace.PhaseModels[0].color = this.panel1.BackColor.ToArgb(); this.PhaseColor = this.panel1.BackColor; this.runDectForColor(); this.documentWorkspace.Refresh(); //关闭色板 this.colorsFormGrid.Close(); } private Mat dstBinary = null; private Vec4b dstVec4b; /// /// 颜色改变时改变相的颜色 /// private unsafe void runDectForColor() { if (dstBinary != null) { dstBinary.Dispose(); dstBinary = null; } if (this.documentWorkspace.PhaseModels[0].mat == null) return; dstVec4b = new Vec4b(this.PhaseColor.B, this.PhaseColor.G, this.PhaseColor.R, this.PhaseColor.A); dstBinary = this.documentWorkspace.PhaseModels[0].mat.Clone();// new Mat(this.documentWorkspace.PhaseModels[0].mat.Rows, this.documentWorkspace.PhaseModels[0].mat.Cols, MatType.CV_8UC1, new Scalar(0)); //如果是rgba this.documentWorkspace.PhaseModels[0].mat.ForEachAsVec4b(ForeachFunctionByteForWhole4B); this.documentWorkspace.PhaseModels[0].mat = dstBinary.Clone(); this.documentWorkspace.Refresh(); } /// /// 提取二值化的透明通道并赋值 /// /// /// private unsafe void ForeachFunctionByteForWhole4B(Vec4b* t, int* position) { if (t->Item3 > 0) dstBinary.Set(position[0], position[1], dstVec4b); } /// /// 添加参数改变的监听 /// /// /// private void GrainSizeStandardDialog_Load(object sender, EventArgs e) { this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged); this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged_1); this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged_1); this.comboBox3.Text = PdnResources.GetString("Menu.pdenoisingtype.Text"); this.comboBox3.SelectedIndex = 1; this.comboBox2.Text = PdnResources.GetString("Menu.electthegrainboundarytype.Text"); this.comboBox2.SelectedIndex = 1; } public GrainBoundaryEditingDialog(AppWorkspace appWorkspace, int menuId, int focusedItemIndex, Color phaseColor, Mat phaseMat, Boolean ShowDrawClassView = false) { this.menuId = menuId; this.ShowDrawClassView = ShowDrawClassView; this.focusedItemIndex = focusedItemIndex; this.appWorkspace = appWorkspace; this.Load += new System.EventHandler(this.GrainSizeStandardDialog_Load); this.colorsFormGrid = new ColorsForm(); this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen; this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged)); InitializeComponent(); InitializeLanguageText(); // //初始化图像控件 // this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace); this.documentWorkspace.Cursor = Cursors.Default; this.documentWorkspace.Dock = DockStyle.Fill; this.documentWorkspace.HookMouseEvents(); this.documentWorkspace.AuxiliaryLineEnabled = false; this.documentWorkspace.Visible = false; this.documentWorkspace.panel.MouseDown += OnMouseDown; this.documentWorkspace.panel.Paint += Panel_Paint; this.documentWorkspace.panel.MouseMove += onMouseMove; this.documentWorkspace.panel.MouseUp += onMouseUp; this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;//禁止视场移动 this.groupBox7.Controls.Add(documentWorkspace); // //初始化操作按钮 // this.commonControlButtons = new CommonControlButtons(); this.commonControlButtons.Dock = DockStyle.Top; this.commonControlButtons.Height = 30; this.commonControlButtons.HideZoomToWindowAndActualSize(); this.groupBox7.Controls.Add(commonControlButtons); { // //初始化相 // PhaseModel model = new PhaseModel(); model.choise = true; model.mat = null; model.color = phaseColor.ToArgb();// Color.Green/*panel2.BackColor*/.ToArgb(); model.position = this.documentWorkspace.PhaseModels.Count + 1; model.name = PdnResources.GetString("Menu.Grainboundarytoreproduce.text"); this.documentWorkspace.PhaseModels.Add(model); } if (phaseMat != null) { this.documentWorkspace.PhaseModels[0].mat = phaseMat; PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone(); this.PhaseColor = phaseColor; } else this.PhaseColor = Color.Red; this.documentWorkspace.Refresh(); existViewFlag = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList.IsExsitView() && ShowDrawClassView; this.bitmap = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreateAliasedBitmap(); if (!existViewFlag) { mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap); } else { mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GetFullSizeWithRegion()); } Document document = Document.FromImage(bitmap); this.documentWorkspace.Document = document; this.documentWorkspace.Visible = true; if (ShowDrawClassView) { this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList; } else { GraphicsList itemGraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList; GraphicsList graphicsList = new GraphicsList(); for (int j = 0; j < itemGraphicsList.Count; j++) { if (itemGraphicsList[j].objectType != Annotation.Enum.DrawClass.View) graphicsList.Add(itemGraphicsList[j]); } this.documentWorkspace.GraphicsList = graphicsList; } InitCommonButtonEvent(); } /// /// 添加操作数据到List集合中,并刷新操作按钮的状态 /// /// /// private void AddOperationToList(int addKtype, PointF[] pointFs) { this.RefreshOperationsToIndex(); this.OperationKtypeList.Add(addKtype); this.OperationsList.Add(pointFs); this.OperationIndex = this.OperationsList.Count - 1; this.RefreshOperationsButtons(); } /// /// 根据OperationIndex去掉已经撤销的操作记录 /// private void RefreshOperationsToIndex() { if (this.OperationIndex < this.OperationsList.Count - 1) { int operationSum = this.OperationsList.Count; for (int i = operationSum - 1; i > this.OperationIndex; i--) { this.OperationKtypeList.RemoveAt(i); this.OperationsList.RemoveAt(i); } } } /// /// 刷新操作按钮的状态 /// private void RefreshOperationsButtons() { if (/*this.OperationIndex >= 0 && */this.OperationKtypeList.Count == this.OperationsList.Count && this.OperationKtypeList.Count > 0) this.resetButton.Enabled = true; else this.resetButton.Enabled = false; if (this.OperationIndex >= 0) this.undoButton.Enabled = true; else this.undoButton.Enabled = false; if (this.OperationIndex < this.OperationKtypeList.Count - 1) this.redoButton.Enabled = true; else this.redoButton.Enabled = false; } #region 矩形拖动 /// /// 鼠标按下 /// /// /// private void OnMouseDown(object sender, MouseEventArgs e) { // 换算后的点 PointF point1 = documentWorkspace.GetScalePoint(e.Location); if (point1.X <= this.documentWorkspace.CompositionSurface.Width && point1.X >= 0 && point1.Y >= 0 && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { if (e.Button == MouseButtons.Left && this.pointKtype >= 1 && !drawedStartPoint) drawedStartPoint = true; startPoint = new Point((int)point1.X, (int)point1.Y); } else if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12) { if (!drawedStartPoint)//#21757 { drawedStartPoint = true; startPoint = new Point((int)point1.X, (int)point1.Y); } } } /// /// 移动 /// /// /// private void onMouseMove(object sender, MouseEventArgs e) { // 换算后的点 PointF point1 = documentWorkspace.GetScalePoint(e.Location); if (e.Button == MouseButtons.Left) { // 椭圆删除/圆形删除 if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint) { endPoint = new Point((int)point1.X, (int)point1.Y); if (this.startPoint.X < this.endPoint.X) { //this.pointFloatArray.Clear(); this.rectangle.X = this.startPoint.X; this.rectangle.Width = this.endPoint.X - this.startPoint.X; } else { this.rectangle.X = this.endPoint.X; this.rectangle.Width = this.startPoint.X - this.endPoint.X; } if (this.startPoint.Y < this.endPoint.Y) { this.rectangle.Y = this.startPoint.Y; this.rectangle.Height = this.endPoint.Y - this.startPoint.Y; } else { this.rectangle.Y = this.endPoint.Y; this.rectangle.Height = this.startPoint.Y - this.endPoint.Y; } this.documentWorkspace.Refresh(); } // 矩形删除 if (this.pointKtype == 13 && drawedStartPoint) { endPoint = new Point((int)point1.X, (int)point1.Y); if (this.startPoint.X < this.endPoint.X) { this.rectangle.X = this.startPoint.X; this.rectangle.Width = this.endPoint.X - this.startPoint.X; } else { this.rectangle.X = this.endPoint.X; this.rectangle.Width = this.startPoint.X - this.endPoint.X; } if (this.startPoint.Y < this.endPoint.Y) { this.rectangle.Y = this.startPoint.Y; this.rectangle.Height = this.endPoint.Y - this.startPoint.Y; } else { this.rectangle.Y = this.endPoint.Y; this.rectangle.Height = this.startPoint.Y - this.endPoint.Y; } this.documentWorkspace.Refresh(); } // 直线添加 if (this.pointKtype == 2 && drawedStartPoint) { endPoint = new Point((int)point1.X, (int)point1.Y); this.documentWorkspace.Refresh(); } } } /// /// 鼠标抬起 /// /// /// private void onMouseUp(object sender, MouseEventArgs e) { // 换算后的点 PointF point1 = documentWorkspace.GetScalePoint(e.Location); if (point1.X <= this.documentWorkspace.CompositionSurface.Width && point1.X >= 0 && point1.Y >= 0 && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { } else { if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)//#21757 { //if (point1.X >= this.documentWorkspace.CompositionSurface.Width) // point1.X = this.documentWorkspace.CompositionSurface.Width - 1; //if (point1.X < 0) // point1.X = 0; //if (point1.Y >= this.documentWorkspace.CompositionSurface.Height) // point1.Y = this.documentWorkspace.CompositionSurface.Height - 1; //if (point1.Y < 0) // point1.Y = 0; } else return; } if (e.Button == MouseButtons.Right) { // 折线删除 if (this.pointKtype == 11 && pointFloatArray.Count > 1) { pointFloatArray.Add(new PointF(point1.X, point1.Y)); endPoint = new Point((int)point1.X, (int)point1.Y); this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFloatArray); this.AddOperationToList(this.pointKtype, pointFloatArray.ToArray()); this.rectangle.X = -1; this.rectangle.Y = -1; this.rectangle.Width = 0; this.rectangle.Height = 0; pointFloatArray.Clear(); startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.pointKtype = 0; this.documentWorkspace.Refresh(); } // 折线添加 if (this.pointKtype == 1 && pointFloatArray.Count > 1) { pointFloatArray.Add(new PointF(point1.X, point1.Y)); endPoint = new Point((int)point1.X, (int)point1.Y); //保存处理后的图片 Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); Draw(graphics, false); this.documentWorkspace.PhaseModels[0].mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit); this.AddOperationToList(this.pointKtype, pointFloatArray.ToArray()); pointFloatArray.Clear(); startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.pointKtype = 0; this.documentWorkspace.Refresh(); } } if (e.Button == MouseButtons.Left) { // 圆形删除/椭圆删除 if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint) { endPoint = new Point((int)point1.X, (int)point1.Y); if (this.startPoint.X < this.endPoint.X) { this.rectangle.X = this.startPoint.X; this.rectangle.Width = this.endPoint.X - this.startPoint.X; } else { this.rectangle.X = this.endPoint.X; this.rectangle.Width = this.startPoint.X - this.endPoint.X; } if (this.startPoint.Y < this.endPoint.Y) { this.rectangle.Y = this.startPoint.Y; this.rectangle.Height = this.endPoint.Y - this.startPoint.Y; } else { this.rectangle.Y = this.endPoint.Y; this.rectangle.Height = this.startPoint.Y - this.endPoint.Y; } if (this.pointKtype == 14) this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle); else this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat , new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height))); List pointOperationArray = new List(); pointOperationArray.Add(new PointF(this.rectangle.X, this.rectangle.Y)); pointOperationArray.Add(new PointF(this.rectangle.Width, this.rectangle.Height)); this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray()); this.rectangle.X = -1; this.rectangle.Y = -1; this.rectangle.Width = 0; this.rectangle.Height = 0; startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.pointKtype = 0; this.documentWorkspace.Refresh(); } // 矩形删除 if (this.pointKtype == 13 && drawedStartPoint) { endPoint = new Point((int)point1.X, (int)point1.Y); if (this.startPoint.X < this.endPoint.X) { this.rectangle.X = this.startPoint.X; this.rectangle.Width = this.endPoint.X - this.startPoint.X; } else { this.rectangle.X = this.endPoint.X; this.rectangle.Width = this.startPoint.X - this.endPoint.X; } if (this.startPoint.Y < this.endPoint.Y) { this.rectangle.Y = this.startPoint.Y; this.rectangle.Height = this.endPoint.Y - this.startPoint.Y; } else { this.rectangle.Y = this.endPoint.Y; this.rectangle.Height = this.startPoint.Y - this.endPoint.Y; } this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle); List pointOperationArray = new List(); pointOperationArray.Add(new PointF(this.rectangle.X, this.rectangle.Y)); pointOperationArray.Add(new PointF(this.rectangle.Width, this.rectangle.Height)); this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray()); this.rectangle.X = -1; this.rectangle.Y = -1; this.rectangle.Width = 0; this.rectangle.Height = 0; startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.pointKtype = 0; this.documentWorkspace.Refresh(); } // 折线添加/折线删除 if (this.pointKtype == 1 || this.pointKtype == 11) { pointFloatArray.Add(new PointF(point1.X, point1.Y)); if (drawedStartPoint) { } else startPoint = new Point((int)point1.X, (int)point1.Y); this.documentWorkspace.Refresh(); } // 直线添加 if (this.pointKtype == 2 && drawedStartPoint) { endPoint = new Point((int)point1.X, (int)point1.Y); //保存处理后的图片 Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); Draw(graphics, false); this.documentWorkspace.PhaseModels[0].mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit); List pointOperationArray = new List(); pointOperationArray.Add(new PointF(startPoint.X, startPoint.Y)); pointOperationArray.Add(new PointF(endPoint.X, endPoint.Y)); this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray()); startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.pointKtype = 0; 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); //if (this.checkBox4_0.Checked)//显示网格 Draw(e.Graphics, true); e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio); e.Graphics.TranslateTransform(-x, -y); } } /// /// 绘制 /// private void Draw(Graphics g, bool DrawGuideLines) { // 抗锯齿 g.SmoothingMode = SmoothingMode.AntiAlias; if (DrawGuideLines) { if (guideClass != null && guideClass.GrainSizeGuideAreaMethodModel != null) guideClass.DrawAreaGuide(g, SelectedItem, guideClass.guideModel); else if (guideClass != null && guideClass.GrainSizeGuideStyleModel != null) guideClass.DrawGuideLines(g, SelectedItem, guideClass.guideModel); } if (guide2Class != null && this.documentWorkspace.CompositionSurface != null) guide2Class.DrawGridViews(g, this.documentWorkspace.CompositionSurface.Height, this.documentWorkspace.CompositionSurface.Width); //圆形删除/椭圆删除 if ((this.pointKtype == 14 || this.pointKtype == 12) && (this.rectangle.Width > 0 || this.rectangle.Height > 0)) { Pen pen = new Pen(this.phaseColor, 1); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; if (this.pointKtype == 14) g.DrawEllipse(pen, this.rectangle); else g.DrawEllipse(pen, new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height))); pen.Dispose(); } //矩形删除 if (this.pointKtype == 13 && (this.rectangle.Width > 0 || this.rectangle.Height > 0)) { Pen pen = new Pen(this.phaseColor, 1); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; g.DrawRectangle(pen, new Rectangle((int)this.rectangle.X, (int)this.rectangle.Y, (int)this.rectangle.Width, (int)this.rectangle.Height)); pen.Dispose(); } // 折线删除 if (this.pointKtype == 11 && pointFloatArray.Count >= 2) { Pen pen = new Pen(this.phaseColor, 1); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; g.DrawPolygon(pen, pointFloatArray.ToArray()); pen.Dispose(); } // 直线添加 if (this.pointKtype == 2 && /*pointFloatArray.Count == 2*/drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1) { Pen pen = new Pen(this.phaseColor, 1); //g.DrawLine(pen, pointFloatArray[0].X, pointFloatArray[0].Y, pointFloatArray[1].X, pointFloatArray[1].Y); ////pen.DashStyle = DashStyle.Dash; g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); pen.Dispose(); } // 折线添加 if (this.pointKtype == 1 && pointFloatArray.Count >= 2) { Pen pen = new Pen(this.phaseColor, 1); g.DrawLines(pen, pointFloatArray.ToArray()); pen.Dispose(); } } private void InitializeLanguageText() { this.checkBox1.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text"); this.label7.Text = PdnResources.GetString("Menu.Image.Sigma.Text"); this.applyLabel.Text = "是否应用:"; this.label9.Text = "标准图像:"; this.label17.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":"; this.label6.Text = PdnResources.GetString("Menu.Denoisingtype.text") + ":"; this.label1.Text = PdnResources.GetString("Menu.Grainboundarytype.text") + ":"; this.checkBox2.Text = PdnResources.GetString("Menu.Grainboundaryenhancement.text"); this.checkBox3.Text = "标准图像"; this.checkBox4.Text = "强制连接"; this.label8.Text = PdnResources.GetString("Menu.Grainboundarysize.text") + ":"; this.button3.Text = PdnResources.GetString("Menu.Grainboundaryedit.text"); this.groupBox4.Text = PdnResources.GetString("Menu.params.text");// PdnResources.GetString("Menu.Grainboundarytoreproduce.text"); this.comboBox3.Items.AddRange(new object[] { PdnResources.GetString("Menu.Gaussiansmoothing.text"), PdnResources.GetString("Menu.directionalsmoothing.text")}); this.comboBox2.Items.AddRange(new object[] { PdnResources.GetString("Menu.Brightgrainboundary.text"), PdnResources.GetString("Menu.Darkgrainboundary.text"), PdnResources.GetString("Menu.gradient.text")}); this.resetButton.Text = "重置"; this.resetButton.Enabled = false; this.redoButton.Text = "恢复"; this.redoButton.Enabled = false; this.undoButton.Text = "撤销"; this.undoButton.Enabled = false; this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.button9.Text = PdnResources.GetString("CommonAction.Undo"); this.button2.Text = PdnResources.GetString("Menu.application.text");// PdnResources.GetString("Menu.File.Close.Text"); this.button1.Text = PdnResources.GetString("Form.OkButton.Text"); this.groupBox2.Text = PdnResources.GetString("Menu.Addgrainboundaries.text"); this.button4.Text = PdnResources.GetString("Menu.Lineadd.text"); this.button3.Text = PdnResources.GetString("Menu.Polylineadd.text"); this.groupBox3.Text = PdnResources.GetString("Menu.Deletegrainboundary.text"); this.button8.Text = PdnResources.GetString("Menu.Ellipsedelete.text"); this.button7.Text = PdnResources.GetString("Menu.BinaryAction.RectangleDelete.Text"); this.button6.Text = PdnResources.GetString("Menu.rounddelete.text"); this.button5.Text = PdnResources.GetString("Menu.BinaryAction.PolygonleDelete.Text"); this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text"); this.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");// PdnResources.GetString("Menu.Grainboundaryedit.text"); } private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button9 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.button8 = new System.Windows.Forms.Button(); this.button7 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.groupBox7 = new System.Windows.Forms.GroupBox(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.panel2 = new System.Windows.Forms.Panel(); this.applyRadioButton2 = new System.Windows.Forms.RadioButton(); this.applyRadioButton1 = new System.Windows.Forms.RadioButton(); this.applyLabel = new System.Windows.Forms.Label(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.panel1 = new System.Windows.Forms.Panel(); this.label8 = new System.Windows.Forms.Label(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.checkBox3 = new System.Windows.Forms.CheckBox(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.textBox6 = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.label17 = new System.Windows.Forms.Label(); this.comboBox3 = new System.Windows.Forms.ComboBox(); this.label6 = new System.Windows.Forms.Label(); this.comboBox2 = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.itemsGroupBox = new System.Windows.Forms.GroupBox(); this.undoButton = new System.Windows.Forms.Button(); this.redoButton = new System.Windows.Forms.Button(); this.resetButton = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.panel2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.itemsGroupBox.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.button9); this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(808, 45); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; // // button9 // this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button9.Location = new System.Drawing.Point(468, 13); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(91, 26); this.button9.TabIndex = 2; this.button9.UseVisualStyleBackColor = true; this.button9.Visible = false; this.button9.Click += new System.EventHandler(this.button9_Click); // // button2 // this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button2.Location = new System.Drawing.Point(592, 14); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(91, 24); this.button2.TabIndex = 1; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button1.Location = new System.Drawing.Point(694, 14); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(91, 24); this.button1.TabIndex = 0; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox2 // this.groupBox2.Controls.Add(this.button4); this.groupBox2.Controls.Add(this.button3); this.groupBox2.Location = new System.Drawing.Point(12, 334); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(233, 57); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; // // button4 // this.button4.Location = new System.Drawing.Point(135, 24); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(73, 26); this.button4.TabIndex = 3; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // button3 // this.button3.Location = new System.Drawing.Point(28, 24); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(73, 26); this.button3.TabIndex = 2; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.button8); this.groupBox3.Controls.Add(this.button7); this.groupBox3.Controls.Add(this.button6); this.groupBox3.Controls.Add(this.button5); this.groupBox3.Location = new System.Drawing.Point(12, 398); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(233, 102); this.groupBox3.TabIndex = 1; this.groupBox3.TabStop = false; // // button8 // this.button8.Location = new System.Drawing.Point(135, 65); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(73, 26); this.button8.TabIndex = 7; this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.button8_Click); // // button7 // this.button7.Location = new System.Drawing.Point(28, 65); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(73, 26); this.button7.TabIndex = 6; this.button7.UseVisualStyleBackColor = true; this.button7.Click += new System.EventHandler(this.button7_Click); // // button6 // this.button6.Location = new System.Drawing.Point(135, 24); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(73, 26); this.button6.TabIndex = 5; this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.button6_Click); // // button5 // this.button5.Location = new System.Drawing.Point(28, 24); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(73, 26); this.button5.TabIndex = 4; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // groupBox7 // this.groupBox7.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.groupBox7.Location = new System.Drawing.Point(251, 63); this.groupBox7.Name = "groupBox7"; this.groupBox7.Size = new System.Drawing.Size(569, 502); this.groupBox7.TabIndex = 1; this.groupBox7.TabStop = false; // // groupBox4 // this.groupBox4.Controls.Add(this.panel2); this.groupBox4.Controls.Add(this.applyLabel); this.groupBox4.Controls.Add(this.radioButton2); this.groupBox4.Controls.Add(this.radioButton1); this.groupBox4.Controls.Add(this.panel1); this.groupBox4.Controls.Add(this.label8); this.groupBox4.Controls.Add(this.numericUpDown2); this.groupBox4.Controls.Add(this.numericUpDown1); this.groupBox4.Controls.Add(this.checkBox2); this.groupBox4.Controls.Add(this.checkBox3); this.groupBox4.Controls.Add(this.checkBox4); this.groupBox4.Controls.Add(this.textBox6); this.groupBox4.Controls.Add(this.label7); this.groupBox4.Controls.Add(this.label9); this.groupBox4.Controls.Add(this.label17); this.groupBox4.Controls.Add(this.comboBox3); this.groupBox4.Controls.Add(this.label6); this.groupBox4.Controls.Add(this.comboBox2); this.groupBox4.Controls.Add(this.label1); this.groupBox4.Controls.Add(this.checkBox1); this.groupBox4.Location = new System.Drawing.Point(12, 63); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(233, 264); this.groupBox4.TabIndex = 38; this.groupBox4.TabStop = false; // // panel2 // this.panel2.Controls.Add(this.applyRadioButton2); this.panel2.Controls.Add(this.applyRadioButton1); this.panel2.Location = new System.Drawing.Point(69, 12); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(134, 33); this.panel2.TabIndex = 130; // // applyRadioButton2 // this.applyRadioButton2.AutoSize = true; this.applyRadioButton2.Location = new System.Drawing.Point(66, 8); this.applyRadioButton2.Name = "applyRadioButton2"; this.applyRadioButton2.Size = new System.Drawing.Size(35, 16); this.applyRadioButton2.TabIndex = 129; this.applyRadioButton2.Text = "否"; this.applyRadioButton2.UseVisualStyleBackColor = true; // // applyRadioButton1 // this.applyRadioButton1.AutoSize = true; this.applyRadioButton1.Checked = true; this.applyRadioButton1.Location = new System.Drawing.Point(16, 8); this.applyRadioButton1.Name = "applyRadioButton1"; this.applyRadioButton1.Size = new System.Drawing.Size(35, 16); this.applyRadioButton1.TabIndex = 128; this.applyRadioButton1.TabStop = true; this.applyRadioButton1.Text = "是"; this.applyRadioButton1.UseVisualStyleBackColor = true; // // applyLabel // this.applyLabel.AutoSize = true; this.applyLabel.Location = new System.Drawing.Point(6, 22); this.applyLabel.Name = "applyLabel"; this.applyLabel.Size = new System.Drawing.Size(0, 12); this.applyLabel.TabIndex = 127; // // radioButton2 // this.radioButton2.AutoSize = true; this.radioButton2.Checked = true; this.radioButton2.Location = new System.Drawing.Point(135, 51); this.radioButton2.Name = "radioButton2"; this.radioButton2.Size = new System.Drawing.Size(35, 16); this.radioButton2.TabIndex = 126; this.radioButton2.TabStop = true; this.radioButton2.Text = "否"; this.radioButton2.UseVisualStyleBackColor = true; this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged); // // radioButton1 // this.radioButton1.AutoSize = true; this.radioButton1.Location = new System.Drawing.Point(85, 51); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(35, 16); this.radioButton1.TabIndex = 125; this.radioButton1.Text = "是"; this.radioButton1.UseVisualStyleBackColor = true; this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged); // // panel1 // this.panel1.BackColor = System.Drawing.Color.Red; this.panel1.Location = new System.Drawing.Point(85, 83); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(72, 21); this.panel1.TabIndex = 20; this.panel1.Click += new System.EventHandler(this.panel1_click); // // label8 // this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(6, 176); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(0, 12); this.label8.TabIndex = 30; this.label8.Visible = false; // // numericUpDown2 // this.numericUpDown2.DecimalPlaces = 2; this.numericUpDown2.Location = new System.Drawing.Point(164, 172); this.numericUpDown2.Maximum = new decimal(new int[] { 1000, 0, 0, 0}); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(61, 21); this.numericUpDown2.TabIndex = 29; this.numericUpDown2.Tag = "max"; this.numericUpDown2.Value = new decimal(new int[] { 500, 0, 0, 0}); this.numericUpDown2.Visible = false; // // numericUpDown1 // this.numericUpDown1.DecimalPlaces = 2; this.numericUpDown1.Location = new System.Drawing.Point(85, 172); this.numericUpDown1.Maximum = new decimal(new int[] { 1000, 0, 0, 0}); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(61, 21); this.numericUpDown1.TabIndex = 28; this.numericUpDown1.Tag = "min"; this.numericUpDown1.Value = new decimal(new int[] { 1, 0, 0, 131072}); this.numericUpDown1.Visible = false; // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Checked = true; this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox2.Location = new System.Drawing.Point(8, 114); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(15, 14); this.checkBox2.TabIndex = 26; this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.Visible = false; // // checkBox3 // this.checkBox3.AutoSize = true; this.checkBox3.Location = new System.Drawing.Point(8, 114); this.checkBox3.Name = "checkBox3"; this.checkBox3.Size = new System.Drawing.Size(15, 14); this.checkBox3.TabIndex = 26; this.checkBox3.UseVisualStyleBackColor = true; this.checkBox3.Visible = false; // // checkBox4 // this.checkBox4.AutoSize = true; this.checkBox4.Location = new System.Drawing.Point(8, 115); this.checkBox4.Name = "checkBox4"; this.checkBox4.Size = new System.Drawing.Size(15, 14); this.checkBox4.TabIndex = 26; this.checkBox4.UseVisualStyleBackColor = true; this.checkBox4.Visible = false; // // textBox6 // this.textBox6.Location = new System.Drawing.Point(85, 141); this.textBox6.Name = "textBox6"; this.textBox6.Size = new System.Drawing.Size(45, 21); this.textBox6.TabIndex = 25; this.textBox6.Text = "0.5"; this.textBox6.Visible = false; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(6, 145); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(0, 12); this.label7.TabIndex = 24; this.label7.Visible = false; // // label9 // this.label9.AutoSize = true; this.label9.Location = new System.Drawing.Point(6, 53); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(0, 12); this.label9.TabIndex = 24; // // label17 // this.label17.AutoSize = true; this.label17.Location = new System.Drawing.Point(6, 87); this.label17.Name = "label17"; this.label17.Size = new System.Drawing.Size(0, 12); this.label17.TabIndex = 124; // // comboBox3 // this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox3.FormattingEnabled = true; this.comboBox3.Location = new System.Drawing.Point(85, 235); this.comboBox3.Name = "comboBox3"; this.comboBox3.Size = new System.Drawing.Size(133, 20); this.comboBox3.TabIndex = 23; this.comboBox3.Visible = false; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(6, 238); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(0, 12); this.label6.TabIndex = 22; this.label6.Visible = false; // // comboBox2 // this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox2.FormattingEnabled = true; this.comboBox2.Location = new System.Drawing.Point(85, 204); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(133, 20); this.comboBox2.TabIndex = 11; this.comboBox2.Visible = false; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(6, 207); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(0, 12); this.label1.TabIndex = 21; this.label1.Visible = false; // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(8, 87); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(15, 14); this.checkBox1.TabIndex = 7; this.checkBox1.UseVisualStyleBackColor = true; this.checkBox1.Visible = false; // // itemsGroupBox // this.itemsGroupBox.Controls.Add(this.undoButton); this.itemsGroupBox.Controls.Add(this.redoButton); this.itemsGroupBox.Controls.Add(this.resetButton); this.itemsGroupBox.Location = new System.Drawing.Point(12, 506); this.itemsGroupBox.Name = "itemsGroupBox"; this.itemsGroupBox.Size = new System.Drawing.Size(233, 59); this.itemsGroupBox.TabIndex = 39; this.itemsGroupBox.TabStop = false; this.itemsGroupBox.Text = "操作"; // // undoButton // this.undoButton.Location = new System.Drawing.Point(156, 23); this.undoButton.Name = "undoButton"; this.undoButton.Size = new System.Drawing.Size(64, 26); this.undoButton.TabIndex = 10; this.undoButton.UseVisualStyleBackColor = true; this.undoButton.Click += new System.EventHandler(this.undoButton_Click); // // redoButton // this.redoButton.Location = new System.Drawing.Point(86, 23); this.redoButton.Name = "redoButton"; this.redoButton.Size = new System.Drawing.Size(64, 26); this.redoButton.TabIndex = 9; this.redoButton.UseVisualStyleBackColor = true; this.redoButton.Click += new System.EventHandler(this.redoButton_Click); // // resetButton // this.resetButton.Location = new System.Drawing.Point(16, 23); this.resetButton.Name = "resetButton"; this.resetButton.Size = new System.Drawing.Size(64, 26); this.resetButton.TabIndex = 8; this.resetButton.UseVisualStyleBackColor = true; this.resetButton.Click += new System.EventHandler(this.resetButton_Click); // // GrainBoundaryEditingDialog // this.ClientSize = new System.Drawing.Size(832, 577); this.Controls.Add(this.itemsGroupBox); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox7); this.Controls.Add(this.groupBox1); this.MaximizeBox = false; this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(848, 616); this.Name = "GrainBoundaryEditingDialog"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GrainBoundryEditingDialog_FormClosing); this.Load += new System.EventHandler(this.GrainBoundryEditingDialog_Load); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.itemsGroupBox.ResumeLayout(false); this.ResumeLayout(false); } /// /// 折线添加 /// /// /// private void button3_Click(object sender, EventArgs e) { if (this.documentWorkspace.PhaseModels[0].mat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")); return; } pointFloatArray.Clear(); startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); pointKtype = 1; this.documentWorkspace.Refresh(); } /// /// 直线添加 /// /// /// private void button4_Click(object sender, EventArgs e) { if (this.documentWorkspace.PhaseModels[0].mat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")); return; } startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); pointKtype = 2; this.documentWorkspace.Refresh(); } private void InitCommonButtonEvent() { this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click); this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click); this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click); this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click); this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click); this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click); } private void zoomInButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomIn(); } private void zoomOutButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomOut(); } private void zoomToWindowButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow; } private void actualSizeButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor; this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne; } private void pointerButton_Click(object sender, EventArgs e) { this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect; this.documentWorkspace.Cursor = Cursors.Default; } private void mobileModeButton_Click(object sender, EventArgs e) { this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode; } //确定按钮点击事件 private void button1_Click(object sender, EventArgs e) { this.PhaseMat = this.documentWorkspace.PhaseModels[0].mat; this.DialogResult = DialogResult.OK; this.Close(); } /// /// 用于get处理后的图像 /// public Mat PhaseMat { get { return this.phaseMat; } set { this.phaseMat = value; } } /// /// 用于get处理后的图像相的颜色 /// public Color PhaseColor { get { return this.phaseColor; } set { this.phaseColor = value; } } /// /// 矩形删除 /// /// /// private void button7_Click(object sender, EventArgs e) { if (this.documentWorkspace.PhaseModels[0].mat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")); return; } startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.rectangle.X = -1; this.rectangle.Y = -1; this.rectangle.Width = 0; this.rectangle.Height = 0; this.pointKtype = 13; this.documentWorkspace.Refresh(); } /// /// 椭圆删除 /// /// /// private void button8_Click(object sender, EventArgs e) { if (this.documentWorkspace.PhaseModels[0].mat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")); return; } startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.rectangle.X = -1; this.rectangle.Y = -1; this.rectangle.Width = 0; this.rectangle.Height = 0; this.pointKtype = 14; this.documentWorkspace.Refresh(); } /// /// 圆形删除 /// /// /// private void button6_Click(object sender, EventArgs e) { if (this.documentWorkspace.PhaseModels[0].mat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")); return; } startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.rectangle.X = -1; this.rectangle.Y = -1; this.rectangle.Width = 0; this.rectangle.Height = 0; this.pointKtype = 12; this.documentWorkspace.Refresh(); } /// /// 多边形删除 /// /// /// private void button5_Click(object sender, EventArgs e) { if (this.documentWorkspace.PhaseModels[0].mat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")); return; } pointFloatArray.Clear(); startPoint = new Point(-1, -1); drawedStartPoint = false; endPoint = new Point(-1, -1); this.rectangle.X = -1; this.rectangle.Y = -1; this.rectangle.Width = 0; this.rectangle.Height = 0; this.pointKtype = 11; this.documentWorkspace.Refresh(); } private void button2_Click(object sender, EventArgs e) { this.applyDect(); //this.Close();//################################## } /// /// 撤销按钮点击事件 /// /// /// private void button9_Click(object sender, EventArgs e) { } private void numericUpDown1_ValueChanged_1(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } private void numericUpDown2_ValueChanged_1(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } #region 晶界重现方法 ProgressThreadProcClass procClass; int grainApplygrainboundaries; int m_iStandardImage; int iConnect; double sigma = 0.5; Mat OrgImg;// = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile); int dark;// = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 int smooth_type;// = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数 int enhance;// = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1 double[] cell_size;// = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小 Mat OrgImg0; private void applyDect() { if (this.bitmap == null) { return; } if (!double.TryParse(textBox6.Text, out sigma)) { return; } //string inputImageFile = "原始图片1.jpg";// "j1.JPG"; ////char[] inputImageFile2 = inputImageFile.ToCharArray(); /*Mat */ OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile); grainApplygrainboundaries = this.applyRadioButton1.Checked ? 1 : 0; m_iStandardImage = this.radioButton1/*checkBox3*/.Checked ? 1 : 0; iConnect = this.checkBox4.Checked ? 1 : 0; /*int */ dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 /*int */ smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数 /*int */ enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1 /*double[] */ cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小 procClass = new ProgressThreadProcClass(); procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyDectAction), PdnResources.GetString("Menu.Grainboundarytoreproduce.text")); //if (isOtherGrainSizeStandardDialog) //{ // if (OrgImg0 != null) // { // this.documentWorkspace.PhaseModels[1].mat = OrgImg0.Clone(); // this.documentWorkspace.Refresh(); // OrgImg0 = null; // } // if (OrgImg != null) // { // OrgImg.Dispose(); // OrgImg = null; // } // return;//## //} if (OrgImg0 != null) { if (getCurrentWorkspace().GraphicsList.IsExsitView() && ShowDrawClassView) { Vec4b vec4 = new Vec4b(0, 0, 0, 0); //视场图像 Mat exsitViewMatOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(getCurrentWorkspace().GetFullSizeWithRegion()); for (int y = 0; y < exsitViewMatOrg/*temp*/.Rows; y++) { for (int x = 0; x < exsitViewMatOrg/*temp*/.Cols; x++) { if (exsitViewMatOrg.At(y, x).Item3 == 0) OrgImg0.Set(y, x, vec4);//不在视场图像范围内 } } } this.documentWorkspace.PhaseModels[0].mat = OrgImg0.Clone(); this.documentWorkspace.Refresh(); if (PhaseModel0MatCopy != null) { PhaseModel0MatCopy.Dispose(); PhaseModel0MatCopy = null; } PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone(); this.resetOperationsAction(); OrgImg0 = null; } if (OrgImg != null) { OrgImg.Dispose(); OrgImg = null; } ////this.runDect(OrgImg, dark, smooth_type, sigma, enhance, cell_size);//###########################2 //if (!isAreaType) // AddRectangleToRectangleFCaps();//0916###18747 //else //{ // GetClassNumberOfGrains(); //} } private void applyDectAction() { OrgImg0 = /*GrainBoundaryEditingDialog.*/runDect(m_iStandardImage, iConnect, this.panel1.BackColor, OrgImg, dark, smooth_type, sigma, enhance, cell_size); if (procClass != null) procClass.DismissProgressAction(this); } private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.applyDect(); } } private void checkBox3_CheckedChanged(object sender, EventArgs e) { //标准图像 if (this.checkBox3.Checked) { this.checkBox2.Visible = false; this.label1.Visible = false; this.label6.Visible = false; this.label7.Visible = false; this.label8.Visible = false; this.textBox6.Visible = false; this.numericUpDown1.Visible = false; this.numericUpDown2.Visible = false; this.comboBox2.Visible = false; this.comboBox3.Visible = false; this.checkBox4.Visible = true; } else { this.checkBox4.Visible = false; this.checkBox2.Visible = true; this.label1.Visible = true; this.label6.Visible = true; this.label7.Visible = true; this.label8.Visible = true; this.textBox6.Visible = true; this.numericUpDown1.Visible = true; this.numericUpDown2.Visible = true; this.comboBox2.Visible = true; this.comboBox3.Visible = true; } } public static Mat runDect(int m_iStandardImage, int iConnect, Color phaseColor, Mat OrgImg0, int dark, int smooth_type, double sigma, int enhance, double[] cell_size) { Mat GryImg = new Mat(); Mat OrgImg = new Mat(); ///// if (4 == OrgImg0.Channels()) { Cv2.CvtColor(OrgImg0, OrgImg, ColorConversionCodes.BGRA2BGR); } else { OrgImg = OrgImg0.Clone(); } In5segmsurf prm = new In5segmsurf(); prm.OrgImg = OrgImg; ///// //Cv2.ImShow("src", OrgImg);//kkkkk ////Cv2.WaitKey(0);//kkkkk //转为为灰度? if (3 == OrgImg.Channels() || 4 == OrgImg.Channels()) { Cv2.CvtColor(OrgImg, GryImg, ColorConversionCodes.RGB2GRAY); } else { if (1 == OrgImg.Channels()) { GryImg = OrgImg.Clone(); } else { return null; } } if (0 == m_iStandardImage) { if (1 == dark) {//采用新的算法不需要这里的处理了 // int Rows = GryImg.Rows; // int Cols = GryImg.Cols; // int[] point = new int[2]; // //单通道图像的反色 // for (point[0] = 0; point[0] < Rows; point[0]++) // { // for (point[1] = 0; point[1] < Cols; point[1]++) // { // byte bTemp = (byte)(255 - GryImg.At(point[0], point[1])); // GryImg.Set(point, bTemp);//mmmmm // } // } //} //if (2 == dark) //{ // Mat TempImg = GryImg.Clone(); // Cv2.Sobel(TempImg, GryImg, -1, 2, 2, 3);//mmmmm } //Cv2.ImShow("src", GryImg);//kkkkk //Cv2.WaitKey(0);//kkkkk //去噪 if (0 == smooth_type) { prm.smoothim_method = "gaussian"; } else { if (1 == smooth_type) { prm.smoothim_method = "dirced"; } else { return null; } } //晶界增强 if (1 == enhance) { prm.filterridges = 1; } else { prm.filterridges = 0; } //调用算法 prm.gaussian_stdev = sigma; prm.LEVEL = ".3"; prm.classifycells_convexarea = 0.50; prm.classifycells_convexperim = 0.45; OLDcellsegm cellsegm = new OLDcellsegm(); string[] namehere = new string[1] { "prm" }; In6segmsurf IN6BNImgs = new In6segmsurf(); OUTsegmsurf RSTss = cellsegm.mf_segmsurf_progress_auto(GryImg, cell_size[0], cell_size[1], namehere, prm, IN6BNImgs, phaseColor); Cv2.CvtColor(RSTss.wat, OrgImg0, ColorConversionCodes.BGR2BGRA); } else { OLDcellsegm cellsegm = new OLDcellsegm(); OrgImg0/*Mat WAT*/ = cellsegm.ProFroStandardImage(GryImg, iConnect, phaseColor); //string filename = "D:\\result.jpg"; //Cv2.ImWrite(filename, WAT); } return OrgImg0; } private void panel1_click(object sender, EventArgs e) { this.panelC = (Panel)sender; this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor); this.colorsFormGrid.ShowDialog(); } #endregion private void radioButton_CheckedChanged(object sender, EventArgs e) { //非标准图像 if (this.radioButton2.Checked) { this.checkBox4.Visible = false; //this.checkBox2.Visible = true; //this.label1.Visible = true; //this.label6.Visible = true; //this.label7.Visible = true; //this.label8.Visible = true; //this.textBox6.Visible = true; //this.numericUpDown1.Visible = true; //this.numericUpDown2.Visible = true; //this.comboBox2.Visible = true; //this.comboBox3.Visible = true; } } private void radioButton1_CheckedChanged(object sender, EventArgs e) { //标准图像 if (this.radioButton1.Checked) { this.checkBox2.Visible = false; this.label1.Visible = false; this.label6.Visible = false; this.label7.Visible = false; this.label8.Visible = false; this.textBox6.Visible = false; this.numericUpDown1.Visible = false; this.numericUpDown2.Visible = false; this.comboBox2.Visible = false; this.comboBox3.Visible = false; this.checkBox4.Visible = true; } } private void GrainBoundryEditingDialog_FormClosing(object sender, FormClosingEventArgs e) { string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml"; bool createNewFile = !System.IO.File.Exists(xmlFilePath); if (createNewFile) xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel.xml"; Base.SettingModel.GrainBoundryDectModel grainBoundryDectModel = Base.CommTool.XmlSerializeHelper.DESerializer(Base.CommTool.FileOperationHelper.ReadStringFromFile(xmlFilePath, System.IO.FileMode.Open)); if (double.TryParse(textBox6.Text, out sigma)) grainBoundryDectModel.sigma = sigma; grainBoundryDectModel.grainColor = this.phaseColor.ToArgb(); grainApplygrainboundaries = this.applyRadioButton1.Checked ? 1 : 0; grainBoundryDectModel.grainApplygrainboundaries = grainApplygrainboundaries; m_iStandardImage = this.radioButton1.Checked ? 1 : 0; grainBoundryDectModel.m_iStandardImage = m_iStandardImage; iConnect = this.checkBox4.Checked ? 1 : 0; grainBoundryDectModel.iConnect = iConnect; dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 grainBoundryDectModel.dark = dark; smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 grainBoundryDectModel.smooth_type = smooth_type; enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1 grainBoundryDectModel.enhance = enhance; cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小 grainBoundryDectModel.cell1_size = cell_size[0]; grainBoundryDectModel.cell2_size = cell_size[1]; xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml"; string userInfoXml = Base.CommTool.XmlSerializeHelper.XmlSerialize(grainBoundryDectModel); Base.CommTool.FileOperationHelper.WriteStringToFile(userInfoXml, xmlFilePath, System.IO.FileMode.Create); } private void GrainBoundryEditingDialog_Load(object sender, EventArgs e) { string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml"; bool createNewFile = !System.IO.File.Exists(xmlFilePath); if (createNewFile) return; Base.SettingModel.GrainBoundryDectModel grainBoundryDectModel = Base.CommTool.XmlSerializeHelper.DESerializer(Base.CommTool.FileOperationHelper.ReadStringFromFile(xmlFilePath, System.IO.FileMode.Open)); this.phaseColor = Color.FromArgb(grainBoundryDectModel.grainColor == 0 ? Color.Red.ToArgb() : grainBoundryDectModel.grainColor); this.panel1.BackColor = this.phaseColor; sigma = grainBoundryDectModel.sigma; textBox6.Text = sigma + ""; grainApplygrainboundaries = grainBoundryDectModel.grainApplygrainboundaries; this.applyRadioButton1.Checked = (grainApplygrainboundaries == 1); this.applyRadioButton2.Checked = (grainApplygrainboundaries != 1); m_iStandardImage = grainBoundryDectModel.m_iStandardImage; this.radioButton1.Checked = (m_iStandardImage == 1); iConnect = grainBoundryDectModel.iConnect; this.checkBox4.Checked = (iConnect == 1); dark = grainBoundryDectModel.dark; this.comboBox2.SelectedIndex = dark;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 smooth_type = grainBoundryDectModel.smooth_type; this.comboBox3.SelectedIndex = smooth_type;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 enhance = grainBoundryDectModel.enhance; this.checkBox2.Checked = (enhance == 1);// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1 cell_size = new double[2] { (double)grainBoundryDectModel.cell1_size, (double)grainBoundryDectModel.cell2_size }; ;// new double[2] { 0.01, 500 };//晶界大小 numericUpDown1.Value = Convert.ToDecimal(cell_size[0]); numericUpDown2.Value = Convert.ToDecimal(cell_size[1]); } /// /// 根据当前操作位置处理图片,并刷新操作按钮状态 /// /// private void RefreshMatsToIndex(int OperationTag) { //...处理图片(this.OperationIndex) this.OperationIndex = OperationTag; ///// 操作类型 //private int pointKtype = 0; if (PhaseModel0MatCopy != null && this.OperationIndex >= 0) { Mat newModel0Mat = PhaseModel0MatCopy.Clone(); for (int i = 0; i <= this.OperationIndex; i++) { //操作类型 0,没有操作 1,折线添加 2,直线添加 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除 int opeType = this.OperationKtypeList[i]; PointF[] opePoints = this.OperationsList[i]; // 折线删除 if (opeType == 11 && opePoints.Length > 1) { newModel0Mat/*this.documentWorkspace.PhaseModels[0].mat*/ = PreActionIntent.PolygonDelete(newModel0Mat/*this.documentWorkspace.PhaseModels[0].mat*/, opePoints.ToList()/*pointFloatArray*/); //this.pointKtype = 0; //this.documentWorkspace.Refresh(); } // 折线添加 if (opeType == 1 && opePoints.Length > 1) { //保存处理后的图片 Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newModel0Mat); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); //Draw(graphics, false); // 抗锯齿 graphics.SmoothingMode = SmoothingMode.AntiAlias; // 折线添加 if (opeType == 1 && opePoints.Length >= 2) { Pen pen = new Pen(this.phaseColor, 1); graphics.DrawLines(pen, opePoints); pen.Dispose(); } newModel0Mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit); } // 圆形删除/椭圆删除 if ((opeType == 14 || opeType == 12) && opePoints.Length == 2) { RectangleF rectangleFOpe = new RectangleF(opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y); if (this.pointKtype == 14) newModel0Mat = PreActionIntent.OvalDelete(newModel0Mat, rectangleFOpe); else newModel0Mat = PreActionIntent.OvalDelete(newModel0Mat, rectangleFOpe); } // 矩形删除 if (opeType == 13 && opePoints.Length == 2) { RectangleF rectangleFOpe = new RectangleF(opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y); newModel0Mat = PreActionIntent.RectangleDelete(newModel0Mat, rectangleFOpe); } // 直线添加 if (opeType == 2 && opePoints.Length == 2/*this.startPoint.X > -1 && this.startPoint.Y > -1*/) { //保存处理后的图片 Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newModel0Mat); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); //Draw(graphics, false); // 抗锯齿 graphics.SmoothingMode = SmoothingMode.AntiAlias; // 直线添加 if (opeType == 2 && opePoints.Length == 2/*this.startPoint.X > -1 && this.startPoint.Y > -1 && this.endPoint.X > -1 && this.endPoint.Y > -1*/) { Pen pen = new Pen(this.phaseColor, 1); graphics.DrawLine(pen, opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y); //////pen.DashStyle = DashStyle.Dash; //g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); pen.Dispose(); } newModel0Mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit); } } this.documentWorkspace.PhaseModels[0].mat = newModel0Mat; this.documentWorkspace.Refresh(); } else if (PhaseModel0MatCopy != null) { this.documentWorkspace.PhaseModels[0].mat = PhaseModel0MatCopy.Clone(); this.documentWorkspace.Refresh(); } //刷新操作按钮的状态 this.RefreshOperationsButtons(); } /// /// 操作-重置 /// private void resetOperationsAction() { this.OperationIndex = -1; this.RefreshOperationsToIndex(); this.RefreshOperationsButtons(); } /// /// 操作-重置 /// /// /// private void resetButton_Click(object sender, EventArgs e) { if (PhaseModel0MatCopy != null) { this.documentWorkspace.PhaseModels[0].mat = PhaseModel0MatCopy.Clone(); this.documentWorkspace.Refresh(); } this.resetOperationsAction(); } /// /// 操作-撤销 /// /// /// private void undoButton_Click(object sender, EventArgs e) { if (this.OperationIndex >= 0) { this.RefreshMatsToIndex(this.OperationIndex - 1); } else this.undoButton.Enabled = false; } /// /// 操作-恢复 /// /// /// private void redoButton_Click(object sender, EventArgs e) { if (this.OperationIndex < this.OperationKtypeList.Count - 1) { this.RefreshMatsToIndex(this.OperationIndex + 1); } else this.redoButton.Enabled = false; } } }