12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760 |
- using OpenCvSharp;
- using PaintDotNet.Adjust;
- using PaintDotNet.Base.Functionodel;
- using PaintDotNet.CustomControl;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using Point = System.Drawing.Point;
- using PaintDotNet.Annotation;
- using System.Linq;
- using Metis.ParameterSet;
- using PaintDotNet.Base.CommTool;
- namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
- {
- internal class GrainBinaryBoundaryEditingDialog : Form
- {
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- /// <summary>
- /// 主控件
- /// </summary>
- private AppWorkspace appWorkspace;
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 选中图片的mat
- /// </summary>
- private Mat imageMat;
- ///// <summary>
- ///// 用于get处理后的图像
- ///// </summary>
- //private Mat phaseMat;
- /// <summary>
- /// 辅助线集成
- /// </summary>
- private GrainSizeGuideClass guideClass;
- public object SelectedItem;
- Color phaseColor;
- Mat phaseMatCopy = new Mat();
- /// <summary>
- /// 当前处理的程序
- /// </summary>
- private Data.Action.Action911 action = new Data.Action.Action911();
- /// <summary>
- /// 起始点
- /// </summary>
- private Point startPoint = new Point(-1, -1);
- /// <summary>
- /// 是否绘制了起始点
- /// </summary>
- private bool drawedStartPoint = false;
- /// <summary>
- /// 结束点
- /// </summary>
- private Point endPoint = new Point(-1, -1);
- ///// <summary>
- ///// 折线点的集合
- ///// </summary>
- //public List<Point> pointArray = new List<Point>();
- /// <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();
- #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>
- /// 将 线宽的数据放入一个List,通过OperationIndex读取当前操作位置
- /// </summary>
- private List<int> OperationsLineWidthList = new List<int>();
- /// <summary>
- /// 保存晶界重现运算的结果
- /// </summary>
- private Mat PhaseModel0MatCopy;
- #endregion
- /// <summary>
- /// 一些方法用到了微米换算
- /// </summary>
- private double ruleValue = 1.0;
- /// <summary>
- /// 是否显示视场
- /// </summary>
- Boolean ShowDrawClassView = true;
- private GroupBox groupBox1;
- private GroupBox groupBox2;
- 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 TriangleTrackBar trackBar2;
- private TextBox textBox1;
- private Label label1;
- private TrackBar trackBar1;
- private GroupBox groupBox4;
- private Panel panel2;
- private RadioButton radioButton6;
- private RadioButton radioButton5;
- private TriangleTrackBar triangleTrackBar1;
- private Label label4;
- private Label label3;
- private Panel panel1;
- private RadioButton radioButton4;
- private RadioButton radioButton3;
- private RadioButton radioButton2;
- private RadioButton radioButton1;
- private Label label2;
- private NumericUpDown numericUpDown2;
- private NumericUpDown numericUpDown1;
- private Button button9;
- private Button undoButton;
- private Button redoButton;
- private Button resetButton;
- private GroupBox groupBox7;
- public GrainSizeGuideClass GuideClass
- {
- set
- {
- this.guideClass = value;
- }
- }
- public GrainBinaryBoundaryEditingDialog(AppWorkspace appWorkspace, int focusedItemIndex, Color phaseColor, Mat phaseMat, Boolean ShowDrawClassView = true, double ruleValue = 1.0)
- {
- this.ShowDrawClassView = ShowDrawClassView;
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- //
- //初始化图像控件
- //
- this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
- this.documentWorkspace.Dock = DockStyle.Fill;
- this.documentWorkspace.HookMouseEvents();
- this.documentWorkspace.AuxiliaryLineEnabled = false;
- this.documentWorkspace.Visible = false;
- this.documentWorkspace.panel.MouseDown += OnMouseDown;
- this.documentWorkspace.panel.Paint += Panel_Paint;
- this.documentWorkspace.panel.MouseMove += onMouseMove;
- this.documentWorkspace.panel.MouseUp += onMouseUp;
- this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);
- this.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);
- //获取
- this.ruleValue = ruleValue;//this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetRuler(MeasurementUnit.Micron)
- //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
- //double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- this.phaseColor = phaseColor;
- {
- //
- //初始化相
- //
- 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.Binarization.text");
- this.documentWorkspace.PhaseModels.Add(model);
- }
- this.documentWorkspace.PhaseModels[0].mat = phaseMat;
- PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
- this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
- this.documentWorkspace.Refresh();
- 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();
- }
- /// <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.OperationsLineWidthList.Add(this.trackBar1.Value);
- 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);
- this.OperationsLineWidthList.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/* && e.Clicks == 1*/&& this.pointKtype >= 1)
- {
- if (!drawedStartPoint)
- {
- drawedStartPoint = true;
- startPoint = new Point((int)point1.X, (int)point1.Y);
- return;
- }
- // 折线添加
- if (this.pointKtype == 1)
- {
- }
- // 直线添加
- else if (this.pointKtype == 2)
- {
- }
- // 多边形删除
- else if (this.pointKtype == 11)
- {
- }
- }
- }
- else if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
- {
- if (!drawedStartPoint)
- {
- drawedStartPoint = true;
- startPoint = new Point((int)point1.X, (int)point1.Y);
- return;
- }
- }
- else
- return;
- // 右键完成操作
- if (e.Button == MouseButtons.Right)
- {
- }
- }
- /// <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.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)
- {
- //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(/*(int)*/point1.X, /*(int)*/point1.Y));
- endPoint = new Point((int)point1.X, (int)point1.Y);
- //List<PointF> pointFArray = new List<PointF>();
- //foreach (var item in pointArray)
- //{
- // pointFArray.Add(new PointF(item.X, item.Y));
- //}
- this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFloatArray);
- this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
- 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(/*(int)*/point1.X, /*(int)*/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/* = phaseMat*/ = PaintDotNet.Camera.Tools.ToMat(newBit);
- this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
- 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)));
- this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
- 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);
- this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
- 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 Point((int)point1.X, (int)point1.Y));
- if (!drawedStartPoint)
- {
- drawedStartPoint = true;
- 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);
- this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
- 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>
- /// surfaceBox双击事件
- /// 目前是参考AxioVision
- /// 应该是把每次选的点都取最高和最低的BGR
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private unsafe void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- /// <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 ((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 && drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1)
- {
- Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
- //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, this.trackBar1.Value);
- g.DrawLines(pen, pointFloatArray.ToArray());
- pen.Dispose();
- }
- }
- private void InitializeLanguageText()
- {
- this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
- this.button9.Text = PdnResources.GetString("CommonAction.Undo");
- this.button2.Text = PdnResources.GetString("Menu.File.Close.Text");
- this.button1.Text = PdnResources.GetString("Form.OkButton.Text");
- this.groupBox2.Text = PdnResources.GetString("Menu.BinaryAction.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.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.button4.Text = PdnResources.GetString("Menu.Lineadd.text");
- this.button3.Text = PdnResources.GetString("Menu.Polylineadd.text");
- this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
- this.groupBox4.Text = PdnResources.GetString("Menu.Particlescreening.text");
- this.radioButton6.Text = PdnResources.GetString("Menu.Pixel.text");
- this.radioButton5.Text = PdnResources.GetString("Menu.Micron.text");
- this.label4.Text = PdnResources.GetString("Menu.filterunit.text") + ":";
- this.label3.Text = PdnResources.GetString("Menu.range.text") + ":";
- this.radioButton4.Text = PdnResources.GetString("Menu.Aspectratio.text");
- this.radioButton3.Text = PdnResources.GetString("Menu.Maximumcaliperdiameter.text");
- this.radioButton2.Text = PdnResources.GetString("Menu.Arearatio.text");
- this.radioButton1.Text = PdnResources.GetString("Menu.area.text");
- this.label2.Text = PdnResources.GetString("Menu.Filterparams.text") + ":";
- this.Text = PdnResources.GetString("Menu.filter.text");
- this.resetButton.Text = "重置";
- this.redoButton.Text = "恢复";
- this.undoButton.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.undoButton = new System.Windows.Forms.Button();
- this.redoButton = new System.Windows.Forms.Button();
- this.resetButton = new System.Windows.Forms.Button();
- this.button8 = new System.Windows.Forms.Button();
- this.trackBar1 = new System.Windows.Forms.TrackBar();
- this.button7 = new System.Windows.Forms.Button();
- this.trackBar2 = new PaintDotNet.CustomControl.TriangleTrackBar();
- this.button6 = new System.Windows.Forms.Button();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.button5 = new System.Windows.Forms.Button();
- this.label1 = new System.Windows.Forms.Label();
- this.button4 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.groupBox7 = new System.Windows.Forms.GroupBox();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
- this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
- this.panel2 = new System.Windows.Forms.Panel();
- this.radioButton6 = new System.Windows.Forms.RadioButton();
- this.radioButton5 = new System.Windows.Forms.RadioButton();
- this.triangleTrackBar1 = new PaintDotNet.CustomControl.TriangleTrackBar();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.panel1 = new System.Windows.Forms.Panel();
- this.radioButton4 = new System.Windows.Forms.RadioButton();
- this.radioButton3 = new System.Windows.Forms.RadioButton();
- this.radioButton2 = new System.Windows.Forms.RadioButton();
- this.radioButton1 = new System.Windows.Forms.RadioButton();
- this.label2 = new System.Windows.Forms.Label();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
- this.groupBox4.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
- this.panel2.SuspendLayout();
- this.panel1.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- 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.Location = new System.Drawing.Point(468, 13);
- this.button9.Name = "button9";
- this.button9.Size = new System.Drawing.Size(91, 26);
- this.button9.TabIndex = 3;
- this.button9.UseVisualStyleBackColor = true;
- this.button9.Visible = false;
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(694, 13);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(91, 26);
- this.button2.TabIndex = 1;
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(582, 13);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(91, 26);
- this.button1.TabIndex = 0;
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.undoButton);
- this.groupBox2.Controls.Add(this.redoButton);
- this.groupBox2.Controls.Add(this.resetButton);
- this.groupBox2.Controls.Add(this.button8);
- this.groupBox2.Controls.Add(this.trackBar1);
- this.groupBox2.Controls.Add(this.button7);
- this.groupBox2.Controls.Add(this.trackBar2);
- this.groupBox2.Controls.Add(this.button6);
- this.groupBox2.Controls.Add(this.textBox1);
- this.groupBox2.Controls.Add(this.button5);
- this.groupBox2.Controls.Add(this.label1);
- this.groupBox2.Controls.Add(this.button4);
- this.groupBox2.Controls.Add(this.button3);
- this.groupBox2.Location = new System.Drawing.Point(12, 347);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(233, 218);
- this.groupBox2.TabIndex = 1;
- this.groupBox2.TabStop = false;
- //
- // undoButton
- //
- this.undoButton.Enabled = false;
- this.undoButton.Location = new System.Drawing.Point(153, 175);
- this.undoButton.Name = "undoButton";
- this.undoButton.Size = new System.Drawing.Size(59, 26);
- this.undoButton.TabIndex = 24;
- this.undoButton.UseVisualStyleBackColor = true;
- this.undoButton.Click += new System.EventHandler(this.undoButton_Click);
- //
- // redoButton
- //
- this.redoButton.Enabled = false;
- this.redoButton.Location = new System.Drawing.Point(85, 175);
- this.redoButton.Name = "redoButton";
- this.redoButton.Size = new System.Drawing.Size(59, 26);
- this.redoButton.TabIndex = 23;
- this.redoButton.UseVisualStyleBackColor = true;
- this.redoButton.Click += new System.EventHandler(this.redoButton_Click);
- //
- // resetButton
- //
- this.resetButton.Enabled = false;
- this.resetButton.Location = new System.Drawing.Point(18, 175);
- this.resetButton.Name = "resetButton";
- this.resetButton.Size = new System.Drawing.Size(59, 26);
- this.resetButton.TabIndex = 22;
- this.resetButton.UseVisualStyleBackColor = true;
- this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
- //
- // button8
- //
- this.button8.Location = new System.Drawing.Point(134, 134);
- 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);
- //
- // trackBar1
- //
- this.trackBar1.AutoSize = false;
- this.trackBar1.Location = new System.Drawing.Point(107, 52);
- this.trackBar1.Maximum = 50;
- this.trackBar1.Minimum = 1;
- this.trackBar1.Name = "trackBar1";
- this.trackBar1.Size = new System.Drawing.Size(104, 31);
- this.trackBar1.TabIndex = 21;
- this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar1.Value = 1;
- this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
- //
- // button7
- //
- this.button7.Location = new System.Drawing.Point(27, 134);
- 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);
- //
- // trackBar2
- //
- this.trackBar2.Location = new System.Drawing.Point(108, 52);
- this.trackBar2.Maximum = 50;
- this.trackBar2.Minimum = 1;
- this.trackBar2.Name = "trackBar2";
- this.trackBar2.Size = new System.Drawing.Size(102, 24);
- this.trackBar2.TabIndex = 20;
- this.trackBar2.Value = 1;
- this.trackBar2.Visible = false;
- //
- // button6
- //
- this.button6.Location = new System.Drawing.Point(134, 90);
- 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);
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(68, 52);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(32, 21);
- this.textBox1.TabIndex = 19;
- this.textBox1.Text = "1";
- this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(27, 90);
- 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);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(28, 56);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(0, 12);
- this.label1.TabIndex = 18;
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(135, 18);
- 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, 18);
- 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);
- //
- // groupBox7
- //
- 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.numericUpDown2);
- this.groupBox4.Controls.Add(this.numericUpDown1);
- this.groupBox4.Controls.Add(this.panel2);
- this.groupBox4.Controls.Add(this.triangleTrackBar1);
- this.groupBox4.Controls.Add(this.label4);
- this.groupBox4.Controls.Add(this.label3);
- this.groupBox4.Controls.Add(this.panel1);
- this.groupBox4.Controls.Add(this.label2);
- this.groupBox4.Location = new System.Drawing.Point(12, 63);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Size = new System.Drawing.Size(233, 278);
- this.groupBox4.TabIndex = 2;
- this.groupBox4.TabStop = false;
- //
- // numericUpDown2
- //
- this.numericUpDown2.DecimalPlaces = 2;
- this.numericUpDown2.Increment = new decimal(new int[] {
- 1,
- 0,
- 0,
- 131072});
- this.numericUpDown2.Location = new System.Drawing.Point(131, 164);
- this.numericUpDown2.Maximum = new decimal(new int[] {
- 2147483647,
- 0,
- 0,
- 0});
- this.numericUpDown2.Name = "numericUpDown2";
- this.numericUpDown2.Size = new System.Drawing.Size(60, 21);
- this.numericUpDown2.TabIndex = 21;
- this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
- //
- // numericUpDown1
- //
- this.numericUpDown1.DecimalPlaces = 2;
- this.numericUpDown1.Increment = new decimal(new int[] {
- 1,
- 0,
- 0,
- 131072});
- this.numericUpDown1.Location = new System.Drawing.Point(66, 164);
- this.numericUpDown1.Maximum = new decimal(new int[] {
- 2147483647,
- 0,
- 0,
- 0});
- this.numericUpDown1.Name = "numericUpDown1";
- this.numericUpDown1.Size = new System.Drawing.Size(60, 21);
- this.numericUpDown1.TabIndex = 20;
- this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
- //
- // panel2
- //
- this.panel2.Controls.Add(this.radioButton6);
- this.panel2.Controls.Add(this.radioButton5);
- this.panel2.Location = new System.Drawing.Point(66, 201);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(127, 30);
- this.panel2.TabIndex = 19;
- //
- // radioButton6
- //
- this.radioButton6.AutoSize = true;
- this.radioButton6.Location = new System.Drawing.Point(60, 7);
- this.radioButton6.Name = "radioButton6";
- this.radioButton6.Size = new System.Drawing.Size(14, 13);
- this.radioButton6.TabIndex = 2;
- this.radioButton6.TabStop = true;
- this.radioButton6.UseVisualStyleBackColor = true;
- this.radioButton6.CheckedChanged += new System.EventHandler(this.radioButton6_CheckedChanged);
- //
- // radioButton5
- //
- this.radioButton5.AutoSize = true;
- this.radioButton5.Checked = true;
- this.radioButton5.Location = new System.Drawing.Point(7, 7);
- this.radioButton5.Name = "radioButton5";
- this.radioButton5.Size = new System.Drawing.Size(14, 13);
- this.radioButton5.TabIndex = 1;
- this.radioButton5.TabStop = true;
- this.radioButton5.UseVisualStyleBackColor = true;
- this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
- //
- // triangleTrackBar1
- //
- this.triangleTrackBar1.Location = new System.Drawing.Point(66, 164);
- this.triangleTrackBar1.Maximum = 10000;
- this.triangleTrackBar1.Minimum = 0;
- this.triangleTrackBar1.Name = "triangleTrackBar1";
- this.triangleTrackBar1.Size = new System.Drawing.Size(102, 24);
- this.triangleTrackBar1.TabIndex = 18;
- this.triangleTrackBar1.Value = 0;
- this.triangleTrackBar1.Visible = false;
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(9, 208);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(0, 12);
- this.label4.TabIndex = 3;
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(33, 168);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(0, 12);
- this.label3.TabIndex = 2;
- //
- // panel1
- //
- this.panel1.Controls.Add(this.radioButton4);
- this.panel1.Controls.Add(this.radioButton3);
- this.panel1.Controls.Add(this.radioButton2);
- this.panel1.Controls.Add(this.radioButton1);
- this.panel1.Location = new System.Drawing.Point(66, 28);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(121, 122);
- this.panel1.TabIndex = 1;
- //
- // radioButton4
- //
- this.radioButton4.AutoSize = true;
- this.radioButton4.Location = new System.Drawing.Point(13, 97);
- this.radioButton4.Name = "radioButton4";
- this.radioButton4.Size = new System.Drawing.Size(14, 13);
- this.radioButton4.TabIndex = 3;
- this.radioButton4.TabStop = true;
- this.radioButton4.UseVisualStyleBackColor = true;
- this.radioButton4.CheckedChanged += new System.EventHandler(this.radioButton4_CheckedChanged);
- //
- // radioButton3
- //
- this.radioButton3.AutoSize = true;
- this.radioButton3.Location = new System.Drawing.Point(13, 67);
- this.radioButton3.Name = "radioButton3";
- this.radioButton3.Size = new System.Drawing.Size(14, 13);
- this.radioButton3.TabIndex = 2;
- this.radioButton3.TabStop = true;
- this.radioButton3.UseVisualStyleBackColor = true;
- this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
- //
- // radioButton2
- //
- this.radioButton2.AutoSize = true;
- this.radioButton2.Location = new System.Drawing.Point(13, 37);
- this.radioButton2.Name = "radioButton2";
- this.radioButton2.Size = new System.Drawing.Size(14, 13);
- this.radioButton2.TabIndex = 1;
- this.radioButton2.TabStop = true;
- this.radioButton2.UseVisualStyleBackColor = true;
- this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
- //
- // radioButton1
- //
- this.radioButton1.AutoSize = true;
- this.radioButton1.Checked = true;
- this.radioButton1.Location = new System.Drawing.Point(13, 7);
- this.radioButton1.Name = "radioButton1";
- this.radioButton1.Size = new System.Drawing.Size(14, 13);
- this.radioButton1.TabIndex = 0;
- this.radioButton1.TabStop = true;
- this.radioButton1.UseVisualStyleBackColor = true;
- this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(9, 35);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(0, 12);
- this.label2.TabIndex = 0;
- //
- // GrainBinaryBoundaryEditingDialog
- //
- this.ClientSize = new System.Drawing.Size(832, 577);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox7);
- this.Controls.Add(this.groupBox1);
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "GrainBinaryBoundaryEditingDialog";
- this.Load += new System.EventHandler(this.GrainBinaryBoundaryEditingDialog_Load);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
- this.groupBox4.ResumeLayout(false);
- this.groupBox4.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
- this.panel2.ResumeLayout(false);
- this.panel2.PerformLayout();
- this.panel1.ResumeLayout(false);
- this.panel1.PerformLayout();
- this.ResumeLayout(false);
- }
- /// <summary>
- /// 折线添加
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- 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)
- {
- 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.phaseMatCopy = this.documentWorkspace.PhaseModels[0].mat;
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- /// <summary>
- /// 用于get处理后的图像
- /// </summary>
- public Mat PhaseMat
- {
- get
- {
- return this.phaseMatCopy;
- }
- set
- {
- this.phaseMatCopy = value;
- }
- }
- /// <summary>
- /// 矩形删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button7_Click(object sender, EventArgs e)
- {
- 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)
- {
- 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)
- {
- 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)
- {
- 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.Close();
- }
- /// <summary>
- /// 线宽改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- int valueT;
- if (!int.TryParse(textBox1.Text, out valueT))
- return;
- if (this.trackBar1.Minimum > valueT)
- valueT = this.trackBar1.Minimum;
- if (this.trackBar1.Maximum < valueT)
- valueT = this.trackBar1.Maximum;
- this.trackBar1.Value = valueT;
- //this.textBox1.Text = valueT + "";
- }
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- this.textBox1.Text = this.trackBar1.Value + "";
- }
- /// <summary>
- /// 范围改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown1_ValueChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- /// <summary>
- /// 范围改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown2_ValueChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- /// <summary>
- /// 筛选单位改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton5_CheckedChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- private void radioButton6_CheckedChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- /// <summary>
- /// 筛选参数改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- private void radioButton3_CheckedChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- private void radioButton4_CheckedChanged(object sender, EventArgs e)
- {
- this.applyChangedAction();
- }
- protected static string ParamKey_FilterParameters = "FilterParameters";//筛选参数
- protected static string ParamKey_UnitParameters = "UnitParameters";//筛选单位
- protected static string ParamKey_Scope1 = "Scope1";//数值范围
- protected static string ParamKey_Scope2 = "Scope2";//数值范围
- protected static string ParamKey_LineWidth = "LineWidth";//线宽
- /// <summary>
- /// 保存参数的key,value和type
- /// </summary>
- /// <param name="param_key"></param>
- /// <param name="param_value"></param>
- /// <param name="param_type"></param>
- private void saveParamValue(string param_key, string param_value, int param_type)
- {
- bool foundItem = false;
- //string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryConfig\\BinaryEditModel.xml";
- //GrainSizeAnalysisModel analysisModelXml;
- //if (!System.IO.File.Exists(xmlFilePath))
- // analysisModelXml = new GrainSizeAnalysisModel();
- //else
- // analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
- ////this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
- //foreach (var item in analysisModelXml.ListParam)
- // item.setValue();
- //if (!foundItem)
- //{
- // GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
- // analysisItem.menuId = this.menuId;
- // analysisItem.param_key = param_key;
- // analysisItem.param_type = param_type;
- // analysisItem.param_value = param_value;
- // analysisItem.setValue();
- // this.analysisModel.ListParam.Add(analysisItem);
- //}
- }
- private void applyChangedAction()
- {
- foreach (Base.Args args in action.Lists)
- {
- switch (args.Key)
- {
- case "FilterParameters"://筛选参数
- {
- if (radioButton1.Checked)
- args.Value = Base.Enum.FilterParameters.Area;
- else if (radioButton2.Checked)
- args.Value = Base.Enum.FilterParameters.AreaRatio;
- else if (radioButton3.Checked)
- args.Value = Base.Enum.FilterParameters.LongTrail;
- else if (radioButton4.Checked)
- args.Value = Base.Enum.FilterParameters.AspectRatio;
- }
- break;
- case "UnitParameters"://筛选单位
- {
- if (radioButton5.Checked)
- args.Value = MeasurementUnit.Micron;
- else if (radioButton6.Checked)
- args.Value = MeasurementUnit.Pixel;
- }
- break;
- case "Scope"://数值范围
- {
- List<double> oneL = new List<double>();
- oneL.Add((double)this.numericUpDown1.Value);
- oneL.Add((double)this.numericUpDown2.Value);
- args.Value = oneL;
- }
- break;
- default:
- break;
- }
- }
- this.applyButtonImpl(null, null);
- }
- /// <summary>
- /// 应用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void applyButtonImpl(object sender, EventArgs e)
- {
- //如果有选中的相
- List<PhaseModel> phases = this.documentWorkspace.PhaseModels;
- if (phases.Count > 0)
- {
- List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
- for (int i = 0; i < phases.Count; i++)
- {
- PhaseModel model = new PhaseModel();
- model.choise = phases[i].choise;
- model.color = phaseColor.ToArgb();// phases[i].color;
- model.name = phases[i].name;
- model.position = phases[i].position;
- model.mat = new OpenCvSharp.Mat();
- phaseMatCopy.CopyTo(model.mat);
- //phases[i].mat.CopyTo(model.mat);//避免碎屑删除不可逆的问题
- phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
- this.documentWorkspace.Refresh();
- }
- if (PhaseModel0MatCopy != null)
- {
- PhaseModel0MatCopy.Dispose();
- PhaseModel0MatCopy = null;
- }
- PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
- this.resetOperationsAction();
- }
- else
- {
- OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
- Document doc = Document.FromMat(mat);
- this.documentWorkspace.Document = doc;
- this.documentWorkspace.Refresh();
- }
- }
- /// <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, this.OperationsLineWidthList[i]);
- 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, this.OperationsLineWidthList[i]);
- 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.PhaseModels[0].mat.CopyTo(phaseMatCopy);
- 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 redoButton_Click(object sender, EventArgs e)
- {
- if (this.OperationIndex < this.OperationKtypeList.Count - 1)
- {
- this.RefreshMatsToIndex(this.OperationIndex + 1);
- }
- else
- this.redoButton.Enabled = false;
- }
- /// <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;
- }
- private void GrainBinaryBoundaryEditingDialog_Load(object sender, EventArgs e)
- {
- }
- }
- }
|