| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181 |
- using Metis.ParameterSet;
- using OpenCvSharp;
- using PaintDotNet.Base.CommTool;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- namespace PaintDotNet.DedicatedAnalysis.NonferrousMetals.YYT098814_2016
- {
- internal class TABM3Dialog : NonFMetalsStandardDialog
- {
- #region 属性
- ///// <summary>
- ///// 调色板
- ///// </summary>
- //private ColorsForm colorsFormGrid;
- //private Panel panelC;
- /// <summary>
- /// 是否调用了灰度化的算法
- /// </summary>
- private bool grayBitmap = false;
- /// <summary>
- /// 记录鼠标最后所在的点的y坐标
- /// </summary>
- int lineNum = 0;
- /// <summary>
- /// 竖直的辅助线
- /// </summary>
- List<Line> vlines = new List<Line>();
- /// <summary>
- /// 基体平行线
- /// </summary>
- Line line;
- /// <summary>
- /// 1显示基体界面 2移动基体界面 0隐藏基体界面
- /// </summary>
- int btnflag = 0;
- ///// <summary>
- ///// 轮廓的线
- ///// </summary>
- //System.Drawing.Point[][] tempLine;
- /// <summary>
- /// 孔隙的mat
- /// </summary>
- Mat tempHoleMat;
- Bitmap tempHoleBitmap;
- /// <summary>
- /// 定义变量存储鼠标操作状态 1拖动上辅助线 2拖动下辅助线 /* 3拖动平行辅助线*/
- /// </summary>
- int mouseFlag = 0;
- ///// <summary>
- ///// 1显示辅助线 2移动辅助线 0隐藏辅助线
- ///// </summary>
- //int btnflag = 0;
- int contoursTop = 0;
- ///// <summary>
- ///// 辅助线
- ///// </summary>
- //Line top, bottom;
- /// <summary>
- /// 下面定义三个变量存储鼠标按下的坐标
- /// </summary>
- int xPos;
- int yPos;
- ///// <summary>
- ///// 定义变量存储鼠标操作状态 1拖动左辅助线 2拖动右辅助线 3拖动平行辅助线
- ///// </summary>
- //int mouseFlag = 0;
- ///// <summary>
- ///// 1显示辅助线 2移动辅助线 0隐藏辅助线
- ///// </summary>
- //int btnflag = 0;
- /// <summary>
- /// 左侧辅助线
- /// </summary>
- Line lineleft;
- /// <summary>
- /// 右侧辅助线
- /// </summary>
- Line lineright;
- /// <summary>
- /// 底部辅助线
- /// </summary>
- Line linebottom;
- /// <summary>
- /// 横向辅助线上孔隙的线段集合
- /// </summary>
- List<Line> honlines = new List<Line>();
- /// <summary>
- /// 横向辅助线
- /// </summary>
- List<Line> hlines = new List<Line>();
- /// <summary>
- /// 总长度
- /// </summary>
- double res_totalL;
- /// <summary>
- /// 平均孔隙截距
- /// </summary>
- double res_perL;
- /// <summary>
- /// 截点数量
- /// </summary>
- double res_count;
- /// <summary>
- /// 选择标尺的物理长度(微米/像素)
- /// </summary>
- double physical_length = 1;
- // <summary>
- /// 保存窗口参数
- /// </summary>
- private GrainSizeAnalysisModel analysisModel;
- private const string ParamKey_Report = "report";//报告设置
- private const string ParamKey_PoreColour = "poreColour";//孔隙颜色
- private const string ParamKey_PoreSpacing = "poreSpacing";//孔隙辅助线间距
- private const string ParamKey_GuideColour = "guideColour";//辅助线颜色
- private const string ParamKey_GuideWidth = "guideWidth";//辅助线线宽
- private const string ParamKey_GuideNumber = "guideNumber";//辅助线条数
- private const string ParamKey_GuideSpacing = "guideSpacing";//辅助线间距
- private const string ParamKey_PoreSetColour = "poreSetColour";//孔隙设置颜色
- private const string ParamKey_PoreSetWidth = "poreSetWidth";//孔隙设置线宽
- private const string ParamKey_DecimalPlace = "decimalPlace";//保留小数位数
- #endregion 属性
- #region 组件
- private Button button2;
- private GroupBox groupBox10;
- private Panel panel1;
- private Label label5;
- private GroupBox groupBox8;
- private Label label14;
- private Label label7;
- private Label label2;
- private Label label13;
- private Label label12;
- private GroupBox groupBox5;
- private Button button14;
- private Button button17;
- private Button button3;
- private Button button15;
- private Button button13;
- private Button button10;
- private Button button4;
- private Button button5;
- private GroupBox groupBox7;
- private Panel panel4;
- private TextBox textBox6;
- private TextBox textBox4;
- private TrackBar trackBar3;
- private TextBox textBox3;
- private Label label15;
- private Label label16;
- private Label label17;
- private Label label18;
- private GroupBox groupBox6;
- private Panel panel3;
- private TrackBar trackBar4;
- private TextBox textBox10;
- private Label label4;
- private Label label6;
- private TextBox textBox1;
- private Label label1;
- private Label label11;
- #endregion 组件
- #region 构造函数
- public TABM3Dialog(AppWorkspace appWorkspace, int menuId) : base(appWorkspace, menuId)
- {
- Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
- this.physical_length = measurementUnitDictionary[MeasurementUnit.Micron];
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
- GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
- this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
- foreach (var item in this.analysisModel.ListParam)
- item.setValue();
- ////
- ////初始化色板
- ////
- //this.colorsFormGrid = new ColorsForm();
- //this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
- //this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
- GetListParamModel();
- InitGridHeader();
- }
- /// <summary>
- /// 初始化表头
- /// </summary>
- private void InitGridHeader()
- {
- DataGridViewTextBoxColumn Column2_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column3_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column4_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
- Column2_total.Name = "Column2_total";
- Column2_total.ReadOnly = true;
- Column3_total.Name = "Column3_total";
- Column3_total.ReadOnly = true;
- Column4_total.Name = "Column4_total";
- Column4_total.ReadOnly = true;
- Column2_total.HeaderText = PdnResources.GetString("Menu.Totallengthofporeintercepts.text");
- Column3_total.HeaderText = PdnResources.GetString("Menu.Meanporeintercept.text");
- Column4_total.HeaderText = PdnResources.GetString("Menu.Numberofintercept.text");
- this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- Column2_total,
- Column3_total,
- Column4_total});
- this.dataGridView_Total.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView_Total.Columns[0].ReadOnly = true;
- this.dataGridView_Total.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView_Total.Columns[1].ReadOnly = true;
- this.dataGridView_Total.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView_Total.Columns[2].ReadOnly = true;
- DataGridViewTextBoxColumn Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- DataGridViewTextBoxColumn Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- Column1.Name = "Column1";
- Column1.ReadOnly = true;
- Column2.Name = "Column2";
- Column2.ReadOnly = true;
- Column3.Name = "Column3";
- Column3.ReadOnly = true;
- Column4.Name = "Column4";
- Column4.ReadOnly = true;
- Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
- Column2.HeaderText = PdnResources.GetString("Menu.Totallengthofporeintercepts.text");
- Column3.HeaderText = PdnResources.GetString("Menu.Meanporeintercept.text");
- Column4.HeaderText = PdnResources.GetString("Menu.Numberofintercept.text");
- this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- Column1,
- Column2,
- Column3,
- Column4});
- Column1.Width = 195;
- Column2.Width = 165;
- Column3.Width = 165;
- Column4.Width = 165;
- this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[0].ReadOnly = true;
- this.dataGridView2.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[1].ReadOnly = true;
- this.dataGridView2.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[2].ReadOnly = true;
- this.dataGridView2.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[3].ReadOnly = true;
- }
- #endregion 构造函数
- #region 初始化组件和实现组件事件
- private void InitializeLanguageText()
- {
- //this.label16.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- //this.label19.Text = PdnResources.GetString("Menu.Distancefromtop.text") + ":";
- this.groupBox7.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text");
- this.label6.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.label4.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.groupBox6.Text = PdnResources.GetString("Menu.holesetting.text");
- this.label5.Text = PdnResources.GetString("Menu.color.text") + ":";
- //this.label3.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.groupBox10.Text = "孔隙";// PdnResources.GetString("Menu.contour.text");
- this.button2.Text = PdnResources.GetString("Menu.reinformation.text");
- this.button5.Text = PdnResources.GetString("Menu.Image.Grayscale.Text");
- this.button4/*button3*/.Text = PdnResources.GetString("Menu.BinaryAction.ErosionExtraction.Text");
- this.button10.Text = PdnResources.GetString("Menu.BinaryAction.DilationExtraction.Text");
- this.button13.Text = PdnResources.GetString("Menu.Drawauxiliarylines.text");
- this.button3.Text = PdnResources.GetString("Menu.reinformation.text");
- this.button15.Text = "寻找孔隙";// PdnResources.GetString("Menu.searchcontour.text");
- this.button17.Text = PdnResources.GetString("Menu.auto-adjust.text");
- this.button14.Text = "修改孔隙";// PdnResources.GetString("Menu.easemodifytheoutline.Text");
- //this.button5.Text = PdnResources.GetString("Menu.reinformation.text");
- this.groupBox5.Text = PdnResources.GetString("Menu.Basicoperation.text");
- this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.Meanporeintercept.text") + ")";
- this.label11.Text = PdnResources.GetString("Menu.Totallengthofporeintercepts.text") + ":";
- this.label12.Text = PdnResources.GetString("Menu.Meanporeintercept.text") + ":";
- this.label13.Text = PdnResources.GetString("Menu.Numberofintercept.text") + ":";
- //this.label11.Text = PdnResources.GetString("Menu.Averagethickness(μm).text") + ":";
- //this.label12.Text = PdnResources.GetString("Menu.standarddeviation.text") + ":";
- //this.label13.Text = PdnResources.GetString("Menu.confidencebound.text") + ":";
- this.groupBox8.Text = PdnResources.GetString("Menu.result.text");
- this.label18.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.label17.Text = PdnResources.GetString("Menu.Numberof.text") + ":";
- this.label16.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.label15.Text = PdnResources.GetString("Menu.spacing.text") + ":";
- this.label1.Text = "辅助线间距";// PdnResources.GetString("Menu.spacing.text") + ":";
- }
- private void InitializeComponent()
- {
- this.button2 = new System.Windows.Forms.Button();
- this.groupBox10 = new System.Windows.Forms.GroupBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.panel1 = new System.Windows.Forms.Panel();
- this.label5 = new System.Windows.Forms.Label();
- this.groupBox8 = new System.Windows.Forms.GroupBox();
- this.label14 = new System.Windows.Forms.Label();
- this.label7 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label13 = new System.Windows.Forms.Label();
- this.label12 = new System.Windows.Forms.Label();
- this.label11 = new System.Windows.Forms.Label();
- this.groupBox5 = new System.Windows.Forms.GroupBox();
- this.button14 = new System.Windows.Forms.Button();
- this.button17 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button15 = new System.Windows.Forms.Button();
- this.button13 = new System.Windows.Forms.Button();
- this.button10 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.groupBox7 = new System.Windows.Forms.GroupBox();
- this.panel4 = new System.Windows.Forms.Panel();
- this.textBox6 = new System.Windows.Forms.TextBox();
- this.textBox4 = new System.Windows.Forms.TextBox();
- this.trackBar3 = new System.Windows.Forms.TrackBar();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.label15 = new System.Windows.Forms.Label();
- this.label16 = new System.Windows.Forms.Label();
- this.label17 = new System.Windows.Forms.Label();
- this.label18 = new System.Windows.Forms.Label();
- this.groupBox6 = new System.Windows.Forms.GroupBox();
- this.panel3 = new System.Windows.Forms.Panel();
- this.trackBar4 = new System.Windows.Forms.TrackBar();
- this.textBox10 = new System.Windows.Forms.TextBox();
- this.label4 = new System.Windows.Forms.Label();
- this.label6 = new System.Windows.Forms.Label();
- this.groupBox_img.SuspendLayout();
- this.groupBox_report.SuspendLayout();
- this.groupBox_analysisResult1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
- this.groupBox10.SuspendLayout();
- this.groupBox8.SuspendLayout();
- this.groupBox5.SuspendLayout();
- this.groupBox7.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
- this.groupBox6.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit();
- this.SuspendLayout();
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(96, 39);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 6;
- this.button2.UseVisualStyleBackColor = true;
- //
- // groupBox10
- //
- this.groupBox10.Controls.Add(this.textBox1);
- this.groupBox10.Controls.Add(this.label1);
- this.groupBox10.Controls.Add(this.panel1);
- this.groupBox10.Controls.Add(this.label5);
- this.groupBox10.Location = new System.Drawing.Point(178, 383);
- this.groupBox10.Name = "groupBox10";
- this.groupBox10.Size = new System.Drawing.Size(354, 41);
- this.groupBox10.TabIndex = 42;
- this.groupBox10.TabStop = false;
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(246, 15);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(101, 21);
- this.textBox1.TabIndex = 25;
- this.textBox1.Text = "100";
- this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
- this.textBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyUp);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(175, 20);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(0, 12);
- this.label1.TabIndex = 24;
- //
- // panel1
- //
- this.panel1.BackColor = System.Drawing.Color.Orange;
- this.panel1.Location = new System.Drawing.Point(63, 15);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(105, 21);
- this.panel1.TabIndex = 21;
- this.panel1.Click += new System.EventHandler(this.panelC_Click);
- //
- // label5
- //
- this.label5.AutoSize = true;
- this.label5.Location = new System.Drawing.Point(15, 20);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(0, 12);
- this.label5.TabIndex = 0;
- //
- // groupBox8
- //
- this.groupBox8.Controls.Add(this.label14);
- this.groupBox8.Controls.Add(this.label7);
- this.groupBox8.Controls.Add(this.label2);
- this.groupBox8.Controls.Add(this.label13);
- this.groupBox8.Controls.Add(this.label12);
- this.groupBox8.Controls.Add(this.label11);
- this.groupBox8.Location = new System.Drawing.Point(179, 563);
- this.groupBox8.Name = "groupBox8";
- this.groupBox8.Size = new System.Drawing.Size(353, 53);
- this.groupBox8.TabIndex = 43;
- this.groupBox8.TabStop = false;
- //
- // label14
- //
- this.label14.AutoSize = true;
- this.label14.Location = new System.Drawing.Point(243, 32);
- this.label14.Name = "label14";
- this.label14.Size = new System.Drawing.Size(0, 12);
- this.label14.TabIndex = 11;
- //
- // label7
- //
- this.label7.AutoSize = true;
- this.label7.Location = new System.Drawing.Point(110, 32);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(0, 12);
- this.label7.TabIndex = 10;
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(123, 15);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(0, 12);
- this.label2.TabIndex = 9;
- //
- // label13
- //
- this.label13.AutoSize = true;
- this.label13.Location = new System.Drawing.Point(172, 32);
- this.label13.Name = "label13";
- this.label13.Size = new System.Drawing.Size(0, 12);
- this.label13.TabIndex = 8;
- //
- // label12
- //
- this.label12.AutoSize = true;
- this.label12.Location = new System.Drawing.Point(15, 32);
- this.label12.Name = "label12";
- this.label12.Size = new System.Drawing.Size(0, 12);
- this.label12.TabIndex = 7;
- //
- // label11
- //
- this.label11.AutoSize = true;
- this.label11.Location = new System.Drawing.Point(16, 15);
- this.label11.Name = "label11";
- this.label11.Size = new System.Drawing.Size(0, 12);
- this.label11.TabIndex = 6;
- //
- // groupBox5
- //
- this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox5.Controls.Add(this.button14);
- this.groupBox5.Controls.Add(this.button17);
- this.groupBox5.Controls.Add(this.button3);
- this.groupBox5.Controls.Add(this.button15);
- this.groupBox5.Controls.Add(this.button13);
- this.groupBox5.Controls.Add(this.button10);
- this.groupBox5.Controls.Add(this.button4);
- this.groupBox5.Controls.Add(this.button5);
- this.groupBox5.Location = new System.Drawing.Point(180, 317);
- this.groupBox5.Name = "groupBox5";
- this.groupBox5.Size = new System.Drawing.Size(353, 66);
- this.groupBox5.TabIndex = 44;
- this.groupBox5.TabStop = false;
- //
- // button14
- //
- this.button14.Location = new System.Drawing.Point(267, 40);
- this.button14.Name = "button14";
- this.button14.Size = new System.Drawing.Size(75, 23);
- this.button14.TabIndex = 8;
- this.button14.UseVisualStyleBackColor = true;
- this.button14.Click += new System.EventHandler(this.button14_Click);
- //
- // button17
- //
- this.button17.Location = new System.Drawing.Point(180, 40);
- this.button17.Name = "button17";
- this.button17.Size = new System.Drawing.Size(75, 23);
- this.button17.TabIndex = 7;
- this.button17.UseVisualStyleBackColor = true;
- this.button17.Click += new System.EventHandler(this.button17_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(93, 40);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 6;
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button15
- //
- this.button15.Location = new System.Drawing.Point(267, 15);
- this.button15.Name = "button15";
- this.button15.Size = new System.Drawing.Size(75, 23);
- this.button15.TabIndex = 5;
- this.button15.UseVisualStyleBackColor = true;
- this.button15.Click += new System.EventHandler(this.button15_Click);
- //
- // button13
- //
- this.button13.Location = new System.Drawing.Point(9, 40);
- this.button13.Name = "button13";
- this.button13.Size = new System.Drawing.Size(75, 23);
- this.button13.TabIndex = 3;
- this.button13.UseVisualStyleBackColor = true;
- this.button13.Click += new System.EventHandler(this.button13_Click);
- //
- // button10
- //
- this.button10.Location = new System.Drawing.Point(180, 15);
- this.button10.Name = "button10";
- this.button10.Size = new System.Drawing.Size(75, 23);
- this.button10.TabIndex = 2;
- this.button10.UseVisualStyleBackColor = true;
- this.button10.Click += new System.EventHandler(this.button10_Click);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(93, 15);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 1;
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(9, 15);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 0;
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // groupBox7
- //
- this.groupBox7.Controls.Add(this.panel4);
- this.groupBox7.Controls.Add(this.textBox6);
- this.groupBox7.Controls.Add(this.textBox4);
- this.groupBox7.Controls.Add(this.trackBar3);
- this.groupBox7.Controls.Add(this.textBox3);
- this.groupBox7.Controls.Add(this.label15);
- this.groupBox7.Controls.Add(this.label16);
- this.groupBox7.Controls.Add(this.label17);
- this.groupBox7.Controls.Add(this.label18);
- this.groupBox7.Location = new System.Drawing.Point(179, 430);
- this.groupBox7.Name = "groupBox7";
- this.groupBox7.Size = new System.Drawing.Size(354, 75);
- this.groupBox7.TabIndex = 45;
- this.groupBox7.TabStop = false;
- //
- // panel4
- //
- this.panel4.BackColor = System.Drawing.Color.Green;
- this.panel4.Location = new System.Drawing.Point(62, 17);
- this.panel4.Name = "panel4";
- this.panel4.Size = new System.Drawing.Size(105, 21);
- this.panel4.TabIndex = 23;
- this.panel4.Click += new System.EventHandler(this.panelC_Click);
- //
- // textBox6
- //
- this.textBox6.Location = new System.Drawing.Point(62, 41);
- this.textBox6.Name = "textBox6";
- this.textBox6.Size = new System.Drawing.Size(105, 21);
- this.textBox6.TabIndex = 10;
- this.textBox6.Text = "10";
- this.textBox6.TextChanged += new System.EventHandler(this.TextBox6_TextChanged);
- //
- // textBox4
- //
- this.textBox4.Location = new System.Drawing.Point(224, 41);
- this.textBox4.Name = "textBox4";
- this.textBox4.Size = new System.Drawing.Size(121, 21);
- this.textBox4.TabIndex = 8;
- this.textBox4.Text = "100";
- this.textBox4.TextChanged += new System.EventHandler(this.TextBox4_TextChanged);
- //
- // trackBar3
- //
- this.trackBar3.AutoSize = false;
- this.trackBar3.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar3.Location = new System.Drawing.Point(220, 18);
- this.trackBar3.Maximum = 50;
- this.trackBar3.Minimum = 1;
- this.trackBar3.Name = "trackBar3";
- this.trackBar3.Size = new System.Drawing.Size(84, 21);
- this.trackBar3.TabIndex = 7;
- this.trackBar3.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar3.Value = 3;
- this.trackBar3.Scroll += new System.EventHandler(this.trackBar3_Scroll);
- this.trackBar3.ValueChanged += new System.EventHandler(this.trackBar3_ValueChanged);
- //
- // textBox3
- //
- this.textBox3.Location = new System.Drawing.Point(310, 17);
- this.textBox3.Name = "textBox3";
- this.textBox3.Size = new System.Drawing.Size(35, 21);
- this.textBox3.TabIndex = 6;
- this.textBox3.Text = "3";
- this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
- this.textBox3.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyUp);
- //
- // label15
- //
- this.label15.AutoSize = true;
- this.label15.Location = new System.Drawing.Point(173, 46);
- this.label15.Name = "label15";
- this.label15.Size = new System.Drawing.Size(0, 12);
- this.label15.TabIndex = 3;
- //
- // label16
- //
- this.label16.AutoSize = true;
- this.label16.Location = new System.Drawing.Point(173, 22);
- this.label16.Name = "label16";
- this.label16.Size = new System.Drawing.Size(0, 12);
- this.label16.TabIndex = 2;
- //
- // label17
- //
- this.label17.AutoSize = true;
- this.label17.Location = new System.Drawing.Point(15, 46);
- this.label17.Name = "label17";
- this.label17.Size = new System.Drawing.Size(0, 12);
- this.label17.TabIndex = 1;
- //
- // label18
- //
- this.label18.AutoSize = true;
- this.label18.Location = new System.Drawing.Point(15, 22);
- this.label18.Name = "label18";
- this.label18.Size = new System.Drawing.Size(0, 12);
- this.label18.TabIndex = 0;
- //
- // groupBox6
- //
- this.groupBox6.Controls.Add(this.panel3);
- this.groupBox6.Controls.Add(this.trackBar4);
- this.groupBox6.Controls.Add(this.textBox10);
- this.groupBox6.Controls.Add(this.label4);
- this.groupBox6.Controls.Add(this.label6);
- this.groupBox6.Location = new System.Drawing.Point(180, 511);
- this.groupBox6.Name = "groupBox6";
- this.groupBox6.Size = new System.Drawing.Size(354, 52);
- this.groupBox6.TabIndex = 46;
- this.groupBox6.TabStop = false;
- //
- // panel3
- //
- this.panel3.BackColor = System.Drawing.Color.Yellow;
- this.panel3.Location = new System.Drawing.Point(62, 18);
- this.panel3.Name = "panel3";
- this.panel3.Size = new System.Drawing.Size(105, 21);
- this.panel3.TabIndex = 22;
- this.panel3.Click += new System.EventHandler(this.panelC_Click);
- //
- // trackBar4
- //
- this.trackBar4.AutoSize = false;
- this.trackBar4.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar4.Location = new System.Drawing.Point(220, 20);
- this.trackBar4.Maximum = 50;
- this.trackBar4.Minimum = 1;
- this.trackBar4.Name = "trackBar4";
- this.trackBar4.Size = new System.Drawing.Size(84, 21);
- this.trackBar4.TabIndex = 7;
- this.trackBar4.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar4.Value = 3;
- this.trackBar4.Scroll += new System.EventHandler(this.trackBar4_Scroll);
- this.trackBar4.ValueChanged += new System.EventHandler(this.trackBar4_ValueChanged);
- //
- // textBox10
- //
- this.textBox10.Location = new System.Drawing.Point(310, 19);
- this.textBox10.Name = "textBox10";
- this.textBox10.Size = new System.Drawing.Size(35, 21);
- this.textBox10.TabIndex = 6;
- this.textBox10.Text = "3";
- this.textBox10.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
- this.textBox10.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox10_KeyUp);
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(173, 24);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(0, 12);
- this.label4.TabIndex = 2;
- //
- // label6
- //
- this.label6.AutoSize = true;
- this.label6.Location = new System.Drawing.Point(15, 24);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(0, 12);
- this.label6.TabIndex = 0;
- //
- // TABM3Dialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(1127, 822);
- this.Controls.Add(this.groupBox6);
- this.Controls.Add(this.groupBox7);
- this.Controls.Add(this.groupBox5);
- this.Controls.Add(this.groupBox8);
- this.Controls.Add(this.groupBox10);
- this.Name = "TABM3Dialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TABM3Dialog_FormClosing);
- this.Controls.SetChildIndex(this.groupBox10, 0);
- this.Controls.SetChildIndex(this.groupBox8, 0);
- this.Controls.SetChildIndex(this.groupBox5, 0);
- this.Controls.SetChildIndex(this.groupBox_img, 0);
- this.Controls.SetChildIndex(this.groupBox_review, 0);
- this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
- this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
- this.Controls.SetChildIndex(this.groupBox_report, 0);
- this.Controls.SetChildIndex(this.groupBox7, 0);
- this.Controls.SetChildIndex(this.groupBox6, 0);
- this.groupBox_img.ResumeLayout(false);
- this.groupBox_report.ResumeLayout(false);
- this.groupBox_report.PerformLayout();
- this.groupBox_analysisResult1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
- this.groupBox10.ResumeLayout(false);
- this.groupBox10.PerformLayout();
- this.groupBox8.ResumeLayout(false);
- this.groupBox8.PerformLayout();
- this.groupBox5.ResumeLayout(false);
- this.groupBox7.ResumeLayout(false);
- this.groupBox7.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
- this.groupBox6.ResumeLayout(false);
- this.groupBox6.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion 初始化组件和实现组件事件
- #region 需继承的一部分方法
- protected override void drawSubclass(Graphics graphics)
- {
- if (tempHoleMat != null && tempHoleBitmap != null)
- {
- graphics.DrawImage(tempHoleBitmap, new PointF(0, 0));
- }
- Pen bluePen = new Pen(this.panel4.BackColor/*Color.FromArgb(255, 0, 208, 202)*/, this.trackBar3.Value/*5*/);
- //画左右下辅助线
- if (lineleft != null)
- graphics.DrawLine(bluePen, lineleft.startPoint, lineleft.endPoint);
- if (lineright != null)
- graphics.DrawLine(bluePen, lineright.startPoint, lineright.endPoint);
- //if (linebottom != null)
- // graphics.DrawLine(bluePen, linebottom.startPoint, linebottom.endPoint);
- if (hlines != null && hlines.Count() > 0)
- {
- foreach (Line l in hlines)
- {
- graphics.DrawLine(bluePen, l.startPoint, l.endPoint);
- }
- }
- //画笔
- Pen yellowPen = new Pen(this.panel3.BackColor/*Color.Yellow*/, this.trackBar4.Value/*5*/);
- if (honlines != null && honlines.Count() > 0)
- {
- foreach (Line l in honlines)
- {
- graphics.DrawLine(yellowPen, l.startPoint, l.endPoint);
- }
- }
- }
- //数据库的name(报告模板)
- protected override string getTemplateName()
- {
- return "Template.Manager.item3.TitaniumAlloyBio3Method";
- }
- //语言包的name(项目工程)
- protected override string getProjectEngineeringName()
- {
- return "Menu.DedicatedAnalysis.NonferrousMetal.TitaniumAlloyBiomaterial.Text";
- }
- protected override void SubclassInitialize()
- {
- InitializeComponent();
- InitializeLanguageText();
- this.panel1.Click += new System.EventHandler(this.panel1_Click);
- this.panel3.Click += new System.EventHandler(this.panel1_Click);
- this.panel4.Click += new System.EventHandler(this.panel1_Click);
- //this.groupBox_img.Size = new System.Drawing.Size(158, 544/*514*/);
- //this.groupBox_review.Size = new System.Drawing.Size(575, 544/*514*/);
- //this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 622/*592*/);
- //this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 622/*592*/);
- //this.groupBox_report.Location = new System.Drawing.Point(974, 622/*592*/);
- this.ClientSize = new System.Drawing.Size(1127, 852);///*822*/
- }
- //切换图片时控制前一张图的信息不遗留显示
- protected override void refreshWhileImgChanged()
- {
- this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
- calculate1d = false;
- this.label2.Text = "";
- this.label7.Text = "";
- this.label14.Text = "";
- hlines.Clear();
- honlines.Clear();
- if (lineleft != null || linebottom != null || lineright != null)
- {
- btnflag = 0;
- lineleft = null;
- linebottom = null;
- lineright = null;
- }
- //contours = null;
- //vlines.Clear();
- //if (line != null)
- //{
- // btnflag = 0;
- // line = null;
- //}
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- //if (this.documentWorkspace.PhaseModels.Count() == 0 || this.documentWorkspace.PhaseModels[0].mat == null || !this.documentWorkspace.PhaseModels[0].choise)
- //{
- // binaryClass.performClickBinaryCheck(false);
- //}
- this.grayBitmap = false;
- }
- #endregion
- #region 基础操作
- /// <summary>
- /// 灰度化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
- return;
- }
- if (this.grayBitmap) {
- MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
- return;
- }
- this.grayBitmap = true;
- Mat lab1Img = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);
- if (lab1Img.Type() != MatType.CV_8UC1)
- {
- lab1Img = lab1Img.CvtColor(ColorConversionCodes.BGR2GRAY);
- Bitmap bitmap2 = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1Img);
- Document document = Document.FromImage(bitmap2);
- this.documentWorkspace.Document = document;
- }
- else
- MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
- lab1Img.Dispose();
- lab1Img = null;
- }
- /// <summary>
- /// 腐蚀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- return;
- }
- Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
- Cv2.Erode(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
- this.documentWorkspace.PhaseModels[0].mat = lab1Img;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 膨胀
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button10_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- return;
- }
- Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
- Cv2.Dilate(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
- this.documentWorkspace.PhaseModels[0].mat = lab1Img;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 寻找孔隙 (寻找轮廓)
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button15_Click(object sender, EventArgs e)
- {
- findContour();
- }
- private void findContour(bool showMessageBox = true)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise/* //###21476 */
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- if (showMessageBox)
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- return;
- }
- Mat analyzeMat = this.documentWorkspace.PhaseModels[0].mat;
- Color tempHoleColor = this.panel1.BackColor;
- Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
- Vec4b vec4B2 = new Vec4b(0, 0, 0, 0);
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- tempHoleMat = new Mat(analyzeMat.Size(), MatType.CV_8UC4);
- int Rows = analyzeMat.Rows;
- int Cols = analyzeMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- if (analyzeMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- tempHoleMat.Set(point, vec4B2);
- else
- tempHoleMat.Set(point, vec4B1);
- }
- }
- tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// PanelC的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void gridColorChanged(object sender, EventArgs e)
- {
- base.gridColorChanged(sender, e);
- if (this.panelC != this.panel1)
- return;
- Color tempHoleColor = this.panel1.BackColor;
- Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
- if (tempHoleMat == null)
- {
- return;
- }
- int Rows = tempHoleMat.Rows;
- int Cols = tempHoleMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- if (tempHoleMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- tempHoleMat.Set(point, vec4B1);
- }
- }
- tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
- this.documentWorkspace.Refresh();
- //findContour(false);
- ////Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
- //////更改背景色,触发事件
- ////this.panelC.BackColor = color;
- ////if (!findContour(false))
- //// this.documentWorkspace.Refresh();
- //////关闭色板
- ////this.colorsFormGrid.Close();
- }
- /// <summary>
- /// 自动调整
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button17_Click(object sender, EventArgs e)
- {
- if (this.documentWorkspace.PhaseModels.Count < 1/* || !this.documentWorkspace.PhaseModels[0].choise*/
- || this.documentWorkspace.PhaseModels[0].mat == null)
- {
- binaryClass.performClickBinaryCheck(true);
- }
- this.button15.PerformClick();
- }
- /// <summary>
- /// 绘制辅助线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button13_Click(object sender, EventArgs e)
- {
- if (tempHoleMat == null)
- {
- MessageBox.Show("请先进行寻找孔隙操作");
- return;
- }
- //if (contours == null)
- //{
- // MessageBox.Show(PdnResources.GetString("Menu.Pleaseclicktodrawtheoutlinefirst.text"));
- // return;
- //}
- ////this.showPhaseMat();
- Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
- if (lab1Img != null/* && drawg != null*/)// && line == null
- {
- //if (string.IsNullOrWhiteSpace(this.textBox4.Text) || textBox4.Text == "")
- //{
- // MessageBox.Show(PdnResources.GetString("Menu.Pleaseentertheauxiliarylinespacingfirst.text"));
- // return;
- //}
- string width = this.textBox4.Text.Trim();
- double result;
- if (!double.TryParse(width, out result))
- {
- MessageBox.Show(PdnResources.GetString("Menu.ormatforauxiliarylinespacin.Text"));
- return;
- }
- string width2 = this.textBox6.Text.Trim();
- int result2;
- if (!int.TryParse(width2, out result2))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Theinputforncorrect.text"));
- return;
- }
- this.drawLines();
- this.documentWorkspace.Refresh();
- }
- else
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
- }
- }
- /// <summary>
- /// 绘制辅助线
- /// </summary>
- private void drawLines()
- {
- string line = this.textBox6.Text.Trim();
- string width = this.textBox4.Text.Trim();
- try
- {
- //画左右下辅助线
- if (lineleft == null || lineright == null)
- {
- int margin = this.bitmap/*lab1Img*/.Width / 20;
- int spaceLine = (int)((this.bitmap.Width - 2 * margin) * this.physical_length);
- if (int.TryParse(this.textBox1.Text.ToString().Trim(), out spaceLine))
- {
- margin = (int)((this.bitmap.Width - spaceLine / this.physical_length) / 2);
- }
- lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
- lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
- }
- if (linebottom == null)
- {
- linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
- }
- //画平行的多条辅助线
- int n = int.Parse(line); //线的数量
- int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
- per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- hlines.Clear();
- {
- for (int i = 0; i < n; i++)
- {
- Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y - per_w * i));
- //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
- hlines.Add(l);
- }
- }
- honlines.Clear();
- btnflag = 1;
- //pictureBox1.Image = map;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- /// <summary>
- /// 重置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
- return;
- }
- calculate1d = false;
- this.label2.Text = "";
- this.label7.Text = "";
- this.label14.Text = "";
- hlines.Clear();
- honlines.Clear();
- if (lineleft == null && linebottom == null && lineright == null)
- { }
- else
- {
- btnflag = 0;
- lineleft = null;
- linebottom = null;
- lineright = null;
- }
- //contours = null;
- //vlines.Clear();
- //if (line == null)
- //{
- //}
- //else
- //{
- // btnflag = 0;
- // line = null;
- //}
- if (tempHoleMat != null)
- {
- tempHoleMat.Dispose();
- tempHoleMat = null;
- }
- if (this.documentWorkspace.PhaseModels.Count() > 0)
- {
- this.documentWorkspace.PhaseModels[0].mat = null;
- }
- this.documentWorkspace.PhaseModels[0].choise = false;
- binaryClass.performClickBinaryCheck(false);
- //this.checkBox10.Checked = false;//PdnResources.GetString("Menu.Binarization.text");//####################
- this.grayBitmap = false;
- Document document = Document.FromImage(this.bitmap);
- this.documentWorkspace.Document = document;
- }
- /// <summary>
- /// 修改孔隙 (修改轮廓)
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button14_Click(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
- return;
- }
- if (tempHoleMat == null)
- {
- MessageBox.Show("请先进行寻找孔隙操作");
- return;
- }
- IntegrationClass.MetalsHoleAreaEditingDialog boundaryEditingDialog = new IntegrationClass.MetalsHoleAreaEditingDialog(this.appWorkspace, this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index, this.panel1.BackColor
- , tempHoleMat);
- if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
- {
- tempHoleMat = boundaryEditingDialog.PhaseMat.Clone();
- tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
- this.documentWorkspace.Refresh();
- }
- }
- #endregion 基础操作
- #region 控件监听事件
- /// <summary>
- /// 相颜色点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panelC_Click(object sender, EventArgs e)
- {
- //this.panelC = (Panel)sender;
- //this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
- //this.colorsFormGrid.ShowDialog();
- }
- private void trackBar4_ValueChanged(object sender, EventArgs e)
- {
- this.documentWorkspace.Refresh();
- }
- private void trackBar4_Scroll(object sender, EventArgs e)
- {
- this.textBox10.Text = "" + this.trackBar4.Value;
- }
- private void trackBar3_ValueChanged(object sender, EventArgs e)
- {
- this.documentWorkspace.Refresh();
- }
- private void trackBar3_Scroll(object sender, EventArgs e)
- {
- this.textBox3.Text = "" + this.trackBar3.Value;
- }
- /// <summary>
- /// 线宽输入框 对输入值做限制
- /// </summary>
- /// <param name="sender"></param>
- private void varifyTextBoxValue(object sender)
- {
- if (string.IsNullOrEmpty(((TextBox)sender)/*this.textBox2*/.Text))
- ((TextBox)sender)/*this.textBox2*/.Text = "1";
- if (Convert.ToInt32(((TextBox)sender)/*this.textBox2*/.Text) > 50)
- ((TextBox)sender)/*this.textBox2*/.Text = "50";
- }
- /// <summary>
- /// 限制只可以输入0-9数字以及退格键
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBoxWidth_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != '\b')//这是允许输入退格键
- {
- int len = ((TextBox)sender)/*this.textBox1*/.Text.Length;
- if (len < 1 && e.KeyChar == '0')
- {
- e.Handled = true;
- }
- else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字
- {
- e.Handled = true;
- }
- }
- }
- private void textBox10_KeyUp(object sender, KeyEventArgs e)
- {
- this.varifyTextBoxValue(sender);
- this.trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
- }
- private void textBox3_KeyUp(object sender, KeyEventArgs e)
- {
- this.varifyTextBoxValue(sender);
- this.trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
- }
- #endregion 控件监听事件
- #region 矩形拖动
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- protected override void OnMouseDown(object sender, MouseEventArgs e)
- {
- if (!CanUseMouseFunctions())
- return;
- try
- {
- //判断
- //画左右下辅助线
- if (linebottom == null || lineleft == null || lineright == null)
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- //在MouseDown处获知鼠标是否按下,并记录下此时的鼠标坐标值;
- if (e.Button == MouseButtons.Left)
- {
- }
- return;
- //int margin = lab1Img.Width / 20;
- //lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, lab1Img.Height));
- //lineright = new Line(new System.Drawing.Point(lab1Img.Width - margin, 0), new System.Drawing.Point(lab1Img.Width - margin, lab1Img.Height));
- }
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
- string line = this.textBox6.Text.Trim();
- string width = this.textBox4.Text.Trim();
- //画平行的多条辅助线
- int n = int.Parse(line); //线的数量
- int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
- per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- int bottomY1 = linebottom.startPoint.Y - per_w * (n - 1);
- if (mouse_x < lineleft.startPoint.X + 10 && mouse_x > lineleft.startPoint.X - 10)
- {
- //拖动左辅助线
- mouseFlag = 1;
- }
- else if (mouse_x < lineright.startPoint.X + 10 && mouse_x > lineright.startPoint.X - 10)
- {
- //拖动右辅助线
- mouseFlag = 2;
- }
- else if (mouse_y < linebottom.startPoint.Y && mouse_y > bottomY1)
- {
- xPos = (int)mouse_x;// e.X;//当前x坐标
- yPos = (int)mouse_y;// e.Y;//当前y坐标
- //拖动平行辅助线
- mouseFlag = 3;
- }
- else
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void onMouseMove(object sender, MouseEventArgs e)
- {
- if (!CanUseMouseFunctions())
- return;
- //拖动左右辅助线
- if (mouseFlag == 1 || mouseFlag == 2)
- {
- //Mat ImageROI = null;
- try
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
- ////移动左辅助线
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- int margin = (int)mouse_x;
- margin = Math.Min(this.bitmap/*lab1Img*/.Width - 10, margin);
- margin = Math.Max(10, margin);
- if (mouseFlag == 1)
- {
- if (lineright != null && margin > lineright.startPoint.X)
- {
- margin = lineright.startPoint.X - 1;
- }
- lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
- }
- else if (mouseFlag == 2)
- {
- if (lineleft != null && margin < lineleft.startPoint.X)
- {
- margin = lineleft.startPoint.X + 1;
- }
- lineright = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
- }
- if (mouseFlag == 1 || mouseFlag == 2)
- {
- //int margin = this.bitmap/*lab1Img*/.Width / 20;
- int spaceLine = (int)((lineright.startPoint.X - lineleft.startPoint.X) * this.physical_length);
- if (spaceLine > 0)
- {
- this.textBox1.Text = spaceLine + "";
- }
- //if (int.TryParse(this.textBox1.Text.ToString().Trim(), out spaceLine))
- //{
- // margin = (int)((this.bitmap.Width - spaceLine / this.physical_length) / 2);
- //}
- }
- this.drawLines();
- this.documentWorkspace.Refresh();
- }
- catch
- {
- }
- finally
- {
- //ImageROI.Dispose();
- //GC.Collect();
- }
- return;
- }
- //拖动平行辅助线
- if (mouseFlag == 3)
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
- string line = this.textBox6.Text.Trim();
- string width = this.textBox4.Text.Trim();
- try
- {
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- //画左右下辅助线
- if (lineleft == null || lineright == null)
- {
- int margin = this.bitmap/*lab1Img*/.Width / 20;
- lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
- lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
- }
- if (linebottom == null)
- {
- linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
- }
- //bluePen = new Pen(Color.Blue, zoom);
- //drawg.DrawLine(bluePen, lineleft.startPoint, lineleft.endPoint);
- //drawg.DrawLine(bluePen, lineright.startPoint, lineright.endPoint);
- //画平行的多条辅助线
- int n = int.Parse(line); //线的数量
- int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
- per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- hlines.Clear();
- for (int i = 0; i < n; i++)
- {
- Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i));
- //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
- hlines.Add(l);
- }
- honlines.Clear();
- btnflag = 1;
- //pictureBox1.Image = map;
- this.documentWorkspace.Refresh();
- }
- catch (Exception ex)
- {
- //MessageBox.Show(ex.Message);//解决不断弹出提示语的bug
- }
- return;
- }
- if (btnflag == 2)
- {
- //Mat ImageROI = null;
- try
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
- ////移动辅助线
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- }
- catch (Exception b)
- {
- //MessageBox.Show(b.Message);//解决不断弹出提示语的bug
- }
- finally
- {
- //ImageROI.Dispose();
- //GC.Collect();
- }
- return;
- }
- if (btnflag == 1)
- {
- try
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
- string line = this.textBox6.Text.Trim();
- string width = this.textBox4.Text.Trim();
- //画平行的多条辅助线
- int n = int.Parse(line); //线的数量
- int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
- per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- int bottomY1 = linebottom.startPoint.Y - per_w * (n - 1);
- if ((mouse_x < lineleft.startPoint.X + 10 && mouse_x > lineleft.startPoint.X - 10) || (mouse_x < lineright.startPoint.X + 10 && mouse_x > lineright.startPoint.X - 10))
- {
- //移动辅助线
- this.documentWorkspace.Cursor = Cursors.SizeWE;
- }
- else if (mouse_y < linebottom.startPoint.Y && mouse_y > bottomY1)
- {
- //移动辅助线
- this.documentWorkspace.Cursor = Cursors.SizeAll;
- }
- else
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- }
- }
- catch (Exception ex)
- {
- //MessageBox.Show(ex.Message);//解决不断弹出提示语的bug
- }
- }
- else
- {
- this.documentWorkspace.Cursor = Cursors.Default;
- }
- }
- /// <summary>
- /// 鼠标抬起
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void onMouseUp(object sender, MouseEventArgs e)
- {
- if (!CanUseMouseFunctions())
- return;
- //拖动平行辅助线
- if (mouseFlag == 3)
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
- float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
- float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
- string line = this.textBox6.Text.Trim();
- string width = this.textBox4.Text.Trim();
- try
- {
- //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
- //画左右下辅助线
- if (lineleft == null || lineright == null)
- {
- int margin = this.bitmap/*lab1Img*/.Width / 20;
- lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
- lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
- }
- if (linebottom == null)
- {
- linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
- }
- //bluePen = new Pen(Color.Blue, zoom);
- //drawg.DrawLine(bluePen, lineleft.startPoint, lineleft.endPoint);
- //drawg.DrawLine(bluePen, lineright.startPoint, lineright.endPoint);
- //画平行的多条辅助线
- int n = int.Parse(line); //线的数量
- int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
- per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- hlines.Clear();
- for (int i = 0; i < n; i++)
- {
- Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i));
- //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
- hlines.Add(l);
- }
- honlines.Clear();
- btnflag = 1;
- //pictureBox1.Image = map;
- linebottom.startPoint.Y = linebottom.startPoint.Y + (int)(mouse_y - yPos);
- this.documentWorkspace.Refresh();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- mouseFlag = 0;
- }
- #endregion
- #region 分析结果的方法
- /// <summary>
- /// 点击保存结果按钮,用来返回需要新增的一行数据
- /// </summary>
- /// <param name="tag"></param>
- /// <param name="imgName"></param>
- /// <returns></returns>
- protected override DataTable toInsertTableRow(string tag, string imgName)
- {
- DataTable dt = new DataTable(tag);
- dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
- dt.Columns.Add(PdnResources.GetString("Menu.Totallengthofporeintercepts.text"));
- dt.Columns.Add(PdnResources.GetString("Menu.Meanporeintercept.text"));
- dt.Columns.Add(PdnResources.GetString("Menu.Numberofintercept.text"));
- //dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
- //dt.Columns.Add(PdnResources.GetString("Menu.Averagethickness(μm).text"));
- //dt.Columns.Add(PdnResources.GetString("Menu.standarddeviation.text"));
- //dt.Columns.Add(PdnResources.GetString("Menu.confidencebound.text"));
- DataRow dataRow = dt.NewRow();
- dataRow[PdnResources.GetString("Menu.picture.Text")] = imgName;
- dataRow[PdnResources.GetString("Menu.Totallengthofporeintercepts.text")] = res_totalL;
- dataRow[PdnResources.GetString("Menu.Meanporeintercept.text")] = res_perL;
- dataRow[PdnResources.GetString("Menu.Numberofintercept.text")] = res_count;
- dt.Rows.Add(dataRow);
- return dt;
- }
- /// <summary>
- /// 计算结果是否存在
- /// </summary>
- /// <returns>返回是否可以计算和保存结果</returns>
- protected override bool resultCalculateExist()
- {
- return tempHoleMat != null;// vlines.Count > 0;
- }
- /// <summary>
- /// 拼接中间数据
- /// </summary>
- /// <returns></returns>
- protected override List<List<string>> buildTempDataList()
- {
- //return null;
- List<List<string>> dataList = new List<List<string>>();
- List<string> columnName = new List<string>();
- //columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
- //columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.Xoordinate.Text"));
- //columnName.Add(PdnResources.GetString("Menu.ToYcoordinate.Text"));
- //columnName.Add(PdnResources.GetString("Menu.ToYcoonate.Text"));
- //columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.MeasureAction.MeasureLength.Text"));
- //columnName.Add(PdnResources.GetString("Menu.Physicallength.text"));//addAction:这里
- columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
- columnName.Add(PdnResources.GetString("Menu.eauxiliarylineYcoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.LeftXcoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.RightXcoordinate.Text"));
- columnName.Add(PdnResources.GetString("Menu.Lengthofauxiliaryline.Text"));
- columnName.Add(PdnResources.GetString("Menu.Physicallength.text"));//addAction:这里
- dataList.Add(columnName);
- int index = 0;
- //if (honlines != null && honlines.Count() > 0)
- //{
- // foreach (Line l in honlines)
- // {
- // graphics.DrawLine(yellowPen, l.startPoint, l.endPoint);
- // }
- //}
- //循环辅助线的集合
- if (honlines != null && honlines.Count() > 0)
- {
- //循环每条线,找到和轮廓的交点
- for (int i = 0; i < honlines.Count(); i++)
- {
- //Line l = honlines[i];
- List<string> strList = new List<string>();
- strList.Add((++index).ToString());
- strList.Add(honlines[i].startPoint.Y.ToString());
- strList.Add(honlines[i].startPoint.X.ToString());
- strList.Add(honlines[i].endPoint.X.ToString());
- strList.Add((honlines[i].endPoint.X - honlines[i].startPoint.X).ToString());
- strList.Add(((honlines[i].endPoint.X - honlines[i].startPoint.X) * physical_length).ToString());
- dataList.Add(strList);
- }
- }
- //int index = 0;
- //////厚度的数组
- ////int[] thickness = new int[vlines.Count()];
- ////循环辅助线的集合
- //if (this.vlines.Count > 0)
- //{
- // //循环每条线,找到和轮廓的交点
- // for (int i = 0; i < vlines.Count(); i++)
- // {
- // ////计算厚度,像素
- // //thickness[i] = lineNum - vlines[i].startPoint.Y;
- // List<string> strList = new List<string>();
- // strList.Add((++index).ToString());
- // strList.Add(vlines[i].startPoint.X.ToString());
- // strList.Add(vlines[i].startPoint.Y.ToString());
- // strList.Add(lineNum.ToString());
- // strList.Add((lineNum - vlines[i].startPoint.Y).ToString());
- // strList.Add(((lineNum - vlines[i].startPoint.Y) * physical_length).ToString());
- // dataList.Add(strList);
- // }
- //}
- return dataList;
- }
- /// <summary>
- /// 计算结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void buttonCalculate_Click(object sender, EventArgs e)
- {
- //if (top == null || bottom == null)
- //{
- // MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectareafirst.text"));
- // return;
- //}
- //int result = 0;
- if (hlines.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
- return;
- }
- if (!resultCalculateExist())
- {
- MessageBox.Show("请先进行寻找孔隙操作");//PdnResources.GetString("Menu.Pleaselookfortheoutlinefirst.text") ;//点击绘制轮廓
- return;
- //MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
- //return;
- }
- //calculation = true;
- //循环计算有效的网格线平均孔隙密度
- float totallength = 0;
- //float perlength = 0;
- int pointsum = 0;
- //List<List<OpenCvSharp.Point>> ddd = new List<List<OpenCvSharp.Point>>();
- honlines.Clear();
- for (int i = 0; i < hlines.Count; i++)//hlines
- {
- //List<OpenCvSharp.Point> list = new List<OpenCvSharp.Point>();
- int xMinPoint = Math.Min(lineleft.endPoint.X, lineright.endPoint.X);
- int xMaxPoint = Math.Max(lineleft.endPoint.X, lineright.endPoint.X);
- int yLinePoint = hlines[i].endPoint.Y;// - 1;
- if (yLinePoint <= 0)
- {
- continue;
- }
- bool holeLineStart = true;//结束于视场的边缘或孔隙区域的中间,则这个区域不应包括在内
- OpenCvSharp.Point startPoint = new OpenCvSharp.Point(-1, yLinePoint);
- for (int j = xMinPoint; j <= xMaxPoint; j++)
- {
- if (tempHoleMat.At<Vec4b>(yLinePoint, j).Item3 > 0)//############
- {
- if (!holeLineStart)
- {
- startPoint.X = j;
- //list.Add(new OpenCvSharp.Point(j, yLinePoint));//记录网格线的起始点
- holeLineStart = true;
- }
- }
- else if (holeLineStart)
- {
- holeLineStart = false;
- if (startPoint.X > 0)
- {
- ++pointsum;
- totallength += (j - startPoint.X);
- honlines.Add(new Line(new System.Drawing.Point(startPoint.X, yLinePoint), new System.Drawing.Point(j, yLinePoint)));
- //list.Add(new OpenCvSharp.Point(j, yLinePoint));//记录网格线的结束点
- }
- }
- }
- //if (!holeLineStart && list.Count > 0)//起始于视场的边缘或孔隙区域的中间,则这个区域不应包括在内
- // list.RemoveAt(list.Count - 1);
- //////for (int j = contours.Count() - 1; j >= 0; j--)//#
- //////{
- ////// List<OpenCvSharp.Point> dsd = contours[j].ToList<OpenCvSharp.Point>();
- ////// List<OpenCvSharp.Point> lll = dsd.FindAll(a => a.Y == hlines[i].endPoint.Y - 1 && a.X > lineleft.endPoint.X && a.X < lineright.endPoint.X);
- ////// if (lll != null && lll.Count > 0)
- ////// {
- ////// //过滤一下,如果点密集,只要一个
- ////// int finetuning = 0;
- ////// //过滤,如果一个轮廓返回了一个点或者奇数点,则抛弃
- ////// List<OpenCvSharp.Point> temp = new List<OpenCvSharp.Point>();
- ////// foreach (var Point in lll)
- ////// {
- ////// //过滤一下,如果点密集,只要一个
- ////// if (finetuning == 0)
- ////// {
- ////// finetuning = Point.X;
- ////// }
- ////// else
- ////// {
- ////// if ((Point.X == finetuning + 1) || (Point.X == finetuning - 1))
- ////// {
- ////// finetuning = Point.X;
- ////// continue;
- ////// }
- ////// finetuning = Point.X;
- ////// }
- ////// temp.Add(new OpenCvSharp.Point(Point.X, Point.Y));
- ////// }
- ////// list.AddRange(temp);
- ////// }
- //////}
- ////list.Sort((a, b) => a.X.CompareTo(b.X));
- //ddd.Add(list);
- }
- ////Cv2.ImShow("dst12344", dst1234);
- //honlines.Clear();
- ////绘制所有交点
- //foreach (var point in ddd)
- //{
- // for (int k = 0; k < point.Count - 1; k += 2)
- // {
- // ////drawg.DrawEllipse(new Pen(Color.Yellow, drawsize), point[k].X, point[k].Y, drawsize, drawsize);
- // OpenCvSharp.Point a = point[k];
- // OpenCvSharp.Point b = point[k + 1];
- // //int x = (a.X + b.X) / 2;
- // ////lab1NoneContourImg
- // //if (dst1234.At<byte>(a.Y, x) <= 0)
- // //{
- // // ++pointsum;
- // // totallength += (b.X - a.X);
- // //honlines.Add(new Line(new System.Drawing.Point(a.X, a.Y), new System.Drawing.Point(b.X, b.Y)));
- // // //drawg.DrawLine(new Pen(Color.Yellow, drawsize), a.X, a.Y, b.X, b.Y);
- // //}
- // ////double innum = Cv2.PointPolygonTest(contours[j], new Point2f(x, a.Y), false);
- // ////if (innum > 0)
- // ////{
- // //// drawg.DrawLine(new Pen(Color.Yellow, drawsize), a.X, a.Y, b.X, b.Y);
- // //// break;
- // ////}//########################################
- // }
- //}
- //////Cv2.DrawContours(lab1Img, contours, -1, Scalar.Blue, Cv2.FILLED);
- //////pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1Img);
- ////pictureBox1.Image = map;
- this.documentWorkspace.Refresh();
- res_totalL = totallength * physical_length;
- res_perL = res_totalL / Math.Max(1, pointsum);
- res_count = Math.Max(1, pointsum);
- //计算结果
- this.label2.Text = this.resShow(res_totalL.ToString());
- this.label7.Text = this.resShow(res_perL.ToString());
- this.label14.Text = res_count.ToString(); ;
- calculate1d = true;
- }
- /// <summary>
- /// 记录输入文字改变的状态
- /// </summary>
- int textBoxChanged = -1;
- /// <summary>
- /// 上辅助线居顶距离改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox4_TextChanged(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- return;
- }
- string width2 = this.textBox6.Text.Trim();
- int result2;
- if (!int.TryParse(width2, out result2))
- {
- //MessageBox.Show("线的数量输入格式不正确");
- return;
- }
- string width = this.textBox4.Text.Trim();
- double result;
- if (!double.TryParse(width, out result))
- {
- return;
- }
- this.drawLines();
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 下辅助线居底距离改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBox6_TextChanged(object sender, EventArgs e)
- {
- if (this.bitmap == null)
- {
- return;
- }
- string width = this.textBox4.Text.Trim();
- double result;
- if (!double.TryParse(width, out result))
- {
- //MessageBox.Show(PdnResources.GetString("Menu.Linespacinginputformatincorrect.text"));
- return;
- }
- string width2 = this.textBox6.Text.Trim();
- int result2;
- if (!int.TryParse(width2, out result2))
- {
- //MessageBox.Show("线的数量输入格式不正确");
- return;
- }
- this.drawLines();
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 小数点位数变化时刷新界面的数据
- /// </summary>
- protected override void RefreshDataGridView1()
- {
- if (calculate1d)
- {
- this.label2.Text = this.resShow(res_totalL.ToString());
- this.label7.Text = this.resShow(res_perL.ToString());
- this.label14.Text = this.resShow(res_count.ToString());
- }
- }
- #endregion 分析结果的方法
- private void textBox1_KeyUp(object sender, KeyEventArgs e)
- {
- //this.varifyTextBoxValue(sender);
- //画左右下辅助线
- if (lineleft != null || lineright != null)
- {
- int margin = this.bitmap/*lab1Img*/.Width / 20;
- int spaceLine = (int)((this.bitmap.Width - 2 * margin) * this.physical_length);
- if (int.TryParse(this.textBox1.Text.ToString().Trim(), out spaceLine))
- {
- margin = (int)((this.bitmap.Width - spaceLine / this.physical_length) / 2);
- if (margin < 0)
- {
- margin = 1;
- /*int */
- spaceLine = (int)((this.bitmap.Width - 2) * this.physical_length);
- if (spaceLine > 0)
- {
- this.textBox1.Text = spaceLine + "";
- }
- }
- lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
- lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
- this.documentWorkspace.Refresh();
- }
- }
- ////if (linebottom == null)
- ////{
- //// linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
- ////}
- //////画平行的多条辅助线
- ////int n = int.Parse(line); //线的数量
- ////int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
- ////per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
- ////hlines.Clear();
- ////{
- //// for (int i = 0; i < n; i++)
- //// {
- //// Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y - per_w * i));
- //// //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
- //// hlines.Add(l);
- //// }
- ////}
- ////honlines.Clear();
- ////btnflag = 1;
- //this.documentWorkspace.Refresh();
- ////this.trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
- }
- #region 参数保存及提取
- /// <summary>
- /// 保存参数的key,value和type
- /// </summary>
- /// <param name="param_key"></param>
- /// <param name="param_value"></param>
- /// <param name="param_type"></param>
- private void saveParamValue(string param_key, string param_value, int param_type)
- {
- bool foundItem = false;
- foreach (var item in this.analysisModel.ListParam)
- {
- if (item.param_key.Equals(param_key) && item.menuId == this.menuId)
- {
- item.param_value = param_value;
- item.setValue();
- foundItem = true;
- break;
- }
- }
- if (!foundItem)
- {
- GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
- analysisItem.menuId = this.menuId;
- analysisItem.param_key = param_key;
- analysisItem.param_type = param_type;
- analysisItem.param_value = param_value;
- analysisItem.setValue();
- this.analysisModel.ListParam.Add(analysisItem);
- }
- }
- /// <summary>
- /// 保存界面中的参数到model
- /// </summary>
- private void saveDialogParamValues()
- {
- saveParamValue(ParamKey_Report, checkBox_generateReport_opensetting.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//报告设置
- saveParamValue(ParamKey_PoreColour, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//孔隙颜色
- saveParamValue(ParamKey_PoreSpacing, textBox1.Text, (int)Base.Dtryt.ItemString);//孔隙辅助线间距
- saveParamValue(ParamKey_GuideColour, panel4.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//辅助线颜色
- saveParamValue(ParamKey_GuideWidth, textBox3.Text, (int)Base.Dtryt.ItemString);//辅助线线宽
- saveParamValue(ParamKey_GuideNumber, textBox6.Text, (int)Base.Dtryt.ItemString);//辅助线条数
- saveParamValue(ParamKey_GuideSpacing, textBox4.Text, (int)Base.Dtryt.ItemString);//辅助线间距
- saveParamValue(ParamKey_PoreSetColour, panel3.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//孔隙设置颜色
- saveParamValue(ParamKey_PoreSetWidth, textBox10.Text, (int)Base.Dtryt.ItemString);//孔隙设置线宽
- saveParamValue(ParamKey_DecimalPlace, numericUpDown1_0 != null ? numericUpDown1_0.Value.ToString() : "", (int)Base.Dtryt.Decimal);//保留小数位数
- }
- /// <summary>
- /// 获取保存的参数
- /// </summary>
- private void GetListParamModel()
- {
- if (this.analysisModel != null)
- {
- for (int i = 0; i < this.analysisModel.ListParam.Count; i++)
- {
- switch (this.analysisModel.ListParam[i].param_key)
- {
- case ParamKey_Report:
- checkBox_generateReport_opensetting.Checked = (Boolean)this.analysisModel.ListParam[i].value;
- break;
- case ParamKey_PoreColour:
- panel1.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_PoreSpacing:
- textBox1.Text = this.analysisModel.ListParam[i].value.ToString();
- break;
- case ParamKey_GuideColour:
- panel4.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_GuideWidth:
- textBox3.Text = this.analysisModel.ListParam[i].value.ToString();
- trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
- break;
- case ParamKey_GuideNumber:
- textBox6.Text = this.analysisModel.ListParam[i].value.ToString();
- break;
- case ParamKey_GuideSpacing:
- textBox4.Text = this.analysisModel.ListParam[i].value.ToString();
- break;
- case ParamKey_PoreSetColour:
- panel3.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
- break;
- case ParamKey_PoreSetWidth:
- textBox10.Text = this.analysisModel.ListParam[i].value.ToString();
- trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
- break;
- case ParamKey_DecimalPlace:
- numericUpDown1_0.Value = decimal.Parse(this.analysisModel.ListParam[i].param_value);
- break;
- }
- }
- }
- }
- /// <summary>
- /// 关闭窗体时保存参数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TABM3Dialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- this.saveDialogParamValues();
- //xml保存路径
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
- GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
- foreach (var analysisItem in this.analysisModel.ListParam)
- {
- bool foundItem = false;
- foreach (var item in analysisModelXml.ListParam)
- {
- if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId)
- {
- item.param_value = analysisItem.param_value;
- foundItem = true;
- break;
- }
- }
- if (!foundItem)
- analysisModelXml.ListParam.Add(analysisItem.cloneModel());
- }
- //按路径和名称保存xml文件
- string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainSizeAnalysisModel>(analysisModelXml);
- //保存xml
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create);
- }
- #endregion
- }
- }
|