COTSImageProcParam.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using OTSMeasureApp._0_OTSModel.OTSDataType;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. using static OTSDataType.otsdataconst;
  9. namespace OTSDataType
  10. {
  11. public class COTSImageProcParam : ISlo
  12. {
  13. int DEFUALT_PARTICALE_AREA_MIN = 1;
  14. int DEFUALT_PARTICALE_AREA_MAX = 200;
  15. int DEFUALT_BG_GRAY_LEVEL_MIN = 150;
  16. int DEFUALT_BG_GRAY_LEVEL_MAX = 255;
  17. int DEFUALT_PARTICLE_GRAY_LEVEL_MIN = 5;
  18. int DEFUALT_PARTICLE_GRAY_LEVEL_MAX = 155;
  19. private CDoubleRange m_oIncArea = new CDoubleRange();
  20. private CIntRange m_oBGGray = new CIntRange();
  21. private CIntRange m_oParticleEigenGray = new CIntRange();
  22. private OTS_BGREMOVE_TYPE m_BGRemoveType;
  23. private OTS_AUTOBGREMOVE_TYPE m_autoBGRemoveType;
  24. int m_OverlapParam;
  25. private CSpecialGrayRangeParam m_specialGreyRangeParam;
  26. private string particleSelectCondition = "";
  27. private double matrixStep = 1;
  28. public double MatrixStep { get => matrixStep; set => matrixStep = value; }
  29. public string GetParticleSelectCondition()
  30. {
  31. return particleSelectCondition;
  32. }
  33. public Dictionary<string, CDoubleRange> GetParticleSelConditionDic()
  34. {
  35. Dictionary<string, CDoubleRange> dic = new Dictionary<string, CDoubleRange>();
  36. if (particleSelectCondition != "" && particleSelectCondition!=null)
  37. {
  38. var conditionstrs = particleSelectCondition.Split(',');
  39. foreach (var singlecondition in conditionstrs)
  40. {
  41. string conditionName = singlecondition.Split(':')[0];
  42. string condition = singlecondition.Split(':')[1];
  43. CDoubleRange rng = new CDoubleRange();
  44. rng.SetStart(Convert.ToDouble(condition.Split('-')[0]));
  45. rng.SetEnd(Convert.ToDouble(condition.Split('-')[1]));
  46. dic.Add(conditionName, rng);
  47. }
  48. }
  49. return dic;
  50. }
  51. public void SetParticleSelectCondition(string value)
  52. {
  53. particleSelectCondition = value;
  54. }
  55. public CSpecialGrayRangeParam GetSpecialGreyRangeParam()
  56. {
  57. if (m_specialGreyRangeParam == null)
  58. {
  59. m_specialGreyRangeParam = new CSpecialGrayRangeParam();
  60. }
  61. return m_specialGreyRangeParam;
  62. }
  63. public void SetSpecialGreyRangeParam(CSpecialGrayRangeParam value)
  64. {
  65. m_specialGreyRangeParam = value;
  66. }
  67. public COTSImageProcParam()
  68. {
  69. Init();
  70. }
  71. public COTSImageProcParam(COTSImageProcParam a_oSource)
  72. {
  73. Init();
  74. // copy data over
  75. Duplicate(a_oSource);
  76. }
  77. public void Init()
  78. {
  79. m_specialGreyRangeParam = new CSpecialGrayRangeParam();
  80. m_oIncArea = new CDoubleRange(DEFUALT_PARTICALE_AREA_MIN, DEFUALT_PARTICALE_AREA_MAX);
  81. m_oBGGray = new CIntRange(DEFUALT_BG_GRAY_LEVEL_MIN, DEFUALT_BG_GRAY_LEVEL_MAX);
  82. m_oParticleEigenGray = new CIntRange(DEFUALT_PARTICLE_GRAY_LEVEL_MIN, DEFUALT_PARTICLE_GRAY_LEVEL_MAX);
  83. m_BGRemoveType = OTS_BGREMOVE_TYPE.MANUAL;// OTS_BGREMOVE_TYPE.AUTO;
  84. m_autoBGRemoveType = OTS_AUTOBGREMOVE_TYPE.MIDDLE;
  85. m_OverlapParam = 20;
  86. }
  87. public CDoubleRange GetIncAreaRange() { return m_oIncArea; }
  88. public void SetIncAreaRange(CDoubleRange a_oVal) { m_oIncArea = a_oVal; }
  89. public CIntRange GetBGGray() { return m_oBGGray; }
  90. public void SetBGGray(CIntRange a_oVal) { m_oBGGray = a_oVal; }
  91. public CIntRange GetParticleGray() { return m_oParticleEigenGray; }
  92. public void SetParticleGray(CIntRange a_oVal) { m_oParticleEigenGray = a_oVal; }
  93. public OTS_BGREMOVE_TYPE GetBGRemoveType() { return m_BGRemoveType; }
  94. public void SetBGRemoveType(OTS_BGREMOVE_TYPE a_oVal) { m_BGRemoveType = a_oVal; }
  95. public OTS_AUTOBGREMOVE_TYPE GetAutoBGRemoveType() { return m_autoBGRemoveType; }
  96. public void SetAutoBGRemoveType(OTS_AUTOBGREMOVE_TYPE a_oVal) { m_autoBGRemoveType = a_oVal; }
  97. public int GetOverlapParam() { return m_OverlapParam; }
  98. public void SetOverlapParam(int overlap) { m_OverlapParam = overlap; }
  99. public void Duplicate(COTSImageProcParam a_oSource)
  100. {
  101. // copy data over
  102. m_oIncArea.SetStart(a_oSource.m_oIncArea.GetStart());
  103. m_oIncArea.SetEnd(a_oSource.m_oIncArea.GetEnd());
  104. m_oBGGray.SetStart(a_oSource.m_oBGGray.GetStart());
  105. m_oBGGray.SetEnd(a_oSource.m_oBGGray.GetEnd());
  106. m_oParticleEigenGray.SetStart(a_oSource.m_oParticleEigenGray.GetStart());
  107. m_oParticleEigenGray.SetEnd(a_oSource.m_oParticleEigenGray.GetEnd());
  108. m_BGRemoveType = a_oSource.m_BGRemoveType;
  109. m_autoBGRemoveType = a_oSource.m_autoBGRemoveType;
  110. SetParticleSelectCondition(a_oSource.GetParticleSelectCondition());
  111. m_OverlapParam = a_oSource.m_OverlapParam;
  112. matrixStep = a_oSource.matrixStep;
  113. }
  114. public bool Equals(COTSImageProcParam a_oSource)
  115. {
  116. // return test result
  117. return m_oIncArea == a_oSource.m_oIncArea &&
  118. m_oBGGray == a_oSource.m_oBGGray &&
  119. m_oParticleEigenGray == a_oSource.m_oParticleEigenGray &&
  120. m_OverlapParam == a_oSource.m_OverlapParam;
  121. }
  122. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  123. {
  124. Slo slo = new Slo();
  125. slo.Register("IncArea", m_oIncArea);
  126. slo.Register("BGGray", m_oBGGray);
  127. slo.Register("ParticleGray", m_oParticleEigenGray);
  128. xInt xnOverlapParam = new xInt();
  129. slo.Register("OverlapParam", xnOverlapParam);
  130. xString xnBGRemoveType = new xString();
  131. xString xnautoBGRemoveType = new xString();
  132. slo.Register("BGRemoveType", xnBGRemoveType);
  133. slo.Register("AutoBGRemoveType", xnautoBGRemoveType);
  134. xString xpartselcondition = new xString();
  135. slo.Register("ParticleSelectionCondition", xpartselcondition);
  136. xDouble xmatrixstep = new xDouble();
  137. slo.Register("MatrixStep", xmatrixstep);
  138. if (isStoring)
  139. {
  140. xnBGRemoveType.AssignValue((int)m_BGRemoveType+":"+m_BGRemoveType.ToString());
  141. xnautoBGRemoveType.AssignValue((int)m_autoBGRemoveType+":"+m_autoBGRemoveType.ToString());
  142. xnOverlapParam.AssignValue(m_OverlapParam);
  143. xpartselcondition.AssignValue(GetParticleSelectCondition());
  144. xmatrixstep.AssignValue(matrixStep);
  145. slo.Serialize(true, classDoc, rootNode);
  146. }
  147. else
  148. {
  149. slo.Serialize(false, classDoc, rootNode);
  150. //自动去背景设置
  151. m_BGRemoveType = (OTS_BGREMOVE_TYPE)Convert.ToInt32( xnBGRemoveType.value().Split(':')[0]);
  152. m_autoBGRemoveType = (OTS_AUTOBGREMOVE_TYPE)Convert.ToInt32( xnautoBGRemoveType.value().Split(':')[0]);
  153. m_OverlapParam = Convert.ToInt32(xnOverlapParam.value());
  154. MatrixStep = Convert.ToDouble(xmatrixstep.value());
  155. SetParticleSelectCondition(xpartselcondition.value());
  156. }
  157. }
  158. }
  159. }