GrainBoundaryEditingDialog .cs 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151
  1. using OpenCvSharp;
  2. using PaintDotNet.Adjust;
  3. using PaintDotNet.Annotation;
  4. using PaintDotNet.Base.Functionodel;
  5. using PaintDotNet.CustomControl;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.Drawing.Drawing2D;
  10. using System.Linq;
  11. using System.Windows.Forms;
  12. using Point = System.Drawing.Point;
  13. namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
  14. {
  15. internal class GrainBoundaryEditingDialog : Form
  16. {
  17. public static string ParamKey_GrainApplygrainboundaries = "GrainApplygrainboundaries";//是否应用(计算晶界)
  18. public static string ParamKey_GrainM_iStandardImage = "GrainM_iStandardImage";//标准图像 this.radioButton1.Checked? 1 : 0;
  19. public static string ParamKey_GrainIConnect = "GrainIConnect";//强制连接 this.checkBox4.Checked? 1 : 0;
  20. public static string ParamKey_GrainSigma = "GrainSigma";//西格玛 如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数 double.TryParse(textBox6.Text, out sigma)
  21. public static string ParamKey_GrainDark = "GrainDark";//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度 dark = this.comboBox2.SelectedIndex;
  22. public static string ParamKey_GrainSmooth_type = "GrainSmooth_type";//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1 smooth_type = this.comboBox3.SelectedIndex;
  23. public static string ParamKey_GrainEnhance = "GrainDisplaysections";//是否增强晶界?不增强:enhance=0; 增强: enhance=1 enhance = this.checkBox2.Checked? 1 : 0
  24. public static string ParamKey_GrainCell_size1 = "GrainCell_size1";//晶界大小
  25. public static string ParamKey_GrainCell_size2 = "GrainCell_size2";//晶界大小 cell_size = new double[2] { (double) numericUpDown1.Value, (double) numericUpDown2.Value }
  26. /// <summary>
  27. /// 调色板
  28. /// </summary>
  29. private ColorsForm colorsFormGrid;
  30. private Panel panelC;
  31. /// <summary>
  32. /// 公共按钮
  33. /// </summary>
  34. private CommonControlButtons commonControlButtons;
  35. /// <summary>
  36. /// 主控件
  37. /// </summary>
  38. private AppWorkspace appWorkspace;
  39. private DocumentWorkspaceWindow documentWorkspace;
  40. /// <summary>
  41. /// 存在视场标记
  42. /// </summary>
  43. private bool existViewFlag = false;
  44. /// <summary>
  45. /// 选中图片的bitmap
  46. /// </summary>
  47. private Bitmap bitmap;
  48. /// <summary>
  49. /// 当前选择的图片
  50. /// </summary>
  51. private Mat mat;
  52. /// <summary>
  53. /// 用于get处理后的图像
  54. /// </summary>
  55. private Mat phaseMat;
  56. /// <summary>
  57. /// 用于get处理后的图像的颜色
  58. /// </summary>
  59. private Color phaseColor;
  60. private int menuId;
  61. /// <summary>
  62. /// 是否显示视场
  63. /// </summary>
  64. Boolean ShowDrawClassView = false;
  65. /// <summary>
  66. /// 起始点
  67. /// </summary>
  68. private Point startPoint = new Point(-1, -1);
  69. /// <summary>
  70. /// 是否绘制了起始点
  71. /// </summary>
  72. private bool drawedStartPoint = false;
  73. /// <summary>
  74. /// 结束点
  75. /// </summary>
  76. private Point endPoint = new Point(-1, -1);
  77. //1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界)
  78. /// <summary>
  79. /// 辅助线集成 20720 【专用分析-晶粒度】4290-仲裁法,晶界重现后,在晶界编辑页面没有把网格带过去
  80. /// </summary>
  81. private GrainSize.GuideSizeArLawClass guide2Class;
  82. /// <summary>
  83. /// 辅助线集成
  84. /// </summary>
  85. private GrainSizeGuideClass guideClass;
  86. public object SelectedItem;
  87. /// <summary>
  88. /// 操作类型
  89. /// 0,没有操作 1,折线添加 2,直线添加
  90. /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
  91. /// </summary>
  92. private int pointKtype = 0;
  93. /// <summary>
  94. /// 折线点的集合
  95. /// </summary>
  96. public List<PointF> pointFloatArray = new List<PointF>();
  97. /// <summary>
  98. /// 外接矩形,或者是计算的矩形
  99. /// </summary>
  100. protected RectangleF rectangle = new RectangleF(/*pointFloatArray 0, 1,,,, 2, 3*/);
  101. #region 实现撤销、恢复、重置的功能
  102. /// <summary>
  103. /// 当前操作在OperationsList的位置,用于判断是否可以撤销、恢复、重置
  104. /// </summary>
  105. private int OperationIndex = -1;
  106. /// <summary>
  107. /// 将 操作类型的集合放入一个List,通过OperationIndex读取当前操作位置
  108. /// </summary>
  109. private List<int> OperationKtypeList = new List<int>();
  110. /// <summary>
  111. /// 将 折线(/直线)点的集合(/外接矩形的xywh)放入一个List,通过OperationIndex读取当前操作位置
  112. /// </summary>
  113. private List<PointF[]> OperationsList = new List<PointF[]>();
  114. /// <summary>
  115. /// 保存晶界重现运算的结果
  116. /// </summary>
  117. private Mat PhaseModel0MatCopy;
  118. #endregion
  119. private GroupBox groupBox1;
  120. private GroupBox groupBox2;
  121. private GroupBox groupBox3;
  122. private Button button2;
  123. private Button button1;
  124. private Button button3;
  125. private Button button4;
  126. private Button button8;
  127. private Button button7;
  128. private Button button6;
  129. private Button button5;
  130. private Button button9;
  131. private GroupBox groupBox4;
  132. private Panel panel1;
  133. private Label label8;
  134. private NumericUpDown numericUpDown2;
  135. private NumericUpDown numericUpDown1;
  136. private CheckBox checkBox2;
  137. private CheckBox checkBox3;
  138. private CheckBox checkBox4;
  139. private TextBox textBox6;
  140. private Label label7;
  141. private Label label9;
  142. private Label label17;
  143. private ComboBox comboBox3;
  144. private Label label6;
  145. private ComboBox comboBox2;
  146. private Label label1;
  147. private CheckBox checkBox1;
  148. private GroupBox groupBox7;
  149. private RadioButton radioButton2;
  150. private RadioButton radioButton1;
  151. private GroupBox itemsGroupBox;
  152. private Button undoButton;
  153. private Button redoButton;
  154. private Button resetButton;
  155. private Panel panel2;
  156. private RadioButton applyRadioButton2;
  157. private RadioButton applyRadioButton1;
  158. private Label applyLabel;
  159. private int focusedItemIndex;
  160. /// <summary>
  161. /// 返回当前选择的图片内容
  162. /// </summary>
  163. /// <returns></returns>
  164. private DocumentWorkspace getCurrentWorkspace()
  165. {
  166. return this.appWorkspace.DocumentWorkspaces[focusedItemIndex];
  167. }
  168. public GrainSize.GuideSizeArLawClass Guide2Class
  169. {
  170. set
  171. {
  172. this.guide2Class = value;
  173. }
  174. }
  175. public GrainSizeGuideClass GuideClass
  176. {
  177. set
  178. {
  179. this.guideClass = value;
  180. }
  181. }
  182. /// <summary>
  183. /// PanelC的调色板颜色改变
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. private void gridColorChanged(object sender, EventArgs e)
  188. {
  189. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  190. ////更改背景色,触发事件
  191. //if (this.panelC != null)
  192. //{
  193. // this.panelC.BackColor = color;
  194. // //this.ColorPanelChanged(this.panelC);
  195. // this.panelC = null;
  196. // //关闭色板
  197. // this.colorsFormGrid.Close();
  198. // this.PhaseColor = this.panel1.BackColor;
  199. // return;
  200. //}
  201. //更改背景色,触发事件
  202. this.panel1.BackColor = color;
  203. this.documentWorkspace.PhaseModels[0].color = this.panel1.BackColor.ToArgb();
  204. this.PhaseColor = this.panel1.BackColor;
  205. this.runDectForColor();
  206. this.documentWorkspace.Refresh();
  207. //关闭色板
  208. this.colorsFormGrid.Close();
  209. }
  210. private Mat dstBinary = null;
  211. private Vec4b dstVec4b;
  212. /// <summary>
  213. /// 颜色改变时改变相的颜色
  214. /// </summary>
  215. private unsafe void runDectForColor()
  216. {
  217. if (dstBinary != null)
  218. {
  219. dstBinary.Dispose();
  220. dstBinary = null;
  221. }
  222. if (this.documentWorkspace.PhaseModels[0].mat == null)
  223. return;
  224. dstVec4b = new Vec4b(this.PhaseColor.B, this.PhaseColor.G, this.PhaseColor.R, this.PhaseColor.A);
  225. 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));
  226. //如果是rgba
  227. this.documentWorkspace.PhaseModels[0].mat.ForEachAsVec4b(ForeachFunctionByteForWhole4B);
  228. this.documentWorkspace.PhaseModels[0].mat = dstBinary.Clone();
  229. this.documentWorkspace.Refresh();
  230. }
  231. /// <summary>
  232. /// 提取二值化的透明通道并赋值
  233. /// </summary>
  234. /// <param name="t"></param>
  235. /// <param name="position"></param>
  236. private unsafe void ForeachFunctionByteForWhole4B(Vec4b* t, int* position)
  237. {
  238. if (t->Item3 > 0)
  239. dstBinary.Set(position[0], position[1], dstVec4b);
  240. }
  241. /// <summary>
  242. /// 添加参数改变的监听
  243. /// </summary>
  244. /// <param name="sender"></param>
  245. /// <param name="e"></param>
  246. private void GrainSizeStandardDialog_Load(object sender, EventArgs e)
  247. {
  248. this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
  249. this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
  250. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged_1);
  251. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged_1);
  252. this.comboBox3.Text = PdnResources.GetString("Menu.pdenoisingtype.Text");
  253. this.comboBox3.SelectedIndex = 1;
  254. this.comboBox2.Text = PdnResources.GetString("Menu.electthegrainboundarytype.Text");
  255. this.comboBox2.SelectedIndex = 1;
  256. }
  257. public GrainBoundaryEditingDialog(AppWorkspace appWorkspace, int menuId, int focusedItemIndex, Color phaseColor, Mat phaseMat, Boolean ShowDrawClassView = false)
  258. {
  259. this.menuId = menuId;
  260. this.ShowDrawClassView = ShowDrawClassView;
  261. this.focusedItemIndex = focusedItemIndex;
  262. this.appWorkspace = appWorkspace;
  263. this.Load += new System.EventHandler(this.GrainSizeStandardDialog_Load);
  264. this.colorsFormGrid = new ColorsForm();
  265. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  266. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  267. InitializeComponent();
  268. InitializeLanguageText();
  269. //
  270. //初始化图像控件
  271. //
  272. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  273. this.documentWorkspace.Cursor = Cursors.Default;
  274. this.documentWorkspace.Dock = DockStyle.Fill;
  275. this.documentWorkspace.HookMouseEvents();
  276. this.documentWorkspace.AuxiliaryLineEnabled = false;
  277. this.documentWorkspace.Visible = false;
  278. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  279. this.documentWorkspace.panel.Paint += Panel_Paint;
  280. this.documentWorkspace.panel.MouseMove += onMouseMove;
  281. this.documentWorkspace.panel.MouseUp += onMouseUp;
  282. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;//禁止视场移动
  283. this.groupBox7.Controls.Add(documentWorkspace);
  284. //
  285. //初始化操作按钮
  286. //
  287. this.commonControlButtons = new CommonControlButtons();
  288. this.commonControlButtons.Dock = DockStyle.Top;
  289. this.commonControlButtons.Height = 30;
  290. this.commonControlButtons.HideZoomToWindowAndActualSize();
  291. this.groupBox7.Controls.Add(commonControlButtons);
  292. {
  293. //
  294. //初始化相
  295. //
  296. PhaseModel model = new PhaseModel();
  297. model.choise = true;
  298. model.mat = null;
  299. model.color = phaseColor.ToArgb();// Color.Green/*panel2.BackColor*/.ToArgb();
  300. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  301. model.name = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
  302. this.documentWorkspace.PhaseModels.Add(model);
  303. }
  304. if (phaseMat != null)
  305. {
  306. this.documentWorkspace.PhaseModels[0].mat = phaseMat;
  307. PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
  308. this.PhaseColor = phaseColor;
  309. }
  310. else
  311. this.PhaseColor = Color.Red;
  312. this.documentWorkspace.Refresh();
  313. existViewFlag = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList.IsExsitView() && ShowDrawClassView;
  314. this.bitmap = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreateAliasedBitmap();
  315. if (!existViewFlag)
  316. {
  317. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
  318. }
  319. else
  320. {
  321. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GetFullSizeWithRegion());
  322. }
  323. Document document = Document.FromImage(bitmap);
  324. this.documentWorkspace.Document = document;
  325. this.documentWorkspace.Visible = true;
  326. if (ShowDrawClassView)
  327. {
  328. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  329. }
  330. else
  331. {
  332. GraphicsList itemGraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  333. GraphicsList graphicsList = new GraphicsList();
  334. for (int j = 0; j < itemGraphicsList.Count; j++)
  335. {
  336. if (itemGraphicsList[j].objectType != Annotation.Enum.DrawClass.View)
  337. graphicsList.Add(itemGraphicsList[j]);
  338. }
  339. this.documentWorkspace.GraphicsList = graphicsList;
  340. }
  341. InitCommonButtonEvent();
  342. }
  343. /// <summary>
  344. /// 添加操作数据到List集合中,并刷新操作按钮的状态
  345. /// </summary>
  346. /// <param name="addKtype"></param>
  347. /// <param name="pointFs"></param>
  348. private void AddOperationToList(int addKtype, PointF[] pointFs)
  349. {
  350. this.RefreshOperationsToIndex();
  351. this.OperationKtypeList.Add(addKtype);
  352. this.OperationsList.Add(pointFs);
  353. this.OperationIndex = this.OperationsList.Count - 1;
  354. this.RefreshOperationsButtons();
  355. }
  356. /// <summary>
  357. /// 根据OperationIndex去掉已经撤销的操作记录
  358. /// </summary>
  359. private void RefreshOperationsToIndex()
  360. {
  361. if (this.OperationIndex < this.OperationsList.Count - 1)
  362. {
  363. int operationSum = this.OperationsList.Count;
  364. for (int i = operationSum - 1; i > this.OperationIndex; i--)
  365. {
  366. this.OperationKtypeList.RemoveAt(i);
  367. this.OperationsList.RemoveAt(i);
  368. }
  369. }
  370. }
  371. /// <summary>
  372. /// 刷新操作按钮的状态
  373. /// </summary>
  374. private void RefreshOperationsButtons()
  375. {
  376. if (/*this.OperationIndex >= 0 && */this.OperationKtypeList.Count == this.OperationsList.Count && this.OperationKtypeList.Count > 0)
  377. this.resetButton.Enabled = true;
  378. else
  379. this.resetButton.Enabled = false;
  380. if (this.OperationIndex >= 0)
  381. this.undoButton.Enabled = true;
  382. else
  383. this.undoButton.Enabled = false;
  384. if (this.OperationIndex < this.OperationKtypeList.Count - 1)
  385. this.redoButton.Enabled = true;
  386. else
  387. this.redoButton.Enabled = false;
  388. }
  389. #region 矩形拖动
  390. /// <summary>
  391. /// 鼠标按下
  392. /// </summary>
  393. /// <param name="drawArea"></param>
  394. /// <param name="e"></param>
  395. private void OnMouseDown(object sender, MouseEventArgs e)
  396. {
  397. // 换算后的点
  398. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  399. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  400. && point1.X >= 0
  401. && point1.Y >= 0
  402. && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
  403. {
  404. if (e.Button == MouseButtons.Left && this.pointKtype >= 1
  405. && !drawedStartPoint)
  406. drawedStartPoint = true;
  407. startPoint = new Point((int)point1.X, (int)point1.Y);
  408. }
  409. else if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
  410. {
  411. if (!drawedStartPoint)//#21757
  412. {
  413. drawedStartPoint = true;
  414. startPoint = new Point((int)point1.X, (int)point1.Y);
  415. }
  416. }
  417. }
  418. /// <summary>
  419. /// 移动
  420. /// </summary>
  421. /// <param name="sender"></param>
  422. /// <param name="e"></param>
  423. private void onMouseMove(object sender, MouseEventArgs e)
  424. {
  425. // 换算后的点
  426. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  427. if (e.Button == MouseButtons.Left)
  428. {
  429. // 椭圆删除/圆形删除
  430. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  431. {
  432. endPoint = new Point((int)point1.X, (int)point1.Y);
  433. if (this.startPoint.X < this.endPoint.X)
  434. {
  435. //this.pointFloatArray.Clear();
  436. this.rectangle.X = this.startPoint.X;
  437. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  438. }
  439. else
  440. {
  441. this.rectangle.X = this.endPoint.X;
  442. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  443. }
  444. if (this.startPoint.Y < this.endPoint.Y)
  445. {
  446. this.rectangle.Y = this.startPoint.Y;
  447. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  448. }
  449. else
  450. {
  451. this.rectangle.Y = this.endPoint.Y;
  452. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  453. }
  454. this.documentWorkspace.Refresh();
  455. }
  456. // 矩形删除
  457. if (this.pointKtype == 13 && drawedStartPoint)
  458. {
  459. endPoint = new Point((int)point1.X, (int)point1.Y);
  460. if (this.startPoint.X < this.endPoint.X)
  461. {
  462. this.rectangle.X = this.startPoint.X;
  463. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  464. }
  465. else
  466. {
  467. this.rectangle.X = this.endPoint.X;
  468. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  469. }
  470. if (this.startPoint.Y < this.endPoint.Y)
  471. {
  472. this.rectangle.Y = this.startPoint.Y;
  473. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  474. }
  475. else
  476. {
  477. this.rectangle.Y = this.endPoint.Y;
  478. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  479. }
  480. this.documentWorkspace.Refresh();
  481. }
  482. // 直线添加
  483. if (this.pointKtype == 2 && drawedStartPoint)
  484. {
  485. endPoint = new Point((int)point1.X, (int)point1.Y);
  486. this.documentWorkspace.Refresh();
  487. }
  488. }
  489. }
  490. /// <summary>
  491. /// 鼠标抬起
  492. /// </summary>
  493. /// <param name="sender"></param>
  494. /// <param name="e"></param>
  495. private void onMouseUp(object sender, MouseEventArgs e)
  496. {
  497. // 换算后的点
  498. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  499. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  500. && point1.X >= 0
  501. && point1.Y >= 0
  502. && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { }
  503. else
  504. {
  505. if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)//#21757
  506. {
  507. //if (point1.X >= this.documentWorkspace.CompositionSurface.Width)
  508. // point1.X = this.documentWorkspace.CompositionSurface.Width - 1;
  509. //if (point1.X < 0)
  510. // point1.X = 0;
  511. //if (point1.Y >= this.documentWorkspace.CompositionSurface.Height)
  512. // point1.Y = this.documentWorkspace.CompositionSurface.Height - 1;
  513. //if (point1.Y < 0)
  514. // point1.Y = 0;
  515. }
  516. else
  517. return;
  518. }
  519. if (e.Button == MouseButtons.Right)
  520. {
  521. // 折线删除
  522. if (this.pointKtype == 11 && pointFloatArray.Count > 1)
  523. {
  524. pointFloatArray.Add(new PointF(point1.X, point1.Y));
  525. endPoint = new Point((int)point1.X, (int)point1.Y);
  526. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFloatArray);
  527. this.AddOperationToList(this.pointKtype, pointFloatArray.ToArray());
  528. this.rectangle.X = -1;
  529. this.rectangle.Y = -1;
  530. this.rectangle.Width = 0;
  531. this.rectangle.Height = 0;
  532. pointFloatArray.Clear();
  533. startPoint = new Point(-1, -1);
  534. drawedStartPoint = false;
  535. endPoint = new Point(-1, -1);
  536. this.pointKtype = 0;
  537. this.documentWorkspace.Refresh();
  538. }
  539. // 折线添加
  540. if (this.pointKtype == 1 && pointFloatArray.Count > 1)
  541. {
  542. pointFloatArray.Add(new PointF(point1.X, point1.Y));
  543. endPoint = new Point((int)point1.X, (int)point1.Y);
  544. //保存处理后的图片
  545. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  546. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  547. Graphics graphics = Graphics.FromImage(newBit);
  548. Draw(graphics, false);
  549. this.documentWorkspace.PhaseModels[0].mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  550. this.AddOperationToList(this.pointKtype, pointFloatArray.ToArray());
  551. pointFloatArray.Clear();
  552. startPoint = new Point(-1, -1);
  553. drawedStartPoint = false;
  554. endPoint = new Point(-1, -1);
  555. this.pointKtype = 0;
  556. this.documentWorkspace.Refresh();
  557. }
  558. }
  559. if (e.Button == MouseButtons.Left)
  560. {
  561. // 圆形删除/椭圆删除
  562. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  563. {
  564. endPoint = new Point((int)point1.X, (int)point1.Y);
  565. if (this.startPoint.X < this.endPoint.X)
  566. {
  567. this.rectangle.X = this.startPoint.X;
  568. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  569. }
  570. else
  571. {
  572. this.rectangle.X = this.endPoint.X;
  573. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  574. }
  575. if (this.startPoint.Y < this.endPoint.Y)
  576. {
  577. this.rectangle.Y = this.startPoint.Y;
  578. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  579. }
  580. else
  581. {
  582. this.rectangle.Y = this.endPoint.Y;
  583. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  584. }
  585. if (this.pointKtype == 14)
  586. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  587. else
  588. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat
  589. , new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));
  590. List<PointF> pointOperationArray = new List<PointF>();
  591. pointOperationArray.Add(new PointF(this.rectangle.X, this.rectangle.Y));
  592. pointOperationArray.Add(new PointF(this.rectangle.Width, this.rectangle.Height));
  593. this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray());
  594. this.rectangle.X = -1;
  595. this.rectangle.Y = -1;
  596. this.rectangle.Width = 0;
  597. this.rectangle.Height = 0;
  598. startPoint = new Point(-1, -1);
  599. drawedStartPoint = false;
  600. endPoint = new Point(-1, -1);
  601. this.pointKtype = 0;
  602. this.documentWorkspace.Refresh();
  603. }
  604. // 矩形删除
  605. if (this.pointKtype == 13 && drawedStartPoint)
  606. {
  607. endPoint = new Point((int)point1.X, (int)point1.Y);
  608. if (this.startPoint.X < this.endPoint.X)
  609. {
  610. this.rectangle.X = this.startPoint.X;
  611. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  612. }
  613. else
  614. {
  615. this.rectangle.X = this.endPoint.X;
  616. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  617. }
  618. if (this.startPoint.Y < this.endPoint.Y)
  619. {
  620. this.rectangle.Y = this.startPoint.Y;
  621. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  622. }
  623. else
  624. {
  625. this.rectangle.Y = this.endPoint.Y;
  626. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  627. }
  628. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  629. List<PointF> pointOperationArray = new List<PointF>();
  630. pointOperationArray.Add(new PointF(this.rectangle.X, this.rectangle.Y));
  631. pointOperationArray.Add(new PointF(this.rectangle.Width, this.rectangle.Height));
  632. this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray());
  633. this.rectangle.X = -1;
  634. this.rectangle.Y = -1;
  635. this.rectangle.Width = 0;
  636. this.rectangle.Height = 0;
  637. startPoint = new Point(-1, -1);
  638. drawedStartPoint = false;
  639. endPoint = new Point(-1, -1);
  640. this.pointKtype = 0;
  641. this.documentWorkspace.Refresh();
  642. }
  643. // 折线添加/折线删除
  644. if (this.pointKtype == 1 || this.pointKtype == 11)
  645. {
  646. pointFloatArray.Add(new PointF(point1.X, point1.Y));
  647. if (drawedStartPoint)
  648. {
  649. }
  650. else
  651. startPoint = new Point((int)point1.X, (int)point1.Y);
  652. this.documentWorkspace.Refresh();
  653. }
  654. // 直线添加
  655. if (this.pointKtype == 2 && drawedStartPoint)
  656. {
  657. endPoint = new Point((int)point1.X, (int)point1.Y);
  658. //保存处理后的图片
  659. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  660. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  661. Graphics graphics = Graphics.FromImage(newBit);
  662. Draw(graphics, false);
  663. this.documentWorkspace.PhaseModels[0].mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  664. List<PointF> pointOperationArray = new List<PointF>();
  665. pointOperationArray.Add(new PointF(startPoint.X, startPoint.Y));
  666. pointOperationArray.Add(new PointF(endPoint.X, endPoint.Y));
  667. this.AddOperationToList(this.pointKtype, pointOperationArray/*pointFloatArray*/.ToArray());
  668. startPoint = new Point(-1, -1);
  669. drawedStartPoint = false;
  670. endPoint = new Point(-1, -1);
  671. this.pointKtype = 0;
  672. this.documentWorkspace.Refresh();
  673. }
  674. }
  675. }
  676. #endregion
  677. /// <summary>
  678. /// 画布绘制
  679. /// </summary>
  680. /// <param name="sender"></param>
  681. /// <param name="e"></param>
  682. private void Panel_Paint(object sender, PaintEventArgs e)
  683. {
  684. if (this.documentWorkspace.CompositionSurface != null)
  685. {
  686. //
  687. // 以下是计算绘制图片的位置和大小并绘制图片
  688. //
  689. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  690. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  691. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  692. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  693. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  694. //
  695. // 以下是绘制网格、标注、测量、视场等开始
  696. //
  697. e.Graphics.TranslateTransform(x, y);
  698. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  699. //if (this.checkBox4_0.Checked)//显示网格
  700. Draw(e.Graphics, true);
  701. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  702. e.Graphics.TranslateTransform(-x, -y);
  703. }
  704. }
  705. /// <summary>
  706. /// 绘制
  707. /// </summary>
  708. private void Draw(Graphics g, bool DrawGuideLines)
  709. {
  710. // 抗锯齿
  711. g.SmoothingMode = SmoothingMode.AntiAlias;
  712. if (DrawGuideLines)
  713. {
  714. if (guideClass != null && guideClass.GrainSizeGuideAreaMethodModel != null)
  715. guideClass.DrawAreaGuide(g, SelectedItem, guideClass.guideModel);
  716. else if (guideClass != null && guideClass.GrainSizeGuideStyleModel != null)
  717. guideClass.DrawGuideLines(g, SelectedItem, guideClass.guideModel);
  718. }
  719. if (guide2Class != null && this.documentWorkspace.CompositionSurface != null)
  720. guide2Class.DrawGridViews(g, this.documentWorkspace.CompositionSurface.Height, this.documentWorkspace.CompositionSurface.Width);
  721. //圆形删除/椭圆删除
  722. if ((this.pointKtype == 14 || this.pointKtype == 12) && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  723. {
  724. Pen pen = new Pen(this.phaseColor, 1);
  725. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  726. if (this.pointKtype == 14)
  727. g.DrawEllipse(pen, this.rectangle);
  728. else
  729. 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)));
  730. pen.Dispose();
  731. }
  732. //矩形删除
  733. if (this.pointKtype == 13 && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  734. {
  735. Pen pen = new Pen(this.phaseColor, 1);
  736. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  737. g.DrawRectangle(pen, new Rectangle((int)this.rectangle.X, (int)this.rectangle.Y, (int)this.rectangle.Width, (int)this.rectangle.Height));
  738. pen.Dispose();
  739. }
  740. // 折线删除
  741. if (this.pointKtype == 11 && pointFloatArray.Count >= 2)
  742. {
  743. Pen pen = new Pen(this.phaseColor, 1);
  744. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  745. g.DrawPolygon(pen, pointFloatArray.ToArray());
  746. pen.Dispose();
  747. }
  748. // 直线添加
  749. if (this.pointKtype == 2 && /*pointFloatArray.Count == 2*/drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1)
  750. {
  751. Pen pen = new Pen(this.phaseColor, 1);
  752. //g.DrawLine(pen, pointFloatArray[0].X, pointFloatArray[0].Y, pointFloatArray[1].X, pointFloatArray[1].Y);
  753. ////pen.DashStyle = DashStyle.Dash;
  754. g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
  755. pen.Dispose();
  756. }
  757. // 折线添加
  758. if (this.pointKtype == 1 && pointFloatArray.Count >= 2)
  759. {
  760. Pen pen = new Pen(this.phaseColor, 1);
  761. g.DrawLines(pen, pointFloatArray.ToArray());
  762. pen.Dispose();
  763. }
  764. }
  765. private void InitializeLanguageText()
  766. {
  767. this.checkBox1.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
  768. this.label7.Text = PdnResources.GetString("Menu.Image.Sigma.Text");
  769. this.applyLabel.Text = "是否应用:";
  770. this.label9.Text = "标准图像:";
  771. this.label17.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
  772. this.label6.Text = PdnResources.GetString("Menu.Denoisingtype.text") + ":";
  773. this.label1.Text = PdnResources.GetString("Menu.Grainboundarytype.text") + ":";
  774. this.checkBox2.Text = PdnResources.GetString("Menu.Grainboundaryenhancement.text");
  775. this.checkBox3.Text = "标准图像";
  776. this.checkBox4.Text = "强制连接";
  777. this.label8.Text = PdnResources.GetString("Menu.Grainboundarysize.text") + ":";
  778. this.button3.Text = PdnResources.GetString("Menu.Grainboundaryedit.text");
  779. this.groupBox4.Text = PdnResources.GetString("Menu.params.text");// PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
  780. this.comboBox3.Items.AddRange(new object[] {
  781. PdnResources.GetString("Menu.Gaussiansmoothing.text"),
  782. PdnResources.GetString("Menu.directionalsmoothing.text")});
  783. this.comboBox2.Items.AddRange(new object[] {
  784. PdnResources.GetString("Menu.Brightgrainboundary.text"),
  785. PdnResources.GetString("Menu.Darkgrainboundary.text"),
  786. PdnResources.GetString("Menu.gradient.text")});
  787. this.resetButton.Text = "重置";
  788. this.resetButton.Enabled = false;
  789. this.redoButton.Text = "恢复";
  790. this.redoButton.Enabled = false;
  791. this.undoButton.Text = "撤销";
  792. this.undoButton.Enabled = false;
  793. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  794. this.button9.Text = PdnResources.GetString("CommonAction.Undo");
  795. this.button2.Text = PdnResources.GetString("Menu.application.text");// PdnResources.GetString("Menu.File.Close.Text");
  796. this.button1.Text = PdnResources.GetString("Form.OkButton.Text");
  797. this.groupBox2.Text = PdnResources.GetString("Menu.Addgrainboundaries.text");
  798. this.button4.Text = PdnResources.GetString("Menu.Lineadd.text");
  799. this.button3.Text = PdnResources.GetString("Menu.Polylineadd.text");
  800. this.groupBox3.Text = PdnResources.GetString("Menu.Deletegrainboundary.text");
  801. this.button8.Text = PdnResources.GetString("Menu.Ellipsedelete.text");
  802. this.button7.Text = PdnResources.GetString("Menu.BinaryAction.RectangleDelete.Text");
  803. this.button6.Text = PdnResources.GetString("Menu.rounddelete.text");
  804. this.button5.Text = PdnResources.GetString("Menu.BinaryAction.PolygonleDelete.Text");
  805. this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
  806. this.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");// PdnResources.GetString("Menu.Grainboundaryedit.text");
  807. }
  808. private void InitializeComponent()
  809. {
  810. this.groupBox1 = new System.Windows.Forms.GroupBox();
  811. this.button9 = new System.Windows.Forms.Button();
  812. this.button2 = new System.Windows.Forms.Button();
  813. this.button1 = new System.Windows.Forms.Button();
  814. this.groupBox2 = new System.Windows.Forms.GroupBox();
  815. this.button4 = new System.Windows.Forms.Button();
  816. this.button3 = new System.Windows.Forms.Button();
  817. this.groupBox3 = new System.Windows.Forms.GroupBox();
  818. this.button8 = new System.Windows.Forms.Button();
  819. this.button7 = new System.Windows.Forms.Button();
  820. this.button6 = new System.Windows.Forms.Button();
  821. this.button5 = new System.Windows.Forms.Button();
  822. this.groupBox7 = new System.Windows.Forms.GroupBox();
  823. this.groupBox4 = new System.Windows.Forms.GroupBox();
  824. this.panel2 = new System.Windows.Forms.Panel();
  825. this.applyRadioButton2 = new System.Windows.Forms.RadioButton();
  826. this.applyRadioButton1 = new System.Windows.Forms.RadioButton();
  827. this.applyLabel = new System.Windows.Forms.Label();
  828. this.radioButton2 = new System.Windows.Forms.RadioButton();
  829. this.radioButton1 = new System.Windows.Forms.RadioButton();
  830. this.panel1 = new System.Windows.Forms.Panel();
  831. this.label8 = new System.Windows.Forms.Label();
  832. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  833. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  834. this.checkBox2 = new System.Windows.Forms.CheckBox();
  835. this.checkBox3 = new System.Windows.Forms.CheckBox();
  836. this.checkBox4 = new System.Windows.Forms.CheckBox();
  837. this.textBox6 = new System.Windows.Forms.TextBox();
  838. this.label7 = new System.Windows.Forms.Label();
  839. this.label9 = new System.Windows.Forms.Label();
  840. this.label17 = new System.Windows.Forms.Label();
  841. this.comboBox3 = new System.Windows.Forms.ComboBox();
  842. this.label6 = new System.Windows.Forms.Label();
  843. this.comboBox2 = new System.Windows.Forms.ComboBox();
  844. this.label1 = new System.Windows.Forms.Label();
  845. this.checkBox1 = new System.Windows.Forms.CheckBox();
  846. this.itemsGroupBox = new System.Windows.Forms.GroupBox();
  847. this.undoButton = new System.Windows.Forms.Button();
  848. this.redoButton = new System.Windows.Forms.Button();
  849. this.resetButton = new System.Windows.Forms.Button();
  850. this.groupBox1.SuspendLayout();
  851. this.groupBox2.SuspendLayout();
  852. this.groupBox3.SuspendLayout();
  853. this.groupBox4.SuspendLayout();
  854. this.panel2.SuspendLayout();
  855. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  856. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  857. this.itemsGroupBox.SuspendLayout();
  858. this.SuspendLayout();
  859. //
  860. // groupBox1
  861. //
  862. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  863. | System.Windows.Forms.AnchorStyles.Right)));
  864. this.groupBox1.Controls.Add(this.button9);
  865. this.groupBox1.Controls.Add(this.button2);
  866. this.groupBox1.Controls.Add(this.button1);
  867. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  868. this.groupBox1.Name = "groupBox1";
  869. this.groupBox1.Size = new System.Drawing.Size(808, 45);
  870. this.groupBox1.TabIndex = 0;
  871. this.groupBox1.TabStop = false;
  872. //
  873. // button9
  874. //
  875. this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  876. this.button9.Location = new System.Drawing.Point(468, 13);
  877. this.button9.Name = "button9";
  878. this.button9.Size = new System.Drawing.Size(91, 26);
  879. this.button9.TabIndex = 2;
  880. this.button9.UseVisualStyleBackColor = true;
  881. this.button9.Visible = false;
  882. this.button9.Click += new System.EventHandler(this.button9_Click);
  883. //
  884. // button2
  885. //
  886. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  887. this.button2.Location = new System.Drawing.Point(592, 14);
  888. this.button2.Name = "button2";
  889. this.button2.Size = new System.Drawing.Size(91, 24);
  890. this.button2.TabIndex = 1;
  891. this.button2.UseVisualStyleBackColor = true;
  892. this.button2.Click += new System.EventHandler(this.button2_Click);
  893. //
  894. // button1
  895. //
  896. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  897. this.button1.Location = new System.Drawing.Point(694, 14);
  898. this.button1.Name = "button1";
  899. this.button1.Size = new System.Drawing.Size(91, 24);
  900. this.button1.TabIndex = 0;
  901. this.button1.UseVisualStyleBackColor = true;
  902. this.button1.Click += new System.EventHandler(this.button1_Click);
  903. //
  904. // groupBox2
  905. //
  906. this.groupBox2.Controls.Add(this.button4);
  907. this.groupBox2.Controls.Add(this.button3);
  908. this.groupBox2.Location = new System.Drawing.Point(12, 334);
  909. this.groupBox2.Name = "groupBox2";
  910. this.groupBox2.Size = new System.Drawing.Size(233, 57);
  911. this.groupBox2.TabIndex = 1;
  912. this.groupBox2.TabStop = false;
  913. //
  914. // button4
  915. //
  916. this.button4.Location = new System.Drawing.Point(135, 24);
  917. this.button4.Name = "button4";
  918. this.button4.Size = new System.Drawing.Size(73, 26);
  919. this.button4.TabIndex = 3;
  920. this.button4.UseVisualStyleBackColor = true;
  921. this.button4.Click += new System.EventHandler(this.button4_Click);
  922. //
  923. // button3
  924. //
  925. this.button3.Location = new System.Drawing.Point(28, 24);
  926. this.button3.Name = "button3";
  927. this.button3.Size = new System.Drawing.Size(73, 26);
  928. this.button3.TabIndex = 2;
  929. this.button3.UseVisualStyleBackColor = true;
  930. this.button3.Click += new System.EventHandler(this.button3_Click);
  931. //
  932. // groupBox3
  933. //
  934. this.groupBox3.Controls.Add(this.button8);
  935. this.groupBox3.Controls.Add(this.button7);
  936. this.groupBox3.Controls.Add(this.button6);
  937. this.groupBox3.Controls.Add(this.button5);
  938. this.groupBox3.Location = new System.Drawing.Point(12, 398);
  939. this.groupBox3.Name = "groupBox3";
  940. this.groupBox3.Size = new System.Drawing.Size(233, 102);
  941. this.groupBox3.TabIndex = 1;
  942. this.groupBox3.TabStop = false;
  943. //
  944. // button8
  945. //
  946. this.button8.Location = new System.Drawing.Point(135, 65);
  947. this.button8.Name = "button8";
  948. this.button8.Size = new System.Drawing.Size(73, 26);
  949. this.button8.TabIndex = 7;
  950. this.button8.UseVisualStyleBackColor = true;
  951. this.button8.Click += new System.EventHandler(this.button8_Click);
  952. //
  953. // button7
  954. //
  955. this.button7.Location = new System.Drawing.Point(28, 65);
  956. this.button7.Name = "button7";
  957. this.button7.Size = new System.Drawing.Size(73, 26);
  958. this.button7.TabIndex = 6;
  959. this.button7.UseVisualStyleBackColor = true;
  960. this.button7.Click += new System.EventHandler(this.button7_Click);
  961. //
  962. // button6
  963. //
  964. this.button6.Location = new System.Drawing.Point(135, 24);
  965. this.button6.Name = "button6";
  966. this.button6.Size = new System.Drawing.Size(73, 26);
  967. this.button6.TabIndex = 5;
  968. this.button6.UseVisualStyleBackColor = true;
  969. this.button6.Click += new System.EventHandler(this.button6_Click);
  970. //
  971. // button5
  972. //
  973. this.button5.Location = new System.Drawing.Point(28, 24);
  974. this.button5.Name = "button5";
  975. this.button5.Size = new System.Drawing.Size(73, 26);
  976. this.button5.TabIndex = 4;
  977. this.button5.UseVisualStyleBackColor = true;
  978. this.button5.Click += new System.EventHandler(this.button5_Click);
  979. //
  980. // groupBox7
  981. //
  982. this.groupBox7.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  983. | System.Windows.Forms.AnchorStyles.Left)
  984. | System.Windows.Forms.AnchorStyles.Right)));
  985. this.groupBox7.Location = new System.Drawing.Point(251, 63);
  986. this.groupBox7.Name = "groupBox7";
  987. this.groupBox7.Size = new System.Drawing.Size(569, 502);
  988. this.groupBox7.TabIndex = 1;
  989. this.groupBox7.TabStop = false;
  990. //
  991. // groupBox4
  992. //
  993. this.groupBox4.Controls.Add(this.panel2);
  994. this.groupBox4.Controls.Add(this.applyLabel);
  995. this.groupBox4.Controls.Add(this.radioButton2);
  996. this.groupBox4.Controls.Add(this.radioButton1);
  997. this.groupBox4.Controls.Add(this.panel1);
  998. this.groupBox4.Controls.Add(this.label8);
  999. this.groupBox4.Controls.Add(this.numericUpDown2);
  1000. this.groupBox4.Controls.Add(this.numericUpDown1);
  1001. this.groupBox4.Controls.Add(this.checkBox2);
  1002. this.groupBox4.Controls.Add(this.checkBox3);
  1003. this.groupBox4.Controls.Add(this.checkBox4);
  1004. this.groupBox4.Controls.Add(this.textBox6);
  1005. this.groupBox4.Controls.Add(this.label7);
  1006. this.groupBox4.Controls.Add(this.label9);
  1007. this.groupBox4.Controls.Add(this.label17);
  1008. this.groupBox4.Controls.Add(this.comboBox3);
  1009. this.groupBox4.Controls.Add(this.label6);
  1010. this.groupBox4.Controls.Add(this.comboBox2);
  1011. this.groupBox4.Controls.Add(this.label1);
  1012. this.groupBox4.Controls.Add(this.checkBox1);
  1013. this.groupBox4.Location = new System.Drawing.Point(12, 63);
  1014. this.groupBox4.Name = "groupBox4";
  1015. this.groupBox4.Size = new System.Drawing.Size(233, 264);
  1016. this.groupBox4.TabIndex = 38;
  1017. this.groupBox4.TabStop = false;
  1018. //
  1019. // panel2
  1020. //
  1021. this.panel2.Controls.Add(this.applyRadioButton2);
  1022. this.panel2.Controls.Add(this.applyRadioButton1);
  1023. this.panel2.Location = new System.Drawing.Point(69, 12);
  1024. this.panel2.Name = "panel2";
  1025. this.panel2.Size = new System.Drawing.Size(134, 33);
  1026. this.panel2.TabIndex = 130;
  1027. //
  1028. // applyRadioButton2
  1029. //
  1030. this.applyRadioButton2.AutoSize = true;
  1031. this.applyRadioButton2.Location = new System.Drawing.Point(66, 8);
  1032. this.applyRadioButton2.Name = "applyRadioButton2";
  1033. this.applyRadioButton2.Size = new System.Drawing.Size(35, 16);
  1034. this.applyRadioButton2.TabIndex = 129;
  1035. this.applyRadioButton2.Text = "否";
  1036. this.applyRadioButton2.UseVisualStyleBackColor = true;
  1037. //
  1038. // applyRadioButton1
  1039. //
  1040. this.applyRadioButton1.AutoSize = true;
  1041. this.applyRadioButton1.Checked = true;
  1042. this.applyRadioButton1.Location = new System.Drawing.Point(16, 8);
  1043. this.applyRadioButton1.Name = "applyRadioButton1";
  1044. this.applyRadioButton1.Size = new System.Drawing.Size(35, 16);
  1045. this.applyRadioButton1.TabIndex = 128;
  1046. this.applyRadioButton1.TabStop = true;
  1047. this.applyRadioButton1.Text = "是";
  1048. this.applyRadioButton1.UseVisualStyleBackColor = true;
  1049. //
  1050. // applyLabel
  1051. //
  1052. this.applyLabel.AutoSize = true;
  1053. this.applyLabel.Location = new System.Drawing.Point(6, 22);
  1054. this.applyLabel.Name = "applyLabel";
  1055. this.applyLabel.Size = new System.Drawing.Size(0, 12);
  1056. this.applyLabel.TabIndex = 127;
  1057. //
  1058. // radioButton2
  1059. //
  1060. this.radioButton2.AutoSize = true;
  1061. this.radioButton2.Checked = true;
  1062. this.radioButton2.Location = new System.Drawing.Point(135, 51);
  1063. this.radioButton2.Name = "radioButton2";
  1064. this.radioButton2.Size = new System.Drawing.Size(35, 16);
  1065. this.radioButton2.TabIndex = 126;
  1066. this.radioButton2.TabStop = true;
  1067. this.radioButton2.Text = "否";
  1068. this.radioButton2.UseVisualStyleBackColor = true;
  1069. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
  1070. //
  1071. // radioButton1
  1072. //
  1073. this.radioButton1.AutoSize = true;
  1074. this.radioButton1.Location = new System.Drawing.Point(85, 51);
  1075. this.radioButton1.Name = "radioButton1";
  1076. this.radioButton1.Size = new System.Drawing.Size(35, 16);
  1077. this.radioButton1.TabIndex = 125;
  1078. this.radioButton1.Text = "是";
  1079. this.radioButton1.UseVisualStyleBackColor = true;
  1080. this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  1081. //
  1082. // panel1
  1083. //
  1084. this.panel1.BackColor = System.Drawing.Color.Red;
  1085. this.panel1.Location = new System.Drawing.Point(85, 83);
  1086. this.panel1.Name = "panel1";
  1087. this.panel1.Size = new System.Drawing.Size(72, 21);
  1088. this.panel1.TabIndex = 20;
  1089. this.panel1.Click += new System.EventHandler(this.panel1_click);
  1090. //
  1091. // label8
  1092. //
  1093. this.label8.AutoSize = true;
  1094. this.label8.Location = new System.Drawing.Point(6, 176);
  1095. this.label8.Name = "label8";
  1096. this.label8.Size = new System.Drawing.Size(0, 12);
  1097. this.label8.TabIndex = 30;
  1098. this.label8.Visible = false;
  1099. //
  1100. // numericUpDown2
  1101. //
  1102. this.numericUpDown2.DecimalPlaces = 2;
  1103. this.numericUpDown2.Location = new System.Drawing.Point(164, 172);
  1104. this.numericUpDown2.Maximum = new decimal(new int[] {
  1105. 1000,
  1106. 0,
  1107. 0,
  1108. 0});
  1109. this.numericUpDown2.Name = "numericUpDown2";
  1110. this.numericUpDown2.Size = new System.Drawing.Size(61, 21);
  1111. this.numericUpDown2.TabIndex = 29;
  1112. this.numericUpDown2.Tag = "max";
  1113. this.numericUpDown2.Value = new decimal(new int[] {
  1114. 500,
  1115. 0,
  1116. 0,
  1117. 0});
  1118. this.numericUpDown2.Visible = false;
  1119. //
  1120. // numericUpDown1
  1121. //
  1122. this.numericUpDown1.DecimalPlaces = 2;
  1123. this.numericUpDown1.Location = new System.Drawing.Point(85, 172);
  1124. this.numericUpDown1.Maximum = new decimal(new int[] {
  1125. 1000,
  1126. 0,
  1127. 0,
  1128. 0});
  1129. this.numericUpDown1.Name = "numericUpDown1";
  1130. this.numericUpDown1.Size = new System.Drawing.Size(61, 21);
  1131. this.numericUpDown1.TabIndex = 28;
  1132. this.numericUpDown1.Tag = "min";
  1133. this.numericUpDown1.Value = new decimal(new int[] {
  1134. 1,
  1135. 0,
  1136. 0,
  1137. 131072});
  1138. this.numericUpDown1.Visible = false;
  1139. //
  1140. // checkBox2
  1141. //
  1142. this.checkBox2.AutoSize = true;
  1143. this.checkBox2.Checked = true;
  1144. this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
  1145. this.checkBox2.Location = new System.Drawing.Point(8, 114);
  1146. this.checkBox2.Name = "checkBox2";
  1147. this.checkBox2.Size = new System.Drawing.Size(15, 14);
  1148. this.checkBox2.TabIndex = 26;
  1149. this.checkBox2.UseVisualStyleBackColor = true;
  1150. this.checkBox2.Visible = false;
  1151. //
  1152. // checkBox3
  1153. //
  1154. this.checkBox3.AutoSize = true;
  1155. this.checkBox3.Location = new System.Drawing.Point(8, 114);
  1156. this.checkBox3.Name = "checkBox3";
  1157. this.checkBox3.Size = new System.Drawing.Size(15, 14);
  1158. this.checkBox3.TabIndex = 26;
  1159. this.checkBox3.UseVisualStyleBackColor = true;
  1160. this.checkBox3.Visible = false;
  1161. //
  1162. // checkBox4
  1163. //
  1164. this.checkBox4.AutoSize = true;
  1165. this.checkBox4.Location = new System.Drawing.Point(8, 115);
  1166. this.checkBox4.Name = "checkBox4";
  1167. this.checkBox4.Size = new System.Drawing.Size(15, 14);
  1168. this.checkBox4.TabIndex = 26;
  1169. this.checkBox4.UseVisualStyleBackColor = true;
  1170. this.checkBox4.Visible = false;
  1171. //
  1172. // textBox6
  1173. //
  1174. this.textBox6.Location = new System.Drawing.Point(85, 141);
  1175. this.textBox6.Name = "textBox6";
  1176. this.textBox6.Size = new System.Drawing.Size(45, 21);
  1177. this.textBox6.TabIndex = 25;
  1178. this.textBox6.Text = "0.5";
  1179. this.textBox6.Visible = false;
  1180. //
  1181. // label7
  1182. //
  1183. this.label7.AutoSize = true;
  1184. this.label7.Location = new System.Drawing.Point(6, 145);
  1185. this.label7.Name = "label7";
  1186. this.label7.Size = new System.Drawing.Size(0, 12);
  1187. this.label7.TabIndex = 24;
  1188. this.label7.Visible = false;
  1189. //
  1190. // label9
  1191. //
  1192. this.label9.AutoSize = true;
  1193. this.label9.Location = new System.Drawing.Point(6, 53);
  1194. this.label9.Name = "label9";
  1195. this.label9.Size = new System.Drawing.Size(0, 12);
  1196. this.label9.TabIndex = 24;
  1197. //
  1198. // label17
  1199. //
  1200. this.label17.AutoSize = true;
  1201. this.label17.Location = new System.Drawing.Point(6, 87);
  1202. this.label17.Name = "label17";
  1203. this.label17.Size = new System.Drawing.Size(0, 12);
  1204. this.label17.TabIndex = 124;
  1205. //
  1206. // comboBox3
  1207. //
  1208. this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  1209. this.comboBox3.FormattingEnabled = true;
  1210. this.comboBox3.Location = new System.Drawing.Point(85, 235);
  1211. this.comboBox3.Name = "comboBox3";
  1212. this.comboBox3.Size = new System.Drawing.Size(133, 20);
  1213. this.comboBox3.TabIndex = 23;
  1214. this.comboBox3.Visible = false;
  1215. //
  1216. // label6
  1217. //
  1218. this.label6.AutoSize = true;
  1219. this.label6.Location = new System.Drawing.Point(6, 238);
  1220. this.label6.Name = "label6";
  1221. this.label6.Size = new System.Drawing.Size(0, 12);
  1222. this.label6.TabIndex = 22;
  1223. this.label6.Visible = false;
  1224. //
  1225. // comboBox2
  1226. //
  1227. this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  1228. this.comboBox2.FormattingEnabled = true;
  1229. this.comboBox2.Location = new System.Drawing.Point(85, 204);
  1230. this.comboBox2.Name = "comboBox2";
  1231. this.comboBox2.Size = new System.Drawing.Size(133, 20);
  1232. this.comboBox2.TabIndex = 11;
  1233. this.comboBox2.Visible = false;
  1234. //
  1235. // label1
  1236. //
  1237. this.label1.AutoSize = true;
  1238. this.label1.Location = new System.Drawing.Point(6, 207);
  1239. this.label1.Name = "label1";
  1240. this.label1.Size = new System.Drawing.Size(0, 12);
  1241. this.label1.TabIndex = 21;
  1242. this.label1.Visible = false;
  1243. //
  1244. // checkBox1
  1245. //
  1246. this.checkBox1.AutoSize = true;
  1247. this.checkBox1.Location = new System.Drawing.Point(8, 87);
  1248. this.checkBox1.Name = "checkBox1";
  1249. this.checkBox1.Size = new System.Drawing.Size(15, 14);
  1250. this.checkBox1.TabIndex = 7;
  1251. this.checkBox1.UseVisualStyleBackColor = true;
  1252. this.checkBox1.Visible = false;
  1253. //
  1254. // itemsGroupBox
  1255. //
  1256. this.itemsGroupBox.Controls.Add(this.undoButton);
  1257. this.itemsGroupBox.Controls.Add(this.redoButton);
  1258. this.itemsGroupBox.Controls.Add(this.resetButton);
  1259. this.itemsGroupBox.Location = new System.Drawing.Point(12, 506);
  1260. this.itemsGroupBox.Name = "itemsGroupBox";
  1261. this.itemsGroupBox.Size = new System.Drawing.Size(233, 59);
  1262. this.itemsGroupBox.TabIndex = 39;
  1263. this.itemsGroupBox.TabStop = false;
  1264. this.itemsGroupBox.Text = "操作";
  1265. //
  1266. // undoButton
  1267. //
  1268. this.undoButton.Location = new System.Drawing.Point(156, 23);
  1269. this.undoButton.Name = "undoButton";
  1270. this.undoButton.Size = new System.Drawing.Size(64, 26);
  1271. this.undoButton.TabIndex = 10;
  1272. this.undoButton.UseVisualStyleBackColor = true;
  1273. this.undoButton.Click += new System.EventHandler(this.undoButton_Click);
  1274. //
  1275. // redoButton
  1276. //
  1277. this.redoButton.Location = new System.Drawing.Point(86, 23);
  1278. this.redoButton.Name = "redoButton";
  1279. this.redoButton.Size = new System.Drawing.Size(64, 26);
  1280. this.redoButton.TabIndex = 9;
  1281. this.redoButton.UseVisualStyleBackColor = true;
  1282. this.redoButton.Click += new System.EventHandler(this.redoButton_Click);
  1283. //
  1284. // resetButton
  1285. //
  1286. this.resetButton.Location = new System.Drawing.Point(16, 23);
  1287. this.resetButton.Name = "resetButton";
  1288. this.resetButton.Size = new System.Drawing.Size(64, 26);
  1289. this.resetButton.TabIndex = 8;
  1290. this.resetButton.UseVisualStyleBackColor = true;
  1291. this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
  1292. //
  1293. // GrainBoundaryEditingDialog
  1294. //
  1295. this.ClientSize = new System.Drawing.Size(832, 577);
  1296. this.Controls.Add(this.itemsGroupBox);
  1297. this.Controls.Add(this.groupBox4);
  1298. this.Controls.Add(this.groupBox2);
  1299. this.Controls.Add(this.groupBox3);
  1300. this.Controls.Add(this.groupBox7);
  1301. this.Controls.Add(this.groupBox1);
  1302. this.MaximizeBox = false;
  1303. this.MinimizeBox = false;
  1304. this.MinimumSize = new System.Drawing.Size(848, 616);
  1305. this.Name = "GrainBoundaryEditingDialog";
  1306. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GrainBoundryEditingDialog_FormClosing);
  1307. this.Load += new System.EventHandler(this.GrainBoundryEditingDialog_Load);
  1308. this.groupBox1.ResumeLayout(false);
  1309. this.groupBox2.ResumeLayout(false);
  1310. this.groupBox3.ResumeLayout(false);
  1311. this.groupBox4.ResumeLayout(false);
  1312. this.groupBox4.PerformLayout();
  1313. this.panel2.ResumeLayout(false);
  1314. this.panel2.PerformLayout();
  1315. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  1316. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  1317. this.itemsGroupBox.ResumeLayout(false);
  1318. this.ResumeLayout(false);
  1319. }
  1320. /// <summary>
  1321. /// 折线添加
  1322. /// </summary>
  1323. /// <param name="sender"></param>
  1324. /// <param name="e"></param>
  1325. private void button3_Click(object sender, EventArgs e)
  1326. {
  1327. if (this.documentWorkspace.PhaseModels[0].mat == null)
  1328. {
  1329. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
  1330. return;
  1331. }
  1332. pointFloatArray.Clear();
  1333. startPoint = new Point(-1, -1);
  1334. drawedStartPoint = false;
  1335. endPoint = new Point(-1, -1);
  1336. pointKtype = 1;
  1337. this.documentWorkspace.Refresh();
  1338. }
  1339. /// <summary>
  1340. /// 直线添加
  1341. /// </summary>
  1342. /// <param name="sender"></param>
  1343. /// <param name="e"></param>
  1344. private void button4_Click(object sender, EventArgs e)
  1345. {
  1346. if (this.documentWorkspace.PhaseModels[0].mat == null)
  1347. {
  1348. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
  1349. return;
  1350. }
  1351. startPoint = new Point(-1, -1);
  1352. drawedStartPoint = false;
  1353. endPoint = new Point(-1, -1);
  1354. pointKtype = 2;
  1355. this.documentWorkspace.Refresh();
  1356. }
  1357. private void InitCommonButtonEvent()
  1358. {
  1359. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  1360. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  1361. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  1362. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  1363. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  1364. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  1365. }
  1366. private void zoomInButton_Click(object sender, EventArgs e)
  1367. {
  1368. this.documentWorkspace.ZoomIn();
  1369. }
  1370. private void zoomOutButton_Click(object sender, EventArgs e)
  1371. {
  1372. this.documentWorkspace.ZoomOut();
  1373. }
  1374. private void zoomToWindowButton_Click(object sender, EventArgs e)
  1375. {
  1376. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1377. }
  1378. private void actualSizeButton_Click(object sender, EventArgs e)
  1379. {
  1380. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1381. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  1382. }
  1383. private void pointerButton_Click(object sender, EventArgs e)
  1384. {
  1385. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;
  1386. this.documentWorkspace.Cursor = Cursors.Default;
  1387. }
  1388. private void mobileModeButton_Click(object sender, EventArgs e)
  1389. {
  1390. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  1391. }
  1392. //确定按钮点击事件
  1393. private void button1_Click(object sender, EventArgs e)
  1394. {
  1395. this.PhaseMat = this.documentWorkspace.PhaseModels[0].mat;
  1396. this.DialogResult = DialogResult.OK;
  1397. this.Close();
  1398. }
  1399. /// <summary>
  1400. /// 用于get处理后的图像
  1401. /// </summary>
  1402. public Mat PhaseMat
  1403. {
  1404. get
  1405. {
  1406. return this.phaseMat;
  1407. }
  1408. set
  1409. {
  1410. this.phaseMat = value;
  1411. }
  1412. }
  1413. /// <summary>
  1414. /// 用于get处理后的图像相的颜色
  1415. /// </summary>
  1416. public Color PhaseColor
  1417. {
  1418. get
  1419. {
  1420. return this.phaseColor;
  1421. }
  1422. set
  1423. {
  1424. this.phaseColor = value;
  1425. }
  1426. }
  1427. /// <summary>
  1428. /// 矩形删除
  1429. /// </summary>
  1430. /// <param name="sender"></param>
  1431. /// <param name="e"></param>
  1432. private void button7_Click(object sender, EventArgs e)
  1433. {
  1434. if (this.documentWorkspace.PhaseModels[0].mat == null)
  1435. {
  1436. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
  1437. return;
  1438. }
  1439. startPoint = new Point(-1, -1);
  1440. drawedStartPoint = false;
  1441. endPoint = new Point(-1, -1);
  1442. this.rectangle.X = -1;
  1443. this.rectangle.Y = -1;
  1444. this.rectangle.Width = 0;
  1445. this.rectangle.Height = 0;
  1446. this.pointKtype = 13;
  1447. this.documentWorkspace.Refresh();
  1448. }
  1449. /// <summary>
  1450. /// 椭圆删除
  1451. /// </summary>
  1452. /// <param name="sender"></param>
  1453. /// <param name="e"></param>
  1454. private void button8_Click(object sender, EventArgs e)
  1455. {
  1456. if (this.documentWorkspace.PhaseModels[0].mat == null)
  1457. {
  1458. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
  1459. return;
  1460. }
  1461. startPoint = new Point(-1, -1);
  1462. drawedStartPoint = false;
  1463. endPoint = new Point(-1, -1);
  1464. this.rectangle.X = -1;
  1465. this.rectangle.Y = -1;
  1466. this.rectangle.Width = 0;
  1467. this.rectangle.Height = 0;
  1468. this.pointKtype = 14;
  1469. this.documentWorkspace.Refresh();
  1470. }
  1471. /// <summary>
  1472. /// 圆形删除
  1473. /// </summary>
  1474. /// <param name="sender"></param>
  1475. /// <param name="e"></param>
  1476. private void button6_Click(object sender, EventArgs e)
  1477. {
  1478. if (this.documentWorkspace.PhaseModels[0].mat == null)
  1479. {
  1480. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
  1481. return;
  1482. }
  1483. startPoint = new Point(-1, -1);
  1484. drawedStartPoint = false;
  1485. endPoint = new Point(-1, -1);
  1486. this.rectangle.X = -1;
  1487. this.rectangle.Y = -1;
  1488. this.rectangle.Width = 0;
  1489. this.rectangle.Height = 0;
  1490. this.pointKtype = 12;
  1491. this.documentWorkspace.Refresh();
  1492. }
  1493. /// <summary>
  1494. /// 多边形删除
  1495. /// </summary>
  1496. /// <param name="sender"></param>
  1497. /// <param name="e"></param>
  1498. private void button5_Click(object sender, EventArgs e)
  1499. {
  1500. if (this.documentWorkspace.PhaseModels[0].mat == null)
  1501. {
  1502. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
  1503. return;
  1504. }
  1505. pointFloatArray.Clear();
  1506. startPoint = new Point(-1, -1);
  1507. drawedStartPoint = false;
  1508. endPoint = new Point(-1, -1);
  1509. this.rectangle.X = -1;
  1510. this.rectangle.Y = -1;
  1511. this.rectangle.Width = 0;
  1512. this.rectangle.Height = 0;
  1513. this.pointKtype = 11;
  1514. this.documentWorkspace.Refresh();
  1515. }
  1516. private void button2_Click(object sender, EventArgs e)
  1517. {
  1518. this.applyDect();
  1519. //this.Close();//##################################
  1520. }
  1521. /// <summary>
  1522. /// 撤销按钮点击事件
  1523. /// </summary>
  1524. /// <param name="sender"></param>
  1525. /// <param name="e"></param>
  1526. private void button9_Click(object sender, EventArgs e)
  1527. {
  1528. }
  1529. private void numericUpDown1_ValueChanged_1(object sender, EventArgs e)
  1530. {
  1531. if (this.checkBox1.Checked)
  1532. {
  1533. this.applyDect();
  1534. }
  1535. }
  1536. private void numericUpDown2_ValueChanged_1(object sender, EventArgs e)
  1537. {
  1538. if (this.checkBox1.Checked)
  1539. {
  1540. this.applyDect();
  1541. }
  1542. }
  1543. #region 晶界重现方法
  1544. ProgressThreadProcClass procClass;
  1545. int grainApplygrainboundaries;
  1546. int m_iStandardImage;
  1547. int iConnect;
  1548. double sigma = 0.5;
  1549. Mat OrgImg;// = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
  1550. int dark;// = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
  1551. int smooth_type;// = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
  1552. //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
  1553. int enhance;// = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
  1554. double[] cell_size;// = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
  1555. Mat OrgImg0;
  1556. private void applyDect()
  1557. {
  1558. if (this.bitmap == null)
  1559. {
  1560. return;
  1561. }
  1562. if (!double.TryParse(textBox6.Text, out sigma))
  1563. {
  1564. return;
  1565. }
  1566. //string inputImageFile = "原始图片1.jpg";// "j1.JPG";
  1567. ////char[] inputImageFile2 = inputImageFile.ToCharArray();
  1568. /*Mat */
  1569. OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
  1570. grainApplygrainboundaries = this.applyRadioButton1.Checked ? 1 : 0;
  1571. m_iStandardImage = this.radioButton1/*checkBox3*/.Checked ? 1 : 0;
  1572. iConnect = this.checkBox4.Checked ? 1 : 0;
  1573. /*int */
  1574. dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
  1575. /*int */
  1576. smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
  1577. //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
  1578. /*int */
  1579. enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
  1580. /*double[] */
  1581. cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
  1582. procClass = new ProgressThreadProcClass();
  1583. procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyDectAction), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"));
  1584. //if (isOtherGrainSizeStandardDialog)
  1585. //{
  1586. // if (OrgImg0 != null)
  1587. // {
  1588. // this.documentWorkspace.PhaseModels[1].mat = OrgImg0.Clone();
  1589. // this.documentWorkspace.Refresh();
  1590. // OrgImg0 = null;
  1591. // }
  1592. // if (OrgImg != null)
  1593. // {
  1594. // OrgImg.Dispose();
  1595. // OrgImg = null;
  1596. // }
  1597. // return;//##
  1598. //}
  1599. if (OrgImg0 != null)
  1600. {
  1601. if (getCurrentWorkspace().GraphicsList.IsExsitView() && ShowDrawClassView)
  1602. {
  1603. Vec4b vec4 = new Vec4b(0, 0, 0, 0);
  1604. //视场图像
  1605. Mat exsitViewMatOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(getCurrentWorkspace().GetFullSizeWithRegion());
  1606. for (int y = 0; y < exsitViewMatOrg/*temp*/.Rows; y++)
  1607. {
  1608. for (int x = 0; x < exsitViewMatOrg/*temp*/.Cols; x++)
  1609. {
  1610. if (exsitViewMatOrg.At<Vec4b>(y, x).Item3 == 0)
  1611. OrgImg0.Set(y, x, vec4);//不在视场图像范围内
  1612. }
  1613. }
  1614. }
  1615. this.documentWorkspace.PhaseModels[0].mat = OrgImg0.Clone();
  1616. this.documentWorkspace.Refresh();
  1617. if (PhaseModel0MatCopy != null)
  1618. {
  1619. PhaseModel0MatCopy.Dispose();
  1620. PhaseModel0MatCopy = null;
  1621. }
  1622. PhaseModel0MatCopy = this.documentWorkspace.PhaseModels[0].mat.Clone();
  1623. this.resetOperationsAction();
  1624. OrgImg0 = null;
  1625. }
  1626. if (OrgImg != null)
  1627. {
  1628. OrgImg.Dispose();
  1629. OrgImg = null;
  1630. }
  1631. ////this.runDect(OrgImg, dark, smooth_type, sigma, enhance, cell_size);//###########################2
  1632. //if (!isAreaType)
  1633. // AddRectangleToRectangleFCaps();//0916###18747
  1634. //else
  1635. //{
  1636. // GetClassNumberOfGrains();
  1637. //}
  1638. }
  1639. private void applyDectAction()
  1640. {
  1641. OrgImg0 = /*GrainBoundaryEditingDialog.*/runDect(m_iStandardImage, iConnect, this.panel1.BackColor, OrgImg, dark, smooth_type, sigma, enhance, cell_size);
  1642. if (procClass != null) procClass.DismissProgressAction(this);
  1643. }
  1644. private void checkBox2_CheckedChanged(object sender, EventArgs e)
  1645. {
  1646. if (this.checkBox1.Checked)
  1647. {
  1648. this.applyDect();
  1649. }
  1650. }
  1651. private void checkBox3_CheckedChanged(object sender, EventArgs e)
  1652. {
  1653. //标准图像
  1654. if (this.checkBox3.Checked)
  1655. {
  1656. this.checkBox2.Visible = false;
  1657. this.label1.Visible = false;
  1658. this.label6.Visible = false;
  1659. this.label7.Visible = false;
  1660. this.label8.Visible = false;
  1661. this.textBox6.Visible = false;
  1662. this.numericUpDown1.Visible = false;
  1663. this.numericUpDown2.Visible = false;
  1664. this.comboBox2.Visible = false;
  1665. this.comboBox3.Visible = false;
  1666. this.checkBox4.Visible = true;
  1667. }
  1668. else
  1669. {
  1670. this.checkBox4.Visible = false;
  1671. this.checkBox2.Visible = true;
  1672. this.label1.Visible = true;
  1673. this.label6.Visible = true;
  1674. this.label7.Visible = true;
  1675. this.label8.Visible = true;
  1676. this.textBox6.Visible = true;
  1677. this.numericUpDown1.Visible = true;
  1678. this.numericUpDown2.Visible = true;
  1679. this.comboBox2.Visible = true;
  1680. this.comboBox3.Visible = true;
  1681. }
  1682. }
  1683. 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)
  1684. {
  1685. Mat GryImg = new Mat();
  1686. Mat OrgImg = new Mat();
  1687. /////
  1688. if (4 == OrgImg0.Channels())
  1689. {
  1690. Cv2.CvtColor(OrgImg0, OrgImg, ColorConversionCodes.BGRA2BGR);
  1691. }
  1692. else
  1693. {
  1694. OrgImg = OrgImg0.Clone();
  1695. }
  1696. In5segmsurf prm = new In5segmsurf();
  1697. prm.OrgImg = OrgImg;
  1698. /////
  1699. //Cv2.ImShow("src", OrgImg);//kkkkk
  1700. ////Cv2.WaitKey(0);//kkkkk
  1701. //转为为灰度?
  1702. if (3 == OrgImg.Channels() || 4 == OrgImg.Channels())
  1703. {
  1704. Cv2.CvtColor(OrgImg, GryImg, ColorConversionCodes.RGB2GRAY);
  1705. }
  1706. else
  1707. {
  1708. if (1 == OrgImg.Channels())
  1709. {
  1710. GryImg = OrgImg.Clone();
  1711. }
  1712. else
  1713. {
  1714. return null;
  1715. }
  1716. }
  1717. if (0 == m_iStandardImage)
  1718. {
  1719. if (1 == dark)
  1720. {//采用新的算法不需要这里的处理了
  1721. // int Rows = GryImg.Rows;
  1722. // int Cols = GryImg.Cols;
  1723. // int[] point = new int[2];
  1724. // //单通道图像的反色
  1725. // for (point[0] = 0; point[0] < Rows; point[0]++)
  1726. // {
  1727. // for (point[1] = 0; point[1] < Cols; point[1]++)
  1728. // {
  1729. // byte bTemp = (byte)(255 - GryImg.At<byte>(point[0], point[1]));
  1730. // GryImg.Set<byte>(point, bTemp);//mmmmm
  1731. // }
  1732. // }
  1733. //}
  1734. //if (2 == dark)
  1735. //{
  1736. // Mat TempImg = GryImg.Clone();
  1737. // Cv2.Sobel(TempImg, GryImg, -1, 2, 2, 3);//mmmmm
  1738. }
  1739. //Cv2.ImShow("src", GryImg);//kkkkk
  1740. //Cv2.WaitKey(0);//kkkkk
  1741. //去噪
  1742. if (0 == smooth_type)
  1743. {
  1744. prm.smoothim_method = "gaussian";
  1745. }
  1746. else
  1747. {
  1748. if (1 == smooth_type)
  1749. {
  1750. prm.smoothim_method = "dirced";
  1751. }
  1752. else
  1753. {
  1754. return null;
  1755. }
  1756. }
  1757. //晶界增强
  1758. if (1 == enhance)
  1759. {
  1760. prm.filterridges = 1;
  1761. }
  1762. else
  1763. {
  1764. prm.filterridges = 0;
  1765. }
  1766. //调用算法
  1767. prm.gaussian_stdev = sigma;
  1768. prm.LEVEL = ".3";
  1769. prm.classifycells_convexarea = 0.50;
  1770. prm.classifycells_convexperim = 0.45;
  1771. OLDcellsegm cellsegm = new OLDcellsegm();
  1772. string[] namehere = new string[1] { "prm" };
  1773. In6segmsurf IN6BNImgs = new In6segmsurf();
  1774. OUTsegmsurf RSTss = cellsegm.mf_segmsurf_progress_auto(GryImg, cell_size[0], cell_size[1], namehere, prm, IN6BNImgs, phaseColor);
  1775. Cv2.CvtColor(RSTss.wat, OrgImg0, ColorConversionCodes.BGR2BGRA);
  1776. }
  1777. else
  1778. {
  1779. OLDcellsegm cellsegm = new OLDcellsegm();
  1780. OrgImg0/*Mat WAT*/ = cellsegm.ProFroStandardImage(GryImg, iConnect, phaseColor);
  1781. //string filename = "D:\\result.jpg";
  1782. //Cv2.ImWrite(filename, WAT);
  1783. }
  1784. return OrgImg0;
  1785. }
  1786. private void panel1_click(object sender, EventArgs e)
  1787. {
  1788. this.panelC = (Panel)sender;
  1789. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
  1790. this.colorsFormGrid.ShowDialog();
  1791. }
  1792. #endregion
  1793. private void radioButton_CheckedChanged(object sender, EventArgs e)
  1794. {
  1795. //非标准图像
  1796. if (this.radioButton2.Checked)
  1797. {
  1798. this.checkBox4.Visible = false;
  1799. //this.checkBox2.Visible = true;
  1800. //this.label1.Visible = true;
  1801. //this.label6.Visible = true;
  1802. //this.label7.Visible = true;
  1803. //this.label8.Visible = true;
  1804. //this.textBox6.Visible = true;
  1805. //this.numericUpDown1.Visible = true;
  1806. //this.numericUpDown2.Visible = true;
  1807. //this.comboBox2.Visible = true;
  1808. //this.comboBox3.Visible = true;
  1809. }
  1810. }
  1811. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  1812. {
  1813. //标准图像
  1814. if (this.radioButton1.Checked)
  1815. {
  1816. this.checkBox2.Visible = false;
  1817. this.label1.Visible = false;
  1818. this.label6.Visible = false;
  1819. this.label7.Visible = false;
  1820. this.label8.Visible = false;
  1821. this.textBox6.Visible = false;
  1822. this.numericUpDown1.Visible = false;
  1823. this.numericUpDown2.Visible = false;
  1824. this.comboBox2.Visible = false;
  1825. this.comboBox3.Visible = false;
  1826. this.checkBox4.Visible = true;
  1827. }
  1828. }
  1829. private void GrainBoundryEditingDialog_FormClosing(object sender, FormClosingEventArgs e)
  1830. {
  1831. string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml";
  1832. bool createNewFile = !System.IO.File.Exists(xmlFilePath);
  1833. if (createNewFile)
  1834. xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel.xml";
  1835. Base.SettingModel.GrainBoundryDectModel grainBoundryDectModel = Base.CommTool.XmlSerializeHelper.DESerializer<Base.SettingModel.GrainBoundryDectModel>(Base.CommTool.FileOperationHelper.ReadStringFromFile(xmlFilePath, System.IO.FileMode.Open));
  1836. if (double.TryParse(textBox6.Text, out sigma))
  1837. grainBoundryDectModel.sigma = sigma;
  1838. grainBoundryDectModel.grainColor = this.phaseColor.ToArgb();
  1839. grainApplygrainboundaries = this.applyRadioButton1.Checked ? 1 : 0;
  1840. grainBoundryDectModel.grainApplygrainboundaries = grainApplygrainboundaries;
  1841. m_iStandardImage = this.radioButton1.Checked ? 1 : 0;
  1842. grainBoundryDectModel.m_iStandardImage = m_iStandardImage;
  1843. iConnect = this.checkBox4.Checked ? 1 : 0;
  1844. grainBoundryDectModel.iConnect = iConnect;
  1845. dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
  1846. grainBoundryDectModel.dark = dark;
  1847. smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
  1848. grainBoundryDectModel.smooth_type = smooth_type;
  1849. enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
  1850. grainBoundryDectModel.enhance = enhance;
  1851. cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
  1852. grainBoundryDectModel.cell1_size = cell_size[0];
  1853. grainBoundryDectModel.cell2_size = cell_size[1];
  1854. xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml";
  1855. string userInfoXml = Base.CommTool.XmlSerializeHelper.XmlSerialize<Base.SettingModel.GrainBoundryDectModel>(grainBoundryDectModel);
  1856. Base.CommTool.FileOperationHelper.WriteStringToFile(userInfoXml, xmlFilePath, System.IO.FileMode.Create);
  1857. }
  1858. private void GrainBoundryEditingDialog_Load(object sender, EventArgs e)
  1859. {
  1860. string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainBoundryDectModel_" + this.menuId + ".xml";
  1861. bool createNewFile = !System.IO.File.Exists(xmlFilePath);
  1862. if (createNewFile)
  1863. return;
  1864. Base.SettingModel.GrainBoundryDectModel grainBoundryDectModel = Base.CommTool.XmlSerializeHelper.DESerializer<Base.SettingModel.GrainBoundryDectModel>(Base.CommTool.FileOperationHelper.ReadStringFromFile(xmlFilePath, System.IO.FileMode.Open));
  1865. this.phaseColor = Color.FromArgb(grainBoundryDectModel.grainColor == 0 ? Color.Red.ToArgb() : grainBoundryDectModel.grainColor);
  1866. this.panel1.BackColor = this.phaseColor;
  1867. sigma = grainBoundryDectModel.sigma;
  1868. textBox6.Text = sigma + "";
  1869. grainApplygrainboundaries = grainBoundryDectModel.grainApplygrainboundaries;
  1870. this.applyRadioButton1.Checked = (grainApplygrainboundaries == 1);
  1871. this.applyRadioButton2.Checked = (grainApplygrainboundaries != 1);
  1872. m_iStandardImage = grainBoundryDectModel.m_iStandardImage;
  1873. this.radioButton1.Checked = (m_iStandardImage == 1);
  1874. iConnect = grainBoundryDectModel.iConnect;
  1875. this.checkBox4.Checked = (iConnect == 1);
  1876. dark = grainBoundryDectModel.dark;
  1877. this.comboBox2.SelectedIndex = dark;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
  1878. smooth_type = grainBoundryDectModel.smooth_type;
  1879. this.comboBox3.SelectedIndex = smooth_type;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
  1880. enhance = grainBoundryDectModel.enhance;
  1881. this.checkBox2.Checked = (enhance == 1);// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
  1882. cell_size = new double[2] { (double)grainBoundryDectModel.cell1_size, (double)grainBoundryDectModel.cell2_size }; ;// new double[2] { 0.01, 500 };//晶界大小
  1883. numericUpDown1.Value = Convert.ToDecimal(cell_size[0]);
  1884. numericUpDown2.Value = Convert.ToDecimal(cell_size[1]);
  1885. }
  1886. /// <summary>
  1887. /// 根据当前操作位置处理图片,并刷新操作按钮状态
  1888. /// </summary>
  1889. /// <param name="OperationTag"></param>
  1890. private void RefreshMatsToIndex(int OperationTag)
  1891. {
  1892. //...处理图片(this.OperationIndex)
  1893. this.OperationIndex = OperationTag;
  1894. ///// 操作类型
  1895. //private int pointKtype = 0;
  1896. if (PhaseModel0MatCopy != null && this.OperationIndex >= 0)
  1897. {
  1898. Mat newModel0Mat = PhaseModel0MatCopy.Clone();
  1899. for (int i = 0; i <= this.OperationIndex; i++)
  1900. {
  1901. //操作类型 0,没有操作 1,折线添加 2,直线添加 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
  1902. int opeType = this.OperationKtypeList[i];
  1903. PointF[] opePoints = this.OperationsList[i];
  1904. // 折线删除
  1905. if (opeType == 11 && opePoints.Length > 1)
  1906. {
  1907. newModel0Mat/*this.documentWorkspace.PhaseModels[0].mat*/ = PreActionIntent.PolygonDelete(newModel0Mat/*this.documentWorkspace.PhaseModels[0].mat*/, opePoints.ToList()/*pointFloatArray*/);
  1908. //this.pointKtype = 0;
  1909. //this.documentWorkspace.Refresh();
  1910. }
  1911. // 折线添加
  1912. if (opeType == 1 && opePoints.Length > 1)
  1913. {
  1914. //保存处理后的图片
  1915. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newModel0Mat);
  1916. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1917. Graphics graphics = Graphics.FromImage(newBit);
  1918. //Draw(graphics, false);
  1919. // 抗锯齿
  1920. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1921. // 折线添加
  1922. if (opeType == 1 && opePoints.Length >= 2)
  1923. {
  1924. Pen pen = new Pen(this.phaseColor, 1);
  1925. graphics.DrawLines(pen, opePoints);
  1926. pen.Dispose();
  1927. }
  1928. newModel0Mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  1929. }
  1930. // 圆形删除/椭圆删除
  1931. if ((opeType == 14 || opeType == 12) && opePoints.Length == 2)
  1932. {
  1933. RectangleF rectangleFOpe = new RectangleF(opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y);
  1934. if (this.pointKtype == 14)
  1935. newModel0Mat = PreActionIntent.OvalDelete(newModel0Mat, rectangleFOpe);
  1936. else
  1937. newModel0Mat = PreActionIntent.OvalDelete(newModel0Mat, rectangleFOpe);
  1938. }
  1939. // 矩形删除
  1940. if (opeType == 13 && opePoints.Length == 2)
  1941. {
  1942. RectangleF rectangleFOpe = new RectangleF(opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y);
  1943. newModel0Mat = PreActionIntent.RectangleDelete(newModel0Mat, rectangleFOpe);
  1944. }
  1945. // 直线添加
  1946. if (opeType == 2 && opePoints.Length == 2/*this.startPoint.X > -1 && this.startPoint.Y > -1*/)
  1947. {
  1948. //保存处理后的图片
  1949. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newModel0Mat);
  1950. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1951. Graphics graphics = Graphics.FromImage(newBit);
  1952. //Draw(graphics, false);
  1953. // 抗锯齿
  1954. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1955. // 直线添加
  1956. if (opeType == 2 && opePoints.Length == 2/*this.startPoint.X > -1 && this.startPoint.Y > -1 && this.endPoint.X > -1 && this.endPoint.Y > -1*/)
  1957. {
  1958. Pen pen = new Pen(this.phaseColor, 1);
  1959. graphics.DrawLine(pen, opePoints[0].X, opePoints[0].Y, opePoints[1].X, opePoints[1].Y);
  1960. //////pen.DashStyle = DashStyle.Dash;
  1961. //g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
  1962. pen.Dispose();
  1963. }
  1964. newModel0Mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  1965. }
  1966. }
  1967. this.documentWorkspace.PhaseModels[0].mat = newModel0Mat;
  1968. this.documentWorkspace.Refresh();
  1969. }
  1970. else if (PhaseModel0MatCopy != null)
  1971. {
  1972. this.documentWorkspace.PhaseModels[0].mat = PhaseModel0MatCopy.Clone();
  1973. this.documentWorkspace.Refresh();
  1974. }
  1975. //刷新操作按钮的状态
  1976. this.RefreshOperationsButtons();
  1977. }
  1978. /// <summary>
  1979. /// 操作-重置
  1980. /// </summary>
  1981. private void resetOperationsAction()
  1982. {
  1983. this.OperationIndex = -1;
  1984. this.RefreshOperationsToIndex();
  1985. this.RefreshOperationsButtons();
  1986. }
  1987. /// <summary>
  1988. /// 操作-重置
  1989. /// </summary>
  1990. /// <param name="sender"></param>
  1991. /// <param name="e"></param>
  1992. private void resetButton_Click(object sender, EventArgs e)
  1993. {
  1994. if (PhaseModel0MatCopy != null)
  1995. {
  1996. this.documentWorkspace.PhaseModels[0].mat = PhaseModel0MatCopy.Clone();
  1997. this.documentWorkspace.Refresh();
  1998. }
  1999. this.resetOperationsAction();
  2000. }
  2001. /// <summary>
  2002. /// 操作-撤销
  2003. /// </summary>
  2004. /// <param name="sender"></param>
  2005. /// <param name="e"></param>
  2006. private void undoButton_Click(object sender, EventArgs e)
  2007. {
  2008. if (this.OperationIndex >= 0)
  2009. {
  2010. this.RefreshMatsToIndex(this.OperationIndex - 1);
  2011. }
  2012. else
  2013. this.undoButton.Enabled = false;
  2014. }
  2015. /// <summary>
  2016. /// 操作-恢复
  2017. /// </summary>
  2018. /// <param name="sender"></param>
  2019. /// <param name="e"></param>
  2020. private void redoButton_Click(object sender, EventArgs e)
  2021. {
  2022. if (this.OperationIndex < this.OperationKtypeList.Count - 1)
  2023. {
  2024. this.RefreshMatsToIndex(this.OperationIndex + 1);
  2025. }
  2026. else
  2027. this.redoButton.Enabled = false;
  2028. }
  2029. }
  2030. }