OxfordEDSController.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using FEIApiControl;
  2. using OTSCLRINTERFACE;
  3. using OxfordExtenderWrapper;
  4. using OTSModelSharp.ServiceCenter;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Runtime.Remoting.Channels.Ipc;
  10. using System.Runtime.Remoting.Channels;
  11. using OTSMeasureApp.ServiceCenter.OxfordExtender;
  12. namespace OTSMeasureApp.ServiceCenter
  13. {
  14. class OxfordEDSController : IEDSController
  15. {
  16. ExtenderIpcUI iExtender;
  17. private int AnalyExpCount = 100000;
  18. private string strResolution = "";
  19. public ExtenderIpcUI GetIExtender()
  20. {
  21. return iExtender;
  22. }
  23. public void SetIExtender(ExtenderIpcUI value)
  24. {
  25. iExtender = value;
  26. }
  27. public OxfordEDSController( int MaxCounts,bool ifautoid, string knownelements)
  28. {
  29. iExtender = ExtenderWrapperIpc.GetExtenderWrapper();
  30. iExtender.SetQuantifiCationParam1(ifautoid, knownelements);
  31. SetAnalyExpCount(MaxCounts);
  32. }
  33. public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
  34. {
  35. iExtender = ExtenderWrapperIpc.GetExtenderWrapper();
  36. List<AreaXrayParam> areaPrms = new List<AreaXrayParam>();
  37. foreach (var part in a_listParticles)
  38. {
  39. var p = new AreaXrayParam();
  40. p.dMilliSecondsTime = a_nXRayAQTime;
  41. var feas = part.GetFeature().GetSegmentsList();
  42. foreach (var f in feas)
  43. {
  44. p.a_listChord.Add(new Segment() { X = f.GetStart(), Y = f.GetHeight(), Length = f.GetLength() });
  45. }
  46. areaPrms.Add(p);
  47. }
  48. NLog.LogManager.GetCurrentClassLogger().Info("Begin to acquire feature xray data :" + areaPrms.Count);
  49. iExtender.CollectXrayByFeatures(ref areaPrms, a_nXRayAQTime, a_bElementInfo);
  50. NLog.LogManager.GetCurrentClassLogger().Info("End acquiring feature xray data :" + areaPrms.Count);
  51. for (int i = 0; i < a_listParticles.Count; i++)
  52. {
  53. CPosXrayClr xray = a_listParticles[i].GetXray();
  54. xray.SetXrayData(areaPrms[i].XrayData);
  55. var listElement = areaPrms[i].listElement;
  56. List<CElementChemistryClr> chelist = new List<CElementChemistryClr>();
  57. foreach (var ele in listElement)
  58. {
  59. var che = new CElementChemistryClr();
  60. che.SetName(ele.Key);
  61. che.SetPercentage(ele.Value);
  62. chelist.Add(che);
  63. }
  64. xray.SetElementQuantifyData(chelist);
  65. a_listParticles[i].SetXray(xray);
  66. }
  67. return true;
  68. }
  69. public bool GetXRayByParts(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
  70. {
  71. iExtender = ExtenderWrapperIpc.GetExtenderWrapper();
  72. List<PointXrayParam> pointXrayPrms = new List<PointXrayParam>();
  73. foreach (var part in a_listParticles)
  74. {
  75. var p = new PointXrayParam();
  76. p.dMilliSecondsTime = a_nXRayAQTime;
  77. var Pos = (Point)(part.GetXRayPos());
  78. p.x = Pos.X;
  79. p.y = Pos.Y;
  80. pointXrayPrms.Add(p);
  81. }
  82. NLog.LogManager.GetCurrentClassLogger().Info("Begin to acquire point xray data :"+ pointXrayPrms.Count);
  83. iExtender.CollectXrayByPoints(ref pointXrayPrms, a_nXRayAQTime, a_bElementInfo);
  84. NLog.LogManager.GetCurrentClassLogger().Info("End acquiring point xray data :" + pointXrayPrms.Count);
  85. for (int i = 0; i < a_listParticles.Count; i++)
  86. {
  87. CPosXrayClr xray = a_listParticles[i].GetXray();
  88. xray.SetXrayData(pointXrayPrms[i].XrayData);
  89. var listElement = pointXrayPrms[i].listElement;
  90. List<CElementChemistryClr> chelist = new List<CElementChemistryClr>();
  91. foreach (var ele in listElement)
  92. {
  93. var che = new CElementChemistryClr();
  94. che.SetName(ele.Key);
  95. che.SetPercentage(ele.Value);
  96. chelist.Add(che);
  97. }
  98. xray.SetElementQuantifyData(chelist);
  99. a_listParticles[i].SetXray(xray);
  100. }
  101. return true;
  102. }
  103. public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
  104. {
  105. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  106. var p = new PointXrayParam();
  107. p.x = 10;
  108. p.y = 10;
  109. p.dMilliSecondsTime = a_nXRayAQTime;
  110. if (iExtender.XrayPointCollecting(ref p))
  111. {
  112. a_XrayData = p.XrayData;
  113. return true;
  114. }
  115. else
  116. {
  117. a_XrayData = p.XrayData;
  118. return false;
  119. }
  120. }
  121. public bool Connect()
  122. {
  123. iExtender = ExtenderWrapperIpc.GetExtenderWrapper();
  124. return true;
  125. }
  126. private bool SetAnalyExpCount(int MaxCounts)
  127. {
  128. AnalyExpCount = MaxCounts;
  129. return true;
  130. }
  131. public EDSTYPE GetEDSType()
  132. {
  133. return EDSTYPE.OXFORD;
  134. }
  135. public void SetFilterKeyEleNames(List<string> KeyNameList)
  136. {
  137. throw new NotImplementedException();
  138. }
  139. public bool QuantifyXrayByParts(List<COTSParticleClr> a_listParticles)
  140. {
  141. return true;
  142. }
  143. void IEDSController.SetResolution(int resolutionWidth, int resolutionHeight)
  144. {
  145. return;
  146. }
  147. public bool QuantifyXrayByPart(COTSParticleClr part)
  148. {
  149. return true;
  150. }
  151. public int GetExpectCount()
  152. {
  153. return AnalyExpCount;
  154. }
  155. //public bool GetIfDelayQuantify()
  156. //{
  157. // return false;
  158. //}
  159. public void SetQuantifiCationParam(bool IfAutoId, string knownElements)
  160. {
  161. iExtender.SetQuantifiCationParam1(IfAutoId, knownElements);
  162. }
  163. public bool GetXRayByExpandFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
  164. {
  165. List<AreaXrayParam> areaPrms = new List<AreaXrayParam>();
  166. foreach (var part in a_listParticles)
  167. {
  168. var p = new AreaXrayParam();
  169. p.dMilliSecondsTime = a_nXRayAQTime;
  170. var feas = part.GetFeature().GetSegmentsList();
  171. foreach (var f in feas)
  172. {
  173. var len = f.GetLength();
  174. var start = f.GetStart() - len*2;
  175. if (start < 0)
  176. {
  177. start = 0;
  178. }
  179. len = len * 3;
  180. p.a_listChord.Add(new Segment() { X = start, Y = f.GetHeight(), Length =len });
  181. }
  182. areaPrms.Add(p);
  183. }
  184. NLog.LogManager.GetCurrentClassLogger().Info("Begin to acquire feature xray data :" + areaPrms.Count);
  185. iExtender.CollectXrayByFeatures(ref areaPrms, a_nXRayAQTime, a_bElementInfo);
  186. NLog.LogManager.GetCurrentClassLogger().Info("End acquiring feature xray data :" + areaPrms.Count);
  187. for (int i = 0; i < a_listParticles.Count; i++)
  188. {
  189. CPosXrayClr xray = a_listParticles[i].GetXray();
  190. xray.SetXrayData(areaPrms[i].XrayData);
  191. var listElement = areaPrms[i].listElement;
  192. List<CElementChemistryClr> chelist = new List<CElementChemistryClr>();
  193. foreach (var ele in listElement)
  194. {
  195. var che = new CElementChemistryClr();
  196. che.SetName(ele.Key);
  197. che.SetPercentage(ele.Value);
  198. chelist.Add(che);
  199. }
  200. xray.SetElementQuantifyData(chelist);
  201. a_listParticles[i].SetXray(xray);
  202. }
  203. return true;
  204. }
  205. }
  206. }