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_GrainAdOutParam0 = "GrainAdOutParam0";//方法1原方法,方法2模拟软件方法 this.radioButton1.Checked? 2 : 1;
public static string ParamKey_GrainAdOutParam1 = "GrainAdOutParam1";//默认为暗晶界,为2时为亮晶界 this.radioButton3.Checked? 2 : 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;
///
/// 选中图片的mat
///
private Mat imageMat;
///
/// 用于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 label17;
private GroupBox groupBox7;
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 Panel panel3;
private RadioButton radioButton1;
private RadioButton radioButton2;
private Label label2;
private Panel panel4;
private RadioButton radioButton3;
private RadioButton radioButton4;
private Label label3;
private Panel panel5;
private Label label1;
private Panel panel6;
private TrackBar trackBar2;
private Label label4;
private TrackBar trackBar1;
private Panel panel7;
private RadioButton radioButton5;
private RadioButton radioButton6;
private Label label5;
private Panel panel8;
private TrackBar trackBar3;
private Label label6;
private RadioButton radioButton10;
private RadioButton radioButton7;
private RadioButton radioButton8;
private Panel panel9;
private RadioButton radioButton9;
private RadioButton radioButton11;
private Label label7;
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 Vec4b dstVecBack4b;
///
/// 颜色改变时改变相的颜色
///
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);
dstVecBack4b = new Vec4b(this.PhaseColor.B, this.PhaseColor.G, this.PhaseColor.R, 0);
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();
//Cv2.ImShow("dstBinary", dstBinary);
//Cv2.WaitKey();
this.documentWorkspace.Refresh();
}
///
/// 提取二值化的透明通道并赋值
///
///
///
private unsafe void ForeachFunctionByteForWhole4B(Vec4b* t, int* position)
{
if (t->Item3 > 0)
dstBinary.Set(position[0], position[1], dstVec4b);
else
dstBinary.Set(position[0], position[1], dstVecBack4b);
}
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.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.imageMat = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreatedAliasedMat();
Document document = Document.FromImageMat(imageMat.Clone());
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 = PaintDotNet.Camera.Tools.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 = PaintDotNet.Camera.Tools.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.applyLabel.Text = PdnResources.GetString("Menu.IsItApplied.text") + ":";
this.label2.Text = PdnResources.GetString("Menu.Method.text") + ":";
this.label3.Text = PdnResources.GetString("Menu.Grainboundarytype.text") + ":";
this.label17.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
this.label1.Text = PdnResources.GetString("Menu.GrainScale.text") + ":";
this.label4.Text = PdnResources.GetString("Menu.GrainWidth.text") + ":";
this.label5.Text = PdnResources.GetString("Menu.adjustment.text") + ":";
this.label6.Text = PdnResources.GetString("Menu.intensity.text") + ":";
this.label7.Text = PdnResources.GetString("Menu.linear.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 = PdnResources.GetString("Menu.reinformation.text");
this.resetButton.Enabled = false;
this.redoButton.Text = PdnResources.GetString("Menu.Edit.Redo.Text");
this.redoButton.Enabled = false;
this.undoButton.Text = PdnResources.GetString("CommonAction.Undo");
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");
this.radioButton9.Text = PdnResources.GetString("Menu.Intercept.text");
this.radioButton11.Text = PdnResources.GetString("Menu.Slope.text");
this.radioButton10.Text = PdnResources.GetString("Menu.LinearTrim.text");
this.radioButton7.Text = PdnResources.GetString("Menu.Bright.text");
this.radioButton8.Text = PdnResources.GetString("Menu.Dimming.text");
this.radioButton5.Text = PdnResources.GetString("Menu.auto-adjust.text");
this.radioButton6.Text = PdnResources.GetString("Menu.NoAdjust.text");
this.radioButton3.Text = PdnResources.GetString("Menu.Brightgrainboundary.text");
this.radioButton4.Text = PdnResources.GetString("Menu.Darkgrainboundary.text");
this.applyRadioButton2.Text = PdnResources.GetString("Menu.no.text");
this.applyRadioButton1.Text = PdnResources.GetString("Menu.Yes.text");
this.itemsGroupBox.Text = PdnResources.GetString("Menu.operation.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.panel9 = new System.Windows.Forms.Panel();
this.radioButton9 = new System.Windows.Forms.RadioButton();
this.radioButton11 = new System.Windows.Forms.RadioButton();
this.label7 = new System.Windows.Forms.Label();
this.panel8 = new System.Windows.Forms.Panel();
this.trackBar3 = new System.Windows.Forms.TrackBar();
this.label6 = new System.Windows.Forms.Label();
this.panel7 = new System.Windows.Forms.Panel();
this.radioButton10 = new System.Windows.Forms.RadioButton();
this.radioButton7 = new System.Windows.Forms.RadioButton();
this.radioButton8 = new System.Windows.Forms.RadioButton();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton6 = new System.Windows.Forms.RadioButton();
this.label5 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.panel6 = new System.Windows.Forms.Panel();
this.trackBar2 = new System.Windows.Forms.TrackBar();
this.label4 = new System.Windows.Forms.Label();
this.panel5 = new System.Windows.Forms.Panel();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.label1 = new System.Windows.Forms.Label();
this.panel4 = new System.Windows.Forms.Panel();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.label3 = new System.Windows.Forms.Label();
this.panel3 = new System.Windows.Forms.Panel();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.label2 = new System.Windows.Forms.Label();
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.label17 = new System.Windows.Forms.Label();
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.panel9.SuspendLayout();
this.panel8.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
this.panel7.SuspendLayout();
this.panel6.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit();
this.panel5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.panel4.SuspendLayout();
this.panel3.SuspendLayout();
this.panel2.SuspendLayout();
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, 359);
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, 420);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(233, 80);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
//
// button8
//
this.button8.Location = new System.Drawing.Point(135, 49);
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, 49);
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, 20);
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, 20);
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.panel9);
this.groupBox4.Controls.Add(this.label7);
this.groupBox4.Controls.Add(this.panel8);
this.groupBox4.Controls.Add(this.label6);
this.groupBox4.Controls.Add(this.panel7);
this.groupBox4.Controls.Add(this.label5);
this.groupBox4.Controls.Add(this.panel1);
this.groupBox4.Controls.Add(this.panel6);
this.groupBox4.Controls.Add(this.label4);
this.groupBox4.Controls.Add(this.panel5);
this.groupBox4.Controls.Add(this.label1);
this.groupBox4.Controls.Add(this.panel4);
this.groupBox4.Controls.Add(this.label3);
this.groupBox4.Controls.Add(this.panel3);
this.groupBox4.Controls.Add(this.label2);
this.groupBox4.Controls.Add(this.panel2);
this.groupBox4.Controls.Add(this.applyLabel);
this.groupBox4.Controls.Add(this.label17);
this.groupBox4.Location = new System.Drawing.Point(12, 63);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(233, 290);
this.groupBox4.TabIndex = 38;
this.groupBox4.TabStop = false;
//
// panel9
//
this.panel9.Controls.Add(this.radioButton9);
this.panel9.Controls.Add(this.radioButton11);
this.panel9.Location = new System.Drawing.Point(69, 251);
this.panel9.Name = "panel9";
this.panel9.Size = new System.Drawing.Size(134, 33);
this.panel9.TabIndex = 132;
//
// radioButton9
//
this.radioButton9.AutoSize = true;
this.radioButton9.Location = new System.Drawing.Point(66, 8);
this.radioButton9.Name = "radioButton9";
this.radioButton9.Size = new System.Drawing.Size(47, 16);
this.radioButton9.TabIndex = 129;
this.radioButton9.Text = "截距";
this.radioButton9.UseVisualStyleBackColor = true;
//
// radioButton11
//
this.radioButton11.AutoSize = true;
this.radioButton11.Checked = true;
this.radioButton11.Location = new System.Drawing.Point(16, 8);
this.radioButton11.Name = "radioButton11";
this.radioButton11.Size = new System.Drawing.Size(47, 16);
this.radioButton11.TabIndex = 128;
this.radioButton11.TabStop = true;
this.radioButton11.Text = "斜率";
this.radioButton11.UseVisualStyleBackColor = true;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(6, 261);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(0, 12);
this.label7.TabIndex = 131;
//
// panel8
//
this.panel8.Controls.Add(this.trackBar3);
this.panel8.Location = new System.Drawing.Point(69, 222);
this.panel8.Name = "panel8";
this.panel8.Size = new System.Drawing.Size(156, 33);
this.panel8.TabIndex = 138;
//
// trackBar3
//
this.trackBar3.AutoSize = false;
this.trackBar3.Location = new System.Drawing.Point(8, 5);
this.trackBar3.Maximum = 20;
this.trackBar3.Minimum = 10;
this.trackBar3.Name = "trackBar3";
this.trackBar3.Size = new System.Drawing.Size(134, 22);
this.trackBar3.TabIndex = 0;
this.trackBar3.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBar3.Value = 10;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(6, 231);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(0, 12);
this.label6.TabIndex = 137;
//
// panel7
//
this.panel7.Controls.Add(this.radioButton10);
this.panel7.Controls.Add(this.radioButton7);
this.panel7.Controls.Add(this.radioButton8);
this.panel7.Controls.Add(this.radioButton5);
this.panel7.Controls.Add(this.radioButton6);
this.panel7.Location = new System.Drawing.Point(69, 163);
this.panel7.Name = "panel7";
this.panel7.Size = new System.Drawing.Size(158, 63);
this.panel7.TabIndex = 132;
//
// radioButton10
//
this.radioButton10.AutoSize = true;
this.radioButton10.Location = new System.Drawing.Point(7, 42);
this.radioButton10.Name = "radioButton10";
this.radioButton10.Size = new System.Drawing.Size(71, 16);
this.radioButton10.TabIndex = 132;
this.radioButton10.Text = "线性调整";
this.radioButton10.UseVisualStyleBackColor = true;
this.radioButton10.CheckedChanged += new System.EventHandler(this.radioButton10_CheckedChanged);
//
// radioButton7
//
this.radioButton7.AutoSize = true;
this.radioButton7.Location = new System.Drawing.Point(80, 22);
this.radioButton7.Name = "radioButton7";
this.radioButton7.Size = new System.Drawing.Size(71, 16);
this.radioButton7.TabIndex = 131;
this.radioButton7.Text = "整体调亮";
this.radioButton7.UseVisualStyleBackColor = true;
this.radioButton7.CheckedChanged += new System.EventHandler(this.radioButton7_CheckedChanged);
//
// radioButton8
//
this.radioButton8.AutoSize = true;
this.radioButton8.Location = new System.Drawing.Point(7, 22);
this.radioButton8.Name = "radioButton8";
this.radioButton8.Size = new System.Drawing.Size(71, 16);
this.radioButton8.TabIndex = 130;
this.radioButton8.Text = "整体调暗";
this.radioButton8.UseVisualStyleBackColor = true;
this.radioButton8.CheckedChanged += new System.EventHandler(this.radioButton8_CheckedChanged);
//
// radioButton5
//
this.radioButton5.AutoSize = true;
this.radioButton5.Location = new System.Drawing.Point(81, 3);
this.radioButton5.Name = "radioButton5";
this.radioButton5.Size = new System.Drawing.Size(71, 16);
this.radioButton5.TabIndex = 129;
this.radioButton5.Text = "自动调整";
this.radioButton5.UseVisualStyleBackColor = true;
this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
//
// radioButton6
//
this.radioButton6.AutoSize = true;
this.radioButton6.Checked = true;
this.radioButton6.Location = new System.Drawing.Point(8, 3);
this.radioButton6.Name = "radioButton6";
this.radioButton6.Size = new System.Drawing.Size(59, 16);
this.radioButton6.TabIndex = 128;
this.radioButton6.TabStop = true;
this.radioButton6.Text = "不调整";
this.radioButton6.UseVisualStyleBackColor = true;
this.radioButton6.CheckedChanged += new System.EventHandler(this.radioButton6_CheckedChanged);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(6, 173);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(0, 12);
this.label5.TabIndex = 131;
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(85, 39);
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);
//
// panel6
//
this.panel6.Controls.Add(this.trackBar2);
this.panel6.Location = new System.Drawing.Point(69, 136);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(156, 33);
this.panel6.TabIndex = 136;
//
// trackBar2
//
this.trackBar2.AutoSize = false;
this.trackBar2.Location = new System.Drawing.Point(8, 5);
this.trackBar2.Maximum = 50;
this.trackBar2.Minimum = 10;
this.trackBar2.Name = "trackBar2";
this.trackBar2.Size = new System.Drawing.Size(134, 22);
this.trackBar2.TabIndex = 0;
this.trackBar2.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBar2.Value = 10;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 145);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(0, 12);
this.label4.TabIndex = 135;
//
// panel5
//
this.panel5.Controls.Add(this.trackBar1);
this.panel5.Location = new System.Drawing.Point(69, 109);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(156, 33);
this.panel5.TabIndex = 134;
//
// trackBar1
//
this.trackBar1.AutoSize = false;
this.trackBar1.Location = new System.Drawing.Point(8, 5);
this.trackBar1.Maximum = 40;
this.trackBar1.Minimum = 10;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(134, 22);
this.trackBar1.TabIndex = 0;
this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBar1.Value = 30;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 118);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(0, 12);
this.label1.TabIndex = 133;
//
// panel4
//
this.panel4.Controls.Add(this.radioButton3);
this.panel4.Controls.Add(this.radioButton4);
this.panel4.Location = new System.Drawing.Point(69, 82);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(156, 33);
this.panel4.TabIndex = 132;
//
// radioButton3
//
this.radioButton3.AutoSize = true;
this.radioButton3.Location = new System.Drawing.Point(83, 8);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(59, 16);
this.radioButton3.TabIndex = 129;
this.radioButton3.Text = "亮晶界";
this.radioButton3.UseVisualStyleBackColor = true;
//
// radioButton4
//
this.radioButton4.AutoSize = true;
this.radioButton4.Checked = true;
this.radioButton4.Location = new System.Drawing.Point(7, 8);
this.radioButton4.Name = "radioButton4";
this.radioButton4.Size = new System.Drawing.Size(59, 16);
this.radioButton4.TabIndex = 128;
this.radioButton4.TabStop = true;
this.radioButton4.Text = "暗晶界";
this.radioButton4.UseVisualStyleBackColor = true;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 92);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(0, 12);
this.label3.TabIndex = 131;
//
// panel3
//
this.panel3.Controls.Add(this.radioButton1);
this.panel3.Controls.Add(this.radioButton2);
this.panel3.Location = new System.Drawing.Point(69, 55);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(134, 33);
this.panel3.TabIndex = 132;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(68, 8);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(29, 16);
this.radioButton1.TabIndex = 129;
this.radioButton1.Text = "2";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Checked = true;
this.radioButton2.Location = new System.Drawing.Point(7, 8);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(29, 16);
this.radioButton2.TabIndex = 128;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "1";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 65);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(0, 12);
this.label2.TabIndex = 131;
//
// 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(68, 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(7, 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;
//
// label17
//
this.label17.AutoSize = true;
this.label17.Location = new System.Drawing.Point(6, 43);
this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(0, 12);
this.label17.TabIndex = 124;
//
// 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.panel9.ResumeLayout(false);
this.panel9.PerformLayout();
this.panel8.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
this.panel7.ResumeLayout(false);
this.panel7.PerformLayout();
this.panel6.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit();
this.panel5.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.panel4.ResumeLayout(false);
this.panel4.PerformLayout();
this.panel3.ResumeLayout(false);
this.panel3.PerformLayout();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
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)
{
}
#region 晶界重现方法
ProgressThreadProcClass procClass;
int grainApplygrainboundaries;
int adOutParam0;
int adOutParam1;
double adOutParam2;// = 3;
double adOutParam3;
int adOutParam4;
double adOutParam5;
int adOutParam6;
Mat OrgImg0;
private int getAdOutParam4Value()
{
int adOutParam = 0;
if (this.radioButton6.Checked) adOutParam = 0;
else if (this.radioButton5.Checked) adOutParam = 1;
else if (this.radioButton8.Checked) adOutParam = 2;
else if (this.radioButton7.Checked) adOutParam = 3;
else if (this.radioButton10.Checked) adOutParam = 4;
return adOutParam;
}
private void applyDect()
{
if (this.imageMat == null)
{
return;
}
//string inputImageFile = "原始图片1.jpg";// "j1.JPG";
////char[] inputImageFile2 = inputImageFile.ToCharArray();
grainApplygrainboundaries = this.applyRadioButton1.Checked ? 1 : 0;
adOutParam0 = this.radioButton1/*checkBox3*/.Checked ? 2 : 1;
adOutParam1 = this.radioButton3.Checked ? 2 : 0;
adOutParam2 = this.trackBar1.Value / 10.0;
adOutParam3 = this.trackBar2.Value / 10.0;
adOutParam4 = this.getAdOutParam4Value();
adOutParam5 = this.trackBar3.Value / 10.0;
adOutParam6 = this.radioButton11.Checked ? 0 : 1;
/*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[] */
//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 = PaintDotNet.Camera.Tools.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.Dispose();//待测试
OrgImg0 = 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(this.panel1.BackColor, imageMat.Clone(), adOutParam0, adOutParam1, (int)adOutParam2, (int)adOutParam3, adOutParam4, adOutParam5, adOutParam6);
if (procClass != null) procClass.DismissProgressAction(this);
}
public static Mat runDect(Color phaseColor, Mat OrgImg0, int adOutParam0, int adOutParam1, int adOutParam2, int adOutParam3, int adOutParam4, double adOutParam5, int adOutParam6)
{
Mat GryImg = new Mat();
Mat OrgImg = new Mat();
if (4 == OrgImg0.Channels())
Cv2.CvtColor(OrgImg0, OrgImg, ColorConversionCodes.BGRA2BGR);
else
OrgImg = OrgImg0.Clone();
//转为为灰度
if (3 == OrgImg.Channels() || 4 == OrgImg.Channels())
Cv2.CvtColor(OrgImg, GryImg, ColorConversionCodes.BGR2GRAY/*RGB2GRAY*/);
else
if (1 == OrgImg.Channels())
GryImg = OrgImg.Clone();
else
return null;
//if (0 == m_iStandardImage)
{
//调用算法
OUTsegmsurf RSTss = new OLDcellsegm().mf_segmsurf_progress_auto(GryImg, phaseColor, adOutParam0, adOutParam1, adOutParam2, adOutParam3, adOutParam4, adOutParam5, adOutParam6);
Cv2.CvtColor(RSTss.wat, OrgImg0, ColorConversionCodes.BGR2BGRA);
}
//else OrgImg0/*Mat WAT*/ = new OLDcellsegm().ProFroStandardImage(GryImg, iConnect, phaseColor);
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 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));
//# 保存参数
adOutParam0 = this.radioButton1.Checked ? 2 : 1;
grainBoundryDectModel.m_AdOutParam_0 = adOutParam0;
adOutParam1 = this.radioButton3.Checked ? 2 : 0;
grainBoundryDectModel.m_AdOutParam_1 = adOutParam1;
adOutParam2 = this.trackBar1.Value / 10.0;
grainBoundryDectModel.m_AdOutParam_2 = adOutParam2;
adOutParam3 = this.trackBar2.Value / 10.0;
grainBoundryDectModel.m_AdOutParam_3 = adOutParam3;
adOutParam4 = this.getAdOutParam4Value();
grainBoundryDectModel.m_AdOutParam_4 = adOutParam4;
adOutParam5 = this.trackBar3.Value / 10.0;
grainBoundryDectModel.m_AdOutParam_5 = adOutParam5;
adOutParam6 = this.radioButton11.Checked ? 0 : 1;
grainBoundryDectModel.m_AdOutParam_6 = adOutParam6;
grainBoundryDectModel.grainColor = this.phaseColor.ToArgb();
grainApplygrainboundaries = this.applyRadioButton1.Checked ? 1 : 0;
grainBoundryDectModel.grainApplygrainboundaries = grainApplygrainboundaries;
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;
//# 读取参数
adOutParam0 = grainBoundryDectModel.m_AdOutParam_0;
this.radioButton1.Checked = (adOutParam0 == 2);
adOutParam1 = grainBoundryDectModel.m_AdOutParam_1;
this.radioButton3.Checked = (adOutParam1 == 2);
adOutParam2 = grainBoundryDectModel.m_AdOutParam_2;
this.trackBar1.Value = (int)(adOutParam2 * 10.0);
adOutParam3 = grainBoundryDectModel.m_AdOutParam_3;
this.trackBar2.Value = (int)(adOutParam3 * 10.0);
adOutParam4 = grainBoundryDectModel.m_AdOutParam_4;
int adOutParam = adOutParam4;
switch (adOutParam)
{
case 0:
this.radioButton6.Checked = true;
break;
case 1:
this.radioButton5.Checked = true;
break;
case 2:
this.radioButton8.Checked = true;
break;
case 3:
this.radioButton7.Checked = true;
break;
case 4:
this.radioButton10.Checked = true;
break;
default:
break;
}
adOutParam5 = grainBoundryDectModel.m_AdOutParam_5;
this.trackBar3.Value = (int)(adOutParam5 * 10.0);
adOutParam6 = grainBoundryDectModel.m_AdOutParam_6;
this.radioButton11.Checked = (adOutParam6 == 0);
this.radioButton9.Checked = (adOutParam6 == 1);
this.refreshRadioStatus();
grainApplygrainboundaries = grainBoundryDectModel.grainApplygrainboundaries;
this.applyRadioButton1.Checked = (grainApplygrainboundaries == 1);
this.applyRadioButton2.Checked = (grainApplygrainboundaries != 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 = PaintDotNet.Camera.Tools.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 = PaintDotNet.Camera.Tools.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;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.label3.Enabled = false;
this.radioButton3.Enabled = false;
this.radioButton4.Enabled = false;
this.label1.Enabled = false;
this.trackBar1.Enabled = false;
this.label4.Enabled = false;
this.trackBar2.Enabled = false;
this.label5.Enabled = false;
this.radioButton6.Enabled = false;
this.radioButton5.Enabled = false;
this.radioButton8.Enabled = false;
this.radioButton7.Enabled = false;
this.radioButton10.Enabled = false;
this.label6.Enabled = false;
this.trackBar3.Enabled = false;
this.label7.Enabled = false;
this.radioButton11.Enabled = false;
this.radioButton9.Enabled = false;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
this.label3.Enabled = true;
this.radioButton3.Enabled = true;
this.radioButton4.Enabled = true;
this.label1.Enabled = true;
this.trackBar1.Enabled = true;
this.label4.Enabled = true;
this.trackBar2.Enabled = true;
this.label5.Enabled = true;
this.radioButton6.Enabled = true;
this.radioButton5.Enabled = true;
this.radioButton8.Enabled = true;
this.radioButton7.Enabled = true;
this.radioButton10.Enabled = true;
this.refreshRadioStatus();
}
}
private void refreshRadioStatus()
{
if (radioButton6.Checked)
{
this.label6.Enabled = false;
this.trackBar3.Enabled = false;
this.label7.Enabled = false;
this.radioButton11.Enabled = false;
this.radioButton9.Enabled = false;
}
else if (radioButton5.Checked)
{
this.label6.Enabled = false;
this.trackBar3.Enabled = false;
this.label7.Enabled = false;
this.radioButton11.Enabled = false;
this.radioButton9.Enabled = false;
}
else if (radioButton8.Checked)
{
this.label6.Enabled = true;
this.trackBar3.Enabled = true;
this.label7.Enabled = false;
this.radioButton11.Enabled = false;
this.radioButton9.Enabled = false;
}
else if (radioButton7.Checked)
{
this.label6.Enabled = true;
this.trackBar3.Enabled = true;
this.label7.Enabled = false;
this.radioButton11.Enabled = false;
this.radioButton9.Enabled = false;
}
else if (radioButton10.Checked)
{
this.label6.Enabled = false;
this.trackBar3.Enabled = false;
this.label7.Enabled = true;
this.radioButton11.Enabled = true;
this.radioButton9.Enabled = true;
}
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
this.refreshRadioStatus();
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
this.refreshRadioStatus();
}
private void radioButton8_CheckedChanged(object sender, EventArgs e)
{
this.refreshRadioStatus();
}
private void radioButton7_CheckedChanged(object sender, EventArgs e)
{
this.refreshRadioStatus();
}
private void radioButton10_CheckedChanged(object sender, EventArgs e)
{
this.refreshRadioStatus();
}
}
}