COTSField.cs 27 KB

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