SmplMeasureReMeasure.cs 8.9 KB

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