Browse Source

add particleSelectCondition function to filter particles further.

gsp 1 year ago
parent
commit
493a9be16e

+ 46 - 15
OTSIncAMeasureApp/0-OTSModel/OTSDataType/COTSImageProcParam.cs

@@ -1,5 +1,4 @@
-//using OTSMeasureApp._0_OTSModel.Measure.ParamData;
-using OTSMeasureApp._0_OTSModel.OTSDataType;
+using OTSMeasureApp._0_OTSModel.OTSDataType;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -23,10 +22,43 @@ namespace OTSDataType
         private CIntRange m_oParticleGray = new CIntRange();
         private OTS_BGREMOVE_TYPE m_BGRemoveType;
         private OTS_AUTOBGREMOVE_TYPE m_autoBGRemoveType;
-      
         int m_OverlapParam;
 
         private CSpecialGrayRangeParam m_specialGreyRangeParam;
+        private string particleSelectCondition = "";
+
+        public string GetParticleSelectCondition()
+        {
+            return particleSelectCondition;
+        }
+        public Dictionary<string, CDoubleRange> GetParticleSelConditionDic()
+        {
+            Dictionary<string, CDoubleRange> dic = new Dictionary<string, CDoubleRange>();
+            if (particleSelectCondition != "" && particleSelectCondition!=null)
+            {
+                var conditionstrs = particleSelectCondition.Split(',');
+               
+                foreach (var singlecondition in conditionstrs)
+                {
+                    string conditionName = singlecondition.Split(':')[0];
+                    string condition = singlecondition.Split(':')[1];
+                    CDoubleRange rng = new CDoubleRange();
+                    rng.SetStart(Convert.ToDouble(condition.Split('-')[0]));
+                    rng.SetEnd(Convert.ToDouble(condition.Split('-')[1]));
+                    dic.Add(conditionName, rng);
+                }
+              
+
+            }
+            return dic;
+        
+        }
+
+        public void SetParticleSelectCondition(string value)
+        {
+            particleSelectCondition = value;
+        }
+
 
         public CSpecialGrayRangeParam GetSpecialGreyRangeParam()
         {
@@ -60,8 +92,7 @@ namespace OTSDataType
             m_oBGGray = new CIntRange(DEFUALT_BG_GRAY_LEVEL_MIN, DEFUALT_BG_GRAY_LEVEL_MAX);
             m_oParticleGray = new CIntRange(DEFUALT_PARTICLE_GRAY_LEVEL_MIN, DEFUALT_PARTICLE_GRAY_LEVEL_MAX);
             m_BGRemoveType = OTS_BGREMOVE_TYPE.MANUAL;// OTS_BGREMOVE_TYPE.AUTO;
-            m_autoBGRemoveType = OTS_AUTOBGREMOVE_TYPE.MIDDLE;
-            //m_errodDilateParam = 3;
+            m_autoBGRemoveType = OTS_AUTOBGREMOVE_TYPE.MIDDLE;           
             m_OverlapParam = 20;
         }
         public CDoubleRange GetIncAreaRange() { return m_oIncArea; }
@@ -81,9 +112,7 @@ namespace OTSDataType
 
         public void SetAutoBGRemoveType(OTS_AUTOBGREMOVE_TYPE a_oVal) { m_autoBGRemoveType = a_oVal; }
 
-        //public int GetErrodDilateParam() { return m_errodDilateParam; }
-
-        //public void SetErrodDilateParam(int a_oVal) { m_errodDilateParam = a_oVal; }
+       
 
         public int GetOverlapParam() { return m_OverlapParam; }
 
@@ -103,7 +132,7 @@ namespace OTSDataType
             m_oParticleGray.SetEnd(a_oSource.m_oParticleGray.GetEnd());
             m_BGRemoveType = a_oSource.m_BGRemoveType;
             m_autoBGRemoveType = a_oSource.m_autoBGRemoveType;
-            //m_errodDilateParam = a_oSource.m_errodDilateParam;
+            SetParticleSelectCondition(a_oSource.GetParticleSelectCondition());
             m_OverlapParam = a_oSource.m_OverlapParam;
 
 
@@ -115,7 +144,7 @@ namespace OTSDataType
             return m_oIncArea == a_oSource.m_oIncArea &&
                 m_oBGGray == a_oSource.m_oBGGray &&
                 m_oParticleGray == a_oSource.m_oParticleGray &&
-                //m_errodDilateParam == a_oSource.m_errodDilateParam&&
+               
                 m_OverlapParam == a_oSource.m_OverlapParam;
 
         }
@@ -132,9 +161,6 @@ namespace OTSDataType
            
             slo.Register("ParticleGray", m_oParticleGray);
 
-            xInt xnCorrosionExpansionCoefficient = new xInt();
-            slo.Register("ErrodDilateParam", xnCorrosionExpansionCoefficient);
-
             xInt xnOverlapParam = new xInt();
             slo.Register("OverlapParam", xnOverlapParam);
 
@@ -144,13 +170,17 @@ namespace OTSDataType
             slo.Register("BGRemoveType", xnBGRemoveType);
             slo.Register("AutoBGRemoveType", xnautoBGRemoveType);
 
+            xString xpartselcondition = new xString();
+            slo.Register("ParticleSelectionCondition", xpartselcondition);
+
             if (isStoring)
             {
 
                 xnBGRemoveType.AssignValue((int)m_BGRemoveType+":"+m_BGRemoveType.ToString());
                 xnautoBGRemoveType.AssignValue((int)m_autoBGRemoveType+":"+m_autoBGRemoveType.ToString());
-                //xnCorrosionExpansionCoefficient.AssignValue(m_errodDilateParam);
+               
                 xnOverlapParam.AssignValue(m_OverlapParam);
+                xpartselcondition.AssignValue(GetParticleSelectCondition());
                 slo.Serialize(true, classDoc, rootNode);
             }
             else
@@ -159,8 +189,9 @@ namespace OTSDataType
                 //自动去背景设置
                 m_BGRemoveType = (OTS_BGREMOVE_TYPE)Convert.ToInt32( xnBGRemoveType.value().Split(':')[0]);
                 m_autoBGRemoveType = (OTS_AUTOBGREMOVE_TYPE)Convert.ToInt32( xnautoBGRemoveType.value().Split(':')[0]);
-                //m_errodDilateParam = Convert.ToInt32(xnCorrosionExpansionCoefficient.value());
+              
                 m_OverlapParam = Convert.ToInt32(xnOverlapParam.value());
+                SetParticleSelectCondition(xpartselcondition.value());
             }
         }
     }

+ 112 - 2
OTSIncAMeasureApp/1-OTSMeasure/Measure/3-MeasureFlow/CSmplMeasure.cs

@@ -803,7 +803,7 @@ namespace OTSModelSharp
             {
                 try
                 {
-                    string userdBpath= Application.StartupPath + "\\Config\\SysData\\" + m_Sample.GetMsrParams().GetSTDName() + ".db";
+                    string userdBpath= System.Windows.Forms.Application.StartupPath + "\\Config\\SysData\\" + m_Sample.GetMsrParams().GetSTDName() + ".db";
                     File.Copy(userdBpath, m_pSampleRstFile.GetFieldFileSubFolderStr().Remove(m_pSampleRstFile.GetFieldFileSubFolderStr().IndexOf("FIELD_FILES")) + m_Sample.GetMsrParams().GetSTDName() + ".db", true);
                 }
                 catch(Exception ex)
@@ -842,6 +842,9 @@ namespace OTSModelSharp
             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.
+
+            SelectParticles(ref curFldData);
+            
             CSampleParam pMsrParam = m_Sample.GetMsrParams();
             COTSImageProcParam pImgProcessParam = pMsrParam.GetImageProcessParam();
             var overlap = pImgProcessParam.GetOverlapParam();
@@ -862,7 +865,7 @@ namespace OTSModelSharp
 
         private void FilterParticles(ref COTSField curFldData)
         {
-          
+            log.Info("filter particle according to xraylimit");
             var listXray = curFldData.GetAllParticles().OrderByDescending(x => x.GetActualArea()).ToList();
             var listXray1 = new List<COTSParticleClr>();
             var pXRayParam =m_Sample.GetMsrParams().GetXRayParam();
@@ -886,7 +889,114 @@ namespace OTSModelSharp
 
 
         }
+        private void SelectParticles(ref COTSField curFldData)
+        {
+            var selconditiondic = m_Sample.GetMsrParams().GetImageProcessParam().GetParticleSelConditionDic();
+            var listselparts = new List<COTSParticleClr>();
+            var excludeparts= new List<COTSParticleClr>();
+            if (selconditiondic.ContainsKey("dmax"))
+            {
+                log.Info("Select particles according to dmax");
+                var rng = selconditiondic["dmax"];
+                foreach (var p in curFldData.GetListAnalysisParticles())
+                {
+                    if (p.GetDMAX() < rng.GetStart() || p.GetDMAX() >= rng.GetEnd())
+                    {
+                        excludeparts.Add(p);
+                    }
+                    else 
+                    {
+                        log.Info("dmax=" + p.GetDMAX().ToString("F2"));
+                    }
+                
+                }
+            
+            }
+            if (selconditiondic.ContainsKey("dmin"))
+            {
+                log.Info("Select particles according to dmin");
+                var rng = selconditiondic["dmin"];
+                foreach (var p in curFldData.GetListAnalysisParticles())
+                {
+                    if (p.GetDMIN() < rng.GetStart() || p.GetDMIN() >= rng.GetEnd())
+                    {
+                        if (!excludeparts.Contains(p))
+                        {
+                            excludeparts.Add(p);
+                        }
+                        else
+                        {
+                            log.Info("dmin=" + p.GetDMIN().ToString("F2"));
+                        }
+                    }
+
+                }
+
+            }
+            if (selconditiondic.ContainsKey("orientation"))
+            {
+                log.Info("Select particles according to orientation");
+                var rng = selconditiondic["orientation"];
+                foreach (var p in curFldData.GetListAnalysisParticles())
+                {
+                    if (p.GetORIENTATION() < rng.GetStart() || p.GetORIENTATION() >= rng.GetEnd())
+                    {
+                        if (!excludeparts.Contains(p))
+                        {
+                            excludeparts.Add(p);
+                        }
+                        else
+                        {
+                            log.Info("orientation=" + p.GetORIENTATION().ToString("F2"));
+                        }
 
+                    }
+                   
+
+                }
+
+            }
+            if (selconditiondic.ContainsKey("aspect"))
+            {
+                log.Info("Select particles according to aspect");
+                var rng = selconditiondic["aspect"];
+                foreach (var p in curFldData.GetListAnalysisParticles())
+                {
+                    double aspect = p.GetDMAX() / p.GetDMIN();
+                    if (aspect < rng.GetStart() || aspect >= rng.GetEnd())
+                    {
+                        if (!excludeparts.Contains(p))
+                        {
+                            excludeparts.Add(p);
+                        }
+                        else
+                        {
+                            log.Info("aspect=" + aspect.ToString("F2"));
+                        }
+
+                    }
+
+
+                }
+
+            }
+
+            foreach (var p in curFldData.GetListAnalysisParticles())
+            {
+                if (!excludeparts.Contains(p))
+                {
+                    listselparts.Add(p);
+                }
+            
+            }
+
+
+            curFldData.SetListAnalysisParticles(listselparts);
+
+            log.Info("Analysis particles:" + listselparts.Count);
+
+
+        }
         public void GetOriginalParticles(ref COTSField curFldData)
         {