OTSScanOxford.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include "stdafx.h"
  2. #include "OTSScanOxford.h"
  3. #define TRACE_HERE /*NOP*/
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #endif
  7. namespace OTSController
  8. {
  9. COTSScanOxford::COTSScanOxford(void)
  10. {
  11. m_oxfordImpl = OxfordImpl::GetInstance();
  12. }
  13. COTSScanOxford::~COTSScanOxford(void)
  14. {
  15. }
  16. // initialisation
  17. BOOL COTSScanOxford::Init()
  18. {
  19. BOOL ifconnect = true;
  20. if (!m_oxfordImpl->IsConnected())
  21. {
  22. ifconnect = m_oxfordImpl->Connect();
  23. }
  24. return ifconnect;
  25. }
  26. CSize COTSScanOxford::GetMatrixSize(int /*a_nMatrixIndex*/)
  27. {
  28. // method return value
  29. CSize oRet = CSize(0);
  30. long nWidth = 0, nHeight = 0;
  31. if (m_oxfordImpl->GetImageSize(nWidth, nHeight))
  32. {
  33. oRet.SetSize(nWidth, nHeight);
  34. }
  35. return oRet;
  36. }
  37. BOOL COTSScanOxford::MoveBeamTo(CPoint& a_beamPos)
  38. {
  39. bool bRet = m_oxfordImpl->SetBeamPosition(a_beamPos.x, a_beamPos.y);
  40. return bRet;
  41. }
  42. // Start Scan Table
  43. BOOL COTSScanOxford::StartScanTable (int a_nMatrixIndex, unsigned int nP, int* px, int* py)
  44. {
  45. CSize szMatrix = GetMatrixSize(a_nMatrixIndex);
  46. double stepSize = ((double)m_szScanRange.cx) /((double) szMatrix.cx);
  47. for (unsigned int i = 0 ; i < nP ; i++)
  48. {
  49. px[i] = (int) (px[i] * stepSize) ;
  50. py[i] = m_szScanRange.cy - (int) (py[i] * stepSize) ;
  51. }
  52. return true;
  53. }
  54. /// set image size
  55. /// input long nImageSize
  56. /// return true if success
  57. BOOL COTSScanOxford::SetImageSize(long newImageSize,long nHeight)
  58. {
  59. if (!m_oxfordImpl->SetImageSize(newImageSize, nHeight))
  60. {
  61. ASSERT(m_oxfordImpl);
  62. if (!m_oxfordImpl)
  63. {
  64. return FALSE;
  65. }
  66. }
  67. return true;
  68. }
  69. /// set dwell time
  70. /// input long a_nDwellTime
  71. /// return true if success
  72. BOOL COTSScanOxford::SetDwellTime(long nDwellTime)
  73. {
  74. if (!m_oxfordImpl->SetScanSpeed(nDwellTime))
  75. {
  76. ASSERT(m_oxfordImpl);
  77. if (!m_oxfordImpl)
  78. {
  79. return FALSE;
  80. }
  81. }
  82. return true;
  83. }
  84. CBSEImgPtr COTSScanOxford::AcquireBSEImage()
  85. {
  86. long nWidth, nHeight;
  87. if (!m_oxfordImpl->GetImageSize(nWidth, nHeight))
  88. {
  89. LogErrorTrace(__FILE__, __LINE__, _T("Call GetImageSize failed."));
  90. return nullptr;
  91. }
  92. long nImageSize = nWidth * nHeight;
  93. if (nImageSize <= 0)
  94. {
  95. LogErrorTrace(__FILE__, __LINE__, _T("AcquireBSEImage failed: invalid image size (%d, %d)."), nWidth, nHeight);
  96. return nullptr;
  97. }
  98. std::vector<BYTE> vecImage(nImageSize, 0);
  99. if (!m_oxfordImpl->CollectImage(&vecImage[0]))
  100. {
  101. LogErrorTrace(__FILE__, __LINE__, _T("Call CollectImage failed."));
  102. return nullptr;
  103. }
  104. CRect imageRect(0, 0, nWidth, nHeight);
  105. CBSEImgPtr bseImage(new CBSEImg(imageRect));
  106. //bseImage->SetImageRect(imageRect);
  107. bseImage->InitImageData(nWidth, nHeight);
  108. BYTE* pImageData = bseImage->GetImageDataPointer();
  109. memcpy(pImageData, &vecImage[0], nWidth * nHeight);
  110. return bseImage;
  111. }
  112. long COTSScanOxford::GetDwellTimeByIndex(const long a_nIndex)
  113. {
  114. // dwell time
  115. if(a_nIndex < DWELLTIME_OXFORD_ID_MIN || a_nIndex > DWELLTIME_OXFORD_ID_MAX)
  116. {
  117. // error, invalid scan speed value
  118. LogErrorTrace(__FILE__, __LINE__, _T("Scan speed (Dwell time) index (%d) error."), a_nIndex);
  119. ASSERT(FALSE);
  120. return -1;
  121. }
  122. // convert dwell time index to dwell time value
  123. return DWELLTIME_OXFORD_VALUES[a_nIndex];
  124. }
  125. BOOL COTSScanOxford::SetDwellTimeByIndex(const long a_nDwellTimeIndex)
  126. {
  127. // dwell time
  128. if(a_nDwellTimeIndex < DWELLTIME_OXFORD_ID_MIN || a_nDwellTimeIndex > DWELLTIME_OXFORD_ID_MAX)
  129. {
  130. // error, invalid scan speed value
  131. LogErrorTrace(__FILE__, __LINE__, _T("Scan speed index (%d) error."), a_nDwellTimeIndex);
  132. }
  133. // convert dwell time index to dwell time value
  134. long nDwellTimeLong = DWELLTIME_OXFORD_VALUES[a_nDwellTimeIndex];
  135. if (!SetDwellTime(nDwellTimeLong))
  136. {
  137. // error, failed to set dwell time
  138. LogErrorTrace(__FILE__, __LINE__, _T("Failed to set dwell time (%d)."), a_nDwellTimeIndex);
  139. }
  140. return true;
  141. }
  142. BOOL COTSScanOxford::SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  143. {
  144. m_nScanFieldSizeX = a_nWidth;
  145. m_nScanFieldSizeY = a_nHeight;
  146. return TRUE;
  147. }
  148. // set the SEM position
  149. BOOL COTSScanOxford::SetEMPosition(const int a_nPosX, const int a_nPosY)
  150. {
  151. m_nCurrentBSEPositionX = a_nPosX;
  152. m_nCurrentBSEPositionY = a_nPosY;
  153. return TRUE;
  154. }
  155. }