123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Drawing;
- using OTSModelSharp.ImageProcess;
- using OTSModelSharp.ServiceInterface;
- using OTSDataType;
- using OTSCLRINTERFACE;
- using System.Xml;
- namespace OTSModelSharp
- {
- using COTSFieldDataList = List<COTSFieldData>;
- public class COTSFieldData:ISlo
- {
- protected NLog.Logger log ;
- // ID
- int m_nID;
- // position (from field center manager)
- protected System.Drawing.PointF m_otsPos ;
- protected CBSEImgClr m_pBSEImg;
- protected double m_pixelSize;
- IImageProcess m_ImagePro;
- protected List<COTSParticleClr> m_listAllParticles = new List<COTSParticleClr>();//hold up all the particles abstracted from bse image;
- protected List<COTSParticleClr> m_listAnalysisParticles = new List<COTSParticleClr>();// according to the size (the diameter) constraint,pick out all the conforming particles.
- protected List<COTSParticleClr> m_listXrayParticles = new List<COTSParticleClr>();//hold up all the particles that need the xray data.
- protected List<COTSParticleClr> m_listBigParticles = new List<COTSParticleClr>();
- protected List<COTSParticleClr> m_listSmallParticles = new List<COTSParticleClr>();
-
- public List<COTSParticleClr> ListSmallParticles { get => m_listSmallParticles; set => m_listSmallParticles = value; }
- public List<COTSParticleClr> ListBigParticles { get => m_listBigParticles; set => m_listBigParticles = value; }
-
- private int height;
- private int width;
- public int Height { get => height; set => height = value; }
- public int Width { get => width; set => width = value; }
- public System.Drawing.PointF OTSPos { get => m_otsPos; set => m_otsPos = value; }
- public List<string> strKeyName;
- public bool GetIsMeasureComplete()
- {
- return isMeasureComplete;
- }
- public void SetIsMeasureComplete(bool value)
- {
- isMeasureComplete = value;
- }
- private bool isMeasureComplete;
- public PointF GetSemPos()
- {
- return m_semPos;
- }
- public void SetSemPos(PointF value)
- {
- m_semPos = value;
- }
- private PointF m_semPos;
- public List<COTSParticleClr> GetAllParticles()
- {
- return m_listAllParticles;
- }
- public List<COTSParticleClr> GetListAnalysisParticles()
- {
- return m_listAnalysisParticles;
- }
- public List<COTSParticleClr> GetListXrayParticles()
- {
- m_listXrayParticles.Clear();
- foreach (var p in m_listAnalysisParticles)
- {
- if (p.IsXrayParticle())
- {
- m_listXrayParticles.Add(p);
- }
- }
- return m_listXrayParticles;
- }
- public void SetListAnalysisParticles(List<COTSParticleClr> value)
- {
- m_listAnalysisParticles = value;
- }
-
- public COTSFieldData(PointF centerPoint, double a_dPixelSize)
- {
- log = NLog.LogManager.GetCurrentClassLogger();
- Init();
- //m_pBSEImg = a_pBSEImg;
- m_otsPos = centerPoint;
- m_pixelSize = a_dPixelSize;
-
-
- }
- public double GetPixelSize()
- {
- return m_pixelSize;
- }
- public void SetPixelSize(double size)
- {
- m_pixelSize = size;
- }
- public COTSFieldData()
- {
- log = NLog.LogManager.GetCurrentClassLogger();
- Init();
- }
- // initialization
- void Init()
- {
- // initialization
- m_nID = -1;
- OTSPos =new System.Drawing.Point(0, 0);
- m_listAllParticles.Clear();
- }
- public void CCOTSFieldData(COTSFieldData a_oSource)
- {
- // can't copy itself
- if (a_oSource == this)
- {
- return;
- }
- Duplicate(a_oSource);
- }
- public COTSFieldData(COTSFieldData a_poSource)
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- Duplicate(a_poSource);
- }
- public CBSEImgClr GetBSEImage()
- {
- return m_pBSEImg;
- }
- public void SetBSEImage(CBSEImgClr a_pBSEImg)
- {
- if (a_pBSEImg == null)
- {
- // invalid BSE image.
- log.Error("SetBSEImage: invalid BSE image.");
- return;
- }
- m_pBSEImg = a_pBSEImg;
- width = a_pBSEImg.GetWidth();
- height = a_pBSEImg.GetHeight();
- }
- public void RemoveImgBGAndGetParticles(COTSImageProcParam a_pImageProcessParam,double a_pixelSize,bool ifXray)
- {
- if (m_pBSEImg == null)
- return;
- CImageHandler imghandler = new CImageHandler();
- List<COTSParticleClr> xrayParts = new List<COTSParticleClr>();
- imghandler.RemoveBGAndGetParts(m_pBSEImg, a_pImageProcessParam,a_pixelSize, ref xrayParts);
- foreach (var p in xrayParts)
- {
- p.SetIsXrayParticle(ifXray);
- m_listAllParticles.Add(p);
-
- }
-
- return ;
- }
- public void GetPartsBySpecialGray(CIntRangeClr grayRange, CDoubleRangeClr diameterRange,double pixelSize, bool ifXray)
- {
- if (m_pBSEImg == null)
- return;
- CImageHandler imghandler = new CImageHandler();
- List<COTSParticleClr> specialParts = new List<COTSParticleClr>();
- imghandler.GetParticlesBySpecialGray(m_pBSEImg, grayRange,diameterRange,pixelSize, ref specialParts);
- foreach (var p in specialParts)
- {
- p.SetIsXrayParticle(ifXray);
- m_listAllParticles.Add(p);
-
- }
- return;
- }
- public bool CalParticleImageProp(List<COTSParticleClr> particles)
- {
- m_ImagePro = new CImageHandler();
- foreach (COTSParticleClr part in particles)
- {
-
- m_ImagePro.CalParticleImageProp( part, m_pixelSize);
- }
- return true;
- }
-
- public void InitParticles(COTSImageProcParam a_pImageProcessParam,double a_dPixelSize)
- {
- m_listAnalysisParticles = new List<COTSParticleClr>();
- // get area range
- CDoubleRange oAreaRange = a_pImageProcessParam.GetIncAreaRange();
- double rMin = oAreaRange.GetStart() / 2.0;
- double rMax = oAreaRange.GetEnd() / 2.0;
-
- int nTagId = 0;
-
- foreach (COTSParticleClr pParticle in m_listAllParticles)//m_listAllParticles memorize all the particles .
- {
-
- pParticle.SetTagId(nTagId);//give all the conforming particles a unified sequence no.
-
- pParticle.SetFieldId(GetId());
-
- pParticle.SetType((int)otsdataconst.OTS_PARTCLE_TYPE.NO_ANALYSIS_X_RAY);
- pParticle.SetTypeName("Not Identified");
-
- pParticle.SetAnalysisId(nTagId); // the same as the tagId no use now.
- nTagId++;
-
-
- }
- log.Info("Total Particles: (>" + oAreaRange.GetStart().ToString("f2") + "): "+ "<" + oAreaRange.GetEnd().ToString("f2") + "): " + m_listAllParticles.Count);
-
-
- }
-
- public bool CreateXrayList(List<COTSParticleClr> a_listParticles)
- {
- ;
- foreach (COTSParticleClr pPart in a_listParticles)
- {
-
-
-
- System.Drawing.Point poi = (System.Drawing.Point)pPart.GetXRayPos();
-
- CPosXrayClr pPosXray = new CPosXrayClr();
-
- pPosXray.SetPosition(poi);
-
- pPosXray.SetPartTagId(pPart.GetTagId());
-
- pPosXray.SetIndex(pPart.GetAnalysisId());
-
- pPosXray.SetScanFieldId(pPart.GetFieldId());
-
- pPart.SetXray(pPosXray);
- }
- return true;
- }
- public bool NoParticle()
- {
- if (m_listAllParticles.Count == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool NoAnalysisParticle()
- {
- if (m_listAllParticles.Count == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool PositionEquals(COTSFieldData a_oSource) // CBSEImg& operator=(const CBSEImg&); // =operator
- {
- var xoffSet = width * m_pixelSize /2;
- var yoffSet = height * m_pixelSize/2 ;
- if (a_oSource.m_otsPos.X < (m_otsPos.X+xoffSet) && a_oSource.m_otsPos.X>( m_otsPos.X-xoffSet))
- {
- if (a_oSource.m_otsPos.Y < (m_otsPos.Y + yoffSet) && a_oSource.m_otsPos.Y > (m_otsPos.Y - yoffSet))
- {
- return true;
- }
- return false;
- }
- else
- {
- return false;
- }
- //return OTSPos.X == a_oSource.m_otsPos.X && OTSPos.Y == a_oSource.m_otsPos.Y;
-
-
- }
-
-
- // ID
- public int GetId()
- {
- return m_nID;
- }
- public void SetId(int a_nID)
- {
- m_nID = a_nID;
- }
- // position (from field center manager)
- public System.Drawing.PointF GetOTSPosition()
- {
- return m_otsPos;
- }
- public void SetOTSPosition(System.Drawing.PointF a_poiPos)
- {
- m_otsPos = a_poiPos;
- }
-
- public List<COTSParticleClr> GetTopBorderedParticles()
- {
- List<COTSParticleClr> parts = new List<COTSParticleClr>();
- foreach (var p in m_listAllParticles)
- {
-
- var segs = p.GetFeature().GetSegmentsList();//COTSSegment
- foreach (var seg in segs)
- {
- if (seg.GetHeight() == 0)
- {
- parts.Add(p);
- break;
- }
- }
- }
- return parts;
- }
- public List< COTSParticleClr > GetBottomBorderedParticles()
- {
- List<COTSParticleClr> parts = new List<COTSParticleClr>();
- foreach (var p in m_listAllParticles)
- {
- var segs = p.GetFeature().GetSegmentsList();
- foreach (var seg in segs)
- {
- if (seg.GetHeight() == this.Height - 1)//the lowest height is 767(height-1),cause starting from 0.
- {
- parts.Add(p);
- break;
- }
- }
- }
- return parts;
- }
- public List<COTSParticleClr> GetLeftBorderedParticles()
- {
- List<COTSParticleClr> parts = new List<COTSParticleClr>();
- foreach (var p in m_listAllParticles)
- {
- var segs = p.GetFeature().GetSegmentsList();
- foreach (var seg in segs)
- {
- if (seg.GetStart() == 0)
- {
- parts.Add(p);
- break;
- }
- }
- }
- return parts;
- }
- public List <COTSParticleClr> GetRightBorderedParticles()
- {
- List<COTSParticleClr> parts = new List<COTSParticleClr>();
- foreach (var p in m_listAllParticles)
- {
- var segs = p.GetFeature().GetSegmentsList();
- foreach (var seg in segs)
- {
- if (seg.GetStart() + seg.GetLength() == this.Width)
- {
- parts.Add(p);
- break;
- }
- }
- }
- return parts;
- }
- // is empty
- public bool IsEmpty()
- {
- return m_listAllParticles.Count == 0;
- }
- void Duplicate( COTSFieldData a_oSource)
- {
-
- m_nID = a_oSource.m_nID;
- OTSPos = a_oSource.OTSPos;
-
- // copy data over
- foreach(var pParticle in a_oSource.m_listAllParticles)
- {
- m_listAllParticles.Add(pParticle);
- }
- }
- public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
- {
- xPoint xPos = new xPoint();
- Slo slo = new Slo();
- slo.Register("OTSPosition", xPos);
-
- if (isStoring)
- {
-
- xPos.AssignValue(new Point((int)m_otsPos.X,(int)m_otsPos.Y));
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_otsPos = xPos.value();
-
- }
- }
- }
-
-
- }
|