GrainSizeAreaMethodDialog.cs 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402
  1. using OpenCvSharp;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.Base.SettingModel;
  4. using PaintDotNet.DedicatedAnalysis.GrainSize.GBT6394_2017;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Drawing;
  10. using System.Drawing.Drawing2D;
  11. using System.IO;
  12. using System.Windows.Forms;
  13. using Point = System.Drawing.Point;
  14. using PaintDotNet.Base.Functionodel;
  15. using PaintDotNet.Annotation.Enum;
  16. using PaintDotNet.CustomControl;
  17. using GroupBox = System.Windows.Forms.GroupBox;
  18. using CheckBox = System.Windows.Forms.CheckBox;
  19. using Button = System.Windows.Forms.Button;
  20. using Label = System.Windows.Forms.Label;
  21. using TextBox = System.Windows.Forms.TextBox;
  22. using System.Data;
  23. using PaintDotNet.DbOpreate.DbModel;
  24. using PaintDotNet.Annotation;
  25. namespace PaintDotNet.DedicatedAnalysis.GrainSize
  26. {
  27. internal class GrainSizeAreaMethodDialog : PdnBaseForm
  28. {
  29. /// <summary>
  30. /// 晶粒度(面积法)
  31. /// </summary>
  32. #region 控件
  33. private GroupBox groupBox1;
  34. private Button button2;
  35. private CheckBox checkBox2_0;
  36. private GroupBox groupBox2;
  37. private ListView listView1;
  38. private Button button9;
  39. private GroupBox groupBox8;
  40. private NumericUpDown numericUpDown1_0;
  41. private Button button16;
  42. private Label label5;
  43. private Button button14;
  44. private Button button13;
  45. private DataGridView dataGridView4;
  46. private Button button12;
  47. private Button button11;
  48. private Label label4;
  49. private Label label3;
  50. private GroupBox groupBox7;
  51. private GroupBox groupBox3;
  52. private GroupBox groupBox11;
  53. private ComboBox comboBox1;
  54. private CheckBox checkBox5_0;
  55. private CheckBox checkBox4_0;
  56. private CheckBox checkBox3_0;
  57. private ImageList imageList1;
  58. private IContainer components;
  59. private Button button1;
  60. #endregion
  61. /// <summary>
  62. /// 主控件
  63. /// </summary>
  64. private AppWorkspace appWorkspace;
  65. /// <summary>
  66. /// 0,GBT6394; ; 2,GBT24177; 3,E112; 4,ISO643
  67. /// </summary>
  68. int gbtType;
  69. /// <summary>
  70. /// 用于编号的坐标点集合
  71. /// </summary>
  72. List<Point2d> massLabelPoints = new List<Point2d>();
  73. /// <summary>
  74. /// 矩形内的连通域
  75. /// </summary>
  76. int within = 0;
  77. //分析结果列表的头标题
  78. /// <summary>
  79. /// PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), "网格面积", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.averageintercept.text"), PdnResources.GetString("Menu.Averagegrainsizegrade.text")
  80. /// </summary>
  81. List<string> contentHead;
  82. /// <summary>
  83. /// 保存用于生成报告的图片
  84. /// </summary>
  85. private List<Bitmap> bitList;
  86. /// <summary>
  87. /// 储存点击保存结果后的所有原图与分析图
  88. /// </summary>
  89. private Dictionary<string, List<Bitmap>> bitDic = new Dictionary<string, List<Bitmap>>();
  90. /// <summary>
  91. /// 中间数据
  92. /// </summary>
  93. private List<ExportProjectModel> tempDataModel = new List<ExportProjectModel>();
  94. //二值化集成1
  95. BinaryClass binaryClass;
  96. /// <summary>
  97. /// 调色板
  98. /// </summary>
  99. private ColorsForm colorsFormGrid;
  100. /// <summary>
  101. /// 选中图片的bitmap
  102. /// </summary>
  103. private Bitmap bitmap;
  104. private DocumentWorkspaceWindow documentWorkspace;
  105. /// <summary>
  106. /// 公共按钮
  107. /// </summary>
  108. private CommonControlButtons commonControlButtons;
  109. //辅助线集成
  110. GrainSizeGuideClass guideClass = new GrainSizeGuideClass();
  111. /// <summary>
  112. /// 是否选择了图片
  113. /// </summary>
  114. private int selectPicture = -1;
  115. /// <summary>
  116. /// 存在视场标记
  117. /// </summary>
  118. private bool existViewFlag = false;
  119. /// <summary>
  120. /// 当前选择的图片
  121. /// </summary>
  122. private Mat mat;
  123. /// <summary>
  124. /// 分析结果暂存
  125. /// </summary>
  126. private List<DataTable> dataTables = new List<DataTable>();
  127. /// <summary>
  128. /// 全部显示
  129. /// </summary>
  130. private bool allShow = false;
  131. /// <summary>
  132. /// 图形位置
  133. /// </summary>
  134. private PointF loctation;
  135. /// <summary>
  136. /// 图形上所有的点
  137. /// </summary>
  138. private List<PointF> linePointList = new List<PointF>();
  139. private string oldSelectItem;
  140. private PointF m_StartPoint = Point.Empty;
  141. private bool m_canMove;
  142. private DataGridViewTextBoxColumn Column1;
  143. private DataGridViewTextBoxColumn Column2;
  144. private DataGridViewTextBoxColumn Column3;
  145. private DataGridViewTextBoxColumn Column4;
  146. private DataGridViewTextBoxColumn Column5;
  147. private DataGridViewTextBoxColumn Column6;
  148. private ListView listView2;
  149. private CheckBox checkBox11;
  150. private GroupBox groupBox4;
  151. private Label label8;
  152. private NumericUpDown numericUpDown2;
  153. private NumericUpDown numericUpDown1;
  154. private CheckBox checkBox2;
  155. private TextBox textBox6;
  156. private Label label7;
  157. private ComboBox comboBox3;
  158. private Label label6;
  159. private ComboBox comboBox2;
  160. private Label label1;
  161. private CheckBox checkBox1;
  162. private Panel panel1;
  163. private Button button3;
  164. private Button button4;
  165. private Button button8;
  166. private BinaryControlSmaller bc;
  167. public bool comboboxChange = true;
  168. /// <summary>
  169. ///
  170. /// </summary>
  171. /// <param name="appWorkspace"></param>
  172. /// <param name="gbtType">0,GBT6394; ; 2,GBT24177; 3,E112; 4,ISO643;5,YST347(XX)</param>
  173. public GrainSizeAreaMethodDialog(AppWorkspace appWorkspace, int gbtType)
  174. {
  175. InitializeComponent();
  176. this.contentHead = new List<string>() { PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), PdnResources.GetString("Menu.Gridarea.text") + "(μm²)", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.averageintercept.text") + "(μm)", PdnResources.GetString("Menu.Averagegrainsizegrade.text") };
  177. this.binaryClass = new BinaryClass();
  178. InitializeCustomControl();
  179. InitializeLanguageText();
  180. this.appWorkspace = appWorkspace;
  181. this.gbtType = gbtType;
  182. string dialogName = "GBT6394_2017";
  183. switch (this.gbtType)
  184. {
  185. case 2:
  186. dialogName = "GBT24177_2009";
  187. break;
  188. case 3:
  189. dialogName = "ASTM_E112_2013";
  190. break;
  191. case 4:
  192. dialogName = "ISO643";
  193. break;
  194. default:
  195. break;
  196. }
  197. this.Text = dialogName + "("+ PdnResources.GetString("Menu.Areamethod.text")+ ")";
  198. this.button11.Visible = true;
  199. this.button16.Visible = false;
  200. //
  201. //二值化相关
  202. //
  203. this.colorsFormGrid = new ColorsForm();
  204. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  205. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  206. //二值化end
  207. //
  208. //初始化图像控件
  209. //
  210. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  211. this.documentWorkspace.Dock = DockStyle.Fill;
  212. this.documentWorkspace.HookMouseEvents();
  213. this.documentWorkspace.AuxiliaryLineEnabled = false;
  214. this.documentWorkspace.Visible = false;
  215. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  216. this.documentWorkspace.panel.Paint += Panel_Paint;
  217. this.documentWorkspace.panel.MouseMove += onMouseMove;
  218. this.documentWorkspace.panel.MouseUp += onMouseUp;
  219. this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);
  220. this.groupBox7.Controls.Add(documentWorkspace);
  221. //
  222. //初始化操作按钮
  223. //
  224. this.commonControlButtons = new CommonControlButtons();
  225. this.commonControlButtons.Dock = DockStyle.Top;
  226. this.commonControlButtons.Height = 30;
  227. this.commonControlButtons.HideZoomToWindowAndActualSize();
  228. this.groupBox7.Controls.Add(commonControlButtons);
  229. //二值化集成2
  230. bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
  231. binaryClass.createDocumentItemsSmaller(new string[] { PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"), PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text") }
  232. , this.bc, this.appWorkspace, this.documentWorkspace, this.listView1);//初始化相的工作结构
  233. binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件
  234. //初始化头
  235. this.listView2.View = View.Details;
  236. ColumnHeader header0 = new ColumnHeader();
  237. header0.Text = "";
  238. header0.Width = 180;
  239. this.listView2.Columns.Add(header0);
  240. InitPicList();
  241. InitComboboxValue(null);
  242. InitCommonButtonEvent();
  243. string templateName = "Template.Manager.item3.GrainSizeArea6394Method";
  244. switch (this.gbtType)
  245. {
  246. case 2:
  247. templateName = "Template.Manager.item3.GrainSizeArea24177Method";
  248. break;
  249. case 3:
  250. templateName = "Template.Manager.item3.GrainSizeArea112Method";
  251. break;
  252. case 4:
  253. templateName = "Template.Manager.item3.GrainSizeArea643Method";
  254. break;
  255. default:
  256. break;
  257. }
  258. SetAnalyzeModelFromXml(templateName);
  259. }
  260. private void InitCommonButtonEvent()
  261. {
  262. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  263. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  264. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  265. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  266. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  267. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  268. }
  269. private void zoomInButton_Click(object sender, EventArgs e)
  270. {
  271. this.documentWorkspace.ZoomIn();
  272. }
  273. private void zoomOutButton_Click(object sender, EventArgs e)
  274. {
  275. this.documentWorkspace.ZoomOut();
  276. }
  277. private void zoomToWindowButton_Click(object sender, EventArgs e)
  278. {
  279. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  280. }
  281. private void actualSizeButton_Click(object sender, EventArgs e)
  282. {
  283. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  284. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  285. }
  286. private void pointerButton_Click(object sender, EventArgs e)
  287. {
  288. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  289. }
  290. private void mobileModeButton_Click(object sender, EventArgs e)
  291. {
  292. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  293. }
  294. /// <summary>
  295. /// 初始化图片列表数据
  296. /// </summary>
  297. public void InitPicList()
  298. {
  299. //初始化图片列表
  300. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  301. {
  302. this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
  303. this.listView1.Items.Add("", i);
  304. this.listView1.Items[i].ImageIndex = i;
  305. this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  306. this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  307. }
  308. }
  309. #region 初始化
  310. private void InitializeLanguageText()
  311. {
  312. this.checkBox1.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
  313. this.label1.Text = PdnResources.GetString("Menu.Grainboundarytype.text") + ":";
  314. this.label6.Text = PdnResources.GetString("Menu.Denoisingtype.text") + ":";
  315. this.label7.Text = PdnResources.GetString("Menu.Image.Sigma.Text")+":";
  316. this.checkBox2.Text = PdnResources.GetString("Menu.Grainboundaryenhancement.text");
  317. this.label8.Text = PdnResources.GetString("Menu.Grainboundarysize.text") + ":";
  318. this.button3.Text = PdnResources.GetString("Menu.Grainboundaryedit.text");
  319. this.groupBox4.Text = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
  320. this.checkBox3_0.Text = PdnResources.GetString("Menu.displaygrainboundaries.text");
  321. this.checkBox4_0.Text = PdnResources.GetString("Menu.displaygrid.text");
  322. this.checkBox5_0.Text = PdnResources.GetString("Menu.Displaygrainnumber.text");
  323. this.checkBox11.Text = PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text");
  324. this.button4.Text = PdnResources.GetString("Menu.Refresh.text");
  325. this.groupBox11.Text = PdnResources.GetString("Menu.Displayparamssettings.text");
  326. this.groupBox3.Text = PdnResources.GetString("Menu.Tools.GridLine.Text");
  327. this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
  328. this.button11.Text = PdnResources.GetString("Menu.Showall.text");
  329. this.button12.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  330. this.Column6.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");
  331. this.Column5.HeaderText = PdnResources.GetString("Menu.averageintercept.text") + "(μm)";
  332. this.Column4.HeaderText = PdnResources.GetString("Menu.Numberofgrains.text");
  333. this.Column2.HeaderText = PdnResources.GetString("Menu.Tools.GridLine.Text");
  334. this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
  335. this.button13.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text");
  336. this.button14.Text = PdnResources.GetString("Menu.Exportresults.text");
  337. this.label5.Text = PdnResources.GetString("Menu.Decimal.text") + ":";
  338. this.button16.Text = PdnResources.GetString("Menu.Cancelshowall.text");
  339. this.button8.Text = PdnResources.GetString("Menu.Exportproject.text");
  340. this.groupBox8.Text = PdnResources.GetString("Menu.Analysisresult.text");
  341. this.button9.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text");
  342. this.groupBox2.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  343. this.button1.Text = PdnResources.GetString("Menu.Setting.Text");
  344. this.checkBox2_0.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text");
  345. this.button2.Text = PdnResources.GetString("Menu.Saveresult.text");
  346. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  347. this.Column3.HeaderText = PdnResources.GetString("Menu.Gridarea.text") + "(μm²)";
  348. this.comboBox3.Items.AddRange(new object[] {
  349. PdnResources.GetString("Menu.Gaussiansmoothing.text"),
  350. PdnResources.GetString("Menu.directionalsmoothing.text")});
  351. this.comboBox2.Items.AddRange(new object[] {
  352. PdnResources.GetString("Menu.Brightgrainboundary.text"),
  353. PdnResources.GetString("Menu.Darkgrainboundary.text"),
  354. PdnResources.GetString("Menu.gradient.text")});
  355. }
  356. private void InitializeCustomControl()
  357. {
  358. //
  359. // bc
  360. //
  361. this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
  362. this.bc.BinaryBackColor = System.Drawing.Color.Red;
  363. this.bc.BinaryChecked = false;
  364. this.bc.BinaryStyle = 1;
  365. this.bc.Location = new System.Drawing.Point(149, 57);
  366. this.bc.Name = "bc";
  367. this.bc.OriginChecked = false;
  368. this.bc.scope1End = 0D;
  369. this.bc.scope1Start = 0D;
  370. this.bc.scope2End = 0D;
  371. this.bc.scope2Start = 0D;
  372. this.bc.scope3End = 0D;
  373. this.bc.scope3Start = 0D;
  374. this.bc.Size = new System.Drawing.Size(360, 247);
  375. this.bc.TabIndex = 26;
  376. this.Controls.Add(this.bc);
  377. this.Controls.SetChildIndex(this.bc, 0);
  378. }
  379. private void InitializeComponent()
  380. {
  381. this.components = new System.ComponentModel.Container();
  382. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  383. this.groupBox1 = new System.Windows.Forms.GroupBox();
  384. this.button2 = new System.Windows.Forms.Button();
  385. this.checkBox2_0 = new System.Windows.Forms.CheckBox();
  386. this.button1 = new System.Windows.Forms.Button();
  387. this.groupBox2 = new System.Windows.Forms.GroupBox();
  388. this.listView1 = new System.Windows.Forms.ListView();
  389. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  390. this.button9 = new System.Windows.Forms.Button();
  391. this.groupBox8 = new System.Windows.Forms.GroupBox();
  392. this.button8 = new System.Windows.Forms.Button();
  393. this.listView2 = new System.Windows.Forms.ListView();
  394. this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown();
  395. this.button16 = new System.Windows.Forms.Button();
  396. this.label5 = new System.Windows.Forms.Label();
  397. this.button14 = new System.Windows.Forms.Button();
  398. this.button13 = new System.Windows.Forms.Button();
  399. this.dataGridView4 = new System.Windows.Forms.DataGridView();
  400. this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  401. this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  402. this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  403. this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  404. this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  405. this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  406. this.button12 = new System.Windows.Forms.Button();
  407. this.button11 = new System.Windows.Forms.Button();
  408. this.label4 = new System.Windows.Forms.Label();
  409. this.label3 = new System.Windows.Forms.Label();
  410. this.groupBox7 = new System.Windows.Forms.GroupBox();
  411. this.groupBox3 = new System.Windows.Forms.GroupBox();
  412. this.comboBox1 = new System.Windows.Forms.ComboBox();
  413. this.groupBox11 = new System.Windows.Forms.GroupBox();
  414. this.button4 = new System.Windows.Forms.Button();
  415. this.checkBox11 = new System.Windows.Forms.CheckBox();
  416. this.checkBox5_0 = new System.Windows.Forms.CheckBox();
  417. this.checkBox4_0 = new System.Windows.Forms.CheckBox();
  418. this.checkBox3_0 = new System.Windows.Forms.CheckBox();
  419. this.panel1 = new System.Windows.Forms.Panel();
  420. this.groupBox4 = new System.Windows.Forms.GroupBox();
  421. this.button3 = new System.Windows.Forms.Button();
  422. this.label8 = new System.Windows.Forms.Label();
  423. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  424. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  425. this.checkBox2 = new System.Windows.Forms.CheckBox();
  426. this.textBox6 = new System.Windows.Forms.TextBox();
  427. this.label7 = new System.Windows.Forms.Label();
  428. this.comboBox3 = new System.Windows.Forms.ComboBox();
  429. this.label6 = new System.Windows.Forms.Label();
  430. this.comboBox2 = new System.Windows.Forms.ComboBox();
  431. this.label1 = new System.Windows.Forms.Label();
  432. this.checkBox1 = new System.Windows.Forms.CheckBox();
  433. this.groupBox1.SuspendLayout();
  434. this.groupBox2.SuspendLayout();
  435. this.groupBox8.SuspendLayout();
  436. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
  437. ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).BeginInit();
  438. this.groupBox3.SuspendLayout();
  439. this.groupBox11.SuspendLayout();
  440. this.groupBox4.SuspendLayout();
  441. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  442. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  443. this.SuspendLayout();
  444. //
  445. // groupBox1
  446. //
  447. this.groupBox1.Controls.Add(this.button2);
  448. this.groupBox1.Controls.Add(this.checkBox2_0);
  449. this.groupBox1.Controls.Add(this.button1);
  450. this.groupBox1.Location = new System.Drawing.Point(14, 3);
  451. this.groupBox1.Name = "groupBox1";
  452. this.groupBox1.Size = new System.Drawing.Size(1081, 50);
  453. this.groupBox1.TabIndex = 2;
  454. this.groupBox1.TabStop = false;
  455. //
  456. // button2
  457. //
  458. this.button2.BackColor = System.Drawing.SystemColors.Control;
  459. this.button2.Location = new System.Drawing.Point(985, 14);
  460. this.button2.Name = "button2";
  461. this.button2.Size = new System.Drawing.Size(84, 30);
  462. this.button2.TabIndex = 3;
  463. this.button2.UseVisualStyleBackColor = false;
  464. this.button2.Click += new System.EventHandler(this.button2_Click);
  465. //
  466. // checkBox2_0
  467. //
  468. this.checkBox2_0.AutoSize = true;
  469. this.checkBox2_0.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
  470. this.checkBox2_0.Location = new System.Drawing.Point(138, 22);
  471. this.checkBox2_0.Name = "checkBox2_0";
  472. this.checkBox2_0.Size = new System.Drawing.Size(132, 16);
  473. this.checkBox2_0.TabIndex = 2;
  474. this.checkBox2_0.UseVisualStyleBackColor = true;
  475. //
  476. // button1
  477. //
  478. this.button1.BackColor = System.Drawing.SystemColors.Control;
  479. this.button1.Location = new System.Drawing.Point(15, 14);
  480. this.button1.Name = "button1";
  481. this.button1.Size = new System.Drawing.Size(84, 30);
  482. this.button1.TabIndex = 0;
  483. this.button1.UseVisualStyleBackColor = false;
  484. this.button1.Click += new System.EventHandler(this.button1_Click);
  485. //
  486. // groupBox2
  487. //
  488. this.groupBox2.Controls.Add(this.listView1);
  489. this.groupBox2.Location = new System.Drawing.Point(14, 59);
  490. this.groupBox2.Name = "groupBox2";
  491. this.groupBox2.Size = new System.Drawing.Size(135, 561);
  492. this.groupBox2.TabIndex = 3;
  493. this.groupBox2.TabStop = false;
  494. //
  495. // listView1
  496. //
  497. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  498. | System.Windows.Forms.AnchorStyles.Left)
  499. | System.Windows.Forms.AnchorStyles.Right)));
  500. this.listView1.HideSelection = false;
  501. this.listView1.LargeImageList = this.imageList1;
  502. this.listView1.Location = new System.Drawing.Point(5, 17);
  503. this.listView1.MultiSelect = false;
  504. this.listView1.Name = "listView1";
  505. this.listView1.Size = new System.Drawing.Size(124, 538);
  506. this.listView1.TabIndex = 0;
  507. this.listView1.UseCompatibleStateImageBehavior = false;
  508. this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
  509. //
  510. // imageList1
  511. //
  512. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  513. this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
  514. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  515. //
  516. // button9
  517. //
  518. this.button9.BackColor = System.Drawing.SystemColors.Control;
  519. this.button9.Location = new System.Drawing.Point(241, 19);
  520. this.button9.Name = "button9";
  521. this.button9.Size = new System.Drawing.Size(92, 26);
  522. this.button9.TabIndex = 10;
  523. this.button9.UseVisualStyleBackColor = false;
  524. this.button9.Click += new System.EventHandler(this.button9_Click);
  525. //
  526. // groupBox8
  527. //
  528. this.groupBox8.Controls.Add(this.button8);
  529. this.groupBox8.Controls.Add(this.listView2);
  530. this.groupBox8.Controls.Add(this.numericUpDown1_0);
  531. this.groupBox8.Controls.Add(this.button16);
  532. this.groupBox8.Controls.Add(this.label5);
  533. this.groupBox8.Controls.Add(this.button14);
  534. this.groupBox8.Controls.Add(this.button13);
  535. this.groupBox8.Controls.Add(this.dataGridView4);
  536. this.groupBox8.Controls.Add(this.button12);
  537. this.groupBox8.Controls.Add(this.button11);
  538. this.groupBox8.Controls.Add(this.label4);
  539. this.groupBox8.Controls.Add(this.label3);
  540. this.groupBox8.Location = new System.Drawing.Point(14, 626);
  541. this.groupBox8.Name = "groupBox8";
  542. this.groupBox8.Size = new System.Drawing.Size(1081, 204);
  543. this.groupBox8.TabIndex = 10;
  544. this.groupBox8.TabStop = false;
  545. //
  546. // button8
  547. //
  548. this.button8.BackColor = System.Drawing.SystemColors.Control;
  549. this.button8.Location = new System.Drawing.Point(941, 109);
  550. this.button8.Name = "button8";
  551. this.button8.Size = new System.Drawing.Size(128, 26);
  552. this.button8.TabIndex = 25;
  553. this.button8.UseVisualStyleBackColor = false;
  554. this.button8.Click += new System.EventHandler(this.button8_Click);
  555. //
  556. // listView2
  557. //
  558. this.listView2.FullRowSelect = true;
  559. this.listView2.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
  560. this.listView2.HideSelection = false;
  561. this.listView2.Location = new System.Drawing.Point(15, 56);
  562. this.listView2.Name = "listView2";
  563. this.listView2.Size = new System.Drawing.Size(181, 140);
  564. this.listView2.TabIndex = 24;
  565. this.listView2.UseCompatibleStateImageBehavior = false;
  566. this.listView2.SelectedIndexChanged += new System.EventHandler(this.listView2_SelectedIndexChanged);
  567. //
  568. // numericUpDown1_0
  569. //
  570. this.numericUpDown1_0.Location = new System.Drawing.Point(997, 163);
  571. this.numericUpDown1_0.Maximum = new decimal(new int[] {
  572. 10,
  573. 0,
  574. 0,
  575. 0});
  576. this.numericUpDown1_0.Name = "numericUpDown1_0";
  577. this.numericUpDown1_0.Size = new System.Drawing.Size(56, 21);
  578. this.numericUpDown1_0.TabIndex = 21;
  579. this.numericUpDown1_0.Value = new decimal(new int[] {
  580. 2,
  581. 0,
  582. 0,
  583. 0});
  584. this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged);
  585. //
  586. // button16
  587. //
  588. this.button16.BackColor = System.Drawing.SystemColors.Control;
  589. this.button16.Location = new System.Drawing.Point(15, 20);
  590. this.button16.Name = "button16";
  591. this.button16.Size = new System.Drawing.Size(93, 26);
  592. this.button16.TabIndex = 20;
  593. this.button16.UseVisualStyleBackColor = false;
  594. this.button16.Click += new System.EventHandler(this.button16_Click);
  595. //
  596. // label5
  597. //
  598. this.label5.AutoSize = true;
  599. this.label5.Location = new System.Drawing.Point(955, 169);
  600. this.label5.Name = "label5";
  601. this.label5.Size = new System.Drawing.Size(41, 12);
  602. this.label5.TabIndex = 18;
  603. //
  604. // button14
  605. //
  606. this.button14.BackColor = System.Drawing.SystemColors.Control;
  607. this.button14.Location = new System.Drawing.Point(941, 71);
  608. this.button14.Name = "button14";
  609. this.button14.Size = new System.Drawing.Size(128, 26);
  610. this.button14.TabIndex = 16;
  611. this.button14.UseVisualStyleBackColor = false;
  612. this.button14.Click += new System.EventHandler(this.button14_Click);
  613. //
  614. // button13
  615. //
  616. this.button13.BackColor = System.Drawing.SystemColors.Control;
  617. this.button13.Location = new System.Drawing.Point(941, 34);
  618. this.button13.Name = "button13";
  619. this.button13.Size = new System.Drawing.Size(128, 26);
  620. this.button13.TabIndex = 12;
  621. this.button13.UseVisualStyleBackColor = false;
  622. this.button13.Click += new System.EventHandler(this.button13_Click);
  623. //
  624. // dataGridView4
  625. //
  626. this.dataGridView4.AllowUserToAddRows = false;
  627. this.dataGridView4.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  628. this.dataGridView4.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
  629. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  630. dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
  631. dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F);
  632. dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
  633. dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  634. dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  635. dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  636. this.dataGridView4.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
  637. this.dataGridView4.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  638. this.dataGridView4.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  639. this.Column1,
  640. this.Column2,
  641. this.Column3,
  642. this.Column4,
  643. this.Column5,
  644. this.Column6});
  645. this.dataGridView4.Location = new System.Drawing.Point(228, 20);
  646. this.dataGridView4.Name = "dataGridView4";
  647. this.dataGridView4.ReadOnly = true;
  648. this.dataGridView4.RowHeadersVisible = false;
  649. this.dataGridView4.RowTemplate.Height = 23;
  650. this.dataGridView4.Size = new System.Drawing.Size(693, 176);
  651. this.dataGridView4.TabIndex = 15;
  652. //
  653. // Column1
  654. //
  655. this.Column1.Name = "Column1";
  656. this.Column1.ReadOnly = true;
  657. //
  658. // Column2
  659. //
  660. this.Column2.Name = "Column2";
  661. this.Column2.ReadOnly = true;
  662. //
  663. // Column3
  664. //
  665. this.Column3.Name = "Column3";
  666. this.Column3.ReadOnly = true;
  667. //
  668. // Column4
  669. //
  670. this.Column4.Name = "Column4";
  671. this.Column4.ReadOnly = true;
  672. //
  673. // Column5
  674. //
  675. this.Column5.Name = "Column5";
  676. this.Column5.ReadOnly = true;
  677. //
  678. // Column6
  679. //
  680. this.Column6.Name = "Column6";
  681. this.Column6.ReadOnly = true;
  682. //
  683. // button12
  684. //
  685. this.button12.BackColor = System.Drawing.SystemColors.Control;
  686. this.button12.Location = new System.Drawing.Point(145, 20);
  687. this.button12.Name = "button12";
  688. this.button12.Size = new System.Drawing.Size(52, 26);
  689. this.button12.TabIndex = 13;
  690. this.button12.UseVisualStyleBackColor = false;
  691. this.button12.Click += new System.EventHandler(this.button12_Click);
  692. //
  693. // button11
  694. //
  695. this.button11.BackColor = System.Drawing.SystemColors.Control;
  696. this.button11.Location = new System.Drawing.Point(15, 20);
  697. this.button11.Name = "button11";
  698. this.button11.Size = new System.Drawing.Size(63, 26);
  699. this.button11.TabIndex = 12;
  700. this.button11.UseVisualStyleBackColor = false;
  701. this.button11.Click += new System.EventHandler(this.button11_Click);
  702. //
  703. // label4
  704. //
  705. this.label4.AutoSize = true;
  706. this.label4.ForeColor = System.Drawing.SystemColors.ScrollBar;
  707. this.label4.Location = new System.Drawing.Point(924, 9);
  708. this.label4.Name = "label4";
  709. this.label4.Size = new System.Drawing.Size(11, 192);
  710. this.label4.TabIndex = 1;
  711. this.label4.Text = "|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|";
  712. //
  713. // label3
  714. //
  715. this.label3.AutoSize = true;
  716. this.label3.ForeColor = System.Drawing.SystemColors.ScrollBar;
  717. this.label3.Location = new System.Drawing.Point(214, 9);
  718. this.label3.Name = "label3";
  719. this.label3.Size = new System.Drawing.Size(11, 192);
  720. this.label3.TabIndex = 0;
  721. this.label3.Text = "|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|";
  722. //
  723. // groupBox7
  724. //
  725. this.groupBox7.Location = new System.Drawing.Point(515, 59);
  726. this.groupBox7.Name = "groupBox7";
  727. this.groupBox7.Size = new System.Drawing.Size(580, 561);
  728. this.groupBox7.TabIndex = 11;
  729. this.groupBox7.TabStop = false;
  730. //
  731. // groupBox3
  732. //
  733. this.groupBox3.Controls.Add(this.button9);
  734. this.groupBox3.Controls.Add(this.comboBox1);
  735. this.groupBox3.Location = new System.Drawing.Point(153, 474);
  736. this.groupBox3.Name = "groupBox3";
  737. this.groupBox3.Size = new System.Drawing.Size(355, 58);
  738. this.groupBox3.TabIndex = 12;
  739. this.groupBox3.TabStop = false;
  740. //
  741. // comboBox1
  742. //
  743. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  744. this.comboBox1.FormattingEnabled = true;
  745. this.comboBox1.Location = new System.Drawing.Point(15, 22);
  746. this.comboBox1.Name = "comboBox1";
  747. this.comboBox1.Size = new System.Drawing.Size(220, 20);
  748. this.comboBox1.TabIndex = 0;
  749. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  750. //
  751. // groupBox11
  752. //
  753. this.groupBox11.Controls.Add(this.button4);
  754. this.groupBox11.Controls.Add(this.checkBox11);
  755. this.groupBox11.Controls.Add(this.checkBox5_0);
  756. this.groupBox11.Controls.Add(this.checkBox4_0);
  757. this.groupBox11.Controls.Add(this.checkBox3_0);
  758. this.groupBox11.Location = new System.Drawing.Point(152, 538);
  759. this.groupBox11.Name = "groupBox11";
  760. this.groupBox11.Size = new System.Drawing.Size(356, 82);
  761. this.groupBox11.TabIndex = 17;
  762. this.groupBox11.TabStop = false;
  763. //
  764. // button4
  765. //
  766. this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right;
  767. this.button4.Location = new System.Drawing.Point(259, 23);
  768. this.button4.Name = "button4";
  769. this.button4.Size = new System.Drawing.Size(75, 23);
  770. this.button4.TabIndex = 18;
  771. this.button4.UseVisualStyleBackColor = true;
  772. this.button4.Click += new System.EventHandler(this.button4_Click);
  773. //
  774. // checkBox11
  775. //
  776. this.checkBox11.AutoSize = true;
  777. this.checkBox11.Checked = true;
  778. this.checkBox11.CheckState = System.Windows.Forms.CheckState.Checked;
  779. this.checkBox11.Location = new System.Drawing.Point(139, 49);
  780. this.checkBox11.Name = "checkBox11";
  781. this.checkBox11.Size = new System.Drawing.Size(132, 16);
  782. this.checkBox11.TabIndex = 3;
  783. this.checkBox11.UseVisualStyleBackColor = true;
  784. this.checkBox11.CheckedChanged += new System.EventHandler(this.checkBox11_CheckedChanged);
  785. //
  786. // checkBox5_0
  787. //
  788. this.checkBox5_0.AutoSize = true;
  789. this.checkBox5_0.Checked = true;
  790. this.checkBox5_0.CheckState = System.Windows.Forms.CheckState.Checked;
  791. this.checkBox5_0.Location = new System.Drawing.Point(140, 27);
  792. this.checkBox5_0.Name = "checkBox5_0";
  793. this.checkBox5_0.Size = new System.Drawing.Size(96, 16);
  794. this.checkBox5_0.TabIndex = 2;
  795. this.checkBox5_0.UseVisualStyleBackColor = true;
  796. this.checkBox5_0.CheckedChanged += new System.EventHandler(this.checkBox5_0_CheckedChanged);
  797. //
  798. // checkBox4_0
  799. //
  800. this.checkBox4_0.AutoSize = true;
  801. this.checkBox4_0.Checked = true;
  802. this.checkBox4_0.CheckState = System.Windows.Forms.CheckState.Checked;
  803. this.checkBox4_0.Location = new System.Drawing.Point(15, 49);
  804. this.checkBox4_0.Name = "checkBox4_0";
  805. this.checkBox4_0.Size = new System.Drawing.Size(72, 16);
  806. this.checkBox4_0.TabIndex = 1;
  807. this.checkBox4_0.UseVisualStyleBackColor = true;
  808. this.checkBox4_0.CheckedChanged += new System.EventHandler(this.checkBox4_0_CheckedChanged);
  809. //
  810. // checkBox3_0
  811. //
  812. this.checkBox3_0.AutoSize = true;
  813. this.checkBox3_0.Checked = true;
  814. this.checkBox3_0.CheckState = System.Windows.Forms.CheckState.Checked;
  815. this.checkBox3_0.Location = new System.Drawing.Point(15, 27);
  816. this.checkBox3_0.Name = "checkBox3_0";
  817. this.checkBox3_0.Size = new System.Drawing.Size(72, 16);
  818. this.checkBox3_0.TabIndex = 0;
  819. this.checkBox3_0.UseVisualStyleBackColor = true;
  820. this.checkBox3_0.CheckedChanged += new System.EventHandler(this.checkBox3_0_CheckedChanged);
  821. //
  822. // panel1
  823. //
  824. this.panel1.BackColor = System.Drawing.Color.Red;
  825. this.panel1.Location = new System.Drawing.Point(89, 16);
  826. this.panel1.Name = "panel1";
  827. this.panel1.Size = new System.Drawing.Size(72, 21);
  828. this.panel1.TabIndex = 20;
  829. this.panel1.Click += new System.EventHandler(this.panel1_Click);
  830. //
  831. // groupBox4
  832. //
  833. this.groupBox4.Controls.Add(this.panel1);
  834. this.groupBox4.Controls.Add(this.button3);
  835. this.groupBox4.Controls.Add(this.label8);
  836. this.groupBox4.Controls.Add(this.numericUpDown2);
  837. this.groupBox4.Controls.Add(this.numericUpDown1);
  838. this.groupBox4.Controls.Add(this.checkBox2);
  839. this.groupBox4.Controls.Add(this.textBox6);
  840. this.groupBox4.Controls.Add(this.label7);
  841. this.groupBox4.Controls.Add(this.comboBox3);
  842. this.groupBox4.Controls.Add(this.label6);
  843. this.groupBox4.Controls.Add(this.comboBox2);
  844. this.groupBox4.Controls.Add(this.label1);
  845. this.groupBox4.Controls.Add(this.checkBox1);
  846. this.groupBox4.Location = new System.Drawing.Point(153, 310);
  847. this.groupBox4.Name = "groupBox4";
  848. this.groupBox4.Size = new System.Drawing.Size(356, 158);
  849. this.groupBox4.TabIndex = 25;
  850. this.groupBox4.TabStop = false;
  851. //
  852. // button3
  853. //
  854. this.button3.Anchor = System.Windows.Forms.AnchorStyles.Right;
  855. this.button3.Location = new System.Drawing.Point(259, 16);
  856. this.button3.Name = "button3";
  857. this.button3.Size = new System.Drawing.Size(75, 23);
  858. this.button3.TabIndex = 31;
  859. this.button3.UseVisualStyleBackColor = true;
  860. this.button3.Click += new System.EventHandler(this.button3_Click);
  861. //
  862. // label8
  863. //
  864. this.label8.AutoSize = true;
  865. this.label8.Location = new System.Drawing.Point(6, 125);
  866. this.label8.Name = "label8";
  867. this.label8.Size = new System.Drawing.Size(65, 12);
  868. this.label8.TabIndex = 30;
  869. //
  870. // numericUpDown2
  871. //
  872. this.numericUpDown2.DecimalPlaces = 2;
  873. this.numericUpDown2.Location = new System.Drawing.Point(164, 121);
  874. this.numericUpDown2.Maximum = new decimal(new int[] {
  875. 1000,
  876. 0,
  877. 0,
  878. 0});
  879. this.numericUpDown2.Name = "numericUpDown2";
  880. this.numericUpDown2.Size = new System.Drawing.Size(61, 21);
  881. this.numericUpDown2.TabIndex = 29;
  882. this.numericUpDown2.Tag = "max";
  883. this.numericUpDown2.Value = new decimal(new int[] {
  884. 500,
  885. 0,
  886. 0,
  887. 0});
  888. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged_1);
  889. //
  890. // numericUpDown1
  891. //
  892. this.numericUpDown1.DecimalPlaces = 2;
  893. this.numericUpDown1.Location = new System.Drawing.Point(85, 121);
  894. this.numericUpDown1.Maximum = new decimal(new int[] {
  895. 1000,
  896. 0,
  897. 0,
  898. 0});
  899. this.numericUpDown1.Name = "numericUpDown1";
  900. this.numericUpDown1.Size = new System.Drawing.Size(61, 21);
  901. this.numericUpDown1.TabIndex = 28;
  902. this.numericUpDown1.Tag = "min";
  903. this.numericUpDown1.Value = new decimal(new int[] {
  904. 1,
  905. 0,
  906. 0,
  907. 131072});
  908. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged_1);
  909. //
  910. // checkBox2
  911. //
  912. this.checkBox2.AutoSize = true;
  913. this.checkBox2.Checked = true;
  914. this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
  915. this.checkBox2.Location = new System.Drawing.Point(8, 57);
  916. this.checkBox2.Name = "checkBox2";
  917. this.checkBox2.Size = new System.Drawing.Size(72, 16);
  918. this.checkBox2.TabIndex = 26;
  919. this.checkBox2.UseVisualStyleBackColor = true;
  920. this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
  921. //
  922. // textBox6
  923. //
  924. this.textBox6.Location = new System.Drawing.Point(65, 89);
  925. this.textBox6.Name = "textBox6";
  926. this.textBox6.Size = new System.Drawing.Size(45, 21);
  927. this.textBox6.TabIndex = 25;
  928. this.textBox6.Text = "0.5";
  929. this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);
  930. //
  931. // label7
  932. //
  933. this.label7.AutoSize = true;
  934. this.label7.Location = new System.Drawing.Point(6, 93);
  935. this.label7.Name = "label7";
  936. this.label7.Size = new System.Drawing.Size(53, 12);
  937. this.label7.TabIndex = 24;
  938. //
  939. // comboBox3
  940. //
  941. this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  942. this.comboBox3.FormattingEnabled = true;
  943. this.comboBox3.Location = new System.Drawing.Point(201, 90);
  944. this.comboBox3.Name = "comboBox3";
  945. this.comboBox3.Size = new System.Drawing.Size(133, 20);
  946. this.comboBox3.TabIndex = 23;
  947. this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
  948. //
  949. // label6
  950. //
  951. this.label6.AutoSize = true;
  952. this.label6.Location = new System.Drawing.Point(136, 93);
  953. this.label6.Name = "label6";
  954. this.label6.Size = new System.Drawing.Size(65, 12);
  955. this.label6.TabIndex = 22;
  956. //
  957. // comboBox2
  958. //
  959. this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  960. this.comboBox2.FormattingEnabled = true;
  961. this.comboBox2.Location = new System.Drawing.Point(201, 55);
  962. this.comboBox2.Name = "comboBox2";
  963. this.comboBox2.Size = new System.Drawing.Size(133, 20);
  964. this.comboBox2.TabIndex = 11;
  965. this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
  966. //
  967. // label1
  968. //
  969. this.label1.AutoSize = true;
  970. this.label1.Location = new System.Drawing.Point(136, 58);
  971. this.label1.Name = "label1";
  972. this.label1.Size = new System.Drawing.Size(65, 12);
  973. this.label1.TabIndex = 21;
  974. //
  975. // checkBox1
  976. //
  977. this.checkBox1.AutoSize = true;
  978. this.checkBox1.Location = new System.Drawing.Point(8, 20);
  979. this.checkBox1.Name = "checkBox1";
  980. this.checkBox1.Size = new System.Drawing.Size(72, 16);
  981. this.checkBox1.TabIndex = 7;
  982. this.checkBox1.UseVisualStyleBackColor = true;
  983. this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
  984. //
  985. // GrainSizeAreaMethodDialog
  986. //
  987. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  988. this.ClientSize = new System.Drawing.Size(1107, 835);
  989. this.Controls.Add(this.groupBox4);
  990. this.Controls.Add(this.groupBox3);
  991. this.Controls.Add(this.groupBox11);
  992. this.Controls.Add(this.groupBox7);
  993. this.Controls.Add(this.groupBox8);
  994. this.Controls.Add(this.groupBox2);
  995. this.Controls.Add(this.groupBox1);
  996. this.Name = "GrainSizeAreaMethodDialog";
  997. this.Text = "";
  998. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GrainSizeDialog_FormClosing);
  999. this.Load += new System.EventHandler(this.GrainSizeDialog_Load);
  1000. this.Controls.SetChildIndex(this.groupBox1, 0);
  1001. this.Controls.SetChildIndex(this.groupBox2, 0);
  1002. this.Controls.SetChildIndex(this.groupBox8, 0);
  1003. this.Controls.SetChildIndex(this.groupBox7, 0);
  1004. this.Controls.SetChildIndex(this.groupBox11, 0);
  1005. this.Controls.SetChildIndex(this.groupBox3, 0);
  1006. this.Controls.SetChildIndex(this.groupBox4, 0);
  1007. this.groupBox1.ResumeLayout(false);
  1008. this.groupBox1.PerformLayout();
  1009. this.groupBox2.ResumeLayout(false);
  1010. this.groupBox8.ResumeLayout(false);
  1011. this.groupBox8.PerformLayout();
  1012. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
  1013. ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).EndInit();
  1014. this.groupBox3.ResumeLayout(false);
  1015. this.groupBox11.ResumeLayout(false);
  1016. this.groupBox11.PerformLayout();
  1017. this.groupBox4.ResumeLayout(false);
  1018. this.groupBox4.PerformLayout();
  1019. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  1020. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  1021. this.ResumeLayout(false);
  1022. }
  1023. #endregion
  1024. /// <summary>
  1025. /// 初始化矩形
  1026. /// </summary>
  1027. private void InitRectangleF(PointF pointF)
  1028. {
  1029. if (this.selectPicture > -1)
  1030. {
  1031. bool foundItem;
  1032. guideClass.RectangleFLine = guideClass.guideAreaRectLine(pointF, this.comboBox1.SelectedItem, out foundItem);
  1033. if (foundItem)
  1034. this.AddRectangleToRectangleFCaps();// "μm²"μm
  1035. }
  1036. }
  1037. /// <summary>
  1038. /// 刷新图形边线点集合
  1039. /// </summary>
  1040. private void AddRectangleToRectangleFCaps()
  1041. {
  1042. GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel;
  1043. if (grainSizeGuideStyleModel == null)
  1044. return;
  1045. this.linePointList.Clear();
  1046. // 圆形
  1047. if (grainSizeGuideStyleModel.circularGuideStyles != null)
  1048. {
  1049. foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles)
  1050. {
  1051. if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
  1052. {
  1053. // 圆心
  1054. Point center = new Point((int)(guideClass.rectangleFLine.X + guideClass.rectangleFLine.Width / 2), (int)(guideClass.rectangleFLine.Y + guideClass.rectangleFLine.Height / 2));
  1055. for (int i = 0; i <= 360; i++)
  1056. {
  1057. OpenCvSharp.Point[] points = roundOutline(center, guideClass.Mat_lineDiameter / 2);
  1058. foreach (var point in points)
  1059. {
  1060. linePointList.Add(new Point(point.X, point.Y));
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. // 矩形
  1067. if (grainSizeGuideStyleModel.rectangleGuideStyles != null)
  1068. {
  1069. foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles)
  1070. {
  1071. if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
  1072. {
  1073. for (int l = (int)guideClass.rectangleFLine.Y; l <= guideClass.rectangleFLine.Bottom; l++)
  1074. {
  1075. if (guideClass.rectangleFLine.X >= 0 && guideClass.RectangleFLine.X < this.documentWorkspace.CompositionSurface.Width && l >= 0 && l < this.documentWorkspace.CompositionSurface.Height)
  1076. linePointList.Add(new PointF(guideClass.RectangleFLine.X, l));
  1077. }
  1078. for (int t = (int)guideClass.RectangleFLine.X; t <= guideClass.RectangleFLine.Right; t++)
  1079. {
  1080. if (t >= 0 && t < this.documentWorkspace.CompositionSurface.Width && guideClass.RectangleFLine.Y >= 0 && guideClass.RectangleFLine.Y < this.documentWorkspace.CompositionSurface.Height)
  1081. linePointList.Add(new PointF(t, guideClass.RectangleFLine.Y));
  1082. }
  1083. for (int r = (int)guideClass.RectangleFLine.Y; r <= guideClass.RectangleFLine.Bottom; r++)
  1084. {
  1085. if (guideClass.RectangleFLine.Right >= 0 && guideClass.RectangleFLine.Right < this.documentWorkspace.CompositionSurface.Width && r >= 0 && r < this.documentWorkspace.CompositionSurface.Height)
  1086. linePointList.Add(new PointF(guideClass.RectangleFLine.Right, r));
  1087. }
  1088. for (int t = (int)guideClass.RectangleFLine.X; t <= guideClass.RectangleFLine.Right; t++)
  1089. {
  1090. if (t >= 0 && t < this.documentWorkspace.CompositionSurface.Width && guideClass.RectangleFLine.Bottom >= 0 && guideClass.RectangleFLine.Bottom < this.documentWorkspace.CompositionSurface.Height)
  1091. linePointList.Add(new PointF(t, guideClass.RectangleFLine.Bottom));
  1092. }
  1093. }
  1094. }
  1095. }
  1096. this.documentWorkspace.Refresh();
  1097. }
  1098. /// <summary>
  1099. /// 辅助线维护
  1100. /// </summary>
  1101. public void InitComboboxValue(ArrayList arrayList)
  1102. {
  1103. guideClass.createGuideAreaClassModels();
  1104. this.comboBox1.DataSource = null;
  1105. if (arrayList != null && arrayList.Count > 0)
  1106. {
  1107. this.comboboxChange = false;
  1108. arrayList.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
  1109. this.comboBox1.DataSource = arrayList;
  1110. this.comboboxChange = false;
  1111. int oldSelectIndex = -1;
  1112. for (int i = 0; i < this.comboBox1.Items.Count; i++)
  1113. {
  1114. if (this.oldSelectItem.Equals(this.comboBox1.Items[i]))
  1115. {
  1116. oldSelectIndex = i;
  1117. }
  1118. }
  1119. if (oldSelectIndex > -1)//0914###18839
  1120. {
  1121. if (this.comboBox1.SelectedIndex != oldSelectIndex)
  1122. this.comboBox1.SelectedIndex = oldSelectIndex;
  1123. }
  1124. else if (this.comboBox1.Items.Count > 0)
  1125. this.comboBox1.SelectedIndex = 0;// this.comboBox1.Items.Count - 1;
  1126. }
  1127. else
  1128. {
  1129. ArrayList arrayList1 = new ArrayList();
  1130. List<int> indexList1 = new List<int>();
  1131. GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel;
  1132. // 圆形
  1133. if (grainSizeGuideStyleModel.circularGuideStyles != null)
  1134. {
  1135. foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles)
  1136. {
  1137. arrayList1.Add(circularGuideStyle.tag/*" "*/);
  1138. indexList1.Add(circularGuideStyle.index);
  1139. }
  1140. }
  1141. // 矩形
  1142. if (grainSizeGuideStyleModel.rectangleGuideStyles != null)
  1143. {
  1144. foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles)
  1145. {
  1146. arrayList1.Add(rectangleGuideStyle.tag/*" "*/);
  1147. indexList1.Add(rectangleGuideStyle.index);
  1148. }
  1149. }
  1150. if (arrayList1.Count > 0)//0916###18839
  1151. {
  1152. //排序算法//0914###18839
  1153. bool sortSuccess = false;
  1154. while (!sortSuccess)
  1155. {
  1156. sortSuccess = true;
  1157. int firstIndex = 0;
  1158. int secondIndex = 0;
  1159. for (int i = 0; i < indexList1.Count; i++)
  1160. {
  1161. for (int j = i + 1; j < indexList1.Count; j++)
  1162. {
  1163. if (indexList1[i] > indexList1[j])
  1164. {
  1165. sortSuccess = false;
  1166. firstIndex = i;
  1167. secondIndex = j;
  1168. }
  1169. }
  1170. if (!sortSuccess)
  1171. break;
  1172. }
  1173. string firstValue = arrayList1[firstIndex] + "";
  1174. arrayList1[firstIndex] = arrayList1[secondIndex] + "";
  1175. arrayList1[secondIndex] = firstValue;
  1176. int firstIndexV = indexList1[firstIndex] + 0;
  1177. indexList1[firstIndex] = indexList1[secondIndex] + 0;
  1178. indexList1[secondIndex] = firstIndexV;
  1179. }
  1180. arrayList1.Insert(0, PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text"));
  1181. this.comboBox1.DataSource = arrayList1;
  1182. this.comboBox1.SelectedIndex = 0;
  1183. }
  1184. }
  1185. guideClass.UpdateGuideAreaStyle(this.bitmap, this.comboBox1.SelectedItem, false/*this.comboBox1.SelectedIndex > 0*/);
  1186. this.documentWorkspace.Refresh();
  1187. }
  1188. /// <summary>
  1189. /// ListView图片选择改变事件
  1190. /// </summary>
  1191. /// <param name="sender"></param>
  1192. /// <param name="e"></param>
  1193. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  1194. {
  1195. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  1196. {
  1197. if (this.selectPicture == this.listView1.FocusedItem.Index)
  1198. return;
  1199. existViewFlag = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.IsExsitView();
  1200. this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1201. if (!existViewFlag)
  1202. {
  1203. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
  1204. }
  1205. else
  1206. {
  1207. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFullSizeWithRegion());
  1208. }
  1209. //this.documentWorkspace.PhaseModels[2].mat = null;//清空前一张图的信息不遗留显示
  1210. //massLabelPoints.Clear();//1013###18808(切换图片的时候前一张图的信息不遗留显示)
  1211. ////二值化相关
  1212. //Document document = Document.FromImage(bitmap);
  1213. //this.documentWorkspace.Document = document;
  1214. //this.documentWorkspace.Visible = true;
  1215. //this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList;
  1216. //this.documentWorkspace.PhaseModels = new List<PhaseModel>();
  1217. //this.documentWorkspace.PhaseModels.AddRange(this.documentItems[this.listView1.FocusedItem.Index].phaseModels);
  1218. ////二值化end
  1219. this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1220. //二值化集成4
  1221. binaryClass.listView1_SelectedIndexChanged(this.bitmap);
  1222. this.documentWorkspace.PhaseModels[2].mat = null;//清空前一张图的信息不遗留显示
  1223. massLabelPoints.Clear();//1013###18808(切换图片的时候前一张图的信息不遗留显示)
  1224. if (this.checkBox1.Checked)
  1225. {
  1226. this.applyDect();
  1227. }
  1228. this.selectPicture = this.listView1.FocusedItem.Index;
  1229. this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
  1230. InitRectangleF(new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2));
  1231. AddRectangleToRectangleFCaps();
  1232. }
  1233. }
  1234. /// <summary>
  1235. /// 辅助线样式
  1236. /// </summary>
  1237. /// <param name="sender"></param>
  1238. /// <param name="e"></param>
  1239. private void button9_Click(object sender, EventArgs e)
  1240. {
  1241. if (this.bitmap == null)
  1242. {
  1243. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  1244. return;
  1245. }
  1246. this.oldSelectItem = (string)this.comboBox1.SelectedItem;
  1247. GrainGuideStyleSettingsDialog grainGuideStyleSettingsDialog = new GrainGuideStyleSettingsDialog(1, this.gbtType, this.bitmap);
  1248. grainGuideStyleSettingsDialog.StartPosition = FormStartPosition.CenterScreen;
  1249. grainGuideStyleSettingsDialog.ShowDialog(this);
  1250. }
  1251. /// <summary>
  1252. /// 画布绘制
  1253. /// </summary>
  1254. /// <param name="sender"></param>
  1255. /// <param name="e"></param>
  1256. private void Panel_Paint(object sender, PaintEventArgs e)
  1257. {
  1258. if (this.documentWorkspace.CompositionSurface != null)
  1259. {
  1260. //
  1261. // 以下是计算绘制图片的位置和大小并绘制图片
  1262. //
  1263. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  1264. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  1265. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  1266. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  1267. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  1268. //
  1269. // 以下是绘制网格、标注、测量、视场等开始
  1270. //
  1271. e.Graphics.TranslateTransform(x, y);
  1272. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  1273. //if (this.checkBox4_0.Checked)//显示网格//1009###19000
  1274. Draw(e.Graphics);
  1275. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  1276. e.Graphics.TranslateTransform(-x, -y);
  1277. }
  1278. }
  1279. /// <summary>
  1280. /// 绘制
  1281. /// </summary>
  1282. private void Draw(Graphics graphics)
  1283. {
  1284. // 抗锯齿
  1285. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1286. if (this.checkBox4_0.Checked)
  1287. {
  1288. guideClass.DrawAreaGuide(graphics, this.comboBox1.SelectedItem);
  1289. }
  1290. if (this.checkBox5_0.Checked && massLabelPoints.Count > 0)
  1291. {
  1292. int index = 0;
  1293. Font myFont = new Font("宋体", 12/*, FontStyle.Bold*/);
  1294. Brush bush = new SolidBrush(this.panel1.BackColor/*Color.Red*/);//填充的颜色
  1295. foreach (var item in massLabelPoints)
  1296. {
  1297. graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5);
  1298. }
  1299. }
  1300. }
  1301. /// <summary>
  1302. /// 切换辅助线
  1303. /// </summary>
  1304. /// <param name="sender"></param>
  1305. /// <param name="e"></param>
  1306. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  1307. {
  1308. if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
  1309. {
  1310. if (!(this.selectPicture > -1))
  1311. {
  1312. int oldSelectIndex = -1;
  1313. for (int i = 0; i < this.comboBox1.Items.Count; i++)
  1314. {
  1315. if (this.oldSelectItem != null && this.oldSelectItem.Equals(this.comboBox1.Items[i]))
  1316. {
  1317. oldSelectIndex = i;
  1318. }
  1319. }
  1320. if (this.comboBox1.SelectedIndex > 0)
  1321. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  1322. if (oldSelectIndex > -1)
  1323. if (this.comboBox1.SelectedIndex != oldSelectIndex)
  1324. this.comboBox1.SelectedIndex = oldSelectIndex;
  1325. else if (this.comboBox1.Items.Count > 0)
  1326. this.comboBox1.SelectedIndex = 0;
  1327. return;
  1328. }
  1329. guideClass.UpdateGuideAreaStyle(this.bitmap, this.comboBox1.SelectedItem, this.comboBox1.SelectedIndex > 0);
  1330. if (this.selectPicture > -1)
  1331. {
  1332. PointF pointF;
  1333. if (this.comboboxChange)
  1334. {
  1335. pointF = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
  1336. this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
  1337. }
  1338. else
  1339. pointF = this.loctation;
  1340. InitRectangleF(pointF);
  1341. this.comboboxChange = true;
  1342. }
  1343. this.documentWorkspace.Refresh();
  1344. }
  1345. }
  1346. #region 矩形拖动
  1347. /// <summary>
  1348. /// 鼠标按下
  1349. /// </summary>
  1350. /// <param name="drawArea"></param>
  1351. /// <param name="e"></param>
  1352. private void OnMouseDown(object sender, MouseEventArgs e)
  1353. {
  1354. // 换算后的点
  1355. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  1356. if (e.Button == MouseButtons.Left && e.Clicks == 1)
  1357. {
  1358. if (guideClass.RectangleFLine.Contains(point1))
  1359. {
  1360. m_canMove = true;
  1361. this.m_StartPoint = point1;
  1362. }
  1363. }
  1364. guideClass.OnMouseDown(point1, sender, e);
  1365. }
  1366. /// <summary>
  1367. /// 移动
  1368. /// </summary>
  1369. /// <param name="sender"></param>
  1370. /// <param name="e"></param>
  1371. private void onMouseMove(object sender, MouseEventArgs e)
  1372. {
  1373. // 换算后的点
  1374. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  1375. this.documentWorkspace.Refresh();
  1376. if (guideClass.onMouseAreaMove(point1, this.comboBox1.SelectedItem, e))// 矩形缩放
  1377. {
  1378. this.loctation = new PointF(guideClass.RectangleFLine.X + guideClass.RectangleFLine.Width / 2, guideClass.RectangleFLine.Y + guideClass.RectangleFLine.Height / 2);
  1379. this.AddRectangleToRectangleFCaps();
  1380. this.documentWorkspace.Refresh();
  1381. }
  1382. else if (e.Button == MouseButtons.Left && m_canMove)
  1383. {
  1384. // 矩形偏移
  1385. guideClass.rectangleFLine.Offset(point1.X - this.m_StartPoint.X, point1.Y - this.m_StartPoint.Y);
  1386. this.loctation = new PointF(guideClass.rectangleFLine.X + guideClass.rectangleFLine.Width / 2, guideClass.rectangleFLine.Y + guideClass.rectangleFLine.Height / 2);
  1387. this.m_StartPoint = point1;
  1388. this.AddRectangleToRectangleFCaps();
  1389. this.documentWorkspace.Refresh();
  1390. }
  1391. }
  1392. /// <summary>
  1393. /// 鼠标抬起
  1394. /// </summary>
  1395. /// <param name="sender"></param>
  1396. /// <param name="e"></param>
  1397. private void onMouseUp(object sender, MouseEventArgs e)
  1398. {
  1399. m_canMove = false;
  1400. guideClass.onMouseUp(sender, e);
  1401. this.AddRectangleToRectangleFCaps();
  1402. }
  1403. #endregion
  1404. /// <summary>
  1405. /// surfaceBox双击事件
  1406. /// 目前是参考AxioVision
  1407. /// 应该是把每次选的点都取最高和最低的BGR
  1408. /// </summary>
  1409. /// <param name="sender"></param>
  1410. /// <param name="e"></param>
  1411. private unsafe void pictureBox1_Click(object sender, EventArgs e)
  1412. {
  1413. }
  1414. /// <summary>
  1415. /// 移除未完成的定义物体的轮廓的对象
  1416. /// </summary>
  1417. /// <param name="sender"></param>
  1418. /// <param name="e"></param>
  1419. private void GrainSizeDialog_FormClosing(object sender, FormClosingEventArgs e)
  1420. {
  1421. this.documentWorkspace.GraphicsList.DeleteDrawClass(DrawClass.PhaseExtraction);//###
  1422. this.documentWorkspace.Refresh();
  1423. }
  1424. /// <summary>
  1425. /// 是否显示晶粒编号
  1426. /// </summary>
  1427. /// <param name="sender"></param>
  1428. /// <param name="e"></param>
  1429. private void checkBox5_0_CheckedChanged(object sender, EventArgs e)
  1430. {
  1431. this.documentWorkspace.Refresh();
  1432. }
  1433. /// <summary>
  1434. /// 是否显示网格
  1435. /// </summary>
  1436. /// <param name="sender"></param>
  1437. /// <param name="e"></param>
  1438. private void checkBox4_0_CheckedChanged(object sender, EventArgs e)
  1439. {
  1440. this.documentWorkspace.Refresh();
  1441. }
  1442. //二值化集成3
  1443. #region 二值化相关方法
  1444. /// <summary>
  1445. /// 添加参数改变的监听
  1446. /// </summary>
  1447. /// <param name="sender"></param>
  1448. /// <param name="e"></param>
  1449. private void GrainSizeDialog_Load(object sender, EventArgs e)
  1450. {
  1451. this.comboBox3.Text = PdnResources.GetString("Menu.pdenoisingtype.Text");
  1452. this.comboBox3.SelectedIndex = 1;
  1453. this.comboBox2.Text = PdnResources.GetString("Menu.electthegrainboundarytype.Text");
  1454. this.comboBox2.SelectedIndex = 1;
  1455. this.binaryClass.loadParams();
  1456. this.binaryClass.guideClass = this.guideClass;
  1457. this.binaryClass.comboBox1 = this.comboBox1;
  1458. }
  1459. private bool bcBinaryChecked()
  1460. {
  1461. return bc != null && bc.BinaryChecked;
  1462. }
  1463. private bool bcOriginChecked()
  1464. {
  1465. return bc != null && bc.OriginChecked;
  1466. }
  1467. /// <summary>
  1468. /// 参数改变时,重新处理图像
  1469. /// </summary>
  1470. /// <param name="sender"></param>
  1471. /// <param name="e"></param>
  1472. private void bClassBinaryImplFinishAction(object sender, EventArgs e)
  1473. {
  1474. this.documentWorkspace.Refresh();
  1475. //AddRectangleToRectangleFCaps();//###
  1476. }
  1477. //private void checkBox10_CheckedChanged(object sender, EventArgs e)
  1478. //{
  1479. // if (checkBox10.Checked && !checkBox5.Checked)
  1480. // {
  1481. // this.documentWorkspace.PhaseModels[0].choise = true;
  1482. // }
  1483. // else
  1484. // {
  1485. // this.documentWorkspace.PhaseModels[0].choise = false;
  1486. // }
  1487. // if (toApplyBinary)
  1488. // this.applyButtonImpl(null, null);
  1489. // toApplyBinary = true;
  1490. // if (this.listView1.FocusedItem != null && checkBox10.Checked)
  1491. // {
  1492. // }
  1493. // else
  1494. // this.documentWorkspace.Refresh();
  1495. //}
  1496. /// <summary>
  1497. /// 显示原图/原图+二值图
  1498. /// </summary>
  1499. /// <param name="sender"></param>
  1500. /// <param name="e"></param>
  1501. private void bcOriginCheckedChanged(object sender, EventArgs e)
  1502. {
  1503. if (!bcOriginChecked())
  1504. {
  1505. if (bcBinaryChecked())
  1506. this.documentWorkspace.PhaseModels[0].choise = true;
  1507. if (checkBox1.Checked && checkBox3_0.Checked)
  1508. this.documentWorkspace.PhaseModels[1].choise = true;
  1509. if (checkBox11.Checked)
  1510. this.documentWorkspace.PhaseModels[2].choise = true;
  1511. }
  1512. else
  1513. {
  1514. this.documentWorkspace.PhaseModels[0].choise = false;
  1515. this.documentWorkspace.PhaseModels[1].choise = false;
  1516. }
  1517. this.documentWorkspace.Refresh();
  1518. }
  1519. ///// <summary>
  1520. ///// 显示原图/原图+二值图
  1521. ///// </summary>
  1522. ///// <param name="sender"></param>
  1523. ///// <param name="e"></param>
  1524. //private void ShowOrHideOriginPic(object sender, EventArgs e)
  1525. //{
  1526. // if (!checkBox5.Checked)
  1527. // {
  1528. // if (checkBox10.Checked)
  1529. // this.documentWorkspace.PhaseModels[0].choise = true;
  1530. // if (checkBox1.Checked && checkBox3_0.Checked) //0916###18744
  1531. // this.documentWorkspace.PhaseModels[1].choise = true;
  1532. // if (checkBox11.Checked)
  1533. // this.documentWorkspace.PhaseModels[2].choise = true;
  1534. // }
  1535. // else
  1536. // {
  1537. // this.documentWorkspace.PhaseModels[0].choise = false;
  1538. // this.documentWorkspace.PhaseModels[1].choise = false;
  1539. // }
  1540. // this.documentWorkspace.Refresh();
  1541. //}
  1542. ///// <summary>
  1543. ///// 参数改变时,重新处理图像
  1544. ///// </summary>
  1545. ///// <param name="sender"></param>
  1546. ///// <param name="e"></param>
  1547. //private void applyButtonImpl(object sender, EventArgs e)
  1548. //{
  1549. // long start = Cv2.GetTickCount();
  1550. // if (this.listView1.FocusedItem != null && checkBox10.Checked)
  1551. // {
  1552. // //判断是否存在视场,如果存在视场,则把视场提取出来,进行处理
  1553. // if (this.documentWorkspace.GraphicsList.IsExsitView())
  1554. // {
  1555. // this.documentWorkspace.PhaseModels[0].mat = action.PerformProcess(
  1556. // OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion()),
  1557. // OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
  1558. // this.documentWorkspace.PhaseModels[0].color = this.panel2.BackColor.ToArgb();
  1559. // this.documentWorkspace.Refresh();
  1560. // }
  1561. // else
  1562. // {
  1563. // this.documentWorkspace.PhaseModels[0].mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
  1564. // this.documentWorkspace.PhaseModels[0].color = this.panel2.BackColor.ToArgb();
  1565. // this.documentWorkspace.Refresh();
  1566. // }
  1567. // }
  1568. // double time = (Cv2.GetTickCount() - start) / Cv2.GetTickFrequency();
  1569. // System.Console.WriteLine("执行时间:" + time);
  1570. //}
  1571. #endregion
  1572. private void panel1_Click(object sender, EventArgs e)
  1573. {
  1574. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
  1575. this.colorsFormGrid.ShowDialog();
  1576. }
  1577. /// <summary>
  1578. /// Panel2的调色板颜色改变
  1579. /// </summary>
  1580. /// <param name="sender"></param>
  1581. /// <param name="e"></param>
  1582. private void gridColorChanged(object sender, EventArgs e)
  1583. {
  1584. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  1585. this.panel1.BackColor = color;
  1586. this.documentWorkspace.PhaseModels[1].color = this.panel1.BackColor.ToArgb();
  1587. if (this.checkBox1.Checked)
  1588. {
  1589. this.applyDect();
  1590. this.documentWorkspace.Refresh();
  1591. }
  1592. //关闭色板
  1593. this.colorsFormGrid.Close();
  1594. }
  1595. /// <summary>
  1596. /// 保存结果
  1597. /// </summary>
  1598. /// <param name="sender"></param>
  1599. /// <param name="e"></param>
  1600. private void button2_Click(object sender, EventArgs e)
  1601. {
  1602. if (this.listView1.SelectedItems.Count > 0)
  1603. {
  1604. if(this.comboBox1.SelectedItem != null && !PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text").Equals(this.comboBox1.SelectedItem))
  1605. {
  1606. string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
  1607. string tag = this.imageList1.Images.Keys[this.listView1.SelectedItems[0].Index];
  1608. System.Data.DataTable dataTable = new System.Data.DataTable();
  1609. bool replace = false;
  1610. int add = 0;
  1611. foreach (ListViewItem item in this.listView2.Items)
  1612. {
  1613. if (item.Tag.Equals(tag))
  1614. {
  1615. add++;
  1616. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1617. if (dr == DialogResult.OK)
  1618. {
  1619. replace = true;
  1620. }
  1621. break;
  1622. }
  1623. }
  1624. if (replace || this.listView2.Items.Count == 0 || add == 0)
  1625. {
  1626. if (!replace)
  1627. {
  1628. ListViewItem listViewItem = new ListViewItem();
  1629. listViewItem.SubItems[0].Text = imgName;
  1630. listViewItem.Tag = "" + tag;
  1631. if (this.listView2.Items.Count == 0)
  1632. this.listView2.Items.Add(listViewItem);
  1633. else
  1634. this.listView2.Items.Insert(0, listViewItem);
  1635. }
  1636. this.dataGridView4.Rows.Clear();
  1637. DataGridViewRow dgvr = new DataGridViewRow();
  1638. foreach (DataGridViewColumn c in this.dataGridView4.Columns)
  1639. {
  1640. dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  1641. }
  1642. dgvr.Cells[0].Value = imgName;
  1643. dgvr.Cells[1].Value = this.comboBox1.SelectedItem;
  1644. // 是否矩形辅助线
  1645. int isRect;
  1646. double aec = guideClass.guideArea(this.comboBox1.SelectedItem, out isRect, this.gbtType);
  1647. dgvr.Cells[2].Value = aec;
  1648. aec = aec * 0.001 * 0.001;
  1649. double grainNumber = GetNumberOfGrains(linePointList, guideClass.RectangleFLine) + isRect;
  1650. dgvr.Cells[3].Value = grainNumber;
  1651. decimal M = 1;// this.appWorkspace.GetGainMultiple() ;
  1652. decimal A = Convert.ToDecimal((double)M * (double)M * grainNumber / aec);
  1653. //dgvr.Cells[4].Value = grainNumber;
  1654. ////1013###19377##面积法位置,使用晶粒的实际面积去标准中的表进行对应,获取截距后,在进行平均的计算 to test
  1655. double[] lengths = {3.88, 7.75 , 10.96, 15.50, 21.92, 31.0, 43.84, 62.0,
  1656. 87.68, 124, 175.36, 248, 350.73, 496, 701.45, 992, 1402.9, 1984.0, 2805.8, 3968.0, 5611.6,
  1657. 7936.0, 11223.2, 15872.0, 22446.4, 31744.1, 44892.9, 63488.1, 89785.8, 126976.3};
  1658. // 差值
  1659. decimal differenceNew = 0;
  1660. decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 2.88, (double)A - 126977.3)));//Convert.ToDecimal(double.MaxValue);//Math.Abs(A - 160000);// Convert.ToDecimal((double)A - 2.22);
  1661. double selectArea = 0;
  1662. int first = -1;
  1663. foreach (double item in lengths)
  1664. {
  1665. selectArea = item;
  1666. differenceNew = Math.Abs(A - Convert.ToDecimal(item));
  1667. if (differenceNew < differenceOld)
  1668. {
  1669. differenceOld = Math.Abs(A - Convert.ToDecimal(item));
  1670. first++;
  1671. }
  1672. else
  1673. break;
  1674. }
  1675. // string[] valueG = {"00"/*"00A"*/, "0" , "0.5", "1.0", "1.5", "2.0", "2.5", "3.0",
  1676. //"3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "6.5", "7.0", "7.5", "8.0", "8.5", "9.0", "9.5",
  1677. //"10.0", "10.5", "11.0", "11.5", "12.0", "12.5", "13.0", "13.5", "14.0"};
  1678. string[] valueG = {"452.5", "320.0" , "269.1", "226.3", "190.3", "160.0", "134.5", "113.1",
  1679. "95.1", "80.0", "67.3", "56.6", "47.6", "40.0", "33.6", "28.3", "23.8", "20.0", "16.8", "14.1", "11.9",
  1680. "10.0", "8.4", "7.1", "5.9", "5.0", "4.2", "3.5", "3.0", "2.5"};//微米## to test
  1681. if (first >= valueG.Length)
  1682. {
  1683. first = valueG.Length - 1;
  1684. }
  1685. else if (first < 0)
  1686. {
  1687. first = 0;
  1688. }
  1689. dgvr.Cells[4].Value = valueG[first];
  1690. double NA = (double)M * (double)M * grainNumber / aec;
  1691. if (this.gbtType == 4)
  1692. dgvr.Cells[5].Value = 3.32 * Math.Log10(NA) - 2.9542;
  1693. else
  1694. dgvr.Cells[5].Value = 3.321928 * Math.Log10(NA) - 2.954;
  1695. this.dataGridView4.Rows.Add(dgvr);
  1696. dataTable.TableName = tag;
  1697. foreach (System.Data.DataTable dataTable1 in dataTables)
  1698. {
  1699. if (dataTable1.TableName.Equals(dataTable.TableName))
  1700. {
  1701. dataTables.Remove(dataTable1);
  1702. break;
  1703. }
  1704. }
  1705. foreach (DataGridViewColumn c in this.dataGridView4.Columns)
  1706. {
  1707. dataTable.Columns.Add(c.HeaderText);
  1708. }
  1709. for (int r = 0; r < this.dataGridView4.Rows.Count; r++)
  1710. {
  1711. DataRow dataRow = dataTable.NewRow();
  1712. for (int c = 0; c < this.dataGridView4.Rows[r].Cells.Count; c++)
  1713. {
  1714. dataRow[this.dataGridView4.Columns[c].HeaderText] = this.dataGridView4.Rows[r].Cells[c].Value;
  1715. }
  1716. dataTable.Rows.Add(dataRow);
  1717. }
  1718. this.dataTables.Add(dataTable);
  1719. this.RefreshDataGridView4();
  1720. //保存处理后的图片
  1721. List<Bitmap> tempBit = new List<Bitmap>();
  1722. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1723. tempBit.Add(originalBit);
  1724. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1725. Graphics graphics = Graphics.FromImage(newBit);
  1726. if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null)
  1727. {
  1728. Mat targetMat = this.documentWorkspace.PhaseModels[0].mat;
  1729. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  1730. }
  1731. if (this.documentWorkspace.PhaseModels[1].choise && this.documentWorkspace.PhaseModels[1].mat != null)
  1732. {
  1733. Mat targetMat = this.documentWorkspace.PhaseModels[1].mat;
  1734. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  1735. }
  1736. if (this.documentWorkspace.PhaseModels[2].choise && this.documentWorkspace.PhaseModels[2].mat != null)
  1737. {
  1738. Mat targetMat = this.documentWorkspace.PhaseModels[2].mat;
  1739. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  1740. }
  1741. Draw(graphics);
  1742. tempBit.Add(newBit);
  1743. if (bitDic.ContainsKey(tag))
  1744. bitDic[tag] = tempBit;
  1745. else
  1746. bitDic.Add(tag, tempBit);
  1747. //拼接中间数据
  1748. List<List<string>> dataList = new List<List<string>>();
  1749. List<string> columnName = new List<string>();
  1750. columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  1751. columnName.Add(PdnResources.GetString("Menu.Xoordinate.Text"));
  1752. columnName.Add(PdnResources.GetString("Menu.Yoordinate.Text"));
  1753. columnName.Add(PdnResources.GetString("Menu.Whethertheinternal.Text"));
  1754. dataList.Add(columnName);
  1755. if (massLabelPoints.Count > 0)
  1756. {
  1757. int index = 0;
  1758. int outMaxIndex = massLabelPoints.Count - 0 - within;
  1759. foreach (var item in massLabelPoints)
  1760. {
  1761. List<string> strList = new List<string>();
  1762. strList.Add(("" + (++index)).ToString());
  1763. strList.Add(item.X.ToString());
  1764. strList.Add(item.Y.ToString());
  1765. if (outMaxIndex < index)
  1766. strList.Add(PdnResources.GetString("Menu.Yes.text"));
  1767. else
  1768. strList.Add(PdnResources.GetString("Menu.no.text"));
  1769. dataList.Add(strList);
  1770. }
  1771. }
  1772. bool isExist = false;//是否已存在进行替换
  1773. int modelIndex = -1;//要替换的下标
  1774. for (int j = 0; j < tempDataModel.Count; j++)
  1775. {
  1776. if (tempDataModel[j].tagName.Equals(tag))
  1777. {
  1778. isExist = true;
  1779. modelIndex = j;
  1780. break;
  1781. }
  1782. }
  1783. if (isExist && modelIndex > -1)
  1784. tempDataModel[modelIndex].dataList = dataList;
  1785. else
  1786. {
  1787. ExportProjectModel newModel = new ExportProjectModel();
  1788. newModel.tagName = tag;
  1789. newModel.picName = imgName;
  1790. newModel.dataList = dataList;
  1791. tempDataModel.Add(newModel);
  1792. }
  1793. }
  1794. }
  1795. else
  1796. {
  1797. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text")+"!");
  1798. }
  1799. }
  1800. else
  1801. {
  1802. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  1803. }
  1804. }
  1805. /// <summary>
  1806. /// 切换分析结果
  1807. /// </summary>
  1808. /// <param name="sender"></param>
  1809. /// <param name="e"></param>
  1810. private void listView2_SelectedIndexChanged(object sender, EventArgs e)
  1811. {
  1812. if(!this.allShow)
  1813. {
  1814. if (this.listView2.SelectedItems.Count <= 0)
  1815. return;
  1816. this.dataGridView4.Rows.Clear();
  1817. for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  1818. {
  1819. System.Data.DataTable dataTable1 = new System.Data.DataTable();
  1820. foreach (var dataTable in this.dataTables)
  1821. {
  1822. if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  1823. dataTable1 = dataTable;
  1824. }
  1825. DataGridViewRow dgvr = new DataGridViewRow();
  1826. foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
  1827. {
  1828. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  1829. }
  1830. for (int c = 0; c < dataTable1.Columns.Count; c++)
  1831. {
  1832. dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
  1833. }
  1834. this.dataGridView4.Rows.Add(dgvr);
  1835. }
  1836. }
  1837. }
  1838. /// <summary>
  1839. /// 晶界重现
  1840. /// </summary>
  1841. /// <param name="sender"></param>
  1842. /// <param name="e"></param>
  1843. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  1844. {
  1845. if (this.checkBox1.Checked && !bcOriginChecked() && checkBox3_0.Checked)
  1846. {
  1847. this.documentWorkspace.PhaseModels[1].choise = true;
  1848. }
  1849. else
  1850. {
  1851. this.documentWorkspace.PhaseModels[1].choise = false;
  1852. this.documentWorkspace.Refresh();
  1853. }
  1854. if (this.checkBox1.Checked)
  1855. {
  1856. this.applyDect();
  1857. }
  1858. else
  1859. AddRectangleToRectangleFCaps();//1009###18946
  1860. }
  1861. ProgressThreadProcClass procClass;
  1862. double sigma = 0.5;
  1863. //string inputImageFile = "原始图片1.jpg";// "j1.JPG";
  1864. ////char[] inputImageFile2 = inputImageFile.ToCharArray();
  1865. Mat OrgImg;// = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
  1866. int dark;// = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
  1867. int smooth_type;// = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
  1868. //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
  1869. int enhance;// = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
  1870. double[] cell_size;// = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
  1871. Mat OrgImg0;
  1872. private void applyDect()
  1873. {
  1874. if (this.bitmap == null)
  1875. {
  1876. return;
  1877. }
  1878. if (!double.TryParse(textBox6.Text, out sigma))
  1879. {
  1880. return;
  1881. }
  1882. //ProgressThreadProcClass.StartProgressAction(this, 100, null);
  1883. //string inputImageFile = "原始图片1.jpg";// "j1.JPG";
  1884. ////char[] inputImageFile2 = inputImageFile.ToCharArray();
  1885. /*Mat */OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
  1886. /*int */dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
  1887. /*int */smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
  1888. //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
  1889. /*int */enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
  1890. /*double[] */cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
  1891. procClass = new ProgressThreadProcClass();
  1892. procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyDectAction), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"));
  1893. if (OrgImg0 != null)
  1894. {
  1895. this.documentWorkspace.PhaseModels[1].mat = OrgImg0.Clone();
  1896. this.documentWorkspace.Refresh();
  1897. OrgImg0 = null;
  1898. }
  1899. if (OrgImg != null)
  1900. {
  1901. OrgImg.Dispose();
  1902. OrgImg = null;
  1903. }
  1904. }
  1905. private void applyDectAction()
  1906. {
  1907. //double sigma = 0.5;
  1908. //if (!double.TryParse(textBox6.Text, out sigma))
  1909. //{
  1910. // return;
  1911. //}
  1912. ////string inputImageFile = "原始图片1.jpg";// "j1.JPG";
  1913. //////char[] inputImageFile2 = inputImageFile.ToCharArray();
  1914. //Mat OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
  1915. //int dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
  1916. //int smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
  1917. ////double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
  1918. //int enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
  1919. //double[] cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
  1920. OrgImg0 = this.runDect(OrgImg, dark, smooth_type, sigma, enhance, cell_size);
  1921. if (procClass != null)
  1922. {
  1923. procClass.DismissProgressAction(this);
  1924. //procClass = null;
  1925. }
  1926. }
  1927. private Mat runDect(Mat OrgImg0, int dark, int smooth_type, double sigma, int enhance, double[] cell_size)
  1928. {
  1929. Mat GryImg = new Mat();
  1930. Mat OrgImg = new Mat();
  1931. /////
  1932. if (4 == OrgImg0.Channels())
  1933. {
  1934. Cv2.CvtColor(OrgImg0, OrgImg, ColorConversionCodes.BGRA2BGR);
  1935. }
  1936. else
  1937. {
  1938. OrgImg = OrgImg0.Clone();
  1939. }
  1940. In5segmsurf prm = new In5segmsurf();
  1941. prm.OrgImg = OrgImg;
  1942. /////
  1943. //Cv2.ImShow("src", OrgImg);//kkkkk
  1944. //Cv2.WaitKey(0);//kkkkk
  1945. //转为为灰度?
  1946. if (3 == OrgImg.Channels() || 4 == OrgImg.Channels())
  1947. {
  1948. Cv2.CvtColor(OrgImg, GryImg, ColorConversionCodes.RGB2GRAY);
  1949. }
  1950. else
  1951. {
  1952. if (1 == OrgImg.Channels())
  1953. {
  1954. GryImg = OrgImg.Clone();
  1955. }
  1956. else
  1957. {
  1958. return null;
  1959. }
  1960. }
  1961. if (1 == dark)
  1962. {
  1963. int Rows = GryImg.Rows;
  1964. int Cols = GryImg.Cols;
  1965. int[] point = new int[2];
  1966. //单通道图像的反色
  1967. for (point[0] = 0; point[0] < Rows; point[0]++)
  1968. {
  1969. for (point[1] = 0; point[1] < Cols; point[1]++)
  1970. {
  1971. byte bTemp = (byte)(255 - GryImg.At<byte>(point[0], point[1]));
  1972. GryImg.Set<byte>(point, bTemp);//mmmmm
  1973. }
  1974. }
  1975. }
  1976. if (2 == dark)
  1977. {
  1978. Mat TempImg = GryImg.Clone();
  1979. Cv2.Sobel(TempImg, GryImg, -1, 2, 2, 3);//mmmmm
  1980. }
  1981. //Cv2.ImShow("src", GryImg);//kkkkk
  1982. //Cv2.WaitKey(0);//kkkkk
  1983. //去噪
  1984. if (0 == smooth_type)
  1985. {
  1986. prm.smoothim_method = "gaussian";
  1987. }
  1988. else
  1989. {
  1990. if (1 == smooth_type)
  1991. {
  1992. prm.smoothim_method = "dirced";
  1993. }
  1994. else
  1995. {
  1996. return null;
  1997. }
  1998. }
  1999. //晶界增强
  2000. if (1 == enhance)
  2001. {
  2002. prm.filterridges = 1;
  2003. }
  2004. else
  2005. {
  2006. prm.filterridges = 0;
  2007. }
  2008. //调用算法
  2009. prm.gaussian_stdev = sigma;
  2010. prm.LEVEL = ".3";
  2011. prm.classifycells_convexarea = 0.50;
  2012. prm.classifycells_convexperim = 0.45;
  2013. OLDcellsegm cellsegm = new OLDcellsegm();
  2014. string[] namehere = new string[1] { "prm" };
  2015. In6segmsurf IN6BNImgs = new In6segmsurf();
  2016. OUTsegmsurf RSTss = cellsegm.mf_segmsurf_progress_auto(GryImg, cell_size[0], cell_size[1], namehere, prm, IN6BNImgs, this.panel1.BackColor, this);
  2017. cell_size = null;
  2018. cellsegm = null;
  2019. namehere = null;
  2020. Cv2.CvtColor(RSTss.wat, OrgImg0, ColorConversionCodes.BGR2BGRA);
  2021. //this.documentWorkspace.PhaseModels[1].mat = OrgImg0;// RSTss.wat;// action.PerformProcess(
  2022. //// OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion()),
  2023. //// OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
  2024. //////this.documentWorkspace.PhaseModels[1].color = this.panel2.BackColor.ToArgb();
  2025. //this.documentWorkspace.Refresh();
  2026. //return RSTss.wat;
  2027. //string filename = "D:\\result11.jpg";
  2028. //Cv2.ImWrite(filename, RSTss.wat);
  2029. return OrgImg0/*null*/;
  2030. }
  2031. private void checkBox3_0_CheckedChanged(object sender, EventArgs e)
  2032. {
  2033. if (!bcOriginChecked() && checkBox1.Checked && checkBox3_0.Checked)
  2034. {
  2035. this.documentWorkspace.PhaseModels[1].choise = true;
  2036. }
  2037. else
  2038. {
  2039. this.documentWorkspace.PhaseModels[1].choise = false;
  2040. }
  2041. this.documentWorkspace.Refresh();
  2042. }
  2043. private void checkBox2_CheckedChanged(object sender, EventArgs e)
  2044. {
  2045. if (this.checkBox1.Checked)
  2046. {
  2047. this.applyDect();
  2048. }
  2049. }
  2050. private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  2051. {
  2052. if (this.checkBox1.Checked)
  2053. {
  2054. this.applyDect();
  2055. }
  2056. }
  2057. private void textBox6_TextChanged(object sender, EventArgs e)
  2058. {
  2059. if (this.checkBox1.Checked)
  2060. {
  2061. this.applyDect();
  2062. }
  2063. }
  2064. private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
  2065. {
  2066. if (this.checkBox1.Checked)
  2067. {
  2068. this.applyDect();
  2069. }
  2070. }
  2071. private void numericUpDown1_ValueChanged_1(object sender, EventArgs e)
  2072. {
  2073. if (this.checkBox1.Checked)
  2074. {
  2075. this.applyDect();
  2076. }
  2077. }
  2078. private void numericUpDown2_ValueChanged_1(object sender, EventArgs e)
  2079. {
  2080. if (this.checkBox1.Checked)
  2081. {
  2082. this.applyDect();
  2083. }
  2084. }
  2085. /// <summary>
  2086. /// 用不同颜色显示晶粒
  2087. /// </summary>
  2088. /// <param name="sender"></param>
  2089. /// <param name="e"></param>
  2090. private void checkBox11_CheckedChanged(object sender, EventArgs e)
  2091. {
  2092. if (!bcOriginChecked() && checkBox11.Checked)
  2093. {
  2094. this.documentWorkspace.PhaseModels[2].choise = true;
  2095. }
  2096. else
  2097. {
  2098. this.documentWorkspace.PhaseModels[2].choise = false;
  2099. }
  2100. this.documentWorkspace.Refresh();
  2101. }
  2102. /// <summary>
  2103. /// 设置
  2104. /// </summary>
  2105. /// <param name="sender"></param>
  2106. /// <param name="e"></param>
  2107. private void button1_Click(object sender, EventArgs e)
  2108. {
  2109. string templateName = "Template.Manager.item3.GrainSizeArea6394Method";
  2110. switch (this.gbtType)
  2111. {
  2112. case 2:
  2113. templateName = "Template.Manager.item3.GrainSizeArea24177Method";
  2114. break;
  2115. case 3:
  2116. templateName = "Template.Manager.item3.GrainSizeArea112Method";
  2117. break;
  2118. case 4:
  2119. templateName = "Template.Manager.item3.GrainSizeArea643Method";
  2120. break;
  2121. default:
  2122. break;
  2123. }
  2124. AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, templateName);
  2125. if (metallographicMethodSetDialog.hasModule)
  2126. {
  2127. metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen;
  2128. metallographicMethodSetDialog.ShowDialog();
  2129. }
  2130. else
  2131. {
  2132. metallographicMethodSetDialog = null;
  2133. }
  2134. }
  2135. /// <summary>
  2136. /// 导出结果
  2137. /// </summary>
  2138. /// <param name="sender"></param>
  2139. /// <param name="e"></param>
  2140. private void button14_Click(object sender, EventArgs e)
  2141. {
  2142. if (this.listView2.Items.Count > 0)
  2143. {
  2144. SaveFileDialog exe = new SaveFileDialog();
  2145. exe.Filter = "Execl files (*.xls)|*.xls";
  2146. exe.FilterIndex = 0;
  2147. exe.RestoreDirectory = true;
  2148. //exe.CreatePrompt = true;
  2149. exe.Title = "Export Excel File";
  2150. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  2151. exe.FileName = PdnResources.GetString("Menu.DedicatedAnalysis.BlackMetal.GrainSize.Text")+"(" + PdnResources.GetString("Menu.Areamethod.text")+ ")"+ PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddHHmmss");
  2152. DialogResult dr = exe.ShowDialog();
  2153. if (dr != DialogResult.OK)
  2154. {
  2155. return;
  2156. }
  2157. DataTable dtb = new DataTable();
  2158. foreach (var item in this.contentHead)
  2159. {
  2160. dtb.Columns.Add(item);
  2161. }
  2162. for (int i = 0; i < this.dataGridView4.Rows.Count; i++)
  2163. {
  2164. DataRow dataRow = dtb.NewRow();
  2165. for (int k = 0; k < this.contentHead.Count; k++)
  2166. {
  2167. dataRow[this.contentHead[k]] = this.dataGridView4.Rows[i].Cells[k].Value;
  2168. }
  2169. dtb.Rows.Add(dataRow);
  2170. }
  2171. List<DataTable> list = new List<DataTable>();
  2172. list.Add(dtb);
  2173. this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, false, false, true);
  2174. }
  2175. else
  2176. MessageBox.Show(PdnResources.GetString("Menu.Noanalysineratereport.text")+"!");
  2177. }
  2178. /// <summary>
  2179. /// 生成报告
  2180. /// </summary>
  2181. /// <param name="sender"></param>
  2182. /// <param name="e"></param>
  2183. private void button13_Click(object sender, EventArgs e)
  2184. {
  2185. if (this.checkBox2_0.Checked)
  2186. this.button1.PerformClick();
  2187. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  2188. {
  2189. //获取word书签与excel单元格的关系,以字典方式存储
  2190. List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  2191. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  2192. if (mic_module_infos != null && mic_module_infos.Count > 0)
  2193. {
  2194. foreach (mic_module_infos info in mic_module_infos)
  2195. {
  2196. tagInfos.Add(info.tag_name, info.cell_position);
  2197. }
  2198. }
  2199. //分析结果
  2200. List<List<string>> analysisContent = new List<List<string>>();
  2201. analysisContent.Add(contentHead);
  2202. foreach (DataGridViewRow item in this.dataGridView4.Rows)
  2203. {
  2204. List<string> content = new List<string>();
  2205. for (int i = 0; i < contentHead.Count; i++)
  2206. {
  2207. content.Add(item.Cells[i].Value.ToString());
  2208. }
  2209. analysisContent.Add(content);
  2210. }
  2211. //图片
  2212. bitList = new List<Bitmap>();
  2213. if (this.allShow)
  2214. {
  2215. foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
  2216. {
  2217. bitList.Add(kv.Value[0]);
  2218. bitList.Add(kv.Value[1]);
  2219. }
  2220. }
  2221. else
  2222. {
  2223. if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  2224. {
  2225. foreach (ListViewItem item in this.listView2.SelectedItems)
  2226. {
  2227. if (bitDic.ContainsKey(item.Name))
  2228. {
  2229. bitList.Add(bitDic[item.Name][0]);
  2230. bitList.Add(bitDic[item.Name][1]);
  2231. }
  2232. else if (bitDic.ContainsKey(item.Tag.ToString()))
  2233. {
  2234. bitList.Add(bitDic[item.Tag.ToString()][0]);
  2235. bitList.Add(bitDic[item.Tag.ToString()][1]);
  2236. }
  2237. }
  2238. }
  2239. else if (this.listView2.Items.Count > 0)
  2240. {
  2241. ListViewItem item = this.listView2.Items[0];
  2242. if (bitDic.ContainsKey(item.Name))
  2243. {
  2244. bitList.Add(bitDic[item.Name][0]);
  2245. bitList.Add(bitDic[item.Name][1]);
  2246. }
  2247. else if (bitDic.ContainsKey(item.Tag.ToString()))
  2248. {
  2249. bitList.Add(bitDic[item.Tag.ToString()][0]);
  2250. bitList.Add(bitDic[item.Tag.ToString()][1]);
  2251. }
  2252. }
  2253. }
  2254. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
  2255. }
  2256. else
  2257. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  2258. }
  2259. /// <summary>
  2260. /// 晶界编辑
  2261. /// </summary>
  2262. /// <param name="sender"></param>
  2263. /// <param name="e"></param>
  2264. private void button3_Click(object sender, EventArgs e)
  2265. {
  2266. if (/*this.documentWorkspace.PhaseModels[1].choise == true && */this.documentWorkspace.PhaseModels[1].mat == null)
  2267. {
  2268. MessageBox.Show(PdnResources.GetString("Menu.Pleaseperformuctionfirst.text"));
  2269. return;
  2270. }
  2271. //1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界)
  2272. GrainBoundaryEditingDialog boundaryEditingDialog = new GrainBoundaryEditingDialog(this.appWorkspace, this.listView1.FocusedItem.Index, this.panel1.BackColor
  2273. , this.documentWorkspace.PhaseModels[1].mat.Clone());
  2274. boundaryEditingDialog.GuideClass = this.guideClass;
  2275. boundaryEditingDialog.SelectedItem = this.comboBox1.SelectedItem;
  2276. if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
  2277. {
  2278. this.documentWorkspace.PhaseModels[1].mat = boundaryEditingDialog.PhaseMat.Clone();
  2279. this.documentWorkspace.Refresh();
  2280. }
  2281. }
  2282. /// <summary>
  2283. /// 刷新晶粒编号
  2284. /// </summary>
  2285. /// <param name="sender"></param>
  2286. /// <param name="e"></param>
  2287. private void button4_Click(object sender, EventArgs e)
  2288. {
  2289. if (this.bitmap == null)
  2290. {
  2291. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  2292. return;
  2293. }
  2294. Getrains(linePointList, guideClass.RectangleFLine);
  2295. }
  2296. /// <summary>
  2297. /// 刷新晶粒编号
  2298. /// </summary>
  2299. /// <param name="pointFs"></param>
  2300. /// <param name="rectangleF"></param>
  2301. private void Getrains(List<PointF> pointFs, RectangleF rectangleF)
  2302. {
  2303. Mat OriginalPicture;// = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2304. if (this.checkBox1.Checked && this.documentWorkspace.PhaseModels[1].mat != null)
  2305. {
  2306. OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2307. Mat oldMat = this.documentWorkspace.PhaseModels[1].mat;
  2308. int Rows = oldMat.Rows;
  2309. int Cols = oldMat.Cols;
  2310. int[] point = new int[2];
  2311. //多通道图像的格式化
  2312. for (point[0] = 0; point[0] < Rows; point[0]++)
  2313. {
  2314. for (point[1] = 0; point[1] < Cols; point[1]++)
  2315. {
  2316. if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  2317. {
  2318. OriginalPicture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
  2319. }
  2320. }
  2321. }
  2322. Cv2.Erode(OriginalPicture, OriginalPicture, null, null, 1);
  2323. }
  2324. else if (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null)
  2325. {
  2326. OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2327. Mat oldMat = this.documentWorkspace.PhaseModels[0].mat;
  2328. int Rows = oldMat.Rows;
  2329. int Cols = oldMat.Cols;
  2330. int[] point = new int[2];
  2331. //多通道图像的格式化
  2332. for (point[0] = 0; point[0] < Rows; point[0]++)
  2333. {
  2334. for (point[1] = 0; point[1] < Cols; point[1]++)
  2335. {
  2336. if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  2337. {
  2338. OriginalPicture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
  2339. }
  2340. }
  2341. }
  2342. }
  2343. else
  2344. {
  2345. OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2346. mat.CopyTo(OriginalPicture);
  2347. }
  2348. Mat erzhi = OriginalPicture;
  2349. Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY);
  2350. Cv2.Threshold(erzhi, erzhi, 100, 255, ThresholdTypes.Binary);
  2351. //Cv2.AdaptiveThreshold(erzhi, erzhi, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 99, 10);
  2352. OpenCvSharp.Point[][] contours;
  2353. HierarchyIndex[] hierarchy;
  2354. Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  2355. List<OpenCvSharp.Point[]> pointss = new List<OpenCvSharp.Point[]>();
  2356. foreach (OpenCvSharp.Point[] contour in contours)
  2357. {
  2358. if (contour.Length < 100)
  2359. {
  2360. foreach (OpenCvSharp.Point point in contour)
  2361. {
  2362. erzhi.Set<byte>(point.Y, point.X, 255);
  2363. }
  2364. pointss.Add(contour);
  2365. }
  2366. }
  2367. Cv2.FillPoly(erzhi, pointss, new Scalar(255));
  2368. // 二次轮廓
  2369. Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  2370. // 计算所有轮廓质点
  2371. List<Point2d> massPoints = new List<Point2d>();
  2372. foreach (OpenCvSharp.Point[] contour in contours)
  2373. {
  2374. OpenCvSharp.Moments moments = new OpenCvSharp.Moments(contour, false);
  2375. massPoints.Add(new Point2d(moments.M10 / moments.M00, moments.M01 / moments.M00));
  2376. }
  2377. Mat labelMat = new Mat();
  2378. Mat stats = new Mat();
  2379. Mat centroids = new Mat();
  2380. // 连通域数量
  2381. int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
  2382. // 连通域质点
  2383. Dictionary<int, Point2d> keyValues = new Dictionary<int, Point2d>();
  2384. massLabelPoints.Clear();
  2385. foreach (var item in massPoints)
  2386. {
  2387. if (double.IsNaN(item.Y) || double.IsNaN(item.X))
  2388. {
  2389. continue;
  2390. }
  2391. int label = labelMat.At<int>((int)item.Y, (int)item.X);
  2392. if (0 <= label && label <= nccomps)
  2393. {
  2394. keyValues[label] = item;
  2395. }
  2396. }
  2397. // 矩形边线上的连通域
  2398. ArrayList nccompSelect = new ArrayList();
  2399. foreach (var pointF in pointFs)
  2400. {
  2401. if (labelMat.Width <= pointF.X || labelMat.Height <= pointF.Y || pointF.X < 0 || pointF.Y < 0)
  2402. {
  2403. continue;
  2404. }
  2405. ////###
  2406. ////判断是否在晶界上面
  2407. //Vec4b vec4B = OriginalPicture.At<Vec4b>((int)pointF.Y, (int)pointF.X);
  2408. //if (getGrainBoundryChecked() && vec4B.Item3 != 0 || getBinaryChecked() && vec4B.Item3 != 0 || !getGrainBoundryChecked() && !getBinaryChecked() && vec4B.Item0 == 0)
  2409. //{
  2410. // //temp.Set<Vec4b>((int)pointF.Y, (int)pointF.X, new Vec4b(0, 255, 0, 255));
  2411. // continue;//0925###19106
  2412. //}
  2413. int label = labelMat.At<int>((int)pointF.Y, (int)pointF.X);
  2414. if (!nccompSelect.Contains(label) && keyValues.ContainsKey(label) && keyValues[label] != null)
  2415. {
  2416. nccompSelect.Add(label);
  2417. if (keyValues.ContainsKey(label) && keyValues[label] != null)
  2418. massLabelPoints.Add(keyValues[label]);
  2419. // massLabelPoints.Add(new Point2d((int)pointF.X, (int)pointF.Y/*-1, -1*/));
  2420. //else
  2421. // massLabelPoints.Add(new Point2d((int)pointF.Y, (int)pointF.Y/*-1, -1*/));
  2422. }
  2423. }
  2424. // 矩形内的连通域
  2425. within = 0;
  2426. ArrayList inccompSelect = new ArrayList();
  2427. GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel;
  2428. // 圆形
  2429. if (grainSizeGuideStyleModel.circularGuideStyles != null)
  2430. {
  2431. foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles)
  2432. {
  2433. if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
  2434. {
  2435. foreach (var keyValue in keyValues)
  2436. {
  2437. //求点到圆心的距离
  2438. double c = BasicCalculationHelper.GetDistance(new PointF((float)keyValue.Value.X, (float)keyValue.Value.Y), new PointF(rectangleF.X + rectangleF.Width / 2, rectangleF.Y + rectangleF.Height / 2), 10);
  2439. if (!nccompSelect.Contains(keyValue.Key) && c < guideClass.Mat_lineDiameter / 2)
  2440. {
  2441. if (!inccompSelect.Contains(keyValue.Key))
  2442. {
  2443. within++;
  2444. inccompSelect.Add(keyValue.Key);
  2445. if (keyValue.Value != null)
  2446. massLabelPoints.Add(keyValue.Value);
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. }
  2453. // 矩形
  2454. if (grainSizeGuideStyleModel.rectangleGuideStyles != null)
  2455. {
  2456. foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles)
  2457. {
  2458. if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
  2459. {
  2460. foreach (var keyValue in keyValues)
  2461. {
  2462. if (!nccompSelect.Contains(keyValue.Key) && keyValue.Value.X > rectangleF.X && keyValue.Value.X < rectangleF.Right
  2463. && keyValue.Value.Y > rectangleF.Y && keyValue.Value.Y < rectangleF.Bottom)
  2464. {
  2465. if (!inccompSelect.Contains(keyValue.Key))
  2466. {
  2467. within++;
  2468. inccompSelect.Add(keyValue.Key);
  2469. if (keyValue.Value != null)
  2470. massLabelPoints.Add(keyValue.Value);
  2471. }
  2472. }
  2473. }
  2474. }
  2475. }
  2476. }
  2477. Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC4);
  2478. //Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC1);
  2479. Random rd = new Random();
  2480. List<Vec4b> colors = new List<Vec4b>(nccomps);
  2481. colors.Add(new Vec4b(0, 0, 0, 0));
  2482. for (int i = 1; i < nccomps; i++)
  2483. {
  2484. //colors.Add(new Vec3b(255, 255, 255));
  2485. colors.Add(new Vec4b(((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), 255));
  2486. }
  2487. for (int y = 0; y < temp.Rows; y++)
  2488. {
  2489. for (int x = 0; x < temp.Cols; x++)
  2490. {
  2491. int label = labelMat.At<int>(y, x);
  2492. if (nccompSelect.Contains(label))
  2493. temp.Set<Vec4b>(y, x, colors[label]);
  2494. if (inccompSelect.Contains(label))
  2495. temp.Set<Vec4b>(y, x, colors[label]);
  2496. //temp.Set<Vec4b>(y, x, new Vec4b(127, 127, 127, 127));
  2497. ////if (0 <= label && label <= nccomps)
  2498. ////{
  2499. //// temp.Set<Vec3b>(y, x, colors[label]);
  2500. ////}
  2501. }
  2502. }
  2503. //foreach (var item in massPoints)
  2504. //{
  2505. // if (double.IsNaN(item.Y) || double.IsNaN(item.X))
  2506. // {
  2507. // continue;
  2508. // }
  2509. // temp.Set<Vec4b>((int)item.Y, (int)item.X, new Vec4b(0, 0, 255, 255));
  2510. //}
  2511. ////Cv2.ImShow("temp", temp);
  2512. this.documentWorkspace.PhaseModels[2].mat = temp;
  2513. this.documentWorkspace.Refresh();
  2514. }
  2515. /// <summary>
  2516. /// 导出项目
  2517. /// </summary>
  2518. /// <param name="sender"></param>
  2519. /// <param name="e"></param>
  2520. private void button8_Click(object sender, EventArgs e)
  2521. {
  2522. if (this.checkBox2_0.Checked)
  2523. this.button1.PerformClick();
  2524. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  2525. {
  2526. Instrument.ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, "Menu.DedicatedAnalysis.BlackMetal.GrainSize.Text", this.analyzeSettingModel.savePath);
  2527. if (nodeItem == null) return;
  2528. //获取word书签与excel单元格的关系,以字典方式存储
  2529. List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  2530. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  2531. if (mic_module_infos != null && mic_module_infos.Count > 0)
  2532. {
  2533. foreach (mic_module_infos info in mic_module_infos)
  2534. {
  2535. tagInfos.Add(info.tag_name, info.cell_position);
  2536. }
  2537. }
  2538. //分析结果
  2539. List<List<string>> analysisContent = new List<List<string>>();
  2540. analysisContent.Add(contentHead);
  2541. foreach (DataGridViewRow item in this.dataGridView4.Rows)
  2542. {
  2543. List<string> content = new List<string>();
  2544. for (int i = 0; i < contentHead.Count; i++)
  2545. {
  2546. content.Add(item.Cells[i].Value.ToString());
  2547. }
  2548. analysisContent.Add(content);
  2549. }
  2550. //图片
  2551. bitList = new List<Bitmap>();
  2552. //中间数据
  2553. List<ExportProjectModel> exportModel = new List<ExportProjectModel>();
  2554. if (this.allShow)
  2555. {
  2556. foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
  2557. {
  2558. bitList.Add(kv.Value[0]);
  2559. bitList.Add(kv.Value[1]);
  2560. }
  2561. //中间数据
  2562. foreach (ExportProjectModel model in this.tempDataModel)
  2563. {
  2564. ExportProjectModel tempModel = new ExportProjectModel();
  2565. tempModel.tagName = model.tagName;
  2566. tempModel.picName = model.picName;
  2567. tempModel.dataList = model.dataList;
  2568. exportModel.Add(tempModel);
  2569. }
  2570. }
  2571. else
  2572. {
  2573. if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  2574. {
  2575. foreach (ListViewItem item in this.listView2.SelectedItems)
  2576. {
  2577. if (bitDic.ContainsKey(item.Name))
  2578. {
  2579. bitList.Add(bitDic[item.Name][0]);
  2580. bitList.Add(bitDic[item.Name][1]);
  2581. }
  2582. else if (bitDic.ContainsKey(item.Tag.ToString()))
  2583. {
  2584. bitList.Add(bitDic[item.Tag.ToString()][0]);
  2585. bitList.Add(bitDic[item.Tag.ToString()][1]);
  2586. }
  2587. }
  2588. //中间数据
  2589. foreach (ListViewItem rowItem in this.listView2.SelectedItems)
  2590. {
  2591. foreach (ExportProjectModel model in this.tempDataModel)
  2592. {
  2593. if (model.tagName.Equals(rowItem.Name))
  2594. {
  2595. ExportProjectModel tempModel = new ExportProjectModel();
  2596. tempModel.tagName = model.tagName;
  2597. tempModel.picName = model.picName;
  2598. tempModel.dataList = model.dataList;
  2599. exportModel.Add(tempModel);
  2600. break;
  2601. }
  2602. else if (model.tagName.Equals(rowItem.Tag.ToString()))
  2603. {
  2604. ExportProjectModel tempModel = new ExportProjectModel();
  2605. tempModel.tagName = model.tagName;
  2606. tempModel.picName = model.picName;
  2607. tempModel.dataList = model.dataList;
  2608. exportModel.Add(tempModel);
  2609. break;
  2610. }
  2611. }
  2612. }
  2613. }
  2614. else if (this.listView2.Items.Count > 0)
  2615. {
  2616. ListViewItem rowItem = this.listView2.Items[0];
  2617. if (bitDic.ContainsKey(rowItem.Name))
  2618. {
  2619. bitList.Add(bitDic[rowItem.Name][0]);
  2620. bitList.Add(bitDic[rowItem.Name][1]);
  2621. }
  2622. else if (bitDic.ContainsKey(rowItem.Tag.ToString()))
  2623. {
  2624. bitList.Add(bitDic[rowItem.Tag.ToString()][0]);
  2625. bitList.Add(bitDic[rowItem.Tag.ToString()][1]);
  2626. }
  2627. //中间数据
  2628. {
  2629. foreach (ExportProjectModel model in this.tempDataModel)
  2630. {
  2631. if (model.tagName.Equals(rowItem.Name))
  2632. {
  2633. ExportProjectModel tempModel = new ExportProjectModel();
  2634. tempModel.tagName = model.tagName;
  2635. tempModel.picName = model.picName;
  2636. tempModel.dataList = model.dataList;
  2637. exportModel.Add(tempModel);
  2638. break;
  2639. }
  2640. else if (model.tagName.Equals(rowItem.Tag.ToString()))
  2641. {
  2642. ExportProjectModel tempModel = new ExportProjectModel();
  2643. tempModel.tagName = model.tagName;
  2644. tempModel.picName = model.picName;
  2645. tempModel.dataList = model.dataList;
  2646. exportModel.Add(tempModel);
  2647. break;
  2648. }
  2649. }
  2650. }
  2651. }
  2652. }
  2653. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, exportModel, bitList, tagInfos, nodeItem.path, nodeItem.code);
  2654. //保存项目信息到数据库
  2655. this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, nodeItem);
  2656. }
  2657. else
  2658. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  2659. }
  2660. /// <summary>
  2661. /// 全部显示
  2662. /// </summary>
  2663. /// <param name="sender"></param>
  2664. /// <param name="e"></param>
  2665. private void button11_Click(object sender, EventArgs e)
  2666. {
  2667. if (this.listView2.Items.Count > 0)
  2668. {
  2669. this.button11.Visible = false;
  2670. this.button16.Visible = true;
  2671. this.button16.Focus();
  2672. this.allShow = true;
  2673. this.dataGridView4.Rows.Clear();
  2674. for (int i = 0; i < this.dataTables.Count; i++)
  2675. {
  2676. DataGridViewRow dgvr = new DataGridViewRow();
  2677. foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
  2678. {
  2679. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  2680. }
  2681. for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
  2682. {
  2683. dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString();
  2684. }
  2685. this.dataGridView4.Rows.Add(dgvr);
  2686. }
  2687. }
  2688. else
  2689. {
  2690. MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
  2691. }
  2692. }
  2693. /// <summary>
  2694. /// 取消全部显示
  2695. /// </summary>
  2696. /// <param name="sender"></param>
  2697. /// <param name="e"></param>
  2698. private void button16_Click(object sender, EventArgs e)
  2699. {
  2700. this.button11.Visible = true;
  2701. this.button16.Visible = false;
  2702. this.button11.Focus();
  2703. this.allShow = false;
  2704. if (this.listView2.SelectedItems.Count <= 0)
  2705. return;
  2706. this.dataGridView4.Rows.Clear();
  2707. for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  2708. {
  2709. System.Data.DataTable dataTable1 = new System.Data.DataTable();
  2710. foreach (var dataTable in this.dataTables)
  2711. {
  2712. if (this.listView2.SelectedItems.Count > 0)
  2713. {
  2714. if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  2715. dataTable1 = dataTable;
  2716. }
  2717. else
  2718. {
  2719. if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
  2720. dataTable1 = dataTable;
  2721. }
  2722. }
  2723. DataGridViewRow dgvr = new DataGridViewRow();
  2724. foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
  2725. {
  2726. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  2727. }
  2728. for (int c = 0; c < dataTable1.Columns.Count; c++)
  2729. {
  2730. dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
  2731. }
  2732. this.dataGridView4.Rows.Add(dgvr);
  2733. }
  2734. }
  2735. /// <summary>
  2736. /// 分析结果删除
  2737. /// </summary>
  2738. /// <param name="sender"></param>
  2739. /// <param name="e"></param>
  2740. private void button12_Click(object sender, EventArgs e)
  2741. {
  2742. if(this.listView2.Items.Count > 0)
  2743. {
  2744. if(this.listView2.SelectedItems.Count > 0)
  2745. {
  2746. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  2747. if (dr == DialogResult.OK)
  2748. {
  2749. if (this.listView2.SelectedItems.Count <= 0)
  2750. return;
  2751. for (int i = this.listView2.SelectedItems.Count - 1; i >= 0; i--)
  2752. {
  2753. int selectIndex = this.listView2.SelectedItems[i].Index;
  2754. foreach (var dataTable in this.dataTables)
  2755. {
  2756. if (dataTable.TableName.Equals(this.listView2.SelectedItems[i].Tag))
  2757. {
  2758. this.dataTables.Remove(dataTable);
  2759. break;
  2760. }
  2761. }
  2762. //1009###18809 //##to test
  2763. if (bitDic.ContainsKey((string)this.listView2.SelectedItems[i].Tag))
  2764. bitDic.Remove((string)this.listView2.SelectedItems[i].Tag);
  2765. foreach (ExportProjectModel model in this.tempDataModel)
  2766. {
  2767. if (model.tagName.Equals((string)this.listView2.SelectedItems[i].Tag))
  2768. {
  2769. this.tempDataModel.Remove(model);
  2770. break;
  2771. }
  2772. }
  2773. this.listView2.Items.RemoveAt(selectIndex);
  2774. }
  2775. if (this.listView2.Items.Count == 0)
  2776. this.dataGridView4.Rows.Clear();
  2777. else
  2778. {
  2779. //if (selectIndex == 0)
  2780. // this.listView2.Items[0].Selected = true;
  2781. //else
  2782. // this.listView2.Items[selectIndex - 1].Selected = true;
  2783. RefreshDataGridView4();
  2784. }
  2785. }
  2786. }
  2787. else
  2788. {
  2789. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!");
  2790. }
  2791. }
  2792. else
  2793. {
  2794. MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
  2795. }
  2796. }
  2797. /// <summary>
  2798. /// 刷新分析结果数据
  2799. /// </summary>
  2800. private void RefreshDataGridView4()
  2801. {
  2802. if (!this.allShow)
  2803. {
  2804. if (this.listView2.SelectedItems.Count > 0)
  2805. {
  2806. this.dataGridView4.Rows.Clear();
  2807. for (int j = 0; j < this.listView2.SelectedItems.Count; j++)
  2808. {
  2809. int dataTableIndex = 0;
  2810. for (int i = 0; i < this.dataTables.Count; i++)
  2811. {
  2812. if (this.dataTables[i].TableName.Equals(this.listView2.SelectedItems[j].Tag))
  2813. dataTableIndex = i;
  2814. }
  2815. if (this.dataTables[dataTableIndex].Rows.Count > 0)
  2816. {
  2817. for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
  2818. {
  2819. DataGridViewRow dgvr = new DataGridViewRow();
  2820. foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
  2821. {
  2822. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  2823. }
  2824. for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
  2825. {
  2826. if (c == 2 || c == 5)
  2827. dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  2828. this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  2829. else
  2830. dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  2831. }
  2832. this.dataGridView4.Rows.Add(dgvr);
  2833. }
  2834. }
  2835. }
  2836. }
  2837. else if (this.listView2.Items.Count > 0)
  2838. {
  2839. this.dataGridView4.Rows.Clear();
  2840. var firstTag = this.listView2.Items[0].Tag;
  2841. int dataTableIndex = 0;
  2842. for (int i = 0; i < this.dataTables.Count; i++)
  2843. {
  2844. if (this.dataTables[i].TableName.Equals(firstTag))
  2845. dataTableIndex = i;
  2846. }
  2847. if (this.dataTables[dataTableIndex].Rows.Count > 0)
  2848. {
  2849. for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
  2850. {
  2851. DataGridViewRow dgvr = new DataGridViewRow();
  2852. foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
  2853. {
  2854. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  2855. }
  2856. for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
  2857. {
  2858. if (c == 2 || c == 5)
  2859. dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  2860. this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  2861. else
  2862. dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  2863. }
  2864. this.dataGridView4.Rows.Add(dgvr);
  2865. }
  2866. }
  2867. }
  2868. }
  2869. else
  2870. {
  2871. this.dataGridView4.Rows.Clear();
  2872. DataTable dataTable = new DataTable();
  2873. for (int i = this.dataTables.Count - 1; i >= 0; i--)
  2874. {
  2875. dataTable = this.dataTables[i];
  2876. for (int r = 0; r < dataTable.Rows.Count; r++)
  2877. {
  2878. DataGridViewRow dgvr = new DataGridViewRow();
  2879. foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
  2880. {
  2881. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  2882. }
  2883. for (int c = 0; c < dataTable.Columns.Count; c++)
  2884. {
  2885. if (c == 2 || c == 5)
  2886. dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" :
  2887. dataTable.Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  2888. else
  2889. dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString();
  2890. }
  2891. this.dataGridView4.Rows.Add(dgvr);
  2892. }
  2893. }
  2894. }
  2895. }
  2896. /// <summary>
  2897. /// 小数位数
  2898. /// </summary>
  2899. /// <param name="sender"></param>
  2900. /// <param name="e"></param>
  2901. private void numericUpDown1_0_ValueChanged(object sender, EventArgs e)
  2902. {
  2903. this.RefreshDataGridView4();
  2904. //this.dec = Convert.ToInt32(this.numericUpDown1.Value);
  2905. //if(this.dataTables.Count > 0)
  2906. //{
  2907. // foreach (var dataTable in this.dataTables)
  2908. // {
  2909. // }
  2910. //}
  2911. }
  2912. private Double GetNumberOfGrains(List<PointF> pointFs, RectangleF rectangleF)
  2913. {
  2914. Mat OriginalPicture;// = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2915. if (this.checkBox1.Checked && this.documentWorkspace.PhaseModels[1].mat != null)
  2916. {
  2917. OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2918. Mat oldMat = this.documentWorkspace.PhaseModels[1].mat;
  2919. int Rows = oldMat.Rows;
  2920. int Cols = oldMat.Cols;
  2921. int[] point = new int[2];
  2922. //多通道图像的格式化
  2923. for (point[0] = 0; point[0] < Rows; point[0]++)
  2924. {
  2925. for (point[1] = 0; point[1] < Cols; point[1]++)
  2926. {
  2927. if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  2928. {
  2929. OriginalPicture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
  2930. }
  2931. }
  2932. }
  2933. Cv2.Erode(OriginalPicture, OriginalPicture, null, null, 1);
  2934. }
  2935. else if (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null)
  2936. {
  2937. OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2938. Mat oldMat = this.documentWorkspace.PhaseModels[0].mat;
  2939. int Rows = oldMat.Rows;
  2940. int Cols = oldMat.Cols;
  2941. int[] point = new int[2];
  2942. //多通道图像的格式化
  2943. for (point[0] = 0; point[0] < Rows; point[0]++)
  2944. {
  2945. for (point[1] = 0; point[1] < Cols; point[1]++)
  2946. {
  2947. if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  2948. {
  2949. OriginalPicture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
  2950. }
  2951. }
  2952. }
  2953. }
  2954. else
  2955. {
  2956. OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
  2957. mat.CopyTo(OriginalPicture);
  2958. }
  2959. Mat erzhi = OriginalPicture;
  2960. Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY);
  2961. Cv2.Threshold(erzhi, erzhi, 100, 255, ThresholdTypes.Binary);
  2962. //Cv2.AdaptiveThreshold(erzhi, erzhi, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 99, 10);
  2963. OpenCvSharp.Point[][] contours;
  2964. HierarchyIndex[] hierarchy;
  2965. Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  2966. //Cv2.ImWrite("erzhi1.tif", erzhi.CvtColor(ColorConversionCodes.GRAY2BGR));
  2967. List<OpenCvSharp.Point[]> pointss = new List<OpenCvSharp.Point[]>();
  2968. foreach (OpenCvSharp.Point[] contour in contours)
  2969. {
  2970. if (contour.Length < 100)
  2971. {
  2972. foreach (OpenCvSharp.Point point in contour)
  2973. {
  2974. erzhi.Set<byte>(point.Y, point.X, 255);
  2975. }
  2976. pointss.Add(contour);
  2977. }
  2978. }
  2979. Cv2.FillPoly(erzhi, pointss, new Scalar(255));
  2980. // 二次轮廓
  2981. Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  2982. // 计算所有轮廓质点
  2983. List<Point2d> massPoints = new List<Point2d>();
  2984. foreach (OpenCvSharp.Point[] contour in contours)
  2985. {
  2986. OpenCvSharp.Moments moments = new OpenCvSharp.Moments(contour, false);
  2987. massPoints.Add(new Point2d(moments.M10 / moments.M00, moments.M01 / moments.M00));
  2988. }
  2989. Mat labelMat = new Mat();
  2990. Mat stats = new Mat();
  2991. Mat centroids = new Mat();
  2992. // 连通域数量
  2993. int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
  2994. //Cv2.ImWrite("erzhi2.tif", labelMat);
  2995. //Cv2.ImWrite("erzhi3.tif", stats);
  2996. //Cv2.ImWrite("erzhi4.tif", centroids);
  2997. // 连通域质点
  2998. Dictionary<int, Point2d> keyValues = new Dictionary<int, Point2d>();
  2999. massLabelPoints.Clear();
  3000. foreach (var item in massPoints)
  3001. {
  3002. if (double.IsNaN(item.Y) || double.IsNaN(item.X))
  3003. {
  3004. continue;
  3005. }
  3006. int label = labelMat.At<int>((int)item.Y, (int)item.X);
  3007. if (0 <= label && label <= nccomps)
  3008. {
  3009. keyValues[label] = item;
  3010. }
  3011. }
  3012. // 矩形边线上的连通域
  3013. ArrayList nccompSelect = new ArrayList();
  3014. foreach (var pointF in pointFs)
  3015. {
  3016. if (labelMat.Width <= pointF.X || labelMat.Height <= pointF.Y || pointF.X < 0 || pointF.Y < 0)//0924###19092
  3017. {
  3018. continue;
  3019. }
  3020. ////判断是否在晶界上面//###
  3021. //Vec4b vec4B = OriginalPicture.At<Vec4b>((int)pointF.Y, (int)pointF.X);
  3022. //if (getGrainBoundryChecked() && vec4B.Item3 != 0 || getBinaryChecked() && vec4B.Item3 != 0 || !getGrainBoundryChecked() && !getBinaryChecked() && vec4B.Item0 == 0)
  3023. //{
  3024. // //temp.Set<Vec4b>((int)pointF.Y, (int)pointF.X, new Vec4b(0, 255, 0, 255));
  3025. // continue;//0925###19106
  3026. //}
  3027. int label = labelMat.At<int>((int)pointF.Y, (int)pointF.X);
  3028. if (!nccompSelect.Contains(label) && keyValues.ContainsKey(label) && keyValues[label] != null)
  3029. {
  3030. nccompSelect.Add(label);
  3031. if (keyValues.ContainsKey(label) && keyValues[label] != null)
  3032. massLabelPoints.Add(keyValues[label]);
  3033. // massLabelPoints.Add(new Point2d((int)pointF.X, (int)pointF.Y/*-1, -1*/));
  3034. //else
  3035. // massLabelPoints.Add(new Point2d((int)pointF.Y, (int)pointF.Y/*-1, -1*/));
  3036. }
  3037. }
  3038. // 矩形内的连通域
  3039. within = 0;
  3040. ArrayList inccompSelect = new ArrayList();
  3041. GrainSizeGuideAreaMethodModel grainSizeGuideStyleModel = guideClass.GrainSizeGuideAreaMethodModel;
  3042. // 圆形
  3043. if (grainSizeGuideStyleModel.circularGuideStyles != null)
  3044. {
  3045. foreach (var circularGuideStyle in grainSizeGuideStyleModel.circularGuideStyles)
  3046. {
  3047. if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
  3048. {
  3049. foreach (var keyValue in keyValues)
  3050. {
  3051. //求点到圆心的距离
  3052. double c = BasicCalculationHelper.GetDistance(new PointF((float)keyValue.Value.X, (float)keyValue.Value.Y), new PointF(rectangleF.X + rectangleF.Width / 2, rectangleF.Y + rectangleF.Height / 2), 10);
  3053. if (!nccompSelect.Contains(keyValue.Key) && c < guideClass.Mat_lineDiameter / 2)
  3054. {
  3055. if (!inccompSelect.Contains(keyValue.Key))
  3056. {
  3057. within++;
  3058. inccompSelect.Add(keyValue.Key);
  3059. if (keyValue.Value != null)
  3060. massLabelPoints.Add(keyValue.Value);
  3061. }
  3062. }
  3063. }
  3064. }
  3065. }
  3066. }
  3067. // 矩形
  3068. if (grainSizeGuideStyleModel.rectangleGuideStyles != null)
  3069. {
  3070. foreach (var rectangleGuideStyle in grainSizeGuideStyleModel.rectangleGuideStyles)
  3071. {
  3072. if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
  3073. {
  3074. foreach (var keyValue in keyValues)
  3075. {
  3076. if (!nccompSelect.Contains(keyValue.Key) && keyValue.Value.X > rectangleF.X && keyValue.Value.X < rectangleF.Right
  3077. && keyValue.Value.Y > rectangleF.Y && keyValue.Value.Y < rectangleF.Bottom)
  3078. {
  3079. if (!inccompSelect.Contains(keyValue.Key))
  3080. {
  3081. within++;
  3082. inccompSelect.Add(keyValue.Key);
  3083. if (keyValue.Value != null)
  3084. massLabelPoints.Add(keyValue.Value);
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. }
  3091. Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC4);
  3092. //Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC1);
  3093. Random rd = new Random();
  3094. List<Vec4b> colors = new List<Vec4b>(nccomps);
  3095. colors.Add(new Vec4b(0, 0, 0, 0));
  3096. for (int i = 1; i < nccomps; i++)
  3097. {
  3098. //colors.Add(new Vec3b(255, 255, 255));
  3099. colors.Add(new Vec4b(((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), 255));
  3100. }
  3101. for (int y = 0; y < temp.Rows; y++)
  3102. {
  3103. for (int x = 0; x < temp.Cols; x++)
  3104. {
  3105. int label = labelMat.At<int>(y, x);
  3106. if (nccompSelect.Contains(label))
  3107. temp.Set<Vec4b>(y, x, colors[label]);
  3108. if (inccompSelect.Contains(label))
  3109. temp.Set<Vec4b>(y, x, colors[label]);
  3110. //temp.Set<Vec4b>(y, x, new Vec4b(127, 127, 127, 127));
  3111. ////if (0 <= label && label <= nccomps)
  3112. ////{
  3113. //// temp.Set<Vec3b>(y, x, colors[label]);
  3114. ////}
  3115. }
  3116. }
  3117. //foreach (var item in massPoints)
  3118. //{
  3119. // if (double.IsNaN(item.Y) || double.IsNaN(item.X))
  3120. // {
  3121. // continue;
  3122. // }
  3123. // temp.Set<Vec4b>((int)item.Y, (int)item.X, new Vec4b(0, 0, 255, 255));
  3124. //}
  3125. //Cv2.ImWrite("erzhi5.tif", temp);
  3126. ////Cv2.ImShow("temp", temp);
  3127. this.documentWorkspace.PhaseModels[2].mat = temp;
  3128. this.documentWorkspace.Refresh();
  3129. return within + (double)nccompSelect.Count / 2;
  3130. }
  3131. /// <summary>
  3132. /// 使用圆心及半径得到圆的轮廓
  3133. /// </summary>
  3134. /// <param name="center">圆心</param>
  3135. /// <param name="radius">半径</param>
  3136. /// <returns></returns>
  3137. public OpenCvSharp.Point[] roundOutline(Point center, int radius)
  3138. {
  3139. if (radius < 1)
  3140. radius = 1;
  3141. Mat mat = new Mat((int)(radius * 2.1), (int)(radius * 2.1), MatType.CV_8UC1, new Scalar(0, 0, 0));
  3142. OpenCvSharp.Point point = new OpenCvSharp.Point(mat.Cols / 2, mat.Rows / 2);
  3143. Cv2.Circle(mat, point, radius, new Scalar(255, 255, 255), -1);
  3144. OpenCvSharp.Point[][] contours;
  3145. HierarchyIndex[] hierarchy;
  3146. Cv2.FindContours(mat, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  3147. OpenCvSharp.Point[] roundOutline = contours[0];
  3148. for (int i = 0; i < roundOutline.Length; i++)
  3149. {
  3150. roundOutline[i].X = roundOutline[i].X - point.X + center.X;
  3151. roundOutline[i].Y = roundOutline[i].Y - point.Y + center.Y;
  3152. }
  3153. return roundOutline;
  3154. }
  3155. #region 内部类
  3156. internal class LocalListViewItem
  3157. {
  3158. public DocumentWorkspace Value { get; }
  3159. public string Display { get; }
  3160. public LocalListViewItem(DocumentWorkspace Value, string Display)
  3161. {
  3162. this.Value = Value;
  3163. this.Display = Display;
  3164. }
  3165. }
  3166. internal class DocumentItem
  3167. {
  3168. public Bitmap bitmap;
  3169. public GraphicsList graphicsList;
  3170. public List<PhaseModel> phaseModels;
  3171. //public AnalysisResult analysisResult;
  3172. public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List<PhaseModel> phaseModels)
  3173. {
  3174. this.bitmap = bitmap;
  3175. this.graphicsList = graphicsList;
  3176. this.phaseModels = phaseModels;
  3177. }
  3178. }
  3179. #endregion
  3180. }
  3181. }