| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 | using OTSCLRINTERFACE;using OTSDataType;using OTSIMGPROC;using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using static OTSDataType.otsdataconst;namespace OTSModelSharp{    public   class CFieldPositionMgr    {               // measure area        CDomain m_pMeasureArea;        // measured field centre points list        List<System.Drawing.Point> m_listMeasuredFieldCentrePoints;        // image scan parameter        COTSImgScanPrm  m_poImageScanParam;        const int RESOLUTION_ID_FIRST_TIE = 0;           // field centre points list        List<System.Drawing.Point> m_listFieldCentrePoints;        // SEM data (measurement)        CSEMDataMsr m_poSEMDataMsr;        // unmeasured field centre points list        List<System.Drawing.Point> m_listUnmeasuredFieldCentrePoints;        CFieldMgrClr fieldmgrclr;        public bool Init(CDomain a_pMeasureArea, COTSImgScanPrm  a_poImageScanParam, COTSImageProcParam a_pImgProcParam, CSEMDataMsr a_poSEMDataMsr, List<System.Drawing.Point> a_listMeasuredFieldCentrePoints)        {            // assign class member            m_pMeasureArea = new CDomain(a_pMeasureArea);            m_poImageScanParam = new COTSImgScanPrm (a_poImageScanParam);            m_poSEMDataMsr = new CSEMDataMsr(a_poSEMDataMsr);                        if (m_listFieldCentrePoints == null)            {                m_listFieldCentrePoints = new List<System.Drawing.Point>();            }            if (m_listUnmeasuredFieldCentrePoints == null)            {                m_listUnmeasuredFieldCentrePoints = new List<System.Drawing.Point>();            }            if (m_listMeasuredFieldCentrePoints == null)            {                m_listMeasuredFieldCentrePoints = new List<System.Drawing.Point>();            }            var scanfieldsize = m_poSEMDataMsr.GetScanFieldSize();            OTS_IMAGE_RESULOTION_OPTIONS nImageSizeId = GetImageScanParam().GetImageResulotion();            long nResulotionId = RESOLUTION_ID_FIRST_TIE + (long)nImageSizeId;                        fieldmgrclr = new CFieldMgrClr(scanfieldsize, RESOLUTION_VALUE[nResulotionId]);            CDomain domainclr = new CDomain(a_pMeasureArea.GetShape(),a_pMeasureArea.GetRectDomain());            domainclr.SetPolygonPoint(a_pMeasureArea.GetPolygonPoint());                        System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];                       fieldmgrclr.Init(domainclr.GetClrDomainObj(), sizePixelImage,scanfieldsize, (int)m_poImageScanParam.GetFieldStartMode());            fieldmgrclr.SetOverlap(a_pImgProcParam.GetOverlapParam());            m_listUnmeasuredFieldCentrePoints = fieldmgrclr.GetUnmeasuredFieldCentrePoints(a_listMeasuredFieldCentrePoints);            m_listFieldCentrePoints = fieldmgrclr.GetFieldCentrePoints();            return true;        }        // test if field is in the measured field centre points list        public bool IsInMeasuredFieldList(System.Drawing.Point a_poiField)        {                               for (int itr = 0; itr < m_listMeasuredFieldCentrePoints.Count; itr++)                {                    if (m_listMeasuredFieldCentrePoints[itr] == a_poiField)                    {                    return a_poiField == m_listMeasuredFieldCentrePoints[itr];                                           }                }            return false;               }        // calculate total fields        public double CalculateTotalFields(CDomain a_pMeasureArea, double a_dScanFieldSizeX, System.Drawing.Size a_sizePixelImage)        {            CDomainClr domainclr = new CDomainClr((int)a_pMeasureArea.GetShape(), a_pMeasureArea.GetRectDomain());            OTS_IMAGE_RESULOTION_OPTIONS nImageSizeId = m_poImageScanParam.GetImageResulotion();            int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;            System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];          return  fieldmgrclr.CalculateTotalFields(domainclr, a_dScanFieldSizeX, sizePixelImage);                              }        // field centre points list        public List<System.Drawing.Point> GetFieldCentrePoints()        {            return m_listFieldCentrePoints;        }        // field centre points list        public bool GetFieldRectByIndex(int a_nIndex,ref System.Drawing.Rectangle a_rectField)        {            // check input            if (a_nIndex < 0 || a_nIndex > (int)m_listFieldCentrePoints.Count)            {                return false;            }            // get image size            OTS_IMAGE_RESULOTION_OPTIONS nImageSizeId = m_poImageScanParam.GetImageResulotion();            int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;            System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];            // scan field size (x, y)            System.Drawing.Size sizeImage = new System.Drawing.Size();            sizeImage.Width = m_poSEMDataMsr.GetScanFieldSize();            sizeImage.Height = sizeImage.Width * sizePixelImage.Height/ sizePixelImage.Width;            // get left top            System.Drawing.Point ptLeftTop = m_listFieldCentrePoints[a_nIndex];            // get field rectangle            a_rectField =new Rectangle(ptLeftTop, sizeImage);            return true;        }        public int GetTotalFields()        {            return (int)m_listFieldCentrePoints.Count;        }        public void SetFieldCentrePoints(List<System.Drawing.Point> listPoint)        {            foreach (var opt in listPoint)            {                m_listFieldCentrePoints.Add(opt);            }        }        // unmeasured field centre points list        public List<System.Drawing.Point> GetUnmeasuredFieldCentrePoints()        {            return m_listUnmeasuredFieldCentrePoints;        }        public void SetUnmeasuredFieldCentrePoints(List<System.Drawing.Point> listPoint)        {            m_listUnmeasuredFieldCentrePoints.Clear();            foreach (var opt in listPoint)            {                m_listUnmeasuredFieldCentrePoints.Add(opt);            }        }        // measured field centre points list        public List<System.Drawing.Point> GetMeasuredFieldCentrePoints()        {            return m_listMeasuredFieldCentrePoints;        }        // measured field centre points list        public void SetMeasuredFieldCentrePoints(List<System.Drawing.Point> listPoint)        {            foreach (var opt in listPoint)            {                m_listMeasuredFieldCentrePoints.Add(opt);            }        }        // measure area        public CDomain GetMeasureArea()        {            return m_pMeasureArea;        }        // measure area        public void SetMeasureArea(CDomain a_pMeasureArea)        {            m_pMeasureArea = new CDomain(a_pMeasureArea);        }        // image scan parameter        public COTSImgScanPrm  GetImageScanParam()        {            return m_poImageScanParam;        }        // image scan parameter        public void SetImageScanParam(COTSImgScanPrm  a_poImageScanParam)        {            m_poImageScanParam = new COTSImgScanPrm (a_poImageScanParam);        }        // SEM data (measurement)        public CSEMDataMsr GetSEMDataMsr()        {            return m_poSEMDataMsr;        }        // SEM data (measurement)        public void SetSEMDataMsr(CSEMDataMsr a_poSEMDataMsr)        {            m_poSEMDataMsr = new CSEMDataMsr(a_poSEMDataMsr);        }                // check if this is a neighbor field centre                                  // test if field is in or partly in the measure domain area       public  bool IsInMeasureArea(System.Drawing.Point a_poiField, System.Drawing.Size a_sizeImageSize)        {            // test field centre point first            if (m_pMeasureArea.PtInDomain(a_poiField))            {                // centre in the measure domain area, return TRUE                 return true;            }            // get measure field centre            System.Drawing.Point poiMsrAreaCentre = m_pMeasureArea.GetDomainCenter();            // move to left top postion.            a_poiField.X = a_poiField.X - (a_sizeImageSize.Width / 2);            a_poiField.Y = a_poiField.Y - (a_sizeImageSize.Height / 2);            Rectangle rectFiled = new Rectangle(a_poiField, a_sizeImageSize);            // check field position            if (rectFiled.Left <= poiMsrAreaCentre.X && rectFiled.Right>= poiMsrAreaCentre.X)            {                // centre column field or centre field                return true;            }            else if (rectFiled.Top <= poiMsrAreaCentre.Y && rectFiled.Bottom>= poiMsrAreaCentre.Y)            {                // centre row field?                return true;            }            else if (rectFiled.Right <= poiMsrAreaCentre.X)            {                // on the left side		                //up                if (rectFiled.Top>= poiMsrAreaCentre.Y)                {                    // on the top left side, need to test the bottom right  corner                    if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Right, rectFiled.Top)))                    {                        return true;                    }                }                else if (rectFiled.Bottom <= poiMsrAreaCentre.Y) //down//                {                    // on the bottom left side, need to test the top right corner                    if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Right,rectFiled.Bottom)))                    {                        return true;                    }                }            }            else if (rectFiled.Left >= poiMsrAreaCentre.X)            {                // on the right side                //up                if (rectFiled.Top >= poiMsrAreaCentre.Y)                {                    // on the top left side, need to test the bottom right  corner                    if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Left , rectFiled.Top)))                    {                        return true;                    }                }                else if (rectFiled.Bottom <= poiMsrAreaCentre.Y) //down//                {                    // on the bottom left side, need to test the top right corner                    if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Left, rectFiled.Bottom)))                    {                        return true;                    }                }            }            // this field is not in the area at all, return FALSE.            return false;        }          }}
 |