Forráskód Böngészése

improve the measure flow and merge the smplMeasureInclution and smplMeasureCleanness class's code.

gsp 3 éve
szülő
commit
b610bd5db6

+ 9 - 0
OTSCPP/OTSClrInterface/CommonClr/OTSParticleClr.h

@@ -219,6 +219,15 @@ namespace OTSCLRINTERFACE {
 			
 			m_Particle->get()->SetGroupId(grpid);
 		}
+		bool IsXrayParticle()
+		{
+		
+			return m_Particle->get()->IsXrayParticle();
+		}
+		void SetIsXrayParticle(bool value)
+		{
+			m_Particle->get()->SetIsXrayParticle(value);
+		}
 
 	protected:		
 		COTSParticlePtr* m_Particle;

+ 5 - 0
OTSCPP/OTSData/OTSParticle.h

@@ -173,6 +173,9 @@ const double Pi = 3.14159;
 		std::string GetGroupColor() const { return m_grpColor; }
 		void SetGroupColor(std::string val) { m_grpColor = val; }
 
+		BOOL IsXrayParticle() const { return m_isXrayParticle; }
+		void SetIsXrayParticle(bool value) { m_isXrayParticle = value; }
+
 protected:
 
 		// cleanup
@@ -183,6 +186,8 @@ protected:
 
 		// duplication 
 		void Duplicate(const COTSParticle& a_oSource);
+
+		bool m_isXrayParticle;
 						
 		// area
 		double m_dArea;

+ 7 - 232
OTSIncAMeasureApp/0-OTSModel/Measure/1-OTSInclution/SmplMeasureInclution.cs

@@ -27,200 +27,7 @@ namespace OTSModelSharp
 
         }
 
-        // field image process
-        public override bool FieldImageProcess(Point fldCenter, CBSEImgClr a_pBSEImg)
-        {
-            int nNewFieldId;
-            nNewFieldId = m_pSampleRstFile.GetIdForANewField();
-
-            // create a field
-            curFldData = new CFieldDataIncA(a_pBSEImg, m_Sample.CalculatePixelSize());
-            curFldData.SetId(nNewFieldId);
-            curFldData.SetOTSPosition(fldCenter);
-            CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
-            Point semPos = new Point();
-            a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter,ref semPos);
-            curFldData.SemPos = semPos;
-           
-            //first step:remove background of the bse image and compound all the finded particles.
-          
-            log.Info("Begin to process image and get all particles!");
-            GetOriginalParticles();
-            
-            // second step :filter the finded particles.
-            log.Info("Begin to filter particles!");
-            InitFieldParticles();
-            CalculateParticleAbsolutPos();
-
-            log.Info("Begin to Calculate the image property of every particle!");
-            var analysisparts = curFldData.GetListAnalysisParticles();
-            curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc.
-
-            COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
-
-            if (pXRayParam.GetUsingXray() == true)
-            {
-                Thread.Sleep(100);
-                CollectParticlesXrayData();
-             
-                Thread.Sleep(100);
-            }
-            
-
-            log.Info("Begin to classify particles! particle num:"+ curFldData.GetListAnalysisParticles().Count);
-            ClassifyFieldParticles();
-
-          
-
-            // save field files
-            m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
-
-            StartSaveFileThread(curFldData);
-
-            return true; 
-
-        }
-
-
-
-
-
-        // save field data
-                   
-
-        public void InitFieldParticles()
-                {
-        
-            // get pixel size
-            double dPixelSize = m_Sample.CalculatePixelSize();        
-         
-            CSampleParam pMsrParam = m_Sample.GetMsrParams();
-            COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
-            curFldData.InitParticles(pImgProcessParam,dPixelSize);
-
-            // make sure the particles list is not empty
-            if (curFldData.NoAnalysisParticle())
-            {
-                log.Info("There's no particles to be analysed!");
-                //return false;
-            }
-            return ;
-        }
-        //calculate the real sem position of the particle
-        //public void CalculateParticlePos(List<COTSParticleClr> xrayParticles)
-        //{
-        //    double dPixelSize = m_Sample.CalculatePixelSize();
-        //    CSEMStageData pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
-        //    foreach (var p in xrayParticles)
-        //    {
-               
-        //        Point fldOtsPos = new Point(curFldData.OTSPos.X, curFldData.OTSPos.Y);//take the field position as the particle's position instead
-        //        Point semPos = new Point();
-        //        pCSEMStageData.ConverOTSToSEMPoint(fldOtsPos, ref semPos);
-        //        p.SetAbsolutPos(semPos);
-        //    }
-
-        //}
-
-        public void CollectParticlesXrayData()
-        {
-            // get x-ray parameters
-            COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
-
-           
-
-            var listXrayAnalysisparts = curFldData.GetListXrayParticles();
-
-          
-         
-            ////=============================================
-            curFldData.CreateXrayList(listXrayAnalysisparts);
-         
-
-            var xraymode = m_Sample.GetMsrParams().GetXRayParam().GetScanMode();
-
-            // get x-ray list (analysis) by particle features
-            uint  nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
-            var nFastXrayAQTime =(uint) pXRayParam.GetFastXrayTime();
-            var quantifyMinSize = pXRayParam.GetFeatureModeMinSize();
-
-            var listXray = listXrayAnalysisparts.OrderByDescending(x => x.GetActualArea()).ToList();
-            var listXray1 = new List<COTSParticleClr>();
-
-            if (listXray.Count > pXRayParam.GetXrayLimit())
-            {
-                for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
-                {
-
-                    listXray1.Add(listXray[i]);
-                }
-
-            }
-            else
-            {
-                listXray1 = listXray;
-            }
-
-
-
-
-            List<COTSParticleClr> smallparts = new List<COTSParticleClr>();
-            List<COTSParticleClr> bigparts = new List<COTSParticleClr>();
-
-
-
-            foreach (var p in listXray1)
-            {
-                double diameter = Math.Sqrt(p.GetActualArea() / 3.14159) * 2;
-                if (diameter >= quantifyMinSize)
-                {
-                    bigparts.Add(p);
-
-                }
-                else 
-                {
-                    smallparts.Add(p);
-                }
-            
-            }
-
-            if (xraymode == OTS_X_RAY_SCAN_MODE.FeatureMode)
-            {
-                if (bigparts.Count > 0)
-                {
-
-                    log.Info("Begin  feature mode xray collection for big particles!AQTime:" + nXRayAQTime + " xrayNum:" + bigparts.Count);
-                    m_EDSHardwareMgr.GetXRayByFeatures(bigparts, nXRayAQTime, true);
-                }
-                
-    
-
-            }
-            else 
-            {
-                if (bigparts.Count > 0)
-                {
-                    log.Info("Begin  point mode xray collection for big particles!AQTime:" + nXRayAQTime + " xrayNum:" + bigparts.Count);
-                    // get x-ray list (analysis) by points
-                    m_EDSHardwareMgr.GetXRayByPoints(bigparts, nXRayAQTime, true);
-
-                }
-               
-     
-
-            }
-            if (smallparts.Count > 0)
-            {
-                log.Info("Begin  point mode xray collection for small particles!AQTime:" + nFastXrayAQTime + " xrayNum:" + smallparts.Count);
-                // get x-ray list (analysis) by points
-                m_EDSHardwareMgr.GetXRayByPoints(smallparts, nFastXrayAQTime, true);
-
-            }
-          
-
-
-            return ;
-        }
+       
 
       
 
@@ -229,8 +36,8 @@ namespace OTSModelSharp
 
             try
             {
-                var curFld = (CFieldDataIncA)curFldData;
-                var anylysisparts = curFld.GetListAnalysisParticles();
+               
+                var anylysisparts = curFldData.GetListAnalysisParticles();
                 int nSize = anylysisparts.Count();
 
                 // go through all analysis particles
@@ -239,14 +46,14 @@ namespace OTSModelSharp
                     string libname = m_Sample.GetMsrParams().GetSTDName();
                     ClassifyIncAParticle(anylysisparts[i], libname);
                 }
-               
-               
+
+
             }
             catch (Exception e)
             {
                 log.Info(" classify failed. " + e.Message);
             }
-          
+
         }
         public override void ClassifyMergedParticles(List<COTSParticleClr> mergedParts)
         {
@@ -310,39 +117,7 @@ namespace OTSModelSharp
         }
      
 
-        public void GetOriginalParticles()
-        {
-            // measure status
-            CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
-
-            // get image process parameter
-            CSampleParam pMsrParam = m_Sample.GetMsrParams();
-            COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
-            var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
-            var pixelsize = m_Sample.CalculatePixelSize();
-            if (specialPartsparam.GetIsToRun())
-            {
-                List<CSpecialGrayRange> ranges = pMsrParam.GetSpecialGrayRangeParam().GetSpecialGreyRanges();
-                foreach (var grayRange in ranges)
-                {
-                    CIntRangeClr range = new CIntRangeClr(grayRange.range.GetStart(), grayRange.range.GetEnd());
-                    CDoubleRangeClr diaRange = new CDoubleRangeClr(grayRange.diameterRange.GetStart(), grayRange.diameterRange.GetEnd());
-                    curFldData.GetPartsBySpecialGray(range, diaRange,pixelsize,grayRange.ifCollectXray);
-                }
-            }
-
-            // remove BES image background
-            curFldData.RemoveImgBGAndGetParticles(pImgProcessParam, pixelsize);
-           
-
-            // check if this is an empty image
-            if (curFldData.NoParticle())
-            { // empty fields
-                log.Info("ImageProcess: empty field.");
-              
-            }
-            return ;
-        }
+       
           
 
 

+ 0 - 81
OTSIncAMeasureApp/0-OTSModel/Measure/2-OTSCleanliness/CFieldDataClean.cs

@@ -14,90 +14,9 @@ namespace OTSModelSharp.Measure.OTSCleanliness
         {
 
         }
-        List<COTSParticleClr> m_listBigParticles = new List<COTSParticleClr>();
-        List<COTSParticleClr> m_listSmallParticles = new List<COTSParticleClr>();
-        double m_smallParticlePercentage;//if the small particles are  measured for a percentage of the whole,then this variable remember the percentage.
 
-        public List<COTSParticleClr> ListSmallParticles { get => m_listSmallParticles; set => m_listSmallParticles = value; }
-        public List<COTSParticleClr> ListBigParticles { get => m_listBigParticles; set => m_listBigParticles = value; }
-        public double SmallParticlePercentage { get => m_smallParticlePercentage; set => m_smallParticlePercentage = value; }
 
         // particle list
 
-        public new List<COTSParticleClr> GetTopBorderedParticles()
-        {
-            List<COTSParticleClr> parts = new List<COTSParticleClr>();
-            foreach (var p in ListBigParticles)
-            {
-
-                var segs = p.GetFeature().GetSegmentsList();//COTSSegment
-                foreach (var seg in segs)
-                {
-                    if (seg.GetHeight() == 0)
-                    {
-                        parts.Add(p);
-                        break;
-                    }
-                }
-            }
-            return parts;
-        }
-
-        public new List<COTSParticleClr> GetBottomBorderedParticles()
-        {
-            List<COTSParticleClr> parts = new List<COTSParticleClr>();
-            foreach (var p in ListBigParticles)
-            {
-                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 new List<COTSParticleClr> GetLeftBorderedParticles()
-        {
-            List<COTSParticleClr> parts = new List<COTSParticleClr>();
-            foreach (var p in ListBigParticles)
-            {
-                var segs = p.GetFeature().GetSegmentsList();
-                foreach (var seg in segs)
-                {
-                    if (seg.GetStart() == 0)
-                    {
-                        parts.Add(p);
-                        break;
-                    }
-
-                }
-            }
-            return parts;
-        }
-
-        public new List<COTSParticleClr> GetRightBorderedParticles()
-        {
-            List<COTSParticleClr> parts = new List<COTSParticleClr>();
-            foreach (var p in ListBigParticles)
-            {
-                var segs = p.GetFeature().GetSegmentsList();
-                foreach (var seg in segs)
-                {
-                    if (seg.GetStart() + seg.GetLength() == this.Width)
-                    {
-                        parts.Add(p);
-                        break;
-                    }
-
-                }
-            }
-            return parts;
-        }
     }
 }

+ 6 - 357
OTSIncAMeasureApp/0-OTSModel/Measure/2-OTSCleanliness/SmplMeasureCleanliness.cs

@@ -25,233 +25,9 @@ namespace OTSModelSharp
             m_classifyEngine = new CClassifyEngine();
         }
 
-        // field image process
-        public override bool FieldImageProcess(Point fldCenter, CBSEImgClr a_BSEImg)
-        {
-            int nNewFieldId;
-            nNewFieldId = m_pSampleRstFile.GetIdForANewField();
-            //first step:remove background of the bse image and compound all the finded particles.
-            curFldData = new CFieldDataClean( a_BSEImg,m_Sample.CalculatePixelSize());
-            CFieldDataClean curFldDataCln =( CFieldDataClean) curFldData;
-          
-            curFldData.SetId(nNewFieldId);
-            curFldData.SetOTSPosition(fldCenter);
-
-            Point semPos = new Point();
-            CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
-            a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter, ref semPos);
-            curFldData.SemPos = semPos;
-
-
-            GetOriginalParticles();
- 
-            // second step :filter the finded particles.
-            FilterParticles((CFieldDataClean)curFldData);
-            CalculateParticleAbsolutPos();
-
-
-            log.Info("Begin to Calculate the image property of every particle!");
-            var analysisparts = curFldDataCln.ListBigParticles;
-            curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc
-
-            COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
-            //collect xray data.
-            if (pXRayParam.GetUsingXray() == true)
-            {
-                Thread.Sleep(100);
-                CollectParticlesXrayData((CFieldDataClean)curFldData);
-                Thread.Sleep(100);
-            }
-      
-
-
-
-
-
-            ClassifyFieldParticles();
-
-  
-
-            // save field files
-            m_Sample.GetMsrStatus() .SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
-
-            StartSaveFileThread(curFldData);
-
-            return true;
-
-        }
-      
-
-
-        // save field data
-        //protected void SaveFieldMgrData()
-        //{
-        //    while (bSaveThreadWorking)
-        //    {
-        //        while (fieldQueue.Count() > 0)
-        //        {
-        //            CFieldDataClean f = (CFieldDataClean) fieldQueue.Dequeue();
-        //            //double pixelSize = m_Sample.CalculatePixelSize();
-
-          
-
-        //            //save to disk first ,then pop . if the size is 0,then we know all the saving work is done.
-        //            SaveFieldData(f,m_pSampleRstFile.GetFieldFileSubFolderStr());
-
-
-        //        }
-        //        if (fieldQueue.Count() == 0)
-        //        {
-        //            bSaveThreadWorking = false; //must set this flag,so the main thread can know this thread has exited.
-        //            return;
-        //        }
-        //    }
-        //    return;
-        //}
-
-
-        //protected void StartSaveFileThread(COTSFieldData a_pFieldMgr)
-        //{
+        
       
 
-        //    fieldQueue.Enqueue(a_pFieldMgr);
-
-
-        //    if (fieldQueue.Count() > 0) //if there's data in the queue and the previous thread has finished then start a new thread.
-        //    {
-        //        if (bSaveThreadWorking == false)
-        //        {
-        //            bSaveThreadWorking = true;
-
-        //            m_thread_ptr = new System.Threading.Thread(this.SaveFieldMgrData);//m_thread_ptr = shared_ptr<thread>(new thread(&CSmplMeasureInc::SaveFieldMgrData, this));
-        //            m_thread_ptr.Start();//m_thread_ptr->detach();
-        //        }
-        //    }
-        //}
-
-        public void FilterParticles(CFieldDataClean fld)
-        {
-            // 1)remove over sized particles, too small particles and get a analysis particles list
-           
-            double dPixelSize = m_Sample.CalculatePixelSize();
-
-
-          
-           
-            CSampleParam pMsrParam = m_Sample.GetMsrParams();
-            COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
-           
-            curFldData.InitParticles(pImgProcessParam, dPixelSize);
-            if (curFldData.NoAnalysisParticle())
-            {
-                log.Warn("There's no analysis particles!");
-            }
-
-            var listXray = curFldData.GetListAnalysisParticles().OrderByDescending(x => x.GetActualArea()).ToList();
-            var listXray1 = new List<COTSParticleClr>();
-            var pXRayParam = pMsrParam.GetXRayParam();
-            if (listXray.Count > pXRayParam.GetXrayLimit())
-            {
-                for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
-                {
-
-                    listXray1.Add(listXray[i]);
-                }
-
-            }
-            else
-            {
-                listXray1 = listXray;
-            }
-
-
-
-            //2) according to the quantify threshold size value saperate the analysis particles into two group :the bigparticles and the smallparticles.
-
-            double quantifyThreshold = m_Sample.GetMsrParams().GetXRayParam().GetFeatureModeMinSize();
-
-            var smallparts = fld.ListSmallParticles;
-            var bigparts = fld.ListBigParticles;
-
-
-            foreach (var part in listXray1)
-            {
-                double equalCircleDiameter = Math.Sqrt(part.GetActualArea() / 3.14159) * 2f;
-                if (equalCircleDiameter < quantifyThreshold)
-                {
-                    smallparts.Add(part);
-                }
-                else
-                {
-                    bigparts.Add(part);
-                }
-            }
-            
-
-            fld.ListSmallParticles = smallparts;
-            fld.ListBigParticles = bigparts;
-            //fld.SmallParticlePercentage=percentage;
-            log.Info("SmallQuantifyParts (<" + quantifyThreshold.ToString("f2") + "): " + smallparts.Count);
-            log.Info("BigQuantifyParts (>=" + quantifyThreshold.ToString("f2")+ "): " + bigparts.Count);
-
-            return ;
-        }
-
-        public void CollectParticlesXrayData(CFieldDataClean fld)
-        {
-            // get x-ray parameters
-            COTSXRayParam pXRayParam = m_Sample.GetMsrParams ().GetXRayParam();
-
-            // calculate search x-ray acquire time
-            uint nXRayAQTime;
-
-            var smallparts = fld.ListSmallParticles;
-            var bigparts = fld.ListBigParticles;
-
-
-            var pStatus = m_Sample.GetMsrStatus();
-            curFldData.CreateXrayList(bigparts); // big particle using the full xray strategy.
-
-
-            curFldData.CreateXrayList(smallparts); //small particle using the fast xray strategy
-
-            if (bigparts.Count > 0)
-            {
-
-           
-                var workmode = pXRayParam.GetScanMode();
-                // get x-ray list (analysis) by particle features
-                if (workmode == OTS_X_RAY_SCAN_MODE.FeatureMode)
-                {
-                    nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
-                    m_EDSHardwareMgr.GetXRayByFeatures(bigparts, nXRayAQTime, true);
-
-                }
-                else
-                {
-                    nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
-                    m_EDSHardwareMgr.GetXRayByPoints(bigparts, nXRayAQTime, true);
-                }
-            }
-
-
-
-
-            if (smallparts.Count > 0)
-            {
-                nXRayAQTime = (uint)pXRayParam.GetFastXrayTime();
-
-                // get x-ray list (analysis) by points
-                m_EDSHardwareMgr.GetXRayByPoints(smallparts, nXRayAQTime, true);
-
-            }
-
-
-           
-     
-            return ;
-        }
-
        
 
         public override void ClassifyFieldParticles()
@@ -259,14 +35,14 @@ namespace OTSModelSharp
            
             try
             {
-                CFieldDataClean curFldDataCln = (CFieldDataClean)curFldData;
+                //CFieldDataClean curFldDataCln = (CFieldDataClean)curFldData;
                 string libname = m_Sample.GetMsrParams().GetSTDName();
                 if (libname != "NoSTDDB")
                 {
                    log.Info("Begin to classify big particles!Using " + libname);
-                    var bigparts = curFldDataCln.ListBigParticles;
+                    var bigparts = curFldData.ListBigParticles;
                     ClassifyQuantifyParticles(bigparts,libname);
-                    var smallParts = curFldDataCln.ListSmallParticles;
+                    var smallParts = curFldData.ListSmallParticles;
                     ClassifyQuantifyParticles(smallParts, libname);
                  
                 }
@@ -305,28 +81,7 @@ namespace OTSModelSharp
         }
     
 
-        public void GetOriginalParticles()
-        {
-            // measure status
-            CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
-
-   
-           // get image process parameter
-           CSampleParam pMsrParam = m_Sample.GetMsrParams();
-            COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
-            var dPixelsize = m_Sample.CalculatePixelSize();
-            // remove BES image background
-            curFldData.RemoveImgBGAndGetParticles(pImgProcessParam, dPixelsize);
-   
-
-            // check if this is an empty image
-            if (curFldData.NoParticle())
-            { // empty fields
-                log.Info("ImageProcess: empty field.");
-                //return false;
-            }
-            return ;
-        }
+     
         public bool ClassifyQuantifyParticles(List<COTSParticleClr> a_listAnalysisParticles, string libname)// classify particles
         {
 
@@ -370,113 +125,7 @@ namespace OTSModelSharp
             return true;
         }
 
-        //public bool SaveFieldFiles(CFieldDataClean fldData, string filedFileFoler)
-        //{
-
-        //    string strFieldFileFolder = filedFileFoler;
-
-        //    CBSEImageFileMgr pBSEImgFileMgr = new CBSEImageFileMgr();
-        //    pBSEImgFileMgr.SetBSEImg(fldData.GetBSEImage());
-        //    int nId = fldData.GetId();
-        //    string sFieldId;
-        //    sFieldId = nId.ToString();
-     
-
-        //    string strBSEFilePathname = strFieldFileFolder + "\\" + m_pSampleRstFile.SMPL_MSR_RESULT_FIELDS_BSE + sFieldId + pBSEImgFileMgr.BMP_IMG_FILE_EXT;
-        //    if (!pBSEImgFileMgr.SaveIntoBitmap(strBSEFilePathname))
-        //    {
-        //        log.Info("SaveFieldFiles: save BSE file failed.");
-        //        return false;
-        //    }
-
-        //    // IncA Data list
-
-        //    CIncAFileMgr pDBFileMgr = m_pSampleRstFile.DBFileMgr;
-
-
-
-        
-        //    pDBFileMgr.SaveStatusDataToDB();
-        //    var fldDB = pDBFileMgr.GetFieldDB();
-
-        //    fldDB.SaveAField(fldData.GetId(), fldData.GetOTSPosition(),fldData.SemPos);
-
-
-
-
-
-        //    var analysisParts = fldData.GetListAnalysisParticles();
-        //    if (!pDBFileMgr.SaveIncADataToDB(analysisParts, fldData.GetOTSPosition()))
-        //    {
-        //        log.Info("SaveFieldFiles: save inclusion file failed.");
-        //        return false;
-        //    }
-        //    //save the xray data and element data.
-        //    CPosXrayDBMgr PosXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();
-        //    var m_listAnalysisPosXray = new List<CPosXrayClr>();
-           
-        //    foreach (var p in analysisParts)
-        //    {
-        //        m_listAnalysisPosXray.Add(p.GetXray());
-        //    }
-
-        //    if (!PosXrayDBMgr.SaveXray(m_listAnalysisPosXray, true))
-        //    {
-        //        log.Info("SaveFieldFiles: save analysis x-ray failed.");
-        //        return false;
-        //    }
-
-
-
-        //    //save the small particle info 
-        //    //CSmallParticleInfoDB smallPartDB = pDBFileMgr.GetSmallParticleInfoDB();
-        //    //Dictionary<int, List<COTSParticleClr>> mapSmallParts = new Dictionary<int, List<COTSParticleClr>>();
-        //    //foreach (COTSParticleClr smallP in fldData.ListSmallParticles)
-        //    //{
-        //    //    if (mapSmallParts.ContainsKey((int)smallP.GetType()))
-        //    //    {
-        //    //        mapSmallParts[(int)smallP.GetType()].Add(smallP);
-        //    //    }
-        //    //    else
-        //    //    {
-        //    //        var plist = new List<COTSParticleClr>();
-        //    //        plist.Add(smallP);
-        //    //        mapSmallParts.Add((int)smallP.GetType(), plist);
-
-        //    //    }
-
-        //    //}
-        //    //List<CSmallParticleInfo> smallparts = new List<CSmallParticleInfo>();
-
-        //    //foreach (KeyValuePair<int, List<COTSParticleClr>> particles in mapSmallParts)
-        //    //{
-        //    //    CSmallParticleInfo partInfo = new CSmallParticleInfo();
-        //    //    partInfo.FieldId = particles.Value[0].GetFieldId();
-        //    //    partInfo.AveGray = particles.Value[0].GetAveGray();
-        //    //    partInfo.Quantity = (int)(particles.Value.Count / fldData.SmallParticlePercentage);
-        //    //    partInfo.TypeId = particles.Key;
-        //    //    partInfo.TypeColor = particles.Value[0].GetTypeColor();
-        //    //    partInfo.TypeName = particles.Value[0].GetTypeName();
-        //    //    double area = 0;
-        //    //    foreach (var p in particles.Value)
-        //    //    {
-        //    //        area += p.GetActualArea();
-        //    //    }
-        //    //    //partInfo.Area = Convert.ToInt32(area / f.SmallParticlePercentage);
-        //    //    partInfo.Area =(int) area ;
-        //    //    smallparts.Add(partInfo);
-        //    //}
-        //    //List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
-        //    //foreach (CSmallParticleInfo smallp in smallparts)
-        //    //{
-        //    //  var cmd=  smallPartDB.SaveAKindOfSmallParticle(smallp, new CPosXrayClr(), new System.Drawing.Point(0, 0));
-        //    //    cmds.Add(cmd);
-        //    //}
-
-        //    //pDBFileMgr.ExecuteNonQueryBatch(ref cmds);
-
-        //    return true;
-        //}
+       
 
 
     }

+ 2 - 3
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CMeasure.cs

@@ -537,10 +537,9 @@ namespace OTSModelSharp
         // measure status
        public void SetMsrLoopStatus(otsdataconst.OTS_MSR_THREAD_STATUS a_nMsrLoopStatus)
         {
-            //if (a_nMsrLoopStatus >= otsdataconst.OTS_MSR_THREAD_STATUS.MIN && a_nMsrLoopStatus <= otsdataconst.OTS_MSR_THREAD_STATUS.MAX)
-            //{
+          
                 m_ThreadStatus.SetStatus( a_nMsrLoopStatus);
-            //}
+            
         }
 
     

+ 235 - 5
OTSIncAMeasureApp/0-OTSModel/Measure/3-MeasureFlow/CSmplMeasure.cs

@@ -14,6 +14,7 @@ using System.Threading;
 using OTSModelSharp.DTLBase;
 using OTSCLRINTERFACE;
 using OTSModelSharp.ServiceCenter;
+using OTSMeasureApp._0_OTSModel.Measure.ParamData;
 
 namespace OTSModelSharp
 {
@@ -475,11 +476,11 @@ namespace OTSModelSharp
             return pBSEImage;
         }
 
-        public virtual bool FieldImageProcess(Point fldCenter, CBSEImgClr imageData)
-        {
-            return true;
+        //public virtual bool FieldImageProcess(Point fldCenter, CBSEImgClr imageData)
+        //{
+        //    return true;
 
-        }
+        //}
         public virtual void ClassifyFieldParticles()
         {
             return;
@@ -782,7 +783,236 @@ namespace OTSModelSharp
             }
           
         }
+        public  bool FieldImageProcess(Point fldCenter, CBSEImgClr a_pBSEImg)
+        {
+            int nNewFieldId;
+            nNewFieldId = m_pSampleRstFile.GetIdForANewField();
+
+            // create a field
+            curFldData = new COTSFieldData(a_pBSEImg, m_Sample.CalculatePixelSize());
+            curFldData.SetId(nNewFieldId);
+            curFldData.SetOTSPosition(fldCenter);
+            CSEMStageData a_pCSEMStageData = m_pMsrThread.GetProjResultData().GetSEMStageData();
+            Point semPos = new Point();
+            a_pCSEMStageData.ConverOTSToSEMPoint(fldCenter, ref semPos);
+            curFldData.SemPos = semPos;
+
+            //first step:remove background of the bse image and compound all the finded particles.
+
+            log.Info("Begin to process image and get all particles!");
+            GetOriginalParticles();
+
+            // second step :filter the finded particles.
+            log.Info("Begin to filter particles!");
+
+            FilterParticles(curFldData);
+
+            CalculateParticleAbsolutPos();
+
+            log.Info("Begin to Calculate the image property of every particle!");
+            var analysisparts = curFldData.GetListAnalysisParticles();
+            curFldData.CalParticleImageProp(analysisparts);//calculate particle image property such as feret diameter, DMAX etc.
+
+            COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
+
+            if (pXRayParam.GetUsingXray() == true)
+            {
+                log.Info("Begin to collect particle's xray data!");
+                Thread.Sleep(100);
+                CollectParticlesXrayData(curFldData);
+
+                Thread.Sleep(100);
+            }
+
+
+            log.Info("Begin to classify particles! particle num:" + curFldData.GetListAnalysisParticles().Count);
+            ClassifyFieldParticles();
+
+
+
+            // save field files
+            m_Sample.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.SUCCESSED);
+
+            StartSaveFileThread(curFldData);
+
+            return true;
+
+        }
+        public void GetOriginalParticles()
+        {
+            // measure status
+            CMsrSampleStatus pStatus = m_Sample.GetMsrStatus();
+
+            // get image process parameter
+            CSampleParam pMsrParam = m_Sample.GetMsrParams();
+            COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
+            var specialPartsparam = pMsrParam.GetSpecialGrayRangeParam();
+            var pixelsize = m_Sample.CalculatePixelSize();
+            if (specialPartsparam.GetIsToRun())
+            {
+                List<CSpecialGrayRange> ranges = pMsrParam.GetSpecialGrayRangeParam().GetSpecialGreyRanges();
+                foreach (var grayRange in ranges)
+                {
+                    CIntRangeClr range = new CIntRangeClr(grayRange.range.GetStart(), grayRange.range.GetEnd());
+                    CDoubleRangeClr diaRange = new CDoubleRangeClr(grayRange.diameterRange.GetStart(), grayRange.diameterRange.GetEnd());
+                    curFldData.GetPartsBySpecialGray(range, diaRange, pixelsize, grayRange.ifCollectXray);
+                }
+            }
+            var ifCollectxray = pMsrParam.GetXRayParam().GetUsingXray();
+            // remove BES image background
+            curFldData.RemoveImgBGAndGetParticles(pImgProcessParam, pixelsize, ifCollectxray);
+
+
+            // check if this is an empty image
+            if (curFldData.NoParticle())
+            { // empty fields
+                log.Info("ImageProcess: empty field.");
+
+            }
+            return;
+        }
+        public void FilterParticles(COTSFieldData fld)
+        {
+
+            if (fld.NoAnalysisParticle())
+            {
+                log.Warn("There's no analysis particles!");
+                return;
+            }
+            CSampleParam pMsrParam = m_Sample.GetMsrParams();
+            COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
+            double dPixelSize = m_Sample.CalculatePixelSize();
+            curFldData.InitParticles(pImgProcessParam, dPixelSize);
+
+
+
+            
+
+           
+
+            var listXray = curFldData.GetAllParticles().OrderByDescending(x => x.GetActualArea()).ToList();
+            var listXray1 = new List<COTSParticleClr>();
+            var pXRayParam = pMsrParam.GetXRayParam();
+            if (listXray.Count > pXRayParam.GetXrayLimit())
+            {
+                for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
+                {
+
+                    listXray1.Add(listXray[i]);
+                }
+
+            }
+            else
+            {
+                listXray1 = listXray;
+            }
 
+            curFldData.SetListAnalysisParticles(listXray1);
+
+            log.Info("Analysis particles:"+ listXray1.Count);
+           
+
+           
+
+            //2) according to the quantify threshold size value saperate the analysis particles into two group :the bigparticles and the smallparticles.
+
+            double quantifyThreshold = m_Sample.GetMsrParams().GetXRayParam().GetFeatureModeMinSize();
+
+            var smallparts = fld.ListSmallParticles;
+            var bigparts = fld.ListBigParticles;
+
+
+            foreach (var part in listXray1)
+            {
+                double equalCircleDiameter = Math.Sqrt(part.GetActualArea() / 3.14159) * 2f;
+                if (equalCircleDiameter < quantifyThreshold)
+                {
+                    smallparts.Add(part);
+                }
+                else
+                {
+                    bigparts.Add(part);
+                }
+            }
+
+
+            fld.ListSmallParticles = smallparts;
+            fld.ListBigParticles = bigparts;
+            //fld.SmallParticlePercentage=percentage;
+            log.Info("SmallQuantifyParts (<" + quantifyThreshold.ToString("f2") + "): " + smallparts.Count);
+            log.Info("BigQuantifyParts (>=" + quantifyThreshold.ToString("f2") + "): " + bigparts.Count);
+
+            return;
+        }
+        public void CollectParticlesXrayData(COTSFieldData fld)
+        {
+            // get x-ray parameters
+            COTSXRayParam pXRayParam = m_Sample.GetMsrParams().GetXRayParam();
+
+            // calculate search x-ray acquire time
+            uint nXRayAQTime;
+            List<COTSParticleClr> smallparts = new List<COTSParticleClr>();
+            List<COTSParticleClr> bigparts = new List<COTSParticleClr>();
+
+            foreach (var p in fld.ListSmallParticles)
+            {
+                if (p.IsXrayParticle())
+                {
+                    smallparts.Add(p);
+                }
+            }
+            foreach (var p in fld.ListBigParticles)
+            {
+                if (p.IsXrayParticle())
+                {
+                    bigparts.Add(p);
+                }
+            }
+            
+
+
+            var pStatus = m_Sample.GetMsrStatus();
+            curFldData.CreateXrayList(bigparts); // big particle using the full xray strategy.
+
+
+            curFldData.CreateXrayList(smallparts); //small particle using the fast xray strategy
+
+            if (bigparts.Count > 0)
+            {
+
+
+                var workmode = pXRayParam.GetScanMode();
+                // get x-ray list (analysis) by particle features
+                if (workmode == OTS_X_RAY_SCAN_MODE.FeatureMode)
+                {
+                    nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
+                    m_EDSHardwareMgr.GetXRayByFeatures(bigparts, nXRayAQTime, true);
+
+                }
+                else
+                {
+                    nXRayAQTime = (uint)pXRayParam.GetMidAnalyAQTime();
+                    m_EDSHardwareMgr.GetXRayByPoints(bigparts, nXRayAQTime, true);
+                }
+            }
+
+
+
+
+            if (smallparts.Count > 0)
+            {
+                nXRayAQTime = (uint)pXRayParam.GetFastXrayTime();
+
+                // get x-ray list (analysis) by points
+                m_EDSHardwareMgr.GetXRayByPoints(smallparts, nXRayAQTime, true);
+
+            }
+
+
+
+
+            return;
+        }
         public void DoHolePreview(int a_nHoleID)
         {
             using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
@@ -995,7 +1225,7 @@ namespace OTSModelSharp
             CMsrDisplayResults pMsrResults = m_Sample.GetMsrResults();
 
             // cumulate field data info
-            //pMsrResults.CumulateMeasureResults(listResultItems);
+        
             pMsrResults.CumulateMeasuredArea(a_nMeasuredArea);
 
             // cumulate ratio

+ 41 - 21
OTSIncAMeasureApp/0-OTSModel/Measure/BSEPicData/COTSFieldData.cs

@@ -30,9 +30,16 @@ namespace OTSModelSharp
 
        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 conform particles.
+       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_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;
 
@@ -44,12 +51,26 @@ namespace OTSModelSharp
         public Point SemPos { get => m_semPos; set => m_semPos = value; }
 
         private Point 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)
@@ -119,15 +140,16 @@ namespace OTSModelSharp
             m_pBSEImg = a_pBSEImg;
         }
 
-        public void RemoveImgBGAndGetParticles(COTSImageProcParam a_pImageProcessParam,double a_pixelSize)
+        public void RemoveImgBGAndGetParticles(COTSImageProcParam a_pImageProcessParam,double a_pixelSize,bool ifXray)
         {
             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);
-                m_listXrayParticles.Add(p);
+               
             }
            
             return ;
@@ -139,11 +161,9 @@ namespace OTSModelSharp
             imghandler.GetParticlesBySpecialGray(m_pBSEImg, grayRange,diameterRange,pixelSize, ref specialParts);
             foreach (var p in specialParts)
             {
+                p.SetIsXrayParticle(ifXray);
                 m_listAllParticles.Add(p);
-                if (ifXray)
-                {
-                    m_listXrayParticles.Add(p);
-                }
+               
             }
 
             return;
@@ -175,7 +195,7 @@ namespace OTSModelSharp
             //int tooSmallnum = 0;
          
             //int overSizenum = 0;
-            log.Info("Total Particles: " + m_listAllParticles.Count);
+            //log.Info("Total Particles: " + m_listAllParticles.Count);
             foreach (COTSParticleClr pParticle in m_listAllParticles)//m_listAllParticles memorize all the particles .
             {
                
@@ -190,24 +210,24 @@ namespace OTSModelSharp
               
                 pParticle.SetAnalysisId(nTagId); // the same as the tagId no use now.  
                 nTagId++;
-                m_listAnalysisParticles.Add(pParticle);
+                //m_listAnalysisParticles.Add(pParticle);
                
             }
-            log.Info("Normal Particles (>"+ oAreaRange.GetStart().ToString("f2") + "): "+ "<" + oAreaRange.GetEnd().ToString("f2") + "): " + m_listAnalysisParticles.Count);
+            log.Info("Total Particles: (>" + oAreaRange.GetStart().ToString("f2") + "): "+ "<" + oAreaRange.GetEnd().ToString("f2") + "): " + m_listAllParticles.Count);
            
 
-            List<COTSParticleClr> xrayParts = new List<COTSParticleClr>();
-            foreach (var p in m_listXrayParticles)//m_listXrayParticles memorize all the particles which needs xray analysis.
-            {
-                if (p.GetTagId() > -1)//it has been initialized and it's a valid particle.
-                {
-                    xrayParts.Add(p);
+            //List<COTSParticleClr> xrayParts = new List<COTSParticleClr>();
+            //foreach (var p in m_listXrayParticles)//m_listXrayParticles memorize all the particles which needs xray analysis.
+            //{
+            //    if (p.GetTagId() > -1)//it has been initialized and it's a valid particle.
+            //    {
+            //        xrayParts.Add(p);
 
 
-                }
+            //    }
             
-            }
-            m_listXrayParticles = xrayParts;
+            //}
+            //m_listXrayParticles = xrayParts;
 
         }
        
@@ -252,7 +272,7 @@ namespace OTSModelSharp
         public bool NoAnalysisParticle()
         {
 
-            if (m_listAnalysisParticles.Count == 0)
+            if (m_listAllParticles.Count == 0)
             {
                 return true;
             }