123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
-
- 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>();
- private bool delayQuant=false;
-
- public static IEDSController GetEDSController(int imgwidth,int imgheight,int expectCount,bool ifautoid,string knownelements)
- {
- string deviceType = FileHelper.GetXMLInformations("EDSName");
-
- if (edsctrl == null)
- {
- if (deviceType == "FEI")
- {
- edsctrl = new FEIEDSController(expectCount,ifautoid,knownelements);
- }
- else if (deviceType == "Oxford")
- {
- edsctrl = new OxfordEDSController(expectCount,ifautoid,knownelements);
- }
- else if (deviceType == "Bruker")
- {
- var ctrl = new EDSController("Bruker",expectCount,ifautoid,knownelements);
- //var delayQuant = Convert.ToBoolean(FileHelper.GetIfDelayQuantify());
- var delayQuant = false;//Now it has proved that this method won't increase the speed of xray analysis.So deactivate it here.
- ctrl.delayQuant = delayQuant;
- edsctrl = ctrl;
- }
- else if (deviceType == "OffLine")
- {
- edsctrl = new EDSController("OffLine",expectCount,ifautoid,knownelements);
-
- }
- edsctrl.SetResolution(imgwidth, imgheight);
- }
- return edsctrl;
- }
- private EDSController(string deviceType,int expectcount,bool ifautoid,string knownelements)
- {
-
- eds = COTSControlFunExport.GetControllerInstance(deviceType);
- eds.SetQuantificationParam(ifautoid, knownelements);
- eds.SetExpectCount(expectcount);
-
- }
- 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)
- {
-
- 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();
- if (delayQuant)
- {
- a_bElementInfo = false;
- }
- 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;
-
- Point[] allpoints = new Point[nSize];
- COTSParticleClr[] partsTemp = new COTSParticleClr[nSize];
- for (int m = 0; m < nSize; m++)
- {
- partsTemp[m] = a_listParticles[m];
- allpoints[m] = Ps[m];
- }
- result = eds.GetXRayByPoints(a_nXRayAQTime, allpoints, partsTemp, a_bElementInfo);
- if (!result)
- {
- NLog.LogManager.GetCurrentClassLogger().Error("GetXRayByPoints: failed to get element.");
- return false;
- }
-
-
- 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 Connect()
- {
- if (!eds.IsConnected())
- {
- eds.ConncetSem();
- }
- bool m_init = eds.EDSInit();
- return m_init;
-
- }
- 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;
- }
-
- public void SetResolution(int resolutionWidth, int resolutionHeight)
- {
- eds.SetImageSize(resolutionWidth, resolutionHeight);
- return ;
- }
- public bool QuantifyXrayByPart(COTSParticleClr part)
- {
- return eds.QuantifyXrayByPart(part);
- }
- public int GetExpectCount()
- {
- return eds.GetExpectCount();
- }
- public bool GetIfDelayQuantify()
- {
- return delayQuant;
- }
- public void SetQuantifiCationParam(bool IfAutoId, string knownElements)
- {
- eds.SetQuantificationParam(IfAutoId, knownElements);
- }
- public bool GetXRayByExpandFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
- {
- bool result = false;
- if (!eds.IsConnected())
- {
- return false;
- }
- if (keyElenamelist.Count > 0)
- {
- 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();
- if (delayQuant)
- {
- a_bElementInfo = false;
- }
- result = eds.GetXRayByFeatures((uint)a_nXRayAQTime, parts, a_bElementInfo);
- if (result == true)
- {
- foreach (var p in a_listParticles)
- {
- ProcessXrayInfo(p);
- }
- }
- return result;
- }
- }
- }
|