COTSField.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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> xrayParts = new List<COTSParticleClr>();
  161. imghandler.RemoveBGAndGetParts(this, a_pImageProcessParam, ref xrayParts);
  162. foreach (var p in xrayParts)
  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. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap))
  175. {
  176. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  177. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  178. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  179. PointF pcenter = prec.GetCenterPoint();
  180. bool findsimilar = false;
  181. var rightsideparts = leftField.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap);
  182. foreach (var p1 in rightsideparts)
  183. {
  184. int p1left = 0, p1right = 0, p1top = 0, p1bottom = 0;
  185. p1.GetOTSRect(ref p1left, ref p1top, ref p1right, ref p1bottom);
  186. COTSRect p1rec = new COTSRect(p1left, p1top, p1right, p1bottom);
  187. PointF p1Center = p1rec.GetCenterPoint();
  188. if (Math.Abs(pcenter.X - p1Center.X) < 2 * overlap && Math.Abs(pcenter.Y - p1Center.Y) < 2 * overlap)
  189. {
  190. var sim = p.CalculateSimilarity(p1);
  191. if ( sim> 0.95)
  192. {
  193. log.Warn("remove left side duplicate particle,similarity:" + sim.ToString("F3"));
  194. findsimilar = true;
  195. break;
  196. }
  197. }
  198. }
  199. if (findsimilar == false)
  200. {
  201. finalparts.Add(p);
  202. }
  203. }
  204. }
  205. else
  206. {
  207. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap))
  208. {
  209. finalparts.Add(p);
  210. }
  211. }
  212. if (upField != null && upField.measureSequence < this.measureSequence)
  213. {
  214. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.UP, overlap))
  215. {
  216. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  217. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  218. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  219. PointF pcenter = prec.GetCenterPoint();
  220. bool findsimilar = false;
  221. var othersideparts = upField.GetSideParticlesByOverlap(SORTING_DIRECTION.DOWN, overlap);
  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. findsimilar = true;
  235. break;
  236. }
  237. }
  238. }
  239. if (findsimilar == false)
  240. {
  241. finalparts.Add(p);
  242. }
  243. }
  244. }
  245. else
  246. {
  247. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.UP, overlap))
  248. {
  249. finalparts.Add(p);
  250. }
  251. }
  252. if (rightField != null && rightField.measureSequence < this.measureSequence)
  253. {
  254. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap))
  255. {
  256. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  257. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  258. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  259. PointF pcenter = prec.GetCenterPoint();
  260. bool findsimilar = false;
  261. var othersideparts = rightField.GetSideParticlesByOverlap(SORTING_DIRECTION.LEFT, overlap);
  262. foreach (var p1 in othersideparts)
  263. {
  264. int p1left = 0, p1right = 0, p1top = 0, p1bottom = 0;
  265. p1.GetOTSRect(ref p1left, ref p1top, ref p1right, ref p1bottom);
  266. COTSRect p1rec = new COTSRect(p1left, p1top, p1right, p1bottom);
  267. PointF p1Center = p1rec.GetCenterPoint();
  268. if (Math.Abs(pcenter.X - p1Center.X) < 2 * overlap && Math.Abs(pcenter.Y - p1Center.Y) < 2 * overlap)
  269. {
  270. var sim = p.CalculateSimilarity(p1);
  271. if (sim > 0.95)
  272. {
  273. log.Warn("remove right side duplicate particle,similarity:" + sim.ToString("F3"));
  274. findsimilar = true;
  275. break;
  276. }
  277. }
  278. }
  279. if (findsimilar == false)
  280. {
  281. finalparts.Add(p);
  282. }
  283. }
  284. }
  285. else
  286. {
  287. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.RIGHT, overlap))
  288. {
  289. finalparts.Add(p);
  290. }
  291. }
  292. if (downField != null && downField.measureSequence < this.measureSequence)
  293. {
  294. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.DOWN, overlap))
  295. {
  296. int pleft = 0, pright = 0, ptop = 0, pbottom = 0;
  297. p.GetOTSRect(ref pleft, ref ptop, ref pright, ref pbottom);
  298. COTSRect prec = new COTSRect(pleft, ptop, pright, pbottom);
  299. PointF pcenter = prec.GetCenterPoint();
  300. bool findsimilar = false;
  301. var othersideparts = downField.GetSideParticlesByOverlap(SORTING_DIRECTION.UP, overlap);
  302. foreach (var p1 in othersideparts)
  303. {
  304. int p1left = 0, p1right = 0, p1top = 0, p1bottom = 0;
  305. p1.GetOTSRect(ref p1left, ref p1top, ref p1right, ref p1bottom);
  306. COTSRect p1rec = new COTSRect(p1left, p1top, p1right, p1bottom);
  307. PointF p1Center = p1rec.GetCenterPoint();
  308. if (Math.Abs(pcenter.X - p1Center.X) < 2 * overlap && Math.Abs(pcenter.Y - p1Center.Y) < 2 * overlap)
  309. {
  310. var sim = p.CalculateSimilarity(p1);
  311. if (sim > 0.95)
  312. {
  313. log.Warn("remove down side duplicate particle,similarity:" + sim.ToString("F3"));
  314. findsimilar = true;
  315. break;
  316. }
  317. }
  318. }
  319. if (findsimilar == false)
  320. {
  321. finalparts.Add(p);
  322. }
  323. }
  324. }
  325. else
  326. {
  327. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.DOWN, overlap))
  328. {
  329. finalparts.Add(p);
  330. }
  331. }
  332. foreach (var p in this.GetSideParticlesByOverlap(SORTING_DIRECTION.CENTER, overlap))
  333. {
  334. finalparts.Add(p);
  335. }
  336. this.SetListAnalysisParticles(finalparts);
  337. }
  338. private List<COTSParticleClr> GetSideParticlesByOverlap(SORTING_DIRECTION direction,int overlap)
  339. {
  340. List<COTSParticleClr> sideparts = new List<COTSParticleClr>();
  341. if (direction == SORTING_DIRECTION.LEFT)
  342. {
  343. foreach (var p in this.GetAllParticles())
  344. {
  345. int left = 0, top = 0, right = 0, bottom = 0;
  346. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  347. if ((right - this.GetOTSRect().GetTopLeft().X) < 2 * overlap)
  348. {
  349. if (left != this.GetOTSRect().GetTopLeft().X)//not on the border
  350. {
  351. sideparts.Add(p);
  352. }
  353. }
  354. }
  355. }
  356. if (direction == SORTING_DIRECTION.RIGHT)
  357. {
  358. foreach (var p in this.GetAllParticles())
  359. {
  360. int left = 0, top = 0, right = 0, bottom = 0;
  361. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  362. if ((this.GetOTSRect().GetBottomRight().X-left) < 2 * overlap)
  363. {
  364. if (right != this.GetOTSRect().GetBottomRight().X)//not on the border
  365. {
  366. sideparts.Add(p);
  367. }
  368. }
  369. }
  370. }
  371. if (direction == SORTING_DIRECTION.UP)
  372. {
  373. foreach (var p in this.GetAllParticles())
  374. {
  375. int left = 0, top = 0, right = 0, bottom = 0;
  376. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  377. if ((this.GetOTSRect().GetTopLeft().Y - bottom) < 2 * overlap)
  378. {
  379. if (top != this.GetOTSRect().GetTopLeft().Y)//not on the border
  380. {
  381. sideparts.Add(p);
  382. }
  383. }
  384. }
  385. }
  386. if (direction == SORTING_DIRECTION.DOWN)
  387. {
  388. foreach (var p in this.GetAllParticles())
  389. {
  390. int left = 0, top = 0, right = 0, bottom = 0;
  391. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  392. if ((top-this.GetOTSRect().GetBottomRight().Y ) < 2 * overlap)
  393. {
  394. if (bottom != this.GetOTSRect().GetBottomRight().Y)//not on the border
  395. {
  396. sideparts.Add(p);
  397. }
  398. }
  399. }
  400. }
  401. if (direction == SORTING_DIRECTION.CENTER)
  402. {
  403. foreach (var p in this.GetAllParticles())
  404. {
  405. int left = 0, top = 0, right = 0, bottom = 0;
  406. p.GetOTSRect(ref left, ref top, ref right, ref bottom);
  407. var fldrec = this.GetOTSRect();
  408. int fldleft = (int)fldrec.GetTopLeft().X;
  409. int fldright = (int)fldrec.GetBottomRight().X;
  410. int fldtop = (int)fldrec.GetTopLeft().Y;
  411. int fldbottom = (int)fldrec.GetBottomRight().Y;
  412. 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))
  413. {
  414. sideparts.Add(p);
  415. }
  416. }
  417. }
  418. return sideparts;
  419. }
  420. public void GetPartsBySpecialGray(CIntRangeClr grayRange, CDoubleRangeClr diameterRange,double pixelSize, bool ifXray)
  421. {
  422. if (m_pBSEImg == null)
  423. return;
  424. CImageHandler imghandler = new CImageHandler();
  425. List<COTSParticleClr> specialParts = new List<COTSParticleClr>();
  426. imghandler.GetParticlesBySpecialGray(m_pBSEImg, grayRange,diameterRange,pixelSize, ref specialParts);
  427. foreach (var p in specialParts)
  428. {
  429. p.SetIsXrayParticle(ifXray);
  430. m_listAllParticles.Add(p);
  431. }
  432. return;
  433. }
  434. public bool CalParticleImageProp(List<COTSParticleClr> particles)
  435. {
  436. m_ImagePro = new CImageHandler();
  437. foreach (COTSParticleClr part in particles)
  438. {
  439. m_ImagePro.CalParticleImageProp( part, m_pixelSize);
  440. }
  441. return true;
  442. }
  443. public void InitParticles(COTSImageProcParam a_pImageProcessParam,double a_dPixelSize)
  444. {
  445. m_listAnalysisParticles = new List<COTSParticleClr>();
  446. // get area range
  447. CDoubleRange oAreaRange = a_pImageProcessParam.GetIncAreaRange();
  448. double rMin = oAreaRange.GetStart() / 2.0;
  449. double rMax = oAreaRange.GetEnd() / 2.0;
  450. int nTagId = 0;
  451. foreach (COTSParticleClr pParticle in m_listAllParticles)//m_listAllParticles memorize all the particles .
  452. {
  453. pParticle.SetParticleId(nTagId);//give all the conforming particles a unified sequence no.
  454. pParticle.SetFieldId(GetId());
  455. pParticle.SetType((int)otsdataconst.OTS_PARTICLE_TYPE.NO_ANALYSIS_X_RAY);
  456. pParticle.SetTypeName("Not Identified");
  457. pParticle.SetAnalysisId(nTagId); // the same as the tagId no use now.
  458. nTagId++;
  459. }
  460. log.Info("Total Particles: (>" + oAreaRange.GetStart().ToString("f2") + "): "+ "<" + oAreaRange.GetEnd().ToString("f2") + "): " + m_listAllParticles.Count);
  461. }
  462. public bool CreateXrayList(List<COTSParticleClr> a_listParticles)
  463. {
  464. foreach (COTSParticleClr pPart in a_listParticles)
  465. {
  466. System.Drawing.Point poi = (System.Drawing.Point)pPart.GetXRayPos();
  467. CPosXrayClr pPosXray = new CPosXrayClr();
  468. pPosXray.SetPosition(poi);
  469. pPosXray.SetPartTagId(pPart.GetParticleId());
  470. pPosXray.SetIndex(pPart.GetAnalysisId());
  471. pPosXray.SetScanFieldId(pPart.GetFieldId());
  472. pPart.SetXray(pPosXray);
  473. }
  474. return true;
  475. }
  476. public bool NoParticle()
  477. {
  478. if (m_listAllParticles.Count == 0)
  479. {
  480. return true;
  481. }
  482. else
  483. {
  484. return false;
  485. }
  486. }
  487. public bool NoAnalysisParticle()
  488. {
  489. if (m_listAllParticles.Count == 0)
  490. {
  491. return true;
  492. }
  493. else
  494. {
  495. return false;
  496. }
  497. }
  498. public bool PositionEquals(COTSField a_oSource)
  499. {
  500. var xoffSet = imgwidth * m_pixelSize /2;
  501. var yoffSet = imgheight * m_pixelSize/2 ;
  502. if (a_oSource.m_otsPos.X < (m_otsPos.X+xoffSet) && a_oSource.m_otsPos.X>( m_otsPos.X-xoffSet))
  503. {
  504. if (a_oSource.m_otsPos.Y < (m_otsPos.Y + yoffSet) && a_oSource.m_otsPos.Y > (m_otsPos.Y - yoffSet))
  505. {
  506. return true;
  507. }
  508. return false;
  509. }
  510. else
  511. {
  512. return false;
  513. }
  514. }
  515. // ID
  516. public int GetId()
  517. {
  518. return m_nID;
  519. }
  520. public void SetId(int a_nID)
  521. {
  522. m_nID = a_nID;
  523. }
  524. // position (from field center manager)
  525. public System.Drawing.PointF GetOTSPosition()
  526. {
  527. return m_otsPos;
  528. }
  529. public void SetOTSPosition(System.Drawing.PointF a_poiPos)
  530. {
  531. m_otsPos = a_poiPos;
  532. }
  533. public List<COTSParticleClr> GetTopBorderedParticles()
  534. {
  535. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  536. foreach (var p in m_listAllParticles)
  537. {
  538. var segs = p.GetFeature().GetSegmentsList();//COTSSegment
  539. foreach (var seg in segs)
  540. {
  541. if (seg.GetHeight() == 0)
  542. {
  543. parts.Add(p);
  544. break;
  545. }
  546. }
  547. }
  548. return parts;
  549. }
  550. public List< COTSParticleClr > GetBottomBorderedParticles()
  551. {
  552. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  553. foreach (var p in m_listAllParticles)
  554. {
  555. var segs = p.GetFeature().GetSegmentsList();
  556. foreach (var seg in segs)
  557. {
  558. if (seg.GetHeight() == this.ImgHeight - 1)//the lowest height is 767(height-1),cause starting from 0.
  559. {
  560. parts.Add(p);
  561. break;
  562. }
  563. }
  564. }
  565. return parts;
  566. }
  567. public List<COTSParticleClr> GetLeftBorderedParticles()
  568. {
  569. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  570. foreach (var p in m_listAllParticles)
  571. {
  572. var segs = p.GetFeature().GetSegmentsList();
  573. foreach (var seg in segs)
  574. {
  575. if (seg.GetStart() == 0)
  576. {
  577. parts.Add(p);
  578. break;
  579. }
  580. }
  581. }
  582. return parts;
  583. }
  584. public List <COTSParticleClr> GetRightBorderedParticles()
  585. {
  586. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  587. foreach (var p in m_listAllParticles)
  588. {
  589. var segs = p.GetFeature().GetSegmentsList();
  590. foreach (var seg in segs)
  591. {
  592. if (seg.GetStart() + seg.GetLength() == this.ImgWidth)
  593. {
  594. parts.Add(p);
  595. break;
  596. }
  597. }
  598. }
  599. return parts;
  600. }
  601. // is empty
  602. public bool IsEmpty()
  603. {
  604. return m_listAllParticles.Count == 0;
  605. }
  606. void Duplicate( COTSField a_oSource)
  607. {
  608. m_nID = a_oSource.m_nID;
  609. m_otsPos = a_oSource.m_otsPos;
  610. // copy data over
  611. foreach(var pParticle in a_oSource.m_listAllParticles)
  612. {
  613. m_listAllParticles.Add(pParticle);
  614. }
  615. }
  616. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  617. {
  618. xPoint xPos = new xPoint();
  619. Slo slo = new Slo();
  620. slo.Register("OTSPosition", xPos);
  621. if (isStoring)
  622. {
  623. xPos.AssignValue(new System.Drawing.Point((int)m_otsPos.X,(int)m_otsPos.Y));
  624. slo.Serialize(true, classDoc, rootNode);
  625. }
  626. else
  627. {
  628. slo.Serialize(false, classDoc, rootNode);
  629. m_otsPos = xPos.value();
  630. }
  631. }
  632. }
  633. }