COTSField.cs 26 KB

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