|
|
@@ -0,0 +1,237 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Data.SQLite;
|
|
|
+using System.Drawing;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using OTSCLRINTERFACE;
|
|
|
+using OTSDataType;
|
|
|
+using OTSMeasureApp._0_OTSModel.Measure._5_OTSMining;
|
|
|
+using OTSModelSharp.Measure;
|
|
|
+using OTSModelSharp.Measure.OTSCleanliness;
|
|
|
+using OTSModelSharp.ServiceCenter;
|
|
|
+using OTSModelSharp.ServiceCenter;
|
|
|
+using static OTSDataType.otsdataconst;
|
|
|
+
|
|
|
+namespace OTSModelSharp
|
|
|
+{
|
|
|
+ class CSmplMeasureMining : CSmplMeasure
|
|
|
+ {
|
|
|
+
|
|
|
+ public CSmplMeasureMining(string a_strWorkingFolder, COTSSample a_pSample) : base(a_strWorkingFolder, a_pSample)
|
|
|
+ {
|
|
|
+ SetWorkingFolder(a_strWorkingFolder);
|
|
|
+ SetSample(a_pSample);
|
|
|
+ m_classifyEngine = new CClassifyEngine();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public override bool FieldImageProcess(COTSFieldData curFldData, CBSEImgClr a_pBSEImg)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ PointF fldCenter = curFldData.OTSPos;
|
|
|
+
|
|
|
+ curFldData.SetBSEImage(a_pBSEImg);
|
|
|
+ CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
|
|
|
+ PointF semPos = new Point();
|
|
|
+ a_pCSEMStageData.ConvertOTSToSEMCoord(fldCenter, ref semPos);
|
|
|
+
|
|
|
+ curFldData.SetSemPos(semPos);
|
|
|
+
|
|
|
+ //first step:remove background of the bse image and compound all the finded particles.
|
|
|
+
|
|
|
+ log.Info("Begin to process image and get all particles!");
|
|
|
+ GetOriginalParticles(ref curFldData);
|
|
|
+
|
|
|
+ // second step :filter the finded particles.
|
|
|
+ log.Info("Begin to filter particles!");
|
|
|
+
|
|
|
+ FilterParticles(ref curFldData);
|
|
|
+
|
|
|
+ CalculateParticleAbsolutPos(ref curFldData);
|
|
|
+
|
|
|
+ log.Info("Begin to Calculate the image property of every particle!");
|
|
|
+ var analysisparts = curFldData.GetListAnalysisParticles();
|
|
|
+ //calculate particle image property such as feret diameter, DMAX etc and calculate the xray point position simultaneously.
|
|
|
+ COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
|
|
|
+
|
|
|
+ var xrayStep = pXRayParam.XrayStep;
|
|
|
+ if (xrayStep == 0)
|
|
|
+ {
|
|
|
+ log.Error("XrayStep=0,is not been set!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ CImageHandler imgHandle = new CImageHandler();
|
|
|
+ foreach (var p in analysisparts)
|
|
|
+ {
|
|
|
+ imgHandle.SplitRawParticleIntoMatrixParticleByXrayStep(p, m_Sample.CalculatePixelSize(), xrayStep);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (pXRayParam.GetUsingXray() == true)
|
|
|
+ {
|
|
|
+ log.Info("Begin to collect particle's xray data!");
|
|
|
+ Thread.Sleep(100);
|
|
|
+
|
|
|
+ m_EDSHardwareMgr.SetResolution(a_pBSEImg.GetWidth(), a_pBSEImg.GetHeight());
|
|
|
+
|
|
|
+ CollectParticlesXrayData(curFldData);
|
|
|
+
|
|
|
+ Thread.Sleep(100);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ log.Info("Begin to classify particles! particle num:" + curFldData.GetListAnalysisParticles().Count);
|
|
|
+ ClassifyFieldParticles(curFldData);
|
|
|
+
|
|
|
+ MergeSubParticleByTheXrayClassification(curFldData);
|
|
|
+
|
|
|
+ //curFldData.CalParticleImageProp(curFldData.GetListAnalysisParticles(), 0);//recalculate the image property of the new merged particles.
|
|
|
+
|
|
|
+ m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+ public override void CollectParticlesXrayData(COTSFieldData curFldData)
|
|
|
+ {
|
|
|
+ // get x-ray parameters
|
|
|
+ COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
|
|
|
+
|
|
|
+ // calculate search x-ray acquire time
|
|
|
+ uint nXRayAQTime;
|
|
|
+ List<COTSParticleClr> parts = new List<COTSParticleClr>();
|
|
|
+
|
|
|
+ foreach (var p in curFldData.GetListAnalysisParticles())
|
|
|
+ {
|
|
|
+ if (p.IsXrayParticle())
|
|
|
+ {
|
|
|
+ parts.Add(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (parts.Count > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
|
|
|
+ m_EDSHardwareMgr.GetXRayByMatrix(parts, nXRayAQTime);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public override void ClassifyFieldParticles(COTSFieldData curFldData)
|
|
|
+ {
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ string libname = m_Sample.GetMsrParams().GetSTDName();
|
|
|
+ if (libname != "NoSTDDB")
|
|
|
+ {
|
|
|
+ log.Info("Begin to classify particles!Using " + libname);
|
|
|
+
|
|
|
+ var parts = curFldData.GetListAnalysisParticles();
|
|
|
+
|
|
|
+ foreach (var p in parts)
|
|
|
+ {
|
|
|
+ ClassifyParticlesBySpectrum(p.GetSubParticles(), libname);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.Info("calcu the particle image property or classify failed. "+e.Message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void MergeSubParticleByTheXrayClassification(COTSFieldData curFldData)
|
|
|
+ {
|
|
|
+ var rawParts = curFldData.GetListAnalysisParticles();
|
|
|
+ Dictionary<int, List<COTSParticleClr>> dicParts = new Dictionary<int, List<COTSParticleClr>>();
|
|
|
+ foreach (var rawPart in rawParts)
|
|
|
+ {
|
|
|
+ foreach (var matricsPart in rawPart.GetSubParticles())
|
|
|
+ {
|
|
|
+ if (!dicParts.ContainsKey(matricsPart.GetType()))
|
|
|
+ {
|
|
|
+ dicParts.Add(matricsPart.GetType(), new List<COTSParticleClr>() { matricsPart });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dicParts[matricsPart.GetType()].Add(matricsPart);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var finalParts = new List<COTSParticleClr>();
|
|
|
+ foreach (var typeParts in dicParts)
|
|
|
+ {
|
|
|
+ var firstPart = typeParts.Value[0];
|
|
|
+ if (typeParts.Value.Count > 0)
|
|
|
+ {
|
|
|
+ var segs = new List<COTSSegmentClr>();
|
|
|
+ segs = firstPart.GetFeature().GetSegmentsList();
|
|
|
+ for (int i = 1; i < typeParts.Value.Count; i++)
|
|
|
+ {
|
|
|
+ segs.AddRange(typeParts.Value[i].GetFeature().GetSegmentsList());
|
|
|
+ }
|
|
|
+ firstPart.GetFeature().SetSegmentsList(segs,false);
|
|
|
+ }
|
|
|
+ finalParts.Add(firstPart);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ curFldData.SetListAnalysisParticles(finalParts);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public bool ClassifyParticlesBySpectrum(List<COTSParticleClr> matricsParts, string libname)
|
|
|
+ {
|
|
|
+ List<COTSParticleClr> a_listAnalysisParticles = matricsParts;
|
|
|
+
|
|
|
+ int nSize = (int)a_listAnalysisParticles.Count();
|
|
|
+
|
|
|
+ // go through all analysis particles
|
|
|
+ for (int i = 0; i < nSize; ++i)
|
|
|
+ {
|
|
|
+ var pParticle = a_listAnalysisParticles[i];
|
|
|
+
|
|
|
+ IClassifyEngine engine = m_classifyEngine.GetCurveCompareEngine(libname);
|
|
|
+
|
|
|
+ if (!engine.Classify(pParticle))
|
|
|
+ {
|
|
|
+ log.Info("ClassifyParticle: can't identify the particle as any inclusion.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|