123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151 |
- 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 }
- /// <summary>
- /// 调色板
- /// </summary>
- private ColorsForm colorsFormGrid;
- private Panel panelC;
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- /// <summary>
- /// 主控件
- /// </summary>
- private AppWorkspace appWorkspace;
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 存在视场标记
- /// </summary>
- private bool existViewFlag = false;
- /// <summary>
- /// 选中图片的bitmap
- /// </summary>
- private Bitmap bitmap;
- /// <summary>
- /// 当前选择的图片
- /// </summary>
- private Mat mat;
- /// <summary>
- /// 用于get处理后的图像
- /// </summary>
- private Mat phaseMat;
- /// <summary>
- /// 用于get处理后的图像的颜色
- /// </summary>
- private Color phaseColor;
- private int menuId;
- /// <summary>
- /// 是否显示视场
- /// </summary>
- Boolean ShowDrawClassView = false;
- /// <summary>
- /// 起始点
- /// </summary>
- private Point startPoint = new Point(-1, -1);
- /// <summary>
- /// 是否绘制了起始点
- /// </summary>
- private bool drawedStartPoint = false;
- /// <summary>
- /// 结束点
- /// </summary>
- private Point endPoint = new Point(-1, -1);
- //1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界)
- /// <summary>
- /// 辅助线集成 20720 【专用分析-晶粒度】4290-仲裁法,晶界重现后,在晶界编辑页面没有把网格带过去
- /// </summary>
- private GrainSize.GuideSizeArLawClass guide2Class;
- /// <summary>
- /// 辅助线集成
- /// </summary>
- private GrainSizeGuideClass guideClass;
- public object SelectedItem;
- /// <summary>
- /// 操作类型
- /// 0,没有操作 1,折线添加 2,直线添加
- /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
- /// </summary>
- private int pointKtype = 0;
- /// <summary>
- /// 折线点的集合
- /// </summary>
- public List<PointF> pointFloatArray = new List<PointF>();
- /// <summary>
- /// 外接矩形,或者是计算的矩形
- /// </summary>
- protected RectangleF rectangle = new RectangleF(/*pointFloatArray 0, 1,,,, 2, 3*/);
- #region 实现撤销、恢复、重置的功能
- /// <summary>
- /// 当前操作在OperationsList的位置,用于判断是否可以撤销、恢复、重置
- /// </summary>
- private int OperationIndex = -1;
- /// <summary>
- /// 将 操作类型的集合放入一个List,通过OperationIndex读取当前操作位置
- /// </summary>
- private List<int> OperationKtypeList = new List<int>();
- /// <summary>
- /// 将 折线(/直线)点的集合(/外接矩形的xywh)放入一个List,通过OperationIndex读取当前操作位置
- /// </summary>
- private List<PointF[]> OperationsList = new List<PointF[]>();
- /// <summary>
- /// 保存晶界重现运算的结果
- /// </summary>
- 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;
- /// <summary>
- /// 返回当前选择的图片内容
- /// </summary>
- /// <returns></returns>
- private DocumentWorkspace getCurrentWorkspace()
- {
- return this.appWorkspace.DocumentWorkspaces[focusedItemIndex];
- }
- public GrainSize.GuideSizeArLawClass Guide2Class
- {
- set
- {
- this.guide2Class = value;
- }
- }
- public GrainSizeGuideClass GuideClass
- {
- set
- {
- this.guideClass = value;
- }
- }
- /// <summary>
- /// PanelC的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- /// <summary>
- /// 颜色改变时改变相的颜色
- /// </summary>
- 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();
- }
- /// <summary>
- /// 提取二值化的透明通道并赋值
- /// </summary>
- /// <param name="t"></param>
- /// <param name="position"></param>
- private unsafe void ForeachFunctionByteForWhole4B(Vec4b* t, int* position)
- {
- if (t->Item3 > 0)
- dstBinary.Set(position[0], position[1], dstVec4b);
- }
- /// <summary>
- /// 添加参数改变的监听
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 添加操作数据到List集合中,并刷新操作按钮的状态
- /// </summary>
- /// <param name="addKtype"></param>
- /// <param name="pointFs"></param>
- 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();
- }
- /// <summary>
- /// 根据OperationIndex去掉已经撤销的操作记录
- /// </summary>
- 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);
- }
- }
- }
- /// <summary>
- /// 刷新操作按钮的状态
- /// </summary>
- 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 矩形拖动
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- }
- /// <summary>
- /// 鼠标抬起
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<PointF> pointOperationArray = new List<PointF>();
- 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<PointF> pointOperationArray = new List<PointF>();
- 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<PointF> pointOperationArray = new List<PointF>();
- 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
- /// <summary>
- /// 画布绘制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 绘制
- /// </summary>
- 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);
- }
- /// <summary>
- /// 折线添加
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 直线添加
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 用于get处理后的图像
- /// </summary>
- public Mat PhaseMat
- {
- get
- {
- return this.phaseMat;
- }
- set
- {
- this.phaseMat = value;
- }
- }
- /// <summary>
- /// 用于get处理后的图像相的颜色
- /// </summary>
- public Color PhaseColor
- {
- get
- {
- return this.phaseColor;
- }
- set
- {
- this.phaseColor = value;
- }
- }
- /// <summary>
- /// 矩形删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 椭圆删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 圆形删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// 多边形删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();//##################################
- }
- /// <summary>
- /// 撤销按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<Vec4b>(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<byte>(point[0], point[1]));
- // GryImg.Set<byte>(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.SettingModel.GrainBoundryDectModel>(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<Base.SettingModel.GrainBoundryDectModel>(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.SettingModel.GrainBoundryDectModel>(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]);
- }
- /// <summary>
- /// 根据当前操作位置处理图片,并刷新操作按钮状态
- /// </summary>
- /// <param name="OperationTag"></param>
- 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();
- }
- /// <summary>
- /// 操作-重置
- /// </summary>
- private void resetOperationsAction()
- {
- this.OperationIndex = -1;
- this.RefreshOperationsToIndex();
- this.RefreshOperationsButtons();
- }
- /// <summary>
- /// 操作-重置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void resetButton_Click(object sender, EventArgs e)
- {
- if (PhaseModel0MatCopy != null)
- {
- this.documentWorkspace.PhaseModels[0].mat = PhaseModel0MatCopy.Clone();
- this.documentWorkspace.Refresh();
- }
- this.resetOperationsAction();
- }
- /// <summary>
- /// 操作-撤销
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void undoButton_Click(object sender, EventArgs e)
- {
- if (this.OperationIndex >= 0)
- {
- this.RefreshMatsToIndex(this.OperationIndex - 1);
- }
- else
- this.undoButton.Enabled = false;
- }
- /// <summary>
- /// 操作-恢复
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- }
- }
|