OxfordEDSController.cs 8.2 KB

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