123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
-
- using System;
- using System.Collections.Generic;
- namespace OTSModelSharp.ServiceCenter
- {
- using OTSCLRINTERFACE;
- using OTSMeasureApp.ServiceCenter;
- using System.Drawing;
-
- public class EDSController : IEDSController
- {
- private COTSControlFunExport eds;
- static IEDSController edsctrl = null;
- private List<String> keyElenamelist = new List<string>();
- public static IEDSController GetEDSController(int imgwidth,int imgheight,int expectCount)
- {
- if (edsctrl == null)
- {
- if (FileHelper.GetXMLInformations("EDSName") == "FEI")
- {
- edsctrl = new FEIEDSController(imgwidth,imgheight,expectCount);
- }
- else
- {
- edsctrl = new EDSController();
- }
-
-
- }
- return edsctrl;
- }
- private EDSController()
- {
-
- eds = OTSCLRINTERFACE.COTSControlFunExport.GetControllerInstance();
-
- }
- private void ProcessXrayInfo(COTSParticleClr partWithXrayInfo)//sometime the result will contain repeat percentage data for one element.It must be processed.
- {
- var eleChemistry = partWithXrayInfo.GetXray().GetElementQuantifyData();
- Dictionary<string, List<double>> eleInfoDic = new Dictionary<string, List<double>>();
- bool hasRepeatEle = false;
- foreach (var ele in eleChemistry)
- {
- if (eleInfoDic.ContainsKey(ele.GetName()))//contain repeat data;
- {
- eleInfoDic[ele.GetName()].Add(ele.GetPercentage());
- hasRepeatEle = true;
- }
- else
- {
- eleInfoDic.Add(ele.GetName(), new List<double>() { ele.GetPercentage() });
- }
- }
- if (hasRepeatEle)
- {
- Dictionary<string, double> resultInfo = new Dictionary<string, double>();
- foreach (var eleInfo in eleInfoDic)
- {
- double newPercentData=0;
- foreach (var p in eleInfo.Value)
- {
- newPercentData += p;
- }
- newPercentData = newPercentData / eleInfo.Value.Count;
- resultInfo.Add(eleInfo.Key, newPercentData);
- }
- foreach (var e in eleChemistry)
- {
- e.SetPercentage(resultInfo[e.GetName()]);
-
- }
- partWithXrayInfo.GetXray().SetElementQuantifyData(eleChemistry);
- }
- }
- public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
- {
- bool result = false;
-
- if (!eds.IsConnected())
- {
- return false;
- }
- if (keyElenamelist.Count > 0)
- {
- if (this.GetEDSType() == EDSTYPE.BRUKER)
- {
- List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
- for (int j = 0; j < keyElenamelist.Count; j++)
- {
- CElementChemistryClr chemistryClr = new CElementChemistryClr();
- chemistryClr.SetName(keyElenamelist[j]);
- elementChemistryClrs.Add(chemistryClr);
- }
- for (int i = 0; i < a_listParticles.Count; i++)
- {
- a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
- }
- }
- }
- COTSParticleClr[] parts = a_listParticles.ToArray();
- result= eds.GetXRayByFeatures((uint)a_nXRayAQTime, parts, a_bElementInfo);
- if (result == true)
- {
- foreach (var p in a_listParticles)
- {
- ProcessXrayInfo(p);
- }
- }
- return result;
- }
- public bool GetXRayByParts(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
- {
- bool result = false;
-
- if (!eds.IsConnected())
- {
- return false;
- }
- int xrayNum = a_listParticles.Count;
- Point[] Ps = new Point[xrayNum];
- for (int i = 0; i < xrayNum; i++)
- {
- Point p = (Point)a_listParticles[i].GetXRayPos();
- Ps[i].X = p.X;
- Ps[i].Y = p.Y;
- }
- if (keyElenamelist.Count > 0)
- {
- if (this.GetEDSType() == EDSTYPE.BRUKER)
- {
- List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
-
- for (int j = 0; j < keyElenamelist.Count; j++)
- {
- CElementChemistryClr chemistryClr = new CElementChemistryClr();
- chemistryClr.SetName(keyElenamelist[j]);
- elementChemistryClrs.Add(chemistryClr);
- }
- for (int i = 0; i < a_listParticles.Count; i++)
- {
-
- a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
- }
- }
- }
-
- int nSize = a_listParticles.Count;
- if (nSize > 1024)
- {
-
- COTSParticleClr[] partsTemp = new COTSParticleClr[1024];
- Point[] PsTemp = new Point[1024];
- int nTimes = nSize / 1024;
- for (int i = 0; i < nTimes; i++)
- {
- NLog.LogManager.GetCurrentClassLogger().Warn("begin 1024 batch");
- for (int m = 0; m < 1024; m++)
- {
- partsTemp[m]=a_listParticles[i * 1024 + m];
- PsTemp[m] = Ps[i * 1024 + m];
- }
- if (!eds.GetXRayByPoints(a_nXRayAQTime, PsTemp, partsTemp, a_bElementInfo))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("GetXRayByPoints: failed to get element.");
- return false;
- }
-
- }
- int nLast = nSize % 1024;
- if (nLast != 0)
- {
-
- COTSParticleClr[] lastParts = new COTSParticleClr[nLast];
- Point[] lastPs = new Point[nLast];
-
- for (int m = 0; m < nLast; m++)
- {
-
- lastParts[m] = a_listParticles[nTimes * 1024 + m];
- lastPs[m] = Ps[nTimes * 1024 + m];
- }
- if (!eds.GetXRayByPoints(a_nXRayAQTime, lastPs, lastParts, a_bElementInfo))
- {
- NLog.LogManager.GetCurrentClassLogger().Error("GetXRayByPoints: failed to get element.");
- return false;
- }
-
- }
- }
- else
- {
- COTSParticleClr[] parts = a_listParticles.ToArray();
- result = eds.GetXRayByPoints(a_nXRayAQTime, Ps, parts, a_bElementInfo);
- }
-
- if (result == true)
- {
- foreach (var p in a_listParticles)
- {
- ProcessXrayInfo(p);
- }
- }
- return result;
- }
-
- public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
- {
- if (!eds.IsConnected())
- {
- return false;
- }
- return eds.CollectSpectrum(a_nXRayAQTime, ref a_XrayData);
-
- }
- public bool Init()
- {
- if (!eds.IsConnected())
- {
- eds.ConncetSem();
- }
- bool m_init = eds.EDSInit();
- return m_init;
-
- }
-
- public bool Connect()
- {
-
- if (!eds.Init())
- {
- return false;
- }
- if (eds.IsConnected())
- {
- return true;
- }
- return eds.ConncetSem();
-
- }
- public EDSTYPE GetEDSType()
- {
- EDSTYPE t;
- switch (eds.EDSGetType())
- {
- case 1:
- t = EDSTYPE.OFFLINE;
- break;
- case 3:
- t = EDSTYPE.BRUKER;
- break;
- case 4:
- t = EDSTYPE.OXFORD;
- break;
- default:
- t = EDSTYPE.OFFLINE;
- break;
-
- }
- return t;
- }
-
- public void SetFilterKeyEleNames(List<string> KeyNameList)
- {
- this.keyElenamelist = KeyNameList;
- }
- }
- }
|