GrainSizeBoundryEditDialog.cs 154 KB

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