| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- using System;
- using System.Collections.Generic;
- 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.ParamData;
- using OTSModelSharp.Measure.OTSInclution;
- using OTSModelSharp.ServiceCenter;
- using OTSModelSharp.ServiceInterface;
- using static OTSDataType.otsdataconst;
- namespace OTSModelSharp
- {
- class CSmplMeasureInclution : CSmplMeasure
- {
-
-
- public CSmplMeasureInclution(string a_strWorkingFolder, COTSSample a_pSample) : base(a_strWorkingFolder, a_pSample)
- {
- SetWorkingFolder(a_strWorkingFolder);
- SetSample(a_pSample);
- m_classifyEngine = new CClassifyEngine();
- }
- // field image process
- public override bool FieldImageProcess(Point fldCenter, CBSEImgClr a_pBSEImg)
- {
- int nNewFieldId;
- nNewFieldId = m_pSampleRstFile.GetIdForANewField();
- // create a field
- curFldData = new CFieldDataIncA(a_pBSEImg, m_Sample.CalculatePixelSize());
- curFldData.SetId(nNewFieldId);
- curFldData.SetOTSPosition(fldCenter);
- CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- Point semPos = new Point();
- a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter,ref semPos);
- curFldData.SemPos = 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();
-
- // second step :filter the finded particles.
- log.Info("Begin to filter particles!");
- InitFieldParticles();
- CalculateParticleAbsolutPos();
- log.Info("Begin to Calculate the image property of every particle!");
- var analysisparts = curFldData.GetListAnalysisParticles();
- curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc.
- COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
- if (pXRayParam.GetUsingXray() == true)
- {
- Thread.Sleep(100);
- CollectParticlesXrayData();
-
- Thread.Sleep(100);
- }
-
- log.Info("Begin to classify particles! particle num:"+ curFldData.GetListAnalysisParticles().Count);
- ClassifyFieldParticles();
-
- // save field files
- m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
- StartSaveFileThread(curFldData);
- return true;
- }
- // save field data
-
- public void InitFieldParticles()
- {
-
- // get pixel size
- double dPixelSize = m_Sample.CalculatePixelSize();
-
- CSampleParam pMsrParam = m_Sample.GetMsrParams();
- COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
- curFldData.InitParticles(pImgProcessParam,dPixelSize);
- // make sure the particles list is not empty
- if (curFldData.NoAnalysisParticle())
- {
- log.Info("There's no particles to be analysed!");
- //return false;
- }
- return ;
- }
- //calculate the real sem position of the particle
- //public void CalculateParticlePos(List<COTSParticleClr> xrayParticles)
- //{
- // double dPixelSize = m_Sample.CalculatePixelSize();
- // CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
- // foreach (var p in xrayParticles)
- // {
-
- // Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);//take the field position as the particle's position instead
- // Point semPos = new Point();
- // pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
- // p.SetAbsolutPos(semPos);
- // }
- //}
- public void CollectParticlesXrayData()
- {
- // get x-ray parameters
- COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
-
- var listXrayAnalysisparts = curFldData.GetListXrayParticles();
-
-
- ////=============================================
- curFldData.CreateXrayList(listXrayAnalysisparts);
-
- var xraymode = m_Sample.GetMsrParams().GetXRayParam().GetScanMode();
- // get x-ray list (analysis) by particle features
- uint nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
- var nFastXrayAQTime =(uint) pXRayParam.GetFastXrayTime();
- var quantifyMinSize = pXRayParam.GetFeatureModeMinSize();
- var listXray = listXrayAnalysisparts.OrderByDescending(x => x.GetActualArea()).ToList();
- var listXray1 = new List<COTSParticleClr>();
- if (listXray.Count > pXRayParam.GetXrayLimit())
- {
- for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
- {
- listXray1.Add(listXray[i]);
- }
- }
- else
- {
- listXray1 = listXray;
- }
- List<COTSParticleClr> smallparts = new List<COTSParticleClr>();
- List<COTSParticleClr> bigparts = new List<COTSParticleClr>();
- foreach (var p in listXray1)
- {
- double diameter = Math.Sqrt(p.GetActualArea() / 3.14159) * 2;
- if (diameter >= quantifyMinSize)
- {
- bigparts.Add(p);
- }
- else
- {
- smallparts.Add(p);
- }
-
- }
- if (xraymode == OTS_X_RAY_SCAN_MODE.FeatureMode)
- {
- if (bigparts.Count > 0)
- {
- log.Info("Begin feature mode xray collection for big particles!AQTime:" + nXRayAQTime + " xrayNum:" + bigparts.Count);
- m_EDSHardwareMgr.GetXRayByFeatures(bigparts, nXRayAQTime, true);
- }
-
-
- }
- else
- {
- if (bigparts.Count > 0)
- {
- log.Info("Begin point mode xray collection for big particles!AQTime:" + nXRayAQTime + " xrayNum:" + bigparts.Count);
- // get x-ray list (analysis) by points
- m_EDSHardwareMgr.GetXRayByPoints(bigparts, nXRayAQTime, true);
- }
-
-
- }
- if (smallparts.Count > 0)
- {
- log.Info("Begin point mode xray collection for small particles!AQTime:" + nFastXrayAQTime + " xrayNum:" + smallparts.Count);
- // get x-ray list (analysis) by points
- m_EDSHardwareMgr.GetXRayByPoints(smallparts, nFastXrayAQTime, true);
- }
-
- return ;
- }
-
- public override void ClassifyFieldParticles()
- {
- try
- {
- var curFld = (CFieldDataIncA)curFldData;
- var anylysisparts = curFld.GetListAnalysisParticles();
- int nSize = anylysisparts.Count();
- // go through all analysis particles
- for (int i = 0; i < nSize; ++i)
- {
- string libname = m_Sample.GetMsrParams().GetSTDName();
- ClassifyIncAParticle(anylysisparts[i], libname);
- }
-
-
- }
- catch (Exception e)
- {
- log.Info(" classify failed. " + e.Message);
- }
-
- }
- public override void ClassifyMergedParticles(List<COTSParticleClr> mergedParts)
- {
- try
- {
-
- var quantifyparts = mergedParts;
- int nSize = quantifyparts.Count();
- // go through all analysis particles
- for (int i = 0; i < nSize; ++i)
- {
- string libname = m_Sample.GetMsrParams().GetSTDName();
- ClassifyIncAParticle(quantifyparts[i], libname);
- }
- }
- catch (Exception e)
- {
- log.Info("merged parts classify failed. " + e.Message);
- }
- }
- public bool ClassifyIncAParticle(COTSParticleClr particle, string libname)// classify particles
- {
- int steelTech = (int)m_Sample.GetMsrParams().GetSteelTechnology();
- particle.SetType((int)OTS_PARTCLE_TYPE.NOT_IDENTIFIED);
- if (m_Sample.IfUsingSysSTD())
- {
- if (libname != "NoSTDDB")
- {
- //var m_classifyEngine = new CClassifyEngine();
- IClassifyEngine engine = m_classifyEngine.GetParticleEngine(libname);
- engine.Classify(particle);
- }
- if (particle.GetType() ==(int) OTS_PARTCLE_TYPE.NOT_IDENTIFIED)
- {
- IClassifyEngine engine;
- engine = m_classifyEngine.GetIncClassifyEngine();
- engine.ClassifyIncA(particle, steelTech);
- }
- }
- else
- {
- if (libname != "NoSTDDB")
- {
- //var m_classifyEngine = new CClassifyEngine();
- IClassifyEngine engine = m_classifyEngine.GetParticleEngine(libname);
- engine.Classify(particle);
- }
- }
-
- return true;
- }
-
- public void GetOriginalParticles()
- {
- // measure status
- CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
- // get image process parameter
- CSampleParam pMsrParam = m_Sample.GetMsrParams();
- COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
- var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
- var pixelsize = m_Sample.CalculatePixelSize();
- if (specialPartsparam.IsToRun)
- {
- List<CSpecialGrayRange> ranges = pMsrParam.GetSpecialGrayRangeParam().GetIntRanges();
- foreach (var grayRange in ranges)
- {
- CIntRangeClr range = new CIntRangeClr(grayRange.range.GetStart(), grayRange.range.GetEnd());
- CIntRangeClr diaRange = new CIntRangeClr(grayRange.diameterRange.GetStart(), grayRange.diameterRange.GetEnd());
- curFldData.GetPartsBySpecialGray(range, diaRange,pixelsize,grayRange.ifCollectXray);
- }
- }
- // remove BES image background
- curFldData.RemoveImgBGAndGetParticles(pImgProcessParam, pixelsize);
-
-
- // check if this is an empty image
- if (curFldData.NoParticle())
- { // empty fields
- log.Info("ImageProcess: empty field.");
-
- }
- return ;
- }
-
- }
- }
|