|
@@ -13,6 +13,7 @@ namespace OTSModelSharp.ServiceInterface
|
|
using OpenCvSharp;
|
|
using OpenCvSharp;
|
|
using OTSCLRINTERFACE;
|
|
using OTSCLRINTERFACE;
|
|
using OTSIMGPROC;
|
|
using OTSIMGPROC;
|
|
|
|
+ using OTSModelSharp.DTLBase;
|
|
using System.Drawing.Imaging;
|
|
using System.Drawing.Imaging;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
@@ -386,5 +387,248 @@ namespace OTSModelSharp.ServiceInterface
|
|
return points;
|
|
return points;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public bool RepeatedParticleTreatment(List<COTSFieldData> allFields, COTSSample theSample, string stdPath)
|
|
|
|
+ {
|
|
|
|
+ int maxPartCount = theSample.GetMsrParams().GetXRayParam().GetXrayLimit();
|
|
|
|
+ int overlap = theSample.GetMsrParams().GetImageProcessParam().GetOverlapParam();
|
|
|
|
+ double pixelSize = theSample.CalculatePixelSize();
|
|
|
|
+ System.Drawing.Size resolutionSize = theSample.GetResolutionSize();
|
|
|
|
+ int scanFieldSizeX = theSample.GetSEMDataMsr().GetScanFieldSize();
|
|
|
|
+ int scanFieldSizeY = scanFieldSizeX * resolutionSize.Height / resolutionSize.Width;
|
|
|
|
+ int offsetX = scanFieldSizeX - (int)(2 * overlap * pixelSize);
|
|
|
|
+ int offsetY = scanFieldSizeY - (int)(2 * overlap * pixelSize);
|
|
|
|
+ List<COTSParticleClr> deletePartList = new List<COTSParticleClr>();
|
|
|
|
+ List<COTSParticleClr> updatePartList = new List<COTSParticleClr>();
|
|
|
|
+
|
|
|
|
+ foreach (var item in allFields)
|
|
|
|
+ {
|
|
|
|
+ if (!item.GetIsMeasureComplete())
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ //找到上下左右四帧图
|
|
|
|
+ List<COTSFieldData> leftField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X - offsetX, item.OTSPos.Y)).ToList();
|
|
|
|
+ List<COTSFieldData> rightField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X + offsetX, item.OTSPos.Y)).ToList();
|
|
|
|
+ List<COTSFieldData> upField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X, item.OTSPos.Y + offsetY)).ToList();
|
|
|
|
+ List<COTSFieldData> downField = allFields.Where(a => a.OTSPos == new System.Drawing.Point(item.OTSPos.X, item.OTSPos.Y - offsetY)).ToList();
|
|
|
|
+ //判断是否有效
|
|
|
|
+ if (leftField.Count() == 1)//包含左帧图
|
|
|
|
+ {
|
|
|
|
+ if (leftField[0].GetIsMeasureComplete() == true)//存在测量帧图
|
|
|
|
+ {
|
|
|
|
+ //寻找重叠颗粒
|
|
|
|
+ deletePartList.AddRange(FieldFun(leftField[0], item, "left_right", resolutionSize, overlap));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (rightField.Count() == 1)//包含右帧图
|
|
|
|
+ {
|
|
|
|
+ if (rightField[0].GetIsMeasureComplete() == true)//存在测量帧图
|
|
|
|
+ {
|
|
|
|
+ //寻找重叠颗粒
|
|
|
|
+ deletePartList.AddRange(FieldFun(item, rightField[0], "left_right", resolutionSize, overlap));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (upField.Count() == 1)//包含上帧图
|
|
|
|
+ {
|
|
|
|
+ if (upField[0].GetIsMeasureComplete() == true)//存在测量帧图
|
|
|
|
+ {
|
|
|
|
+ //寻找重叠颗粒
|
|
|
|
+ deletePartList.AddRange(FieldFun(upField[0], item, "up_down", resolutionSize, overlap));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (downField.Count() == 1)//包含下帧图
|
|
|
|
+ {
|
|
|
|
+ if (downField[0].GetIsMeasureComplete() == true)//存在测量帧图
|
|
|
|
+ {
|
|
|
|
+ //寻找重叠颗粒
|
|
|
|
+ deletePartList.AddRange(FieldFun(item, downField[0], "up_down", resolutionSize, overlap));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //数据库操作
|
|
|
|
+ SQLiteHelper sQLiteHelper = new SQLiteHelper(stdPath);
|
|
|
|
+ sQLiteHelper.GetDBConnection();
|
|
|
|
+ sQLiteHelper.BeginTransaction();
|
|
|
|
+
|
|
|
|
+ deletePartList = deletePartList.Distinct().ToList();//去重
|
|
|
|
+
|
|
|
|
+ if (!sQLiteHelper.DeletePartForTransaction(deletePartList))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sQLiteHelper.CommitTransaction();
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<COTSParticleClr> FieldFun(COTSFieldData left_upField, COTSFieldData right_downField, string style, System.Drawing.Size resolutionSize, int overlap)
|
|
|
|
+ {
|
|
|
|
+ List<COTSParticleClr> particleClrs = new List<COTSParticleClr>();
|
|
|
|
+ if (style == "left_right")
|
|
|
|
+ {
|
|
|
|
+ //寻找左帧图的右侧区域颗粒
|
|
|
|
+ foreach (var leftParticles in left_upField.GetListAnalysisParticles())
|
|
|
|
+ {
|
|
|
|
+ Rectangle leftRectangle = (Rectangle)leftParticles.GetParticleRect();
|
|
|
|
+ if (leftRectangle.Right > resolutionSize.Width - overlap)//颗粒在左帧图的右侧重叠区域
|
|
|
|
+ {
|
|
|
|
+ particleClrs.Add(leftParticles);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //寻找当前帧图的左侧区域颗粒
|
|
|
|
+ foreach (var centerParticles in right_downField.GetListAnalysisParticles())
|
|
|
|
+ {
|
|
|
|
+ Rectangle centerRectangle = (Rectangle)centerParticles.GetParticleRect();
|
|
|
|
+ if (centerRectangle.Left < overlap)//左侧颗粒在当前帧图的左侧重叠区域
|
|
|
|
+ {
|
|
|
|
+ particleClrs.Add(centerParticles);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //寻找上帧图的下侧区域颗粒
|
|
|
|
+ foreach (var upParticles in left_upField.GetListAnalysisParticles())
|
|
|
|
+ {
|
|
|
|
+ Rectangle upRectangle = (Rectangle)upParticles.GetParticleRect();
|
|
|
|
+ if (upRectangle.Bottom > resolutionSize.Height - overlap)//颗粒在左帧图的右侧重叠区域
|
|
|
|
+ {
|
|
|
|
+ particleClrs.Add(upParticles);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //寻找当前帧图的上侧区域颗粒
|
|
|
|
+ foreach (var downParticles in right_downField.GetListAnalysisParticles())
|
|
|
|
+ {
|
|
|
|
+ Rectangle downRectangle = (Rectangle)downParticles.GetParticleRect();
|
|
|
|
+ if (downRectangle.Top < overlap)//左侧颗粒在当前帧图的左侧重叠区域
|
|
|
|
+ {
|
|
|
|
+ particleClrs.Add(downParticles);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return particleClrs;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void CombinFun(Dictionary<COTSParticleClr, COTSParticleClr> combin, string style, System.Drawing.Size resolutionSize, int overlap, ref List<COTSParticleClr> deletePartList, ref List<COTSParticleClr> updatePartList)
|
|
|
|
+ {
|
|
|
|
+ foreach (var item in combin)
|
|
|
|
+ {
|
|
|
|
+ Rectangle left_topRectangle = (Rectangle)item.Key.GetParticleRect();
|
|
|
|
+ Rectangle right_bottomRectangle = (Rectangle)item.Value.GetParticleRect();
|
|
|
|
+
|
|
|
|
+ //左颗粒:跨右边界 右颗粒:跨左边界
|
|
|
|
+ if (style == "left_right")
|
|
|
|
+ {
|
|
|
|
+ if (left_topRectangle.Right == resolutionSize.Width - 1 && right_bottomRectangle.Left == 0)
|
|
|
|
+ {
|
|
|
|
+ int offset = right_bottomRectangle.Y - left_topRectangle.Y;
|
|
|
|
+ if (item.Key.GetActualArea() > item.Value.GetActualArea())
|
|
|
|
+ {
|
|
|
|
+ Rectangle rectangle = new Rectangle(right_bottomRectangle.X, left_topRectangle.Y, right_bottomRectangle.Width, right_bottomRectangle.Height);
|
|
|
|
+ item.Value.SetParticleRect(rectangle);
|
|
|
|
+ COTSFeatureClr featureClr = item.Value.GetFeature();
|
|
|
|
+ List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
|
|
|
|
+ foreach (var Segment in segmentClrs)
|
|
|
|
+ {
|
|
|
|
+ Segment.SetHeight(Segment.GetHeight() - offset);
|
|
|
|
+ }
|
|
|
|
+ if (!updatePartList.Contains(item.Value))
|
|
|
|
+ {
|
|
|
|
+ updatePartList.Add(item.Value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Rectangle rectangle = new Rectangle(left_topRectangle.X, right_bottomRectangle.Y, left_topRectangle.Width, left_topRectangle.Height);
|
|
|
|
+ item.Key.SetParticleRect(rectangle);
|
|
|
|
+ COTSFeatureClr featureClr = item.Key.GetFeature();
|
|
|
|
+ List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
|
|
|
|
+ foreach (var Segment in segmentClrs)
|
|
|
|
+ {
|
|
|
|
+ Segment.SetHeight(Segment.GetHeight() + offset);
|
|
|
|
+ }
|
|
|
|
+ if (!updatePartList.Contains(item.Key))
|
|
|
|
+ {
|
|
|
|
+ updatePartList.Add(item.Key);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (item.Key.GetActualArea() > item.Value.GetActualArea())
|
|
|
|
+ {
|
|
|
|
+ if (!deletePartList.Contains(item.Value))
|
|
|
|
+ {
|
|
|
|
+ deletePartList.Add(item.Value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (!deletePartList.Contains(item.Key))
|
|
|
|
+ {
|
|
|
|
+ deletePartList.Add(item.Key);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (left_topRectangle.Bottom == resolutionSize.Height - 1 && right_bottomRectangle.Top == 0)
|
|
|
|
+ {
|
|
|
|
+ int offset = left_topRectangle.X - right_bottomRectangle.X;
|
|
|
|
+ if (item.Key.GetActualArea() > item.Value.GetActualArea())
|
|
|
|
+ {
|
|
|
|
+ Rectangle rectangle = new Rectangle(left_topRectangle.X, right_bottomRectangle.Y, right_bottomRectangle.Width, right_bottomRectangle.Height);
|
|
|
|
+ item.Value.SetParticleRect(rectangle);
|
|
|
|
+ COTSFeatureClr featureClr = item.Value.GetFeature();
|
|
|
|
+ List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
|
|
|
|
+ foreach (var Segment in segmentClrs)
|
|
|
|
+ {
|
|
|
|
+ Segment.SetStart(Segment.GetStart() + offset);
|
|
|
|
+ }
|
|
|
|
+ if (!updatePartList.Contains(item.Value))
|
|
|
|
+ {
|
|
|
|
+ updatePartList.Add(item.Value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Rectangle rectangle = new Rectangle(right_bottomRectangle.X, left_topRectangle.Y, left_topRectangle.Width, left_topRectangle.Height);
|
|
|
|
+ item.Key.SetParticleRect(rectangle);
|
|
|
|
+ COTSFeatureClr featureClr = item.Key.GetFeature();
|
|
|
|
+ List<COTSSegmentClr> segmentClrs = featureClr.GetSegmentsList();
|
|
|
|
+ foreach (var Segment in segmentClrs)
|
|
|
|
+ {
|
|
|
|
+ Segment.SetStart(Segment.GetStart() - offset);
|
|
|
|
+ }
|
|
|
|
+ if (!updatePartList.Contains(item.Key))
|
|
|
|
+ {
|
|
|
|
+ updatePartList.Add(item.Key);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (item.Key.GetActualArea() > item.Value.GetActualArea())
|
|
|
|
+ {
|
|
|
|
+ if (!deletePartList.Contains(item.Value))
|
|
|
|
+ {
|
|
|
|
+ deletePartList.Add(item.Value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (!deletePartList.Contains(item.Key))
|
|
|
|
+ {
|
|
|
|
+ deletePartList.Add(item.Key);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|