COTSField.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. using OTSCLRINTERFACE;
  2. using OTSMeasureApp._0_OTSModel.OTSDataType;
  3. using OTSModelSharp;
  4. using OTSModelSharp.ServiceCenter;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Xml;
  9. namespace OTSDataType
  10. {
  11. public class COTSField : ISlo
  12. {
  13. public COTSField leftField = null;
  14. public COTSField upField = null;
  15. public COTSField downField = null;
  16. public COTSField rightField = null;
  17. protected NLog.Logger log;
  18. // ID
  19. int m_nID;
  20. int measureSequence;
  21. // position (from field center manager)
  22. protected System.Drawing.PointF m_otsPos;
  23. protected CBSEImgClr m_pBSEImg;
  24. protected double m_pixelSize;
  25. protected CImageHandler m_ImagePro;
  26. protected List<COTSParticleClr> m_listAllParticles = new List<COTSParticleClr>();//hold up all the particles abstracted from bse image;
  27. protected List<COTSParticleClr> m_listAnalysisParticles = new List<COTSParticleClr>();// according to xraylimit constraint,pick out the first big particles.
  28. protected List<COTSParticleClr> m_listXrayParticles = new List<COTSParticleClr>();//hold up all the particles that needing the xray data.
  29. private int imgheight;
  30. private int imgwidth;
  31. private COTSRect m_otsRect;
  32. private COTSSample m_sample;
  33. public COTSField()
  34. {
  35. log = NLog.LogManager.GetCurrentClassLogger();
  36. Init();
  37. }//only using in xmlserialization
  38. public int ImgHeight { get => imgheight; set => imgheight = value; }
  39. public int ImgWidth { get => imgwidth; set => imgwidth = value; }
  40. public COTSSample Sample { get => m_sample; set => m_sample = value; }
  41. internal COTSRect GetOTSRect()
  42. {
  43. return m_otsRect;
  44. }
  45. internal void SetOTSRect(COTSRect value)
  46. {
  47. m_otsRect = value;
  48. }
  49. public int GetMeasureSequence()
  50. {
  51. return measureSequence;
  52. }
  53. public void SetMeasureSequence(int value)
  54. {
  55. measureSequence = value;
  56. }
  57. public List<string> strKeyName;
  58. public bool GetIsMeasureComplete()
  59. {
  60. return isMeasureComplete;
  61. }
  62. public void SetIsMeasureComplete(bool value)
  63. {
  64. isMeasureComplete = value;
  65. }
  66. private bool isMeasureComplete;
  67. public PointF GetSemPos()
  68. {
  69. return m_semPos;
  70. }
  71. public void SetSemPos(PointF value)
  72. {
  73. m_semPos = value;
  74. }
  75. private PointF m_semPos;
  76. public List<COTSParticleClr> GetAllParticles()
  77. {
  78. return m_listAllParticles;
  79. }
  80. public List<COTSParticleClr> GetListAnalysisParticles()
  81. {
  82. return m_listAnalysisParticles;
  83. }
  84. public List<COTSParticleClr> GetListXrayParticles()
  85. {
  86. m_listXrayParticles.Clear();
  87. foreach (var p in m_listAnalysisParticles)
  88. {
  89. if (p.IsXrayParticle())
  90. {
  91. m_listXrayParticles.Add(p);
  92. }
  93. }
  94. return m_listXrayParticles;
  95. }
  96. public void SetListAnalysisParticles(List<COTSParticleClr> value)
  97. {
  98. m_listAnalysisParticles = value;
  99. }
  100. public COTSField(PointF centerPoint, double a_dPixelSize)
  101. {
  102. log = NLog.LogManager.GetCurrentClassLogger();
  103. Init();
  104. //m_pBSEImg = a_pBSEImg;
  105. m_otsPos = centerPoint;
  106. m_pixelSize = a_dPixelSize;
  107. }
  108. public double GetPixelSize()
  109. {
  110. return m_pixelSize;
  111. }
  112. public void SetPixelSize(double size)
  113. {
  114. m_pixelSize = size;
  115. }
  116. // initialization
  117. void Init()
  118. {
  119. // initialization
  120. m_nID = -1;
  121. m_otsPos = new System.Drawing.Point(0, 0);
  122. m_listAllParticles.Clear();
  123. }
  124. public COTSField(COTSField a_poSource)
  125. {
  126. // can't copy itself
  127. if (a_poSource == this)
  128. {
  129. return;
  130. }
  131. Duplicate(a_poSource);
  132. }
  133. public CBSEImgClr GetBSEImage()
  134. {
  135. return m_pBSEImg;
  136. }
  137. public void SetBSEImage(CBSEImgClr a_pBSEImg)
  138. {
  139. if (a_pBSEImg == null)
  140. {
  141. // invalid BSE image.
  142. log.Error("SetBSEImage: invalid BSE image.");
  143. return;
  144. }
  145. m_pBSEImg = a_pBSEImg;
  146. imgwidth = a_pBSEImg.GetWidth();
  147. imgheight = a_pBSEImg.GetHeight();
  148. }
  149. public void RemoveImgBGAndGetParticles(COTSImageProcParam a_pImageProcessParam, double a_pixelSize, bool ifXray)
  150. {
  151. if (m_pBSEImg == null)
  152. return;
  153. CImageHandler imghandler = new CImageHandler();
  154. List<COTSParticleClr> allParts = new List<COTSParticleClr>();
  155. imghandler.RemoveBGAndGetParts(this, a_pImageProcessParam, ref allParts);
  156. foreach (var p in allParts)
  157. {
  158. p.SetIsXrayParticle(ifXray);
  159. m_listAllParticles.Add(p);
  160. }
  161. return;
  162. }
  163. public void RemoveDuplicateOverlapParticles(int overlap)
  164. {
  165. List<COTSParticleClr> finalparts = new List<COTSParticleClr>();
  166. List<COTSParticleClr> duplicateparts = new List<COTSParticleClr>();
  167. //find left side duplicate particles
  168. var leftparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap);
  169. if (leftField != null && leftField.measureSequence < this.measureSequence)
  170. {
  171. var rightsideparts = leftField.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap);
  172. if (leftField.upField != null && leftField.upField.measureSequence < this.measureSequence)//include the left up corner parts
  173. {
  174. var leftupParts = leftField.upField.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap);
  175. rightsideparts.AddRange(leftupParts);
  176. }
  177. if (leftField.downField != null && leftField.downField.measureSequence < this.measureSequence)//include the left down corner parts
  178. {
  179. var leftdownParts = leftField.downField.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap);
  180. rightsideparts.AddRange(leftdownParts);
  181. }
  182. log.Info("left side particles num:" + leftparts.Count.ToString());
  183. foreach (var p in leftparts)
  184. {
  185. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  186. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  187. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  188. PointF pcenter = prec.GetCenterPoint();
  189. foreach (var p1 in rightsideparts)
  190. {
  191. int p1left = 0, p1right = 0, p1top = 0, p1bottom = 0;
  192. p1.GetOTSRect(ref p1left, ref p1top, ref p1right, ref p1bottom);
  193. COTSRect p1rec = new COTSRect(p1left, p1top, p1right, p1bottom);
  194. PointF p1Center = p1rec.GetCenterPoint();
  195. if (Math.Abs(pcenter.X - p1Center.X) < 2 * overlap && Math.Abs(pcenter.Y - p1Center.Y) < 2 * overlap)
  196. {
  197. var sim = p.CalculateSimilarity(p1);
  198. if (sim > 0.95)
  199. {
  200. log.Warn("remove left side duplicate particle,similarity:" + sim.ToString("F3"));
  201. log.Warn("P1:" + p.GetImgPortraitString());
  202. log.Warn("P2:" + p1.GetImgPortraitString());
  203. duplicateparts.Add(p);
  204. break;
  205. }
  206. }
  207. }
  208. }
  209. }
  210. //find up side duplicate particles
  211. var upparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.UP, overlap);
  212. if (upField != null && upField.measureSequence < this.measureSequence)
  213. {
  214. var othersideparts = upField.GetSideParticlesByOverlap(SORTING_DIRECTION.DOWN, overlap);
  215. log.Info("up side particles num:" + upparts.Count.ToString());
  216. foreach (var p in upparts)
  217. {
  218. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  219. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  220. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  221. PointF pcenter = prec.GetCenterPoint();
  222. foreach (var p1 in othersideparts)
  223. {
  224. int p1left = 0, p1right = 0, p1top = 0, p1bottom = 0;
  225. p1.GetOTSRect(ref p1left, ref p1top, ref p1right, ref p1bottom);
  226. COTSRect p1rec = new COTSRect(p1left, p1top, p1right, p1bottom);
  227. PointF p1Center = p1rec.GetCenterPoint();
  228. if (Math.Abs(pcenter.X - p1Center.X) < 2 * overlap && Math.Abs(pcenter.Y - p1Center.Y) < 2 * overlap)
  229. {
  230. var sim = p.CalculateSimilarity(p1);
  231. if (sim > 0.95)
  232. {
  233. log.Warn("remove upside duplicate particle,similarity:" + sim.ToString("F3"));
  234. log.Warn("P1:" + p.GetImgPortraitString());
  235. log.Warn("P2:" + p1.GetImgPortraitString());
  236. duplicateparts.Add(p);
  237. break;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. //find right side duplicate particles
  244. var rightparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap);
  245. if (rightField != null && rightField.measureSequence < this.measureSequence)
  246. {
  247. log.Info("right side particles num:" + rightparts.Count.ToString());
  248. var othersideparts = rightField.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap);
  249. if (rightField.upField != null && rightField.upField.measureSequence < this.measureSequence)// right up corner parts
  250. {
  251. var rightupParts = rightField.upField.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap);
  252. othersideparts.AddRange(rightupParts);
  253. }
  254. if (rightField.downField != null && leftField.downField.measureSequence < this.measureSequence)// rightdown corner parts
  255. {
  256. var rightdownParts = leftField.downField.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap);
  257. othersideparts.AddRange(rightdownParts);
  258. }
  259. foreach (var p in rightparts)
  260. {
  261. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  262. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  263. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  264. PointF pcenter = prec.GetCenterPoint();
  265. foreach (var p1 in othersideparts)
  266. {
  267. int p1left = 0, p1right = 0, p1top = 0, p1bottom = 0;
  268. p1.GetOTSRect(ref p1left, ref p1top, ref p1right, ref p1bottom);
  269. COTSRect p1rec = new COTSRect(p1left, p1top, p1right, p1bottom);
  270. PointF p1Center = p1rec.GetCenterPoint();
  271. if (Math.Abs(pcenter.X - p1Center.X) < 2 * overlap && Math.Abs(pcenter.Y - p1Center.Y) < 2 * overlap)
  272. {
  273. var sim = p.CalculateSimilarity(p1);
  274. if (sim > 0.95)
  275. {
  276. log.Warn("remove right side duplicate particle,similarity:" + sim.ToString("F3"));
  277. log.Warn("P1:" + p.GetImgPortraitString());
  278. log.Warn("P2:" + p1.GetImgPortraitString());
  279. duplicateparts.Add(p);
  280. break;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. //find down side duplicate particles
  287. var downparts = this.GetSideParticlesByOverlap(SORTING_DIRECTION.DOWN, overlap);
  288. if (downField != null && downField.measureSequence < this.measureSequence)
  289. {
  290. log.Info("down side particles num:" + downparts.Count.ToString());
  291. var othersideparts = downField.GetSideParticlesByOverlap(SORTING_DIRECTION.UP, overlap);
  292. foreach (var p in downparts)
  293. {
  294. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  295. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  296. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  297. PointF pcenter = prec.GetCenterPoint();
  298. foreach (var p1 in othersideparts)
  299. {
  300. int p1left = 0, p1right = 0, p1top = 0, p1bottom = 0;
  301. p1.GetOTSRect(ref p1left, ref p1top, ref p1right, ref p1bottom);
  302. COTSRect p1rec = new COTSRect(p1left, p1top, p1right, p1bottom);
  303. PointF p1Center = p1rec.GetCenterPoint();
  304. if (Math.Abs(pcenter.X - p1Center.X) < 2 * overlap && Math.Abs(pcenter.Y - p1Center.Y) < 2 * overlap)
  305. {
  306. var sim = p.CalculateSimilarity(p1);
  307. if (sim > 0.95)
  308. {
  309. log.Warn("remove down side duplicate particle,similarity:" + sim.ToString("F3"));
  310. log.Warn("P1:" + p.GetImgPortraitString());
  311. log.Warn("P2:" + p1.GetImgPortraitString());
  312. duplicateparts.Add(p);
  313. break;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. foreach (var p in leftparts)
  320. {
  321. if (duplicateparts.Contains(p))
  322. {
  323. continue;
  324. }
  325. if (!finalparts.Contains(p))
  326. {
  327. finalparts.Add(p);
  328. }
  329. }
  330. foreach (var p in upparts)
  331. {
  332. if (duplicateparts.Contains(p))
  333. {
  334. continue;
  335. }
  336. if (!finalparts.Contains(p))
  337. {
  338. finalparts.Add(p);
  339. }
  340. }
  341. foreach (var p in rightparts)
  342. {
  343. if (duplicateparts.Contains(p))
  344. {
  345. continue;
  346. }
  347. if (!finalparts.Contains(p))
  348. {
  349. finalparts.Add(p);
  350. }
  351. }
  352. foreach (var p in downparts)
  353. {
  354. if (duplicateparts.Contains(p))
  355. {
  356. continue;
  357. }
  358. if (!finalparts.Contains(p))
  359. {
  360. finalparts.Add(p);
  361. }
  362. }
  363. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.CENTER, overlap))
  364. {
  365. if (!finalparts.Contains(p))
  366. {
  367. finalparts.Add(p);
  368. }
  369. }
  370. this.SetListAnalysisParticles(finalparts);
  371. log.Info("removing duplicate particles result:" + finalparts.Count);
  372. }
  373. private List<COTSParticleClr> GetSideParticlesByOverlap(SORTING_DIRECTION direction, int overlap)
  374. {
  375. List<COTSParticleClr> sideparts = new List<COTSParticleClr>();
  376. var borderedparts = this.GetBorderedParticles();
  377. if (direction == SORTING_DIRECTION.LEFT)
  378. {
  379. foreach (var p in this.GetListAnalysisParticles())
  380. {
  381. int left = 0, top = 0, right = 0, bottom = 0;
  382. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  383. if (Math.Abs(right - this.GetOTSRect().GetTopLeft().X) < 2 * overlap)
  384. {
  385. if (!borderedparts.Contains(p) || Math.Abs(left - right) > 2 * overlap)//not on the border or it's a big particle
  386. {
  387. sideparts.Add(p);
  388. }
  389. }
  390. }
  391. }
  392. if (direction == SORTING_DIRECTION.RIGHT)
  393. {
  394. foreach (var p in this.GetListAnalysisParticles())
  395. {
  396. int left = 0, top = 0, right = 0, bottom = 0;
  397. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  398. if (Math.Abs(this.GetOTSRect().GetBottomRight().X - left) < 2 * overlap)
  399. {
  400. if (!borderedparts.Contains(p) || Math.Abs(left - right) > 2 * overlap)//not on the border or is a big part
  401. {
  402. sideparts.Add(p);
  403. }
  404. }
  405. }
  406. }
  407. if (direction == SORTING_DIRECTION.UP)
  408. {
  409. foreach (var p in this.GetListAnalysisParticles())
  410. {
  411. int left = 0, top = 0, right = 0, bottom = 0;
  412. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  413. if (Math.Abs(this.GetOTSRect().GetTopLeft().Y - bottom) < 2 * overlap)
  414. {
  415. if (!borderedparts.Contains(p) || Math.Abs(top - bottom) > 2 * overlap)//not on the border
  416. {
  417. sideparts.Add(p);
  418. }
  419. }
  420. }
  421. }
  422. if (direction == SORTING_DIRECTION.DOWN)
  423. {
  424. foreach (var p in this.GetListAnalysisParticles())
  425. {
  426. int left = 0, top = 0, right = 0, bottom = 0;
  427. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  428. if (Math.Abs(top - this.GetOTSRect().GetBottomRight().Y) < 2 * overlap)
  429. {
  430. if (!borderedparts.Contains(p) || Math.Abs(top - bottom) > 2 * overlap)//not on the border
  431. {
  432. sideparts.Add(p);
  433. }
  434. }
  435. }
  436. }
  437. if (direction == SORTING_DIRECTION.CENTER)
  438. {
  439. foreach (var p in this.GetListAnalysisParticles())
  440. {
  441. int left = 0, top = 0, right = 0, bottom = 0;
  442. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  443. var fldrec = this.GetOTSRect();
  444. int fldleft = (int)fldrec.GetTopLeft().X;
  445. int fldright = (int)fldrec.GetBottomRight().X;
  446. int fldtop = (int)fldrec.GetTopLeft().Y;
  447. int fldbottom = (int)fldrec.GetBottomRight().Y;
  448. if ((Math.Abs(top - fldtop) > 2 * overlap) && (Math.Abs(fldbottom - bottom) > 2 * overlap) && (Math.Abs(left - fldleft) > 2 * overlap) && (Math.Abs(fldright - right) > 2 * overlap))
  449. {
  450. sideparts.Add(p);
  451. }
  452. }
  453. }
  454. return sideparts;
  455. }
  456. public void GetPartsBySpecialGray(CIntRangeClr grayRange, CDoubleRangeClr diameterRange, double pixelSize, bool ifXray)
  457. {
  458. if (m_pBSEImg == null)
  459. return;
  460. CImageHandler imghandler = new CImageHandler();
  461. List<COTSParticleClr> specialParts = new List<COTSParticleClr>();
  462. imghandler.GetParticlesBySpecialGray(m_pBSEImg, grayRange, diameterRange, pixelSize, ref specialParts);
  463. foreach (var p in specialParts)
  464. {
  465. p.SetIsXrayParticle(ifXray);
  466. m_listAllParticles.Add(p);
  467. }
  468. return;
  469. }
  470. public bool CalParticleImageProp(List<COTSParticleClr> particles)
  471. {
  472. m_ImagePro = new CImageHandler();
  473. foreach (COTSParticleClr part in particles)
  474. {
  475. m_ImagePro.CalParticleImageProp(part, m_pixelSize);
  476. }
  477. return true;
  478. }
  479. public void InitParticles(COTSImageProcParam a_pImageProcessParam)
  480. {
  481. // get area range
  482. CDoubleRange oAreaRange = a_pImageProcessParam.GetIncAreaRange();
  483. double rMin = oAreaRange.GetStart() / 2.0;
  484. double rMax = oAreaRange.GetEnd() / 2.0;
  485. int nTagId = 0;
  486. foreach (COTSParticleClr pParticle in m_listAnalysisParticles)//m_listAllParticles memorize all the particles .
  487. {
  488. pParticle.SetParticleId(nTagId);//give all the conforming particles a unified sequence no.
  489. pParticle.SetFieldId(GetId());
  490. pParticle.SetType((int)otsdataconst.OTS_PARTICLE_TYPE.NO_ANALYSIS_X_RAY);
  491. pParticle.SetTypeName("Not Identified");
  492. pParticle.SetAnalysisId(nTagId); // the same as the tagId no use now.
  493. nTagId++;
  494. }
  495. log.Info("Total analysis Particles: (>" + rMin.ToString("f2") + "): " + "<" + rMax.ToString("f2") + "): " + m_listAnalysisParticles.Count);
  496. }
  497. public bool CreateXrayList(List<COTSParticleClr> a_listParticles)
  498. {
  499. foreach (COTSParticleClr pPart in a_listParticles)
  500. {
  501. System.Drawing.Point poi = (System.Drawing.Point)pPart.GetXRayPos();
  502. CPosXrayClr pPosXray = new CPosXrayClr();
  503. pPosXray.SetPosition(poi);
  504. pPosXray.SetPartTagId(pPart.GetParticleId());
  505. pPosXray.SetIndex(pPart.GetAnalysisId());
  506. pPosXray.SetScanFieldId(pPart.GetFieldId());
  507. pPart.SetXray(pPosXray);
  508. }
  509. return true;
  510. }
  511. public bool NoParticle()
  512. {
  513. if (m_listAllParticles.Count == 0)
  514. {
  515. return true;
  516. }
  517. else
  518. {
  519. return false;
  520. }
  521. }
  522. public bool NoAnalysisParticle()
  523. {
  524. if (m_listAllParticles.Count == 0)
  525. {
  526. return true;
  527. }
  528. else
  529. {
  530. return false;
  531. }
  532. }
  533. public bool PositionEquals(COTSField a_oSource)
  534. {
  535. if (a_oSource.m_otsPos == this.m_otsPos)
  536. {
  537. return true;
  538. }
  539. else
  540. {
  541. return false;
  542. }
  543. }
  544. // ID
  545. public int GetId()
  546. {
  547. return m_nID;
  548. }
  549. public void SetId(int a_nID)
  550. {
  551. m_nID = a_nID;
  552. }
  553. // position (from field center manager)
  554. public System.Drawing.PointF GetOTSPosition()
  555. {
  556. return m_otsPos;
  557. }
  558. public void SetOTSPosition(System.Drawing.PointF a_poiPos)
  559. {
  560. m_otsPos = a_poiPos;
  561. }
  562. public List<COTSParticleClr> GetTopBorderedParticles()
  563. {
  564. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  565. foreach (var p in m_listAnalysisParticles)
  566. {
  567. var segs = p.GetFeature().GetSegmentsList();//COTSSegment
  568. foreach (var seg in segs)
  569. {
  570. if (seg.GetHeight() == 0)
  571. {
  572. parts.Add(p);
  573. break;
  574. }
  575. }
  576. }
  577. return parts;
  578. }
  579. public List<COTSParticleClr> GetBottomBorderedParticles()
  580. {
  581. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  582. foreach (var p in m_listAnalysisParticles)
  583. {
  584. var segs = p.GetFeature().GetSegmentsList();
  585. foreach (var seg in segs)
  586. {
  587. if (seg.GetHeight() == this.ImgHeight - 1)//the lowest height is 767(height-1),cause starting from 0.
  588. {
  589. parts.Add(p);
  590. break;
  591. }
  592. }
  593. }
  594. return parts;
  595. }
  596. public List<COTSParticleClr> GetBorderedParticles()
  597. {
  598. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  599. var leftparts = this.GetLeftBorderedParticles();
  600. var rightp = this.GetRightBorderedParticles();
  601. var topp = this.GetTopBorderedParticles();
  602. var bottomp = this.GetBottomBorderedParticles();
  603. foreach (var p in leftparts)
  604. {
  605. if (!parts.Contains(p))
  606. {
  607. parts.Add(p);
  608. }
  609. }
  610. foreach (var p in rightp)//
  611. {
  612. if (!parts.Contains(p))
  613. {
  614. parts.Add(p);
  615. }
  616. }
  617. foreach (var p in topp)
  618. {
  619. if (!parts.Contains(p))//there may be some particles connect to both the left and top.
  620. {
  621. parts.Add(p);
  622. }
  623. }
  624. foreach (var p in bottomp)
  625. {
  626. if (!parts.Contains(p))
  627. {
  628. parts.Add(p);
  629. }
  630. }
  631. return parts;
  632. }
  633. public List<COTSParticleClr> GetLeftBorderedParticles()
  634. {
  635. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  636. foreach (var p in m_listAnalysisParticles)
  637. {
  638. var segs = p.GetFeature().GetSegmentsList();
  639. foreach (var seg in segs)
  640. {
  641. if (seg.GetStart() == 0)
  642. {
  643. parts.Add(p);
  644. break;
  645. }
  646. }
  647. }
  648. return parts;
  649. }
  650. public List<COTSParticleClr> GetRightBorderedParticles()
  651. {
  652. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  653. foreach (var p in m_listAnalysisParticles)
  654. {
  655. var segs = p.GetFeature().GetSegmentsList();
  656. foreach (var seg in segs)
  657. {
  658. if (seg.GetStart() + seg.GetLength() == this.ImgWidth)
  659. {
  660. parts.Add(p);
  661. break;
  662. }
  663. }
  664. }
  665. return parts;
  666. }
  667. // is empty
  668. public bool IsEmpty()
  669. {
  670. return m_listAllParticles.Count == 0;
  671. }
  672. void Duplicate(COTSField a_oSource)
  673. {
  674. m_nID = a_oSource.m_nID;
  675. m_otsPos = a_oSource.m_otsPos;
  676. // copy data over
  677. foreach (var pParticle in a_oSource.m_listAllParticles)
  678. {
  679. m_listAllParticles.Add(pParticle);
  680. }
  681. }
  682. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  683. {
  684. xPoint xPos = new xPoint();
  685. Slo slo = new Slo();
  686. slo.Register("OTSPosition", xPos);
  687. if (isStoring)
  688. {
  689. xPos.AssignValue(new System.Drawing.Point((int)m_otsPos.X, (int)m_otsPos.Y));
  690. slo.Serialize(true, classDoc, rootNode);
  691. }
  692. else
  693. {
  694. slo.Serialize(false, classDoc, rootNode);
  695. m_otsPos = xPos.value();
  696. }
  697. }
  698. }
  699. }