CClassifyEngine.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //using OTSDataType;
  2. using OTSModelSharp.ServiceCenter;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OTSModelSharp.ServiceCenter
  9. {
  10. using OTSCLRINTERFACE;
  11. public class CClassifyEngine : IClassifyEngine
  12. {
  13. COTSClassifyEngineClr myEng;
  14. bool ifWeightPercentageToAtomicPercentage;
  15. public bool ClassifyIncA(COTSParticleClr particle, int steelTech)
  16. {
  17. bool r = myEng.ClassifyIncA(particle,steelTech);//the classify engine will
  18. return true;
  19. }
  20. public IClassifyEngine GetSpectrumCompareEngine(string libName)
  21. {
  22. if (!libName.Contains(".db"))
  23. {
  24. libName = libName + ".db";
  25. }
  26. myEng = new COTSClassifyEngineClr(EngineType.SpectrumCompare, libName);
  27. return this;
  28. }
  29. public IClassifyEngine GetIncClassifyEngine()
  30. {
  31. myEng = new COTSClassifyEngineClr(EngineType.InclutionEng, "");
  32. return this;
  33. }
  34. public IClassifyEngine GetExpressionClassifyEngine(string libName)
  35. {
  36. if (!libName.Contains(".db"))
  37. {
  38. libName = libName + ".db";
  39. }
  40. myEng = new COTSClassifyEngineClr(EngineType.ExpressionClassifyEng, libName);
  41. ifWeightPercentageToAtomicPercentage = FileHelper.GetIfTranslateWeightPercentageToAtomicPercentage();
  42. return this;
  43. }
  44. public bool IfNeedMaxEDS(COTSParticleClr particle,ref double maxeds)
  45. {
  46. return myEng.IfNeedMaxEDS(particle,ref maxeds);
  47. }
  48. public bool ClassifyBySpectrum(COTSParticleClr particle)
  49. {
  50. return myEng.ClassifyBySpectrum(particle);
  51. }
  52. public bool ClassifyByExpressionTemporarySpectrum(COTSParticleClr particle)
  53. {
  54. return myEng.ClassifyByExpressionTemporarySpectrum(particle);
  55. }
  56. public bool ClassifyByExpression(COTSParticleClr particle)
  57. {
  58. if (ifWeightPercentageToAtomicPercentage==true)
  59. {
  60. double sumMolar=0;
  61. foreach (var ele in particle.GetXray().GetElementQuantifyData())
  62. {
  63. sumMolar += ele.GetMolarPercentage();
  64. }
  65. foreach (var ele in particle.GetXray().GetElementQuantifyData())
  66. {
  67. ele.SetPercentage(ele.GetMolarPercentage() / sumMolar);
  68. }
  69. }
  70. return myEng.ClassifyByExpression(particle);
  71. }
  72. }
  73. }