123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821 |
- using OTSCLRINTERFACE;
- using OTSCommon;
- using OTSCommon.DBOperate.Model;
- using OTSIncAReportApp.OTSRstMgrFunction;
- using OTSIncAReportGraph.Class;
- using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
- using OTSPeriodicTable;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SQLite;
- using System.Drawing;
- using System.Linq;
- using System.Reflection;
- using System.Threading;
- using System.Windows.Forms;
- using Color = System.Drawing.Color;
- namespace OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage
- {
- public partial class ListOfSimilarParticles : Form
- {
- OTSIncAReportGrids.ParticlesGridDevidePage _particlesGridDevidePage;
- CPosXrayClr SelXrayclr = new CPosXrayClr();
- DataTable particlesAll;
- DataTable particles;
- Hashtable table;
- int _classifyid;
- List<string> _RenameInfo;
- private Thread m_mythread;
- //记录线程是否已经运行完成的状态
- private bool m_mythread_state = false;
- //底层操作类
- OTSReportGridsFun m_OTSIncAReportGridsFun = null;
- public ListOfSimilarParticles(OTSIncAReportGrids.ParticlesGridDevidePage particlesGridDevidePage, uint[] SelXray, int classifyid, List<string> RenameInfo)
- {
- InitializeComponent();
- _particlesGridDevidePage = particlesGridDevidePage;
- SelXrayclr.SetXrayData(SelXray);
- table = particlesGridDevidePage.table;
- _classifyid = classifyid;
- _RenameInfo = RenameInfo;
- m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
- //设置窗体的双缓冲,以保证大数据时拖动不卡
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
- this.UpdateStyles();
- //利用反射设置DataGridView的双缓冲
- Type dgvType = this.dgV_SimilarParticles.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi.SetValue(this.dgV_SimilarParticles, true, null);
- this.control_XRayTable1 = new OTSIncAReportGraph.Controls.Control_XRayTable(null);
- this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
- this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.control_XRayTable1.GBInfoStr = "";
- this.control_XRayTable1.GoodChineseName = "";
- this.control_XRayTable1.MaterialName = "";
- this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
- this.control_XRayTable1.Name = "control_XRayTable1";
- this.control_XRayTable1.ShowAnalysisXray = true;
- this.control_XRayTable1.ShowSearchXray = false;
- this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
- this.control_XRayTable1.STDName = "";
- this.control_XRayTable1.Visible = false;
- this.control_XRayTable1.label_close.Visible = true;
- panel1.Controls.Add(this.control_XRayTable1);
- }
- private void btn_Search_Click(object sender, EventArgs e)
- {
- double val;
- if (!double.TryParse(tB_SimilarRatio.Text, out val))
- {
- MessageBox.Show("The value must range from 0 to 100!");
- return;
- }
- else
- {
- this.Cursor = Cursors.WaitCursor;
- particlesAll = ObtainSourceOfSimilarParticles(_classifyid);
- DataTable elementchemistry = _particlesGridDevidePage.Particledata.GetElementChemistry();
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
- DataRow[] drs = elementchemistry.Select(str);
- string ConcatenatedString = "";
- for (int j = 0; j < drs.Length; j++)
- {
- ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
- }
- particlesAll.Rows[i]["Element"] = ConcatenatedString;
- }
- particlesAll.Columns.Add("SimilarRatio", typeof(double));
- DataTable mergeParticles = _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_mergeParticles("");
- if (mergeParticles != null && mergeParticles.Rows.Count > 0)
- {
- _particlesGridDevidePage.RemoveMergeParticles(ref particlesAll, mergeParticles);
- }
- DataTable XRayData = _particlesGridDevidePage.Particledata.GetXRayData();
- particlesAll.Columns.Add("XRayDataCount");
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- if (int.Parse(particlesAll.Rows[i]["particleId"].ToString()) > -1)
- {
- particlesAll.Rows[i]["XRayDataCount"] = 0;
- string str = " XrayIndex= " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
- DataRow[] drs = XRayData.Select(str);
- uint xraycount = 0;
- if (drs != null)
- {
- if (drs.Length > 0)
- {
- uint[] Analysis_xray = new uint[2000];
- for (int j = 0; j < 2000; j++)
- {
- Analysis_xray[j] = BitConverter.ToUInt32((byte[])drs[0][2], j * 4);
- }
- for (int j = 0; j < 2000; j++)
- {
- xraycount += Analysis_xray[j];
- }
- particlesAll.Rows[i]["XRayDataCount"] = xraycount;
- }
- }
- }
- }
- particles = particlesAll.Clone();
- foreach (DataRow row in particlesAll.Rows)
- {
- var tmpPart = _particlesGridDevidePage.Particledata.GetParticleXrayDataByFidAndPid(row["fieldid"].ToString(), row["xrayid"].ToString());
- if (tmpPart != null)
- {
- uint[] Search_xray = new uint[2000];
- for (int i = 0; i < 2000; i++)
- {
- Search_xray[i] = BitConverter.ToUInt32(tmpPart.XRayData, i * 4);
- }
- CPosXrayClr Xrayclr = new CPosXrayClr();
- Xrayclr.SetXrayData(Search_xray);
- row["SimilarRatio"] = GetCosValue(SelXrayclr, Xrayclr);
- if ((double)row["SimilarRatio"] >= val/100)
- {
- particles.ImportRow(row);
- }
- }
- }
- particles.DefaultView.Sort = "SimilarRatio DESC";
- particles = particles.DefaultView.ToTable();
- BindDataGridView();
- SetDataGridViewStyle();
- cBx_All.Checked = false;
- cBx_All.Checked = true;
- label3.Text = "共搜索到" + (dgV_SimilarParticles.Rows.Count-1).ToString() + "个相似颗粒";
- this.Cursor = Cursors.Default;
- }
- }
- private void SetDataGridViewStyle()
- {
- //用户不能调整标题的高度
- dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //用户不能调整 行高
- dgV_SimilarParticles.AllowUserToResizeRows = false;
- //点击选择整行
- dgV_SimilarParticles.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- //居中显示
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
- dgV_SimilarParticles.DefaultCellStyle = dataGridViewCellStyle1;
- dgV_SimilarParticles.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- //再次重覆禁用拖动表头高度,居然有效果了
- dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //设置grid可以复制
- dgV_SimilarParticles.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
- //设置每列的宽度
- dgV_SimilarParticles.Columns[0].Width = 30;//第一列序号的宽度设置一下吧,要不太丑
- dgV_SimilarParticles.Columns[1].Width = 100;
- for (int i = 4; i < dgV_SimilarParticles.Columns.Count; i++)
- {
- dgV_SimilarParticles.Columns[i].Width = 65;
- }
- //设置序号列不排序
- dgV_SimilarParticles.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- dgV_SimilarParticles.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
- //设置序号列不可以设置宽度
- dgV_SimilarParticles.Columns[0].Resizable = DataGridViewTriState.False;
- dgV_SimilarParticles.RowsDefaultCellStyle.BackColor = Color.Azure;
- if (dgV_SimilarParticles.Rows.Count > 0)
- {
- dgV_SimilarParticles.Rows[0].Frozen = true;
- }
- }
- private void BindDataGridView()
- {
- dgV_SimilarParticles.Visible = false;
- dgV_SimilarParticles.Rows.Clear();
- dgV_SimilarParticles.Columns.Clear();
- string str_DefaultComputedColName = "", str_ElementsColName = "";
- DataSet ds = XMLoperate.GetXmlData(Application.StartupPath + RptConfigFile.m_ReportMgrParamFile, "XMLData");
- DataTable dt = ds.Tables["Member"];
- foreach (DataRow element in dt.Rows)
- {
- string RegName = element["RegName"].ToString();
- if (RegName == "DefaultComputedColName")
- {
- str_DefaultComputedColName = element["strValue"].ToString();
- }
- if (RegName == "ElementsColName")
- {
- str_ElementsColName = element["strValue"].ToString();
- }
- }
- string[] strs = str_DefaultComputedColName.Split(',');
- Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
- keyValues.Add("SimilarRatio", "相似度");
- keyValues.Add("TypeName", table["str6"].ToString());
- keyValues.Add("ParticleImage", table["str5"].ToString());
- keyValues.Add("FieldId", "FieldId");
- keyValues.Add("ParticleId", "ParticleId");
- keyValues.Add("SEMPosX", "SEMPosX");
- keyValues.Add("SEMPosY", "SEMPosY");
- for (int i = 0; i < strs.Count(); i++)
- {
- if (strs[i] == "ParticleCoordinate")
- {
- keyValues.Add("AbPosX", "PosX");
- keyValues.Add("AbPosY", "PosY");
- }
- if (strs[i] == "Area")
- {
- keyValues.Add("Area", table["str21"].ToString());
- }
- if (strs[i] == "EquivalentCircleDiameter")
- {
- keyValues.Add("Equivalent", table["str22"].ToString());
- }
- if (strs[i] == "MaxDiameter")
- {
- keyValues.Add("DMAX", table["str23"].ToString());
- }
- if (strs[i] == "MinDiameter")
- {
- keyValues.Add("DMIN", table["str24"].ToString());
- }
- if (strs[i] == "DiameterRatio")
- {
- keyValues.Add("DiameterRatio", table["str25"].ToString());
- }
- if (strs[i] == "FerretDiameter")
- {
- keyValues.Add("DFERET", table["str26"].ToString());
- }
- if (strs[i] == "PERP")
- {
- keyValues.Add("DPERP", table["str27"].ToString());
- }
- if (strs[i] == "PERI")
- {
- keyValues.Add("PERIMETER", table["str28"].ToString());
- }
- if (strs[i] == "INSCR")
- {
- keyValues.Add("DINSCR", table["str29"].ToString());
- }
- if (strs[i] == "MEAN")
- {
- keyValues.Add("DMEAN", table["str30"].ToString());
- }
- if (strs[i] == "ELONG")
- {
- keyValues.Add("DELONG", table["str31"].ToString());
- }
- if (strs[i] == "ASPECT_ELONG")
- {
- keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
- }
- if (strs[i] == "Orientation")
- {
- keyValues.Add("ORIENTATION", table["str33"].ToString());
- }
- if (strs[i] == "XRayDataCount")
- {
- keyValues.Add("XRayDataCount", "XRay计数");
- }
- }
- keyValues.Add("Element", "Element");
- Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
- for (int irow = 0; irow < keyValues.Count; irow++)
- {
- if (en.MoveNext())
- {
- if (en.Current.Key == "ParticleImage")
- {
- DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
- iconColumn.Name = en.Current.Key;
- iconColumn.HeaderText = en.Current.Value;
- dgV_SimilarParticles.Columns.Add(iconColumn);
- }
- else if (en.Current.Key == "Element")
- {
- }
- else
- {
- dgV_SimilarParticles.Columns.Add(en.Current.Key, en.Current.Value);
- if (en.Current.Key == "Area" || en.Current.Key == "EquivalentCircleDiameter" || en.Current.Key == "MaxDiameter" || en.Current.Key == "MinDiameter" || en.Current.Key == "DiameterRatio" || en.Current.Key == "FerretDiameter" || en.Current.Key == "PERP" || en.Current.Key == "PERI" || en.Current.Key == "INSCR" || en.Current.Key == "MEAN" || en.Current.Key == "ELONG" || en.Current.Key == "ASPECT_ELONG" || en.Current.Key == "Orientation")
- {
- int id = dgV_SimilarParticles.Columns.Count;
- dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType";
- }
- }
- }
- }
- if (particlesAll == null)
- {
- return;
- }
- string particleM = "";
- List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
- for (int i = 0; i < ElementTypeSort.Count; i++)
- {
- if (ElementTypeSort[0] == "")
- {
- ElementTypeSort.RemoveAt(0);
- break;
- }
- dgV_SimilarParticles.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
- int id = dgV_SimilarParticles.Columns.Count;
- dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType";
- }
- string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
- KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
- for (int i = 0; i < particles.Rows.Count; i++)
- {
- Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
- int add_rowindex = dgV_SimilarParticles.Rows.Add();
- for (int k = 0; k < keyValues.Count; k++)
- {
- if (enl.MoveNext())
- {
- if (enl.Current.Key == "ParticleImage")
- {
- if (particles.Columns.Contains("SubParticles"))
- {
- string subt = particles.Rows[i]["SubParticles"].ToString();
- if (subt != null && subt != "")
- {
- double ScanFieldSize = _particlesGridDevidePage.result.GetScanFieldSizeX();
- string filePatht = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
- string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
- Bitmap tempbit = _particlesGridDevidePage.Particledata.ReadImageFile(imagePatht);
- int pixw = tempbit.Width;
- double xs = pixw / ScanFieldSize;
- particleM = particleM + "," + subt;
- Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapForBig(subt, xs, _particlesGridDevidePage.result.FilePath, tempbit.Height, tempbit.Width);
- if (bmap != null)
- {
- string[] str = subt.Split(',');
- bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
- dgV_SimilarParticles.Rows[add_rowindex].Height = 150;
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = bmap;
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
- dgV_SimilarParticles.Rows[add_rowindex].DefaultCellStyle.ForeColor = Color.Chocolate;
- }
- else
- {
- dgV_SimilarParticles.Rows[add_rowindex].Height = 150;
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
- }
- }
- }
- else
- {
- if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
- {
- string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
- FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), _particlesGridDevidePage.Particledata.ReadImageFile(imagePath));
- }
- Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particles.Rows[i]["RectLeft"]), Y = Convert.ToInt32(particles.Rows[i]["RectTop"]), Width = Convert.ToInt32(particles.Rows[i]["RectWidth"]), Height = Convert.ToInt32(particles.Rows[i]["RectHeight"]) };
- Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
- bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString(), particles.Rows[i]["XrayId"].ToString() };
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = bmap;
- dgV_SimilarParticles.Rows[add_rowindex].Height = bmap.Height + 20;
- }
- }
- if (enl.Current.Key == "DiameterRatio")
- {
- double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
- }
- if (en.Current.Key == "Element")
- {
- }
- if (enl.Current.Key == "ASPECT_ELONG")
- {
- double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
- }
- if (particles.Columns.Contains(enl.Current.Key))
- {
- double num = 0;
- if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
- {
- if (enl.Current.Key == "SimilarRatio")
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 5);
- }
- else
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);}
- }
- else if (enl.Current.Key == "Element")
- {
- List<string> elementtemp = new List<string>(ElementTypeSort);
- string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
- for (int j = 0; j < strcbo.Length; j++)
- {
- if (ElementTypeSort.Count == 0)
- {
- break;
- }
- string[] str = strcbo[j].Split('-');
- if (ElementTypeSort.Contains(str[0]))
- { dgV_SimilarParticles.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
- elementtemp.Remove(str[0].ToString());
- }
- foreach (var ele in elementtemp)
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[ele].Value = "0";
- }
- }
- else
- {
- double val = 0;
- if (double.TryParse(Convert.ToString(particles.Rows[i][enl.Current.Key]), out val))
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = val;
- }
- else
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
- }
- }
- }
- if (enl.Current.Key == "TypeName")
- {
- if (particles.Rows[i]["TypeId"].ToString() == "9")
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = "Not Identified";
- }
- }
- if (enl.Current.Key == "Equivalent")
- {
- double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
- double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
- }
- if (enl.Current.Key == "AbPosX")
- {
- Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(Convert.ToInt32(particles.Rows[i]["SEMPosX"]), Convert.ToInt32(particles.Rows[i]["SEMPosY"])), new Point(Convert.ToInt32(particles.Rows[i]["PosX"]), Convert.ToInt32(particles.Rows[i]["PosY"])));
- dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosX"].Value = point.X;
- dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosY"].Value = point.Y;
- }
- }
- }
- }
- DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
- checkBoxColumn.HeaderText = "选择";
- checkBoxColumn.Name = "IsSelected";
- checkBoxColumn.TrueValue = true;
- checkBoxColumn.FalseValue = false;
- checkBoxColumn.Width = 30;
- checkBoxColumn.ReadOnly = false;
- dgV_SimilarParticles.Columns.Insert(0, checkBoxColumn);
- dgV_SimilarParticles.Rows[0].Cells[2].Value = _RenameInfo[1];
- dgV_SimilarParticles.Visible = true;
- }
- private double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1)
- {
- if (posXray == null) return 0;
- if (posXray1 == null) return 0;
- if (posXray.GetChannelsNum() != posXray1.GetChannelsNum())
- {
- return 0;
- }
- var pXrayData = posXray.GetXrayData();
- var pXrayData1 = posXray1.GetXrayData();
- // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2))
- double dotProduct = 0;
- double d1 = 0;
- double d2 = 0;
- for (int i = 0; i < posXray.GetChannelsNum(); i++)
- {
- double r1 = pXrayData[i];
- double r2 = pXrayData1[i];
- r1 *= r2;
- dotProduct = dotProduct + r1;
- }
- d1 = posXray.GetXrayDataVectorNorm();
- d2 = posXray1.GetXrayDataVectorNorm();
- return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2);
- }
- private void ListOfSimilarParticles_Load(object sender, EventArgs e)
- {
- btn_Search_Click(null, null);
- }
- private void btn_OK_Click(object sender, EventArgs e)
- {
- List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
- foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
- {
- if (row.Cells["IsSelected"].Value != null && (bool)row.Cells["IsSelected"].Value)
- {
- row.Cells[1].Value = _RenameInfo[0];
- Bitmap ls_bp = (Bitmap)row.Cells[3].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- int i_ls_fieldid = Convert.ToInt32(list_str[0]);
- int i_ls_particleid = Convert.ToInt32(list_str[1]);
- List<int> ints = new List<int>();
- ints.Add(i_ls_fieldid);
- ints.Add(i_ls_particleid);
- var cmd = _particlesGridDevidePage.Particledata.GetUpdataAIncACmd(ints, _RenameInfo);
- cmdlist.Add(cmd);
- }
- }
- _particlesGridDevidePage.Particledata.ExecuteNonQueryBatch(cmdlist);
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- private void cBx_All_CheckedChanged(object sender, EventArgs e)
- {
- CheckBox selectAllCheckBox = (CheckBox)sender;
- foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
- {
- DataGridViewCheckBoxCell checkBox = row.Cells["IsSelected"] as DataGridViewCheckBoxCell;
- checkBox.Value = selectAllCheckBox.Checked;
- }
- dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
- }
- DataTable ObtainSourceOfSimilarParticles(int _classifyid)
- {
- if (_classifyid == -1)
- {
- return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_InvalidParticle("");
- }
- else if (_classifyid == 9)
- {
- return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_NotIdentifyParticle("");
- }
- else if (_classifyid != 4)
- {
- return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_analyticalParticle("");
- }
- return null;
- }
- private void btn_Cannnel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- this.Close();
- }
- private void dgV_SimilarParticles_MouseUp(object sender, MouseEventArgs e)
- {
- var SelectRows = dgV_SimilarParticles.SelectedRows;
- if (SelectRows.Count != 0)
- {
- if (SelectRows.Count == 1)
- {
- DataGridViewRow dgvr = SelectRows[0];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- uint[] Search_xray = new uint[2000];
- uint[] Analysis_xray = new uint[2000];
- int i_xray_id = 0;
- List<Element> list_celementchemistryclr = new List<Element>();
- _particlesGridDevidePage.ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
- List<OTSIncAReportGraph.Controls.ShowElementInfo> list_showelementinfo = new List<OTSIncAReportGraph.Controls.ShowElementInfo>();
- for (int i = 0; i < list_celementchemistryclr.Count; i++)
- {
- OTSIncAReportGraph.Controls.ShowElementInfo ls_sei = new OTSIncAReportGraph.Controls.ShowElementInfo();
- ls_sei.ElementName = list_celementchemistryclr[i].Name;
- ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
- ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
- double de_sx2 = 0;
- if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
- {
- de_sx2 = 0;
- }
- else
- {
- de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
- }
- ls_sei.dLF = de_sx2;
- list_showelementinfo.Add(ls_sei);
- }
- list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
- string str_IncAName = "";
- str_IncAName = Convert.ToString(dgvr.Cells[2].Value);
- Particle particle = _particlesGridDevidePage.result.List_OTSField.Find(x => x.FieldID == Convert.ToInt32(dgvr.Cells["fieldid"].Value)).ParticleList.Find(x => x.ParticleId == Convert.ToInt32(dgvr.Cells["particleId"].Value));
- if (particle == null)
- {
- return;
- }
- control_XRayTable1.SetParticleInfo("Area:" + Math.Round(particle.Area, 2) + " " + "DMAX:" + Math.Round(particle.DMAX, 2) + " " + "DELONG:" + Math.Round(particle.DELONG, 2) + " " + "DFERET:" + Math.Round(particle.DFERET, 2) + " " + "DINSCR:" + Math.Round(particle.DINSCR, 2) + "\n" + "DMEAN:" + Math.Round(particle.DMEAN, 2) + " " + "DMIN:" + Math.Round(particle.DMIN, 2) + " " + "DPERP:" + Math.Round(particle.DPERP, 2) + " " + "ORIENTATION:" + Math.Round(particle.ORIENTATION, 2) + " " + "PERIMETER:" + Math.Round(particle.PERIMETER, 2));
- control_XRayTable1.Visible = true;
- control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo);
- //颗粒国标信息
- control_XRayTable1.GBInfoStr = "";
- control_XRayTable1.MaterialName = str_IncAName;//杂夹物
- control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
- DataRow[] drs = particles.Select(str);
- if (drs.Length > 0)
- {
- Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) };
- Bitmap dpImage = new Bitmap(_particlesGridDevidePage.result.GetImageWidth(), _particlesGridDevidePage.result.GetImageHeight());
- using (Graphics graphics = Graphics.FromImage(dpImage))
- {
- graphics.Clear(Color.White); // 清除位图背景为白色
- }
- string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
- string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp";
- Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath);
- foreach (Segment seg in particle.SegmentList)
- {
- int f_length = seg.Length;
- for (int m = 0; m < f_length; m++)
- {
- int lsjs_x = seg.Start + m;
- int lsjs_y = seg.Height;
- var pixelColor = m_originalImage.GetPixel(lsjs_x, lsjs_y);
- dpImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
- }
- }
- Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(dpImage, rectangle);
- Bitmap bmap1 = _particlesGridDevidePage.Particledata.GetBitmapByParticle(m_originalImage, rectangle);
- control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap);
- Invalidate();
- }
- else
- {
- control_XRayTable1.Visible = false;
- }
- }
- }
- }
- private void movetoparticleToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
- string i_ls_fieldid = "";
- string i_ls_particleid = "";
- int cou = dgV_SimilarParticles.SelectedRows.Count;
- if (cou > 0)
- {
- DataGridViewRow dgvr = dgV_SimilarParticles.SelectedRows[cou - 1];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- if (list_str != null)
- {
- i_ls_fieldid = list_str[0];
- i_ls_particleid = list_str[1];
- }
- }
- DataOperation.DataAccess.ParticleData particleData = new DataOperation.DataAccess.ParticleData(_particlesGridDevidePage.result.FilePath);
- Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
- //取得Field的Position,然后执行线程移动SEM到当前Field的位置
- if (m_mythread == null)
- {
- return;
- }
- if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
- {
- return;
- }
- if (m_mythread.ThreadState == ThreadState.Stopped)
- {
- m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
- }
- Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY));
- //改为线程调用,先判断线程状态
- m_mythread.Start(point);
- }
- #region 连接电镜相关
- /// <summary>
- /// 移动SEM到指定位置线程函数
- /// </summary>
- private void Thread_GO(object in_obj)
- {
- if (m_mythread_state == false)
- {
- m_mythread_state = true;
- Point sem_point = (Point)in_obj;
- //第一步,连接电镜
- m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
- Thread.Sleep(500);
- //第二步,移动到指定位置,先读取再设置
- if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
- {
- m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
- }
- Thread.Sleep(1500);
- m_mythread_state = false;
- }
- }
- #endregion
- private void dgV_SimilarParticles_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Down)
- {
- dgV_SimilarParticles_MouseUp(null, null);
- }
- if (e.KeyData == Keys.Up)
- {
- dgV_SimilarParticles_MouseUp(null, null);
- }
- if (e.KeyData == Keys.Space)
- {
- dgV_SimilarParticles_CellMouseDoubleClick(null,null);
- }
- }
- private void tB_SimilarRatio_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Enter)
- {
- btn_Search_Click(null, null);
- }
- }
- private void dgV_SimilarParticles_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- var SelectRows = dgV_SimilarParticles.SelectedRows;
- if (SelectRows.Count != 0)
- {
- if (SelectRows.Count == 1)
- {
- DataGridViewRow dgvr = SelectRows[0];
- if ((bool)dgvr.Cells[0].EditedFormattedValue == true)
- {
- dgvr.Cells[0].Value = false;
- }
- else
- {
- dgvr.Cells[0].Value = true;
- }
- dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
- }
- }
- }
- private void dgV_SimilarParticles_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- }
- }
- }
|