OTSControlFunExport.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. #include "stdafx.h"
  2. #include "OTSControlFunExport.h"
  3. namespace OTSCLRINTERFACE
  4. {
  5. bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, array<unsigned long>^% a_XrayData)
  6. {
  7. CPoint pt;
  8. pt.x = a_oPoint.X;
  9. pt.y = a_oPoint.Y;
  10. bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds, pt);
  11. DWORD* xrd;
  12. xrd = m_pEDS->GetXRayData();
  13. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  14. {
  15. a_XrayData[i] = xrd[i];
  16. }
  17. return bRet;
  18. }
  19. bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, unsigned long a_nBufferSize)
  20. {
  21. long* aData = new long[a_nBufferSize];
  22. memset(aData, 0, a_nBufferSize);
  23. bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds, aData, a_nBufferSize);
  24. for (int i = a_nBufferSize; i < (int)a_nBufferSize; i++)
  25. {
  26. a_XrayData[i] = aData[i];
  27. }
  28. delete[] aData;
  29. return bRet;
  30. }
  31. bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData)
  32. {
  33. bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds);
  34. DWORD* xrd;
  35. xrd = m_pEDS->GetXRayData();
  36. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  37. {
  38. a_XrayData[i] = xrd[i];
  39. }
  40. return bRet;
  41. }
  42. bool COTSControlFunExport::GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant)
  43. {
  44. std::vector<CPosXrayPtr> listXRayPoints;
  45. for (int i = 0; i < points->Length; i++)
  46. {
  47. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  48. pXRayPoint->SetPosition(CPoint(points[i].X, points[i].Y));
  49. listXRayPoints.push_back(pXRayPoint);
  50. }
  51. // set get quantify info flag
  52. if (bQuant)
  53. {
  54. m_pEDS->SetQuantification(TRUE);
  55. }
  56. else
  57. {
  58. m_pEDS->SetQuantification(FALSE);
  59. }
  60. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  61. DWORD* xrd;
  62. for (int i = 0; i < points->Length; i++)
  63. {
  64. xrd = listXRayPoints[i]->GetXrayData();
  65. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  66. {
  67. a_XrayData[i][j] = xrd[j];
  68. }
  69. }
  70. if (bQuant)
  71. {
  72. for (int i = 0; i < points->Length; i++)
  73. {
  74. CElementChemistriesList& listElement = listXRayPoints[i]->GetElementQuantifyData();
  75. int nElementNum = (int)listElement.size();
  76. CString strElementResult = _T("");
  77. for (auto pElement : listElement)
  78. {
  79. CString strResult;
  80. CString strName = pElement->GetName();
  81. double dPercent = pElement->GetPercentage();
  82. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  83. strElementResult += strResult;
  84. }
  85. a_strEleResult[i] = gcnew String(strElementResult);
  86. }
  87. }
  88. return bRet;
  89. }
  90. bool COTSControlFunExport::GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<COTSParticleClr^>^ parts, bool bQuant)
  91. {
  92. std::vector<CPosXrayPtr> listXRayPoints;
  93. for (int i = 0; i < points->Length; i++)
  94. {
  95. CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr();
  96. pXRayPoint->SetPosition(CPoint(points[i].X, points[i].Y));
  97. listXRayPoints.push_back(pXRayPoint);
  98. }
  99. // set get quantify info flag
  100. if (bQuant)
  101. {
  102. m_pEDS->SetQuantification(TRUE);
  103. }
  104. else
  105. {
  106. m_pEDS->SetQuantification(FALSE);
  107. }
  108. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  109. //DWORD* xrd;
  110. for (int i = 0; i < points->Length; i++)
  111. {
  112. auto part = parts[i]->GetOTSParticlePtr();
  113. part->SetXrayInfo(listXRayPoints[i]);
  114. }
  115. return bRet;
  116. }
  117. bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSFeatureClr^>^ features, array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant)
  118. {
  119. std::vector<CPosXrayPtr> listXRayPoints;
  120. long xraynum = features->Length;
  121. for (int i = 0; i < xraynum; i++)
  122. {
  123. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  124. listXRayPoints.push_back(pXRayPoint);
  125. }
  126. std::vector<BrukerFeature>listFeatures;
  127. for (int i = 0; i < xraynum; i++)
  128. {
  129. auto feature = features[i]->GetOTSFeaturePtr();
  130. auto otsSegs = feature->GetSegmentsList();
  131. BrukerSegment* segArray = new BrukerSegment[otsSegs.size()];
  132. for (int j = 0; j < otsSegs.size(); j++)
  133. {
  134. auto seg = otsSegs[j];
  135. BrukerSegment* oSegment = &segArray[j];
  136. oSegment->XCount = seg->GetLength();
  137. oSegment->XStart = seg->GetStart();
  138. oSegment->Y = seg->GetHeight();
  139. }
  140. BrukerFeature oFeature;
  141. oFeature.SegmentCount = otsSegs.size();
  142. oFeature.pSegment = segArray;
  143. listFeatures.push_back(oFeature);
  144. }
  145. // set get quantify info flag
  146. if (bQuant)
  147. {
  148. m_pEDS->SetQuantification(TRUE);
  149. }
  150. else
  151. {
  152. m_pEDS->SetQuantification(FALSE);
  153. }
  154. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  155. DWORD* xrd;
  156. for (int i = 0; i < xraynum; i++)
  157. {
  158. xrd = listXRayPoints[i]->GetXrayData();
  159. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  160. {
  161. a_XrayData[i][j] = xrd[j];
  162. }
  163. delete listFeatures[i].pSegment;// here using the pure pointer increase the understandability but bring another problem: you must not forget to free the pointer or you involve into memory leak!
  164. }
  165. if (bQuant)
  166. {
  167. for (int i = 0; i < features->Length; i++)
  168. {
  169. CElementChemistriesList& listElement = listXRayPoints[i]->GetElementQuantifyData();
  170. int nElementNum = (int)listElement.size();
  171. CString strElementResult = _T("");
  172. for (auto pElement : listElement)
  173. {
  174. CString strResult;
  175. CString strName = pElement->GetName();
  176. double dPercent = pElement->GetPercentage();
  177. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  178. strElementResult += strResult;
  179. }
  180. a_strEleResult[i] = gcnew String(strElementResult);
  181. }
  182. }
  183. return bRet;
  184. }
  185. bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSParticleClr^>^ parts, bool bQuant)
  186. {
  187. std::vector<CPosXrayPtr> listXRayPoints;
  188. long xraynum = parts->Length;
  189. for (int i = 0; i < xraynum; i++)
  190. {
  191. CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr();
  192. listXRayPoints.push_back(pXRayPoint);
  193. }
  194. std::vector<BrukerFeature>listFeatures;
  195. for (int i = 0; i < xraynum; i++)
  196. {
  197. auto feature = parts[i]->GetOTSParticlePtr()->GetFeature();
  198. auto otsSegs = feature->GetSegmentsList();
  199. BrukerSegment* segArray = new BrukerSegment[otsSegs.size()];
  200. for (int j = 0; j < otsSegs.size(); j++)
  201. {
  202. auto seg = otsSegs[j];
  203. BrukerSegment* oSegment = &segArray[j];
  204. oSegment->XCount = seg->GetLength();
  205. oSegment->XStart = seg->GetStart();
  206. oSegment->Y = seg->GetHeight();
  207. }
  208. BrukerFeature oFeature;
  209. oFeature.SegmentCount = otsSegs.size();
  210. oFeature.pSegment = segArray;
  211. listFeatures.push_back(oFeature);
  212. }
  213. // set get quantify info flag
  214. if (bQuant)
  215. {
  216. m_pEDS->SetQuantification(TRUE);
  217. }
  218. else
  219. {
  220. m_pEDS->SetQuantification(FALSE);
  221. }
  222. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  223. //DWORD* xrd;
  224. for (int i = 0; i < xraynum; i++)
  225. {
  226. auto part = parts[i]->GetOTSParticlePtr();
  227. part->SetXrayInfo(listXRayPoints[i]);
  228. delete listFeatures[i].pSegment;// using the pure pointer increase the understandability but bring another problem: you must not forget to free the pointer or you involve into memory leak!
  229. }
  230. return bRet;
  231. }
  232. bool COTSControlFunExport::GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  233. {
  234. std::vector<CPosXrayPtr> listXRayPoints;
  235. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  236. pXRayPoint->SetPosition(CPoint(point.X, point.Y));
  237. listXRayPoints.push_back(pXRayPoint);
  238. // set get quantify info flag
  239. if (bQuant)
  240. {
  241. m_pEDS->SetQuantification(TRUE);
  242. }
  243. else
  244. {
  245. m_pEDS->SetQuantification(FALSE);
  246. }
  247. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  248. DWORD* xrd;
  249. xrd = listXRayPoints[0]->GetXrayData();
  250. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  251. {
  252. a_XrayData[j] = xrd[j];
  253. }
  254. if (bQuant)
  255. {
  256. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  257. int nElementNum = (int)listElement.size();
  258. CString strElementResult = _T("");
  259. for (auto pElement : listElement)
  260. {
  261. CString strResult;
  262. CString strName = pElement->GetName();
  263. double dPercent = pElement->GetPercentage();
  264. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  265. strElementResult += strResult;
  266. }
  267. a_strEleResult = gcnew String(strElementResult);
  268. }
  269. return bRet;
  270. }
  271. bool COTSControlFunExport::GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  272. {
  273. std::vector<CPosXrayPtr> listXRayPoints;
  274. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  275. listXRayPoints.push_back(pXRayPoint);
  276. std::vector<BrukerSegment> listSegment;
  277. std::vector<BrukerFeature>listFeatures;
  278. auto otsSegs = feature->GetSegmentsList();
  279. for (int j = 0; j < otsSegs->Count; j++)
  280. {
  281. auto seg = otsSegs[j];
  282. BrukerSegment oSegment;
  283. oSegment.XCount = seg->GetLength();
  284. oSegment.XStart = seg->GetStart();
  285. oSegment.Y = seg->GetHeight();
  286. listSegment.push_back(oSegment);
  287. }
  288. BrukerFeature ofeature;
  289. ofeature.SegmentCount = listSegment.size();
  290. ofeature.pSegment = &listSegment[0];
  291. listFeatures.push_back(ofeature);
  292. bool bRet = FALSE;
  293. // set get quantify info flag
  294. if (bQuant)
  295. {
  296. m_pEDS->SetQuantification(TRUE);
  297. }
  298. else
  299. {
  300. m_pEDS->SetQuantification(FALSE);
  301. }
  302. bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  303. DWORD* xrd;
  304. pXRayPoint = listXRayPoints[0];
  305. xrd = pXRayPoint->GetXrayData();
  306. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  307. {
  308. a_XrayData[i] = xrd[i];
  309. }
  310. if (bQuant)
  311. {
  312. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  313. int nElementNum = (int)listElement.size();
  314. CString strElementResult = _T("");
  315. for (auto pElement : listElement)
  316. {
  317. CString strResult;
  318. CString strName = pElement->GetName();
  319. double dPercent = pElement->GetPercentage();
  320. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  321. strElementResult += strResult;
  322. }
  323. a_strEleResult = gcnew String(strElementResult);
  324. }
  325. return bRet;
  326. }
  327. bool COTSControlFunExport::GetXRayElements(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  328. {
  329. std::vector<CPosXrayPtr> listXRayPoints;
  330. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  331. pXRayPoint->SetPosition(CPoint(10, 10));
  332. listXRayPoints.push_back(pXRayPoint);
  333. CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray());
  334. pXRayPoint1->SetPosition(CPoint(20, 20));
  335. listXRayPoints.push_back(pXRayPoint1);
  336. // set get quantify info flag
  337. m_pEDS->SetQuantification(TRUE);
  338. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  339. DWORD* xrd;
  340. pXRayPoint = listXRayPoints[1];
  341. xrd = pXRayPoint->GetXrayData();
  342. // element quantify data
  343. CElementChemistriesList& listElement = listXRayPoints[1]->GetElementQuantifyData();
  344. int nElementNum = (int)listElement.size();
  345. CString strElementResult = _T("");
  346. for (auto pElement : listElement)
  347. {
  348. CString strResult;
  349. CString strName = pElement->GetName();
  350. double dPercent = pElement->GetPercentage();
  351. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  352. strElementResult += strResult;
  353. }
  354. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  355. {
  356. a_XrayData[i] = xrd[i];
  357. }
  358. a_nElementNum = nElementNum;
  359. a_strResult = gcnew String(strElementResult);
  360. return bRet;
  361. }
  362. bool COTSControlFunExport::GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  363. {
  364. std::vector<CPosXrayPtr> listXRayPoints;
  365. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  366. pXRayPoint->SetPosition(CPoint(a_BSEX, a_BSEY));
  367. listXRayPoints.push_back(pXRayPoint);
  368. /*CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray());
  369. pXRayPoint1->SetPosition(CPoint(a_BSEX, a_BSEY));
  370. listXRayPoints.push_back(pXRayPoint1);*/
  371. // set get quantify info flag
  372. //m_pEDS->SetQuantification(FALSE);
  373. m_pEDS->SetQuantification(TRUE);
  374. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  375. /*std::vector<CPosXrayPtr> listXRayPointsTemp;
  376. CPosXrayPtr pXRayPointTemp = CPosXrayPtr(new CPosXray());
  377. listXRayPointsTemp.push_back(pXRayPointTemp);
  378. for (int i = 0; i < 2; i++)
  379. {
  380. listXRayPointsTemp[0] = listXRayPoints[i];
  381. m_pEDS->SetQuantification(TRUE);
  382. bool bRet = m_pEDS->GetXRayByPoints(listXRayPointsTemp, a_nMilliseconds);
  383. listXRayPoints[i] = listXRayPointsTemp[0];
  384. }*/
  385. DWORD* xrd;
  386. pXRayPoint = listXRayPoints[0];
  387. xrd = pXRayPoint->GetXrayData();
  388. // element quantify data
  389. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  390. int nElementNum = (int)listElement.size();
  391. CString strElementResult = _T("");
  392. for (auto pElement : listElement)
  393. {
  394. CString strResult;
  395. CString strName = pElement->GetName();
  396. double dPercent = pElement->GetPercentage();
  397. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  398. strElementResult += strResult;
  399. }
  400. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  401. {
  402. a_XrayData[i] = xrd[i];
  403. }
  404. a_nElementNum = nElementNum;
  405. a_strResult = gcnew String(strElementResult);
  406. return bRet;
  407. }
  408. int COTSControlFunExport::AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, array<System::Byte>^% a_ImgData)
  409. {
  410. int bRet = 0;
  411. CSize sz;
  412. int height, width;
  413. CBSEImgPtr pbseImg = nullptr;
  414. pbseImg = m_pScan->AcquireBSEImage(a_nMatrixIndex, nReads, nDwell);
  415. if (pbseImg == nullptr)
  416. {
  417. return bRet;
  418. }
  419. sz = pbseImg->GetImageSize();
  420. height = sz.cx;
  421. width = sz.cy;
  422. bRet = height * width;
  423. BYTE* lpData = pbseImg->GetImageDataPointer();
  424. for (int i = 0; i < bRet; i++)
  425. {
  426. a_ImgData[i] = lpData[i];
  427. }
  428. return bRet;
  429. }
  430. }