OTSControlFunExport.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. #include "stdafx.h"
  2. #include "OTSControlFunExport.h"
  3. namespace OTSCLRINTERFACE
  4. {
  5. bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, cli::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, cli::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, cli::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, cli::array<CPosXrayClr^>^% a_XrayData, bool bQuant)
  43. {
  44. std::vector<CPosXrayPtr> listXRayPoints;
  45. for (int i = 0; i < a_XrayData->Length; i++)
  46. {
  47. listXRayPoints.push_back(a_XrayData[i]->GetPosXrayPtr());
  48. }
  49. // set get quantify info flag
  50. if (bQuant)
  51. {
  52. m_pEDS->SetQuantification(TRUE);
  53. }
  54. else
  55. {
  56. m_pEDS->SetQuantification(FALSE);
  57. }
  58. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  59. return bRet;
  60. }
  61. bool COTSControlFunExport::GetXRayByPoints(unsigned long a_nMilliseconds, cli::array<Point>^ points, cli::array<COTSParticleClr^>^ parts, bool bQuant)
  62. {
  63. std::vector<CPosXrayPtr> listXRayPoints;
  64. for (int i = 0; i < points->Length; i++)
  65. {
  66. CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr();
  67. pXRayPoint->SetPosition(CPoint(points[i].X, points[i].Y));
  68. listXRayPoints.push_back(pXRayPoint);
  69. }
  70. if (bQuant)
  71. {
  72. m_pEDS->SetQuantification(TRUE);
  73. }
  74. else
  75. {
  76. m_pEDS->SetQuantification(FALSE);
  77. }
  78. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  79. for (int i = 0; i < points->Length; i++)
  80. {
  81. auto part = parts[i]->GetOTSParticlePtr();
  82. part->SetXrayInfo(listXRayPoints[i]);
  83. }
  84. return bRet;
  85. }
  86. bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, cli::array<COTSFeatureClr^>^ features, cli::array<cli::array<unsigned long>^>^% a_XrayData, cli::array<String^>^% a_strEleResult, bool bQuant)
  87. {
  88. std::vector<CPosXrayPtr> listXRayPoints;
  89. long xraynum = features->Length;
  90. for (int i = 0; i < xraynum; i++)
  91. {
  92. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  93. listXRayPoints.push_back(pXRayPoint);
  94. }
  95. std::vector<BrukerFeature>listFeatures;
  96. for (int i = 0; i < xraynum; i++)
  97. {
  98. auto feature = features[i]->GetOTSFeaturePtr();
  99. auto otsSegs = feature->GetSegmentsList();
  100. BrukerSegment* segArray = new BrukerSegment[otsSegs.size()];
  101. for (int j = 0; j < otsSegs.size(); j++)
  102. {
  103. auto seg = otsSegs[j];
  104. BrukerSegment* oSegment = &segArray[j];
  105. oSegment->XCount = seg->GetLength();
  106. oSegment->XStart = seg->GetStart();
  107. oSegment->Y = seg->GetHeight();
  108. }
  109. BrukerFeature oFeature;
  110. oFeature.SegmentCount = otsSegs.size();
  111. oFeature.pSegment = segArray;
  112. listFeatures.push_back(oFeature);
  113. }
  114. // set get quantify info flag
  115. if (bQuant)
  116. {
  117. m_pEDS->SetQuantification(TRUE);
  118. }
  119. else
  120. {
  121. m_pEDS->SetQuantification(FALSE);
  122. }
  123. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  124. DWORD* xrd;
  125. for (int i = 0; i < xraynum; i++)
  126. {
  127. xrd = listXRayPoints[i]->GetXrayData();
  128. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  129. {
  130. a_XrayData[i][j] = xrd[j];
  131. }
  132. 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!
  133. }
  134. if (bQuant)
  135. {
  136. for (int i = 0; i < features->Length; i++)
  137. {
  138. CElementChemistriesList& listElement = listXRayPoints[i]->GetElementQuantifyData();
  139. int nElementNum = (int)listElement.size();
  140. CString strElementResult = _T("");
  141. for (auto pElement : listElement)
  142. {
  143. CString strResult;
  144. CString strName = pElement->GetName();
  145. double dPercent = pElement->GetPercentage();
  146. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  147. strElementResult += strResult;
  148. }
  149. a_strEleResult[i] = gcnew String(strElementResult);
  150. }
  151. }
  152. return bRet;
  153. }
  154. bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, cli::array<COTSParticleClr^>^ parts, bool bQuant)
  155. {
  156. std::vector<CPosXrayPtr> listXRayPoints;
  157. long xraynum = parts->Length;
  158. for (int i = 0; i < xraynum; i++)
  159. {
  160. CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr();
  161. listXRayPoints.push_back(pXRayPoint);
  162. }
  163. std::vector<BrukerFeature>listFeatures;
  164. for (int i = 0; i < xraynum; i++)
  165. {
  166. auto feature = parts[i]->GetOTSParticlePtr()->GetFeature();
  167. auto otsSegs = feature->GetSegmentsList();
  168. BrukerSegment* segArray = new BrukerSegment[otsSegs.size()];
  169. for (int j = 0; j < otsSegs.size(); j++)
  170. {
  171. auto seg = otsSegs[j];
  172. BrukerSegment* oSegment = &segArray[j];
  173. oSegment->XCount = seg->GetLength();
  174. oSegment->XStart = seg->GetStart();
  175. oSegment->Y = seg->GetHeight();
  176. }
  177. BrukerFeature oFeature;
  178. oFeature.SegmentCount = otsSegs.size();
  179. oFeature.pSegment = segArray;
  180. listFeatures.push_back(oFeature);
  181. }
  182. // set get quantify info flag
  183. if (bQuant)
  184. {
  185. m_pEDS->SetQuantification(TRUE);
  186. }
  187. else
  188. {
  189. m_pEDS->SetQuantification(FALSE);
  190. }
  191. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  192. //DWORD* xrd;
  193. for (int i = 0; i < xraynum; i++)
  194. {
  195. auto part = parts[i]->GetOTSParticlePtr();
  196. part->SetXrayInfo(listXRayPoints[i]);
  197. 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!
  198. }
  199. return bRet;
  200. }
  201. bool COTSControlFunExport::GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, cli::array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  202. {
  203. std::vector<CPosXrayPtr> listXRayPoints;
  204. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  205. pXRayPoint->SetPosition(CPoint(point.X, point.Y));
  206. listXRayPoints.push_back(pXRayPoint);
  207. // set get quantify info flag
  208. if (bQuant)
  209. {
  210. m_pEDS->SetQuantification(TRUE);
  211. }
  212. else
  213. {
  214. m_pEDS->SetQuantification(FALSE);
  215. }
  216. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  217. DWORD* xrd;
  218. xrd = listXRayPoints[0]->GetXrayData();
  219. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  220. {
  221. a_XrayData[j] = xrd[j];
  222. }
  223. if (bQuant)
  224. {
  225. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  226. int nElementNum = (int)listElement.size();
  227. CString strElementResult = _T("");
  228. for (auto pElement : listElement)
  229. {
  230. CString strResult;
  231. CString strName = pElement->GetName();
  232. double dPercent = pElement->GetPercentage();
  233. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  234. strElementResult += strResult;
  235. }
  236. a_strEleResult = gcnew String(strElementResult);
  237. }
  238. return bRet;
  239. }
  240. bool COTSControlFunExport::GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, cli::array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  241. {
  242. std::vector<CPosXrayPtr> listXRayPoints;
  243. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  244. listXRayPoints.push_back(pXRayPoint);
  245. std::vector<BrukerSegment> listSegment;
  246. std::vector<BrukerFeature>listFeatures;
  247. auto otsSegs = feature->GetSegmentsList();
  248. for (int j = 0; j < otsSegs->Count; j++)
  249. {
  250. auto seg = otsSegs[j];
  251. BrukerSegment oSegment;
  252. oSegment.XCount = seg->GetLength();
  253. oSegment.XStart = seg->GetStart();
  254. oSegment.Y = seg->GetHeight();
  255. listSegment.push_back(oSegment);
  256. }
  257. BrukerFeature ofeature;
  258. ofeature.SegmentCount = listSegment.size();
  259. ofeature.pSegment = &listSegment[0];
  260. listFeatures.push_back(ofeature);
  261. bool bRet = FALSE;
  262. // set get quantify info flag
  263. if (bQuant)
  264. {
  265. m_pEDS->SetQuantification(TRUE);
  266. }
  267. else
  268. {
  269. m_pEDS->SetQuantification(FALSE);
  270. }
  271. bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  272. DWORD* xrd;
  273. pXRayPoint = listXRayPoints[0];
  274. xrd = pXRayPoint->GetXrayData();
  275. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  276. {
  277. a_XrayData[i] = xrd[i];
  278. }
  279. if (bQuant)
  280. {
  281. CString strElementResult = listXRayPoints[0]->GetQuantifiedElementsStr();
  282. a_strEleResult = gcnew String(strElementResult);
  283. }
  284. return bRet;
  285. }
  286. //bool COTSControlFunExport::GetXRayElements(unsigned long a_nMilliseconds, cli::array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  287. //{
  288. // std::vector<CPosXrayPtr> listXRayPoints;
  289. // CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  290. // pXRayPoint->SetPosition(CPoint(10, 10));
  291. // listXRayPoints.push_back(pXRayPoint);
  292. // CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray());
  293. // pXRayPoint1->SetPosition(CPoint(20, 20));
  294. // listXRayPoints.push_back(pXRayPoint1);
  295. // // set get quantify info flag
  296. // m_pEDS->SetQuantification(TRUE);
  297. // bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  298. // DWORD* xrd;
  299. // pXRayPoint = listXRayPoints[1];
  300. // xrd = pXRayPoint->GetXrayData();
  301. // CString strElementResult = listXRayPoints[1]->GetQuantifiedElementsStr();
  302. //
  303. // for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  304. // {
  305. // a_XrayData[i] = xrd[i];
  306. // }
  307. // a_nElementNum =(int) listXRayPoints[1]->GetElementQuantifyData().size();
  308. // a_strResult = gcnew String(strElementResult);
  309. // return bRet;
  310. //}
  311. bool COTSControlFunExport::GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, cli::array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  312. {
  313. std::vector<CPosXrayPtr> listXRayPoints;
  314. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  315. pXRayPoint->SetPosition(CPoint(a_BSEX, a_BSEY));
  316. listXRayPoints.push_back(pXRayPoint);
  317. m_pEDS->SetQuantification(TRUE);
  318. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  319. DWORD* xrd;
  320. pXRayPoint = listXRayPoints[0];
  321. xrd = pXRayPoint->GetXrayData();
  322. // element quantify data
  323. a_nElementNum = (int)listXRayPoints[0]->GetElementQuantifyData().size();
  324. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  325. {
  326. a_XrayData[i] = xrd[i];
  327. }
  328. CString strElementResult = listXRayPoints[0]->GetQuantifiedElementsStr();
  329. a_strResult = gcnew String(strElementResult);
  330. return bRet;
  331. }
  332. int COTSControlFunExport::AcquireBSEImage( cli::array<System::Byte>^% a_ImgData)
  333. {
  334. int bRet = 0;
  335. CSize sz;
  336. int height, width;
  337. CBSEImgPtr pbseImg = nullptr;
  338. pbseImg = m_pScan->AcquireBSEImage();
  339. if (pbseImg == nullptr)
  340. {
  341. return bRet;
  342. }
  343. sz = pbseImg->GetImageSize();
  344. height = sz.cx;
  345. width = sz.cy;
  346. bRet = height * width;
  347. BYTE* lpData = pbseImg->GetImageDataPointer();
  348. for (int i = 0; i < bRet; i++)
  349. {
  350. a_ImgData[i] = lpData[i];
  351. }
  352. return bRet;
  353. }
  354. }