PetroleumGeologyStandardDialog.cs 170 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798
  1. using Microsoft.Office.Interop.Excel;
  2. using OpenCvSharp;
  3. using PaintDotNet.Annotation;
  4. using PaintDotNet.Annotation.Enum;
  5. using PaintDotNet.Base;
  6. using PaintDotNet.Base.CommTool;
  7. using PaintDotNet.Base.Functionodel;
  8. using PaintDotNet.Base.SettingModel;
  9. using PaintDotNet.CustomControl;
  10. using PaintDotNet.Data.Action;
  11. using PaintDotNet.Data.Param;
  12. using PaintDotNet.DbOpreate.DbModel;
  13. using PaintDotNet.Instrument;
  14. using System;
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. using System.ComponentModel;
  18. using System.Data;
  19. using System.Drawing;
  20. using System.Drawing.Drawing2D;
  21. using System.IO;
  22. using System.Linq;
  23. using System.Windows.Forms;
  24. using Application = System.Windows.Forms.Application;
  25. using Button = System.Windows.Forms.Button;
  26. using CheckBox = System.Windows.Forms.CheckBox;
  27. using DataTable = System.Data.DataTable;
  28. using Font = System.Drawing.Font;
  29. using GroupBox = System.Windows.Forms.GroupBox;
  30. using Label = System.Windows.Forms.Label;
  31. using Point = System.Drawing.Point;
  32. using Rectangle = System.Drawing.Rectangle;
  33. namespace PaintDotNet.DedicatedAnalysis.PetroleumGeology.SYT6103
  34. {
  35. internal class PetroleumGeologyStandardDialog : PdnBaseForm
  36. {
  37. #region 属性
  38. /// <summary>
  39. /// 主控件
  40. /// </summary>
  41. protected AppWorkspace appWorkspace;
  42. /// <summary>
  43. /// 公共按钮
  44. /// </summary>
  45. private CommonControlButtons commonControlButtons;
  46. /// <summary>
  47. /// 图像面板
  48. /// </summary>
  49. protected DocumentWorkspaceWindow documentWorkspace;
  50. /// <summary>
  51. /// 当前选择的图片
  52. /// </summary>
  53. protected Bitmap bitmap;
  54. /// <summary>
  55. /// 当前选择的图片
  56. /// </summary>
  57. protected Mat matOrg;
  58. protected Mat matGeology;
  59. /// <summary>
  60. /// 选择标尺的物理长度(1倍下的 微米/像素)
  61. /// </summary>
  62. double physical_length = 1;
  63. protected string oldSelectItem;
  64. public bool comboboxChange = true;
  65. /// <summary>
  66. /// 图形位置
  67. /// </summary>
  68. private PointF m_StartPoint = Point.Empty;
  69. private PointF m_EndPoint = Point.Empty;
  70. protected bool m_canMove;
  71. private bool addPoint = false;
  72. //二值化集成1
  73. protected BinaryClass binaryClass;
  74. protected int menuId;
  75. protected string menuName;
  76. /// <summary>
  77. /// 调色板
  78. /// </summary>
  79. private ColorsForm colorsFormGrid;
  80. /// <summary>
  81. /// 当前选择的颜色块
  82. /// </summary>
  83. private Panel colorsPanel;
  84. //分析结果列表的头标题
  85. /// <summary>
  86. /// PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.Tools.GridLine.Text"), "网格面积", PdnResources.GetString("Menu.Numberofgrains.text"), PdnResources.GetString("Menu.Averagegrainsizegrade.text")
  87. /// </summary>
  88. List<string> contentHead;
  89. /// <summary>
  90. /// 保存用于生成报告的图片
  91. /// </summary>
  92. protected List<Bitmap> bitList;
  93. /// <summary>
  94. /// 储存点击保存结果后的所有原图与分析图
  95. /// </summary>
  96. protected Dictionary<string, List<Bitmap>> bitDic = new Dictionary<string, List<Bitmap>>();
  97. /// <summary>
  98. /// 中间数据
  99. /// </summary>
  100. protected List<ExportProjectModel> tempDataModel = new List<ExportProjectModel>();
  101. /// <summary>
  102. /// 分析结果暂存
  103. /// </summary>
  104. protected List<System.Data.DataTable> dataTables = new List<System.Data.DataTable>();
  105. /// <summary>
  106. /// 孔隙的面积周边长等数据
  107. /// </summary>
  108. protected List<List<int>> lstAttribute = new List<List<int>>();
  109. /// <summary>
  110. /// 孔隙的面积周边长等数据与tag绑定关系并缓存起来
  111. /// </summary>
  112. protected Dictionary<string, List<List<int>>> lstAttriDict = new Dictionary<string, List<List<int>>>();
  113. /// <summary>
  114. /// 多图平均结果暂存
  115. /// </summary>
  116. protected List<System.Data.DataTable> dataPerTables = new List<System.Data.DataTable>();
  117. /// <summary>
  118. /// 全部显示
  119. /// </summary>
  120. protected bool allShow = false;
  121. protected int defaultIndex = -1;
  122. #endregion
  123. #region 组件
  124. private GroupBox groupBox_operating;
  125. protected GroupBox groupBox_img;
  126. private ListView lstView_img;
  127. private ImageList imageList_img;
  128. private IContainer components;
  129. protected GroupBox groupBox_review;
  130. protected GroupBox groupBox_report;
  131. private Label label_resultPrecision;
  132. private Button button_exportResults;
  133. private Button button_generateReport;
  134. protected GroupBox groupBox6groupBox_analysisResult2;
  135. protected GroupBox groupBox_analysisResult1;
  136. private ToolTip toolTip_GrainSizeDetails;
  137. private Button button_setting;
  138. protected CheckBox checkBox_generateReport_opensetting;
  139. protected DataGridView dataGridView2;
  140. protected ListView listView2;
  141. private Button button16;
  142. private Button button12;
  143. private Button button11;
  144. protected NumericUpDown numericUpDown1_0;
  145. private Button button1;
  146. protected DataGridView dataGridView1;
  147. private DataGridViewTextBoxColumn Column1;
  148. private DataGridViewTextBoxColumn Column2;
  149. private DataGridViewTextBoxColumn Column3;
  150. private DataGridViewTextBoxColumn Column4;
  151. private DataGridViewTextBoxColumn Column5;
  152. private DataGridViewTextBoxColumn Column6;
  153. private DataGridViewTextBoxColumn Column7;
  154. private DataGridViewTextBoxColumn Column8;
  155. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
  156. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
  157. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
  158. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
  159. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;
  160. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn6;
  161. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn7;
  162. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn8;
  163. private BinaryControl bc;
  164. private Button btn_saveresult;
  165. #endregion
  166. #region 构造函数
  167. public PetroleumGeologyStandardDialog(AppWorkspace appWorkspace, string dialogText, bool isAreaType, PdnMenuItem menuItem)
  168. {
  169. this.appWorkspace = appWorkspace;
  170. this.Text = dialogText;
  171. this.Icon = PdnInfo.AppIcon;
  172. this.Load += new System.EventHandler(this.PetroleumGeologyStandardDialog_Load);
  173. this.colorsFormGrid = new ColorsForm();
  174. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  175. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  176. //Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
  177. //physical_length = measurementUnitDictionary[MeasurementUnit.Micron];
  178. InitializeComponent();
  179. InitializeLanguageText();
  180. InitializeBC();
  181. contentHead = new List<string>() { PdnResources.GetString("Menu.picture.Text"), PdnResources.GetString("Menu.view.text"), PdnResources.GetString("Menu.Dedicatedanalysis.Non-ferrousmetals.serialnumber.text"), PdnResources.GetString("Menu.Theporediameter.text"), PdnResources.GetString("Menu.Apparentporeratiosurface.text"), PdnResources.GetString("Menu.Shapefactor.text"), PdnResources.GetString("Menu.Porethroatthan.text"), PdnResources.GetString("Menu.Coordinationnumber.text") };
  182. this.menuId = menuItem.MenuId;
  183. this.menuName = menuItem.Text;
  184. binaryClass = new BinaryClass(menuId);
  185. Initialize();
  186. SubclassInitialize();
  187. //二值化集成2
  188. bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
  189. binaryClass.createDocumentItems(new string[] { PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"), PdnResources.GetString("Menu.Grainboundarytoreproduce.text"), PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text") }
  190. , this.bc, this.appWorkspace, this.documentWorkspace, this.lstView_img);//初始化相的工作结构
  191. binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件
  192. //初始化头
  193. this.listView2.View = View.Details;
  194. ColumnHeader header0 = new ColumnHeader();
  195. header0.Text = "";
  196. header0.Width = 180;
  197. this.listView2.Columns.Add(header0);
  198. this.button11.Visible = true;
  199. this.button16.Visible = false;
  200. SetAnalyzeModelFromXml(getTemplateName());
  201. }
  202. public PetroleumGeologyStandardDialog()
  203. {
  204. //this.Icon = PdnInfo.AppIcon;
  205. InitializeComponent();
  206. /*InitializeLanguageText();
  207. InitializeBC();
  208. binaryClass = new BinaryClass();*/
  209. }
  210. #endregion
  211. private void InitializeLanguageText()
  212. {
  213. this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
  214. this.dataGridViewTextBoxColumn8.HeaderText = PdnResources.GetString("Menu.Averageporecoordinationnumber.text");
  215. this.dataGridViewTextBoxColumn7.HeaderText = PdnResources.GetString("Menu.Porediameterseparationcoefficient.text");
  216. this.dataGridViewTextBoxColumn6.HeaderText = PdnResources.GetString("Menu.Homogeneouscoefficient.text");
  217. this.dataGridViewTextBoxColumn5.HeaderText = PdnResources.GetString("Menu.Meanporethroatratio.text");
  218. this.dataGridViewTextBoxColumn4.HeaderText = PdnResources.GetString("Menu.Averageporeshapefactor.text");
  219. this.dataGridViewTextBoxColumn3.HeaderText = PdnResources.GetString("Menu.Meanapparentporeratiosurface.text");
  220. this.dataGridViewTextBoxColumn2.HeaderText = PdnResources.GetString("Menu.Meanporediameter.text");
  221. this.dataGridViewTextBoxColumn1.HeaderText = PdnResources.GetString("Menu.Facerate.text");
  222. this.button_generateReport.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text");
  223. this.button_exportResults.Text = PdnResources.GetString("Menu.Exportresults.text");
  224. this.label_resultPrecision.Text = PdnResources.GetString("Menu.Decimal.text")+":";
  225. this.button1.Text = PdnResources.GetString("Menu.Exportproject.text");
  226. this.groupBox_review.Text = PdnResources.GetString("Menu.Preview.text");
  227. this.groupBox_img.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text");
  228. this.btn_saveresult.Text = PdnResources.GetString("Menu.Saveresult.text");
  229. this.button_setting.Text = PdnResources.GetString("Menu.Setting.Text");
  230. this.checkBox_generateReport_opensetting.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text");
  231. this.groupBox_operating.Text = PdnResources.GetString("Menu.operation.text");
  232. this.button12.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  233. this.button16.Text = PdnResources.GetString("Menu.Cancelshowall.text");
  234. this.button11.Text = PdnResources.GetString("Menu.Showall.text");
  235. this.groupBox_analysisResult1.Text = PdnResources.GetString("Menu.Analysisresult.text");
  236. this.Column8.HeaderText = PdnResources.GetString("Menu.Coordinationnumber.text");
  237. this.Column7.HeaderText = PdnResources.GetString("Menu.Porethroatthan.text");
  238. this.Column6.HeaderText = PdnResources.GetString("Menu.Shapefactor.text");
  239. this.Column5.HeaderText = PdnResources.GetString("Menu.Apparentporeratiosurface.text");
  240. this.Column4.HeaderText = PdnResources.GetString("Menu.Theporediameter.text");
  241. this.Column3.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Non-ferrousmetals.serialnumber.text");
  242. this.Column2.HeaderText = PdnResources.GetString("Menu.view.text");
  243. }
  244. private void InitializeBC()
  245. {
  246. this.bc = new PaintDotNet.CustomControl.BinaryControl();
  247. //
  248. // bc
  249. //
  250. this.bc.BinaryBackColor = System.Drawing.Color.Red;
  251. this.bc.BinaryChecked = false;
  252. this.bc.BinaryStyle = 1;
  253. this.bc.Location = new System.Drawing.Point(179, 70);
  254. this.bc.Name = "bc";
  255. this.bc.OriginChecked = false;
  256. this.bc.scope1End = 0D;
  257. this.bc.scope1Start = 0D;
  258. this.bc.scope2End = 0D;
  259. this.bc.scope2Start = 0D;
  260. this.bc.scope3End = 0D;
  261. this.bc.scope3Start = 0D;
  262. this.bc.Size = new System.Drawing.Size(360, 292);
  263. this.bc.TabIndex = 34;
  264. this.Controls.Add(this.bc);
  265. this.Controls.SetChildIndex(this.bc, 0);
  266. }
  267. #region 初始化组件
  268. private void InitializeComponent()
  269. {
  270. this.components = new System.ComponentModel.Container();
  271. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
  272. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
  273. this.groupBox_operating = new System.Windows.Forms.GroupBox();
  274. this.checkBox_generateReport_opensetting = new System.Windows.Forms.CheckBox();
  275. this.button_setting = new System.Windows.Forms.Button();
  276. this.btn_saveresult = new System.Windows.Forms.Button();
  277. this.groupBox_img = new System.Windows.Forms.GroupBox();
  278. this.lstView_img = new System.Windows.Forms.ListView();
  279. this.imageList_img = new System.Windows.Forms.ImageList(this.components);
  280. this.groupBox_review = new System.Windows.Forms.GroupBox();
  281. this.groupBox_report = new System.Windows.Forms.GroupBox();
  282. this.button1 = new System.Windows.Forms.Button();
  283. this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown();
  284. this.label_resultPrecision = new System.Windows.Forms.Label();
  285. this.button_exportResults = new System.Windows.Forms.Button();
  286. this.button_generateReport = new System.Windows.Forms.Button();
  287. this.groupBox6groupBox_analysisResult2 = new System.Windows.Forms.GroupBox();
  288. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  289. this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  290. this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  291. this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  292. this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  293. this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  294. this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  295. this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  296. this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  297. this.dataGridView2 = new System.Windows.Forms.DataGridView();
  298. this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  299. this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  300. this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  301. this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  302. this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  303. this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  304. this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  305. this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  306. this.groupBox_analysisResult1 = new System.Windows.Forms.GroupBox();
  307. this.button11 = new System.Windows.Forms.Button();
  308. this.listView2 = new System.Windows.Forms.ListView();
  309. this.button16 = new System.Windows.Forms.Button();
  310. this.button12 = new System.Windows.Forms.Button();
  311. this.toolTip_GrainSizeDetails = new System.Windows.Forms.ToolTip(this.components);
  312. this.groupBox_operating.SuspendLayout();
  313. this.groupBox_img.SuspendLayout();
  314. this.groupBox_report.SuspendLayout();
  315. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
  316. this.groupBox6groupBox_analysisResult2.SuspendLayout();
  317. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  318. ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
  319. this.groupBox_analysisResult1.SuspendLayout();
  320. this.SuspendLayout();
  321. //
  322. // groupBox_operating
  323. //
  324. this.groupBox_operating.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  325. | System.Windows.Forms.AnchorStyles.Right)));
  326. this.groupBox_operating.Controls.Add(this.checkBox_generateReport_opensetting);
  327. this.groupBox_operating.Controls.Add(this.button_setting);
  328. this.groupBox_operating.Controls.Add(this.btn_saveresult);
  329. this.groupBox_operating.Location = new System.Drawing.Point(13, 12);
  330. this.groupBox_operating.Name = "groupBox_operating";
  331. this.groupBox_operating.Size = new System.Drawing.Size(1102, 53);
  332. this.groupBox_operating.TabIndex = 12;
  333. this.groupBox_operating.TabStop = false;
  334. //
  335. // checkBox_generateReport_opensetting
  336. //
  337. this.checkBox_generateReport_opensetting.AutoSize = true;
  338. this.checkBox_generateReport_opensetting.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
  339. this.checkBox_generateReport_opensetting.Location = new System.Drawing.Point(91, 24);
  340. this.checkBox_generateReport_opensetting.Name = "checkBox_generateReport_opensetting";
  341. this.checkBox_generateReport_opensetting.Size = new System.Drawing.Size(15, 14);
  342. this.checkBox_generateReport_opensetting.TabIndex = 6;
  343. this.checkBox_generateReport_opensetting.UseVisualStyleBackColor = true;
  344. //
  345. // button_setting
  346. //
  347. this.button_setting.Location = new System.Drawing.Point(6, 20);
  348. this.button_setting.Name = "button_setting";
  349. this.button_setting.Size = new System.Drawing.Size(75, 23);
  350. this.button_setting.TabIndex = 4;
  351. this.button_setting.UseVisualStyleBackColor = true;
  352. this.button_setting.Click += new System.EventHandler(this.button_setting_Click);
  353. //
  354. // btn_saveresult
  355. //
  356. this.btn_saveresult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  357. this.btn_saveresult.Location = new System.Drawing.Point(992, 20);
  358. this.btn_saveresult.Name = "btn_saveresult";
  359. this.btn_saveresult.Size = new System.Drawing.Size(75, 23);
  360. this.btn_saveresult.TabIndex = 2;
  361. this.btn_saveresult.UseVisualStyleBackColor = true;
  362. this.btn_saveresult.Click += new System.EventHandler(this.btn_saveresult_Click);
  363. //
  364. // groupBox_img
  365. //
  366. this.groupBox_img.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  367. | System.Windows.Forms.AnchorStyles.Left)));
  368. this.groupBox_img.Controls.Add(this.lstView_img);
  369. this.groupBox_img.Location = new System.Drawing.Point(13, 72);
  370. this.groupBox_img.Margin = new System.Windows.Forms.Padding(4);
  371. this.groupBox_img.Name = "groupBox_img";
  372. this.groupBox_img.Padding = new System.Windows.Forms.Padding(4);
  373. this.groupBox_img.Size = new System.Drawing.Size(158, 522);
  374. this.groupBox_img.TabIndex = 13;
  375. this.groupBox_img.TabStop = false;
  376. //
  377. // lstView_img
  378. //
  379. this.lstView_img.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  380. | System.Windows.Forms.AnchorStyles.Left)
  381. | System.Windows.Forms.AnchorStyles.Right)));
  382. this.lstView_img.HideSelection = false;
  383. this.lstView_img.LargeImageList = this.imageList_img;
  384. this.lstView_img.Location = new System.Drawing.Point(8, 26);
  385. this.lstView_img.Margin = new System.Windows.Forms.Padding(4);
  386. this.lstView_img.MultiSelect = false;
  387. this.lstView_img.Name = "lstView_img";
  388. this.lstView_img.Size = new System.Drawing.Size(140, 488);
  389. this.lstView_img.TabIndex = 0;
  390. this.lstView_img.UseCompatibleStateImageBehavior = false;
  391. this.lstView_img.SelectedIndexChanged += new System.EventHandler(this.lstView_img_SelectedIndexChanged);
  392. //
  393. // imageList_img
  394. //
  395. this.imageList_img.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  396. this.imageList_img.ImageSize = new System.Drawing.Size(64, 64);
  397. this.imageList_img.TransparentColor = System.Drawing.Color.Transparent;
  398. //
  399. // groupBox_review
  400. //
  401. this.groupBox_review.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  402. | System.Windows.Forms.AnchorStyles.Left)
  403. | System.Windows.Forms.AnchorStyles.Right)));
  404. this.groupBox_review.Location = new System.Drawing.Point(545, 72);
  405. this.groupBox_review.Name = "groupBox_review";
  406. this.groupBox_review.Size = new System.Drawing.Size(571, 522);
  407. this.groupBox_review.TabIndex = 30;
  408. this.groupBox_review.TabStop = false;
  409. //
  410. // groupBox_report
  411. //
  412. this.groupBox_report.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  413. this.groupBox_report.Controls.Add(this.button1);
  414. this.groupBox_report.Controls.Add(this.numericUpDown1_0);
  415. this.groupBox_report.Controls.Add(this.label_resultPrecision);
  416. this.groupBox_report.Controls.Add(this.button_exportResults);
  417. this.groupBox_report.Controls.Add(this.button_generateReport);
  418. this.groupBox_report.Location = new System.Drawing.Point(974, 600);
  419. this.groupBox_report.Name = "groupBox_report";
  420. this.groupBox_report.Size = new System.Drawing.Size(142, 218);
  421. this.groupBox_report.TabIndex = 33;
  422. this.groupBox_report.TabStop = false;
  423. //
  424. // button1
  425. //
  426. this.button1.Location = new System.Drawing.Point(29, 108);
  427. this.button1.Name = "button1";
  428. this.button1.Size = new System.Drawing.Size(75, 23);
  429. this.button1.TabIndex = 23;
  430. this.button1.UseVisualStyleBackColor = true;
  431. this.button1.Click += new System.EventHandler(this.button1_Click);
  432. //
  433. // numericUpDown1_0
  434. //
  435. this.numericUpDown1_0.Location = new System.Drawing.Point(63, 170);
  436. this.numericUpDown1_0.Maximum = new decimal(new int[] {
  437. 10,
  438. 0,
  439. 0,
  440. 0});
  441. this.numericUpDown1_0.Name = "numericUpDown1_0";
  442. this.numericUpDown1_0.Size = new System.Drawing.Size(56, 21);
  443. this.numericUpDown1_0.TabIndex = 22;
  444. this.numericUpDown1_0.Value = new decimal(new int[] {
  445. 2,
  446. 0,
  447. 0,
  448. 0});
  449. this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged);
  450. //
  451. // label_resultPrecision
  452. //
  453. this.label_resultPrecision.AutoSize = true;
  454. this.label_resultPrecision.Location = new System.Drawing.Point(17, 174);
  455. this.label_resultPrecision.Name = "label_resultPrecision";
  456. this.label_resultPrecision.Size = new System.Drawing.Size(35, 12);
  457. this.label_resultPrecision.TabIndex = 3;
  458. this.label_resultPrecision.Text = "小数:";
  459. //
  460. // button_exportResults
  461. //
  462. this.button_exportResults.Location = new System.Drawing.Point(29, 69);
  463. this.button_exportResults.Name = "button_exportResults";
  464. this.button_exportResults.Size = new System.Drawing.Size(75, 23);
  465. this.button_exportResults.TabIndex = 1;
  466. this.button_exportResults.UseVisualStyleBackColor = true;
  467. this.button_exportResults.Click += new System.EventHandler(this.button_exportResults_Click);
  468. //
  469. // button_generateReport
  470. //
  471. this.button_generateReport.Location = new System.Drawing.Point(29, 30);
  472. this.button_generateReport.Name = "button_generateReport";
  473. this.button_generateReport.Size = new System.Drawing.Size(75, 23);
  474. this.button_generateReport.TabIndex = 0;
  475. this.button_generateReport.UseVisualStyleBackColor = true;
  476. this.button_generateReport.Click += new System.EventHandler(this.button_generateReport_Click);
  477. //
  478. // groupBox6groupBox_analysisResult2
  479. //
  480. this.groupBox6groupBox_analysisResult2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  481. | System.Windows.Forms.AnchorStyles.Right)));
  482. this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView1);
  483. this.groupBox6groupBox_analysisResult2.Controls.Add(this.dataGridView2);
  484. this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 601);
  485. this.groupBox6groupBox_analysisResult2.Name = "groupBox6groupBox_analysisResult2";
  486. this.groupBox6groupBox_analysisResult2.Size = new System.Drawing.Size(719, 217);
  487. this.groupBox6groupBox_analysisResult2.TabIndex = 32;
  488. this.groupBox6groupBox_analysisResult2.TabStop = false;
  489. //
  490. // dataGridView1
  491. //
  492. this.dataGridView1.AllowUserToAddRows = false;
  493. this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  494. | System.Windows.Forms.AnchorStyles.Right)));
  495. this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  496. this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
  497. dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  498. dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
  499. dataGridViewCellStyle3.Font = new System.Drawing.Font("宋体", 9F);
  500. dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
  501. dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  502. dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  503. dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  504. this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle3;
  505. this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  506. this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  507. this.dataGridViewTextBoxColumn1,
  508. this.dataGridViewTextBoxColumn2,
  509. this.dataGridViewTextBoxColumn3,
  510. this.dataGridViewTextBoxColumn4,
  511. this.dataGridViewTextBoxColumn5,
  512. this.dataGridViewTextBoxColumn6,
  513. this.dataGridViewTextBoxColumn7,
  514. this.dataGridViewTextBoxColumn8});
  515. this.dataGridView1.Location = new System.Drawing.Point(13, 115);
  516. this.dataGridView1.Name = "dataGridView1";
  517. this.dataGridView1.ReadOnly = true;
  518. this.dataGridView1.RowHeadersVisible = false;
  519. this.dataGridView1.RowTemplate.Height = 23;
  520. this.dataGridView1.Size = new System.Drawing.Size(693, 98);
  521. this.dataGridView1.TabIndex = 17;
  522. //
  523. // dataGridViewTextBoxColumn1
  524. //
  525. this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
  526. this.dataGridViewTextBoxColumn1.ReadOnly = true;
  527. //
  528. // dataGridViewTextBoxColumn2
  529. //
  530. this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
  531. this.dataGridViewTextBoxColumn2.ReadOnly = true;
  532. //
  533. // dataGridViewTextBoxColumn3
  534. //
  535. this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
  536. this.dataGridViewTextBoxColumn3.ReadOnly = true;
  537. //
  538. // dataGridViewTextBoxColumn4
  539. //
  540. this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
  541. this.dataGridViewTextBoxColumn4.ReadOnly = true;
  542. //
  543. // dataGridViewTextBoxColumn5
  544. //
  545. this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
  546. this.dataGridViewTextBoxColumn5.ReadOnly = true;
  547. //
  548. // dataGridViewTextBoxColumn6
  549. //
  550. this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";
  551. this.dataGridViewTextBoxColumn6.ReadOnly = true;
  552. //
  553. // dataGridViewTextBoxColumn7
  554. //
  555. this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
  556. this.dataGridViewTextBoxColumn7.ReadOnly = true;
  557. //
  558. // dataGridViewTextBoxColumn8
  559. //
  560. this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8";
  561. this.dataGridViewTextBoxColumn8.ReadOnly = true;
  562. //
  563. // dataGridView2
  564. //
  565. this.dataGridView2.AllowUserToAddRows = false;
  566. this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  567. | System.Windows.Forms.AnchorStyles.Right)));
  568. this.dataGridView2.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  569. this.dataGridView2.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
  570. dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  571. dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
  572. dataGridViewCellStyle4.Font = new System.Drawing.Font("宋体", 9F);
  573. dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
  574. dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  575. dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  576. dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  577. this.dataGridView2.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4;
  578. this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  579. this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  580. this.Column1,
  581. this.Column2,
  582. this.Column3,
  583. this.Column4,
  584. this.Column5,
  585. this.Column6,
  586. this.Column7,
  587. this.Column8});
  588. this.dataGridView2.Location = new System.Drawing.Point(13, 11);
  589. this.dataGridView2.Name = "dataGridView2";
  590. this.dataGridView2.ReadOnly = true;
  591. this.dataGridView2.RowHeadersVisible = false;
  592. this.dataGridView2.RowTemplate.Height = 23;
  593. this.dataGridView2.Size = new System.Drawing.Size(693, 98);
  594. this.dataGridView2.TabIndex = 16;
  595. //
  596. // Column1
  597. //
  598. this.Column1.Name = "Column1";
  599. this.Column1.ReadOnly = true;
  600. //
  601. // Column2
  602. //
  603. this.Column2.Name = "Column2";
  604. this.Column2.ReadOnly = true;
  605. //
  606. // Column3
  607. //
  608. this.Column3.Name = "Column3";
  609. this.Column3.ReadOnly = true;
  610. //
  611. // Column4
  612. //
  613. this.Column4.Name = "Column4";
  614. this.Column4.ReadOnly = true;
  615. //
  616. // Column5
  617. //
  618. this.Column5.Name = "Column5";
  619. this.Column5.ReadOnly = true;
  620. //
  621. // Column6
  622. //
  623. this.Column6.Name = "Column6";
  624. this.Column6.ReadOnly = true;
  625. //
  626. // Column7
  627. //
  628. this.Column7.Name = "Column7";
  629. this.Column7.ReadOnly = true;
  630. //
  631. // Column8
  632. //
  633. this.Column8.Name = "Column8";
  634. this.Column8.ReadOnly = true;
  635. //
  636. // groupBox_analysisResult1
  637. //
  638. this.groupBox_analysisResult1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  639. this.groupBox_analysisResult1.Controls.Add(this.button11);
  640. this.groupBox_analysisResult1.Controls.Add(this.listView2);
  641. this.groupBox_analysisResult1.Controls.Add(this.button16);
  642. this.groupBox_analysisResult1.Controls.Add(this.button12);
  643. this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 601);
  644. this.groupBox_analysisResult1.Name = "groupBox_analysisResult1";
  645. this.groupBox_analysisResult1.Size = new System.Drawing.Size(224, 217);
  646. this.groupBox_analysisResult1.TabIndex = 31;
  647. this.groupBox_analysisResult1.TabStop = false;
  648. //
  649. // button11
  650. //
  651. this.button11.BackColor = System.Drawing.SystemColors.Control;
  652. this.button11.Location = new System.Drawing.Point(19, 22);
  653. this.button11.Name = "button11";
  654. this.button11.Size = new System.Drawing.Size(63, 26);
  655. this.button11.TabIndex = 27;
  656. this.button11.UseVisualStyleBackColor = false;
  657. this.button11.Click += new System.EventHandler(this.button11_Click);
  658. //
  659. // listView2
  660. //
  661. this.listView2.FullRowSelect = true;
  662. this.listView2.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
  663. this.listView2.HideSelection = false;
  664. this.listView2.Location = new System.Drawing.Point(19, 58);
  665. this.listView2.Name = "listView2";
  666. this.listView2.Size = new System.Drawing.Size(181, 153);
  667. this.listView2.TabIndex = 26;
  668. this.listView2.UseCompatibleStateImageBehavior = false;
  669. this.listView2.SelectedIndexChanged += new System.EventHandler(this.listview2_SelectedIndexChanged);
  670. //
  671. // button16
  672. //
  673. this.button16.BackColor = System.Drawing.SystemColors.Control;
  674. this.button16.Location = new System.Drawing.Point(19, 21);
  675. this.button16.Name = "button16";
  676. this.button16.Size = new System.Drawing.Size(93, 26);
  677. this.button16.TabIndex = 25;
  678. this.button16.UseVisualStyleBackColor = false;
  679. this.button16.Click += new System.EventHandler(this.button16_Click);
  680. //
  681. // button12
  682. //
  683. this.button12.BackColor = System.Drawing.SystemColors.Control;
  684. this.button12.Location = new System.Drawing.Point(149, 21);
  685. this.button12.Name = "button12";
  686. this.button12.Size = new System.Drawing.Size(52, 26);
  687. this.button12.TabIndex = 24;
  688. this.button12.UseVisualStyleBackColor = false;
  689. this.button12.Click += new System.EventHandler(this.button12_Click);
  690. //
  691. // PetroleumGeologyStandardDialog
  692. //
  693. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  694. this.ClientSize = new System.Drawing.Size(1127, 830);
  695. this.Controls.Add(this.groupBox_report);
  696. this.Controls.Add(this.groupBox6groupBox_analysisResult2);
  697. this.Controls.Add(this.groupBox_analysisResult1);
  698. this.Controls.Add(this.groupBox_review);
  699. this.Controls.Add(this.groupBox_img);
  700. this.Controls.Add(this.groupBox_operating);
  701. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  702. this.Location = new System.Drawing.Point(0, 0);
  703. this.Name = "PetroleumGeologyStandardDialog";
  704. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.InclusionsStandardDialog_FormClosing);
  705. this.Shown += new System.EventHandler(this.ShownChoiseItemAndInitData);
  706. this.Controls.SetChildIndex(this.groupBox_operating, 0);
  707. this.Controls.SetChildIndex(this.groupBox_img, 0);
  708. this.Controls.SetChildIndex(this.groupBox_review, 0);
  709. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  710. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  711. this.Controls.SetChildIndex(this.groupBox_report, 0);
  712. this.groupBox_operating.ResumeLayout(false);
  713. this.groupBox_operating.PerformLayout();
  714. this.groupBox_img.ResumeLayout(false);
  715. this.groupBox_report.ResumeLayout(false);
  716. this.groupBox_report.PerformLayout();
  717. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
  718. this.groupBox6groupBox_analysisResult2.ResumeLayout(false);
  719. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  720. ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
  721. this.groupBox_analysisResult1.ResumeLayout(false);
  722. this.ResumeLayout(false);
  723. }
  724. private void ShowImgEvent(object sender, EventArgs e)
  725. {
  726. lstView_img.Focus();
  727. if (this.defaultIndex != -1)
  728. {
  729. this.lstView_img.Items[defaultIndex].Focused = true;
  730. this.lstView_img.Items[defaultIndex].Selected = true;
  731. }
  732. }
  733. public void Initialize()
  734. {
  735. //初始化图片列表
  736. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  737. {
  738. this.imageList_img.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
  739. this.lstView_img.Items.Add("", i);
  740. this.lstView_img.Items[i].ImageIndex = i;
  741. this.lstView_img.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  742. this.lstView_img.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  743. if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace))
  744. {
  745. defaultIndex = i;
  746. }
  747. }
  748. this.Shown += ShowImgEvent;
  749. //
  750. //初始化图像控件
  751. //
  752. this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
  753. this.documentWorkspace.Cursor = Cursors.Default;
  754. this.documentWorkspace.Dock = DockStyle.Fill;
  755. this.documentWorkspace.HookMouseEvents();
  756. this.documentWorkspace.AuxiliaryLineEnabled = false;
  757. this.documentWorkspace.Visible = true;
  758. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  759. this.documentWorkspace.panel.Paint += Panel_Paint;
  760. this.documentWorkspace.panel.MouseMove += onMouseMove;
  761. this.documentWorkspace.panel.MouseUp += onMouseUp;
  762. this.groupBox_review.Controls.Add(this.documentWorkspace);
  763. //
  764. //初始化操作按钮
  765. //
  766. this.commonControlButtons = new CommonControlButtons();
  767. this.commonControlButtons.Dock = DockStyle.Top;
  768. this.commonControlButtons.Height = 30;
  769. this.commonControlButtons.HideZoomToWindowAndActualSize();
  770. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  771. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  772. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  773. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  774. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  775. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  776. groupBox_review.Controls.Add(this.commonControlButtons);
  777. }
  778. #endregion
  779. #region 事件
  780. #region 公共按钮
  781. private void zoomInButton_Click(object sender, EventArgs e)
  782. {
  783. this.documentWorkspace.ZoomIn();
  784. }
  785. private void zoomOutButton_Click(object sender, EventArgs e)
  786. {
  787. this.documentWorkspace.ZoomOut();
  788. }
  789. private void zoomToWindowButton_Click(object sender, EventArgs e)
  790. {
  791. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  792. }
  793. private void actualSizeButton_Click(object sender, EventArgs e)
  794. {
  795. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  796. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  797. }
  798. private void pointerButton_Click(object sender, EventArgs e)
  799. {
  800. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;
  801. }
  802. private void mobileModeButton_Click(object sender, EventArgs e)
  803. {
  804. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  805. }
  806. #endregion
  807. /// <summary>
  808. /// 设置
  809. /// </summary>
  810. /// <param name="sender"></param>
  811. /// <param name="e"></param>
  812. private void button_setting_Click(object sender, EventArgs e)
  813. {
  814. string templateName = getTemplateName();
  815. AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, templateName);
  816. if (metallographicMethodSetDialog.hasModule)
  817. {
  818. metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen;
  819. metallographicMethodSetDialog.ShowDialog();
  820. }
  821. else
  822. {
  823. metallographicMethodSetDialog = null;
  824. }
  825. }
  826. private void btn_saveresult_Click(object sender, EventArgs e)
  827. {
  828. buildListBox_analysisResult();
  829. }
  830. private void lstView_img_SelectedIndexChanged(object sender, EventArgs e)
  831. {
  832. if (this.lstView_img.FocusedItem != null && this.lstView_img.FocusedItem.Selected)
  833. {
  834. this.physical_length = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  835. //double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  836. //this.documentWorkspace.Document = Document.FromImage(this.documentItems[this.lstView_img.FocusedItem.Index].bitmap);
  837. //this.documentWorkspace.Visible = true;
  838. //this.documentWorkspace.activeTool = DrawToolType.InclusionNoEffect;
  839. //this.documentWorkspace.GraphicsList = this.documentItems[this.lstView_img.FocusedItem.Index].graphicsList;
  840. //this.documentWorkspace.PhaseModels = new List<PhaseModel>();
  841. //this.documentWorkspace.PhaseModels.AddRange(this.documentItems[this.lstView_img.FocusedItem.Index].phaseModels);
  842. this.bitmap = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  843. //if (!this.documentWorkspace.PhaseModels[0].choise)
  844. // this.checkBox10.Checked = false;
  845. bool existViewFlag = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GraphicsList.IsExsitView();
  846. if (!existViewFlag)
  847. {
  848. matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
  849. }
  850. else
  851. {
  852. matOrg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetFullSizeWithRegion());
  853. }
  854. //二值化集成4
  855. binaryClass.listView1_SelectedIndexChanged(this.bitmap);
  856. if (bcOriginChecked())
  857. {
  858. this.documentWorkspace.PhaseModels[0].choise = false;
  859. this.documentWorkspace.Refresh();
  860. }
  861. //if (this.checkBox1.Checked)
  862. //{
  863. // this.applyDect();
  864. //}
  865. if (segmentedHolesMat != null)
  866. {
  867. segmentedHolesMat.Dispose();
  868. segmentedHolesMat = null;
  869. }
  870. lstAttribute.Clear();
  871. minLinePoints.Clear();
  872. refreshWhileImgChanged();
  873. }
  874. }
  875. #region 矩形拖动
  876. /// <summary>
  877. /// 鼠标按下
  878. /// </summary>
  879. /// <param name="drawArea"></param>
  880. /// <param name="e"></param>
  881. protected virtual void OnMouseDown(object sender, MouseEventArgs e)
  882. {
  883. // 换算后的点
  884. //PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  885. if (addPoint)
  886. {
  887. m_StartPoint = documentWorkspace.GetScalePoint(e.Location);
  888. }
  889. }
  890. /// <summary>
  891. /// 移动
  892. /// </summary>
  893. /// <param name="sender"></param>
  894. /// <param name="e"></param>
  895. protected virtual void onMouseMove(object sender, MouseEventArgs e)
  896. {
  897. //this.documentWorkspace.Refresh();
  898. // 换算后的点
  899. //PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  900. if (addPoint && m_StartPoint.X > 0 && m_StartPoint.Y > 0)
  901. {
  902. m_EndPoint = documentWorkspace.GetScalePoint(e.Location);
  903. this.documentWorkspace.Refresh();
  904. }
  905. }
  906. /// <summary>
  907. /// 鼠标抬起
  908. /// </summary>
  909. /// <param name="sender"></param>
  910. /// <param name="e"></param>
  911. private void onMouseUp(object sender, MouseEventArgs e)
  912. {
  913. if (this.bitmap != null && m_StartPoint.X > 0 && m_StartPoint.Y > 0 && m_StartPoint.X < this.bitmap.Width && m_StartPoint.Y < this.bitmap.Height
  914. && m_EndPoint.X > 0 && m_EndPoint.Y > 0 && m_EndPoint.X < this.bitmap.Width && m_EndPoint.Y < this.bitmap.Height)
  915. {
  916. Line lineI = new Line(new Point((int)m_StartPoint.X, (int)m_StartPoint.Y), new Point((int)m_EndPoint.X, (int)m_EndPoint.Y));
  917. minLinePoints.Add(new Point2d((int)((m_StartPoint.X + m_EndPoint.X) / 2), (int)((m_StartPoint.Y + m_EndPoint.Y) / 2)), lineI);
  918. if (segmentedHolesMat != null)
  919. {
  920. segmentedHolesMat.Dispose();
  921. segmentedHolesMat = null;
  922. }
  923. if (segmentedHolesMat == null && createSegmentedHoldsMat() || segmentedHolesMat != null)
  924. {
  925. m_StartPoint = Point.Empty;
  926. m_EndPoint = Point.Empty;
  927. m_canMove = false;
  928. //addPoint = false;
  929. return;
  930. }
  931. else
  932. //图像分割
  933. this.documentWorkspace.Refresh();
  934. }
  935. m_StartPoint = Point.Empty;
  936. m_EndPoint = Point.Empty;
  937. m_canMove = false;
  938. addPoint = false;
  939. this.documentWorkspace.Refresh();
  940. }
  941. #endregion
  942. /// <summary>
  943. /// 画布绘制
  944. /// </summary>
  945. /// <param name="sender"></param>
  946. /// <param name="e"></param>
  947. private void Panel_Paint(object sender, PaintEventArgs e)
  948. {
  949. if (this.documentWorkspace.CompositionSurface != null)
  950. {
  951. //
  952. // 以下是计算绘制图片的位置和大小并绘制图片
  953. //
  954. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  955. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  956. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  957. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  958. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  959. //
  960. // 以下是绘制网格、标注、测量、视场等开始
  961. //
  962. e.Graphics.TranslateTransform(x, y);
  963. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  964. Draw(e.Graphics);
  965. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  966. e.Graphics.TranslateTransform(-x, -y);
  967. }
  968. }
  969. /// <summary>
  970. /// 绘制
  971. /// </summary>
  972. private void Draw(Graphics graphics)
  973. {
  974. // 抗锯齿
  975. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  976. drawSubclass(graphics);
  977. }
  978. #endregion
  979. #region 内部方法
  980. /// <summary>
  981. /// 从末梢的点开始寻找截线的极小值点
  982. /// </summary>
  983. /// <param name="threshold_2">阈值的平方</param>
  984. /// <param name="point">从枝干末梢的坐标点根据抽骨架路径往里走</param>
  985. /// <param name="mat">抽骨架的mat</param>
  986. /// <param name="distance_temp">距离变换的mat</param>
  987. /// <param name="foundList">已经找到的极小值点</param>
  988. /// <param name="former1Distance">point点的距离</param>
  989. /// <param name="former2Distance">point前面的点的距离</param>
  990. /// <returns></returns>
  991. private Dictionary<Point2d, float> GetMinLabelPoint(int threshold_2, Point point, Mat mat, Mat distance_temp, Dictionary<Point2d, float> foundList, float former1Distance, float former2Distance)
  992. {
  993. //if (routePoints.FindAll(a => a.X == point.X && a.Y == point.Y).Count > 0)
  994. if (routePoints.Contains(point))
  995. return foundList;
  996. routePoints.Add(new Point(point.X, point.Y));
  997. bool firstValueOnBoundry;
  998. bool lastValueOnBoundry;
  999. Point lastPoint = new Point(point.X, point.Y);
  1000. Point nextPoint = new Point(point.X - 1, point.Y - 1);
  1001. float currDistance;
  1002. int count;
  1003. do
  1004. {
  1005. count = 0;
  1006. if (point.X > mat.Width - 2 || point.X < 1 || point.Y > mat.Height - 2 || point.Y < 1)
  1007. {
  1008. }
  1009. else
  1010. {
  1011. if (!routePoints.Contains(new Point(point.X - 1, point.Y - 1)) && mat.At<Vec4b>(point.Y - 1, point.X - 1).Item3 != 0)
  1012. {
  1013. nextPoint = new Point(point.X - 1, point.Y - 1);
  1014. count++;
  1015. firstValueOnBoundry = true;
  1016. lastValueOnBoundry = true;
  1017. }
  1018. else
  1019. {
  1020. firstValueOnBoundry = false;
  1021. lastValueOnBoundry = false;
  1022. }
  1023. if (!routePoints.Contains(new Point(point.X, point.Y - 1)) && mat.At<Vec4b>(point.Y - 1, point.X).Item3 != 0)
  1024. {
  1025. if (!lastValueOnBoundry)
  1026. {
  1027. nextPoint = new Point(point.X, point.Y - 1);
  1028. count++;
  1029. }
  1030. lastValueOnBoundry = true;
  1031. }
  1032. else lastValueOnBoundry = false;
  1033. if (!routePoints.Contains(new Point(point.X + 1, point.Y - 1)) && mat.At<Vec4b>(point.Y - 1, point.X + 1).Item3 != 0)
  1034. {
  1035. if (!lastValueOnBoundry)
  1036. {
  1037. nextPoint = new Point(point.X + 1, point.Y - 1);
  1038. count++;
  1039. }
  1040. lastValueOnBoundry = true;
  1041. }
  1042. else lastValueOnBoundry = false;
  1043. if (!routePoints.Contains(new Point(point.X + 1, point.Y)) && mat.At<Vec4b>(point.Y, point.X + 1).Item3 != 0)
  1044. {
  1045. if (!lastValueOnBoundry)
  1046. {
  1047. nextPoint = new Point(point.X + 1, point.Y);
  1048. count++;
  1049. }
  1050. lastValueOnBoundry = true;
  1051. }
  1052. else lastValueOnBoundry = false;
  1053. if (!routePoints.Contains(new Point(point.X + 1, point.Y + 1)) && mat.At<Vec4b>(point.Y + 1, point.X + 1).Item3 != 0)
  1054. {
  1055. if (!lastValueOnBoundry)
  1056. {
  1057. nextPoint = new Point(point.X + 1, point.Y + 1);
  1058. count++;
  1059. }
  1060. lastValueOnBoundry = true;
  1061. }
  1062. else lastValueOnBoundry = false;
  1063. if (!routePoints.Contains(new Point(point.X, point.Y + 1)) && mat.At<Vec4b>(point.Y + 1, point.X).Item3 != 0)
  1064. {
  1065. if (!lastValueOnBoundry)
  1066. {
  1067. nextPoint = new Point(point.X, point.Y + 1);
  1068. count++;
  1069. }
  1070. lastValueOnBoundry = true;
  1071. }
  1072. else lastValueOnBoundry = false;
  1073. if (!routePoints.Contains(new Point(point.X - 1, point.Y + 1)) && mat.At<Vec4b>(point.Y + 1, point.X - 1).Item3 != 0)
  1074. {
  1075. if (!lastValueOnBoundry)
  1076. {
  1077. nextPoint = new Point(point.X - 1, point.Y + 1);
  1078. count++;
  1079. }
  1080. lastValueOnBoundry = true;
  1081. }
  1082. else lastValueOnBoundry = false;
  1083. if (!routePoints.Contains(new Point(point.X - 1, point.Y)) && mat.At<Vec4b>(point.Y, point.X - 1).Item3 != 0)
  1084. {
  1085. if (!lastValueOnBoundry && !firstValueOnBoundry)
  1086. {
  1087. nextPoint = new Point(point.X - 1, point.Y);
  1088. count++;
  1089. }
  1090. lastValueOnBoundry = true;
  1091. }
  1092. else lastValueOnBoundry = false;
  1093. }
  1094. if (count == 1)
  1095. {
  1096. //if (routePoints.Count > 0)
  1097. // routePoints.RemoveAt(routePoints.Count - 1);
  1098. routePoints.Add(new Point(nextPoint.X, nextPoint.Y));
  1099. }
  1100. else if (count > 1)
  1101. {
  1102. routePoints.Add(new Point(nextPoint.X, nextPoint.Y));
  1103. }
  1104. if (count == 1)
  1105. {
  1106. //走到其中一条路径
  1107. currDistance = distance_temp.At<float>(nextPoint.Y, nextPoint.X);
  1108. if ((currDistance - former1Distance >= 0) && (former1Distance - former2Distance) <= 0 && former2Distance != float.MinValue)
  1109. {
  1110. if (/*foundList.Count == 0 || foundList.Count > 0 && */Math.Max(10, currDistance * currDistance * 9)/*threshold_2*/ < ((lastPoint.X - nextPoint.X) * (lastPoint.X - nextPoint.X) + (lastPoint.Y - nextPoint.Y) * (lastPoint.Y - nextPoint.Y)))
  1111. {
  1112. foundList.Add(new Point2d(point.X, point.Y), (int)(Math.Round(former1Distance * former1Distance)));
  1113. lastPoint.X = nextPoint.X;
  1114. lastPoint.Y = nextPoint.Y;
  1115. }
  1116. }
  1117. point.X = nextPoint.X;
  1118. point.Y = nextPoint.Y;
  1119. former2Distance = former1Distance;
  1120. former1Distance = currDistance;
  1121. }
  1122. } while (count == 1);
  1123. return foundList;
  1124. }
  1125. /// <summary>
  1126. /// 导出项目
  1127. /// </summary>
  1128. /// <param name="sender"></param>
  1129. /// <param name="e"></param>
  1130. private void button1_Click(object sender, EventArgs e)
  1131. {
  1132. if (this.listView2.Items.Count == 0)
  1133. {
  1134. MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
  1135. return;
  1136. }
  1137. if (this.checkBox_generateReport_opensetting.Checked)
  1138. this.button_setting.PerformClick();
  1139. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  1140. {
  1141. //获取项目工程内的文件夹路径
  1142. ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, getProjectEngineeringName(), this.analyzeSettingModel.savePath);
  1143. if (nodeItem == null) return;
  1144. //获取word书签与excel单元格的关系,以字典方式存储
  1145. List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  1146. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  1147. if (mic_module_infos != null && mic_module_infos.Count > 0)
  1148. {
  1149. foreach (mic_module_infos info in mic_module_infos)
  1150. {
  1151. tagInfos.Add(info.tag_name, info.cell_position);
  1152. }
  1153. }
  1154. //分析结果
  1155. List<List<string>> analysisContent = new List<List<string>>();
  1156. analysisContent.Add(contentHead);
  1157. foreach (DataGridViewRow item in this.dataGridView2.Rows)
  1158. {
  1159. List<string> content = new List<string>();
  1160. for (int i = 0; i < contentHead.Count; i++)
  1161. {
  1162. content.Add(item.Cells[i].Value.ToString());
  1163. }
  1164. analysisContent.Add(content);
  1165. }
  1166. //图片
  1167. bitList = new List<Bitmap>();
  1168. //中间数据
  1169. List<ExportProjectModel> exportModel = new List<ExportProjectModel>();
  1170. if (this.allShow)
  1171. {
  1172. foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
  1173. {
  1174. bitList.Add(kv.Value[0]);
  1175. bitList.Add(kv.Value[1]);
  1176. }
  1177. //中间数据
  1178. foreach (ExportProjectModel model in this.tempDataModel)
  1179. {
  1180. ExportProjectModel tempModel = new ExportProjectModel();
  1181. tempModel.tagName = model.tagName;
  1182. tempModel.picName = model.picName;
  1183. tempModel.dataList = model.dataList;
  1184. exportModel.Add(tempModel);
  1185. }
  1186. }
  1187. else
  1188. {
  1189. if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  1190. {
  1191. foreach (ListViewItem item in this.listView2.SelectedItems)
  1192. {
  1193. if (bitDic.ContainsKey(item.Name))
  1194. {
  1195. bitList.Add(bitDic[item.Name][0]);
  1196. bitList.Add(bitDic[item.Name][1]);
  1197. }
  1198. else if (bitDic.ContainsKey(item.Tag.ToString()))
  1199. {
  1200. bitList.Add(bitDic[item.Tag.ToString()][0]);
  1201. bitList.Add(bitDic[item.Tag.ToString()][1]);
  1202. }
  1203. }
  1204. //中间数据
  1205. foreach (ListViewItem rowItem in this.listView2.SelectedItems)
  1206. {
  1207. foreach (ExportProjectModel model in this.tempDataModel)
  1208. {
  1209. if (model.tagName.Equals(rowItem.Name))
  1210. {
  1211. ExportProjectModel tempModel = new ExportProjectModel();
  1212. tempModel.tagName = model.tagName;
  1213. tempModel.picName = model.picName;
  1214. tempModel.dataList = model.dataList;
  1215. exportModel.Add(tempModel);
  1216. break;
  1217. }
  1218. else if (model.tagName.Equals(rowItem.Tag.ToString()))
  1219. {
  1220. ExportProjectModel tempModel = new ExportProjectModel();
  1221. tempModel.tagName = model.tagName;
  1222. tempModel.picName = model.picName;
  1223. tempModel.dataList = model.dataList;
  1224. exportModel.Add(tempModel);
  1225. break;
  1226. }
  1227. }
  1228. }
  1229. }
  1230. else if (this.listView2.Items.Count > 0)//###
  1231. {
  1232. ListViewItem rowItem = this.listView2.Items[0];
  1233. if (bitDic.ContainsKey(rowItem.Name))
  1234. {
  1235. bitList.Add(bitDic[rowItem.Name][0]);
  1236. bitList.Add(bitDic[rowItem.Name][1]);
  1237. }
  1238. else if (bitDic.ContainsKey(rowItem.Tag.ToString()))
  1239. {
  1240. bitList.Add(bitDic[rowItem.Tag.ToString()][0]);
  1241. bitList.Add(bitDic[rowItem.Tag.ToString()][1]);
  1242. }
  1243. //中间数据
  1244. foreach (ExportProjectModel model in this.tempDataModel)
  1245. {
  1246. if (model.tagName.Equals(rowItem.Name))
  1247. {
  1248. ExportProjectModel tempModel = new ExportProjectModel();
  1249. tempModel.tagName = model.tagName;
  1250. tempModel.picName = model.picName;
  1251. tempModel.dataList = model.dataList;
  1252. exportModel.Add(tempModel);
  1253. break;
  1254. }
  1255. else if (model.tagName.Equals(rowItem.Tag.ToString()))
  1256. {
  1257. ExportProjectModel tempModel = new ExportProjectModel();
  1258. tempModel.tagName = model.tagName;
  1259. tempModel.picName = model.picName;
  1260. tempModel.dataList = model.dataList;
  1261. exportModel.Add(tempModel);
  1262. break;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, exportModel, bitList, tagInfos, nodeItem.path, nodeItem.code);
  1268. //保存项目信息到数据库
  1269. this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, nodeItem);
  1270. }
  1271. else
  1272. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  1273. }
  1274. /// <summary>
  1275. /// 导出结果
  1276. /// </summary>
  1277. /// <param name="sender"></param>
  1278. /// <param name="e"></param>
  1279. private void button_exportResults_Click(object sender, EventArgs e)
  1280. {
  1281. if (this.listView2.Items.Count > 0)
  1282. {
  1283. System.Data.DataSet ds = new DataSet();
  1284. DataTable table1 = new DataTable();
  1285. table1.TableName = PdnResources.GetString("Menu.breakdown.text");
  1286. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  1287. {
  1288. table1.Columns.Add(c.HeaderText);
  1289. }
  1290. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  1291. {
  1292. DataRow dataRow = table1.NewRow();
  1293. if (r == 0)
  1294. {
  1295. for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
  1296. {
  1297. dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Columns[c].HeaderText;
  1298. }
  1299. table1.Rows.Add(dataRow);
  1300. }
  1301. dataRow = table1.NewRow();
  1302. for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
  1303. {
  1304. dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Rows[r].Cells[c].Value;
  1305. }
  1306. table1.Rows.Add(dataRow);
  1307. }
  1308. DataTable table2 = new DataTable();
  1309. table2.TableName = PdnResources.GetString("Menu.statisaatics.text");
  1310. foreach (DataGridViewColumn c in this.dataGridView1.Columns)
  1311. {
  1312. table2.Columns.Add(c.HeaderText);
  1313. }
  1314. for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
  1315. {
  1316. DataRow dataRow = table2.NewRow();
  1317. if (r == 0)
  1318. {
  1319. for (int c = 0; c < this.dataGridView1.Rows[r].Cells.Count; c++)
  1320. {
  1321. dataRow[this.dataGridView1.Columns[c].HeaderText] = this.dataGridView1.Columns[c].HeaderText;
  1322. }
  1323. table2.Rows.Add(dataRow);
  1324. }
  1325. dataRow = table2.NewRow();
  1326. for (int c = 0; c < this.dataGridView1.Rows[r].Cells.Count; c++)
  1327. {
  1328. dataRow[this.dataGridView1.Columns[c].HeaderText] = this.dataGridView1.Rows[r].Cells[c].Value;
  1329. }
  1330. table2.Rows.Add(dataRow);
  1331. }
  1332. if (table1.Rows.Count > 0) ds.Tables.Add(table1);
  1333. if (table2.Rows.Count > 0) ds.Tables.Add(table2);
  1334. if (ds.Tables.Count > 0)
  1335. DataToExcle(ds);
  1336. }
  1337. else
  1338. {
  1339. MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text")+"!");
  1340. }
  1341. }
  1342. /// <summary>
  1343. /// 导出多 Sheet 报表
  1344. /// </summary>
  1345. /// <param name="ds">要导出的数据</param>
  1346. public void DataToExcle(System.Data.DataSet ds)
  1347. {
  1348. try
  1349. {
  1350. if (ds.Tables == null || ds.Tables.Count == 0)
  1351. {
  1352. MessageBox.Show(PdnResources.GetString("Menu.Nonedata.Text")+"!");
  1353. return;
  1354. }
  1355. SaveFileDialog saveFileDialog = new SaveFileDialog();
  1356. saveFileDialog.DefaultExt = "xlsx";
  1357. saveFileDialog.Title = PdnResources.GetString("Menu.ExportdatatoEXECLtable.Text");
  1358. saveFileDialog.FileName = PdnResources.GetString("Menu.estructurecharacteristics.text") + DateTime.Now.ToString("yyyyMMddhhmmss");
  1359. saveFileDialog.Filter = "microsoft office execl files (*.xlsx)|*.xlsx";
  1360. saveFileDialog.RestoreDirectory = true;
  1361. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  1362. {
  1363. List<System.Data.DataTable> list = new List<System.Data.DataTable>();
  1364. foreach (System.Data.DataTable itemTable in ds.Tables)
  1365. list.Add(itemTable);
  1366. this.appWorkspace.ExportDataToExcelWithProgress(list, saveFileDialog.FileName, true, false, true);
  1367. }
  1368. }
  1369. catch (Exception e)
  1370. {
  1371. throw e;
  1372. }
  1373. }
  1374. #endregion
  1375. //二值化集成3
  1376. #region 二值化相关方法
  1377. private void InclusionsStandardDialog_FormClosing(object sender, FormClosingEventArgs e)
  1378. {
  1379. #region [开启脚本录制]
  1380. if (appWorkspace.startScriptRecording)
  1381. {
  1382. getScriptRecording();
  1383. }
  1384. #endregion
  1385. binaryClass.saveParams();
  1386. }
  1387. private void ShownChoiseItemAndInitData(object sender, EventArgs e)
  1388. {
  1389. binaryClass.RefreshHistogramControl1Values();
  1390. }
  1391. /// <summary>
  1392. /// 添加参数改变的监听
  1393. /// </summary>
  1394. /// <param name="sender"></param>
  1395. /// <param name="e"></param>
  1396. private void PetroleumGeologyStandardDialog_Load(object sender, EventArgs e)
  1397. {
  1398. this.binaryClass.loadParams();
  1399. }
  1400. private bool bcBinaryChecked()
  1401. {
  1402. return bc != null && bc.BinaryChecked;
  1403. }
  1404. private bool bcOriginChecked()
  1405. {
  1406. return bc != null && bc.OriginChecked;
  1407. }
  1408. /// <summary>
  1409. /// 参数改变时,重新处理图像
  1410. /// </summary>
  1411. /// <param name="sender"></param>
  1412. /// <param name="e"></param>
  1413. private void bClassBinaryImplFinishAction(object sender, EventArgs e)
  1414. {
  1415. this.documentWorkspace.Refresh();
  1416. }
  1417. /// <summary>
  1418. /// 显示原图/原图+二值图
  1419. /// </summary>
  1420. /// <param name="sender"></param>
  1421. /// <param name="e"></param>
  1422. private void bcOriginCheckedChanged(object sender, EventArgs e)
  1423. {
  1424. if (!bcOriginChecked())
  1425. {
  1426. if (bcBinaryChecked())
  1427. this.documentWorkspace.PhaseModels[0].choise = true;
  1428. }
  1429. else
  1430. {
  1431. this.documentWorkspace.PhaseModels[0].choise = false;
  1432. }
  1433. this.documentWorkspace.Refresh();
  1434. }
  1435. #endregion
  1436. protected void panelColor_Click(object sender, EventArgs e)
  1437. {
  1438. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
  1439. this.colorsPanel = (Panel)sender;
  1440. this.colorsFormGrid.ShowDialog();
  1441. }
  1442. /// <summary>
  1443. /// Panel2的调色板颜色改变
  1444. /// </summary>
  1445. /// <param name="sender"></param>
  1446. /// <param name="e"></param>
  1447. private void gridColorChanged(object sender, EventArgs e)
  1448. {
  1449. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  1450. if (colorsPanel != null)
  1451. {
  1452. colorsPanel.BackColor = color;
  1453. //刷新显示页面文字颜色
  1454. this.documentWorkspace.Refresh();
  1455. }
  1456. //关闭色板
  1457. this.colorsFormGrid.Close();
  1458. }
  1459. #region 可调用方法
  1460. /// <summary>
  1461. /// 是否显示原图
  1462. /// </summary>
  1463. /// <returns></returns>
  1464. protected Boolean showOrimat()
  1465. {
  1466. return bcOriginChecked();
  1467. }
  1468. /// <summary>
  1469. /// 是否能取到二值的结果
  1470. /// </summary>
  1471. /// <returns></returns>
  1472. protected Boolean getBinaryChecked()
  1473. {
  1474. return (bcBinaryChecked() && this.documentWorkspace.PhaseModels[0].mat != null);
  1475. }
  1476. /// <summary>
  1477. /// 返回当前选择的图片内容
  1478. /// </summary>
  1479. /// <returns></returns>
  1480. protected DocumentWorkspace getCurrentWorkspace()
  1481. {
  1482. return this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index];
  1483. }
  1484. /// <summary>
  1485. /// 返回当前选择的图片tag
  1486. /// </summary>
  1487. /// <returns></returns>
  1488. protected string getCurrentWorkTag()
  1489. {
  1490. return this.imageList_img.Images.Keys[this.lstView_img.FocusedItem.Index/*lstView_img.SelectedItems[0].Index*/];
  1491. }
  1492. protected bool holeNumberVisible = false;
  1493. /// <summary>
  1494. /// 喉道分割后的图片
  1495. /// </summary>
  1496. private Mat segmentedHolesMat;
  1497. /// <summary>
  1498. /// 显示、隐藏孔隙编号
  1499. /// </summary>
  1500. /// <param name="visible"></param>
  1501. protected void controlHoleNumberVisible(bool visible)
  1502. {
  1503. holeNumberVisible = visible;
  1504. if (holeNumberVisible && minLinePoints.Count > 0 &&
  1505. /*成功获取喉道分割后的图片*/(segmentedHolesMat == null && createSegmentedHoldsMat() || segmentedHolesMat != null))
  1506. {
  1507. //this.documentWorkspace.PhaseModels[0].choise = false;
  1508. //this.documentWorkspace.PhaseModels[1].choise = true;
  1509. //this.documentWorkspace.PhaseModels[2].choise = true;
  1510. }
  1511. else
  1512. {
  1513. //this.documentWorkspace.PhaseModels[0].choise = true;
  1514. //this.documentWorkspace.PhaseModels[1].choise = false;
  1515. //this.documentWorkspace.PhaseModels[2].choise = false;
  1516. holeNumberVisible = false;
  1517. }
  1518. this.documentWorkspace.PhaseModels[0].choise = true;
  1519. this.documentWorkspace.Refresh();
  1520. }
  1521. /// <summary>
  1522. /// 获取喉道分割后的图片
  1523. /// </summary>
  1524. private bool createSegmentedHoldsMat()
  1525. {
  1526. if (this.documentWorkspace.PhaseModels.Count > 0 && this.documentWorkspace.PhaseModels[0].choise == true && this.documentWorkspace.PhaseModels[0].mat != null)
  1527. {
  1528. }
  1529. else
  1530. return false;
  1531. Mat src = this.documentWorkspace.PhaseModels[0].mat;
  1532. Mat distance_temp = new Mat();
  1533. //灰度图
  1534. Mat Inmat = BinaryClass.BGRA2GRAY(this.documentWorkspace.PhaseModels[0].mat)/* //### .CvtColor(ColorConversionCodes.BGR2GRAY)*/;
  1535. Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise);
  1536. Mat newMat = new Mat(src.Height, src.Width, MatType.CV_8UC4, new Scalar(0, 0, 0, 0));
  1537. Bitmap newBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(newMat);
  1538. Graphics graphics = Graphics.FromImage(newBit);
  1539. Pen linePen = new Pen(Color.FromArgb(this.documentWorkspace.PhaseModels[0].color), 2/*1*/);
  1540. foreach (var itemLine in minLinePoints.Values)
  1541. {
  1542. graphics.DrawLine(linePen, itemLine.startPoint, itemLine.endPoint);
  1543. }
  1544. Mat dst = new Mat();
  1545. Mat mat1 = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  1546. int w = src.Width;
  1547. int h = src.Height;
  1548. int w1 = mat1.Width;
  1549. int h1 = mat1.Height;
  1550. Mat mat2 = new Mat(h, w, src.Type(), Scalar.All(0));
  1551. Rect rect = new Rect(0, 0, Math.Min(w, w1), Math.Min(h, h1));
  1552. Mat tempMat = mat1.Clone(rect);
  1553. //复制用户选中的区域到原图像
  1554. Mat mask = tempMat.CvtColor(ColorConversionCodes.RGBA2GRAY);
  1555. Mat pos = new Mat(mat2, rect);
  1556. tempMat.CopyTo(pos, mask);
  1557. //Cv2.CopyMakeBorder(src, src, 0, maxh - src.Height, 0, maxw - src.Width, BorderTypes.Isolated);
  1558. //Cv2.CopyMakeBorder(mat1, mat1, 0, maxh - mat1.Height, 0, maxw - mat1.Width, BorderTypes.Isolated);
  1559. Mat tempMat0 = src.Clone(rect);
  1560. //复制用户选中的区域到原图像
  1561. Mat mask0 = tempMat0.CvtColor(ColorConversionCodes.RGBA2GRAY);
  1562. Mat mat0 = new Mat(h, w, src.Type(), Scalar.All(/*255*/0));
  1563. Mat pos0 = new Mat(mat0, rect);
  1564. tempMat0.CopyTo(pos0, mask0);
  1565. Cv2.Subtract(src/*待确认效果:mat0*/, mat2, dst);
  1566. //Cv2.Subtract(src, mat1, dst);
  1567. if (segmentedHolesMat != null)
  1568. {
  1569. segmentedHolesMat.Dispose();
  1570. segmentedHolesMat = null;
  1571. }
  1572. segmentedHolesMat = dst.Clone();
  1573. //this.documentWorkspace.PhaseModels[1].mat = dst;
  1574. //显示连通域和编号信息
  1575. Mat erzhi = dst;//.Clone();
  1576. //Cv2.ImShow("erzhi1", erzhi);
  1577. //Cv2.WaitKey();
  1578. Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY);
  1579. //Cv2.ImShow("erzhi2", erzhi);
  1580. //Cv2.WaitKey();
  1581. Cv2.Threshold(erzhi, erzhi, 10, 255, ThresholdTypes.Binary);
  1582. //Cv2.ImShow("erzhi3", erzhi);
  1583. //Cv2.WaitKey();
  1584. OpenCvSharp.Point[][] contours;
  1585. HierarchyIndex[] hierarchy;
  1586. Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  1587. List<OpenCvSharp.Point[]> pointss = new List<OpenCvSharp.Point[]>();
  1588. foreach (OpenCvSharp.Point[] contour in contours)
  1589. {
  1590. if (contour.Length < 10000/*100*/)
  1591. {
  1592. foreach (OpenCvSharp.Point point in contour)
  1593. {
  1594. erzhi.Set<byte>(point.Y, point.X, 255);
  1595. }
  1596. pointss.Add(contour);
  1597. }
  1598. }
  1599. //Cv2.ImShow("dst", dst);
  1600. //Cv2.ImShow("erzhi", erzhi);
  1601. //Cv2.WaitKey();
  1602. Cv2.FillPoly(erzhi, pointss, new Scalar(255));
  1603. //// 二次轮廓
  1604. //Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  1605. ////// 计算所有轮廓质点
  1606. ////List<Point2d> massPoints = new List<Point2d>();
  1607. ////foreach (OpenCvSharp.Point[] contour in contours)
  1608. ////{
  1609. //// OpenCvSharp.Moments moments = new OpenCvSharp.Moments(contour, false);
  1610. //// massPoints.Add(new Point2d(moments.M10 / moments.M00, moments.M01 / moments.M00));
  1611. ////}
  1612. lstAttribute.Clear();
  1613. Mat labelMat = new Mat();
  1614. Mat stats = new Mat();
  1615. Mat centroids = new Mat();
  1616. // 连通域数量
  1617. int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
  1618. List<int> attribute;
  1619. for (int hcomp = 1; hcomp < centroids.Height; hcomp++)
  1620. {
  1621. //double a = centroids.At<double>(h, 0);
  1622. //double b = centroids.At<double>(h, 1);
  1623. int x = (int)centroids.At<double>(hcomp, 0);// stats.At<int>(hcomp, 0);
  1624. int y = (int)centroids.At<double>(hcomp, 1);// stats.At<int>(hcomp, 1);
  1625. int width = stats.At<int>(hcomp, 2);
  1626. int height = stats.At<int>(hcomp, 3);
  1627. if (x < 0 || y < 0 || width > bitmap.Width || height > bitmap.Height || x >= bitmap.Width || y >= bitmap.Height)
  1628. {
  1629. continue;
  1630. }
  1631. int areaField1 = stats.At<int>(hcomp, 4);
  1632. attribute = new List<int>();
  1633. //int label = labelMat.At<int>(y, x);
  1634. attribute.Add(hcomp);
  1635. attribute.Add(x);
  1636. attribute.Add(y);
  1637. attribute.Add(width);
  1638. attribute.Add(height);
  1639. attribute.Add(areaField1);
  1640. attribute.Add(0);//喉道数量
  1641. attribute.Add(hcomp);//编号
  1642. attribute.Add(0);//孔隙周边长,单位是像素
  1643. attribute.Add(0);//与该空腔连通的喉道总宽度,单位是像素
  1644. //attribute.Add(0);//长径
  1645. //attribute.Add(0);//短径
  1646. //attribute.Add(0);//平均径
  1647. //lstAttribute.Add(attribute);
  1648. ////double areaField = areaField1 * unitLength * unitLength;
  1649. Point centerRadiusPoint = new Point(x, y);
  1650. Point startPoint;
  1651. Point endPoint;
  1652. bool notFound;
  1653. int matHeight = erzhi.Height;
  1654. int matWidth = erzhi.Width;
  1655. int step = -1;
  1656. List<int> d2list = new List<int>();
  1657. for (int rotateAngleV = 0; rotateAngleV < 360; rotateAngleV += 15)
  1658. {
  1659. notFound = true;
  1660. startPoint = new Point(x, y);
  1661. while (notFound)
  1662. {
  1663. startPoint.X += step;
  1664. Point itemP11 = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, startPoint.X, startPoint.Y, centerRadiusPoint.X, centerRadiusPoint.Y);
  1665. if (itemP11.Y < 0 || itemP11.X < 0 || itemP11.Y >= matHeight || itemP11.X >= matWidth)
  1666. {
  1667. startPoint.X = itemP11.X;
  1668. startPoint.Y = itemP11.Y;
  1669. notFound = false;
  1670. break;
  1671. }
  1672. Vec4b vec4B = erzhi/*binary_temp*/.At<Vec4b>(itemP11.Y, itemP11.X);
  1673. if (vec4B.Item3 == 0)
  1674. {
  1675. startPoint.X = itemP11.X;
  1676. startPoint.Y = itemP11.Y;
  1677. notFound = false;
  1678. break;
  1679. }
  1680. }
  1681. notFound = true;
  1682. endPoint = new Point(x, y);
  1683. while (notFound)
  1684. {
  1685. endPoint.X -= step;
  1686. Point itemP11 = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, endPoint.X, endPoint.Y, centerRadiusPoint.X, centerRadiusPoint.Y);
  1687. if (itemP11.Y < 0 || itemP11.X < 0 || itemP11.Y >= matHeight || itemP11.X >= matWidth)
  1688. {
  1689. endPoint.X = itemP11.X;
  1690. endPoint.Y = itemP11.Y;
  1691. notFound = false;
  1692. break;
  1693. }
  1694. Vec4b vec4B = erzhi/*binary_temp*/.At<Vec4b>(itemP11.Y, itemP11.X);
  1695. if (vec4B.Item3 == 0)
  1696. {
  1697. endPoint.X = itemP11.X;
  1698. endPoint.Y = itemP11.Y;
  1699. notFound = false;
  1700. break;
  1701. }
  1702. }
  1703. //int d2Value = (startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) + (startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y);
  1704. d2list.Add((startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) + (startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y));
  1705. //int insertIndex = 0;
  1706. //for (int id2Index = 0; id2Index < d2list.Count; id2Index++)
  1707. //{
  1708. // if (d2Value > d2list[id2Index])
  1709. // ++insertIndex;
  1710. // else
  1711. // break;
  1712. //}
  1713. //d2list.Insert(insertIndex, d2Value);
  1714. }
  1715. d2list.Sort();
  1716. attribute.Add(d2list[d2list.Count-1]);//长径
  1717. attribute.Add(d2list[0]);//短径
  1718. attribute.Add(d2list.ToArray().Sum() / d2list.Count());//平均径
  1719. lstAttribute.Add(attribute);
  1720. }
  1721. // 计算所有轮廓周边长(即孔隙周边长,单位是像素)
  1722. int labelP2;
  1723. int labelP3;
  1724. //Mat dismat = new Mat(distance_temp.Height, distance_temp.Width, MatType.CV_8UC4, new Scalar(0, 0, 0, 0));
  1725. Point[] offsetPoints1 = new Point[] { new Point(-1, -1), new Point(0, -1), new Point(1, -1), new Point(1, 0), new Point(1, 1), new Point(0, 1), new Point(-1, 1), new Point(-1, 0) };
  1726. //float currDistance;
  1727. for (int int_Y = 1; int_Y < distance_temp.Height - 1; int_Y++)
  1728. {
  1729. for (int int_X = 1; int_X < distance_temp.Width - 1; int_X++)
  1730. {
  1731. labelP2 = labelMat.At<int>(int_Y, int_X);
  1732. if (labelP2 > 0)
  1733. {
  1734. //循环找内圈的轮廓点
  1735. foreach (var itemOffset in offsetPoints1)
  1736. {
  1737. labelP3 = labelMat.At<int>(int_Y + itemOffset.Y, int_X + itemOffset.X);
  1738. if (labelP3 == 0)
  1739. {
  1740. //dismat.Set<Vec4b>(int_Y, int_X, new Vec4b(0, 255, 0, 255));
  1741. lstAttribute[labelP2 - 1][8] += 1;
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. //循环找外圈的轮廓点
  1748. foreach (var itemOffset in offsetPoints1)
  1749. {
  1750. labelP2 = labelMat.At<int>(int_Y + itemOffset.Y, int_X + itemOffset.X);
  1751. if (labelP2 > 0)
  1752. {
  1753. //dismat.Set<Vec4b>(int_Y, int_X, new Vec4b(0, 255, 0, 255));
  1754. lstAttribute[labelP2 - 1][8] += 1;
  1755. }
  1756. }
  1757. }
  1758. //currDistance = distance_temp.At<float>(int_Y, int_X);
  1759. //if (currDistance == 1 || int_Y == 0 || int_X == 0 || int_X == distance_temp.Width - 1 || int_Y == distance_temp.Height - 1)
  1760. //{
  1761. // dismat.Set<Vec4b>(int_Y, int_X, new Vec4b(0, 255, 0, 255));
  1762. // labelP2 = labelMat.At<int>(int_Y, int_X);
  1763. // if (labelP2 > 0)
  1764. // {
  1765. // lstAttribute[labelP2 - 1][8] += 1;
  1766. // }
  1767. //}
  1768. }
  1769. }
  1770. foreach (var itemAttri in lstAttribute)
  1771. {
  1772. itemAttri[8] /= 6/*2*/;
  1773. }
  1774. for (int int_Y = 0; int_Y < distance_temp.Height; int_Y++)
  1775. {
  1776. int int_X = 0;
  1777. labelP2 = labelMat.At<int>(int_Y, int_X);
  1778. if (labelP2 > 0)
  1779. lstAttribute[labelP2 - 1][8] += 1;
  1780. }
  1781. for (int int_Y = 0; int_Y < distance_temp.Height; int_Y++)
  1782. {
  1783. int int_X = distance_temp.Width - 1;
  1784. labelP2 = labelMat.At<int>(int_Y, int_X);
  1785. if (labelP2 > 0)
  1786. lstAttribute[labelP2 - 1][8] += 1;
  1787. }
  1788. for (int int_X = 1; int_X < distance_temp.Width - 1; int_X++)
  1789. {
  1790. int int_Y = 0;
  1791. labelP2 = labelMat.At<int>(int_Y, int_X);
  1792. if (labelP2 > 0)
  1793. lstAttribute[labelP2 - 1][8] += 1;
  1794. }
  1795. for (int int_X = 1; int_X < distance_temp.Width - 1; int_X++)
  1796. {
  1797. int int_Y = distance_temp.Height - 1;
  1798. labelP2 = labelMat.At<int>(int_Y, int_X);
  1799. if (labelP2 > 0)
  1800. lstAttribute[labelP2 - 1][8] += 1;
  1801. }
  1802. //Cv2.ImShow("dis", dismat);
  1803. //Cv2.WaitKey();
  1804. //foreach (OpenCvSharp.Point[] contour in contours)
  1805. //{
  1806. // labelP2 = -1;
  1807. // foreach (var itemP2 in contour)
  1808. // {
  1809. // labelP2 = labelMat.At<int>(itemP2.Y, itemP2.X);
  1810. // if (labelP2 > 0 && lstAttribute[labelP2 - 1][8] == 0)
  1811. // {
  1812. // lstAttribute[labelP2 - 1][8] += contour.Length;
  1813. // break;
  1814. // }
  1815. // }
  1816. //}
  1817. Point itemP;
  1818. int matW = labelMat.Width;
  1819. int matH = labelMat.Height;
  1820. int countP;
  1821. int labelP1;
  1822. //int labelP2;
  1823. Point[] offsetPoints = new Point[] { new Point(-1, -1), new Point(0, -1), new Point(1, -1), new Point(1, 0), new Point(1, 1), new Point(0, 1), new Point(-1, 1), new Point(-1, 0) ,
  1824. new Point(0, -2), new Point(2, 0), new Point(0, 2), new Point(-2, 0), new Point(-2, -2), new Point(-2, 2), new Point(2, 2), new Point(2, -2) };
  1825. //获取连通域的喉道信息
  1826. foreach (var itemLine in minLinePoints.Values)
  1827. {
  1828. itemP = new Point((itemLine.startPoint.X + itemLine.endPoint.X) / 2, (itemLine.startPoint.Y + itemLine.endPoint.Y) / 2);
  1829. if (itemP.Y < 2 || itemP.X < 2 || itemP.Y >= matH - 1 || itemP.X >= matW - 1)
  1830. continue;
  1831. countP = 0;
  1832. labelP1 = -1;
  1833. labelP2 = -1;
  1834. foreach (var itemOffset in offsetPoints)
  1835. {
  1836. labelP2 = labelMat.At<int>(itemP.Y + itemOffset.Y, itemP.X + itemOffset.X);
  1837. if (labelP2 > 0 && labelP2 != labelP1)
  1838. {
  1839. List<int> attributeP = lstAttribute[labelP2 - 1];
  1840. attributeP[6] = attributeP[6] + 1;
  1841. attributeP[9] = attributeP[9] + (int)Math.Sqrt((itemLine.startPoint.Y - itemLine.endPoint.Y) * (itemLine.startPoint.Y - itemLine.endPoint.Y) + (itemLine.startPoint.X - itemLine.endPoint.X) * (itemLine.startPoint.X - itemLine.endPoint.X));
  1842. labelP1 = labelP2;
  1843. if (++countP > 1)
  1844. break;
  1845. }
  1846. }
  1847. //graphics.DrawLine(linePen, itemLine.startPoint, itemLine.endPoint);
  1848. }
  1849. //// 连通域质点
  1850. //Dictionary<int, Point2d> keyValues = new Dictionary<int, Point2d>();
  1851. //massLabelPoints.Clear();
  1852. //foreach (var item in massPoints)
  1853. //{
  1854. // if (double.IsNaN(item.Y) || double.IsNaN(item.X))
  1855. // {
  1856. // continue;
  1857. // }
  1858. // int label = labelMat.At<int>((int)item.Y, (int)item.X);
  1859. // if (0 <= label/* && label <= nccomps*/)
  1860. // {
  1861. // keyValues[label] = item;
  1862. // }
  1863. //}
  1864. //// 矩形边线上的连通域
  1865. //ArrayList nccompSelect = new ArrayList();
  1866. //Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC4);
  1867. //Random rd = new Random();
  1868. //List<Vec4b> colors = new List<Vec4b>(nccomps);
  1869. ////colors.Add(new Vec4b(0, 0, 0, 0));
  1870. //for (int i = 0; i < nccomps; i++)
  1871. //{
  1872. // //colors.Add(new Vec3b(255, 255, 255));
  1873. // colors.Add(new Vec4b(((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), 255));
  1874. //}
  1875. //for (int y = 0; y < temp.Rows; y++)
  1876. //{
  1877. // for (int x = 0; x < temp.Cols; x++)
  1878. // {
  1879. // int label = labelMat.At<int>(y, x);
  1880. // if (label > 0)
  1881. // temp.Set<Vec4b>(y, x, colors[label]);
  1882. // }
  1883. //}
  1884. ////foreach (var item in massPoints)
  1885. ////{
  1886. //// if (double.IsNaN(item.Y) || double.IsNaN(item.X))
  1887. //// {
  1888. //// continue;
  1889. //// }
  1890. //// temp.Set<Vec4b>((int)item.Y, (int)item.X, new Vec4b(0, 0, 255, 255));
  1891. ////}
  1892. //////Cv2.ImShow("temp", temp);
  1893. //this.documentWorkspace.PhaseModels[2].mat = temp;
  1894. this.documentWorkspace.Refresh();
  1895. return true;
  1896. }
  1897. /// <summary>
  1898. /// 用于枝干相交的坐标点集合
  1899. /// </summary>
  1900. List<Point2d> massLabelPoints = new List<Point2d>();
  1901. /// <summary>
  1902. /// 用于枝干末梢的坐标点集合
  1903. /// </summary>
  1904. List<Point2d> sideLabelPoints = new List<Point2d>();
  1905. /// <summary>
  1906. /// 用于枝干与轮廓截线长度为极小值的坐标点集合 key为点 value为距离值
  1907. /// </summary>
  1908. Dictionary<Point2d, float> minLabelPoints = new Dictionary<Point2d, float>();
  1909. /// <summary>
  1910. /// 用于枝干与轮廓截线长度为极小值的坐标点集合 key为点 value为线的坐标
  1911. /// </summary>
  1912. Dictionary<Point2d, Line> minLinePoints = new Dictionary<Point2d, Line>();
  1913. /// <summary>
  1914. /// 寻找极小值的坐标点集合,用来记录已经走过的点,避免路径重复
  1915. /// </summary>
  1916. List<Point> routePoints = new List<Point>();
  1917. /// <summary>
  1918. /// 手动分割
  1919. /// </summary>
  1920. protected void menuSegmentAction(Button sender)
  1921. {
  1922. addPoint = !addPoint;
  1923. sender.Text = addPoint ? PdnResources.GetString("Menu.segmented.text") : PdnResources.GetString("Menu.Manualsegmentation.text");
  1924. }
  1925. /// <summary>
  1926. /// 将多颜色图像转换为单颜色图像,避免抽骨架算不出结果
  1927. /// </summary>
  1928. /// <param name="phaseModel"></param>
  1929. /// <returns></returns>
  1930. private Mat getBinaryOneColorPicture(PhaseModel phaseModel)
  1931. {
  1932. if (phaseModel.mat == null)
  1933. return null;
  1934. Mat phaseModelMat = phaseModel.mat.Clone();
  1935. Mat multipleMat = new Mat(phaseModelMat.Height/*Width*/, phaseModelMat.Width/*Height*/, MatType.CV_8UC4, new Scalar(0, 0, 0, 0));
  1936. for (int int_Y = 0; int_Y < phaseModelMat.Height; int_Y++)
  1937. {
  1938. for (int int_X = 0; int_X < phaseModelMat.Width; int_X++)
  1939. {
  1940. if (phaseModelMat.At<Vec4b>(int_Y, int_X).Item3 > 0)
  1941. multipleMat.Set<Vec4b>(int_Y, int_X, new Vec4b(0, 255, 0, 255));
  1942. }
  1943. }
  1944. phaseModelMat.Dispose();
  1945. phaseModelMat = null;
  1946. return multipleMat;
  1947. }
  1948. ProgressThreadProcClass procClass;
  1949. private int thresholdValue;
  1950. /// <summary>
  1951. /// 自动分割
  1952. /// </summary>
  1953. /// <param name="thresholdValue">阈值(μm)</param>
  1954. protected void autoSegmentAction(int thresholdValue)
  1955. {
  1956. if (this.matOrg == null)
  1957. {
  1958. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  1959. return;
  1960. }
  1961. if (this.documentWorkspace.PhaseModels.Count > 0 && this.documentWorkspace.PhaseModels[0].choise == true && this.documentWorkspace.PhaseModels[0].mat != null)
  1962. {
  1963. //PhaseModel phasesCopy = new PhaseModel();
  1964. //phasesCopy.mat = this.getBinaryOneColorPicture(this.documentWorkspace.PhaseModels[0]);// this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//#################
  1965. ////phasesCopy.mat = this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//#################
  1966. //phasesCopy.color = Color.Green/*panel2.BackColor*/.ToArgb();
  1967. //action912.PerformProcess(phasesCopy, 1).CopyTo(matGeology);
  1968. ////灰度图
  1969. //Mat Inmat = this.documentWorkspace.PhaseModels[0].mat.CvtColor(ColorConversionCodes.BGR2GRAY);
  1970. ////Cv2.ImShow("Inmat", Inmat);
  1971. //Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise);
  1972. ////Cv2.ImShow("distance_temp", distance_temp);
  1973. //binary_temp = this.documentWorkspace.PhaseModels[0].mat.Clone();
  1974. }
  1975. else
  1976. {
  1977. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  1978. return;
  1979. }
  1980. this.thresholdValue = thresholdValue;
  1981. procClass = new ProgressThreadProcClass();
  1982. procClass.StartProgressAutoAction(this, new System.Threading.ThreadStart(applyAutoSegAction), "自动分割");
  1983. if (segmentedHolesMat != null)
  1984. {
  1985. segmentedHolesMat.Dispose();
  1986. segmentedHolesMat = null;
  1987. }
  1988. if (segmentedHolesMat == null && createSegmentedHoldsMat() || segmentedHolesMat != null)
  1989. {
  1990. }
  1991. else
  1992. //图像分割
  1993. this.documentWorkspace.Refresh();
  1994. }
  1995. private void applyAutoSegAction()
  1996. {
  1997. //int matValue = 10;// (int)(thresholdValue / this.physical_length);
  1998. Action912 action912 = new Action912();
  1999. if (matGeology != null)
  2000. matGeology.Dispose();
  2001. matGeology = new Mat();
  2002. Mat distance_temp = new Mat();
  2003. Mat binary_temp = null;
  2004. if (this.documentWorkspace.PhaseModels.Count > 0 && this.documentWorkspace.PhaseModels[0].choise == true && this.documentWorkspace.PhaseModels[0].mat != null)
  2005. {
  2006. PhaseModel phasesCopy = new PhaseModel();
  2007. phasesCopy.mat = this.getBinaryOneColorPicture(this.documentWorkspace.PhaseModels[0]);// this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//#################
  2008. //phasesCopy.mat = this.documentWorkspace.PhaseModels[0].mat.Clone();//对多相进行处理//#################
  2009. phasesCopy.color = Color.Green/*panel2.BackColor*/.ToArgb();
  2010. action912.PerformProcess(phasesCopy, 1).CopyTo(matGeology);
  2011. //灰度图
  2012. Mat Inmat = BinaryClass.BGRA2GRAY(this.documentWorkspace.PhaseModels[0].mat)/* //### .CvtColor(ColorConversionCodes.BGR2GRAY)*/;
  2013. //Cv2.ImShow("Inmat", Inmat);
  2014. Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise);
  2015. //Cv2.ImShow("distance_temp", distance_temp);
  2016. binary_temp = this.documentWorkspace.PhaseModels[0].mat.Clone();
  2017. }
  2018. else
  2019. {
  2020. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  2021. return;
  2022. OpenCvSharp.Mat mat = action912.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
  2023. if (mat != null)
  2024. {
  2025. mat.CopyTo(matGeology);
  2026. //灰度图
  2027. Mat Inmat = this.documentWorkspace.PhaseModels[0].mat.CvtColor(ColorConversionCodes.BGR2GRAY);
  2028. Cv2.ImShow("Inmat", Inmat);
  2029. Cv2.DistanceTransform(Inmat, distance_temp, DistanceTypes.L2, DistanceMaskSize.Precise);
  2030. }
  2031. //Document doc = Document.FromMat(mat);
  2032. //this.documentWorkspace.Document = doc;
  2033. //this.documentWorkspace.Refresh();
  2034. }
  2035. //标记所有相交和末梢的点
  2036. massLabelPoints.Clear();
  2037. sideLabelPoints.Clear();
  2038. for (int index_x = 1; index_x < matGeology.Width - 1; index_x++)
  2039. {
  2040. for (int index_y = 1; index_y < matGeology.Height - 1; index_y++)
  2041. {
  2042. int countSideLines = GetBoundryCountDOfBinary(new Point(index_x, index_y), matGeology);
  2043. if (countSideLines > 2)
  2044. massLabelPoints.Add(new Point2d(index_x, index_y));
  2045. else if (countSideLines == 1)
  2046. sideLabelPoints.Add(new Point2d(index_x, index_y));
  2047. }
  2048. }
  2049. //从末梢的点开始寻找截线的极小值点
  2050. routePoints.Clear();
  2051. minLabelPoints.Clear();
  2052. foreach (Point2d pointSide in sideLabelPoints)
  2053. {
  2054. Dictionary<Point2d, float> minPoint = GetMinLabelPoint(thresholdValue * thresholdValue, new Point((int)pointSide.X, (int)pointSide.Y), matGeology, distance_temp, new Dictionary<Point2d, float>(), float.MinValue, float.MinValue);
  2055. if (minPoint != null && minPoint.Count > 0)
  2056. foreach (var item in minPoint)
  2057. minLabelPoints.Add(item.Key, item.Value);
  2058. }
  2059. foreach (Point2d pointSide in massLabelPoints)
  2060. {
  2061. Dictionary<Point2d, float> minPoint = GetMinLabelPoint(thresholdValue * thresholdValue, new Point((int)pointSide.X, (int)pointSide.Y), matGeology, distance_temp, new Dictionary<Point2d, float>(), float.MinValue, float.MinValue);
  2062. if (minPoint != null && minPoint.Count > 0)
  2063. foreach (var item in minPoint)
  2064. minLabelPoints.Add(item.Key, item.Value);
  2065. }
  2066. //根据极小值点获取截线
  2067. minLinePoints.Clear();
  2068. if (minLabelPoints.Count > 0 && binary_temp != null)
  2069. {
  2070. foreach (var item in minLabelPoints.Keys)
  2071. {
  2072. int radius = (int)(Math.Sqrt(minLabelPoints[new Point2d((int)item.X, (int)item.Y)]) + 1);
  2073. Point line1Point = GetMinRadiusPoint(new Point((int)item.X, (int)item.Y), radius, matGeology, binary_temp);
  2074. if (line1Point.X > 0 && line1Point.Y > 0)
  2075. {
  2076. Point line2Point = GetMinAnotherPoint(thresholdValue * thresholdValue, new Point((int)item.X, (int)item.Y), line1Point, radius, binary_temp);
  2077. if (line2Point.X > 0 && line2Point.Y > 0)
  2078. {
  2079. Line lineI = new Line(line1Point, line2Point/*new Point((int)item.X, (int)item.Y)*/);
  2080. if ((lineI.startPoint.X - lineI.endPoint.X) * (lineI.startPoint.X - lineI.endPoint.X) + (lineI.startPoint.Y - lineI.endPoint.Y) * (lineI.startPoint.Y - lineI.endPoint.Y)
  2081. <= thresholdValue * thresholdValue / (this.physical_length * this.physical_length))
  2082. minLinePoints.Add(new Point2d((int)item.X, (int)item.Y), lineI);
  2083. }
  2084. else
  2085. {
  2086. Line lineI = GetMinLinePoint(thresholdValue * thresholdValue, new Point((int)item.X, (int)item.Y), radius, binary_temp);
  2087. if (lineI != null && (lineI.startPoint.X - lineI.endPoint.X) * (lineI.startPoint.X - lineI.endPoint.X) + (lineI.startPoint.Y - lineI.endPoint.Y) * (lineI.startPoint.Y - lineI.endPoint.Y)
  2088. <= thresholdValue * thresholdValue / (this.physical_length * this.physical_length))
  2089. {
  2090. minLinePoints.Add(new Point2d((int)item.X, (int)item.Y), lineI);
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. //for (int lineIndex = minLinePoints.Count - 1; lineIndex >= 0; lineIndex--)
  2097. //{
  2098. // Line lineI = minLinePoints.Values[lineIndex];
  2099. // if ((lineI.startPoint.X - lineI.endPoint.X) * (lineI.startPoint.X - lineI.endPoint.X) + (lineI.startPoint.Y - lineI.endPoint.Y) * (lineI.startPoint.Y - lineI.endPoint.Y)
  2100. // <= thresholdValue * thresholdValue / (this.physical_length * this.physical_length))
  2101. // {
  2102. // }
  2103. //}
  2104. if (procClass != null) procClass.DismissProgressAction(this);
  2105. }
  2106. #endregion
  2107. /// <summary>
  2108. /// 根据圆心得到截线与轮廓的截线
  2109. /// </summary>
  2110. /// <param name="threshold_2">阈值的平方</param>
  2111. /// <param name="center">圆心</param>
  2112. /// <param name="radius">半径</param>
  2113. /// <param name="binary_temp">二值提取的mat</param>
  2114. /// <returns></returns>
  2115. private Line GetMinLinePoint(int threshold_2, Point center, int radius, Mat binary_temp)
  2116. {
  2117. Line line = null;// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue));
  2118. int matW = binary_temp.Width;
  2119. int matH = binary_temp.Height;
  2120. int luntimes = radius * 10;
  2121. int step = -1;
  2122. int length_2 = 0;
  2123. Point startPoint = new Point(center.X, center.Y);
  2124. Point endPoint = new Point(center.X, center.Y);
  2125. for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15)
  2126. {
  2127. startPoint = new Point(center.X, center.Y);
  2128. step = -1;
  2129. for (int i = 1; i < luntimes; i++)
  2130. {
  2131. startPoint.X += step;
  2132. Point itemP = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, startPoint.X, startPoint.Y, center.X, center.Y);
  2133. if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW)
  2134. continue;
  2135. Vec4b vec4B = binary_temp.At<Vec4b>(itemP.Y, itemP.X);
  2136. if (vec4B.Item3 == 0)
  2137. {
  2138. startPoint.X = itemP.X;
  2139. startPoint.Y = itemP.Y;
  2140. break;
  2141. }
  2142. }
  2143. endPoint = new Point(center.X, center.Y);
  2144. step = 1;
  2145. for (int i = 1; i < luntimes; i++)
  2146. {
  2147. endPoint.X += step;
  2148. Point itemP = rotatedVPaiPoint(rotateAngleV * Math.PI / 180.0, endPoint.X, endPoint.Y, center.X, center.Y);
  2149. if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW)
  2150. continue;
  2151. Vec4b vec4B = binary_temp.At<Vec4b>(itemP.Y, itemP.X);
  2152. if (vec4B.Item3 == 0)
  2153. {
  2154. endPoint.X = itemP.X;
  2155. endPoint.Y = itemP.Y;
  2156. break;
  2157. }
  2158. }
  2159. if (line == null || ((startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) + (startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y))
  2160. < length_2)
  2161. {
  2162. line = new Line(new Point(startPoint.X, startPoint.Y), new Point(endPoint.X, endPoint.Y));
  2163. length_2 = (line.startPoint.X - line.endPoint.X) * (line.startPoint.X - line.endPoint.X) + (line.startPoint.Y - line.endPoint.Y) * (line.startPoint.Y - line.endPoint.Y);
  2164. }
  2165. }
  2166. if (radius > 1 && length_2 > radius * radius * 50 && length_2 < 10)
  2167. {
  2168. return null;
  2169. }
  2170. return line;
  2171. }
  2172. /// <summary>
  2173. /// 根据圆心和其中一个交点得到截线与轮廓的另一个交点
  2174. /// </summary>
  2175. /// <param name="threshold_2">阈值的平方</param>
  2176. /// <param name="center">圆心</param>
  2177. /// <param name="startP">其中一个交点</param>
  2178. /// <param name="radius">半径</param>
  2179. /// <param name="binary_temp">二值提取的mat</param>
  2180. /// <returns></returns>
  2181. private Point GetMinAnotherPoint(int threshold_2, Point center, Point startP, int radius, Mat binary_temp)
  2182. {
  2183. Point line1Point = new Point(-1, -1);
  2184. bool rotateFromY = true;
  2185. Point startRotateFormerPoint = new Point(startP.X, startP.Y);
  2186. if (Math.Abs(center.X - startP.X) > Math.Abs(center.Y - startP.Y))
  2187. {
  2188. startRotateFormerPoint.Y = center.Y;
  2189. rotateFromY = false;
  2190. }
  2191. else
  2192. {
  2193. startRotateFormerPoint.X = center.X;
  2194. rotateFromY = true;
  2195. }
  2196. int length = rotateFromY ? (center.Y - startP.Y) : (center.X - startP.X);
  2197. if (length == 0)
  2198. return line1Point;
  2199. int count = Math.Abs(length);
  2200. int step = length / count;
  2201. int length_2 = 0;
  2202. int matW = binary_temp.Width;
  2203. int matH = binary_temp.Height;
  2204. double rotateAngle = AngleText(new PointF(center.X, center.Y), new PointF(startRotateFormerPoint.X, startRotateFormerPoint.Y), new PointF(startP.X, startP.Y));
  2205. Point endRotateFormerPoint = new Point(center.X, center.Y);
  2206. int luntimes;
  2207. if (count < 3)
  2208. {
  2209. luntimes = 4;
  2210. }
  2211. else
  2212. {
  2213. luntimes = count * 3;
  2214. }
  2215. if (rotateFromY)
  2216. {
  2217. for (int i = 1; i < luntimes; i++)
  2218. {
  2219. endRotateFormerPoint.Y += step;
  2220. Point itemP = rotatedVPaiPoint(rotateAngle, endRotateFormerPoint.X, endRotateFormerPoint.Y, center.X, center.Y);
  2221. if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW)
  2222. continue;
  2223. Vec4b vec4B = binary_temp.At<Vec4b>(itemP.Y, itemP.X);
  2224. if (vec4B.Item3 == 0)
  2225. {
  2226. length_2 = (itemP.X - startP.X) * (itemP.X - startP.X) + (itemP.Y - startP.Y) * (itemP.Y - startP.Y);
  2227. if (length_2 > 9)
  2228. {
  2229. line1Point = new Point(itemP.X, itemP.Y);
  2230. }
  2231. break;
  2232. }
  2233. }
  2234. }
  2235. else
  2236. {
  2237. for (int i = 1; i < luntimes; i++)
  2238. {
  2239. endRotateFormerPoint.X += step;
  2240. Point itemP = rotatedVPaiPoint(rotateAngle, endRotateFormerPoint.X, endRotateFormerPoint.Y, center.X, center.Y);
  2241. if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW)
  2242. continue;
  2243. Vec4b vec4B = binary_temp.At<Vec4b>(itemP.Y, itemP.X);
  2244. if (vec4B.Item3 == 0)
  2245. {
  2246. length_2 = (itemP.X - startP.X) * (itemP.X - startP.X) + (itemP.Y - startP.Y) * (itemP.Y - startP.Y);
  2247. if (length_2 > 9)
  2248. {
  2249. line1Point = new Point(itemP.X, itemP.Y);
  2250. }
  2251. break;
  2252. }
  2253. }
  2254. }
  2255. return line1Point;
  2256. }
  2257. /// <summary>
  2258. /// 根据圆心和半径得到截线与其中一端轮廓的交点
  2259. /// </summary>
  2260. /// <param name="center">圆心</param>
  2261. /// <param name="radius">半径</param>
  2262. /// <param name="mat">抽骨架的mat</param>
  2263. /// <param name="binary_temp">二值提取的mat</param>
  2264. /// <returns></returns>
  2265. private Point GetMinRadiusPoint(Point center, int radius, Mat mat, Mat binary_temp)
  2266. {
  2267. Point line1Point = new Point(-1, -1);// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue));
  2268. // 圆上的点集合
  2269. Point[] points1 = roundOutline(center, radius);
  2270. int matW = binary_temp.Width;
  2271. int matH = binary_temp.Height;
  2272. foreach (var itemP in points1)
  2273. {
  2274. if (itemP.Y < 0 || itemP.X < 0 || itemP.Y >= matH || itemP.X >= matW)
  2275. continue;
  2276. Vec4b vec4B = binary_temp.At<Vec4b>(itemP.Y, itemP.X);
  2277. if (vec4B.Item3 == 0)
  2278. {
  2279. line1Point = new Point(itemP.X, itemP.Y);
  2280. break;
  2281. }
  2282. }
  2283. //for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15)
  2284. //{
  2285. // Point startPoint = new Point(-1, -1);
  2286. // while (startPoint.X < -10)
  2287. // {
  2288. // }
  2289. // for (int length = 0; length < 100; length++)
  2290. // {
  2291. // }
  2292. //}
  2293. return line1Point;
  2294. }
  2295. /// <summary>
  2296. /// 根据圆心和半径得到截线与其中一端轮廓的交点
  2297. /// </summary>
  2298. /// <param name="point">圆心</param>
  2299. /// <param name="radius">半径</param>
  2300. /// <param name="mat">抽骨架的mat</param>
  2301. /// <param name="binary_temp">二值提取的mat</param>
  2302. /// <returns></returns>
  2303. private Line GetMinRadiusLine(Point point, int radius, Mat mat, Mat binary_temp)
  2304. {
  2305. Line line = null;// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue));
  2306. for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15)
  2307. {
  2308. Point startPoint = new Point(-1, -1);
  2309. while (startPoint.X < -10)
  2310. {
  2311. }
  2312. for (int length = 0; length < 100; length++)
  2313. {
  2314. }
  2315. }
  2316. return line;
  2317. }
  2318. /// <summary>
  2319. ///
  2320. /// </summary>
  2321. /// <param name="point"></param>
  2322. /// <param name="mat">抽骨架的mat</param>
  2323. /// <param name="binary_temp">二值提取的mat</param>
  2324. /// <returns></returns>
  2325. private Line GetMinLabelLine(Point point, Mat mat, Mat binary_temp)
  2326. {
  2327. Line line = null;// new Line(new Point(int.MinValue, int.MinValue), new Point(int.MaxValue, int.MaxValue));
  2328. for (int rotateAngleV = 0; rotateAngleV < 361; rotateAngleV += 15)
  2329. {
  2330. Point startPoint = new Point(-1, -1);
  2331. while (startPoint.X < 0)
  2332. {
  2333. }
  2334. for (int length = 0; length < 100; length++)
  2335. {
  2336. }
  2337. }
  2338. return line;
  2339. }
  2340. /// <summary>
  2341. /// 三点角计算
  2342. /// </summary>
  2343. /// <param name="cen"></param>
  2344. /// <param name="first"></param>
  2345. /// <param name="second"></param>
  2346. /// <returns></returns>
  2347. public double AngleText(PointF cen, PointF first, PointF second)
  2348. {
  2349. double ma_x = first.X - cen.X;
  2350. double ma_y = first.Y - cen.Y;
  2351. double mb_x = second.X - cen.X;
  2352. double mb_y = second.Y - cen.Y;
  2353. double v1 = (ma_x * mb_x) + (ma_y * mb_y);
  2354. double ma_val = Math.Sqrt(ma_x * ma_x + ma_y * ma_y);
  2355. double mb_val = Math.Sqrt(mb_x * mb_x + mb_y * mb_y);
  2356. double cosM = v1 / (ma_val * mb_val);
  2357. double angleAMB = Math.Acos(cosM);// * 180 / M_PI;
  2358. return angleAMB;
  2359. }
  2360. /// <summary>
  2361. /// 获取旋转后的坐标点
  2362. /// </summary>
  2363. /// <param name="rotatedVPai">旋转角度</param>
  2364. /// <param name="point_X">旋转前的X坐标</param>
  2365. /// <param name="point_Y">旋转前的Y坐标</param>
  2366. /// <param name="centerX">旋转中心点X坐标</param>
  2367. /// <param name="centerY">旋转中心点Y坐标</param>
  2368. /// <returns></returns>
  2369. private Point rotatedVPaiPoint(double rotatedVPai, float point_X, float point_Y, float centerX, float centerY)
  2370. {
  2371. //double rotatedVPai = rotateAngleV * Math.PI / 180.0;
  2372. double disX = point_X - centerX;
  2373. double disY = point_Y - centerY;
  2374. double outX = disX * Math.Cos(rotatedVPai) - disY * Math.Sin(rotatedVPai);
  2375. double outY = disX * Math.Sin(rotatedVPai) + disY * Math.Cos(rotatedVPai);
  2376. return new Point((int)(outX + centerX), (int)(outY + centerY));
  2377. //return new PointF((float)outX + centerX, (float)outY + centerY);
  2378. }
  2379. /// <summary>
  2380. /// 获取旋转后的坐标点
  2381. /// </summary>
  2382. /// <param name="rotateAngleV">旋转角度</param>
  2383. /// <param name="point_X">旋转前的X坐标</param>
  2384. /// <param name="point_Y">旋转前的Y坐标</param>
  2385. /// <param name="centerX">旋转中心点X坐标</param>
  2386. /// <param name="centerY">旋转中心点Y坐标</param>
  2387. /// <returns></returns>
  2388. private PointF rotatedPoint(int rotateAngleV, float point_X, float point_Y, float centerX, float centerY)
  2389. {
  2390. double rotatedVPai = rotateAngleV * Math.PI / 180.0;
  2391. double disX = point_X - centerX;
  2392. double disY = point_Y - centerY;
  2393. double outX = disX * Math.Cos(rotatedVPai) - disY * Math.Sin(rotatedVPai);
  2394. double outY = disX * Math.Sin(rotatedVPai) + disY * Math.Cos(rotatedVPai);
  2395. return new PointF((float)outX + centerX, (float)outY + centerY);
  2396. }
  2397. #region 需继承方法
  2398. protected virtual void drawSubclass(Graphics graphics)
  2399. {
  2400. if (showOrimat())
  2401. return;
  2402. ////if (matGeology != null && matGeology.Width > 0 && matGeology.Height > 0)
  2403. ////{
  2404. //// graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(matGeology), 0, 0);
  2405. ////}
  2406. //if (sideLabelPoints.Count > 0 && false)
  2407. //{
  2408. // Pen pointsPen = new Pen(Color.Yellow, 2);
  2409. // foreach (var item in sideLabelPoints)
  2410. // {
  2411. // graphics.DrawEllipse(pointsPen, new RectangleF((float)item.X - 1, (float)item.Y - 1, 3, 3));
  2412. // }
  2413. //}
  2414. ////if (minLabelPoints.Count > 0)
  2415. ////{
  2416. //// Pen pointsPen = new Pen(Color.Yellow, 1);
  2417. //// foreach (var item in minLabelPoints.Keys)
  2418. //// {
  2419. //// graphics.DrawEllipse(pointsPen, new RectangleF((float)item.X, (float)item.Y, 1, 1));
  2420. //// }
  2421. ////}
  2422. if (addPoint && m_StartPoint.X > 0 && m_StartPoint.Y > 0 && m_EndPoint.X > 0 && m_EndPoint.Y > 0)
  2423. {
  2424. Pen pointsPen = new Pen(Color.Blue, 1);
  2425. graphics.DrawLine(pointsPen, new Point((int)m_StartPoint.X, (int)m_StartPoint.Y), new Point((int)m_EndPoint.X, (int)m_EndPoint.Y));
  2426. }
  2427. if (minLinePoints.Count > 0/* && !holeNumberVisible*/)
  2428. {
  2429. Pen pointsPen = new Pen(Color.Blue, 1);
  2430. foreach (var item in minLinePoints.Values)
  2431. {
  2432. graphics.DrawLine(pointsPen, item.startPoint, item.endPoint);
  2433. }
  2434. }
  2435. //if (lstAttribute.Count > 0 && holeNumberVisible)
  2436. //{
  2437. // Font myFont = new Font("宋体", 8/*, FontStyle.Bold*/);
  2438. // Brush bush = new SolidBrush(/*this.panel1.BackColor*/Color.Black);//填充的颜色
  2439. // foreach (var attribute in lstAttribute)
  2440. // {
  2441. // if (attribute[7] == 27)
  2442. // {
  2443. // graphics.DrawString(/*attribute[0] + */"" + attribute[7], myFont, new SolidBrush(/*this.panel1.BackColor*/Color.Green), (float)attribute[1] - 3, (float)attribute[2] - 3);
  2444. // }
  2445. // else
  2446. // graphics.DrawString(/*attribute[0] + */"" + attribute[7], myFont, bush, (float)attribute[1] - 3, (float)attribute[2] - 3);
  2447. // }
  2448. //}
  2449. //if (massLabelPoints.Count > 0 && false)
  2450. //{
  2451. // //int index = 0;
  2452. // Pen pointsPen = new Pen(Color.Yellow, 2);
  2453. // //Font myFont = new Font("宋体", 12/*, FontStyle.Bold*/);
  2454. // //Brush bush = new SolidBrush(this.panel1.BackColor/*Color.Red*/);//填充的颜色
  2455. // foreach (var item in massLabelPoints)
  2456. // {
  2457. // graphics.DrawEllipse(pointsPen, new RectangleF((float)item.X - 1, (float)item.Y - 1, 3, 3));
  2458. // //graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5);
  2459. // }
  2460. //}
  2461. }
  2462. /// <summary>
  2463. /// 图片索引改变后调用的事件
  2464. /// </summary>
  2465. protected virtual void refreshWhileImgChanged()
  2466. {
  2467. }
  2468. protected virtual void refreshPhaseModelChoise()
  2469. {
  2470. }
  2471. /// <summary>
  2472. /// 获取孔隙直径计算类型 1长径 2短径 3平均径 4等效圆直径 5φ值
  2473. /// </summary>
  2474. /// <returns></returns>
  2475. protected virtual int getHolesType()
  2476. {
  2477. return 4;
  2478. }
  2479. /// <summary>
  2480. /// 获取孔隙直径
  2481. /// </summary>
  2482. /// <param name="attribute"></param>
  2483. /// <returns></returns>
  2484. protected double getHolesD(List<int> attribute)
  2485. {
  2486. int holesType = getHolesType();
  2487. switch (holesType)
  2488. {
  2489. case 1:
  2490. return Math.Sqrt(attribute[10] * this.physical_length * this.physical_length);
  2491. break;
  2492. case 2:
  2493. return Math.Sqrt(attribute[11] * this.physical_length * this.physical_length);
  2494. break;
  2495. case 3:
  2496. return Math.Sqrt(attribute[12] * this.physical_length * this.physical_length);
  2497. break;
  2498. case 4:
  2499. return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2;
  2500. break;
  2501. case 5:
  2502. return 0.3815 + 0.9027 * Math.Sqrt(attribute[10] * this.physical_length * this.physical_length);
  2503. //{
  2504. // double longD = Math.Sqrt(attribute[10] * this.physical_length * this.physical_length);
  2505. // return 0.3815 + 0.9027 * Math.Sqrt(attribute[10] * this.physical_length * this.physical_length);
  2506. //}
  2507. //return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2;
  2508. break;
  2509. default:
  2510. return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2;
  2511. }
  2512. //return Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2;
  2513. }
  2514. /// <summary>
  2515. /// 获取视孔隙比表面
  2516. /// </summary>
  2517. /// <param name="attribute"></param>
  2518. /// <returns></returns>
  2519. private double getHolesS0(List<int> attribute)
  2520. {
  2521. return 4 * attribute[8] / (attribute[5] * this.physical_length * Math.PI);
  2522. }
  2523. /// <summary>
  2524. /// 获取形状因子
  2525. /// </summary>
  2526. /// <param name="attribute"></param>
  2527. /// <returns></returns>
  2528. private double getHolesF(List<int> attribute)
  2529. {
  2530. return Math.Min(1.0, 4 * Math.PI * (attribute[5] - 0) / (attribute[8] * attribute[8]));
  2531. }
  2532. /// <summary>
  2533. /// 获取孔喉比
  2534. /// </summary>
  2535. /// <param name="attribute"></param>
  2536. /// <returns></returns>
  2537. private string getHolesRpt(List<int> attribute)
  2538. {
  2539. return attribute[9] == 0 ? "无" : "" + Math.Sqrt(attribute[5] / Math.PI) * 2 * attribute[6] / attribute[9];
  2540. }
  2541. /// <summary>
  2542. /// 获取孔喉比
  2543. /// </summary>
  2544. /// <param name="attribute"></param>
  2545. /// <returns></returns>
  2546. private double getHolesRptValue(List<int> attribute)
  2547. {
  2548. return attribute[9] == 0 ? 0 : Math.Sqrt(attribute[5] / Math.PI) * 2 * attribute[6] / attribute[9];
  2549. }
  2550. /// <summary>
  2551. /// 保存结果
  2552. /// </summary>
  2553. protected virtual void buildListBox_analysisResult()
  2554. {
  2555. if (this.matOrg == null)
  2556. {
  2557. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  2558. return;
  2559. }
  2560. if (lstAttribute.Count == 0)
  2561. {
  2562. MessageBox.Show(PdnResources.GetString("Menu.Noanalysisresults.text"));
  2563. return;
  2564. }
  2565. string imgName = getCurrentWorkspace().GetFriendlyName();
  2566. string tag = getCurrentWorkTag();
  2567. DataTable dataTable;
  2568. bool replace = false;
  2569. int add = 0;
  2570. foreach (ListViewItem item in this.listView2.Items)
  2571. {
  2572. if (item.Tag.Equals(tag))
  2573. {
  2574. add++;
  2575. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  2576. if (dr == DialogResult.OK)
  2577. {
  2578. replace = true;
  2579. }
  2580. break;
  2581. }
  2582. }
  2583. if (replace || this.listView2.Items.Count == 0 || add == 0)
  2584. {
  2585. if (!replace)
  2586. {
  2587. ListViewItem listViewItem = new ListViewItem();
  2588. listViewItem.SubItems[0].Text = imgName;
  2589. listViewItem.Tag = "" + tag;
  2590. if (this.listView2.Items.Count == 0)
  2591. this.listView2.Items.Add(listViewItem);
  2592. else
  2593. this.listView2.Items.Insert(0, listViewItem);
  2594. }
  2595. this.dataGridView2.Rows.Clear();
  2596. //this.dataTables.Clear();
  2597. for (int dataTableI = dataTables.Count - 1; dataTableI >= 0; dataTableI--)
  2598. {
  2599. System.Data.DataTable dataTable1 = dataTables[dataTableI];
  2600. if (dataTable1.TableName.Equals(tag))
  2601. dataTables.RemoveAt(dataTableI);
  2602. }
  2603. if (lstAttriDict.ContainsKey(tag))
  2604. lstAttriDict.Remove(tag);
  2605. List<List<int>> attriValues = new List<List<int>>();
  2606. List<int> listValues;
  2607. //添加视域的面积信息
  2608. listValues = new List<int>();
  2609. listValues.Add(this.bitmap.Width * this.bitmap.Height);
  2610. //foreach (var itemInt in attribute)
  2611. // listValues.Add(itemInt);
  2612. attriValues.Add(listValues);
  2613. DataGridViewRow dgvr;// = new DataGridViewRow();
  2614. //attribute = new List<int>();
  2615. //attribute.Add(hcomp);
  2616. //attribute.Add(x);
  2617. //attribute.Add(y);
  2618. //attribute.Add(width);
  2619. //attribute.Add(height);
  2620. //attribute.Add(areaField1);
  2621. //attribute.Add(0);//喉道数量
  2622. //attribute.Add(hcomp);//编号
  2623. //attribute.Add(0);//孔隙周边长,单位是像素
  2624. //attribute.Add(0);//与该空腔连通的喉道总宽度,单位是像素
  2625. //lstAttribute.Add(attribute);
  2626. string value0 = imgName;
  2627. string value1 = PdnResources.GetString("Menu.view.text")+"0";//视场
  2628. //string value2;// = firRow.Cells[1].Value;//编号
  2629. //int value3;// = firRow.Cells[2].Value;//孔隙直径
  2630. //视孔隙比表面
  2631. //形状因子
  2632. //孔喉比
  2633. //配位数
  2634. foreach (var attribute in lstAttribute)
  2635. {
  2636. //if (attribute[5] < 5)
  2637. // continue;
  2638. listValues = new List<int>();
  2639. foreach (var itemInt in attribute)
  2640. listValues.Add(itemInt);
  2641. attriValues.Add(listValues);
  2642. dgvr = new DataGridViewRow();
  2643. dgvr.Tag = tag;
  2644. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  2645. {
  2646. dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  2647. }
  2648. dgvr.Cells[0].Value = value0;
  2649. dgvr.Cells[1].Value = value1;
  2650. dgvr.Cells[2].Value = attribute[7];//编号
  2651. dgvr.Cells[3].Value = this.getHolesD(attribute);//孔隙直径
  2652. dgvr.Cells[4].Value = this.getHolesS0(attribute);//视孔隙比表面(<--4/* * this.physical_length*/ * attribute[8] / (attribute[5]/* * this.physical_length*/ * this.physical_length * Math.PI);)
  2653. dgvr.Cells[5].Value = this.getHolesF(attribute);//形状因子
  2654. dgvr.Cells[6].Value = this.getHolesRpt(attribute);//孔喉比(<--Math.Sqrt(attribute[5] * this.physical_length * this.physical_length / Math.PI) * 2 / (attribute[9] * this.physical_length / attribute[6]))
  2655. dgvr.Cells[7].Value = attribute[6];//配位数
  2656. this.dataGridView2.Rows.Add(dgvr);
  2657. dataTable = new DataTable();
  2658. dataTable.TableName = tag;
  2659. for (int i = 0; i < this.dataGridView2.Columns.Count; i++)
  2660. {
  2661. dataTable.Columns.Add("" + i);
  2662. }
  2663. DataRow dataRow = dataTable.NewRow();
  2664. dataRow["0"] = value0;
  2665. dataRow["1"] = dgvr.Cells[1].Value;
  2666. dataRow["2"] = dgvr.Cells[2].Value;
  2667. dataRow["3"] = dgvr.Cells[3].Value;
  2668. dataRow["4"] = dgvr.Cells[4].Value;
  2669. dataRow["5"] = dgvr.Cells[5].Value;
  2670. dataRow["6"] = dgvr.Cells[6].Value;
  2671. dataRow["7"] = dgvr.Cells[7].Value;
  2672. dataTable.Rows.Add(dataRow);
  2673. this.dataTables.Add(dataTable);
  2674. }
  2675. lstAttriDict.Add(tag, attriValues);
  2676. //if (this.allShow)
  2677. // AllShow();
  2678. this.RefreshDataGridView4();
  2679. //保存处理后的图片
  2680. double pantographRatio = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  2681. List<Bitmap> tempBit = new List<Bitmap>();
  2682. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.lstView_img.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  2683. originalBit.Tag = pantographRatio;
  2684. tempBit.Add(originalBit);
  2685. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  2686. Graphics graphics = Graphics.FromImage(newBit);
  2687. if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null)
  2688. {
  2689. Mat targetMat = this.documentWorkspace.PhaseModels[0].mat;
  2690. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  2691. }
  2692. Draw(graphics);
  2693. newBit.Tag = pantographRatio;
  2694. tempBit.Add(newBit);
  2695. if (bitDic.ContainsKey(tag))
  2696. bitDic[tag] = tempBit;
  2697. else
  2698. bitDic.Add(tag, tempBit);
  2699. //中间数据-拼接中间数据
  2700. List<List<string>> dataList = new List<List<string>>();
  2701. //string value0 = imgName;//图片
  2702. //string value1 = "视场0";//视场
  2703. ////string value2;// = firRow.Cells[1].Value;//编号
  2704. ////int value3;// = firRow.Cells[2].Value;//孔隙直径
  2705. ////视孔隙比表面
  2706. ////形状因子
  2707. ////孔喉比
  2708. ////配位数
  2709. List<string> columnName = new List<string>();
  2710. columnName.Add(PdnResources.GetString("Menu.picture.Text"));
  2711. columnName.Add(PdnResources.GetString("Menu.view.text"));
  2712. columnName.Add(PdnResources.GetString("Menu.Dedicatedanalysis.Non-ferrousmetals.serialnumber.text"));
  2713. columnName.Add(PdnResources.GetString("Menu.Theporediameter.text"));
  2714. columnName.Add(PdnResources.GetString("Menu.Apparentporeratiosurface.text"));
  2715. columnName.Add(PdnResources.GetString("Menu.Shapefactor.text"));
  2716. columnName.Add(PdnResources.GetString("Menu.Porethroatthan.text"));
  2717. columnName.Add(PdnResources.GetString("Menu.Coordinationnumber.text"));
  2718. dataList.Add(columnName);
  2719. foreach (DataGridViewRow Row in this.dataGridView2/*dataGridView1*/.Rows)
  2720. {
  2721. List<string> strList = new List<string>();
  2722. strList.Add(Row.Cells[0].Value.ToString());
  2723. strList.Add(Row.Cells[1].Value.ToString());
  2724. strList.Add(Row.Cells[2].Value.ToString());
  2725. strList.Add(Row.Cells[3].Value.ToString());
  2726. strList.Add(Row.Cells[4].Value.ToString());
  2727. strList.Add(Row.Cells[5].Value.ToString());
  2728. strList.Add(Row.Cells[6].Value.ToString());
  2729. strList.Add(Row.Cells[7].Value.ToString());
  2730. dataList.Add(strList);
  2731. }
  2732. bool isExist = false;//是否已存在进行替换
  2733. int modelIndex = -1;//要替换的下标
  2734. for (int j = 0; j < tempDataModel.Count; j++)
  2735. {
  2736. if (tempDataModel[j].tagName.Equals(tag))
  2737. {
  2738. isExist = true;
  2739. modelIndex = j;
  2740. break;
  2741. }
  2742. }
  2743. if (isExist && modelIndex > -1)
  2744. tempDataModel[modelIndex].dataList = dataList;
  2745. else
  2746. {
  2747. Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel();
  2748. newModel.tagName = tag;
  2749. newModel.picName = imgName;
  2750. newModel.dataList = dataList;
  2751. tempDataModel.Add(newModel);
  2752. }
  2753. }
  2754. //this.listBox_analysisResult.Items.Clear();
  2755. ////foreach (var item in analysisResults.Keys)
  2756. ////{
  2757. //// this.listBox_analysisResult.Items.Add(new LocalListViewItem(item, item.GetFriendlyName()));
  2758. ////}
  2759. ////buildListView_analysisResult();
  2760. }
  2761. protected virtual void SubclassInitialize()
  2762. {
  2763. throw new NotImplementedException();
  2764. }
  2765. /// <summary>
  2766. /// 报告模板命名
  2767. /// </summary>
  2768. /// <returns></returns>
  2769. protected virtual string getTemplateName()
  2770. {
  2771. throw new NotImplementedException();
  2772. }
  2773. /// <summary>
  2774. /// 项目工程内的文件夹路径名称
  2775. /// </summary>
  2776. /// <returns></returns>
  2777. protected virtual string getProjectEngineeringName()
  2778. {
  2779. throw new NotImplementedException();
  2780. }
  2781. protected virtual void getScriptRecording()
  2782. {
  2783. }
  2784. #endregion
  2785. #region 内部类
  2786. private int GetBoundryCountDOfBinary(Point point, Mat mat)
  2787. {
  2788. int count = 0;
  2789. if (point.X > mat.Width - 2 || point.X < 1 || point.Y > mat.Height - 2 || point.Y < 1)
  2790. {
  2791. return count;
  2792. }
  2793. bool firstValueOnBoundry = false;
  2794. bool lastValueOnBoundry = false;
  2795. Vec4b vec4B = mat.At<Vec4b>(point.Y, point.X);
  2796. if (vec4B.Item3 == 0)
  2797. return -1;
  2798. vec4B = mat.At<Vec4b>(point.Y - 1, point.X - 1);
  2799. if (vec4B.Item3 != 0)
  2800. {
  2801. count++;
  2802. firstValueOnBoundry = true;
  2803. lastValueOnBoundry = true;
  2804. }
  2805. vec4B = mat.At<Vec4b>(point.Y - 1, point.X);
  2806. if (vec4B.Item3 != 0)
  2807. {
  2808. if (!lastValueOnBoundry)
  2809. count++;
  2810. lastValueOnBoundry = true;
  2811. }
  2812. else lastValueOnBoundry = false;
  2813. vec4B = mat.At<Vec4b>(point.Y - 1, point.X + 1);
  2814. if (vec4B.Item3 != 0)
  2815. {
  2816. if (!lastValueOnBoundry)
  2817. count++;
  2818. lastValueOnBoundry = true;
  2819. }
  2820. else lastValueOnBoundry = false;
  2821. vec4B = mat.At<Vec4b>(point.Y, point.X + 1);
  2822. if (vec4B.Item3 != 0)
  2823. {
  2824. if (!lastValueOnBoundry)
  2825. count++;
  2826. lastValueOnBoundry = true;
  2827. }
  2828. else lastValueOnBoundry = false;
  2829. vec4B = mat.At<Vec4b>(point.Y + 1, point.X + 1);
  2830. if (vec4B.Item3 != 0)
  2831. {
  2832. if (!lastValueOnBoundry)
  2833. count++;
  2834. lastValueOnBoundry = true;
  2835. }
  2836. else lastValueOnBoundry = false;
  2837. vec4B = mat.At<Vec4b>(point.Y + 1, point.X);
  2838. if (vec4B.Item3 != 0)
  2839. {
  2840. if (!lastValueOnBoundry)
  2841. count++;
  2842. lastValueOnBoundry = true;
  2843. }
  2844. else lastValueOnBoundry = false;
  2845. vec4B = mat.At<Vec4b>(point.Y + 1, point.X - 1);
  2846. if (vec4B.Item3 != 0)
  2847. {
  2848. if (!lastValueOnBoundry)
  2849. count++;
  2850. lastValueOnBoundry = true;
  2851. }
  2852. else lastValueOnBoundry = false;
  2853. vec4B = mat.At<Vec4b>(point.Y, point.X - 1);
  2854. if (vec4B.Item3 != 0)
  2855. {
  2856. if (!lastValueOnBoundry && !firstValueOnBoundry)
  2857. count++;
  2858. }
  2859. return count;
  2860. }
  2861. internal class LocalListViewItem
  2862. {
  2863. public DocumentWorkspace Value { get; }
  2864. public string Display { get; }
  2865. public LocalListViewItem(DocumentWorkspace Value, string Display)
  2866. {
  2867. this.Value = Value;
  2868. this.Display = Display;
  2869. }
  2870. }
  2871. internal class DocumentItem
  2872. {
  2873. public Bitmap bitmap;
  2874. public GraphicsList graphicsList;
  2875. public List<PhaseModel> phaseModels;
  2876. //public AnalysisResult analysisResult;
  2877. public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List<PhaseModel> phaseModels)
  2878. {
  2879. this.bitmap = bitmap;
  2880. this.graphicsList = graphicsList;
  2881. this.phaseModels = phaseModels;
  2882. }
  2883. }
  2884. internal class Line
  2885. {
  2886. /// <summary>
  2887. /// 直线的起点
  2888. /// </summary>
  2889. public System.Drawing.Point startPoint;
  2890. /// <summary>
  2891. /// 直线的终点
  2892. /// </summary>
  2893. public System.Drawing.Point endPoint;
  2894. /// <summary>
  2895. /// 构造方法
  2896. /// </summary>
  2897. /// <param name="s"></param>
  2898. /// <param name="e"></param>
  2899. public Line(System.Drawing.Point s, System.Drawing.Point e)
  2900. {
  2901. this.startPoint = s;
  2902. this.endPoint = e;
  2903. }
  2904. }
  2905. #endregion
  2906. /// <summary>
  2907. /// 使用圆心及半径得到圆的轮廓
  2908. /// </summary>
  2909. /// <param name="center">圆心</param>
  2910. /// <param name="radius">半径</param>
  2911. /// <returns></returns>
  2912. public Point[] roundOutline(Point center, int radius)
  2913. {
  2914. if (radius < 1) radius = 1;
  2915. Mat mat = new Mat((int)(radius * 2.1), (int)(radius * 2.1), MatType.CV_8UC1, new Scalar(0, 0, 0));
  2916. OpenCvSharp.Point point = new OpenCvSharp.Point(mat.Cols / 2, mat.Rows / 2);
  2917. Cv2.Circle(mat, point, radius, new Scalar(255, 255, 255), -1);
  2918. OpenCvSharp.Point[][] contours;
  2919. HierarchyIndex[] hierarchy;
  2920. Cv2.FindContours(mat, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
  2921. if (contours.Length > 0)
  2922. {
  2923. OpenCvSharp.Point[] roundOutline = contours[0];
  2924. Point[] roundOutPoints = new Point[roundOutline.Length];
  2925. for (int i = 0; i < roundOutline.Length; i++)
  2926. {
  2927. roundOutPoints[i].X = roundOutline[i].X - point.X + center.X;
  2928. roundOutPoints[i].Y = roundOutline[i].Y - point.Y + center.Y;
  2929. }
  2930. return roundOutPoints;
  2931. }
  2932. return new Point[0];
  2933. }
  2934. private void button16_Click(object sender, EventArgs e)
  2935. {
  2936. this.button11.Visible = true;
  2937. this.button16.Visible = false;
  2938. this.button11.Focus();
  2939. this.allShow = false;
  2940. if (this.listView2.SelectedItems.Count <= 0)
  2941. return;
  2942. this.dataGridView2.Rows.Clear();
  2943. for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  2944. {
  2945. System.Data.DataTable dataTable1 = new System.Data.DataTable();
  2946. foreach (var dataTable in this.dataTables)
  2947. {
  2948. if (this.listView2.SelectedItems.Count > 0)
  2949. {
  2950. if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  2951. dataTable1 = dataTable;
  2952. }
  2953. else
  2954. {
  2955. if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
  2956. dataTable1 = dataTable;
  2957. }
  2958. }
  2959. DataGridViewRow dgvr = new DataGridViewRow();
  2960. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  2961. {
  2962. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  2963. }
  2964. for (int c = 0; c < dataTable1.Columns.Count; c++)
  2965. {
  2966. dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
  2967. }
  2968. this.dataGridView2.Rows.Add(dgvr);
  2969. }
  2970. this.RefreshDataGridView4();
  2971. }
  2972. /// <summary>
  2973. /// 添加显示并刷新dataGridView1的数据
  2974. /// </summary>
  2975. /// <param name="tempsAttribute"></param>
  2976. protected void AddRowDataGridView1(List<List<int>> tempsAttribute)
  2977. {
  2978. DataTable dataTable;
  2979. this.dataGridView1.Rows.Clear();
  2980. DataGridViewRow dgvr = new DataGridViewRow();
  2981. //获取视域面积
  2982. List<int> areaInt = tempsAttribute[0];
  2983. //attribute = new List<int>();
  2984. //attribute.Add(hcomp);
  2985. //attribute.Add(x);
  2986. //attribute.Add(y);
  2987. //attribute.Add(width);
  2988. //attribute.Add(height);
  2989. //attribute.Add(areaField1);
  2990. //attribute.Add(0);//喉道数量
  2991. //attribute.Add(hcomp);//编号
  2992. //attribute.Add(0);//孔隙周边长,单位是像素
  2993. //attribute.Add(0);//与该空腔连通的喉道总宽度,单位是像素
  2994. //lstAttribute.Add(attribute);
  2995. double value0 = 0;//面孔率(第i个孔隙的面积)
  2996. double value1_0 = 0;//第i个孔隙直径
  2997. double value1 = 0;//平均孔隙直径
  2998. double value2 = 0;//平均视孔隙比表面
  2999. double value3 = 0;//平均孔隙形状因子
  3000. double value4 = 0;//平均孔喉比
  3001. double value5 = 0;//均质系数(最大孔隙直径)
  3002. double value6 = 0;//孔隙直径分选系数
  3003. double value7 = 0;//平均孔隙配位数
  3004. for (int attributeI = 1; attributeI < lstAttribute.Count; attributeI++)
  3005. {
  3006. var attribute = lstAttribute[attributeI];
  3007. //if (attribute[5] < 5)
  3008. // continue;
  3009. value0 += attribute[5];
  3010. value1_0 = this.getHolesD(attribute);
  3011. value1 += value1_0 * attribute[5] * 100.0 / areaInt[0];
  3012. value2 += this.getHolesS0(attribute);
  3013. value3 += this.getHolesF(attribute);
  3014. value4 += this.getHolesRptValue(attribute);
  3015. if (value1_0 > value5)
  3016. value5 = value1_0;
  3017. value7 += attribute[6];
  3018. }
  3019. dgvr.Tag = "tag";//<--tag
  3020. foreach (DataGridViewColumn c in this.dataGridView1.Columns)
  3021. {
  3022. dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  3023. }
  3024. double outValue;
  3025. //面孔率
  3026. value0 = value0 * 100.0 / areaInt[0];
  3027. if (double.TryParse(string.IsNullOrEmpty(value0.ToString()) ? "0" :
  3028. value0.ToString(), out outValue))
  3029. {
  3030. dgvr.Cells[0].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3031. }
  3032. else
  3033. dgvr.Cells[0].Value = value0.ToString();
  3034. //平均孔隙直径
  3035. value1 = value1 / 100.0;// areaInt[0]/*(lstAttribute.Count - 1)*/;
  3036. if (double.TryParse(string.IsNullOrEmpty(value1.ToString()) ? "0" :
  3037. value1.ToString(), out outValue))
  3038. {
  3039. dgvr.Cells[1].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3040. }
  3041. else
  3042. dgvr.Cells[1].Value = value1.ToString();
  3043. //平均视孔隙比表面
  3044. value2 = value2 / (lstAttribute.Count - 1);
  3045. if (double.TryParse(string.IsNullOrEmpty(value2.ToString()) ? "0" :
  3046. value2.ToString(), out outValue))
  3047. {
  3048. dgvr.Cells[2].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3049. }
  3050. else
  3051. dgvr.Cells[2].Value = value2.ToString();
  3052. //平均孔隙形状因子
  3053. value3 = 4 * Math.PI * value3 / (lstAttribute.Count - 1);
  3054. if (double.TryParse(string.IsNullOrEmpty(value3.ToString()) ? "0" :
  3055. value3.ToString(), out outValue))
  3056. {
  3057. dgvr.Cells[3].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3058. }
  3059. else
  3060. dgvr.Cells[3].Value = value3.ToString();
  3061. //平均孔喉比
  3062. value4 = value4 / (lstAttribute.Count - 1);
  3063. if (double.TryParse(string.IsNullOrEmpty(value4.ToString()) ? "0" :
  3064. value4.ToString(), out outValue))
  3065. {
  3066. dgvr.Cells[4].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3067. }
  3068. else
  3069. dgvr.Cells[4].Value = value4.ToString();
  3070. //均质系数
  3071. value5 = value1 / value5;
  3072. if (double.TryParse(string.IsNullOrEmpty(value5.ToString()) ? "0" :
  3073. value5.ToString(), out outValue))
  3074. {
  3075. dgvr.Cells[5].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3076. }
  3077. else
  3078. dgvr.Cells[5].Value = value5.ToString();
  3079. //孔隙直径分选系数
  3080. value6 = 0;
  3081. for (int attributeI = 1; attributeI < lstAttribute.Count; attributeI++)
  3082. {
  3083. var attribute = lstAttribute[attributeI];
  3084. ////if (attribute[5] < 5)
  3085. //// continue;
  3086. //value0 += attribute[5];
  3087. value1_0 = this.getHolesD(attribute) - value1;
  3088. value1_0 = value1_0 * value1_0 * attribute[5] * 100.0 / areaInt[0];
  3089. value6 += value1_0;
  3090. }
  3091. value6 = Math.Sqrt(value6 / 100.0);
  3092. if (double.TryParse(string.IsNullOrEmpty(value6.ToString()) ? "0" :
  3093. value6.ToString(), out outValue))
  3094. {
  3095. dgvr.Cells[6].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3096. }
  3097. else
  3098. dgvr.Cells[6].Value = value6.ToString();
  3099. //平均孔隙配位数
  3100. value7 = value7 * 1.0 / (lstAttribute.Count - 1);
  3101. if (double.TryParse(string.IsNullOrEmpty(value7.ToString()) ? "0" :
  3102. value7.ToString(), out outValue))
  3103. {
  3104. dgvr.Cells[7].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3105. }
  3106. else
  3107. dgvr.Cells[7].Value = value7.ToString();
  3108. this.dataGridView1.Rows.Add(dgvr);
  3109. //DataGridViewRow dgvr = new DataGridViewRow();
  3110. //foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  3111. //{
  3112. // dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  3113. //}
  3114. //for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
  3115. //{
  3116. // //if (c == 2 || c == 3)
  3117. // // dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  3118. // // this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3119. // //else
  3120. // if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7)
  3121. // {
  3122. // double outValue;
  3123. // if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  3124. // this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue))
  3125. // {
  3126. // dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3127. // }
  3128. // else
  3129. // dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  3130. // }
  3131. // else
  3132. // dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  3133. //}
  3134. //this.dataGridView2.Rows.Add(dgvr);
  3135. }
  3136. /// <summary>
  3137. /// 刷新分析结果数据
  3138. /// </summary>
  3139. protected void RefreshDataGridView4()//####
  3140. {
  3141. if (!this.allShow)
  3142. {
  3143. if (this.listView2.SelectedItems.Count > 0)
  3144. {
  3145. this.dataGridView1.Rows.Clear();
  3146. this.dataGridView2.Rows.Clear();
  3147. for (int j = 0; j < this.listView2.SelectedItems.Count; j++)
  3148. {
  3149. int dataTableIndex = 0;
  3150. if (lstAttriDict.ContainsKey(this.listView2.SelectedItems[j].Tag.ToString()))
  3151. this.AddRowDataGridView1(lstAttriDict[this.listView2.SelectedItems[j].Tag.ToString()]);
  3152. for (int i = 0; i < this.dataTables.Count; i++)
  3153. {
  3154. if (this.dataTables[i].TableName.Equals(this.listView2.SelectedItems[j].Tag))
  3155. {
  3156. dataTableIndex = i;
  3157. if (this.dataTables.Count > dataTableIndex && this.dataTables[dataTableIndex].Rows.Count > 0)
  3158. {
  3159. for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
  3160. {
  3161. DataGridViewRow dgvr = new DataGridViewRow();
  3162. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  3163. {
  3164. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  3165. }
  3166. for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
  3167. {
  3168. //if (c == 2 || c == 3)
  3169. // dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  3170. // this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3171. //else
  3172. if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7)
  3173. {
  3174. double outValue;
  3175. if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  3176. this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue))
  3177. {
  3178. dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3179. }
  3180. else
  3181. dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  3182. }
  3183. else
  3184. dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  3185. }
  3186. this.dataGridView2.Rows.Add(dgvr);
  3187. }
  3188. }
  3189. }
  3190. }
  3191. }
  3192. }
  3193. else if (this.listView2.Items.Count > 0)
  3194. {
  3195. this.dataGridView1.Rows.Clear();
  3196. this.dataGridView2.Rows.Clear();
  3197. var firstTag = this.listView2.Items[0].Tag;
  3198. if (lstAttriDict.ContainsKey(this.listView2.Items[0].Tag.ToString()))
  3199. this.AddRowDataGridView1(lstAttriDict[this.listView2.Items[0].Tag.ToString()]);
  3200. int dataTableIndex = 0;
  3201. for (int i = 0; i < this.dataTables.Count; i++)
  3202. {
  3203. if (this.dataTables[i].TableName.Equals(firstTag))
  3204. {
  3205. dataTableIndex = i;
  3206. if (this.dataTables[dataTableIndex].Rows.Count > 0)
  3207. {
  3208. for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
  3209. {
  3210. DataGridViewRow dgvr = new DataGridViewRow();
  3211. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  3212. {
  3213. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  3214. }
  3215. for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
  3216. {
  3217. //if (c == 2 || c == 3)
  3218. // dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  3219. // this.dataTables[dataTableIndex].Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3220. //else
  3221. if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7)
  3222. {
  3223. double outValue;
  3224. if (double.TryParse(string.IsNullOrEmpty(this.dataTables[dataTableIndex].Rows[r][c].ToString()) ? "0" :
  3225. this.dataTables[dataTableIndex].Rows[r][c].ToString(), out outValue))
  3226. {
  3227. dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3228. }
  3229. else
  3230. dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  3231. }
  3232. else
  3233. dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
  3234. }
  3235. this.dataGridView2.Rows.Add(dgvr);
  3236. }
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. else
  3243. {
  3244. this.dataGridView1.Rows.Clear();
  3245. this.dataGridView2.Rows.Clear();
  3246. foreach (var itemlist in lstAttriDict.Values)
  3247. {
  3248. this.AddRowDataGridView1(itemlist);
  3249. }
  3250. //if (lstAttriDict.ContainsKey(this.listView2.Items[0].Tag.ToString()))
  3251. // this.AddRowDataGridView1(lstAttriDict[this.listView2.Items[0].Tag.ToString()]);
  3252. DataTable dataTable = new DataTable();
  3253. for (int i = this.dataTables.Count - 1; i >= 0; i--)
  3254. {
  3255. dataTable = this.dataTables[i];
  3256. for (int r = 0; r < dataTable.Rows.Count; r++)
  3257. {
  3258. DataGridViewRow dgvr = new DataGridViewRow();
  3259. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  3260. {
  3261. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  3262. }
  3263. for (int c = 0; c < dataTable.Columns.Count; c++)
  3264. {
  3265. //if (c == 2 || c == 3)
  3266. // dgvr.Cells[c].Value = Math.Round(double.Parse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" :
  3267. // dataTable.Rows[r][c].ToString()), Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3268. //else
  3269. if (c == 3 || c == 4 || c == 5 || c == 6 || c == 7)
  3270. {
  3271. double outValue;
  3272. if (double.TryParse(string.IsNullOrEmpty(dataTable.Rows[r][c].ToString()) ? "0" :
  3273. dataTable.Rows[r][c].ToString(), out outValue))
  3274. {
  3275. dgvr.Cells[c].Value = Math.Round(outValue, Convert.ToInt32(this.numericUpDown1_0.Value)) + "";
  3276. }
  3277. else
  3278. dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString();
  3279. }
  3280. else
  3281. dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString();
  3282. }
  3283. this.dataGridView2.Rows.Add(dgvr);
  3284. }
  3285. }
  3286. }
  3287. }
  3288. /// <summary>
  3289. /// 切换分析结果
  3290. /// </summary>
  3291. /// <param name="sender"></param>
  3292. /// <param name="e"></param>
  3293. private void listview2_SelectedIndexChanged(object sender, EventArgs e)
  3294. {
  3295. if (!this.allShow)
  3296. {
  3297. if (this.listView2.SelectedItems.Count <= 0)
  3298. return;
  3299. this.dataGridView1.Rows.Clear();
  3300. this.dataGridView2.Rows.Clear();
  3301. for (int i = 0; i < this.listView2.SelectedItems.Count; i++)
  3302. {
  3303. System.Data.DataTable dataTable1 = new System.Data.DataTable();
  3304. foreach (var dataTable in this.dataTables)
  3305. {
  3306. if (lstAttriDict.ContainsKey(this.listView2.SelectedItems[i].Tag.ToString()))
  3307. this.AddRowDataGridView1(lstAttriDict[this.listView2.SelectedItems[i].Tag.ToString()]);
  3308. if (this.listView2.SelectedItems[i].Tag.Equals(dataTable.TableName))
  3309. dataTable1 = dataTable;
  3310. }
  3311. DataGridViewRow dgvr = new DataGridViewRow();
  3312. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  3313. {
  3314. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  3315. }
  3316. for (int c = 0; c < dataTable1.Columns.Count; c++)
  3317. {
  3318. dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
  3319. }
  3320. this.dataGridView2.Rows.Add(dgvr);
  3321. }
  3322. this.RefreshDataGridView4();
  3323. }
  3324. }
  3325. /// <summary>
  3326. /// 全部显示
  3327. /// </summary>
  3328. /// <param name="sender"></param>
  3329. /// <param name="e"></param>
  3330. private void button11_Click(object sender, EventArgs e)
  3331. {
  3332. if (this.listView2.Items.Count > 0)
  3333. {
  3334. this.button11.Visible = false;
  3335. this.button16.Visible = true;
  3336. this.button16.Focus();
  3337. this.allShow = true;
  3338. this.dataGridView1.Rows.Clear();
  3339. this.dataGridView2.Rows.Clear();
  3340. foreach (var itemlist in lstAttriDict.Values)
  3341. {
  3342. this.AddRowDataGridView1(itemlist);
  3343. }
  3344. for (int i = 0; i < this.dataTables.Count; i++)
  3345. {
  3346. DataGridViewRow dgvr = new DataGridViewRow();
  3347. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  3348. {
  3349. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  3350. }
  3351. for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
  3352. {
  3353. dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString();
  3354. }
  3355. this.dataGridView2.Rows.Add(dgvr);
  3356. }
  3357. this.RefreshDataGridView4();
  3358. }
  3359. else
  3360. {
  3361. MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
  3362. }
  3363. }
  3364. private void button12_Click(object sender, EventArgs e)
  3365. {
  3366. if (this.listView2.Items.Count > 0)
  3367. {
  3368. if (this.listView2.SelectedItems.Count > 0)
  3369. {
  3370. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  3371. if (dr == DialogResult.OK)
  3372. {
  3373. if (this.listView2.SelectedItems.Count <= 0)
  3374. return;
  3375. for (int i = this.listView2.SelectedItems.Count - 1; i >= 0; i--)
  3376. {
  3377. int selectIndex = this.listView2.SelectedItems[i].Index;
  3378. foreach (var dataTable in this.dataTables)
  3379. {
  3380. if (dataTable.TableName.Equals(this.listView2.SelectedItems[i].Tag))
  3381. {
  3382. this.dataTables.Remove(dataTable);
  3383. break;
  3384. }
  3385. }
  3386. if (bitDic.ContainsKey((string)this.listView2.SelectedItems[i].Tag))
  3387. bitDic.Remove((string)this.listView2.SelectedItems[i].Tag);
  3388. foreach (ExportProjectModel model in this.tempDataModel)
  3389. {
  3390. if (model.tagName.Equals((string)this.listView2.SelectedItems[i].Tag))
  3391. {
  3392. this.tempDataModel.Remove(model);
  3393. break;
  3394. }
  3395. }
  3396. this.listView2.Items.RemoveAt(selectIndex);
  3397. }
  3398. if (this.listView2.Items.Count == 0)
  3399. {
  3400. this.dataGridView1.Rows.Clear();
  3401. this.dataGridView2.Rows.Clear();
  3402. }
  3403. else
  3404. RefreshDataGridView4();
  3405. }
  3406. }
  3407. else
  3408. {
  3409. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!");
  3410. }
  3411. }
  3412. else
  3413. {
  3414. MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
  3415. }
  3416. }
  3417. private void numericUpDown1_0_ValueChanged(object sender, EventArgs e)
  3418. {
  3419. this.RefreshDataGridView4();
  3420. }
  3421. /// <summary>
  3422. /// 生成报告
  3423. /// </summary>
  3424. /// <param name="sender"></param>
  3425. /// <param name="e"></param>
  3426. private void button_generateReport_Click(object sender, EventArgs e)
  3427. {
  3428. if (this.listView2.Items.Count == 0)
  3429. {
  3430. MessageBox.Show(PdnResources.GetString("Menu.Noresults.text"));
  3431. return;
  3432. }
  3433. if (this.checkBox_generateReport_opensetting.Checked)
  3434. this.button_setting.PerformClick();
  3435. if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
  3436. {
  3437. //获取word书签与excel单元格的关系,以字典方式存储
  3438. List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
  3439. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  3440. if (mic_module_infos != null && mic_module_infos.Count > 0)
  3441. {
  3442. foreach (mic_module_infos info in mic_module_infos)
  3443. {
  3444. tagInfos.Add(info.tag_name, info.cell_position);
  3445. }
  3446. }
  3447. //分析结果
  3448. List<List<string>> analysisContent = new List<List<string>>();
  3449. analysisContent.Add(contentHead);
  3450. foreach (DataGridViewRow item in this.dataGridView2.Rows)
  3451. {
  3452. List<string> content = new List<string>();
  3453. for (int i = 0; i < contentHead.Count; i++)
  3454. {
  3455. content.Add(item.Cells[i].Value.ToString());
  3456. }
  3457. analysisContent.Add(content);
  3458. }
  3459. //图片
  3460. bitList = new List<Bitmap>();
  3461. if (this.allShow)
  3462. {
  3463. foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
  3464. {
  3465. bitList.Add(kv.Value[0]);
  3466. bitList.Add(kv.Value[1]);
  3467. }
  3468. }
  3469. else
  3470. {
  3471. if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
  3472. {
  3473. foreach (ListViewItem item in this.listView2.SelectedItems)
  3474. {
  3475. if (bitDic.ContainsKey(item.Name))
  3476. {
  3477. bitList.Add(bitDic[item.Name][0]);
  3478. bitList.Add(bitDic[item.Name][1]);
  3479. }
  3480. else if (bitDic.ContainsKey(item.Tag.ToString()))
  3481. {
  3482. bitList.Add(bitDic[item.Tag.ToString()][0]);
  3483. bitList.Add(bitDic[item.Tag.ToString()][1]);
  3484. }
  3485. }
  3486. }
  3487. else if (this.listView2.Items.Count > 0)//###
  3488. {
  3489. ListViewItem item = this.listView2.Items[0];
  3490. if (bitDic.ContainsKey(item.Name))
  3491. {
  3492. bitList.Add(bitDic[item.Name][0]);
  3493. bitList.Add(bitDic[item.Name][1]);
  3494. }
  3495. else if (bitDic.ContainsKey(item.Tag.ToString()))
  3496. {
  3497. bitList.Add(bitDic[item.Tag.ToString()][0]);
  3498. bitList.Add(bitDic[item.Tag.ToString()][1]);
  3499. }
  3500. }
  3501. }
  3502. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
  3503. }
  3504. else
  3505. MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!");
  3506. }
  3507. }
  3508. }