123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using OTSCLRINTERFACE;
- using OTSCommon;
- using OTSCommon.Model;
- using OTSModelSharp;
- using OTSModelSharp.DTLBase;
- using OTSModelSharp.ServiceInterface;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using static OTSDataType.otsdataconst;
- namespace OTSMeasureApp._0_OTSModel.Measure._4_ReMeasure
- {
- class SmplMeasureReMeasure : CSmplMeasure
- {
- SemController sem = SemController.GetSEMController();
- ScanController scan = ScanController.GetScanController();
- EDSController eds = EDSController.GetEDSController();
- public bool ReMeasure(string samplePath, int width, int height, Dictionary<int, List<Particle>> keyValues, int IMGSCANSPEED_INDEX, int XRAYSCANMODE_INDEX, int NUD_SCANTIME_COUNT)
- {
- try
- {
- sem.Connect();
- eds.Connect();
- //参数定义
- int nBrukerDwellTimeId = 3;
- long nBrukerDwellTime = 0;
- switch (IMGSCANSPEED_INDEX)
- {
- case (int)OTS_IMAGE_SCANSPEED_OPTIONS.low:
- nBrukerDwellTimeId = 3;
- break;
- case (int)OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
- nBrukerDwellTimeId = 4;
- break;
- case (int)OTS_IMAGE_SCANSPEED_OPTIONS.high:
- nBrukerDwellTimeId = 5;
- break;
- default:
- nBrukerDwellTimeId = 3;
- break;
- }
- nBrukerDwellTime = DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId];
- SQLiteHelper sQLiteHelper = new SQLiteHelper(samplePath + "Inclusion.db");
- sQLiteHelper.GetDBConnection();
- sQLiteHelper.BeginTransaction();
- log.Info("Begin to process field count : " + keyValues.Count);
- //按帧图分析
- for (int i = 0; i < keyValues.Count; i++)
- {
- List<COTSParticleClr> cOTSParticleClrs = new List<COTSParticleClr>();
- //移动到当前帧
- log.Debug("Begin to move to the field : " + keyValues.ElementAt(i).Value[0].FieldId);
- sem.MoveSEMToPoint(keyValues.ElementAt(i).Value[0].FieldPosX, keyValues.ElementAt(i).Value[0].FieldPosY);
- //采集图像
- log.Info("Begin to AcquireBSEImage ");
- scan.SetDwellTime(nBrukerDwellTimeId);
- scan.SetImageSize(width, height);
- CBSEImgClr imgClr = scan.AcquireBSEImage(0, 0, (int)nBrukerDwellTime);
- Bitmap bitmap = Imagepro.ToGrayBitmap(imgClr.GetImageDataPtr(), width, height);
- bitmap.Save(samplePath + "Field" + keyValues.ElementAt(i).Value[0].FieldId + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
- //打能谱
- log.Info("Begin to GetXRayByPoints count : " + keyValues.ElementAt(i).Value.Count);
- if (XRAYSCANMODE_INDEX == (int)OTS_X_RAY_SCAN_MODE.PointMode)
- {
- for (int j = 0; j < keyValues.ElementAt(i).Value.Count; j++)
- {
- COTSParticleClr cOTSParticle = new COTSParticleClr();
- CPosXrayClr cPosXray = new CPosXrayClr();
- cOTSParticle.SetAnalysisId(keyValues.ElementAt(i).Value[j].XrayId);
- cOTSParticle.SetFieldId(keyValues.ElementAt(i).Value[j].FieldId);
- cOTSParticle.SetXray(cPosXray);
- cOTSParticle.SetXRayPos(new Point(keyValues.ElementAt(i).Value[j].PosX, keyValues.ElementAt(i).Value[j].PosY));
- cOTSParticleClrs.Add(cOTSParticle);
- }
- eds.GetXRayByPoints(cOTSParticleClrs, (uint)nBrukerDwellTime, true);
- }
- else
- {
- for (int j = 0; j < keyValues.ElementAt(i).Value.Count; j++)
- {
- COTSParticleClr cOTSParticle = new COTSParticleClr();
- CPosXrayClr cPosXray = new CPosXrayClr();
- cOTSParticle.SetAnalysisId(keyValues.ElementAt(i).Value[j].XrayId);
- cOTSParticle.SetFieldId(keyValues.ElementAt(i).Value[j].FieldId);
- cOTSParticle.SetXray(cPosXray);
- 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));
- COTSFeatureClr fea = new COTSFeatureClr();
- List<COTSSegmentClr> segs = new List<COTSSegmentClr>();
- for (int k = 0; k < keyValues.ElementAt(i).Value[j].SegmentNum; k++)
- {
- 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));
- }
- fea.SetSegmentsList(segs, false);
- cOTSParticle.SetFeature(fea);
- cOTSParticleClrs.Add(cOTSParticle);
- }
- eds.GetXRayByFeatures(cOTSParticleClrs, (uint)nBrukerDwellTime, true);
- }
- //修改数据库能谱
- log.Info("Begin to save info to db ");
- for (int j = 0; j < cOTSParticleClrs.Count; j++)
- {
- UInt32[] xrayData = cOTSParticleClrs[j].GetXray().GetXrayData();
- byte[] bytedata = new byte[GENERALXRAYCHANNELS * 4];
- for (int k = 0; k < GENERALXRAYCHANNELS; k++)
- {
- uint m = xrayData[k];
- byte[] dwordData = BitConverter.GetBytes(m);
- bytedata[k * 4] = dwordData[0];
- bytedata[k * 4 + 1] = dwordData[1];
- bytedata[k * 4 + 2] = dwordData[2];
- bytedata[k * 4 + 3] = dwordData[3];
- }
- sQLiteHelper.ExecuteXrayForTransaction(cOTSParticleClrs[j].GetAnalysisId(), cOTSParticleClrs[j].GetFieldId(), bytedata);
- List<CElementChemistryClr> elementChemistryClrs = cOTSParticleClrs[j].GetXray().GetElementQuantifyData();
- List<string> nameList = new List<string>();
- List<double> perList = new List<double>();
- for (int k = 0; k < elementChemistryClrs.Count; k++)
- {
- nameList.Add(elementChemistryClrs[k].GetName());
- perList.Add(elementChemistryClrs[k].GetPercentage());
- }
- sQLiteHelper.ExecuteElementForTransaction(cOTSParticleClrs[j].GetAnalysisId(), cOTSParticleClrs[j].GetFieldId(), cOTSParticleClrs[j].GetXray().GetElementNum(), nameList, perList);
- }
- log.Info("End process the field : " + keyValues.ElementAt(i).Value[0].FieldId);
- }
- sQLiteHelper.CommitTransaction();
- sem.DisConnect();
- eds.DisConnect();
- return true;
- }
- catch (Exception ex)
- {
- log.Error("ReMeasure Erroe ! " + ex);
- return false;
- }
- }
- }
- }
|