SmplMeasureReMeasure.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using OTSCLRINTERFACE;
  2. using OTSCommon;
  3. using OTSCommon.Model;
  4. using OTSModelSharp;
  5. using OTSModelSharp.DTLBase;
  6. using OTSModelSharp.ServiceInterface;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using static OTSDataType.otsdataconst;
  14. namespace OTSMeasureApp._0_OTSModel.Measure._4_ReMeasure
  15. {
  16. class SmplMeasureReMeasure : CSmplMeasure
  17. {
  18. SemController sem = SemController.GetSEMController();
  19. ScanController scan = ScanController.GetScanController();
  20. EDSController eds = EDSController.GetEDSController();
  21. public bool ReMeasure(string samplePath, int width, int height, Dictionary<int, List<Particle>> keyValues, int IMGSCANSPEED_INDEX, int XRAYSCANMODE_INDEX, int NUD_SCANTIME_COUNT)
  22. {
  23. try
  24. {
  25. sem.Connect();
  26. eds.Connect();
  27. //参数定义
  28. int nBrukerDwellTimeId = 3;
  29. long nBrukerDwellTime = 0;
  30. switch (IMGSCANSPEED_INDEX)
  31. {
  32. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.low:
  33. nBrukerDwellTimeId = 3;
  34. break;
  35. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
  36. nBrukerDwellTimeId = 4;
  37. break;
  38. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.high:
  39. nBrukerDwellTimeId = 5;
  40. break;
  41. default:
  42. nBrukerDwellTimeId = 3;
  43. break;
  44. }
  45. nBrukerDwellTime = DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId];
  46. SQLiteHelper sQLiteHelper = new SQLiteHelper(samplePath + "Inclusion.db");
  47. sQLiteHelper.GetDBConnection();
  48. sQLiteHelper.BeginTransaction();
  49. log.Info("Begin to process field count : " + keyValues.Count);
  50. //按帧图分析
  51. for (int i = 0; i < keyValues.Count; i++)
  52. {
  53. List<COTSParticleClr> cOTSParticleClrs = new List<COTSParticleClr>();
  54. //移动到当前帧
  55. log.Debug("Begin to move to the field : " + keyValues.ElementAt(i).Value[0].FieldId);
  56. sem.MoveSEMToPoint(keyValues.ElementAt(i).Value[0].FieldPosX, keyValues.ElementAt(i).Value[0].FieldPosY);
  57. //采集图像
  58. log.Info("Begin to AcquireBSEImage ");
  59. scan.SetDwellTime(nBrukerDwellTimeId);
  60. scan.SetImageSize(width, height);
  61. CBSEImgClr imgClr = scan.AcquireBSEImage(0, 0, (int)nBrukerDwellTime);
  62. Bitmap bitmap = Imagepro.ToGrayBitmap(imgClr.GetImageDataPtr(), width, height);
  63. bitmap.Save(samplePath + "Field" + keyValues.ElementAt(i).Value[0].FieldId + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
  64. //打能谱
  65. log.Info("Begin to GetXRayByPoints count : " + keyValues.ElementAt(i).Value.Count);
  66. if (XRAYSCANMODE_INDEX == (int)OTS_X_RAY_SCAN_MODE.PointMode)
  67. {
  68. for (int j = 0; j < keyValues.ElementAt(i).Value.Count; j++)
  69. {
  70. COTSParticleClr cOTSParticle = new COTSParticleClr();
  71. CPosXrayClr cPosXray = new CPosXrayClr();
  72. cOTSParticle.SetAnalysisId(keyValues.ElementAt(i).Value[j].XrayId);
  73. cOTSParticle.SetFieldId(keyValues.ElementAt(i).Value[j].FieldId);
  74. cOTSParticle.SetXray(cPosXray);
  75. cOTSParticle.SetXRayPos(new Point(keyValues.ElementAt(i).Value[j].PosX, keyValues.ElementAt(i).Value[j].PosY));
  76. cOTSParticleClrs.Add(cOTSParticle);
  77. }
  78. eds.GetXRayByPoints(cOTSParticleClrs, (uint)nBrukerDwellTime, true);
  79. }
  80. else
  81. {
  82. for (int j = 0; j < keyValues.ElementAt(i).Value.Count; j++)
  83. {
  84. COTSParticleClr cOTSParticle = new COTSParticleClr();
  85. CPosXrayClr cPosXray = new CPosXrayClr();
  86. cOTSParticle.SetAnalysisId(keyValues.ElementAt(i).Value[j].XrayId);
  87. cOTSParticle.SetFieldId(keyValues.ElementAt(i).Value[j].FieldId);
  88. cOTSParticle.SetXray(cPosXray);
  89. cOTSParticle.SetParticleRect(new Rectangle(keyValues.ElementAt(i).Value[j].RectLeft, keyValues.ElementAt(i).Value[j].RectTop, keyValues.ElementAt(i).Value[j].RectWidth, keyValues.ElementAt(i).Value[j].RectHeight));
  90. COTSFeatureClr fea = new COTSFeatureClr();
  91. List<COTSSegmentClr> segs = new List<COTSSegmentClr>();
  92. for (int k = 0; k < keyValues.ElementAt(i).Value[j].SegmentNum; k++)
  93. {
  94. segs.Add(new COTSSegmentClr(keyValues.ElementAt(i).Value[j].SegmentList[k].Height, keyValues.ElementAt(i).Value[j].SegmentList[k].Start, keyValues.ElementAt(i).Value[j].SegmentList[k].Length));
  95. }
  96. fea.SetSegmentsList(segs, false);
  97. cOTSParticle.SetFeature(fea);
  98. cOTSParticleClrs.Add(cOTSParticle);
  99. }
  100. eds.GetXRayByFeatures(cOTSParticleClrs, (uint)nBrukerDwellTime, true);
  101. }
  102. //修改数据库能谱
  103. log.Info("Begin to save info to db ");
  104. for (int j = 0; j < cOTSParticleClrs.Count; j++)
  105. {
  106. UInt32[] xrayData = cOTSParticleClrs[j].GetXray().GetXrayData();
  107. byte[] bytedata = new byte[GENERALXRAYCHANNELS * 4];
  108. for (int k = 0; k < GENERALXRAYCHANNELS; k++)
  109. {
  110. uint m = xrayData[k];
  111. byte[] dwordData = BitConverter.GetBytes(m);
  112. bytedata[k * 4] = dwordData[0];
  113. bytedata[k * 4 + 1] = dwordData[1];
  114. bytedata[k * 4 + 2] = dwordData[2];
  115. bytedata[k * 4 + 3] = dwordData[3];
  116. }
  117. sQLiteHelper.ExecuteXrayForTransaction(cOTSParticleClrs[j].GetAnalysisId(), cOTSParticleClrs[j].GetFieldId(), bytedata);
  118. List<CElementChemistryClr> elementChemistryClrs = cOTSParticleClrs[j].GetXray().GetElementQuantifyData();
  119. List<string> nameList = new List<string>();
  120. List<double> perList = new List<double>();
  121. for (int k = 0; k < elementChemistryClrs.Count; k++)
  122. {
  123. nameList.Add(elementChemistryClrs[k].GetName());
  124. perList.Add(elementChemistryClrs[k].GetPercentage());
  125. }
  126. sQLiteHelper.ExecuteElementForTransaction(cOTSParticleClrs[j].GetAnalysisId(), cOTSParticleClrs[j].GetFieldId(), cOTSParticleClrs[j].GetXray().GetElementNum(), nameList, perList);
  127. }
  128. log.Info("End process the field : " + keyValues.ElementAt(i).Value[0].FieldId);
  129. }
  130. sQLiteHelper.CommitTransaction();
  131. sem.DisConnect();
  132. eds.DisConnect();
  133. return true;
  134. }
  135. catch (Exception ex)
  136. {
  137. log.Error("ReMeasure Erroe ! " + ex);
  138. return false;
  139. }
  140. }
  141. }
  142. }