SmplMeasureReMeasure.cs 8.8 KB

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