COTSFieldData.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Drawing;
  8. using OTSModelSharp.ImageProcess;
  9. using OTSModelSharp.ServiceInterface;
  10. using OTSDataType;
  11. using OTSCLRINTERFACE;
  12. namespace OTSModelSharp
  13. {
  14. using COTSFieldDataList = List<COTSFieldData>;
  15. public class COTSFieldData
  16. {
  17. protected NLog.Logger log ;
  18. // ID
  19. int m_nID;
  20. // position (from field center manager)
  21. protected System.Drawing.Point m_otsPos ;
  22. protected CBSEImgClr m_pBSEImg;
  23. protected double m_pixelSize;
  24. IImageProcess m_ImagePro;
  25. protected List<COTSParticleClr> m_listAllParticles = new List<COTSParticleClr>();//hold up all the particles abstracted from bse image;
  26. protected List<COTSParticleClr> m_listAnalysisParticles = new List<COTSParticleClr>();// according to the size (the diameter) constraint,pick out all the conforming particles.
  27. protected List<COTSParticleClr> m_listXrayParticles = new List<COTSParticleClr>();//hold up all the particles that need the xray data.
  28. protected List<COTSParticleClr> m_listBigParticles = new List<COTSParticleClr>();
  29. protected List<COTSParticleClr> m_listSmallParticles = new List<COTSParticleClr>();
  30. public List<COTSParticleClr> ListSmallParticles { get => m_listSmallParticles; set => m_listSmallParticles = value; }
  31. public List<COTSParticleClr> ListBigParticles { get => m_listBigParticles; set => m_listBigParticles = value; }
  32. private int height;
  33. private int width;
  34. public int Height { get => height; set => height = value; }
  35. public int Width { get => width; set => width = value; }
  36. public System.Drawing.Point OTSPos { get => m_otsPos; set => m_otsPos = value; }
  37. public bool GetIsMeasureComplete()
  38. {
  39. return isMeasureComplete;
  40. }
  41. public void SetIsMeasureComplete(bool value)
  42. {
  43. isMeasureComplete = value;
  44. }
  45. private bool isMeasureComplete;
  46. public Point GetSemPos()
  47. {
  48. return m_semPos;
  49. }
  50. public void SetSemPos(Point value)
  51. {
  52. m_semPos = value;
  53. }
  54. private Point m_semPos;
  55. public List<COTSParticleClr> GetAllParticles()
  56. {
  57. return m_listAllParticles;
  58. }
  59. public List<COTSParticleClr> GetListAnalysisParticles()
  60. {
  61. return m_listAnalysisParticles;
  62. }
  63. public List<COTSParticleClr> GetListXrayParticles()
  64. {
  65. m_listXrayParticles.Clear();
  66. foreach (var p in m_listAnalysisParticles)
  67. {
  68. if (p.IsXrayParticle())
  69. {
  70. m_listXrayParticles.Add(p);
  71. }
  72. }
  73. return m_listXrayParticles;
  74. }
  75. public void SetListAnalysisParticles(List<COTSParticleClr> value)
  76. {
  77. m_listAnalysisParticles = value;
  78. }
  79. public COTSFieldData(Point centerPoint, double a_dPixelSize)
  80. {
  81. log = NLog.LogManager.GetCurrentClassLogger();
  82. Init();
  83. //m_pBSEImg = a_pBSEImg;
  84. m_otsPos = centerPoint;
  85. m_pixelSize = a_dPixelSize;
  86. }
  87. public double GetPixelSize()
  88. {
  89. return m_pixelSize;
  90. }
  91. public COTSFieldData()
  92. {
  93. log = NLog.LogManager.GetCurrentClassLogger();
  94. Init();
  95. }
  96. // initialization
  97. void Init()
  98. {
  99. // initialization
  100. m_nID = -1;
  101. OTSPos =new System.Drawing.Point(0, 0);
  102. m_listAllParticles.Clear();
  103. }
  104. public void CCOTSFieldData(COTSFieldData a_oSource)
  105. {
  106. // can't copy itself
  107. if (a_oSource == this)
  108. {
  109. return;
  110. }
  111. Duplicate(a_oSource);
  112. }
  113. public COTSFieldData(COTSFieldData a_poSource)
  114. {
  115. // can't copy itself
  116. if (a_poSource == this)
  117. {
  118. return;
  119. }
  120. Duplicate(a_poSource);
  121. }
  122. public CBSEImgClr GetBSEImage()
  123. {
  124. return m_pBSEImg;
  125. }
  126. public void SetBSEImage(CBSEImgClr a_pBSEImg)
  127. {
  128. if (a_pBSEImg == null)
  129. {
  130. // invalid BSE image.
  131. log.Error("SetBSEImage: invalid BSE image.");
  132. return;
  133. }
  134. m_pBSEImg = a_pBSEImg;
  135. width = a_pBSEImg.GetWidth();
  136. height = a_pBSEImg.GetHeight();
  137. }
  138. public void RemoveImgBGAndGetParticles(COTSImageProcParam a_pImageProcessParam,double a_pixelSize,bool ifXray)
  139. {
  140. if (m_pBSEImg == null)
  141. return;
  142. CImageHandler imghandler = new CImageHandler();
  143. List<COTSParticleClr> xrayParts = new List<COTSParticleClr>();
  144. imghandler.RemoveBGAndGetParts(m_pBSEImg, a_pImageProcessParam,a_pixelSize, ref xrayParts);
  145. foreach (var p in xrayParts)
  146. {
  147. p.SetIsXrayParticle(ifXray);
  148. m_listAllParticles.Add(p);
  149. }
  150. return ;
  151. }
  152. public void GetPartsBySpecialGray(CIntRangeClr grayRange, CDoubleRangeClr diameterRange,double pixelSize, bool ifXray)
  153. {
  154. if (m_pBSEImg == null)
  155. return;
  156. CImageHandler imghandler = new CImageHandler();
  157. List<COTSParticleClr> specialParts = new List<COTSParticleClr>();
  158. imghandler.GetParticlesBySpecialGray(m_pBSEImg, grayRange,diameterRange,pixelSize, ref specialParts);
  159. foreach (var p in specialParts)
  160. {
  161. p.SetIsXrayParticle(ifXray);
  162. m_listAllParticles.Add(p);
  163. }
  164. return;
  165. }
  166. public bool CalParticleImageProp(List<COTSParticleClr> particles)
  167. {
  168. m_ImagePro = new CImageHandler();
  169. foreach (COTSParticleClr part in particles)
  170. {
  171. m_ImagePro.CalParticleImageProp( part, m_pixelSize);
  172. }
  173. return true;
  174. }
  175. public void InitParticles(COTSImageProcParam a_pImageProcessParam,double a_dPixelSize)
  176. {
  177. m_listAnalysisParticles = new List<COTSParticleClr>();
  178. // get area range
  179. CDoubleRange oAreaRange = a_pImageProcessParam.GetIncAreaRange();
  180. double rMin = oAreaRange.GetStart() / 2.0;
  181. double rMax = oAreaRange.GetEnd() / 2.0;
  182. //double dAreaLow = rMin * rMin * 3.14159;
  183. //double dAreaHigh = rMax * rMax * 3.14159;
  184. int nTagId = 0;
  185. //int nAnalysisPartId = 0;
  186. //int tooSmallnum = 0;
  187. //int overSizenum = 0;
  188. //log.Info("Total Particles: " + m_listAllParticles.Count);
  189. foreach (COTSParticleClr pParticle in m_listAllParticles)//m_listAllParticles memorize all the particles .
  190. {
  191. pParticle.SetTagId(nTagId);//give all the conforming particles a unified sequence no.
  192. pParticle.SetFieldId(GetId());
  193. pParticle.SetType((int)otsdataconst.OTS_PARTCLE_TYPE.NO_ANALYSIS_X_RAY);
  194. pParticle.SetTypeName("Not Identified");
  195. pParticle.SetAnalysisId(nTagId); // the same as the tagId no use now.
  196. nTagId++;
  197. }
  198. log.Info("Total Particles: (>" + oAreaRange.GetStart().ToString("f2") + "): "+ "<" + oAreaRange.GetEnd().ToString("f2") + "): " + m_listAllParticles.Count);
  199. }
  200. public bool CreateXrayList(List<COTSParticleClr> a_listParticles)
  201. {
  202. ;
  203. foreach (COTSParticleClr pPart in a_listParticles)
  204. {
  205. System.Drawing.Point poi = (System.Drawing.Point)pPart.GetXRayPos();
  206. CPosXrayClr pPosXray = new CPosXrayClr();
  207. pPosXray.SetPosition(poi);
  208. pPosXray.SetPartTagId(pPart.GetTagId());
  209. pPosXray.SetIndex(pPart.GetAnalysisId());
  210. pPosXray.SetScanFieldId(pPart.GetFieldId());
  211. pPart.SetXray(pPosXray);
  212. }
  213. return true;
  214. }
  215. public bool NoParticle()
  216. {
  217. if (m_listAllParticles.Count == 0)
  218. {
  219. return true;
  220. }
  221. else
  222. {
  223. return false;
  224. }
  225. }
  226. public bool NoAnalysisParticle()
  227. {
  228. if (m_listAllParticles.Count == 0)
  229. {
  230. return true;
  231. }
  232. else
  233. {
  234. return false;
  235. }
  236. }
  237. public bool Equals(COTSFieldData a_oSource) // CBSEImg& operator=(const CBSEImg&); // =operator
  238. {
  239. int nSize = m_listAllParticles.Count;
  240. if (nSize != a_oSource.m_listAllParticles.Count)
  241. {
  242. return false;
  243. }
  244. for (int i = 0; i < nSize; ++i)
  245. {
  246. if (!m_listAllParticles[i] .Equals( a_oSource.m_listAllParticles[i]))
  247. {
  248. return false;
  249. }
  250. }
  251. return m_nID == a_oSource.m_nID &&
  252. OTSPos == a_oSource.OTSPos;
  253. }
  254. // destructor
  255. // ID
  256. public int GetId()
  257. {
  258. return m_nID;
  259. }
  260. public void SetId(int a_nID)
  261. {
  262. m_nID = a_nID;
  263. }
  264. // position (from field center manager)
  265. public System.Drawing.Point GetOTSPosition()
  266. {
  267. return m_otsPos;
  268. }
  269. public void SetOTSPosition(System.Drawing.Point a_poiPos)
  270. {
  271. m_otsPos = a_poiPos;
  272. }
  273. public List<COTSParticleClr> GetTopBorderedParticles()
  274. {
  275. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  276. foreach (var p in m_listAllParticles)
  277. {
  278. var segs = p.GetFeature().GetSegmentsList();//COTSSegment
  279. foreach (var seg in segs)
  280. {
  281. if (seg.GetHeight() == 0)
  282. {
  283. parts.Add(p);
  284. break;
  285. }
  286. }
  287. }
  288. return parts;
  289. }
  290. public List< COTSParticleClr > GetBottomBorderedParticles()
  291. {
  292. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  293. foreach (var p in m_listAllParticles)
  294. {
  295. var segs = p.GetFeature().GetSegmentsList();
  296. foreach (var seg in segs)
  297. {
  298. if (seg.GetHeight() == this.Height - 1)//the lowest height is 767(height-1),cause starting from 0.
  299. {
  300. parts.Add(p);
  301. break;
  302. }
  303. }
  304. }
  305. return parts;
  306. }
  307. public List<COTSParticleClr> GetLeftBorderedParticles()
  308. {
  309. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  310. foreach (var p in m_listAllParticles)
  311. {
  312. var segs = p.GetFeature().GetSegmentsList();
  313. foreach (var seg in segs)
  314. {
  315. if (seg.GetStart() == 0)
  316. {
  317. parts.Add(p);
  318. break;
  319. }
  320. }
  321. }
  322. return parts;
  323. }
  324. public List <COTSParticleClr> GetRightBorderedParticles()
  325. {
  326. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  327. foreach (var p in m_listAllParticles)
  328. {
  329. var segs = p.GetFeature().GetSegmentsList();
  330. foreach (var seg in segs)
  331. {
  332. if (seg.GetStart() + seg.GetLength() == this.Width)
  333. {
  334. parts.Add(p);
  335. break;
  336. }
  337. }
  338. }
  339. return parts;
  340. }
  341. // is empty
  342. public bool IsEmpty()
  343. {
  344. return m_listAllParticles.Count == 0;
  345. }
  346. void Duplicate( COTSFieldData a_oSource)
  347. {
  348. m_nID = a_oSource.m_nID;
  349. OTSPos = a_oSource.OTSPos;
  350. //m_strFieldFileFolder = a_oSource.m_strFieldFileFolder;
  351. // copy data over
  352. foreach(var pParticle in a_oSource.m_listAllParticles)
  353. {
  354. m_listAllParticles.Add(pParticle);
  355. }
  356. }
  357. }
  358. }