CImageHandler.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. using OTSDataType;
  2. using OTSModelSharp.ImageProcess;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using static OTSDataType.otsdataconst;
  10. namespace OTSModelSharp.ServiceInterface
  11. {
  12. using OpenCvSharp;
  13. using OTSCLRINTERFACE;
  14. using OTSIMGPROC;
  15. using OTSModelSharp.DTLBase;
  16. using System.Drawing.Imaging;
  17. using System.Runtime.InteropServices;
  18. using System.Windows;
  19. public class CImageHandler:IImageProcess
  20. {
  21. #region 通过byte数组生成BMP图像文件
  22. /// <summary>
  23. /// 将一个byte的数组转换为8bit灰度位图
  24. /// </summary>
  25. /// <param name="data">数组</param>
  26. /// <param name="width">图像宽度</param>
  27. /// <param name="height">图像高度</param>
  28. /// <returns>位图</returns>
  29. public static Bitmap ToGrayBitmap(byte[] data, int width, int height)
  30. {
  31. if (width == 0 || height == 0)
  32. return null;
  33. //// 申请目标位图的变量,并将其内存区域锁定
  34. Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
  35. //// BitmapData这部分内容 需要 using System.Drawing.Imaging;
  36. BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height),
  37. ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
  38. //// 获取图像参数
  39. // 扫描线的宽度
  40. int stride = bmpData.Stride;
  41. // 显示宽度与扫描线宽度的间隙
  42. int offset = stride - width;
  43. // 获取bmpData的内存起始位置
  44. IntPtr iptr = bmpData.Scan0;
  45. // 用stride宽度,表示这是内存区域的大小
  46. int scanBytes = stride * height;
  47. //// 下面把原始的显示大小字节数组转换为内存中实际存放的字节数组
  48. int posScan = 0;
  49. int posReal = 0;// 分别设置两个位置指针,指向源数组和目标数组
  50. byte[] pixelValues = new byte[scanBytes]; //为目标数组分配内存
  51. //for (int x = height-1;x>=0 ; x--) data[startIndex+ y];//
  52. for (int x = 0; x < height; x++)
  53. {
  54. int startIndex = x * width;
  55. //// 下面的循环节是模拟行扫描
  56. for (int y = 0; y < width; y++)
  57. {
  58. pixelValues[posScan++] = data[posReal++];
  59. }
  60. posScan += offset; //行扫描结束,要将目标位置指针移过那段“间隙”
  61. }
  62. //// 用Marshal的Copy方法,将刚才得到的内存字节数组复制到BitmapData中
  63. System.Runtime.InteropServices.Marshal.Copy(pixelValues, 0, iptr, scanBytes);
  64. bmp.UnlockBits(bmpData); // 解锁内存区域
  65. //// 下面的代码是为了修改生成位图的索引表,从伪彩修改为灰度
  66. ColorPalette tempPalette;
  67. using (Bitmap tempBmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed))
  68. {
  69. tempPalette = tempBmp.Palette;
  70. }
  71. for (int i = 0; i < 256; i++)
  72. {
  73. tempPalette.Entries[i] = Color.FromArgb(i, i, i);
  74. }
  75. bmp.Palette = tempPalette;
  76. return bmp;
  77. }
  78. #endregion
  79. public static byte[] BitmapToGrayByte(Bitmap bitmap)
  80. {
  81. // 申请目标位图的变量,并将其内存区域锁定
  82. BitmapData bitmapDat = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
  83. // 获取bmpData的内存起始位置
  84. IntPtr intPtr = bitmapDat.Scan0;
  85. byte[] image = new byte[bitmap.Width * bitmap.Height];//原始数据
  86. Marshal.Copy(intPtr, image, 0, bitmap.Width * bitmap.Height); // 将数据复制到byte数组中,
  87. //解锁内存区域
  88. bitmap.UnlockBits(bitmapDat);
  89. return image;
  90. }
  91. //获取测量的BSE图
  92. //COTSSample WSample: 工作样品测量
  93. //Byte[] BSEImage: 带背景图数据
  94. //int iHeight: 图像高度
  95. //int iWidth: 图像宽度
  96. //Byte[]BSEImageNoBG : 去背景图数据
  97. public bool GetBSEImage(COTSImageProcParam ImgProcPrm, double pixelSize, byte[] BSEImage, int iHeight, int iWidth, ref byte[] BSEImageNoBG)
  98. {
  99. Rectangle rect = new Rectangle();
  100. rect.Height = iHeight;
  101. rect.Width = iWidth;
  102. CBSEImgClr pBSEImageIn = new CBSEImgClr(rect);
  103. CBSEImgClr pBSEImageOut = new CBSEImgClr(rect);
  104. //pBSEImageIn.SetImageRect(rect);
  105. pBSEImageIn.SetImageData(BSEImage,iWidth, iHeight );
  106. //pBSEImageOut.SetImageRect(rect);
  107. if (null == ImgProcPrm)
  108. {
  109. return false;
  110. }
  111. RemoveBackGround(pBSEImageIn, ImgProcPrm, pixelSize ,ref pBSEImageOut);
  112. BSEImageNoBG = pBSEImageOut.GetImageDataPtr();
  113. return true;
  114. }
  115. /// <summary>
  116. /// 获取测量的BSE图
  117. /// </summary>
  118. /// <param name="BSEImage">BSE原数据</param>
  119. /// <param name="iHeight">图像高度</param>
  120. /// <param name="iWidth">图像宽度</param>
  121. /// <param name="grayStart"></param>
  122. /// <param name="grayEnd"></param>
  123. /// <param name="BSEImageNoBG">去背景图数据</param>
  124. /// <returns></returns>
  125. public bool GetBSEImage(byte[] BSEImage, int iHeight, int iWidth, int grayStart, int grayEnd, ref byte[] BSEImageNoBG)
  126. {
  127. Rectangle rect = new Rectangle();
  128. rect.Height = iHeight;
  129. rect.Width = iWidth;
  130. CBSEImgClr pBSEImageIn = new CBSEImgClr(rect);
  131. CBSEImgClr pBSEImageOut = new CBSEImgClr(rect);
  132. //pBSEImageIn.SetImageRect(rect);
  133. pBSEImageIn.SetImageData(BSEImage, iWidth, iHeight );
  134. CIntRangeClr cIntRangeClr = new CIntRangeClr();
  135. cIntRangeClr.SetStart(grayStart);
  136. cIntRangeClr.SetEnd(grayEnd);
  137. OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();
  138. int num=0;
  139. imgpro.GetSpecialGrayRangeImage(pBSEImageIn, cIntRangeClr, pBSEImageOut,ref num);
  140. for (int i = 0; i < iWidth; i++)
  141. {
  142. for (int j = 0; j < iHeight; j++)
  143. {
  144. var bse = pBSEImageOut.GetBSEValue(i, j);
  145. if (bse == 255)
  146. {
  147. var originalBse = pBSEImageIn.GetBSEValue(i, j);
  148. pBSEImageOut.SetBSEValue(i, j, originalBse);
  149. }
  150. else
  151. {
  152. pBSEImageOut.SetBSEValue(i, j, 255);
  153. }
  154. }
  155. }
  156. BSEImageNoBG = pBSEImageOut.GetImageDataPtr();
  157. return true;
  158. }
  159. // remove background
  160. public void RemoveBackGround(CBSEImgClr a_pImgIn, COTSImageProcParam a_pImgProcessParam, double a_pixelSize, ref CBSEImgClr a_pImgOut)
  161. {
  162. List<COTSParticleClr> parts = new List<COTSParticleClr>();
  163. List<COTSParticleClr> specialGreyparts = new List<COTSParticleClr>();
  164. if (!RemoveBGAndGetParts(a_pImgIn, a_pImgProcessParam, a_pixelSize, ref parts))
  165. {
  166. return;
  167. }
  168. if (a_pImgProcessParam.SpecialGreyRangeParam.GetIsToRun())
  169. {
  170. var param = a_pImgProcessParam.SpecialGreyRangeParam;
  171. var ranges = param.GetSpecialGreyRanges();
  172. foreach (var r in ranges)
  173. {
  174. CIntRangeClr r1 = new CIntRangeClr();
  175. r1.SetStart(r.range.GetStart());
  176. r1.SetEnd(r.range.GetEnd());
  177. CDoubleRangeClr r2 = new CDoubleRangeClr();
  178. r2.SetStart(r.diameterRange.GetStart());
  179. r2.SetEnd(r.diameterRange.GetEnd());
  180. GetParticlesBySpecialGray(a_pImgIn, r1, r2, a_pixelSize, ref specialGreyparts);
  181. }
  182. }
  183. for (int i = 0; i < a_pImgOut.GetWidth(); i++)
  184. {
  185. for (int j = 0; j < a_pImgOut.GetHeight(); j++)
  186. {
  187. a_pImgOut.SetBSEValue(i, j, 255);
  188. }
  189. }
  190. if (specialGreyparts.Count > 0)
  191. {
  192. foreach (var p in specialGreyparts)
  193. {
  194. foreach (var s in p.GetFeature().GetSegmentsList())
  195. {
  196. for (int i = s.GetStart(); i < s.GetStart() + s.GetLength(); i++)
  197. {
  198. var bseValue = a_pImgIn.GetBSEValue(i, s.GetHeight());
  199. a_pImgOut.SetBSEValue(i, s.GetHeight(), bseValue);
  200. }
  201. }
  202. }
  203. }
  204. foreach (var p in parts)
  205. {
  206. foreach (var s in p.GetFeature().GetSegmentsList())
  207. {
  208. for (int i = s.GetStart(); i < s.GetStart() + s.GetLength(); i++)
  209. {
  210. var bseValue = a_pImgIn.GetBSEValue(i, s.GetHeight());
  211. a_pImgOut.SetBSEValue(i, s.GetHeight(), bseValue);
  212. }
  213. }
  214. }
  215. return;
  216. }
  217. public void BDilate3(string source, string target, int wDegree, int rows, int columns)
  218. {
  219. throw new NotImplementedException();
  220. }
  221. public void BErode3(string source, string target, int wDegree, int rows, int columns)
  222. {
  223. throw new NotImplementedException();
  224. }
  225. public bool CalParticleImageProp( COTSParticleClr part, double a_pixelSize)
  226. {
  227. OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();
  228. imgpro.CalcuParticleImagePropertes(part,a_pixelSize);
  229. return true;
  230. }
  231. public bool RemoveBGAndGetParts(CBSEImgClr img, COTSImageProcParam a_pImgProcessParam,double a_pixelSize,ref List<COTSParticleClr> parts)
  232. {
  233. OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();
  234. OTSCLRINTERFACE.COTSImgProcPrmClr prm = GetImageProcPrmClr(a_pImgProcessParam);
  235. OTSCLRINTERFACE.COTSFieldDataClr flddataclr = new OTSCLRINTERFACE.COTSFieldDataClr();
  236. if (!imgpro.GetFieldDataFromImage(img, prm, a_pixelSize, flddataclr))
  237. {
  238. return false;
  239. }
  240. parts = flddataclr.GetParticleList();
  241. return true;
  242. }
  243. public bool GetParticlesBySpecialGray(CBSEImgClr img, CIntRangeClr grayrange, CDoubleRangeClr diameterRange,double a_pixelSize, ref List<COTSParticleClr> parts)
  244. {
  245. OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();
  246. //OTSCLRINTERFACE.COTSImgProcPrmClr prm = GetImageProcPrmClr(a_pImgProcessParam);
  247. OTSCLRINTERFACE.COTSFieldDataClr flddataclr = new OTSCLRINTERFACE.COTSFieldDataClr();
  248. imgpro.GetParticlesBySpecialPartGrayRange(img, grayrange,diameterRange,a_pixelSize, flddataclr);
  249. parts = flddataclr.GetParticleList();
  250. return true;
  251. }
  252. private COTSImgProcPrmClr GetImageProcPrmClr(COTSImageProcParam a_oSource)
  253. {
  254. COTSImgProcPrmClr prmclr = new COTSImgProcPrmClr();
  255. OTSCLRINTERFACE.CDoubleRangeClr r1 = new OTSCLRINTERFACE.CDoubleRangeClr(a_oSource.GetIncAreaRange().GetStart(), a_oSource.GetIncAreaRange().GetEnd());
  256. prmclr.SetIncArea(r1);
  257. OTSCLRINTERFACE.CIntRangeClr r2= new OTSCLRINTERFACE.CIntRangeClr(a_oSource.GetBGGray().GetStart(), a_oSource.GetBGGray().GetEnd());
  258. prmclr.SetBGGray(r2);
  259. OTSCLRINTERFACE.CIntRangeClr r3= new OTSCLRINTERFACE.CIntRangeClr(a_oSource.GetParticleGray().GetStart(), a_oSource.GetParticleGray().GetEnd());
  260. prmclr.SetParticleGray(r3);
  261. prmclr.SetBGRemoveType((int)a_oSource.GetBGRemoveType());
  262. prmclr.SetAutoBGRemoveType((int)a_oSource.GetAutoBGRemoveType());
  263. prmclr.SetErrodDilateParam(a_oSource.GetErrodDilateParam());
  264. prmclr.SetOverlapParam(a_oSource.GetOverlapParam());
  265. return prmclr;
  266. }
  267. public bool MergeBigBoundaryParticles(List<COTSFieldData> allFields, double pixelSize, int scanFieldSize, System.Drawing.Size ResolutionSize, ref List<COTSParticleClr> mergedParts)
  268. {
  269. List<COTSFieldDataClr> fldclrs = new List<COTSFieldDataClr>();
  270. foreach (var f in allFields)
  271. {
  272. COTSFieldDataClr fldclr = new COTSFieldDataClr();
  273. fldclr.SetPosition(f.GetOTSPosition());
  274. fldclr.SetImageWidth(f.Width);
  275. fldclr.SetImageHeight(f.Height);
  276. var parts = f.GetListAnalysisParticles();
  277. foreach (var p in parts)
  278. {
  279. fldclr.AddParticle(p);
  280. }
  281. fldclrs.Add(fldclr);
  282. }
  283. OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();
  284. imgpro.MergeBigBoundaryParticles(fldclrs, pixelSize, scanFieldSize, ResolutionSize, mergedParts);
  285. return true;
  286. }
  287. /// <summary>
  288. /// 根据Segment寻找边缘坐标点
  289. /// </summary>
  290. /// <param name="width"></param>
  291. /// <param name="height"></param>
  292. /// <param name="segmentClrs"></param>
  293. /// <returns></returns>
  294. public static List<System.Drawing.Point> FindContoursBySegment(int width, int height, List<COTSSegmentClr> segmentClrs)
  295. {
  296. List<System.Drawing.Point> points = new List<System.Drawing.Point>();
  297. using (Mat mat = new Mat(height, width, MatType.CV_8UC1, new Scalar(0)))
  298. {
  299. for (int i = 0; i < segmentClrs.Count; i++)
  300. {
  301. Cv2.Line(mat, new OpenCvSharp.Point(segmentClrs[i].GetStart(), segmentClrs[i].GetHeight()), new OpenCvSharp.Point(segmentClrs[i].GetStart() + segmentClrs[i].GetLength(), segmentClrs[i].GetHeight()), Scalar.White, 1, LineTypes.AntiAlias);
  302. }
  303. Point[][] contours;
  304. HierarchyIndex[] hierarchy;
  305. Cv2.FindContours(mat, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple, null);
  306. for (int i = 0; i < contours.ToList().Count(); i++)
  307. {
  308. for (int j = 0; j < contours[i].Count(); j++)
  309. {
  310. System.Drawing.Point point = new System.Drawing.Point(contours[i][j].X, contours[i][j].Y);
  311. if (!points.Contains(point))
  312. {
  313. points.Add(point);
  314. }
  315. }
  316. }
  317. }
  318. return points;
  319. }
  320. public bool RepeatedParticleTreatment(List<COTSFieldData> allFields, COTSSample theSample, string stdPath)
  321. {
  322. int maxPartCount = theSample.GetMsrParams().GetXRayParam().GetXrayLimit();
  323. int overlap = theSample.GetMsrParams().GetImageProcessParam().GetOverlapParam();
  324. double pixelSize = theSample.CalculatePixelSize();
  325. System.Drawing.Size resolutionSize = theSample.GetResolutionSize();
  326. int scanFieldSizeX = theSample.GetSEMDataMsr().GetScanFieldSize();
  327. int scanFieldSizeY = scanFieldSizeX * resolutionSize.Height / resolutionSize.Width;
  328. int offsetX = scanFieldSizeX - (int)(2 * overlap * pixelSize);
  329. int offsetY = scanFieldSizeY - (int)(2 * overlap * pixelSize);
  330. List<COTSParticleClr> deletePartList = new List<COTSParticleClr>();
  331. List<COTSParticleClr> updatePartList = new List<COTSParticleClr>();
  332. foreach (var item in allFields)
  333. {
  334. if (!item.GetIsMeasureComplete())
  335. {
  336. break;
  337. }
  338. //找到上下左右四帧图
  339. List<COTSFieldData> leftField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X - offsetX, item.OTSPos.Y)).ToList();
  340. List<COTSFieldData> rightField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X + offsetX, item.OTSPos.Y)).ToList();
  341. List<COTSFieldData> upField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X, item.OTSPos.Y + offsetY)).ToList();
  342. List<COTSFieldData> downField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X, item.OTSPos.Y - offsetY)).ToList();
  343. //判断是否有效
  344. if (leftField.Count() == 1)//包含左帧图
  345. {
  346. if (leftField[0].GetIsMeasureComplete() == true)//存在测量帧图
  347. {
  348. //寻找重叠颗粒
  349. deletePartList.AddRange(FieldFun(leftField[0], item, "left_right", resolutionSize, overlap));
  350. }
  351. }
  352. if (rightField.Count() == 1)//包含右帧图
  353. {
  354. if (rightField[0].GetIsMeasureComplete() == true)//存在测量帧图
  355. {
  356. //寻找重叠颗粒
  357. deletePartList.AddRange(FieldFun(item, rightField[0], "left_right", resolutionSize, overlap));
  358. }
  359. }
  360. if (upField.Count() == 1)//包含上帧图
  361. {
  362. if (upField[0].GetIsMeasureComplete() == true)//存在测量帧图
  363. {
  364. //寻找重叠颗粒
  365. deletePartList.AddRange(FieldFun(upField[0], item, "up_down", resolutionSize, overlap));
  366. }
  367. }
  368. if (downField.Count() == 1)//包含下帧图
  369. {
  370. if (downField[0].GetIsMeasureComplete() == true)//存在测量帧图
  371. {
  372. //寻找重叠颗粒
  373. deletePartList.AddRange(FieldFun(item, downField[0], "up_down", resolutionSize, overlap));
  374. }
  375. }
  376. }
  377. //数据库操作
  378. SQLiteHelper sQLiteHelper = new SQLiteHelper(stdPath);
  379. sQLiteHelper.GetDBConnection();
  380. sQLiteHelper.BeginTransaction();
  381. deletePartList = deletePartList.Distinct().ToList();//去重
  382. if (!sQLiteHelper.DeletePartForTransaction(deletePartList))
  383. {
  384. return false;
  385. }
  386. sQLiteHelper.CommitTransaction();
  387. return true;
  388. }
  389. private List<COTSParticleClr> FieldFun(COTSFieldData left_upField, COTSFieldData right_downField, string style, System.Drawing.Size resolutionSize, int overlap)
  390. {
  391. List<COTSParticleClr> particleClrs = new List<COTSParticleClr>();
  392. if (style == "left_right")
  393. {
  394. //寻找左帧图的右侧区域颗粒
  395. foreach (var leftParticles in left_upField.GetListAnalysisParticles())
  396. {
  397. Rectangle leftRectangle = (Rectangle)leftParticles.GetParticleRect();
  398. if (leftRectangle.Right > resolutionSize.Width - overlap)//颗粒在左帧图的右侧重叠区域
  399. {
  400. particleClrs.Add(leftParticles);
  401. }
  402. }
  403. //寻找当前帧图的左侧区域颗粒
  404. foreach (var centerParticles in right_downField.GetListAnalysisParticles())
  405. {
  406. Rectangle centerRectangle = (Rectangle)centerParticles.GetParticleRect();
  407. if (centerRectangle.Left < overlap)//左侧颗粒在当前帧图的左侧重叠区域
  408. {
  409. particleClrs.Add(centerParticles);
  410. }
  411. }
  412. }
  413. else
  414. {
  415. //寻找上帧图的下侧区域颗粒
  416. foreach (var upParticles in left_upField.GetListAnalysisParticles())
  417. {
  418. Rectangle upRectangle = (Rectangle)upParticles.GetParticleRect();
  419. if (upRectangle.Bottom > resolutionSize.Height - overlap)//颗粒在左帧图的右侧重叠区域
  420. {
  421. particleClrs.Add(upParticles);
  422. }
  423. }
  424. //寻找当前帧图的上侧区域颗粒
  425. foreach (var downParticles in right_downField.GetListAnalysisParticles())
  426. {
  427. Rectangle downRectangle = (Rectangle)downParticles.GetParticleRect();
  428. if (downRectangle.Top < overlap)//左侧颗粒在当前帧图的左侧重叠区域
  429. {
  430. particleClrs.Add(downParticles);
  431. }
  432. }
  433. }
  434. return particleClrs;
  435. }
  436. private void CombinFun(Dictionary<COTSParticleClr, COTSParticleClr> combin, string style, System.Drawing.Size resolutionSize, int overlap, ref List<COTSParticleClr> deletePartList, ref List<COTSParticleClr> updatePartList)
  437. {
  438. foreach (var item in combin)
  439. {
  440. Rectangle left_topRectangle = (Rectangle)item.Key.GetParticleRect();
  441. Rectangle right_bottomRectangle = (Rectangle)item.Value.GetParticleRect();
  442. //左颗粒:跨右边界 右颗粒:跨左边界
  443. if (style == "left_right")
  444. {
  445. if (left_topRectangle.Right == resolutionSize.Width - 1 && right_bottomRectangle.Left == 0)
  446. {
  447. int offset = right_bottomRectangle.Y - left_topRectangle.Y;
  448. if (item.Key.GetActualArea() > item.Value.GetActualArea())
  449. {
  450. Rectangle rectangle = new Rectangle(right_bottomRectangle.X, left_topRectangle.Y, right_bottomRectangle.Width, right_bottomRectangle.Height);
  451. item.Value.SetParticleRect(rectangle);
  452. COTSFeatureClr featureClr = item.Value.GetFeature();
  453. List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
  454. foreach (var Segment in segmentClrs)
  455. {
  456. Segment.SetHeight(Segment.GetHeight() - offset);
  457. }
  458. if (!updatePartList.Contains(item.Value))
  459. {
  460. updatePartList.Add(item.Value);
  461. }
  462. }
  463. else
  464. {
  465. Rectangle rectangle = new Rectangle(left_topRectangle.X, right_bottomRectangle.Y, left_topRectangle.Width, left_topRectangle.Height);
  466. item.Key.SetParticleRect(rectangle);
  467. COTSFeatureClr featureClr = item.Key.GetFeature();
  468. List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
  469. foreach (var Segment in segmentClrs)
  470. {
  471. Segment.SetHeight(Segment.GetHeight() + offset);
  472. }
  473. if (!updatePartList.Contains(item.Key))
  474. {
  475. updatePartList.Add(item.Key);
  476. }
  477. }
  478. }
  479. else
  480. {
  481. if (item.Key.GetActualArea() > item.Value.GetActualArea())
  482. {
  483. if (!deletePartList.Contains(item.Value))
  484. {
  485. deletePartList.Add(item.Value);
  486. }
  487. }
  488. else
  489. {
  490. if (!deletePartList.Contains(item.Key))
  491. {
  492. deletePartList.Add(item.Key);
  493. }
  494. }
  495. }
  496. }
  497. else
  498. {
  499. if (left_topRectangle.Bottom == resolutionSize.Height - 1 && right_bottomRectangle.Top == 0)
  500. {
  501. int offset = left_topRectangle.X - right_bottomRectangle.X;
  502. if (item.Key.GetActualArea() > item.Value.GetActualArea())
  503. {
  504. Rectangle rectangle = new Rectangle(left_topRectangle.X, right_bottomRectangle.Y, right_bottomRectangle.Width, right_bottomRectangle.Height);
  505. item.Value.SetParticleRect(rectangle);
  506. COTSFeatureClr featureClr = item.Value.GetFeature();
  507. List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
  508. foreach (var Segment in segmentClrs)
  509. {
  510. Segment.SetStart(Segment.GetStart() + offset);
  511. }
  512. if (!updatePartList.Contains(item.Value))
  513. {
  514. updatePartList.Add(item.Value);
  515. }
  516. }
  517. else
  518. {
  519. Rectangle rectangle = new Rectangle(right_bottomRectangle.X, left_topRectangle.Y, left_topRectangle.Width, left_topRectangle.Height);
  520. item.Key.SetParticleRect(rectangle);
  521. COTSFeatureClr featureClr = item.Key.GetFeature();
  522. List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
  523. foreach (var Segment in segmentClrs)
  524. {
  525. Segment.SetStart(Segment.GetStart() - offset);
  526. }
  527. if (!updatePartList.Contains(item.Key))
  528. {
  529. updatePartList.Add(item.Key);
  530. }
  531. }
  532. }
  533. else
  534. {
  535. if (item.Key.GetActualArea() > item.Value.GetActualArea())
  536. {
  537. if (!deletePartList.Contains(item.Value))
  538. {
  539. deletePartList.Add(item.Value);
  540. }
  541. }
  542. else
  543. {
  544. if (!deletePartList.Contains(item.Key))
  545. {
  546. deletePartList.Add(item.Key);
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. }
  554. }