SmplMeasureInclution.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using OTSCLRINTERFACE;
  9. using OTSDataType;
  10. using OTSMeasureApp._0_OTSModel.Measure.ParamData;
  11. using OTSModelSharp.Measure.OTSInclution;
  12. using OTSModelSharp.ServiceCenter;
  13. using OTSModelSharp.ServiceInterface;
  14. using static OTSDataType.otsdataconst;
  15. namespace OTSModelSharp
  16. {
  17. class CSmplMeasureInclution : CSmplMeasure
  18. {
  19. public CSmplMeasureInclution(string a_strWorkingFolder, COTSSample a_pSample) : base(a_strWorkingFolder, a_pSample)
  20. {
  21. SetWorkingFolder(a_strWorkingFolder);
  22. SetSample(a_pSample);
  23. m_classifyEngine = new CClassifyEngine();
  24. }
  25. // field image process
  26. public override bool FieldImageProcess(Point fldCenter, CBSEImgClr a_pBSEImg)
  27. {
  28. int nNewFieldId;
  29. nNewFieldId = m_pSampleRstFile.GetIdForANewField();
  30. // create a field
  31. curFldData = new CFieldDataIncA(a_pBSEImg, m_Sample.CalculatePixelSize());
  32. curFldData.SetId(nNewFieldId);
  33. curFldData.SetOTSPosition(fldCenter);
  34. CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  35. Point semPos = new Point();
  36. a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter,ref semPos);
  37. curFldData.SemPos = semPos;
  38. //first step:remove background of the bse image and compound all the finded particles.
  39. log.Info("Begin to process image and get all particles!");
  40. GetOriginalParticles();
  41. // second step :filter the finded particles.
  42. log.Info("Begin to filter particles!");
  43. InitFieldParticles();
  44. CalculateParticleAbsolutPos();
  45. log.Info("Begin to Calculate the image property of every particle!");
  46. var analysisparts = curFldData.GetListAnalysisParticles();
  47. curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc.
  48. COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
  49. if (pXRayParam.GetUsingXray() == true)
  50. {
  51. Thread.Sleep(100);
  52. CollectParticlesXrayData();
  53. Thread.Sleep(100);
  54. }
  55. log.Info("Begin to classify particles! particle num:"+ curFldData.GetListAnalysisParticles().Count);
  56. ClassifyFieldParticles();
  57. // save field files
  58. m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
  59. StartSaveFileThread(curFldData);
  60. return true;
  61. }
  62. // save field data
  63. public void InitFieldParticles()
  64. {
  65. // get pixel size
  66. double dPixelSize = m_Sample.CalculatePixelSize();
  67. CSampleParam pMsrParam = m_Sample.GetMsrParams();
  68. COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
  69. curFldData.InitParticles(pImgProcessParam,dPixelSize);
  70. // make sure the particles list is not empty
  71. if (curFldData.NoAnalysisParticle())
  72. {
  73. log.Info("There's no particles to be analysed!");
  74. //return false;
  75. }
  76. return ;
  77. }
  78. //calculate the real sem position of the particle
  79. //public void CalculateParticlePos(List<COTSParticleClr> xrayParticles)
  80. //{
  81. // double dPixelSize = m_Sample.CalculatePixelSize();
  82. // CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
  83. // foreach (var p in xrayParticles)
  84. // {
  85. // Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);//take the field position as the particle's position instead
  86. // Point semPos = new Point();
  87. // pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
  88. // p.SetAbsolutPos(semPos);
  89. // }
  90. //}
  91. public void CollectParticlesXrayData()
  92. {
  93. // get x-ray parameters
  94. COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
  95. var listXrayAnalysisparts = curFldData.GetListXrayParticles();
  96. ////=============================================
  97. curFldData.CreateXrayList(listXrayAnalysisparts);
  98. var xraymode = m_Sample.GetMsrParams().GetXRayParam().GetScanMode();
  99. // get x-ray list (analysis) by particle features
  100. uint nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
  101. var nFastXrayAQTime =(uint) pXRayParam.GetFastXrayTime();
  102. var quantifyMinSize = pXRayParam.GetFeatureModeMinSize();
  103. var listXray = listXrayAnalysisparts.OrderByDescending(x => x.GetActualArea()).ToList();
  104. var listXray1 = new List<COTSParticleClr>();
  105. if (listXray.Count > pXRayParam.GetXrayLimit())
  106. {
  107. for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
  108. {
  109. listXray1.Add(listXray[i]);
  110. }
  111. }
  112. else
  113. {
  114. listXray1 = listXray;
  115. }
  116. List<COTSParticleClr> smallparts = new List<COTSParticleClr>();
  117. List<COTSParticleClr> bigparts = new List<COTSParticleClr>();
  118. foreach (var p in listXray1)
  119. {
  120. double diameter = Math.Sqrt(p.GetActualArea() / 3.14159) * 2;
  121. if (diameter >= quantifyMinSize)
  122. {
  123. bigparts.Add(p);
  124. }
  125. else
  126. {
  127. smallparts.Add(p);
  128. }
  129. }
  130. if (xraymode == OTS_X_RAY_SCAN_MODE.FeatureMode)
  131. {
  132. if (bigparts.Count > 0)
  133. {
  134. log.Info("Begin feature mode xray collection for big particles!AQTime:" + nXRayAQTime + " xrayNum:" + bigparts.Count);
  135. m_EDSHardwareMgr.GetXRayByFeatures(bigparts, nXRayAQTime, true);
  136. }
  137. }
  138. else
  139. {
  140. if (bigparts.Count > 0)
  141. {
  142. log.Info("Begin point mode xray collection for big particles!AQTime:" + nXRayAQTime + " xrayNum:" + bigparts.Count);
  143. // get x-ray list (analysis) by points
  144. m_EDSHardwareMgr.GetXRayByPoints(bigparts, nXRayAQTime, true);
  145. }
  146. }
  147. if (smallparts.Count > 0)
  148. {
  149. log.Info("Begin point mode xray collection for small particles!AQTime:" + nFastXrayAQTime + " xrayNum:" + smallparts.Count);
  150. // get x-ray list (analysis) by points
  151. m_EDSHardwareMgr.GetXRayByPoints(smallparts, nFastXrayAQTime, true);
  152. }
  153. return ;
  154. }
  155. public override void ClassifyFieldParticles()
  156. {
  157. try
  158. {
  159. var curFld = (CFieldDataIncA)curFldData;
  160. var anylysisparts = curFld.GetListAnalysisParticles();
  161. int nSize = anylysisparts.Count();
  162. // go through all analysis particles
  163. for (int i = 0; i < nSize; ++i)
  164. {
  165. string libname = m_Sample.GetMsrParams().GetSTDName();
  166. ClassifyIncAParticle(anylysisparts[i], libname);
  167. }
  168. }
  169. catch (Exception e)
  170. {
  171. log.Info(" classify failed. " + e.Message);
  172. }
  173. }
  174. public override void ClassifyMergedParticles(List<COTSParticleClr> mergedParts)
  175. {
  176. try
  177. {
  178. var quantifyparts = mergedParts;
  179. int nSize = quantifyparts.Count();
  180. // go through all analysis particles
  181. for (int i = 0; i < nSize; ++i)
  182. {
  183. string libname = m_Sample.GetMsrParams().GetSTDName();
  184. ClassifyIncAParticle(quantifyparts[i], libname);
  185. }
  186. }
  187. catch (Exception e)
  188. {
  189. log.Info("merged parts classify failed. " + e.Message);
  190. }
  191. }
  192. public bool ClassifyIncAParticle(COTSParticleClr particle, string libname)// classify particles
  193. {
  194. int steelTech = (int)m_Sample.GetMsrParams().GetSteelTechnology();
  195. particle.SetType((int)OTS_PARTCLE_TYPE.NOT_IDENTIFIED);
  196. if (m_Sample.IfUsingSysSTD())
  197. {
  198. if (libname != "NoSTDDB")
  199. {
  200. //var m_classifyEngine = new CClassifyEngine();
  201. IClassifyEngine engine = m_classifyEngine.GetParticleEngine(libname);
  202. engine.Classify(particle);
  203. }
  204. if (particle.GetType() ==(int) OTS_PARTCLE_TYPE.NOT_IDENTIFIED)
  205. {
  206. IClassifyEngine engine;
  207. engine = m_classifyEngine.GetIncClassifyEngine();
  208. engine.ClassifyIncA(particle, steelTech);
  209. }
  210. }
  211. else
  212. {
  213. if (libname != "NoSTDDB")
  214. {
  215. //var m_classifyEngine = new CClassifyEngine();
  216. IClassifyEngine engine = m_classifyEngine.GetParticleEngine(libname);
  217. engine.Classify(particle);
  218. }
  219. }
  220. return true;
  221. }
  222. public void GetOriginalParticles()
  223. {
  224. // measure status
  225. CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
  226. // get image process parameter
  227. CSampleParam pMsrParam = m_Sample.GetMsrParams();
  228. COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
  229. var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
  230. var pixelsize = m_Sample.CalculatePixelSize();
  231. if (specialPartsparam.IsToRun)
  232. {
  233. List<CSpecialGrayRange> ranges = pMsrParam.GetSpecialGrayRangeParam().GetIntRanges();
  234. foreach (var grayRange in ranges)
  235. {
  236. CIntRangeClr range = new CIntRangeClr(grayRange.range.GetStart(), grayRange.range.GetEnd());
  237. CIntRangeClr diaRange = new CIntRangeClr(grayRange.diameterRange.GetStart(), grayRange.diameterRange.GetEnd());
  238. curFldData.GetPartsBySpecialGray(range, diaRange,pixelsize,grayRange.ifCollectXray);
  239. }
  240. }
  241. // remove BES image background
  242. curFldData.RemoveImgBGAndGetParticles(pImgProcessParam, pixelsize);
  243. // check if this is an empty image
  244. if (curFldData.NoParticle())
  245. { // empty fields
  246. log.Info("ImageProcess: empty field.");
  247. }
  248. return ;
  249. }
  250. }
  251. }