BinaryClass.cs 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  1. using OpenCvSharp;
  2. using PaintDotNet.Annotation;
  3. using PaintDotNet.Base;
  4. using PaintDotNet.Base.CommTool;
  5. using PaintDotNet.Base.Functionodel;
  6. using PaintDotNet.Base.SettingModel;
  7. using PaintDotNet.Data.Param;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Windows.Forms;
  13. namespace PaintDotNet
  14. {
  15. class BinaryClass
  16. {
  17. private int menuId;
  18. protected static string ParamKey_binaryStyle = "binaryStyle";//二值样式
  19. //protected static string ParamKey_displaygrid = "displaygrid";//显示网格
  20. //protected static string ParamKey_displaysections = "displaysections";//显示截点
  21. /// <summary>
  22. /// 是否针对全图进行二值化操作
  23. /// </summary>
  24. public bool processWholeMat = false;
  25. /// <summary>
  26. /// 是否显示视场
  27. /// </summary>
  28. public Boolean ShowDrawClassView = true;
  29. /// <summary>
  30. /// 调色板
  31. /// </summary>
  32. PaintDotNet.ColorsForm colorsForm1;
  33. /// <summary>
  34. /// 构造工作结构
  35. /// </summary>
  36. private Dictionary<int, DocumentItem> documentItems;
  37. /// <summary>
  38. /// 需要的数据在这里引用
  39. /// </summary>
  40. CustomControl.BinaryControlSmaller bmc;
  41. /// <summary>
  42. /// 需要的数据在这里引用
  43. /// </summary>
  44. CustomControl.BinaryControl bc;
  45. AppWorkspace appWorkspace;
  46. DocumentWorkspaceWindow documentWorkspace;
  47. ListView listView1;
  48. /// <summary>
  49. /// 是否要调用二值化的算法
  50. /// </summary>
  51. private bool toApplyBinary = true;
  52. /// <summary>
  53. /// 处理程序
  54. /// </summary>
  55. private ParamObject action = new Data.Action.Action901();
  56. /// <summary>
  57. /// 处理程序
  58. /// </summary>
  59. private ParamObject analysisAction = new Data.Action.ActionAnalysis();
  60. /// <summary>
  61. /// 二值参数配置值(当前图片)
  62. /// </summary>
  63. private BinaryExtractionModel binaryExtractionModel;
  64. /// <summary>
  65. /// 二值参数是否进行全部应用,用于更新图片二值化效果,默认为false
  66. /// </summary>
  67. private Dictionary<string, bool> binaryModelFlag = new Dictionary<string, bool>();
  68. /// <summary>
  69. /// 二值参数配置值(全部图片的)
  70. /// </summary>
  71. private Dictionary<string, BinaryExtractionModel> binaryModelDict = new Dictionary<string, BinaryExtractionModel>();
  72. /// <summary>
  73. /// 二值(备份全部图片)
  74. /// </summary>
  75. private Dictionary<string, Mat> binaryData1Dict = new Dictionary<string, Mat>();
  76. /// <summary>
  77. /// 相0的图片,处理多视场使用
  78. /// </summary>
  79. public Mat PhaseModels0Mat;
  80. /// <summary>
  81. /// 辅助线集成
  82. /// </summary>
  83. public PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass.GrainSizeGuideClass guideClass;
  84. public ComboBox comboBox1;
  85. //public object SelectedItem;
  86. //public GrainSizeGuideClass GuideClass
  87. //{
  88. // set
  89. // {
  90. // this.guideClass = value;
  91. // }
  92. //}
  93. public static Mat dstBinary;
  94. /// <summary>
  95. /// 对二值图像的透明通道提取出单通道图像
  96. /// </summary>
  97. /// <param name="source"></param>
  98. /// <returns></returns>
  99. public unsafe static Mat BGRA2GRAY(Mat source/*, out Mat dst*/)
  100. {
  101. if (source.Channels() != 4)
  102. {
  103. //Mat dst = source;
  104. return source.CvtColor(ColorConversionCodes.BGR2GRAY);// dst;// false;、、should never go here !
  105. }
  106. //二值提取
  107. if (dstBinary != null)
  108. {
  109. dstBinary.Dispose();
  110. dstBinary = null;
  111. }
  112. dstBinary = new Mat(source.Rows, source.Cols, MatType.CV_8UC1, new Scalar(0));
  113. //如果是rgba
  114. source.ForEachAsVec4b(ForeachFunctionByteForWhole4B);
  115. Mat dst = dstBinary.Clone();
  116. dstBinary.Dispose();
  117. dstBinary = null;
  118. return dst;// true;
  119. }
  120. /// <summary>
  121. /// 提取二值化的透明通道并赋值
  122. /// </summary>
  123. /// <param name="t"></param>
  124. /// <param name="position"></param>
  125. public unsafe static void ForeachFunctionByteForWhole4B(Vec4b* t, int* position)
  126. {
  127. dstBinary.Set(position[0], position[1], t->Item3);
  128. }
  129. /// <summary>
  130. /// 公开的事件,每次二值化之后需要的计算事件写在这里
  131. /// </summary>
  132. public event EventHandler BinaryImplFinishAction;
  133. private void OnBinaryImplFinishAction()
  134. {
  135. if (BinaryImplFinishAction != null)
  136. {
  137. BinaryImplFinishAction(this, new EventArgs());
  138. }
  139. }
  140. public BinaryClass(int menuId)
  141. {
  142. this.menuId = menuId;
  143. }
  144. /// <summary>
  145. /// 判断是否进行二值,以及返回二值图片
  146. /// </summary>
  147. /// <param name="imagesKey"></param>
  148. /// <returns></returns>
  149. public Mat getModelMat(string imagesKey)
  150. {
  151. if (binaryData1Dict.ContainsKey(imagesKey) && (!binaryModelDict.ContainsKey(imagesKey) && binaryExtractionModel.BinaryCheckFlag > 1
  152. || binaryModelDict.ContainsKey(imagesKey) && binaryModelDict[imagesKey].BinaryCheckFlag > 1))
  153. return binaryData1Dict[imagesKey];
  154. return null;
  155. }
  156. /// <summary>
  157. /// 判断是否进行二值
  158. /// </summary>
  159. /// <param name="imagesKey"></param>
  160. /// <returns></returns>
  161. public bool getModelBinaryCheckFlag(string imagesKey)
  162. {
  163. if ((!binaryModelDict.ContainsKey(imagesKey) && binaryExtractionModel.BinaryCheckFlag > 1
  164. || binaryModelDict.ContainsKey(imagesKey) && binaryModelDict[imagesKey].BinaryCheckFlag > 1))
  165. return true;
  166. return false;
  167. }
  168. /// <summary>
  169. /// 判断是否需要计算,并根据判断结果进行相关处理
  170. /// </summary>
  171. /// <param name="imagesKey"></param>
  172. /// <param name="analysisPicture"></param>
  173. public void updateAnalysisData(string imagesKey, int analysisPicture)
  174. {
  175. if (!binaryModelDict.ContainsKey(imagesKey) && binaryExtractionModel.BinaryCheckFlag > 1
  176. || binaryModelDict.ContainsKey(imagesKey) && binaryModelDict[imagesKey].BinaryCheckFlag > 1)
  177. ////|| binaryModelFlag.ContainsKey(imagesKey) && binaryModelFlag[imagesKey]/* //################ && binaryModelFlag[imagesKey] = false;*/)
  178. {
  179. this.applyButtonImpl(imagesKey, analysisPicture, /*bitmap = */this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.CreateAliasedBitmap());
  180. //if (binaryModelFlag.ContainsKey(imagesKey) && binaryModelFlag[imagesKey])
  181. // binaryModelFlag[imagesKey] = false;
  182. }
  183. else if (binaryData1Dict.ContainsKey(imagesKey))
  184. {
  185. if (binaryData1Dict[imagesKey] != null)
  186. binaryData1Dict[imagesKey] = null;
  187. }
  188. }
  189. public void InitBinaryControlEvent()
  190. {
  191. if (bmc != null)
  192. {
  193. bmc.InitBinaryControlEvent();
  194. bmc.BinaryGetParamAction += new EventHandler(this.bcBinaryGetParamAction);
  195. bmc.AutoThresClickAction += new EventHandler(this.bcAutoThresClickAction);
  196. bmc.InverseClickAction += new EventHandler(this.bcBinaryGetParamAction);
  197. bmc.InverseClickAction += new EventHandler(this.bcApplyButtonImplAction);
  198. bmc.RadioButton1ChangedAction += new EventHandler(this.bcBinaryGetParamAction);
  199. bmc.RadioButton2ChangedAction += new EventHandler(this.bcBinaryGetParamAction);
  200. bmc.ApplyButtonImplAction += new EventHandler(this.bcApplyButtonImplAction);
  201. bmc.BinaryCheckedChangedAction += new EventHandler(this.bcBinaryCheckedChanged);
  202. bmc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);
  203. bmc.BinaryEditClickAction += new EventHandler(this.bcBinaryEditClickAction);
  204. bmc.PanelColorClickAction += new EventHandler(this.bcPanelColorClickAction);//初始化颜色点击事件
  205. return;
  206. }
  207. if (bc == null)
  208. return;
  209. bc.InitBinaryControlEvent();
  210. bc.BinaryGetParamAction += new EventHandler(this.bcBinaryGetParamAction);
  211. bc.AutoThresClickAction += new EventHandler(this.bcAutoThresClickAction);
  212. bc.InverseClickAction += new EventHandler(this.bcBinaryGetParamAction);
  213. bc.InverseClickAction += new EventHandler(this.bcApplyButtonImplAction);
  214. bc.RadioButton1ChangedAction += new EventHandler(this.bcBinaryGetParamAction);
  215. bc.RadioButton2ChangedAction += new EventHandler(this.bcBinaryGetParamAction);
  216. bc.ApplyButtonImplAction += new EventHandler(this.bcApplyButtonImplAction);
  217. bc.BinaryCheckedChangedAction += new EventHandler(this.bcBinaryCheckedChanged);
  218. bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);
  219. bc.BinaryEditClickAction += new EventHandler(this.bcBinaryEditClickAction);
  220. bc.PanelColorClickAction += new EventHandler(this.bcPanelColorClickAction);//初始化颜色点击事件
  221. }
  222. /// <summary>
  223. /// 外部需要改变二值化勾选状态时调用该方法
  224. /// </summary>
  225. /// <param name="toCheck"></param>
  226. public void performClickBinaryCheck(bool toCheck)
  227. {
  228. if (bmc != null)
  229. bmc.BinaryChecked = toCheck;
  230. else
  231. bc.BinaryChecked = toCheck;
  232. }
  233. /// <summary>
  234. /// 相颜色点击事件
  235. /// </summary>
  236. /// <param name="sender"></param>
  237. /// <param name="e"></param>
  238. private void bcPanelColorClickAction(object sender, EventArgs e)
  239. {
  240. this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(bmc != null ? bmc.BinaryBackColor : bc.BinaryBackColor);
  241. this.colorsForm1.ShowDialog();
  242. this.applyButtonImpl(/*bitmap*/);
  243. }
  244. /// <summary>
  245. /// 二值筛选
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void bcBinaryEditClickAction(object sender, EventArgs e)
  250. {
  251. if (this.documentWorkspace.PhaseModels[0].mat == null)
  252. {
  253. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperonfirst.text"));
  254. return;
  255. }
  256. PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass.GrainBinaryBoundaryEditingDialog boundaryEditingDialog = new PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass.GrainBinaryBoundaryEditingDialog(this.appWorkspace, this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index, bmc != null ? bmc.BinaryBackColor : bc.BinaryBackColor
  257. , this.documentWorkspace.PhaseModels[0].mat.Clone(), ShowDrawClassView, this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index].GetRuler(MeasurementUnit.Micron));
  258. ////1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界)
  259. if (this.guideClass != null && this.comboBox1 != null && this.comboBox1.SelectedItem != null)
  260. {
  261. boundaryEditingDialog.GuideClass = this.guideClass;
  262. boundaryEditingDialog.SelectedItem = this.comboBox1.SelectedItem;
  263. }
  264. if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
  265. {
  266. this.documentWorkspace.PhaseModels[0].mat = boundaryEditingDialog.PhaseMat.Clone();
  267. OnBinaryImplFinishAction();
  268. }
  269. }
  270. /// <summary>
  271. /// 显示原图勾选改变事件
  272. /// </summary>
  273. /// <param name="sender"></param>
  274. /// <param name="e"></param>
  275. private void bcOriginCheckedChanged(object sender, EventArgs e)
  276. {
  277. if (bc == null && bmc == null)
  278. return;
  279. int BinaryCheckFlag = 0;
  280. if (bmc != null ? bmc.OriginChecked : bc.OriginChecked)
  281. BinaryCheckFlag += 1;
  282. if (bmc != null ? bmc.BinaryChecked : bc.BinaryChecked)
  283. BinaryCheckFlag += 2;
  284. this.binaryExtractionModel.BinaryCheckFlag = BinaryCheckFlag;
  285. }
  286. /// <summary>
  287. /// 二值化勾选改变事件
  288. /// </summary>
  289. /// <param name="sender"></param>
  290. /// <param name="e"></param>
  291. private void bcBinaryCheckedChanged(object sender, EventArgs e)
  292. {
  293. if (bc == null && bmc == null)
  294. return;
  295. int BinaryCheckFlag = 0;
  296. if (bmc != null ? bmc.OriginChecked : bc.OriginChecked)
  297. BinaryCheckFlag += 1;
  298. if (bmc != null ? bmc.BinaryChecked : bc.BinaryChecked)
  299. BinaryCheckFlag += 2;
  300. this.binaryExtractionModel.BinaryCheckFlag = BinaryCheckFlag;
  301. if ((bmc != null ? bmc.BinaryChecked : bc.BinaryChecked) && !(bmc != null ? bmc.OriginChecked : bc.OriginChecked))
  302. {
  303. this.documentWorkspace.PhaseModels[0].choise = true;
  304. }
  305. else
  306. {
  307. this.documentWorkspace.PhaseModels[0].choise = false;
  308. }
  309. if (toApplyBinary)
  310. this.applyButtonImpl();
  311. else
  312. OnBinaryImplFinishAction();
  313. toApplyBinary = true;
  314. if (this.listView1.FocusedItem == null || !(bmc != null ? bmc.BinaryChecked : bc.BinaryChecked))
  315. this.documentWorkspace.Refresh();
  316. }
  317. /// <summary>
  318. /// 自动阈值
  319. /// </summary>
  320. /// <param name="sender"></param>
  321. /// <param name="e"></param>
  322. private void bcAutoThresClickAction(object sender, EventArgs e)
  323. {
  324. if (bc == null && bmc == null)
  325. return;
  326. Bitmap bitmap = null;
  327. if (listView1.FocusedItem != null || this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  328. bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index].CompositionSurface.CreateAliasedBitmap();
  329. if (bitmap != null)
  330. {
  331. //先计算阈值
  332. Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
  333. Mat gray = mat.CvtColor(ColorConversionCodes.BGR2GRAY);
  334. double otsu = Cv2.Threshold(gray, gray, 0, 255, ThresholdTypes.Triangle/*.Otsu*/);
  335. if (otsu <= 10 || otsu >= 245)
  336. {
  337. otsu = Cv2.Threshold(mat.CvtColor(ColorConversionCodes.BGR2GRAY), gray, 0, 255, ThresholdTypes.Otsu);//.Triangle
  338. }
  339. //如果当前是两个区间,则需要重新计算一次
  340. if (this.ColorInterval == 2)
  341. {
  342. if (bmc != null)
  343. bmc.OnInverseClickAction();
  344. else
  345. bc.OnInverseClickAction();
  346. this.ColorInterval = (bmc != null ? bmc.getInverseStyle() : bc.getInverseStyle());
  347. }
  348. else
  349. {
  350. if (bmc != null)
  351. bmc.setInverseStyle(1);
  352. else
  353. bc.setInverseStyle(1);
  354. }
  355. //给控件赋值
  356. if (bmc != null)
  357. bmc.scope1Start = 0;
  358. else
  359. bc.scope1Start = 0;
  360. if (bmc != null)
  361. bmc.scope1End = otsu;
  362. else
  363. bc.scope1End = otsu;
  364. //处理直方图
  365. if (bmc != null)
  366. bmc.UpdateVerticalBarWithOneScope(0, Convert.ToInt32(bmc.scope1End));
  367. else
  368. bc.UpdateVerticalBarWithOneScope(0, Convert.ToInt32(bc.scope1End));
  369. mat.Dispose();
  370. GC.Collect();
  371. this.bcApplyButtonImplAction(sender, e);
  372. }
  373. else
  374. {
  375. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  376. }
  377. }
  378. /// <summary>
  379. /// 执行读取参数的事件
  380. /// </summary>
  381. /// <param name="sender"></param>
  382. /// <param name="e"></param>
  383. private void bcBinaryGetParamAction(object sender, EventArgs e)
  384. {
  385. if (bc == null && bmc == null)
  386. return;
  387. this.binaryExtractionModel.ColorInterval = (bmc != null ? bmc.getInverseStyle() : bc.getInverseStyle());//###
  388. this.binaryExtractionModel.BinaryStyle = (bmc != null ? bmc.BinaryStyle : bc.BinaryStyle);
  389. this.binaryExtractionModel.ColorOneStart = (int)(bmc != null ? bmc.scope1Start : bc.scope1Start);
  390. this.binaryExtractionModel.ColorOneEnd = (int)(bmc != null ? bmc.scope1End : bc.scope1End);
  391. this.binaryExtractionModel.ColorTwoStart = (int)(bmc != null ? bmc.scope2Start : bc.scope2Start);
  392. this.binaryExtractionModel.ColorTwoEnd = (int)(bmc != null ? bmc.scope2End : bc.scope2End);
  393. this.binaryExtractionModel.ColorThreeStart = (int)(bmc != null ? bmc.scope3Start : bc.scope3Start);
  394. this.binaryExtractionModel.ColorThreeEnd = (int)(bmc != null ? bmc.scope3End : bc.scope3End);
  395. this.initParamsToAction();
  396. }
  397. /// <summary>
  398. /// 获取相的工作结构
  399. /// </summary>
  400. /// <param name="index">指明获取第几个相的工作结构</param>
  401. /// <returns></returns>
  402. public List<PhaseModel> getPhaseModels(int index)
  403. {
  404. return this.documentItems[index].phaseModels;
  405. }
  406. /// <summary>
  407. /// 应用到全部
  408. /// </summary>
  409. /// <param name="imagesKeys">所有要改变参数的图片tag</param>
  410. /// <param name="currentImagesKey">当前操作的图片tag</param>
  411. public void applyToAll(System.Collections.Specialized.StringCollection imagesKeys, string currentImagesKey)
  412. {
  413. foreach (var imagesKey in imagesKeys)
  414. {
  415. if (imagesKey.Equals(currentImagesKey))
  416. continue;//#
  417. if (!binaryModelDict.ContainsKey(imagesKey))
  418. {
  419. binaryModelFlag.Add(imagesKey, true);
  420. binaryModelDict.Add(imagesKey, this.binaryExtractionModel.cloneModel());
  421. if (!binaryData1Dict.ContainsKey(imagesKey))
  422. {
  423. binaryData1Dict.Add(imagesKey, null);
  424. }
  425. else
  426. binaryData1Dict[imagesKey] = null;//###
  427. }
  428. else
  429. {
  430. binaryModelFlag[imagesKey] = true;
  431. binaryModelDict[imagesKey] = this.binaryExtractionModel.cloneModel();
  432. binaryData1Dict[imagesKey] = null;
  433. }
  434. }
  435. }
  436. /// <summary>
  437. /// 保存二值化图片
  438. /// </summary>
  439. /// <param name="imagesKey"></param>
  440. public void saveMat(string imagesKey)
  441. {
  442. if (binaryData1Dict.ContainsKey(imagesKey))
  443. {
  444. if (binaryData1Dict[imagesKey] != null)
  445. binaryData1Dict[imagesKey] = null;
  446. binaryData1Dict[imagesKey] = this.documentWorkspace.phaseModels[0].mat;
  447. }
  448. else
  449. {
  450. try
  451. {
  452. binaryData1Dict.Add(imagesKey, this.documentWorkspace.phaseModels[0].mat);
  453. }
  454. catch (Exception)
  455. {
  456. binaryData1Dict.Add(imagesKey, null);
  457. }
  458. }
  459. }
  460. /// <summary>
  461. /// ListView图片选择改变事件,不显示视场
  462. /// </summary>
  463. /// <param name="imagesKey">选择改变后的图片tag</param>
  464. /// <param name="bitmap">选择改变后的图片</param>
  465. public void listView1_SelectedIndexChangedHideDrawClassView(Bitmap bitmap, string imagesKey = null)
  466. {
  467. if (imagesKey != null)
  468. {
  469. if (!binaryModelDict.ContainsKey(imagesKey))
  470. {
  471. binaryModelFlag.Add(imagesKey, false);
  472. this.binaryExtractionModel = this.binaryExtractionModel.cloneModel();
  473. binaryModelDict.Add(imagesKey, this.binaryExtractionModel);
  474. }
  475. //else
  476. {
  477. this.binaryExtractionModel = binaryModelDict[imagesKey];
  478. this.initParamsToAction();
  479. this.InitParameterToControl();
  480. }
  481. }
  482. Document document = Document.FromImage(bitmap);
  483. this.documentWorkspace.Document = document;
  484. this.documentWorkspace.Visible = true;
  485. GraphicsList itemGraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index].GraphicsList;
  486. GraphicsList graphicsList = new GraphicsList();
  487. for (int j = 0; j < itemGraphicsList.Count; j++)
  488. {
  489. if (itemGraphicsList[j].objectType != Annotation.Enum.DrawClass.View)
  490. graphicsList.Add(itemGraphicsList[j]);
  491. }
  492. this.documentWorkspace.GraphicsList = graphicsList;
  493. this.documentWorkspace.PhaseModels = new List<PhaseModel>();
  494. this.documentWorkspace.PhaseModels.AddRange(this.getPhaseModels(this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index));
  495. if ((imagesKey == null || !binaryModelFlag.ContainsKey(imagesKey) || !binaryModelFlag[imagesKey]/*用于更新图片二值化效果*/) && (bc != null || bmc != null) && this.documentWorkspace.PhaseModels[0].mat != null)
  496. {
  497. if (!(bmc != null ? bmc.BinaryChecked : bc.BinaryChecked) && this.documentWorkspace.PhaseModels[0].choise
  498. /*&& (this.binaryExtractionModel.BinaryCheckFlag > 1)*/)
  499. {
  500. this.toApplyBinary = false;
  501. if (bmc != null)
  502. bmc.BinaryChecked = true;
  503. else
  504. bc.BinaryChecked = true;
  505. }
  506. }
  507. else
  508. {
  509. if (binaryData1Dict.ContainsKey(imagesKey) && binaryData1Dict[imagesKey] != null)
  510. {
  511. documentWorkspace.PhaseModels[0].mat = binaryData1Dict[imagesKey];// this.PerformProcess(
  512. //OpenCvSharp.Extensions.BitmapConverter.ToMat(documentWorkspace.GetFullSizeWithRegion()),
  513. //OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));
  514. //documentWorkspace.PhaseModels[0].color = (bmc != null ? bmc.BinaryBackColor.ToArgb() : bc.BinaryBackColor.ToArgb());
  515. documentWorkspace.Refresh();
  516. }
  517. else
  518. this.applyButtonImpl();
  519. }
  520. if (imagesKey != null && binaryModelFlag.ContainsKey(imagesKey)/*用于更新图片二值化效果*/)
  521. {
  522. this.documentWorkspace.PhaseModels[0].choise = (this.binaryExtractionModel.BinaryCheckFlag == 2)/*(bmc != null ? bmc.BinaryChecked : bc.BinaryChecked)*/;
  523. binaryModelFlag[imagesKey] = false;
  524. if (bmc != null)
  525. bmc.BinaryChecked = this.documentWorkspace.PhaseModels[0].choise || (this.binaryExtractionModel.BinaryCheckFlag > 1);
  526. else
  527. bc.BinaryChecked = this.documentWorkspace.PhaseModels[0].choise || (this.binaryExtractionModel.BinaryCheckFlag > 1);
  528. }
  529. else if ((bc != null || bmc != null) && !this.documentWorkspace.PhaseModels[0].choise
  530. && (this.binaryExtractionModel.BinaryCheckFlag <= 1))
  531. if (bmc != null)
  532. bmc.BinaryChecked = false;
  533. else
  534. bc.BinaryChecked = false;
  535. if (imagesKey != null)
  536. {
  537. if (this.binaryExtractionModel.BinaryCheckFlag % 2 == 1)
  538. {
  539. if (bmc != null)
  540. bmc.OriginChecked = true;
  541. else
  542. bc.OriginChecked = true;
  543. }
  544. else
  545. {
  546. if (bmc != null)
  547. bmc.OriginChecked = false;
  548. else
  549. bc.OriginChecked = false;
  550. }
  551. }
  552. //显示直方图
  553. if (bc != null || bmc != null)
  554. if (bmc != null)
  555. bmc.CreateHistogram(bitmap, true, 339, 130, 0);
  556. else
  557. bc.CreateHistogram(bitmap, true, 339, 130, 0);
  558. this.RefreshHistogramControl1Values();//##
  559. }
  560. /// <summary>
  561. /// ListView图片选择改变事件
  562. /// </summary>
  563. /// <param name="bitmap">选择改变后的图片</param>
  564. public void listView1_SelectedIndexChanged(Bitmap bitmap, string imagesKey = null)
  565. {
  566. if (imagesKey != null)
  567. {
  568. if (!binaryModelDict.ContainsKey(imagesKey))
  569. {
  570. binaryModelFlag.Add(imagesKey, false);
  571. this.binaryExtractionModel = this.binaryExtractionModel.cloneModel();
  572. binaryModelDict.Add(imagesKey, this.binaryExtractionModel);
  573. }
  574. //else
  575. {
  576. this.binaryExtractionModel = binaryModelDict[imagesKey];
  577. this.initParamsToAction();
  578. this.InitParameterToControl();
  579. }
  580. }
  581. Document document = Document.FromImage(bitmap);
  582. this.documentWorkspace.Document = document;
  583. this.documentWorkspace.Visible = true;
  584. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index].GraphicsList;
  585. this.documentWorkspace.PhaseModels = new List<PhaseModel>();
  586. this.documentWorkspace.PhaseModels.AddRange(this.getPhaseModels(this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index));
  587. if (((imagesKey == null || !binaryModelFlag.ContainsKey(imagesKey) || !binaryModelFlag[imagesKey]/*用于更新图片二值化效果*/) && (bc != null || bmc != null)) && this.documentWorkspace.PhaseModels[0].mat != null)
  588. {
  589. if (!(bmc != null ? bmc.BinaryChecked : bc.BinaryChecked) && this.documentWorkspace.PhaseModels[0].choise)
  590. {
  591. this.toApplyBinary = false;
  592. if (bmc != null)
  593. bmc.BinaryChecked = true;
  594. else
  595. bc.BinaryChecked = true;
  596. }
  597. }
  598. else
  599. {
  600. this.applyButtonImpl();
  601. }
  602. if (imagesKey != null && binaryModelFlag.ContainsKey(imagesKey)/*用于更新图片二值化效果*/)
  603. {
  604. this.documentWorkspace.PhaseModels[0].choise = (this.binaryExtractionModel.BinaryCheckFlag == 2);// (bmc != null ? bmc.BinaryChecked : bc.BinaryChecked);
  605. binaryModelFlag[imagesKey] = false;
  606. if (bmc != null)
  607. bmc.BinaryChecked = this.documentWorkspace.PhaseModels[0].choise || (this.binaryExtractionModel.BinaryCheckFlag > 1);
  608. else
  609. bc.BinaryChecked = this.documentWorkspace.PhaseModels[0].choise || (this.binaryExtractionModel.BinaryCheckFlag > 1);
  610. }
  611. else if ((bc != null || bmc != null) && !this.documentWorkspace.PhaseModels[0].choise
  612. && (this.binaryExtractionModel.BinaryCheckFlag <= 1))
  613. if (bmc != null)
  614. bmc.BinaryChecked = false;
  615. else
  616. bc.BinaryChecked = false;
  617. if (imagesKey != null)
  618. {
  619. if (this.binaryExtractionModel.BinaryCheckFlag % 2 == 1)
  620. {
  621. if (bmc != null)
  622. bmc.OriginChecked = true;
  623. else
  624. bc.OriginChecked = true;
  625. }
  626. else
  627. {
  628. if (bmc != null)
  629. bmc.OriginChecked = false;
  630. else
  631. bc.OriginChecked = false;
  632. }
  633. }
  634. //显示直方图
  635. if (bc != null || bmc != null)
  636. if (bmc != null)
  637. bmc.CreateHistogram(bitmap, true, 339, 130, 0);
  638. else
  639. bc.CreateHistogram(bitmap, true, 339, 130, 0);
  640. this.RefreshHistogramControl1Values();
  641. }
  642. /// <summary>
  643. /// ListView图片选择改变事件
  644. /// </summary>
  645. /// <param name="bitmap">选择改变后的图片</param>
  646. public void listView1_SelectedIndexChangedNoCheckedChanged(Bitmap bitmap, string imagesKey = null)
  647. {
  648. if (imagesKey != null)
  649. {
  650. if (!binaryModelDict.ContainsKey(imagesKey))
  651. {
  652. binaryModelFlag.Add(imagesKey, false);
  653. this.binaryExtractionModel = this.binaryExtractionModel.cloneModel();
  654. binaryModelDict.Add(imagesKey, this.binaryExtractionModel);
  655. }
  656. //else
  657. {
  658. this.binaryExtractionModel = binaryModelDict[imagesKey];
  659. this.initParamsToAction();
  660. this.InitParameterToControl();
  661. }
  662. }
  663. Document document = Document.FromImage(bitmap);
  664. this.documentWorkspace.Document = document;
  665. this.documentWorkspace.Visible = true;
  666. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index].GraphicsList;
  667. this.documentWorkspace.PhaseModels = new List<PhaseModel>();
  668. this.documentWorkspace.PhaseModels.AddRange(this.getPhaseModels(this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index));
  669. if ((imagesKey == null || !binaryModelFlag.ContainsKey(imagesKey) || !binaryModelFlag[imagesKey]/*用于更新图片二值化效果*/) && (bc != null || bmc != null) && this.documentWorkspace.PhaseModels[0].mat != null)
  670. {
  671. if (!(bmc != null ? bmc.BinaryChecked : bc.BinaryChecked) && this.documentWorkspace.PhaseModels[0].choise)//to sure and test
  672. {
  673. this.toApplyBinary = false;
  674. if (bmc != null)
  675. bmc.BinaryChecked = true;
  676. else
  677. bc.BinaryChecked = true;
  678. }
  679. }
  680. else
  681. {
  682. this.applyButtonImpl();
  683. }
  684. if (imagesKey != null && binaryModelFlag.ContainsKey(imagesKey)/*用于更新图片二值化效果*/)
  685. {
  686. this.documentWorkspace.PhaseModels[0].choise = (this.binaryExtractionModel.BinaryCheckFlag == 2);// (bmc != null ? bmc.BinaryChecked : bc.BinaryChecked);
  687. binaryModelFlag[imagesKey] = false;
  688. if (bmc != null)
  689. bmc.BinaryChecked = this.documentWorkspace.PhaseModels[0].choise || (this.binaryExtractionModel.BinaryCheckFlag > 1);
  690. else
  691. bc.BinaryChecked = this.documentWorkspace.PhaseModels[0].choise || (this.binaryExtractionModel.BinaryCheckFlag > 1);
  692. }
  693. //else
  694. ////to sure and test
  695. //if (bc != null && !this.documentWorkspace.PhaseModels[0].choise)
  696. // bc.BinaryChecked = false;
  697. //显示直方图
  698. if (bc != null || bmc != null)
  699. if (bmc != null)
  700. bmc.CreateHistogram(bitmap, true, 339, 130, 0);
  701. else
  702. bc.CreateHistogram(bitmap, true, 339, 130, 0);
  703. this.RefreshHistogramControl1Values();
  704. }
  705. /// <summary>
  706. /// 构造相的工作结构
  707. /// </summary>
  708. /// <param name="phaseNames">相的命名,如果只有二值则只传PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text")即可,没有特殊情况命名第一个相为PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text")</param>
  709. /// <param name="bmc"></param>
  710. /// <param name="appWorkspace"></param>
  711. /// <param name="documentWorkspace"></param>
  712. public void createDocumentItemsSmaller(string[] phaseNames, CustomControl.BinaryControlSmaller bmc, AppWorkspace appWorkspace
  713. , DocumentWorkspaceWindow documentWorkspace, ListView listView1)
  714. {
  715. this.bmc = bmc;
  716. this.appWorkspace = appWorkspace;
  717. this.documentWorkspace = documentWorkspace;
  718. this.listView1 = listView1;
  719. //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
  720. if (this.appWorkspace.ScriptRunning && this.appWorkspace.ScriptCurrentParam != null)
  721. {
  722. binaryExtractionModel = new BinaryExtractionModel();
  723. foreach (Args args in analysisAction.Lists)
  724. {
  725. Args param1 = this.appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(args.Key));
  726. if (param1 != null && param1.value != null)
  727. args.Value = param1.value;
  728. if (args.Key == "colorInterval")
  729. {
  730. this.binaryExtractionModel.ColorInterval = (Boolean)args.Value ? 2 : 1;
  731. }
  732. else if (args.Key == "scope1")
  733. {
  734. List<double> twoL = (List<double>)args.Value;
  735. this.binaryExtractionModel.ColorOneStart = (int)twoL[0];
  736. this.binaryExtractionModel.ColorOneEnd = (int)twoL[1];
  737. }
  738. else if (args.Key == "scope2")
  739. {
  740. List<double> twoL = (List<double>)args.Value;
  741. this.binaryExtractionModel.ColorTwoStart = (int)twoL[0];
  742. this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1];
  743. }
  744. else if (args.Key == "scope3")
  745. {
  746. List<double> twoL = (List<double>)args.Value;
  747. this.binaryExtractionModel.ColorThreeStart = (int)twoL[0];
  748. this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1];
  749. }
  750. else if (args.Key == "scope4")
  751. {
  752. this.binaryExtractionModel.DebrisAreaStart = (int)((List<double>)args.Value)[0];
  753. this.binaryExtractionModel.DebrisAreaEnd = (int)((List<double>)args.Value)[1];
  754. }
  755. else if (args.Key == "binaryStyle")
  756. {
  757. this.binaryExtractionModel.BinaryStyle = (int)args.Value;
  758. }
  759. else if (args.Key == "phaseColor")
  760. {
  761. this.binaryExtractionModel.PhaseColor = (int)args.Value;
  762. }
  763. else if (args.Key == "binarization")
  764. {
  765. this.binaryExtractionModel.BinaryCheckFlag = Convert.ToBoolean(args.Value) == true ? 2 : 0;
  766. }
  767. else if (args.Key == "theoriginalcolor")
  768. {
  769. bool thisValue = Convert.ToBoolean(args.Value);
  770. if (thisValue)
  771. {
  772. this.binaryExtractionModel.BinaryCheckFlag = this.binaryExtractionModel.BinaryCheckFlag == 2 ? 3 : 1;
  773. }
  774. }
  775. }
  776. //string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryConfig\\Default_" + this.menuId + ".xml";
  777. //bool createNewFile = !System.IO.File.Exists(xmlFilePath);
  778. //if (createNewFile)
  779. // xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\Default.xml";
  780. //this.binaryExtractionModel = XmlSerializeHelper.DESerializer<BinaryExtractionModel>(FileOperationHelper.ReadStringFromFile(xmlFilePath, FileMode.Open));
  781. //if (createNewFile)
  782. // this.binaryExtractionModel.BinaryCheckFlag = 0;
  783. this.initParamsToAction();
  784. }
  785. else
  786. this.initParams();
  787. for (int i = 0; i < phaseNames.Length; i++)
  788. {
  789. PhaseModel model = new PhaseModel();
  790. model.choise = true;
  791. model.mat = null;
  792. model.color = (i == 0 && bmc != null) ? bmc.BinaryBackColor.ToArgb() : Color.Green.ToArgb();//###
  793. model.position = documentWorkspace.PhaseModels.Count + 1;
  794. model.name = phaseNames[i];
  795. documentWorkspace.PhaseModels.Add(model);
  796. }
  797. this.documentItems = new Dictionary<int, DocumentItem>();
  798. // 构造工作结构
  799. for (int i = 0; i < appWorkspace.DocumentWorkspaces.Length; i++)
  800. {
  801. Bitmap bitmap = appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap();
  802. GraphicsList graphicsList = new GraphicsList();
  803. for (int j = 0; j < appWorkspace.DocumentWorkspaces[i].GraphicsList.Count; j++)
  804. {
  805. graphicsList.Add(appWorkspace.DocumentWorkspaces[i].GraphicsList[j]);
  806. }
  807. List<PhaseModel> phaseModels = new List<PhaseModel>();
  808. for (int j = 0; j < phaseNames.Length; j++)
  809. {
  810. //二值化相关
  811. if (j == 0)
  812. {
  813. PhaseModel analysisModel = appWorkspace.DocumentWorkspaces[i].AnalysisPhaseModel;
  814. if (analysisModel == null)
  815. {
  816. PhaseModel model = new PhaseModel();
  817. model.choise = true;
  818. model.mat = null;
  819. model.color = bmc != null ? bmc.BinaryBackColor.ToArgb() : Color.Green.ToArgb();
  820. model.position = phaseModels.Count + 1;
  821. model.name = phaseNames[j];
  822. phaseModels.Add(model);
  823. }
  824. else
  825. phaseModels.Add(analysisModel);
  826. }
  827. else
  828. {
  829. PhaseModel model = new PhaseModel();
  830. model.choise = true;
  831. model.mat = null;
  832. model.color = Color.Green/*panel2.BackColor*/.ToArgb();//###
  833. model.position = phaseModels.Count + 1;
  834. model.name = phaseNames[j];
  835. phaseModels.Add(model);
  836. }
  837. }
  838. this.documentItems.Add(i, new DocumentItem(bitmap, graphicsList, phaseModels));
  839. }
  840. //
  841. //调色板
  842. //
  843. this.colorsForm1 = new ColorsForm();
  844. this.colorsForm1.StartPosition = FormStartPosition.CenterScreen;
  845. this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.colorsForm1Changed));
  846. this.InitParameterToControl();//###
  847. if (this.binaryExtractionModel != null)
  848. this.applyButtonImpl();
  849. this.InitBinaryControlEvent();
  850. }
  851. /// <summary>
  852. /// 构造相的工作结构
  853. /// </summary>
  854. /// <param name="phaseNames">相的命名,如果只有二值则只传(二值提取)即可,没有特殊情况命名第一个相为(二值提取)</param>
  855. /// <param name="bc"></param>
  856. /// <param name="appWorkspace"></param>
  857. /// <param name="documentWorkspace"></param>
  858. public void createDocumentItems(string[] phaseNames, CustomControl.BinaryControl bc, AppWorkspace appWorkspace
  859. , DocumentWorkspaceWindow documentWorkspace, ListView listView1)
  860. {
  861. this.bc = bc;
  862. this.appWorkspace = appWorkspace;
  863. this.documentWorkspace = documentWorkspace;
  864. this.listView1 = listView1;
  865. //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
  866. if (this.appWorkspace.ScriptRunning && this.appWorkspace.ScriptCurrentParam != null)
  867. {
  868. binaryExtractionModel = new BinaryExtractionModel();
  869. foreach (Args args in analysisAction.Lists)
  870. {
  871. Args param1 = this.appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(args.Key));
  872. if (param1 != null && param1.value != null)
  873. args.Value = param1.value;
  874. if (args.Key == "colorInterval")
  875. {
  876. this.binaryExtractionModel.ColorInterval = (Boolean)args.Value ? 2 : 1;
  877. }
  878. else if (args.Key == "scope1")
  879. {
  880. List<double> twoL = (List<double>)args.Value;
  881. this.binaryExtractionModel.ColorOneStart = (int)twoL[0];
  882. this.binaryExtractionModel.ColorOneEnd = (int)twoL[1];
  883. }
  884. else if (args.Key == "scope2")
  885. {
  886. List<double> twoL = (List<double>)args.Value;
  887. this.binaryExtractionModel.ColorTwoStart = (int)twoL[0];
  888. this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1];
  889. }
  890. else if (args.Key == "scope3")
  891. {
  892. List<double> twoL = (List<double>)args.Value;
  893. this.binaryExtractionModel.ColorThreeStart = (int)twoL[0];
  894. this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1];
  895. }
  896. else if (args.Key == "scope4")
  897. {
  898. this.binaryExtractionModel.DebrisAreaStart = (int)((List<double>)args.Value)[0];
  899. this.binaryExtractionModel.DebrisAreaEnd = (int)((List<double>)args.Value)[1];
  900. }
  901. else if (args.Key == "binaryStyle")
  902. {
  903. this.binaryExtractionModel.BinaryStyle = (int)args.Value;
  904. }
  905. else if (args.Key == "phaseColor")
  906. {
  907. this.binaryExtractionModel.PhaseColor = (int)args.Value;
  908. }
  909. else if (args.Key == "binarization")
  910. {
  911. this.binaryExtractionModel.BinaryCheckFlag = Convert.ToBoolean(args.Value) == true ? 2 : 0;
  912. }
  913. else if (args.Key == "theoriginalcolor")
  914. {
  915. bool thisValue = Convert.ToBoolean(args.Value);
  916. if (thisValue)
  917. {
  918. this.binaryExtractionModel.BinaryCheckFlag = this.binaryExtractionModel.BinaryCheckFlag == 2 ? 3 : 1;
  919. }
  920. }
  921. }
  922. //string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryConfig\\Default_" + this.menuId + ".xml";
  923. //bool createNewFile = !System.IO.File.Exists(xmlFilePath);
  924. //if (createNewFile)
  925. // xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\Default.xml";
  926. //this.binaryExtractionModel = XmlSerializeHelper.DESerializer<BinaryExtractionModel>(FileOperationHelper.ReadStringFromFile(xmlFilePath, FileMode.Open));
  927. //if (createNewFile)
  928. // this.binaryExtractionModel.BinaryCheckFlag = 0;
  929. this.initParamsToAction();
  930. }
  931. else
  932. this.initParams();
  933. for (int i = 0; i < phaseNames.Length; i++)
  934. {
  935. PhaseModel model = new PhaseModel();
  936. model.choise = true;
  937. model.mat = null;
  938. model.color = (i == 0 && bc != null) ? bc.BinaryBackColor.ToArgb() : Color.Green.ToArgb();//###
  939. model.position = documentWorkspace.PhaseModels.Count + 1;
  940. model.name = phaseNames[i];
  941. documentWorkspace.PhaseModels.Add(model);
  942. }
  943. this.documentItems = new Dictionary<int, DocumentItem>();
  944. // 构造工作结构
  945. for (int i = 0; i < appWorkspace.DocumentWorkspaces.Length; i++)
  946. {
  947. Bitmap bitmap = appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap();
  948. GraphicsList graphicsList = new GraphicsList();
  949. for (int j = 0; j < appWorkspace.DocumentWorkspaces[i].GraphicsList.Count; j++)
  950. {
  951. graphicsList.Add(appWorkspace.DocumentWorkspaces[i].GraphicsList[j]);
  952. }
  953. List<PhaseModel> phaseModels = new List<PhaseModel>();
  954. for (int j = 0; j < phaseNames.Length; j++)
  955. {
  956. //二值化相关
  957. if (j == 0)
  958. {
  959. PhaseModel analysisModel = appWorkspace.DocumentWorkspaces[i].AnalysisPhaseModel;
  960. if (analysisModel == null)
  961. {
  962. PhaseModel model = new PhaseModel();
  963. model.choise = true;
  964. model.mat = null;
  965. model.color = bc != null ? bc.BinaryBackColor.ToArgb() : Color.Green.ToArgb();
  966. model.position = phaseModels.Count + 1;
  967. model.name = phaseNames[j];
  968. phaseModels.Add(model);
  969. }
  970. else
  971. phaseModels.Add(analysisModel);
  972. }
  973. else
  974. {
  975. PhaseModel model = new PhaseModel();
  976. model.choise = true;
  977. model.mat = null;
  978. model.color = Color.Green/*panel2.BackColor*/.ToArgb();//###
  979. model.position = phaseModels.Count + 1;
  980. model.name = phaseNames[j];
  981. phaseModels.Add(model);
  982. }
  983. }
  984. this.documentItems.Add(i, new DocumentItem(bitmap, graphicsList, phaseModels));
  985. }
  986. //
  987. //调色板
  988. //
  989. this.colorsForm1 = new ColorsForm();
  990. this.colorsForm1.StartPosition = FormStartPosition.CenterScreen;
  991. this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.colorsForm1Changed));
  992. this.InitParameterToControl();//###
  993. if (this.binaryExtractionModel != null)
  994. this.applyButtonImpl();
  995. this.InitBinaryControlEvent();
  996. }
  997. /// <summary>
  998. /// 无视场执行运算
  999. /// </summary>
  1000. public OpenCvSharp.Mat PerformProcess(OpenCvSharp.Mat src) { return action.PerformProcess(src); }
  1001. /// <summary>
  1002. /// 多视场执行运算
  1003. /// </summary>
  1004. /// <param name="src">视场mat</param>
  1005. /// <param name="mat">原图mat</param>
  1006. /// <returns></returns>
  1007. public OpenCvSharp.Mat PerformProcess(OpenCvSharp.Mat src, OpenCvSharp.Mat mat) { return action.PerformProcess(src, mat); }
  1008. public int ColorInterval
  1009. {
  1010. get
  1011. {
  1012. return this.binaryExtractionModel.ColorInterval;
  1013. }
  1014. set
  1015. {
  1016. this.binaryExtractionModel.ColorInterval = value;
  1017. }
  1018. }
  1019. private void colorsForm1Changed(object sender, EventArgs e)
  1020. {
  1021. Color color = this.colorsForm1.UserPrimaryColor.ToColor();
  1022. this.SetBinaryBackColor(color);//改变参数配置的相颜色
  1023. this.colorsForm1.Close();
  1024. }
  1025. /// <summary>
  1026. /// 把参数的值设置到控件上
  1027. /// </summary>
  1028. public void InitParameterToControl()
  1029. {
  1030. if (this.binaryExtractionModel != null)
  1031. {
  1032. if (bc != null || bmc != null)
  1033. {
  1034. if (this.binaryExtractionModel.BinaryCheckFlag > 1)
  1035. {
  1036. if (bmc != null)
  1037. bmc.BinaryChecked = true;
  1038. else
  1039. bc.BinaryChecked = true;
  1040. }
  1041. if (this.binaryExtractionModel.BinaryCheckFlag % 2 == 1)
  1042. {
  1043. if (bmc != null)
  1044. bmc.OriginChecked = true;
  1045. else
  1046. bc.OriginChecked = true;
  1047. }
  1048. //阈值相关
  1049. //1个颜色区间还是2个
  1050. if (bmc != null)
  1051. bmc.setInverseStyle((this.binaryExtractionModel.ColorInterval == 1) ? 1 : 2);
  1052. else
  1053. bc.setInverseStyle((this.binaryExtractionModel.ColorInterval == 1) ? 1 : 2);
  1054. //删除事件
  1055. if (bmc != null)
  1056. bmc.DeleteEventHandler();
  1057. else
  1058. bc.DeleteEventHandler();
  1059. if (bmc != null)
  1060. bmc.scope1End = this.binaryExtractionModel.ColorOneEnd;
  1061. else
  1062. bc.scope1End = this.binaryExtractionModel.ColorOneEnd;
  1063. if (bmc != null)
  1064. bmc.scope1Start = this.binaryExtractionModel.ColorOneStart;
  1065. else
  1066. bc.scope1Start = this.binaryExtractionModel.ColorOneStart;
  1067. if (bmc != null)
  1068. bmc.scope2End = this.binaryExtractionModel.ColorTwoEnd;
  1069. else
  1070. bc.scope2End = this.binaryExtractionModel.ColorTwoEnd;
  1071. if (bmc != null)
  1072. bmc.scope2Start = this.binaryExtractionModel.ColorTwoStart;
  1073. else
  1074. bc.scope2Start = this.binaryExtractionModel.ColorTwoStart;
  1075. if (bmc != null)
  1076. bmc.scope3End = this.binaryExtractionModel.ColorThreeEnd;
  1077. else
  1078. bc.scope3End = this.binaryExtractionModel.ColorThreeEnd;
  1079. if (bmc != null)
  1080. bmc.scope3Start = this.binaryExtractionModel.ColorThreeStart;
  1081. else
  1082. bc.scope3Start = this.binaryExtractionModel.ColorThreeStart;
  1083. if (bmc != null)
  1084. bmc.BinaryStyle = this.binaryExtractionModel.BinaryStyle;
  1085. else
  1086. bc.BinaryStyle = this.binaryExtractionModel.BinaryStyle;
  1087. if (bmc != null)
  1088. bmc.BinaryBackColor = Color.FromArgb(this.binaryExtractionModel.PhaseColor);
  1089. else
  1090. bc.BinaryBackColor = Color.FromArgb(this.binaryExtractionModel.PhaseColor);
  1091. //添加事件
  1092. if (bmc != null)
  1093. bmc.AddEventHandler();
  1094. else
  1095. bc.AddEventHandler();
  1096. if (bmc != null)
  1097. bmc.InitParameterToControl();
  1098. else
  1099. bc.InitParameterToControl();
  1100. }
  1101. }
  1102. }
  1103. /// <summary>
  1104. /// 更新显示直方图的数据
  1105. /// </summary>
  1106. public void RefreshHistogramControl1Values()
  1107. {
  1108. ////显示直方图
  1109. //if (bc != null || bmc != null)
  1110. // if (bmc != null)
  1111. // bmc.CreateHistogram(bitmap, true, 339, 130, 0);
  1112. // else
  1113. // bc.CreateHistogram(bitmap, true, 339, 130, 0);
  1114. if (bmc != null)
  1115. bmc.InitParameterToControl(this.binaryExtractionModel.ColorInterval);
  1116. else
  1117. bc.InitParameterToControl(this.binaryExtractionModel.ColorInterval);
  1118. }
  1119. Vec4b vecForPhaseColor4B;
  1120. public unsafe void SetBinaryBackColor(Color color)
  1121. {
  1122. if (bmc != null)
  1123. bmc.BinaryBackColor = color;//设置panel背景
  1124. else
  1125. bc.BinaryBackColor = color;//设置panel背景
  1126. this.binaryExtractionModel.PhaseColor = color.ToArgb();
  1127. //###
  1128. foreach (Args args in action.Lists)
  1129. {
  1130. if (args.Key == "phaseColor")
  1131. {
  1132. args.Value = color.ToArgb();//this.binaryExtractionModel.PhaseColor
  1133. break;
  1134. }
  1135. }
  1136. if (this.documentWorkspace.PhaseModels[0].mat == null || this.documentWorkspace.PhaseModels[0].mat.IsDisposed)
  1137. {
  1138. this.applyButtonImpl();
  1139. }
  1140. else
  1141. {
  1142. Mat source = this.documentWorkspace.PhaseModels[0].mat;
  1143. //##20143
  1144. if (source.Channels() != 4)
  1145. {
  1146. this.applyButtonImpl();// false;、、should never go here !
  1147. return;
  1148. }
  1149. //二值提取
  1150. if (dstBinary != null)
  1151. {
  1152. dstBinary.Dispose();
  1153. dstBinary = null;
  1154. }
  1155. dstBinary = new Mat(source.Rows, source.Cols, MatType.CV_8UC4, new Scalar(0, 0, 0, 0));
  1156. //赋值二值相的颜色
  1157. vecForPhaseColor4B = new Vec4b(color.B, color.G, color.R, color.A);
  1158. source.ForEachAsVec4b(ForeachFunctionByteForPhaseColor4B);
  1159. this.documentWorkspace.PhaseModels[0].mat/*Mat dst*/ = dstBinary.Clone();
  1160. this.documentWorkspace.Refresh();
  1161. dstBinary.Dispose();
  1162. dstBinary = null;
  1163. }
  1164. //return dst;// true;
  1165. }
  1166. /// <summary>
  1167. /// 提取二值化的透明通道并赋值
  1168. /// </summary>
  1169. /// <param name="t"></param>
  1170. /// <param name="position"></param>
  1171. public unsafe void ForeachFunctionByteForPhaseColor4B(Vec4b* t, int* position)
  1172. {
  1173. if (t->Item3 > 0)
  1174. dstBinary.Set(position[0], position[1], vecForPhaseColor4B);
  1175. }
  1176. /// <summary>
  1177. /// 保证二值化颜色赋值到action
  1178. /// </summary>
  1179. public void loadParams()
  1180. {
  1181. if (bc == null && bmc == null)
  1182. return;
  1183. foreach (Args args in action.Lists)
  1184. {
  1185. switch (args.Key)
  1186. {
  1187. case "scope1"://不反选时候的范围
  1188. if (bmc != null)
  1189. bmc.ScopeValue1ChangedAction += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
  1190. else
  1191. bc.ScopeValue1ChangedAction += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
  1192. break;
  1193. case "scope2"://反选时候的范围1
  1194. if (bmc != null)
  1195. bmc.ScopeValue2ChangedAction += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
  1196. else
  1197. bc.ScopeValue2ChangedAction += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
  1198. break;
  1199. case "scope3"://反选时候的范围2
  1200. if (bmc != null)
  1201. bmc.ScopeValue3ChangedAction += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
  1202. else
  1203. bc.ScopeValue3ChangedAction += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
  1204. break;
  1205. case "phaseColor":
  1206. args.Value = this.binaryExtractionModel.PhaseColor;
  1207. break;
  1208. default:
  1209. break;
  1210. }
  1211. }
  1212. }
  1213. /// <summary>
  1214. /// 执行二值方法的事件
  1215. /// </summary>
  1216. /// <param name="sender"></param>
  1217. /// <param name="e"></param>
  1218. private void bcApplyButtonImplAction(object sender, EventArgs e)
  1219. {
  1220. this.applyButtonImpl(/*bitmap*/);
  1221. }
  1222. ///// <summary>
  1223. ///// 参数改变时,重新处理图像
  1224. ///// </summary>
  1225. /// <param name="imagesKey">不是当前显示图片的需要传值</param>
  1226. /// <param name="analysisPicture">不是当前显示图片的需要传值</param>
  1227. /// <param name="bitmap">不带视场处理的需要传值</param>
  1228. public void applyButtonImpl(string imagesKey = null, int analysisPicture = -1, Bitmap bitmap = null)
  1229. {
  1230. if (bc == null && bmc == null)
  1231. return;
  1232. //long start = Cv2.GetTickCount();
  1233. if (bitmap != null ||
  1234. (listView1.FocusedItem != null || this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0) && (bmc != null ? bmc.BinaryChecked : bc.BinaryChecked))
  1235. {
  1236. bool processWholeMat11 = (bitmap != null);
  1237. if (bitmap == null)
  1238. /*Bitmap */bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index : this.listView1.SelectedItems[0].Index].CompositionSurface.CreateAliasedBitmap();
  1239. //判断是否存在视场,如果存在视场,则把视场提取出来,进行处理//可能会带视场//########################
  1240. DocumentView documentWorkspace = this.documentWorkspace;
  1241. if (analysisPicture >= 0)
  1242. documentWorkspace = this.appWorkspace.DocumentWorkspaces[analysisPicture];
  1243. if (!processWholeMat11
  1244. && !processWholeMat && documentWorkspace.GraphicsList.IsExsitView())
  1245. {
  1246. if (analysisPicture == -1)
  1247. {
  1248. documentWorkspace.PhaseModels[0].mat = this.PerformProcess(
  1249. OpenCvSharp.Extensions.BitmapConverter.ToMat(documentWorkspace.GetFullSizeWithRegion()),
  1250. OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));
  1251. documentWorkspace.PhaseModels[0].color = (bmc != null ? bmc.BinaryBackColor.ToArgb() : bc.BinaryBackColor.ToArgb());
  1252. documentWorkspace.Refresh();
  1253. }
  1254. else
  1255. {
  1256. if (binaryData1Dict.ContainsKey(imagesKey))
  1257. {
  1258. if (binaryData1Dict[imagesKey] != null)
  1259. binaryData1Dict[imagesKey] = null;
  1260. binaryData1Dict[imagesKey] = this.PerformProcess(
  1261. OpenCvSharp.Extensions.BitmapConverter.ToMat(documentWorkspace.GetFullSizeWithRegion()),
  1262. OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));// this.documentWorkspace.phaseModels[0].mat;
  1263. }
  1264. else
  1265. {
  1266. try
  1267. {
  1268. binaryData1Dict.Add(imagesKey, this.PerformProcess(
  1269. OpenCvSharp.Extensions.BitmapConverter.ToMat(documentWorkspace.GetFullSizeWithRegion()),
  1270. OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap))/*this.documentWorkspace.phaseModels[0].mat*/);
  1271. }
  1272. catch (Exception)
  1273. {
  1274. binaryData1Dict.Add(imagesKey, null);
  1275. }
  1276. }
  1277. }
  1278. }
  1279. else if (!processWholeMat11
  1280. && processWholeMat && documentWorkspace.GraphicsList.IsExsitView())
  1281. {
  1282. if (PhaseModels0Mat != null)
  1283. {
  1284. PhaseModels0Mat.Dispose();
  1285. PhaseModels0Mat = null;
  1286. }
  1287. Mat OrgImg0 = this.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));
  1288. PhaseModels0Mat = OrgImg0.Clone();
  1289. Vec4b vec4 = new Vec4b(0, 0, 0, 0);
  1290. //视场图像
  1291. Mat exsitViewMatOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(documentWorkspace.GetFullSizeWithRegion());
  1292. for (int y = 0; y < exsitViewMatOrg/*temp*/.Rows; y++)
  1293. {
  1294. for (int x = 0; x < exsitViewMatOrg/*temp*/.Cols; x++)
  1295. {
  1296. if (exsitViewMatOrg.At<Vec4b>(y, x).Item3 == 0)
  1297. OrgImg0.Set(y, x, vec4);//不在视场图像范围内
  1298. }
  1299. }
  1300. if (analysisPicture == -1)
  1301. {
  1302. documentWorkspace.PhaseModels[0].mat = OrgImg0;
  1303. documentWorkspace.PhaseModels[0].color = (bmc != null ? bmc.BinaryBackColor.ToArgb() : bc.BinaryBackColor.ToArgb());
  1304. documentWorkspace.Refresh();
  1305. }
  1306. else
  1307. {
  1308. if (binaryData1Dict.ContainsKey(imagesKey))
  1309. {
  1310. if (binaryData1Dict[imagesKey] != null)
  1311. binaryData1Dict[imagesKey] = null;
  1312. binaryData1Dict[imagesKey] = OrgImg0;// this.documentWorkspace.phaseModels[0].mat;
  1313. }
  1314. else
  1315. {
  1316. try
  1317. {
  1318. binaryData1Dict.Add(imagesKey, OrgImg0/*this.documentWorkspace.phaseModels[0].mat*/);
  1319. }
  1320. catch (Exception)
  1321. {
  1322. binaryData1Dict.Add(imagesKey, null);
  1323. }
  1324. }
  1325. }
  1326. }
  1327. else
  1328. {
  1329. if (analysisPicture == -1)
  1330. {
  1331. documentWorkspace.PhaseModels[0].mat = this.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));
  1332. documentWorkspace.PhaseModels[0].color = (bmc != null ? bmc.BinaryBackColor.ToArgb() : bc.BinaryBackColor.ToArgb());
  1333. documentWorkspace.Refresh();
  1334. }
  1335. else
  1336. {
  1337. if (binaryData1Dict.ContainsKey(imagesKey))
  1338. {
  1339. if (binaryData1Dict[imagesKey] != null)
  1340. binaryData1Dict[imagesKey] = null;
  1341. binaryData1Dict[imagesKey] = this.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap));// this.documentWorkspace.phaseModels[0].mat;
  1342. }
  1343. else
  1344. {
  1345. try
  1346. {
  1347. binaryData1Dict.Add(imagesKey, this.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap))/*this.documentWorkspace.phaseModels[0].mat*/);
  1348. }
  1349. catch (Exception)
  1350. {
  1351. binaryData1Dict.Add(imagesKey, null);
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. ////double time = (Cv2.GetTickCount() - start) / Cv2.GetTickFrequency();
  1358. ////System.Console.WriteLine("执行时间:" + time);
  1359. ////AddRectangleToRectangleFCaps();//0916###18745
  1360. //if (analysisPicture != -1)
  1361. OnBinaryImplFinishAction();
  1362. }
  1363. /// <summary>
  1364. /// 初始化二值化相关的变量
  1365. /// </summary>
  1366. public void initParams()
  1367. {
  1368. string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryConfig\\Default_" + this.menuId + ".xml";
  1369. bool createNewFile = !System.IO.File.Exists(xmlFilePath);
  1370. if (createNewFile)
  1371. xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\Default.xml";
  1372. this.binaryExtractionModel = XmlSerializeHelper.DESerializer<BinaryExtractionModel>(FileOperationHelper.ReadStringFromFile(xmlFilePath, FileMode.Open));
  1373. if (createNewFile)
  1374. this.binaryExtractionModel.BinaryCheckFlag = 0;
  1375. this.initParamsToAction();
  1376. }
  1377. /// <summary>
  1378. /// 把参数的值设置到action
  1379. /// </summary>
  1380. public void initParamsToAction()
  1381. {
  1382. foreach (Args args in action.Lists)
  1383. {
  1384. if (args.Key == "colorInterval")
  1385. args.Value = this.binaryExtractionModel.ColorInterval;
  1386. else if (args.Key == "binaryStyle")
  1387. args.Value = this.binaryExtractionModel.BinaryStyle;
  1388. else if (args.Key == "scope1")
  1389. {
  1390. ((List<double>)args.Value)[0] = (int)(this.binaryExtractionModel.ColorOneStart);
  1391. ((List<double>)args.Value)[1] = (int)(this.binaryExtractionModel.ColorOneEnd);
  1392. }
  1393. else if (args.Key == "scope2")
  1394. {
  1395. ((List<double>)args.Value)[0] = (int)(this.binaryExtractionModel.ColorTwoStart);
  1396. ((List<double>)args.Value)[1] = (int)(this.binaryExtractionModel.ColorTwoEnd);
  1397. }
  1398. else if (args.Key == "scope3")
  1399. {
  1400. ((List<double>)args.Value)[0] = (int)(this.binaryExtractionModel.ColorThreeStart);
  1401. ((List<double>)args.Value)[1] = (int)(this.binaryExtractionModel.ColorThreeEnd);
  1402. }
  1403. else if (args.Key == "phaseColor")//#22092
  1404. {
  1405. args.Value = this.binaryExtractionModel.PhaseColor;
  1406. }
  1407. }
  1408. }
  1409. /// <summary>
  1410. /// 保存二值化相关的变量
  1411. /// </summary>
  1412. public void saveParams()
  1413. {
  1414. string xmlFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryConfig\\Default_" + this.menuId + ".xml";
  1415. string userInfoXml = XmlSerializeHelper.XmlSerialize<BinaryExtractionModel>(this.binaryExtractionModel);
  1416. FileOperationHelper.WriteStringToFile(userInfoXml, xmlFilePath, System.IO.FileMode.Create);
  1417. }
  1418. #region [脚本录制参数]
  1419. public object setScriptRecording(string key) {
  1420. object value = null;
  1421. if (key == "colorInterval")
  1422. {
  1423. value = this.binaryExtractionModel.ColorInterval == 2 ? true : false;
  1424. }
  1425. else if (key == "scope1")
  1426. {
  1427. value = new List<double>() { this.binaryExtractionModel.ColorOneStart, this.binaryExtractionModel.ColorOneEnd };
  1428. }
  1429. else if (key == "scope2")
  1430. {
  1431. value = new List<double>() { this.binaryExtractionModel.ColorTwoStart, this.binaryExtractionModel.ColorTwoEnd };
  1432. }
  1433. else if (key == "scope3")
  1434. {
  1435. value = new List<double>() { this.binaryExtractionModel.ColorThreeStart, this.binaryExtractionModel.ColorThreeEnd };
  1436. }
  1437. else if (key == "scope4")
  1438. {
  1439. value = new List<double>() { this.binaryExtractionModel.DebrisAreaStart, this.binaryExtractionModel.DebrisAreaEnd };
  1440. }
  1441. else if (key == "binaryStyle")
  1442. {
  1443. value = this.binaryExtractionModel.BinaryStyle;
  1444. }
  1445. else if (key == "phaseColor")
  1446. {
  1447. value = this.binaryExtractionModel.PhaseColor;
  1448. }
  1449. else if (key == "binarization")
  1450. {
  1451. value = this.binaryExtractionModel.BinaryCheckFlag == 2 || this.binaryExtractionModel.BinaryCheckFlag == 3 ? true : false;
  1452. }
  1453. else if (key == "theoriginalcolor")
  1454. {
  1455. value = this.binaryExtractionModel.BinaryCheckFlag == 1 || this.binaryExtractionModel.BinaryCheckFlag == 3 ? true : false;
  1456. }
  1457. return value;
  1458. }
  1459. #endregion
  1460. #region 内部类
  1461. internal class LocalListViewItem
  1462. {
  1463. public DocumentWorkspace Value { get; }
  1464. public string Display { get; }
  1465. public LocalListViewItem(DocumentWorkspace Value, string Display)
  1466. {
  1467. this.Value = Value;
  1468. this.Display = Display;
  1469. }
  1470. }
  1471. internal class DocumentItem
  1472. {
  1473. public Bitmap bitmap;
  1474. public GraphicsList graphicsList;
  1475. public List<PhaseModel> phaseModels;
  1476. public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List<PhaseModel> phaseModels)
  1477. {
  1478. this.bitmap = bitmap;
  1479. this.graphicsList = graphicsList;
  1480. this.phaseModels = phaseModels;
  1481. }
  1482. }
  1483. #endregion
  1484. }
  1485. }