BinaryExtractDialog.cs 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  1. using Metis.ParameterSet;
  2. using OpenCvSharp;
  3. using PaintDotNet.Base;
  4. using PaintDotNet.Base.CommTool;
  5. using PaintDotNet.Base.Functionodel;
  6. using PaintDotNet.Base.SettingModel;
  7. using PaintDotNet.CustomControl;
  8. using PaintDotNet.Data.Param;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Windows.Forms;
  15. namespace PaintDotNet.Binarization
  16. {
  17. /// <summary>
  18. /// 二值提取
  19. /// </summary>
  20. internal class BinaryExtractDialog : PdnBaseForm
  21. {
  22. #region 控件
  23. private GroupBox groupBox1;
  24. private GroupBox groupBox2;
  25. private CheckBox checkBox1;
  26. private Button button2;
  27. private Button button1;
  28. private GroupBox groupBox3;
  29. private GroupBox groupBox4;
  30. private ListView listView1;
  31. private ImageList imageList1;
  32. private IContainer components;
  33. private GroupBox groupBox5;
  34. private GroupBox groupBox6;
  35. private GroupBox groupBox7;
  36. private Label label1;
  37. private ComboBox comboBox1;
  38. private Button button3;
  39. private Button button4;
  40. private Button button5;
  41. private CheckBox checkBox2;
  42. private CheckBox checkBox3;
  43. private CheckBox checkBox4;
  44. private NumericUpDown numericUpDown2;
  45. private NumericUpDown numericUpDown1;
  46. private RadioButton radioButton2;
  47. private RadioButton radioButton1;
  48. private Panel panel2;
  49. private Label label2;
  50. private Button button6;
  51. private Button button7;
  52. private CheckBox checkBox5;
  53. private CustomControl.DecimalScopeControl numberScopeControl3;
  54. private CustomControl.DecimalScopeControl numberScopeControl2;
  55. private CustomControl.DecimalScopeControl numberScopeControl1;
  56. private RadioButton radioButton5;
  57. private RadioButton radioButton4;
  58. private RadioButton radioButton3;
  59. private CustomControl.HistogramControl histogramControl1;
  60. private Button button8;
  61. private Button button9;
  62. private Button button10;
  63. #endregion
  64. /// <summary>
  65. /// 主控件
  66. /// </summary>
  67. private AppWorkspace appWorkspace;
  68. /// <summary>
  69. /// 公共按钮
  70. /// </summary>
  71. private CommonControlButtons commonControlButtons;
  72. /// <summary>
  73. /// 图像面板
  74. /// </summary>
  75. private DocumentWorkspaceWindow documentWorkspace;
  76. /// <summary>
  77. /// 处理程序
  78. /// </summary>
  79. private ParamObject action = new Data.Action.Action901();
  80. /// <summary>
  81. /// 步长 初始值1,依次增加
  82. /// </summary>
  83. private string stepLength = "00" + Startup.instance.step_length;
  84. /// <summary>
  85. /// 调色板
  86. /// </summary>
  87. private ColorsForm colorsFormGrid;
  88. /// <summary>
  89. /// 选中图片的mat
  90. /// </summary>
  91. private Mat imageMat;
  92. /// <summary>
  93. /// 参数下拉的集合
  94. /// </summary>
  95. private List<string> files = new List<string>();
  96. /// <summary>
  97. /// 初始系统参数配置值
  98. /// </summary>
  99. private BinaryExtractionModel binaryExtractionModel;
  100. /// <summary>
  101. /// 选中的左侧list的下标
  102. /// </summary>
  103. private int index = 0;
  104. /// <summary>
  105. /// 单位标尺
  106. /// </summary>
  107. private double unitLength = 1;
  108. /// <summary>
  109. /// 另存为弹出框显示
  110. /// </summary>
  111. private CreateNameDialog dialog;
  112. private int menuId;
  113. private string menuName;
  114. /// <summary>
  115. /// 各个图片对应数据
  116. /// </summary>
  117. private GrainSizeAnalysisModel analysisModel;
  118. private const string ParamKey_Paramlist = "paramlist";//参数列表
  119. private const string ParamKey_NewPic = "newPic";//创建新图
  120. public BinaryExtractDialog(AppWorkspace appWorkspace, string dialogText, PdnMenuItem menuItem)
  121. {
  122. this.menuId = menuItem.MenuId;
  123. this.menuName = menuItem.Text;
  124. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryActionSaving\\ParameterSaving.xml";
  125. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  126. this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
  127. foreach (var item in this.analysisModel.ListParam)
  128. item.setValue();
  129. InitializeComponent();
  130. InitializeLanguageText();
  131. //
  132. // 设置Dialog属性
  133. //
  134. this.appWorkspace = appWorkspace;
  135. this.Text = dialogText;
  136. this.Icon = PdnInfo.AppIcon;
  137. //
  138. // 初始化目标选择的背景图
  139. //
  140. this.InitButtonBackgroundImage();
  141. //
  142. //初始化色板
  143. //
  144. this.colorsFormGrid = new ColorsForm();
  145. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  146. //
  147. //初始化图像控件
  148. //
  149. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  150. this.documentWorkspace.Dock = DockStyle.Fill;
  151. this.documentWorkspace.HookMouseEvents();
  152. this.documentWorkspace.AuxiliaryLineEnabled = false;
  153. this.documentWorkspace.Visible = false;
  154. this.groupBox1.Controls.Add(documentWorkspace);
  155. //
  156. //初始化操作按钮
  157. //
  158. this.commonControlButtons = new CommonControlButtons();
  159. this.commonControlButtons.Dock = DockStyle.Top;
  160. this.commonControlButtons.Height = 30;
  161. this.commonControlButtons.HideZoomToWindowAndActualSize();
  162. this.groupBox1.Controls.Add(commonControlButtons);
  163. //
  164. //初始化相
  165. //
  166. PhaseModel model = new PhaseModel();
  167. model.choise = true;
  168. model.mat = null;
  169. model.color = panel2.BackColor.ToArgb();
  170. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  171. model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text");
  172. this.documentWorkspace.PhaseModels.Add(model);
  173. //
  174. // 设置listview事件
  175. //
  176. this.listView1.SelectedIndexChanged += new EventHandler(this.ListViewSelectedIndexChanged);
  177. InitParameterList();
  178. //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
  179. if (this.appWorkspace.ScriptRunning && this.appWorkspace.ScriptCurrentParam != null && this.appWorkspace.ScriptCurrentParam.MenuId == action.MenuId)
  180. {
  181. foreach (Args arg in action.Lists)
  182. {
  183. Args param1 = this.appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key));
  184. if (param1.value != null)
  185. arg.Value = param1.value;
  186. }
  187. foreach (Args args in action.Lists)
  188. {
  189. if (args.Key == "colorInterval")
  190. {
  191. this.binaryExtractionModel.ColorInterval = (Boolean)args.Value ? 2 : 1;
  192. }
  193. else if (args.Key == "scope1")
  194. {
  195. List<double> twoL = (List<double>)args.Value;
  196. this.binaryExtractionModel.ColorOneStart = (int)twoL[0];
  197. this.binaryExtractionModel.ColorOneEnd = (int)twoL[1];
  198. }
  199. else if (args.Key == "scope2")
  200. {
  201. List<double> twoL = (List<double>)args.Value;
  202. this.binaryExtractionModel.ColorTwoStart = (int)twoL[0];
  203. this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1];
  204. }
  205. else if (args.Key == "scope3")
  206. {
  207. List<double> twoL = (List<double>)args.Value;
  208. this.binaryExtractionModel.ColorThreeStart = (int)twoL[0];
  209. this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1];
  210. }
  211. else if (args.Key == "deleteBoundaryObject")
  212. {
  213. this.binaryExtractionModel.DeleteBoundaryObject = (bool)args.Value;
  214. }
  215. else if (args.Key == "holeFilling")
  216. {
  217. this.binaryExtractionModel.HoleFilling = (bool)args.Value;
  218. }
  219. else if (args.Key == "debrisRemoval")
  220. {
  221. this.binaryExtractionModel.DebrisRemoval = (bool)args.Value;
  222. }
  223. else if (args.Key == "scope4")
  224. {
  225. this.binaryExtractionModel.DebrisAreaStart = (int)((List<double>)args.Value)[0];
  226. this.binaryExtractionModel.DebrisAreaEnd = (int)((List<double>)args.Value)[1];
  227. }
  228. else if (args.Key == "binaryStyle")
  229. {
  230. this.binaryExtractionModel.BinaryStyle = (int)args.Value;
  231. }
  232. else if (args.Key == "phaseColor")
  233. {
  234. this.binaryExtractionModel.PhaseColor = (int)args.Value;
  235. }
  236. else if (args.Key == "targetSelection")
  237. {
  238. this.binaryExtractionModel.TargetSelection = (int)args.Value - 1;
  239. }
  240. else if (args.Key == "createNewImg")
  241. {
  242. checkBox1.Checked = (int)args.Value == 0 ? true : false;
  243. }
  244. }
  245. this.appWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数
  246. }
  247. InitPicList();
  248. InitHistogramDragEvent();
  249. InitCommonButtonEvent();
  250. this.Shown += new EventHandler(this.ShownChoiseItemAndInitData);
  251. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing);
  252. }
  253. private void formClosing(object sender, EventArgs e)
  254. {
  255. #region [开启脚本录制]
  256. if (appWorkspace.startScriptRecording)
  257. {
  258. getScriptRecording();
  259. }
  260. #endregion
  261. }
  262. private void ShownChoiseItemAndInitData(object sender, EventArgs e)
  263. {
  264. //滚动到指定的行位置
  265. this.listView1.EnsureVisible(index);
  266. // 初始化数据
  267. this.imageMat = this.appWorkspace.DocumentWorkspaces[index].CompositionSurface.CreatedAliasedMat();
  268. Document document = Document.FromImageMat(imageMat.Clone());
  269. this.documentWorkspace.Document = document;
  270. this.documentWorkspace.Visible = true;
  271. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[index].GraphicsList;
  272. //this.applyButtonImpl(null, null);
  273. //显示直方图
  274. this.histogramControl1.CreateHistogram(this.imageMat, true, 339, 130, 0);
  275. GetListParamModel();
  276. InitParameterToControl();
  277. }
  278. private void InitButtonBackgroundImage()
  279. {
  280. this.button8.FlatStyle = FlatStyle.Flat;
  281. this.button8.FlatAppearance.BorderSize = 0;
  282. this.button8.BackgroundImageLayout = ImageLayout.Zoom;
  283. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
  284. this.button8.Click += new EventHandler(this.button8_click);
  285. this.button9.FlatStyle = FlatStyle.Flat;
  286. this.button9.FlatAppearance.BorderSize = 0;
  287. this.button9.BackgroundImageLayout = ImageLayout.Zoom;
  288. this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference;
  289. this.button9.Click += new EventHandler(this.button9_click);
  290. this.button10.FlatStyle = FlatStyle.Flat;
  291. this.button10.FlatAppearance.BorderSize = 0;
  292. this.button10.BackgroundImageLayout = ImageLayout.Zoom;
  293. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
  294. this.button10.Click += new EventHandler(this.button10_click);
  295. }
  296. private void button8_click(object sender, EventArgs e)
  297. {
  298. this.binaryExtractionModel.TargetSelection = 1;
  299. this.radioButton3.Checked = true;
  300. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle1.png").Reference;
  301. this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference;
  302. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
  303. }
  304. private void button9_click(object sender, EventArgs e)
  305. {
  306. this.binaryExtractionModel.TargetSelection = 2;
  307. this.radioButton4.Checked = true;
  308. this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference;
  309. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
  310. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
  311. }
  312. private void button10_click(object sender, EventArgs e)
  313. {
  314. this.binaryExtractionModel.TargetSelection = 3;
  315. this.radioButton5.Checked = true;
  316. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle3.png").Reference;
  317. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
  318. this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference;
  319. }
  320. private void InitCommonButtonEvent()
  321. {
  322. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  323. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  324. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  325. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  326. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  327. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  328. }
  329. private void zoomInButton_Click(object sender, EventArgs e)
  330. {
  331. if (this.imageMat != null)
  332. this.documentWorkspace.ZoomIn();
  333. }
  334. private void zoomOutButton_Click(object sender, EventArgs e)
  335. {
  336. if (this.imageMat != null)
  337. this.documentWorkspace.ZoomOut();
  338. }
  339. private void zoomToWindowButton_Click(object sender, EventArgs e)
  340. {
  341. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  342. }
  343. private void actualSizeButton_Click(object sender, EventArgs e)
  344. {
  345. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  346. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  347. }
  348. private void pointerButton_Click(object sender, EventArgs e)
  349. {
  350. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  351. }
  352. private void mobileModeButton_Click(object sender, EventArgs e)
  353. {
  354. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  355. }
  356. private void InitHistogramDragEvent()
  357. {
  358. this.histogramControl1.DragOneEventActionFinish += new EventHandler<EventArgs<int>>(this.DragOneEvent);
  359. this.histogramControl1.DragTwoEventActionFinish += new EventHandler<EventArgs<int>>(this.DragTwoEvent);
  360. this.histogramControl1.DragThreeEventActionFinish += new EventHandler<EventArgs<int>>(this.DragThreeEvent);
  361. this.histogramControl1.DragFourEventActionFinish += new EventHandler<EventArgs<int>>(this.DragFourEvent);
  362. this.histogramControl1.DragFiveEventActionFinish += new EventHandler<EventArgs<int[]>>(this.DragFiveEvent);
  363. this.histogramControl1.DragSixEventActionFinish += new EventHandler<EventArgs<int[]>>(this.DragSixEvent);
  364. }
  365. /// <summary>
  366. /// 颜色区间2 截止值变化
  367. /// </summary>
  368. /// <param name="sender"></param>
  369. /// <param name="e"></param>
  370. private void DragFourEvent(object sender, EventArgs<int> e)
  371. {
  372. this.numberScopeControl2.maxValue = e.Data;
  373. this.SetArgsValue();
  374. }
  375. /// <summary>
  376. /// 颜色区间2 起始值变化
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void DragThreeEvent(object sender, EventArgs<int> e)
  381. {
  382. this.numberScopeControl2.minValue = e.Data;
  383. this.SetArgsValue();
  384. }
  385. /// <summary>
  386. /// 颜色区间1 截止值变化
  387. /// </summary>
  388. /// <param name="sender"></param>
  389. /// <param name="e"></param>
  390. private void DragTwoEvent(object sender, EventArgs<int> e)
  391. {
  392. if (this.binaryExtractionModel.ColorInterval == 1)
  393. {
  394. this.numberScopeControl1.maxValue = e.Data;
  395. }
  396. else if (this.binaryExtractionModel.ColorInterval == 2)
  397. {
  398. this.numberScopeControl3.maxValue = e.Data;
  399. }
  400. this.SetArgsValue();
  401. }
  402. /// <summary>
  403. /// 颜色区间1 起始值变化
  404. /// </summary>
  405. /// <param name="sender"></param>
  406. /// <param name="e"></param>
  407. private void DragOneEvent(object sender, EventArgs<int> e)
  408. {
  409. if (this.binaryExtractionModel.ColorInterval == 1)
  410. {
  411. this.numberScopeControl1.minValue = e.Data;
  412. }
  413. else if (this.binaryExtractionModel.ColorInterval == 2)
  414. {
  415. this.numberScopeControl3.minValue = e.Data;
  416. }
  417. this.SetArgsValue();
  418. }
  419. private void DragFiveEvent(object sender, EventArgs<int[]> e)
  420. {
  421. this.DeleteEventHandler();
  422. if (this.binaryExtractionModel.ColorInterval == 1)
  423. {
  424. this.numberScopeControl1.minValue = e.Data[1];
  425. this.numberScopeControl1.maxValue = e.Data[0];
  426. }
  427. else if (this.binaryExtractionModel.ColorInterval == 2)
  428. {
  429. this.numberScopeControl3.minValue = e.Data[1];
  430. this.numberScopeControl3.maxValue = e.Data[0];
  431. }
  432. this.AddEventHandler();
  433. this.SetArgsValue();
  434. this.applyButtonImpl(null, null);
  435. }
  436. private void DragSixEvent(object sender, EventArgs<int[]> e)
  437. {
  438. this.DeleteEventHandler();
  439. /*if (this.binaryExtractionModel.ColorInterval == 1)
  440. {*/
  441. this.numberScopeControl2.minValue = e.Data[1];
  442. this.numberScopeControl2.maxValue = e.Data[0];
  443. /*}
  444. else if (this.binaryExtractionModel.ColorInterval == 2)
  445. {
  446. this.numberScopeControl3.minValue = e.Data[1];
  447. this.numberScopeControl3.maxValue = e.Data[0];
  448. }*/
  449. this.AddEventHandler();
  450. this.SetArgsValue();
  451. this.applyButtonImpl(null, null);
  452. }
  453. /// <summary>
  454. /// 初始化参数配置下拉
  455. /// </summary>
  456. public void InitParameterList(int index = 0, bool reInit = true)
  457. {
  458. List<string> fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\");
  459. files.Clear();
  460. foreach (string fileName in fileNames)
  461. {
  462. string name = fileName.Substring(0, fileName.LastIndexOf("."));
  463. files.Add(name);
  464. }
  465. this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged;
  466. this.comboBox1.DataSource = null;
  467. this.comboBox1.DataSource = files;
  468. string nowModelName = Startup.instance.configModel.BinaryParameter.Substring(0, Startup.instance.configModel.Watermark.LastIndexOf("."));
  469. if (index != 0)
  470. {
  471. if (this.files.Count > index)
  472. {
  473. this.comboBox1.SelectedIndex = index;
  474. }
  475. else
  476. {
  477. this.comboBox1.SelectedIndex = 0;
  478. }
  479. }
  480. else
  481. {
  482. this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName));
  483. }
  484. if (reInit)
  485. {
  486. this.binaryExtractionModel = XmlSerializeHelper.DESerializer<BinaryExtractionModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
  487. }
  488. this.panel2.BackColor = Color.FromArgb(this.binaryExtractionModel.PhaseColor);
  489. this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
  490. }
  491. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  492. {
  493. this.binaryExtractionModel = XmlSerializeHelper.DESerializer<BinaryExtractionModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
  494. this.InitParameterToControl();
  495. this.applyButtonImpl(null, null);
  496. }
  497. /// <summary>
  498. /// 把参数的值设置到控件上
  499. /// </summary>
  500. public void InitParameterToControl()
  501. {
  502. if (this.binaryExtractionModel != null)
  503. {
  504. //阈值相关
  505. //1个颜色区间还是2个
  506. if (this.binaryExtractionModel.ColorInterval == 1)
  507. {
  508. this.numberScopeControl2.Visible = false;
  509. this.numberScopeControl3.Visible = false;
  510. this.button6.Text = PdnResources.GetString("Menu.inverse.text");
  511. }
  512. else
  513. {
  514. this.numberScopeControl2.Visible = true;
  515. this.numberScopeControl3.Visible = true;
  516. this.button6.Text = PdnResources.GetString("Menu.Uncheck.text");
  517. }
  518. //删除事件
  519. this.DeleteEventHandler();
  520. this.numberScopeControl1.maxValue = this.binaryExtractionModel.ColorOneEnd;
  521. this.numberScopeControl1.minValue = this.binaryExtractionModel.ColorOneStart;
  522. this.numberScopeControl2.maxValue = this.binaryExtractionModel.ColorTwoEnd;
  523. this.numberScopeControl2.minValue = this.binaryExtractionModel.ColorTwoStart;
  524. this.numberScopeControl3.maxValue = this.binaryExtractionModel.ColorThreeEnd;
  525. this.numberScopeControl3.minValue = this.binaryExtractionModel.ColorThreeStart;
  526. this.checkBox2.Checked = this.binaryExtractionModel.DeleteBoundaryObject;
  527. this.checkBox3.Checked = this.binaryExtractionModel.HoleFilling;
  528. this.checkBox4.Checked = this.binaryExtractionModel.DebrisRemoval;
  529. this.numericUpDown1.Value = this.binaryExtractionModel.DebrisAreaStart;
  530. this.numericUpDown2.Value = this.binaryExtractionModel.DebrisAreaEnd;
  531. if (this.binaryExtractionModel.BinaryStyle == 1) this.radioButton1.Checked = true;
  532. if (this.binaryExtractionModel.BinaryStyle == 2) this.radioButton2.Checked = true;
  533. this.panel2.BackColor = Color.FromArgb(this.binaryExtractionModel.PhaseColor);
  534. if (this.binaryExtractionModel.TargetSelection == 1)
  535. {
  536. this.button8_click(null, null);
  537. }
  538. if (this.binaryExtractionModel.TargetSelection == 2)
  539. {
  540. this.button9_click(null, null);
  541. }
  542. if (this.binaryExtractionModel.TargetSelection == 3)
  543. {
  544. this.button10_click(null, null);
  545. }
  546. this.SetArgsValue();
  547. foreach (Args args in action.Lists)
  548. {
  549. if (args.Key == "targetSelection")
  550. {
  551. args.Value = this.binaryExtractionModel.TargetSelection;
  552. }
  553. else if (args.Key == "phaseColor")
  554. {
  555. args.Value = this.binaryExtractionModel.PhaseColor;
  556. }
  557. else if (args.Key == "binaryStyle")
  558. {
  559. args.Value = this.binaryExtractionModel.BinaryStyle;
  560. }
  561. }
  562. //添加事件
  563. this.AddEventHandler();
  564. //处理直方图
  565. if (this.binaryExtractionModel.ColorInterval == 1)
  566. {
  567. this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
  568. }
  569. else
  570. {
  571. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  572. (int)(this.numberScopeControl3.minValue),
  573. (int)(this.numberScopeControl3.maxValue),
  574. (int)(this.numberScopeControl2.minValue),
  575. (int)(this.numberScopeControl2.maxValue)
  576. );
  577. }
  578. }
  579. }
  580. /// <summary>
  581. /// 删除事件
  582. /// </summary>
  583. private void DeleteEventHandler()
  584. {
  585. this.numberScopeControl1.ValueChanged -= this.numberScope1_ValueChanged;
  586. this.numberScopeControl1.numericUpDown1.KeyUp -= this.numberScope1_ValueChanged;
  587. this.numberScopeControl1.numericUpDown2.KeyUp -= this.numberScope1_ValueChanged;
  588. this.numberScopeControl3.numericUpDown2.KeyUp -= this.applyButtonImpl;
  589. this.numberScopeControl2.ValueChanged -= this.numberScope2_ValueChanged;
  590. this.numberScopeControl2.numericUpDown1.KeyUp -= this.numberScope2_ValueChanged;
  591. this.numberScopeControl2.numericUpDown2.KeyUp -= this.numberScope2_ValueChanged;
  592. this.numberScopeControl3.ValueChanged -= this.numberScope3_ValueChanged;
  593. this.numberScopeControl3.numericUpDown1.KeyUp -= this.numberScope3_ValueChanged;
  594. this.numberScopeControl3.numericUpDown2.KeyUp -= this.numberScope3_ValueChanged;
  595. //this.numberScopeControl1.ValueChanged -= this.applyButtonImpl;
  596. //this.numberScopeControl2.ValueChanged -= this.applyButtonImpl;
  597. //this.numberScopeControl3.ValueChanged -= this.applyButtonImpl;
  598. this.radioButton1.CheckedChanged -= this.radioButton1Or2_ValueChanged;
  599. this.radioButton2.CheckedChanged -= this.radioButton1Or2_ValueChanged;
  600. this.checkBox2.CheckedChanged -= this.applyButtonImpl;
  601. this.panel2.BackColorChanged -= this.applyButtonImpl;
  602. this.checkBox3.CheckedChanged -= this.applyButtonImpl;
  603. this.checkBox4.CheckedChanged -= this.applyButtonImpl;
  604. this.numericUpDown1.KeyUp -= this.Detritus_ValueChanged;
  605. this.numericUpDown1.ValueChanged -= new System.EventHandler(this.Detritus_ValueChanged);
  606. this.numericUpDown2.KeyUp -= this.Detritus_ValueChanged;
  607. this.numericUpDown2.ValueChanged -= new System.EventHandler(this.Detritus_ValueChanged);
  608. this.radioButton5.CheckedChanged -= this.radioButton5_CheckedChanged;
  609. this.radioButton4.CheckedChanged -= this.radioButton5_CheckedChanged;
  610. this.radioButton3.CheckedChanged -= this.radioButton5_CheckedChanged;
  611. }
  612. /// <summary>
  613. /// 添加事件
  614. /// </summary>
  615. private void AddEventHandler()
  616. {
  617. this.numberScopeControl1.ValueChanged += this.numberScope1_ValueChanged;
  618. this.numberScopeControl1.numericUpDown1.KeyUp += this.numberScope1_ValueChanged;
  619. this.numberScopeControl1.numericUpDown2.KeyUp += this.numberScope1_ValueChanged;
  620. this.numberScopeControl3.numericUpDown2.KeyUp += this.applyButtonImpl;
  621. this.numberScopeControl2.ValueChanged += this.numberScope2_ValueChanged;
  622. this.numberScopeControl2.numericUpDown1.KeyUp += this.numberScope2_ValueChanged;
  623. this.numberScopeControl2.numericUpDown2.KeyUp += this.numberScope2_ValueChanged;
  624. this.numberScopeControl3.ValueChanged += this.numberScope3_ValueChanged;
  625. this.numberScopeControl3.numericUpDown1.KeyUp += this.numberScope3_ValueChanged;
  626. this.numberScopeControl3.numericUpDown2.KeyUp += this.numberScope3_ValueChanged;
  627. //this.numberScopeControl1.ValueChanged += this.applyButtonImpl;
  628. //this.numberScopeControl2.ValueChanged += this.applyButtonImpl;
  629. //this.numberScopeControl3.ValueChanged += this.applyButtonImpl;
  630. this.radioButton1.CheckedChanged += this.radioButton1Or2_ValueChanged;
  631. this.radioButton2.CheckedChanged += this.radioButton1Or2_ValueChanged;
  632. this.checkBox2.CheckedChanged += this.applyButtonImpl;
  633. this.panel2.BackColorChanged += this.applyButtonImpl;
  634. this.checkBox3.CheckedChanged += this.applyButtonImpl;
  635. this.checkBox4.CheckedChanged += this.applyButtonImpl;
  636. this.numericUpDown1.KeyUp += this.Detritus_ValueChanged;
  637. this.numericUpDown1.ValueChanged += new System.EventHandler(this.Detritus_ValueChanged);
  638. this.numericUpDown2.KeyUp += this.Detritus_ValueChanged;
  639. this.numericUpDown2.ValueChanged += new System.EventHandler(this.Detritus_ValueChanged);
  640. this.radioButton5.CheckedChanged += this.radioButton5_CheckedChanged;
  641. this.radioButton4.CheckedChanged += this.radioButton5_CheckedChanged;
  642. this.radioButton3.CheckedChanged += this.radioButton5_CheckedChanged;
  643. }
  644. /// <summary>
  645. /// 初始化图片列表数据
  646. /// </summary>
  647. public void InitPicList()
  648. {
  649. //初始化图片列表
  650. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  651. {
  652. this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.Thumbnail);//.CreateAliasedBitmap()
  653. this.listView1.Items.Add("", i);
  654. this.listView1.Items[i].ImageIndex = i;
  655. this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  656. this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  657. if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  658. {
  659. index = i;
  660. }
  661. }
  662. //
  663. // 初始化选中的数据
  664. //
  665. this.listView1.Items[index].Selected = true; //选中行
  666. }
  667. /// <summary>
  668. /// ListView图片选择改变事件
  669. /// </summary>
  670. /// <param name="sender"></param>
  671. /// <param name="e"></param>
  672. private void ListViewSelectedIndexChanged(object sender, EventArgs e)
  673. {
  674. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  675. {
  676. //获取标尺-微米
  677. unitLength = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].GetRuler(MeasurementUnit.Micron);
  678. this.appWorkspace.ActiveDocumentWorkspace = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index];
  679. this.imageMat = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].CompositionSurface.CreatedAliasedMat();
  680. Document document = Document.FromImageMat(imageMat.Clone());
  681. this.documentWorkspace.Document = document;
  682. this.documentWorkspace.Visible = true;
  683. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].GraphicsList;
  684. if (this.checkBox4.Checked)
  685. {
  686. //参数改变
  687. foreach (Args args in action.Lists)
  688. {
  689. if (args.Key == "scope4")
  690. {
  691. ((List<double>)args.Value)[0] = (double)numericUpDown1.Value / unitLength / unitLength;
  692. ((List<double>)args.Value)[1] = (double)numericUpDown2.Value / unitLength / unitLength;
  693. break;
  694. }
  695. }
  696. this.binaryExtractionModel.DebrisAreaStart = (int)((double)numericUpDown1.Value / unitLength / unitLength);
  697. this.binaryExtractionModel.DebrisAreaEnd = (int)((double)numericUpDown2.Value / unitLength / unitLength);
  698. }
  699. this.applyButtonImpl(sender, e);
  700. //显示直方图
  701. this.histogramControl1.CreateHistogram(this.imageMat, true, 339, 130, 0);
  702. }
  703. }
  704. /// <summary>
  705. /// 添加参数改变的监听
  706. /// </summary>
  707. /// <param name="sender"></param>
  708. /// <param name="e"></param>
  709. private void BinaryExtractionDialog_Load(object sender, EventArgs e)
  710. {
  711. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  712. foreach (Args args in action.Lists)
  713. {
  714. switch (args.Key)
  715. {
  716. case "phaseColor":
  717. args.Value = this.binaryExtractionModel.PhaseColor;
  718. break;
  719. default:
  720. break;
  721. }
  722. }
  723. this.applyButtonImpl(null, null);
  724. }
  725. #region 参数事件
  726. #region 阈值相关
  727. /// <summary>
  728. /// 反选/取消反选
  729. /// </summary>
  730. /// <param name="sender"></param>
  731. /// <param name="e"></param>
  732. private void button6_Click(object sender, EventArgs e)
  733. {
  734. this.DeleteEventHandler();
  735. if (numberScopeControl2.Visible)
  736. {
  737. this.numberScopeControl1.minValue = this.numberScopeControl3.maxValue;
  738. this.numberScopeControl1.maxValue = this.numberScopeControl2.minValue;
  739. this.numberScopeControl2.Visible = false;
  740. this.numberScopeControl3.Visible = false;
  741. this.button6.Text = PdnResources.GetString("Menu.inverse.text");
  742. this.binaryExtractionModel.ColorInterval = 1;
  743. this.histogramControl1.Flag = 1;
  744. //处理直方图
  745. this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
  746. }
  747. else
  748. {
  749. this.numberScopeControl3.minValue = 0;
  750. this.numberScopeControl3.maxValue = this.numberScopeControl1.minValue;
  751. this.numberScopeControl2.minValue = this.numberScopeControl1.maxValue;
  752. this.numberScopeControl2.maxValue = 255;
  753. this.numberScopeControl2.Visible = true;
  754. this.numberScopeControl3.Visible = true;
  755. this.button6.Text = PdnResources.GetString("Menu.Uncheck.text");
  756. this.binaryExtractionModel.ColorInterval = 2;
  757. this.histogramControl1.Flag = 2;
  758. //处理直方图
  759. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  760. (int)(this.numberScopeControl3.minValue),
  761. (int)(this.numberScopeControl3.maxValue),
  762. (int)(this.numberScopeControl2.minValue),
  763. (int)(this.numberScopeControl2.maxValue)
  764. );
  765. }
  766. this.AddEventHandler();
  767. this.SetArgsValue();
  768. this.applyButtonImpl(null, null);
  769. }
  770. /// <summary>
  771. /// 一个颜色区间时
  772. /// 区间值变化的事件
  773. /// </summary>
  774. /// <param name="sender"></param>
  775. /// <param name="e"></param>
  776. private void numberScope1_ValueChanged(object sender, EventArgs e)
  777. {
  778. this.SetArgsValue();
  779. this.binaryExtractionModel.ColorOneStart = (int)(this.numberScopeControl1.numericUpDown1.Value);
  780. this.binaryExtractionModel.ColorOneEnd = (int)(this.numberScopeControl1.numericUpDown2.Value);
  781. //处理直方图
  782. this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
  783. this.applyButtonImpl(null, null);
  784. }
  785. /// <summary>
  786. /// 二个颜色区间时
  787. /// 区间1值变化的事件
  788. /// </summary>
  789. /// <param name="sender"></param>
  790. /// <param name="e"></param>
  791. private void numberScope2_ValueChanged(object sender, EventArgs e)
  792. {
  793. this.SetArgsValue();
  794. this.binaryExtractionModel.ColorTwoStart = (int)(this.numberScopeControl2.minValue);
  795. this.binaryExtractionModel.ColorTwoEnd = (int)(this.numberScopeControl2.maxValue);
  796. //处理直方图
  797. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  798. (int)(this.numberScopeControl3.minValue),
  799. (int)(this.numberScopeControl3.maxValue),
  800. (int)(this.numberScopeControl2.minValue),
  801. (int)(this.numberScopeControl2.maxValue)
  802. );
  803. this.applyButtonImpl(null, null);
  804. }
  805. /// <summary>
  806. /// 二个颜色区间时
  807. /// 区间2值变化的事件
  808. /// </summary>
  809. /// <param name="sender"></param>
  810. /// <param name="e"></param>
  811. private void numberScope3_ValueChanged(object sender, EventArgs e)
  812. {
  813. this.SetArgsValue();
  814. this.binaryExtractionModel.ColorThreeStart = (int)(this.numberScopeControl3.minValue);
  815. this.binaryExtractionModel.ColorThreeEnd = (int)(this.numberScopeControl3.maxValue);
  816. //处理直方图
  817. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  818. (int)(this.numberScopeControl3.minValue),
  819. (int)(this.numberScopeControl3.maxValue),
  820. (int)(this.numberScopeControl2.minValue),
  821. (int)(this.numberScopeControl2.maxValue)
  822. );
  823. this.applyButtonImpl(null, null);
  824. }
  825. /// <summary>
  826. /// 自动阈值
  827. /// </summary>
  828. /// <param name="sender"></param>
  829. /// <param name="e"></param>
  830. private void button7_Click(object sender, EventArgs e)
  831. {
  832. this.DeleteEventHandler();
  833. if (imageMat != null)
  834. {
  835. //先计算阈值
  836. Mat mat = imageMat.Clone();// PaintDotNet.Camera.Tools.ToMat(bitmap);
  837. Mat gray = mat.CvtColor(ColorConversionCodes.BGR2GRAY);
  838. double otsu = Cv2.Threshold(gray, gray, 0, 255, ThresholdTypes.Triangle);
  839. if (otsu <= 10 || otsu >= 245)
  840. {
  841. otsu = Cv2.Threshold(mat.CvtColor(ColorConversionCodes.BGR2GRAY), gray, 0, 255, ThresholdTypes.Otsu);//.Triangle
  842. }
  843. {
  844. //隐藏控件
  845. this.numberScopeControl1.minValue = this.numberScopeControl3.maxValue;
  846. this.numberScopeControl1.maxValue = this.numberScopeControl2.minValue;
  847. this.numberScopeControl2.Visible = false;
  848. this.numberScopeControl3.Visible = false;
  849. this.button6.Text = PdnResources.GetString("Menu.inverse.text");
  850. this.binaryExtractionModel.ColorInterval = 1;
  851. this.histogramControl1.Flag = 1;
  852. //给控件赋值
  853. this.numberScopeControl1.minValue = 0;
  854. this.numberScopeControl1.maxValue = otsu;
  855. this.binaryExtractionModel.ColorOneStart = Convert.ToInt32(this.numberScopeControl1.minValue);
  856. this.binaryExtractionModel.ColorOneEnd = Convert.ToInt32(otsu);
  857. this.SetArgsValue();
  858. }
  859. //处理直方图
  860. this.histogramControl1.UpdateVerticalBarWithOneScope(0, Convert.ToInt32(this.numberScopeControl1.maxValue));
  861. mat.Dispose();
  862. GC.Collect();
  863. this.applyButtonImpl(sender, e);
  864. }
  865. else
  866. {
  867. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  868. }
  869. this.AddEventHandler();
  870. }
  871. #endregion
  872. #region 处理细节
  873. /// <summary>
  874. /// 删除边界对象
  875. /// </summary>
  876. /// <param name="sender"></param>
  877. /// <param name="e"></param>
  878. private void checkBox2_CheckedChanged(object sender, EventArgs e)
  879. {
  880. //参数改变
  881. foreach (Args args in action.Lists)
  882. {
  883. if (args.Key == "deleteBoundaryObject")
  884. {
  885. args.Value = this.checkBox2.Checked;
  886. break;
  887. }
  888. }
  889. this.binaryExtractionModel.DeleteBoundaryObject = this.checkBox2.Checked;
  890. }
  891. /// <summary>
  892. /// 孔洞填充
  893. /// </summary>
  894. /// <param name="sender"></param>
  895. /// <param name="e"></param>
  896. private void checkBox3_CheckedChanged(object sender, EventArgs e)
  897. {
  898. //参数改变
  899. foreach (Args args in action.Lists)
  900. {
  901. if (args.Key == "holeFilling")
  902. {
  903. args.Value = this.checkBox3.Checked;
  904. break;
  905. }
  906. }
  907. this.binaryExtractionModel.HoleFilling = this.checkBox3.Checked;
  908. }
  909. /// <summary>
  910. /// 碎屑删除
  911. /// </summary>
  912. /// <param name="sender"></param>
  913. /// <param name="e"></param>
  914. private void checkBox4_CheckedChanged(object sender, EventArgs e)
  915. {
  916. //参数改变
  917. foreach (Args args in action.Lists)
  918. {
  919. if (args.Key == "debrisRemoval")
  920. {
  921. args.Value = this.checkBox4.Checked;
  922. break;
  923. }
  924. }
  925. this.binaryExtractionModel.DebrisRemoval = this.checkBox4.Checked;
  926. }
  927. /// <summary>
  928. /// 碎屑面积变化
  929. /// </summary>
  930. /// <param name="sender"></param>
  931. /// <param name="e"></param>
  932. private void Detritus_ValueChanged(object sender, EventArgs e)
  933. {
  934. if (this.checkBox4.Checked)
  935. {
  936. DeleteEventHandler();
  937. if (((NumericUpDown)sender).Name.Equals("numericUpDown1"))
  938. numericUpDown2.Value = Math.Max(numericUpDown2.Value, numericUpDown1.Value);
  939. else if (((NumericUpDown)sender).Name.Equals("numericUpDown2"))
  940. numericUpDown1.Value = Math.Min(numericUpDown1.Value, numericUpDown2.Value);
  941. foreach (Args args in action.Lists)
  942. {
  943. if (args.Key == "scope4")
  944. {
  945. ((List<double>)args.Value)[0] = (double)numericUpDown1.Value / unitLength / unitLength;
  946. ((List<double>)args.Value)[1] = (double)numericUpDown2.Value / unitLength / unitLength;
  947. break;
  948. }
  949. }
  950. this.binaryExtractionModel.DebrisAreaStart = (int)((double)numericUpDown1.Value / unitLength / unitLength);
  951. this.binaryExtractionModel.DebrisAreaEnd = (int)((double)numericUpDown2.Value / unitLength / unitLength);
  952. this.applyButtonImpl(null, null);
  953. AddEventHandler();
  954. }
  955. }
  956. #endregion
  957. #region 二值样式
  958. /// <summary>
  959. /// 实心和边线
  960. /// </summary>
  961. /// <param name="sender"></param>
  962. /// <param name="e"></param>
  963. private void radioButton1Or2_ValueChanged(object sender, EventArgs e)
  964. {
  965. if (((RadioButton)sender).Checked)
  966. {
  967. //参数改变
  968. foreach (Args args in action.Lists)
  969. {
  970. if (args.Key == "binaryStyle")
  971. {
  972. if (radioButton1.Checked)
  973. {
  974. args.Value = 1;
  975. }
  976. else
  977. {
  978. args.Value = 2;
  979. }
  980. break;
  981. }
  982. }
  983. this.binaryExtractionModel.BinaryStyle = radioButton1.Checked ? 1 : 2;
  984. this.applyButtonImpl(sender, e);
  985. }
  986. }
  987. /// <summary>
  988. /// 相颜色点击事件
  989. /// </summary>
  990. /// <param name="sender"></param>
  991. /// <param name="e"></param>
  992. private void panel2_Click(object sender, EventArgs e)
  993. {
  994. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
  995. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  996. this.colorsFormGrid.ShowDialog();
  997. }
  998. /// <summary>
  999. /// Panel2的调色板颜色改变
  1000. /// </summary>
  1001. /// <param name="sender"></param>
  1002. /// <param name="e"></param>
  1003. private void gridColorChanged(object sender, EventArgs e)
  1004. {
  1005. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  1006. //先修改参数
  1007. foreach (Args args in action.Lists)
  1008. {
  1009. if (args.Key == "phaseColor")
  1010. {
  1011. args.Value = color.ToArgb();
  1012. break;
  1013. }
  1014. }
  1015. //更改背景色,触发事件
  1016. this.panel2.BackColor = color;
  1017. //改变配置文件里面的相颜色
  1018. this.binaryExtractionModel.PhaseColor = color.ToArgb();
  1019. //关闭色板
  1020. this.colorsFormGrid.Close();
  1021. }
  1022. #endregion
  1023. #region 目标选择
  1024. /// <summary>
  1025. /// 目标选择
  1026. /// </summary>
  1027. /// <param name="sender"></param>
  1028. /// <param name="e"></param>
  1029. private void radioButton5_CheckedChanged(object sender, EventArgs e)
  1030. {
  1031. //参数改变
  1032. foreach (Args args in action.Lists)
  1033. {
  1034. if (args.Key == "targetSelection")
  1035. {
  1036. if (radioButton3.Checked)
  1037. {
  1038. args.Value = 1;
  1039. this.binaryExtractionModel.TargetSelection = 1;
  1040. }
  1041. else if (radioButton4.Checked)
  1042. {
  1043. args.Value = 2;
  1044. this.binaryExtractionModel.TargetSelection = 2;
  1045. }
  1046. else
  1047. {
  1048. args.Value = 3;
  1049. this.binaryExtractionModel.TargetSelection = 3;
  1050. }
  1051. break;
  1052. }
  1053. }
  1054. if (((RadioButton)sender).Checked)
  1055. {
  1056. this.applyButtonImpl(null, null);
  1057. }
  1058. }
  1059. #endregion
  1060. #endregion
  1061. /// <summary>
  1062. /// 生成新图
  1063. /// </summary>
  1064. /// <param name="mat"></param>
  1065. private void OpenFileImpl()
  1066. {
  1067. if (imageMat != null)
  1068. {
  1069. DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();
  1070. Document document = Document.FromImageMat(imageMat.Clone());
  1071. dw.Document = document;
  1072. dw.fileText = this.Text + "-" + stepLength;
  1073. dw.rules = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].rules;
  1074. dw.xmlSaveModel = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].xmlSaveModel;
  1075. this.appWorkspace.ActiveDocumentWorkspace = dw;
  1076. this.appWorkspace.ActiveDocumentWorkspace.PhaseModels = this.documentWorkspace.PhaseModelsForCopy;
  1077. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  1078. Startup.instance.step_length += 1;
  1079. stepLength = "00" + Startup.instance.step_length;
  1080. }
  1081. }
  1082. /// <summary>
  1083. /// 应用到全部
  1084. /// </summary>
  1085. /// <param name="sender"></param>
  1086. /// <param name="e"></param>
  1087. private void button2_Click(object sender, EventArgs e)
  1088. {
  1089. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  1090. int itemCount = 100;
  1091. ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
  1092. System.Threading.ThreadStart copyThreadProc =
  1093. delegate ()
  1094. {
  1095. try
  1096. {
  1097. int num = this.appWorkspace.DocumentWorkspaces.Length;
  1098. for (int i = 0; i < num; i++)
  1099. {
  1100. List<PhaseModel> list = new List<PhaseModel>();
  1101. PhaseModel model = new PhaseModel();
  1102. model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text");
  1103. model.choise = true;
  1104. if (this.appWorkspace.DocumentWorkspaces[i].GraphicsList.IsExsitView())
  1105. {
  1106. model.mat = action.PerformProcess(
  1107. PaintDotNet.Camera.Tools.ToMat(this.appWorkspace.DocumentWorkspaces[i].GetFullSizeWithRegion()),
  1108. this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreatedAliasedMat().Clone(), true);
  1109. model.color = this.panel2.BackColor.ToArgb();
  1110. }
  1111. else
  1112. {
  1113. model.mat = action.PerformProcess(this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreatedAliasedMat().Clone(), true);
  1114. model.color = this.panel2.BackColor.ToArgb();
  1115. }
  1116. list.Add(model);
  1117. this.Invoke(new EventHandler(delegate
  1118. {
  1119. if (checkBox1.Checked)
  1120. {
  1121. DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();//return mat/*.Clone()*/;//待测试
  1122. Document document = Document.FromImageMat(this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreatedAliasedMat().Clone());
  1123. dw.Document = document;
  1124. dw.rules = this.appWorkspace.DocumentWorkspaces[i].rules;
  1125. dw.xmlSaveModel = this.appWorkspace.DocumentWorkspaces[i].xmlSaveModel;
  1126. dw.fileText = this.Text + "-" + stepLength;
  1127. dw.PhaseModels = list;
  1128. this.appWorkspace.ActiveDocumentWorkspace = dw;
  1129. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  1130. Startup.instance.step_length += 1;
  1131. stepLength = "00" + Startup.instance.step_length;
  1132. }
  1133. else
  1134. {
  1135. this.appWorkspace.DocumentWorkspaces[i].PhaseModels = list;
  1136. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  1137. }
  1138. }));
  1139. }
  1140. this.Invoke(new EventHandler(delegate
  1141. {
  1142. this.Close();
  1143. }));
  1144. }
  1145. catch (Exception)
  1146. {
  1147. }
  1148. finally
  1149. {
  1150. progressEvents.EndOperation(OperationResult.Finished);
  1151. }
  1152. };
  1153. procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null);
  1154. }
  1155. /// <summary>
  1156. /// 显示原图/原图+二值图
  1157. /// </summary>
  1158. /// <param name="sender"></param>
  1159. /// <param name="e"></param>
  1160. private void ShowOrHideOriginPic(object sender, EventArgs e)
  1161. {
  1162. if (!checkBox5.Checked)
  1163. {
  1164. this.documentWorkspace.PhaseModels[0].choise = true;
  1165. }
  1166. else
  1167. {
  1168. this.documentWorkspace.PhaseModels[0].choise = false;
  1169. }
  1170. this.documentWorkspace.Refresh();
  1171. }
  1172. /// <summary>
  1173. /// 参数改变时,重新处理图像
  1174. /// </summary>
  1175. /// <param name="sender"></param>
  1176. /// <param name="e"></param>
  1177. private void applyButtonImpl(object sender, EventArgs e)
  1178. {
  1179. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  1180. int itemCount = 100;
  1181. ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
  1182. System.Threading.ThreadStart copyThreadProc =
  1183. delegate ()
  1184. {
  1185. try
  1186. {
  1187. long start = Cv2.GetTickCount();
  1188. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  1189. {
  1190. //判断是否存在视场,如果存在视场,则把视场提取出来,进行处理
  1191. if (this.documentWorkspace.GraphicsList.IsExsitView())
  1192. {
  1193. this.documentWorkspace.PhaseModels.Clear();
  1194. PhaseModel model = new PhaseModel();
  1195. model.choise = true;
  1196. model.mat = action.PerformProcess(
  1197. PaintDotNet.Camera.Tools.ToMat(this.documentWorkspace.GetFullSizeWithRegion()),
  1198. this.imageMat.Clone(), true);
  1199. model.color = this.panel2.BackColor.ToArgb();
  1200. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  1201. model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text");
  1202. this.documentWorkspace.PhaseModels.Add(model);
  1203. }
  1204. else
  1205. {
  1206. this.documentWorkspace.PhaseModels.Clear();
  1207. PhaseModel model = new PhaseModel();
  1208. model.choise = true;
  1209. model.mat = action.PerformProcess(this.imageMat.Clone(), true);
  1210. model.color = this.panel2.BackColor.ToArgb();
  1211. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  1212. model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text");
  1213. this.documentWorkspace.PhaseModels.Add(model);
  1214. }
  1215. ShowOrHideOriginPic(null, null);
  1216. }
  1217. double time = (Cv2.GetTickCount() - start) / Cv2.GetTickFrequency();
  1218. System.Console.WriteLine(PdnResources.GetString("Menu.executiontime.Text") + ":" + time);
  1219. }
  1220. catch (Exception)
  1221. {
  1222. }
  1223. finally
  1224. {
  1225. progressEvents.EndOperation(OperationResult.Finished);
  1226. }
  1227. };
  1228. procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, this.Text);//#21198
  1229. }
  1230. /// <summary>
  1231. /// 应用
  1232. /// </summary>
  1233. /// <param name="sender"></param>
  1234. /// <param name="e"></param>
  1235. private void applyButton_Click(object sender, EventArgs e)
  1236. {
  1237. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  1238. {
  1239. if (checkBox1.Checked)
  1240. {
  1241. this.OpenFileImpl();
  1242. }
  1243. else
  1244. {
  1245. if (this.documentWorkspace.PhaseModels.Count > 0)
  1246. {
  1247. List<PhaseModel> models = new List<PhaseModel>();
  1248. foreach (PhaseModel temp in this.documentWorkspace.PhaseModels)
  1249. {
  1250. if (temp.mat == null)
  1251. { return; }
  1252. PhaseModel model = new PhaseModel();
  1253. model.choise = temp.choise;
  1254. model.color = temp.color;
  1255. model.mat = temp.mat.Clone();
  1256. model.name = temp.name;
  1257. model.position = temp.position;
  1258. models.Add(model);
  1259. }
  1260. this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].PhaseModels = models;
  1261. this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].Refresh();
  1262. }
  1263. }
  1264. }
  1265. this.Close();
  1266. }
  1267. /// <summary>
  1268. /// 删除按钮
  1269. /// </summary>
  1270. /// <param name="sender"></param>
  1271. /// <param name="e"></param>
  1272. private void button3_Click(object sender, EventArgs e)
  1273. {
  1274. if ("Default".Equals(this.comboBox1.Text))
  1275. {
  1276. MessageBox.Show(PdnResources.GetString("Menu.Defaultparamscannotbedeleted.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1277. return;
  1278. }
  1279. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodeleteparams.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  1280. if (dr == DialogResult.OK)
  1281. {
  1282. //删除xml文件
  1283. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.Text + ".xml";
  1284. FileInfo fileInfo = new FileInfo(filePath);
  1285. fileInfo.Delete();
  1286. //初始化xml文件列表
  1287. InitParameterList(this.comboBox1.SelectedIndex);
  1288. this.binaryExtractionModel = XmlSerializeHelper.DESerializer<BinaryExtractionModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
  1289. InitParameterToControl();
  1290. }
  1291. }
  1292. /// <summary>
  1293. /// 保存参数
  1294. /// </summary>
  1295. /// <param name="sender"></param>
  1296. /// <param name="e"></param>
  1297. private void button5_Click(object sender, EventArgs e)
  1298. {
  1299. foreach (Args args in action.Lists)
  1300. {
  1301. if (args.Key == "colorInterval")
  1302. {
  1303. this.binaryExtractionModel.ColorInterval = int.Parse(args.Value.ToString());
  1304. }
  1305. else if (args.Key == "scope1")
  1306. {
  1307. List<double> twoL = (List<double>)args.Value;
  1308. this.binaryExtractionModel.ColorOneStart = (int)twoL[0];
  1309. this.binaryExtractionModel.ColorOneEnd = (int)twoL[1];
  1310. }
  1311. else if (args.Key == "scope3")
  1312. {
  1313. List<double> twoL = (List<double>)args.Value;
  1314. this.binaryExtractionModel.ColorTwoStart = (int)twoL[0];
  1315. this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1];
  1316. }
  1317. else if (args.Key == "scope2")
  1318. {
  1319. List<double> twoL = (List<double>)args.Value;
  1320. this.binaryExtractionModel.ColorThreeStart = (int)twoL[0];
  1321. this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1];
  1322. }
  1323. else if (args.Key == "deleteBoundaryObject")
  1324. {
  1325. this.binaryExtractionModel.DeleteBoundaryObject = (bool)args.Value;
  1326. }
  1327. else if (args.Key == "holeFilling")
  1328. {
  1329. this.binaryExtractionModel.HoleFilling = (bool)args.Value;
  1330. }
  1331. else if (args.Key == "debrisRemoval")
  1332. {
  1333. this.binaryExtractionModel.DebrisRemoval = (bool)args.Value;
  1334. }
  1335. else if (args.Key == "scope4")
  1336. {
  1337. this.binaryExtractionModel.DebrisAreaStart = (int)((List<double>)args.Value)[0];
  1338. this.binaryExtractionModel.DebrisAreaEnd = (int)((List<double>)args.Value)[1];
  1339. }
  1340. else if (args.Key == "binaryStyle")
  1341. {
  1342. this.binaryExtractionModel.BinaryStyle = (int)args.Value;
  1343. }
  1344. else if (args.Key == "phaseColor")
  1345. {
  1346. this.binaryExtractionModel.PhaseColor = (int)args.Value;
  1347. }
  1348. else if (args.Key == "targetSelection")
  1349. {
  1350. this.binaryExtractionModel.TargetSelection = (int)args.Value;
  1351. }
  1352. }
  1353. string stageModelXml = XmlSerializeHelper.XmlSerialize<BinaryExtractionModel>(this.binaryExtractionModel);
  1354. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.Text + ".xml";
  1355. FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
  1356. }
  1357. /// <summary>
  1358. /// 另存为
  1359. /// </summary>
  1360. /// <param name="sender"></param>
  1361. /// <param name="e"></param>
  1362. private void button4_Click(object sender, EventArgs e)
  1363. {
  1364. dialog = new CreateNameDialog(this);
  1365. dialog.Text = PdnResources.GetString("Menu.File.SaveAs.Text");
  1366. dialog.StartPosition = FormStartPosition.CenterParent;
  1367. dialog.ShowDialog();
  1368. }
  1369. /// <summary>
  1370. /// 另存为弹窗 确定保存
  1371. /// </summary>
  1372. /// <param name="name"></param>
  1373. public override void GetCreateName(string name)
  1374. {
  1375. string currentcomboBox = this.comboBox1.Text;
  1376. if (files.Contains(name))
  1377. {
  1378. MessageBox.Show(PdnResources.GetString("Menu.Stylenamecannotberepeated.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1379. return;
  1380. }
  1381. BinaryExtractionModel newModel = this.binaryExtractionModel;
  1382. foreach (Args args in action.Lists)
  1383. {
  1384. if (args.Key == "colorInterval")
  1385. {
  1386. this.binaryExtractionModel.ColorInterval = int.Parse(args.Value.ToString());
  1387. }
  1388. else if (args.Key == "scope1")
  1389. {
  1390. List<double> twoL = (List<double>)args.Value;
  1391. this.binaryExtractionModel.ColorOneStart = (int)twoL[0];
  1392. this.binaryExtractionModel.ColorOneEnd = (int)twoL[1];
  1393. }
  1394. else if (args.Key == "scope3")
  1395. {
  1396. List<double> twoL = (List<double>)args.Value;
  1397. this.binaryExtractionModel.ColorTwoStart = (int)twoL[0];
  1398. this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1];
  1399. }
  1400. else if (args.Key == "scope2")
  1401. {
  1402. List<double> twoL = (List<double>)args.Value;
  1403. this.binaryExtractionModel.ColorThreeStart = (int)twoL[0];
  1404. this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1];
  1405. }
  1406. else if (args.Key == "deleteBoundaryObject")
  1407. {
  1408. this.binaryExtractionModel.DeleteBoundaryObject = (bool)args.Value;
  1409. }
  1410. else if (args.Key == "holeFilling")
  1411. {
  1412. this.binaryExtractionModel.HoleFilling = (bool)args.Value;
  1413. }
  1414. else if (args.Key == "debrisRemoval")
  1415. {
  1416. this.binaryExtractionModel.DebrisRemoval = (bool)args.Value;
  1417. }
  1418. else if (args.Key == "scope4")
  1419. {
  1420. this.binaryExtractionModel.DebrisAreaStart = (int)((List<double>)args.Value)[0];
  1421. this.binaryExtractionModel.DebrisAreaEnd = (int)((List<double>)args.Value)[1];
  1422. }
  1423. else if (args.Key == "binaryStyle")
  1424. {
  1425. this.binaryExtractionModel.BinaryStyle = (int)args.Value;
  1426. }
  1427. else if (args.Key == "phaseColor")
  1428. {
  1429. this.binaryExtractionModel.PhaseColor = (int)args.Value;
  1430. }
  1431. else if (args.Key == "targetSelection")
  1432. {
  1433. this.binaryExtractionModel.TargetSelection = (int)args.Value;
  1434. }
  1435. }
  1436. //另存为
  1437. string stageModelXml = XmlSerializeHelper.XmlSerialize<BinaryExtractionModel>(newModel);
  1438. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + name + ".xml";
  1439. FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
  1440. InitParameterList(0, false);
  1441. this.comboBox1.Text = currentcomboBox;
  1442. dialog.Close();
  1443. }
  1444. public void SetArgsValue()
  1445. {
  1446. foreach (Args args in action.Lists)
  1447. {
  1448. if (args.Key == "colorInterval")
  1449. {
  1450. args.Value = this.binaryExtractionModel.ColorInterval;
  1451. }
  1452. else if (args.Key == "scope1")
  1453. {
  1454. List<double> twoL = new List<double>();
  1455. twoL.Add(this.numberScopeControl1.minValue);
  1456. twoL.Add(this.numberScopeControl1.maxValue);
  1457. args.Value = twoL;
  1458. }
  1459. else if (args.Key == "scope2")
  1460. {
  1461. List<double> twoL = new List<double>();
  1462. twoL.Add(this.numberScopeControl3.minValue);
  1463. twoL.Add(this.numberScopeControl3.maxValue);
  1464. args.Value = twoL;
  1465. }
  1466. else if (args.Key == "scope3")
  1467. {
  1468. List<double> twoL = new List<double>();
  1469. twoL.Add(this.numberScopeControl2.minValue);
  1470. twoL.Add(this.numberScopeControl2.maxValue);
  1471. args.Value = twoL;
  1472. }
  1473. }
  1474. }
  1475. private void InitializeLanguageText()
  1476. {
  1477. this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text");
  1478. this.groupBox2.Text = PdnResources.GetString("Menu.operation.text");
  1479. this.button5.Text = PdnResources.GetString("Menu.File.Save.Text");
  1480. this.button4.Text = PdnResources.GetString("Menu.File.SaveAs.Text");
  1481. this.button3.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  1482. this.label1.Text = PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.paramslist.text") + ":";
  1483. this.checkBox1.Text = PdnResources.GetString("Menu.Createnewgraph.text");
  1484. this.button2.Text = PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.Applytoall.text");
  1485. this.button1.Text = PdnResources.GetString("Menu.application.text");
  1486. this.groupBox3.Text = PdnResources.GetString("Menu.Tools.Histogram.Text");
  1487. this.checkBox5.Text = PdnResources.GetString("Menu.Theoriginalcolor.text");
  1488. this.button7.Text = PdnResources.GetString("Menu.Automaticthreshold.text");
  1489. this.button6.Text = PdnResources.GetString("Menu.inverse.text");
  1490. this.groupBox4.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  1491. this.groupBox5.Text = PdnResources.GetString("Menu.Processingdetails.text");
  1492. this.checkBox4.Text = PdnResources.GetString("Menu.Clasticdelete.text");
  1493. this.checkBox3.Text = PdnResources.GetString("Menu.BinaryAction.HoleFilling.Text");
  1494. this.checkBox2.Text = PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.Deleteboundaryobject.text");
  1495. this.groupBox6.Text = PdnResources.GetString("Menu.Binarystyle.text");
  1496. this.label2.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
  1497. this.radioButton2.Text = PdnResources.GetString("Menu.Sideline.text");
  1498. this.radioButton1.Text = PdnResources.GetString("Menu.solid.text");
  1499. this.groupBox7.Text = PdnResources.GetString("Menu.Targetselection.text");
  1500. this.radioButton5.Text = PdnResources.GetString("Menu.style.text") + "3";
  1501. this.radioButton4.Text = PdnResources.GetString("Menu.style.text") + "2";
  1502. this.radioButton3.Text = PdnResources.GetString("Menu.style.text") + "1";
  1503. }
  1504. private void InitializeComponent()
  1505. {
  1506. this.components = new System.ComponentModel.Container();
  1507. this.groupBox1 = new System.Windows.Forms.GroupBox();
  1508. this.groupBox2 = new System.Windows.Forms.GroupBox();
  1509. this.button5 = new System.Windows.Forms.Button();
  1510. this.button4 = new System.Windows.Forms.Button();
  1511. this.button3 = new System.Windows.Forms.Button();
  1512. this.comboBox1 = new System.Windows.Forms.ComboBox();
  1513. this.label1 = new System.Windows.Forms.Label();
  1514. this.checkBox1 = new System.Windows.Forms.CheckBox();
  1515. this.button2 = new System.Windows.Forms.Button();
  1516. this.button1 = new System.Windows.Forms.Button();
  1517. this.groupBox3 = new System.Windows.Forms.GroupBox();
  1518. this.histogramControl1 = new PaintDotNet.CustomControl.HistogramControl();
  1519. this.numberScopeControl3 = new PaintDotNet.CustomControl.DecimalScopeControl();
  1520. this.numberScopeControl2 = new PaintDotNet.CustomControl.DecimalScopeControl();
  1521. this.numberScopeControl1 = new PaintDotNet.CustomControl.DecimalScopeControl();
  1522. this.checkBox5 = new System.Windows.Forms.CheckBox();
  1523. this.button7 = new System.Windows.Forms.Button();
  1524. this.button6 = new System.Windows.Forms.Button();
  1525. this.groupBox4 = new System.Windows.Forms.GroupBox();
  1526. this.listView1 = new System.Windows.Forms.ListView();
  1527. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  1528. this.groupBox5 = new System.Windows.Forms.GroupBox();
  1529. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  1530. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  1531. this.checkBox4 = new System.Windows.Forms.CheckBox();
  1532. this.checkBox3 = new System.Windows.Forms.CheckBox();
  1533. this.checkBox2 = new System.Windows.Forms.CheckBox();
  1534. this.groupBox6 = new System.Windows.Forms.GroupBox();
  1535. this.label2 = new System.Windows.Forms.Label();
  1536. this.panel2 = new System.Windows.Forms.Panel();
  1537. this.radioButton2 = new System.Windows.Forms.RadioButton();
  1538. this.radioButton1 = new System.Windows.Forms.RadioButton();
  1539. this.groupBox7 = new System.Windows.Forms.GroupBox();
  1540. this.button10 = new System.Windows.Forms.Button();
  1541. this.button9 = new System.Windows.Forms.Button();
  1542. this.button8 = new System.Windows.Forms.Button();
  1543. this.radioButton5 = new System.Windows.Forms.RadioButton();
  1544. this.radioButton4 = new System.Windows.Forms.RadioButton();
  1545. this.radioButton3 = new System.Windows.Forms.RadioButton();
  1546. this.groupBox2.SuspendLayout();
  1547. this.groupBox3.SuspendLayout();
  1548. this.groupBox4.SuspendLayout();
  1549. this.groupBox5.SuspendLayout();
  1550. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  1551. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  1552. this.groupBox6.SuspendLayout();
  1553. this.groupBox7.SuspendLayout();
  1554. this.SuspendLayout();
  1555. //
  1556. // groupBox1
  1557. //
  1558. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  1559. | System.Windows.Forms.AnchorStyles.Left)
  1560. | System.Windows.Forms.AnchorStyles.Right)));
  1561. this.groupBox1.Location = new System.Drawing.Point(532, 70);
  1562. this.groupBox1.Name = "groupBox1";
  1563. this.groupBox1.Size = new System.Drawing.Size(398, 447);
  1564. this.groupBox1.TabIndex = 5;
  1565. this.groupBox1.TabStop = false;
  1566. this.groupBox1.Text = "预览";
  1567. //
  1568. // groupBox2
  1569. //
  1570. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  1571. | System.Windows.Forms.AnchorStyles.Right)));
  1572. this.groupBox2.Controls.Add(this.button5);
  1573. this.groupBox2.Controls.Add(this.button4);
  1574. this.groupBox2.Controls.Add(this.button3);
  1575. this.groupBox2.Controls.Add(this.comboBox1);
  1576. this.groupBox2.Controls.Add(this.label1);
  1577. this.groupBox2.Controls.Add(this.checkBox1);
  1578. this.groupBox2.Controls.Add(this.button2);
  1579. this.groupBox2.Controls.Add(this.button1);
  1580. this.groupBox2.Location = new System.Drawing.Point(13, 12);
  1581. this.groupBox2.Name = "groupBox2";
  1582. this.groupBox2.Size = new System.Drawing.Size(917, 52);
  1583. this.groupBox2.TabIndex = 6;
  1584. this.groupBox2.TabStop = false;
  1585. this.groupBox2.Text = "操作";
  1586. //
  1587. // button5
  1588. //
  1589. this.button5.Location = new System.Drawing.Point(354, 21);
  1590. this.button5.Name = "button5";
  1591. this.button5.Size = new System.Drawing.Size(75, 23);
  1592. this.button5.TabIndex = 10;
  1593. this.button5.Text = "保存";
  1594. this.button5.UseVisualStyleBackColor = true;
  1595. this.button5.Click += new System.EventHandler(this.button5_Click);
  1596. //
  1597. // button4
  1598. //
  1599. this.button4.Location = new System.Drawing.Point(272, 21);
  1600. this.button4.Name = "button4";
  1601. this.button4.Size = new System.Drawing.Size(75, 23);
  1602. this.button4.TabIndex = 9;
  1603. this.button4.Text = "另存为";
  1604. this.button4.UseVisualStyleBackColor = true;
  1605. this.button4.Click += new System.EventHandler(this.button4_Click);
  1606. //
  1607. // button3
  1608. //
  1609. this.button3.Location = new System.Drawing.Point(190, 21);
  1610. this.button3.Name = "button3";
  1611. this.button3.Size = new System.Drawing.Size(75, 23);
  1612. this.button3.TabIndex = 8;
  1613. this.button3.Text = "删除";
  1614. this.button3.UseVisualStyleBackColor = true;
  1615. this.button3.Click += new System.EventHandler(this.button3_Click);
  1616. //
  1617. // comboBox1
  1618. //
  1619. this.comboBox1.FormattingEnabled = true;
  1620. this.comboBox1.Location = new System.Drawing.Point(82, 22);
  1621. this.comboBox1.Name = "comboBox1";
  1622. this.comboBox1.Size = new System.Drawing.Size(101, 20);
  1623. this.comboBox1.TabIndex = 7;
  1624. //
  1625. // label1
  1626. //
  1627. this.label1.AutoSize = true;
  1628. this.label1.Location = new System.Drawing.Point(7, 26);
  1629. this.label1.Name = "label1";
  1630. this.label1.Size = new System.Drawing.Size(65, 12);
  1631. this.label1.TabIndex = 6;
  1632. this.label1.Text = "参数列表:";
  1633. //
  1634. // checkBox1
  1635. //
  1636. this.checkBox1.Anchor = System.Windows.Forms.AnchorStyles.Right;
  1637. this.checkBox1.AutoSize = true;
  1638. this.checkBox1.Location = new System.Drawing.Point(680, 24);
  1639. this.checkBox1.Name = "checkBox1";
  1640. this.checkBox1.Size = new System.Drawing.Size(72, 16);
  1641. this.checkBox1.TabIndex = 5;
  1642. this.checkBox1.Text = "创建新图";
  1643. this.checkBox1.UseVisualStyleBackColor = true;
  1644. //
  1645. // button2
  1646. //
  1647. this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right;
  1648. this.button2.Location = new System.Drawing.Point(757, 20);
  1649. this.button2.Name = "button2";
  1650. this.button2.Size = new System.Drawing.Size(75, 23);
  1651. this.button2.TabIndex = 4;
  1652. this.button2.Text = "应用到全部一个";
  1653. this.button2.UseVisualStyleBackColor = true;
  1654. this.button2.Click += new System.EventHandler(this.button2_Click);
  1655. //
  1656. // button1
  1657. //
  1658. this.button1.Anchor = System.Windows.Forms.AnchorStyles.Right;
  1659. this.button1.Location = new System.Drawing.Point(838, 20);
  1660. this.button1.Name = "button1";
  1661. this.button1.Size = new System.Drawing.Size(75, 23);
  1662. this.button1.TabIndex = 3;
  1663. this.button1.Text = "应用";
  1664. this.button1.UseVisualStyleBackColor = true;
  1665. this.button1.Click += new System.EventHandler(this.applyButton_Click);
  1666. //
  1667. // groupBox3
  1668. //
  1669. this.groupBox3.Controls.Add(this.histogramControl1);
  1670. this.groupBox3.Controls.Add(this.numberScopeControl3);
  1671. this.groupBox3.Controls.Add(this.numberScopeControl2);
  1672. this.groupBox3.Controls.Add(this.numberScopeControl1);
  1673. this.groupBox3.Controls.Add(this.checkBox5);
  1674. this.groupBox3.Controls.Add(this.button7);
  1675. this.groupBox3.Controls.Add(this.button6);
  1676. this.groupBox3.Location = new System.Drawing.Point(159, 70);
  1677. this.groupBox3.Name = "groupBox3";
  1678. this.groupBox3.Size = new System.Drawing.Size(367, 221);
  1679. this.groupBox3.TabIndex = 7;
  1680. this.groupBox3.TabStop = false;
  1681. this.groupBox3.Text = "直方图";
  1682. //
  1683. // histogramControl1
  1684. //
  1685. this.histogramControl1.Flag = 1;
  1686. this.histogramControl1.Location = new System.Drawing.Point(8, 22);
  1687. this.histogramControl1.Name = "histogramControl1";
  1688. this.histogramControl1.Size = new System.Drawing.Size(340, 130);
  1689. this.histogramControl1.TabIndex = 16;
  1690. //
  1691. // numberScopeControl3
  1692. //
  1693. this.numberScopeControl3.DecimalPlaces = 0;
  1694. this.numberScopeControl3.Location = new System.Drawing.Point(8, 158);
  1695. this.numberScopeControl3.Maximum = 255D;
  1696. this.numberScopeControl3.maxValue = 0D;
  1697. this.numberScopeControl3.Minimum = 0D;
  1698. this.numberScopeControl3.minValue = 0D;
  1699. this.numberScopeControl3.Name = "numberScopeControl3";
  1700. this.numberScopeControl3.Size = new System.Drawing.Size(150, 22);
  1701. this.numberScopeControl3.TabIndex = 15;
  1702. this.numberScopeControl3.Visible = false;
  1703. //
  1704. // numberScopeControl2
  1705. //
  1706. this.numberScopeControl2.DecimalPlaces = 0;
  1707. this.numberScopeControl2.Location = new System.Drawing.Point(186, 158);
  1708. this.numberScopeControl2.Maximum = 255D;
  1709. this.numberScopeControl2.maxValue = 0D;
  1710. this.numberScopeControl2.Minimum = 0D;
  1711. this.numberScopeControl2.minValue = 0D;
  1712. this.numberScopeControl2.Name = "numberScopeControl2";
  1713. this.numberScopeControl2.Size = new System.Drawing.Size(150, 22);
  1714. this.numberScopeControl2.TabIndex = 14;
  1715. this.numberScopeControl2.Visible = false;
  1716. //
  1717. // numberScopeControl1
  1718. //
  1719. this.numberScopeControl1.DecimalPlaces = 0;
  1720. this.numberScopeControl1.Location = new System.Drawing.Point(8, 158);
  1721. this.numberScopeControl1.Maximum = 255D;
  1722. this.numberScopeControl1.maxValue = 0D;
  1723. this.numberScopeControl1.Minimum = 0D;
  1724. this.numberScopeControl1.minValue = 0D;
  1725. this.numberScopeControl1.Name = "numberScopeControl1";
  1726. this.numberScopeControl1.Size = new System.Drawing.Size(150, 22);
  1727. this.numberScopeControl1.TabIndex = 13;
  1728. this.numberScopeControl1.Tag = "numberScopeControl1";
  1729. //
  1730. // checkBox5
  1731. //
  1732. this.checkBox5.Anchor = System.Windows.Forms.AnchorStyles.Right;
  1733. this.checkBox5.AutoSize = true;
  1734. this.checkBox5.Location = new System.Drawing.Point(311, 196);
  1735. this.checkBox5.Name = "checkBox5";
  1736. this.checkBox5.Size = new System.Drawing.Size(48, 16);
  1737. this.checkBox5.TabIndex = 11;
  1738. this.checkBox5.Text = "原图";
  1739. this.checkBox5.UseVisualStyleBackColor = true;
  1740. this.checkBox5.CheckedChanged += new System.EventHandler(this.ShowOrHideOriginPic);
  1741. //
  1742. // button7
  1743. //
  1744. this.button7.Anchor = System.Windows.Forms.AnchorStyles.Right;
  1745. this.button7.Location = new System.Drawing.Point(197, 192);
  1746. this.button7.Name = "button7";
  1747. this.button7.Size = new System.Drawing.Size(75, 23);
  1748. this.button7.TabIndex = 12;
  1749. this.button7.Text = "自动阈值";
  1750. this.button7.UseVisualStyleBackColor = true;
  1751. this.button7.Click += new System.EventHandler(this.button7_Click);
  1752. //
  1753. // button6
  1754. //
  1755. this.button6.Anchor = System.Windows.Forms.AnchorStyles.Right;
  1756. this.button6.Location = new System.Drawing.Point(19, 192);
  1757. this.button6.Name = "button6";
  1758. this.button6.Size = new System.Drawing.Size(75, 23);
  1759. this.button6.TabIndex = 11;
  1760. this.button6.Text = "反选";
  1761. this.button6.UseVisualStyleBackColor = true;
  1762. this.button6.Click += new System.EventHandler(this.button6_Click);
  1763. //
  1764. // groupBox4
  1765. //
  1766. this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  1767. | System.Windows.Forms.AnchorStyles.Left)));
  1768. this.groupBox4.Controls.Add(this.listView1);
  1769. this.groupBox4.Location = new System.Drawing.Point(13, 71);
  1770. this.groupBox4.Name = "groupBox4";
  1771. this.groupBox4.Size = new System.Drawing.Size(140, 446);
  1772. this.groupBox4.TabIndex = 8;
  1773. this.groupBox4.TabStop = false;
  1774. this.groupBox4.Text = "图像索引";
  1775. //
  1776. // listView1
  1777. //
  1778. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  1779. | System.Windows.Forms.AnchorStyles.Left)
  1780. | System.Windows.Forms.AnchorStyles.Right)));
  1781. this.listView1.HideSelection = false;
  1782. this.listView1.LargeImageList = this.imageList1;
  1783. this.listView1.Location = new System.Drawing.Point(7, 21);
  1784. this.listView1.Name = "listView1";
  1785. this.listView1.Size = new System.Drawing.Size(127, 419);
  1786. this.listView1.TabIndex = 0;
  1787. this.listView1.UseCompatibleStateImageBehavior = false;
  1788. //
  1789. // imageList1
  1790. //
  1791. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  1792. this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
  1793. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  1794. //
  1795. // groupBox5
  1796. //
  1797. this.groupBox5.Controls.Add(this.numericUpDown2);
  1798. this.groupBox5.Controls.Add(this.numericUpDown1);
  1799. this.groupBox5.Controls.Add(this.checkBox4);
  1800. this.groupBox5.Controls.Add(this.checkBox3);
  1801. this.groupBox5.Controls.Add(this.checkBox2);
  1802. this.groupBox5.Location = new System.Drawing.Point(160, 298);
  1803. this.groupBox5.Name = "groupBox5";
  1804. this.groupBox5.Size = new System.Drawing.Size(366, 64);
  1805. this.groupBox5.TabIndex = 9;
  1806. this.groupBox5.TabStop = false;
  1807. this.groupBox5.Text = "处理细节";
  1808. //
  1809. // numericUpDown2
  1810. //
  1811. this.numericUpDown2.Location = new System.Drawing.Point(317, 26);
  1812. this.numericUpDown2.Maximum = new decimal(new int[] {
  1813. 2147483647,
  1814. 0,
  1815. 0,
  1816. 0});
  1817. this.numericUpDown2.Name = "numericUpDown2";
  1818. this.numericUpDown2.Size = new System.Drawing.Size(40, 21);
  1819. this.numericUpDown2.TabIndex = 6;
  1820. //
  1821. // numericUpDown1
  1822. //
  1823. this.numericUpDown1.Location = new System.Drawing.Point(272, 26);
  1824. this.numericUpDown1.Maximum = new decimal(new int[] {
  1825. 2147483647,
  1826. 0,
  1827. 0,
  1828. 0});
  1829. this.numericUpDown1.Name = "numericUpDown1";
  1830. this.numericUpDown1.Size = new System.Drawing.Size(40, 21);
  1831. this.numericUpDown1.TabIndex = 5;
  1832. //
  1833. // checkBox4
  1834. //
  1835. this.checkBox4.AutoSize = true;
  1836. this.checkBox4.Location = new System.Drawing.Point(197, 29);
  1837. this.checkBox4.Name = "checkBox4";
  1838. this.checkBox4.Size = new System.Drawing.Size(72, 16);
  1839. this.checkBox4.TabIndex = 2;
  1840. this.checkBox4.Text = "碎屑删除";
  1841. this.checkBox4.UseVisualStyleBackColor = true;
  1842. this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged);
  1843. //
  1844. // checkBox3
  1845. //
  1846. this.checkBox3.AutoSize = true;
  1847. this.checkBox3.Location = new System.Drawing.Point(117, 29);
  1848. this.checkBox3.Name = "checkBox3";
  1849. this.checkBox3.Size = new System.Drawing.Size(72, 16);
  1850. this.checkBox3.TabIndex = 1;
  1851. this.checkBox3.Text = "孔洞填充";
  1852. this.checkBox3.UseVisualStyleBackColor = true;
  1853. this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
  1854. //
  1855. // checkBox2
  1856. //
  1857. this.checkBox2.AutoSize = true;
  1858. this.checkBox2.Location = new System.Drawing.Point(7, 29);
  1859. this.checkBox2.Name = "checkBox2";
  1860. this.checkBox2.Size = new System.Drawing.Size(96, 16);
  1861. this.checkBox2.TabIndex = 0;
  1862. this.checkBox2.Text = "删除边界对象";
  1863. this.checkBox2.UseVisualStyleBackColor = true;
  1864. this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
  1865. //
  1866. // groupBox6
  1867. //
  1868. this.groupBox6.Controls.Add(this.label2);
  1869. this.groupBox6.Controls.Add(this.panel2);
  1870. this.groupBox6.Controls.Add(this.radioButton2);
  1871. this.groupBox6.Controls.Add(this.radioButton1);
  1872. this.groupBox6.Location = new System.Drawing.Point(159, 369);
  1873. this.groupBox6.Name = "groupBox6";
  1874. this.groupBox6.Size = new System.Drawing.Size(367, 64);
  1875. this.groupBox6.TabIndex = 10;
  1876. this.groupBox6.TabStop = false;
  1877. this.groupBox6.Text = "二值样式";
  1878. //
  1879. // label2
  1880. //
  1881. this.label2.AutoSize = true;
  1882. this.label2.Location = new System.Drawing.Point(105, 34);
  1883. this.label2.Name = "label2";
  1884. this.label2.Size = new System.Drawing.Size(41, 12);
  1885. this.label2.TabIndex = 20;
  1886. this.label2.Text = "相颜色";
  1887. //
  1888. // panel2
  1889. //
  1890. this.panel2.BackColor = System.Drawing.Color.Blue;
  1891. this.panel2.Location = new System.Drawing.Point(160, 29);
  1892. this.panel2.Name = "panel2";
  1893. this.panel2.Size = new System.Drawing.Size(72, 21);
  1894. this.panel2.TabIndex = 19;
  1895. this.panel2.Click += new System.EventHandler(this.panel2_Click);
  1896. //
  1897. // radioButton2
  1898. //
  1899. this.radioButton2.AutoSize = true;
  1900. this.radioButton2.Location = new System.Drawing.Point(56, 32);
  1901. this.radioButton2.Name = "radioButton2";
  1902. this.radioButton2.Size = new System.Drawing.Size(47, 16);
  1903. this.radioButton2.TabIndex = 1;
  1904. this.radioButton2.Text = "边线";
  1905. this.radioButton2.UseVisualStyleBackColor = true;
  1906. //
  1907. // radioButton1
  1908. //
  1909. this.radioButton1.AutoSize = true;
  1910. this.radioButton1.Checked = true;
  1911. this.radioButton1.Location = new System.Drawing.Point(7, 32);
  1912. this.radioButton1.Name = "radioButton1";
  1913. this.radioButton1.Size = new System.Drawing.Size(47, 16);
  1914. this.radioButton1.TabIndex = 0;
  1915. this.radioButton1.TabStop = true;
  1916. this.radioButton1.Text = "实心";
  1917. this.radioButton1.UseVisualStyleBackColor = true;
  1918. //
  1919. // groupBox7
  1920. //
  1921. this.groupBox7.Controls.Add(this.button10);
  1922. this.groupBox7.Controls.Add(this.button9);
  1923. this.groupBox7.Controls.Add(this.button8);
  1924. this.groupBox7.Controls.Add(this.radioButton5);
  1925. this.groupBox7.Controls.Add(this.radioButton4);
  1926. this.groupBox7.Controls.Add(this.radioButton3);
  1927. this.groupBox7.Location = new System.Drawing.Point(159, 440);
  1928. this.groupBox7.Name = "groupBox7";
  1929. this.groupBox7.Size = new System.Drawing.Size(367, 77);
  1930. this.groupBox7.TabIndex = 11;
  1931. this.groupBox7.TabStop = false;
  1932. this.groupBox7.Text = "目标选择";
  1933. //
  1934. // button10
  1935. //
  1936. this.button10.Location = new System.Drawing.Point(106, 21);
  1937. this.button10.Name = "button10";
  1938. this.button10.Size = new System.Drawing.Size(40, 40);
  1939. this.button10.TabIndex = 5;
  1940. this.button10.UseVisualStyleBackColor = true;
  1941. //
  1942. // button9
  1943. //
  1944. this.button9.Location = new System.Drawing.Point(60, 21);
  1945. this.button9.Name = "button9";
  1946. this.button9.Size = new System.Drawing.Size(40, 40);
  1947. this.button9.TabIndex = 4;
  1948. this.button9.UseVisualStyleBackColor = true;
  1949. //
  1950. // button8
  1951. //
  1952. this.button8.Location = new System.Drawing.Point(14, 21);
  1953. this.button8.Name = "button8";
  1954. this.button8.Size = new System.Drawing.Size(40, 40);
  1955. this.button8.TabIndex = 3;
  1956. this.button8.UseVisualStyleBackColor = true;
  1957. //
  1958. // radioButton5
  1959. //
  1960. this.radioButton5.AutoSize = true;
  1961. this.radioButton5.Location = new System.Drawing.Point(238, 55);
  1962. this.radioButton5.Name = "radioButton5";
  1963. this.radioButton5.Size = new System.Drawing.Size(14, 13);
  1964. this.radioButton5.TabIndex = 2;
  1965. this.radioButton5.UseVisualStyleBackColor = true;
  1966. this.radioButton5.Visible = false;
  1967. //
  1968. // radioButton4
  1969. //
  1970. this.radioButton4.AutoSize = true;
  1971. this.radioButton4.Checked = true;
  1972. this.radioButton4.Location = new System.Drawing.Point(297, 44);
  1973. this.radioButton4.Name = "radioButton4";
  1974. this.radioButton4.Size = new System.Drawing.Size(14, 13);
  1975. this.radioButton4.TabIndex = 1;
  1976. this.radioButton4.TabStop = true;
  1977. this.radioButton4.UseVisualStyleBackColor = true;
  1978. this.radioButton4.Visible = false;
  1979. //
  1980. // radioButton3
  1981. //
  1982. this.radioButton3.AutoSize = true;
  1983. this.radioButton3.Location = new System.Drawing.Point(279, 21);
  1984. this.radioButton3.Name = "radioButton3";
  1985. this.radioButton3.Size = new System.Drawing.Size(14, 13);
  1986. this.radioButton3.TabIndex = 0;
  1987. this.radioButton3.UseVisualStyleBackColor = true;
  1988. this.radioButton3.Visible = false;
  1989. //
  1990. // BinaryExtractDialog
  1991. //
  1992. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  1993. this.ClientSize = new System.Drawing.Size(942, 529);
  1994. this.Controls.Add(this.groupBox7);
  1995. this.Controls.Add(this.groupBox6);
  1996. this.Controls.Add(this.groupBox5);
  1997. this.Controls.Add(this.groupBox4);
  1998. this.Controls.Add(this.groupBox3);
  1999. this.Controls.Add(this.groupBox2);
  2000. this.Controls.Add(this.groupBox1);
  2001. this.Name = "BinaryExtractDialog";
  2002. this.ShowInTaskbar = false;
  2003. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  2004. this.Text = "二值提取";
  2005. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.BinaryExtractDialog_FormClosing);
  2006. this.Load += new System.EventHandler(this.BinaryExtractionDialog_Load);
  2007. this.Controls.SetChildIndex(this.groupBox1, 0);
  2008. this.Controls.SetChildIndex(this.groupBox2, 0);
  2009. this.Controls.SetChildIndex(this.groupBox3, 0);
  2010. this.Controls.SetChildIndex(this.groupBox4, 0);
  2011. this.Controls.SetChildIndex(this.groupBox5, 0);
  2012. this.Controls.SetChildIndex(this.groupBox6, 0);
  2013. this.Controls.SetChildIndex(this.groupBox7, 0);
  2014. this.groupBox2.ResumeLayout(false);
  2015. this.groupBox2.PerformLayout();
  2016. this.groupBox3.ResumeLayout(false);
  2017. this.groupBox3.PerformLayout();
  2018. this.groupBox4.ResumeLayout(false);
  2019. this.groupBox5.ResumeLayout(false);
  2020. this.groupBox5.PerformLayout();
  2021. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  2022. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  2023. this.groupBox6.ResumeLayout(false);
  2024. this.groupBox6.PerformLayout();
  2025. this.groupBox7.ResumeLayout(false);
  2026. this.groupBox7.PerformLayout();
  2027. this.ResumeLayout(false);
  2028. }
  2029. #region 参数保存及提取
  2030. /// <summary>
  2031. /// 保存参数的key,value和type
  2032. /// </summary>
  2033. /// <param name="param_key"></param>
  2034. /// <param name="param_value"></param>
  2035. /// <param name="param_type"></param>
  2036. private void saveParamValue(string param_key, string param_value, int param_type)
  2037. {
  2038. bool foundItem = false;
  2039. foreach (var item in this.analysisModel.ListParam)
  2040. {
  2041. if (item.param_key.Equals(param_key) && item.menuId == this.menuId)
  2042. {
  2043. item.param_value = param_value;
  2044. item.setValue();
  2045. foundItem = true;
  2046. break;
  2047. }
  2048. }
  2049. if (!foundItem)
  2050. {
  2051. GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
  2052. analysisItem.menuId = this.menuId;
  2053. analysisItem.param_key = param_key;
  2054. analysisItem.param_type = param_type;
  2055. analysisItem.param_value = param_value;
  2056. analysisItem.setValue();
  2057. this.analysisModel.ListParam.Add(analysisItem);
  2058. }
  2059. }
  2060. /// <summary>
  2061. /// 保存界面中的参数到model
  2062. /// </summary>
  2063. private void saveDialogParamValues()
  2064. {
  2065. saveParamValue(ParamKey_Paramlist, comboBox1.Text, (int)Base.Dtryt.ItemString);//参数列表
  2066. saveParamValue(ParamKey_NewPic, checkBox1.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//是否创建新图
  2067. }
  2068. /// <summary>
  2069. /// 获取保存的参数
  2070. /// </summary>
  2071. private void GetListParamModel()
  2072. {
  2073. if (this.analysisModel != null)
  2074. {
  2075. for (int i = 0; i < this.analysisModel.ListParam.Count; i++)
  2076. {
  2077. switch (this.analysisModel.ListParam[i].param_key)
  2078. {
  2079. case ParamKey_Paramlist:
  2080. comboBox1.Text = (string)this.analysisModel.ListParam[i].value;
  2081. //comboBox1_SelectedIndexChanged(null, null);
  2082. break;
  2083. case ParamKey_NewPic:
  2084. checkBox1.Checked = (Boolean)this.analysisModel.ListParam[i].value;
  2085. break;
  2086. }
  2087. }
  2088. }
  2089. }
  2090. private void BinaryExtractDialog_FormClosing(object sender, FormClosingEventArgs e)
  2091. {
  2092. this.saveDialogParamValues();
  2093. //xml保存路径
  2094. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryActionSaving\\ParameterSaving.xml";
  2095. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  2096. foreach (var analysisItem in this.analysisModel.ListParam)
  2097. {
  2098. bool foundItem = false;
  2099. foreach (var item in analysisModelXml.ListParam)
  2100. {
  2101. if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId)
  2102. {
  2103. item.param_value = analysisItem.param_value;
  2104. foundItem = true;
  2105. break;
  2106. }
  2107. }
  2108. if (!foundItem)
  2109. analysisModelXml.ListParam.Add(analysisItem.cloneModel());
  2110. }
  2111. //按路径和名称保存xml文件
  2112. string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainSizeAnalysisModel>(analysisModelXml);
  2113. //保存xml
  2114. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create);
  2115. }
  2116. #endregion
  2117. #region [脚本录制]
  2118. private void getScriptRecording()
  2119. {
  2120. List<Args> args = action.Lists;
  2121. foreach (var item in args)
  2122. {
  2123. item.value = setScriptRecording(item.key);
  2124. }
  2125. appWorkspace.SetScriptStartRecording(this.menuId, menuName, args);
  2126. }
  2127. private object setScriptRecording(string key)
  2128. {
  2129. object value = null;
  2130. if (key == "colorInterval")
  2131. {
  2132. value = this.binaryExtractionModel.ColorInterval == 2 ? true : false;
  2133. }
  2134. else if (key == "scope1")
  2135. {
  2136. value = new List<double>() { this.binaryExtractionModel.ColorOneStart, this.binaryExtractionModel.ColorOneEnd };
  2137. }
  2138. else if (key == "scope2")
  2139. {
  2140. value = new List<double>() { this.binaryExtractionModel.ColorTwoStart, this.binaryExtractionModel.ColorTwoEnd };
  2141. }
  2142. else if (key == "scope3")
  2143. {
  2144. value = new List<double>() { this.binaryExtractionModel.ColorThreeStart, this.binaryExtractionModel.ColorThreeEnd };
  2145. }
  2146. else if (key == "deleteBoundaryObject")
  2147. {
  2148. value = this.binaryExtractionModel.DeleteBoundaryObject;
  2149. }
  2150. else if (key == "holeFilling")
  2151. {
  2152. value = this.binaryExtractionModel.HoleFilling;
  2153. }
  2154. else if (key == "debrisRemoval")
  2155. {
  2156. value = this.binaryExtractionModel.DebrisRemoval;
  2157. }
  2158. else if (key == "scope4")
  2159. {
  2160. value = new List<double>() { this.binaryExtractionModel.DebrisAreaStart, this.binaryExtractionModel.DebrisAreaEnd };
  2161. }
  2162. else if (key == "binaryStyle")
  2163. {
  2164. value = this.binaryExtractionModel.BinaryStyle;
  2165. }
  2166. else if (key == "phaseColor")
  2167. {
  2168. value = this.binaryExtractionModel.PhaseColor;
  2169. }
  2170. else if (key == "targetSelection")
  2171. {
  2172. value = this.binaryExtractionModel.TargetSelection + 1;
  2173. }
  2174. else if (key == "createNewImg")
  2175. {
  2176. value = checkBox1.Checked ? 0 : 1;
  2177. }
  2178. return value;
  2179. }
  2180. #endregion
  2181. }
  2182. }