CFieldPositionMgr.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using OTSCLRINTERFACE;
  2. using OTSDataType;
  3. using OTSIMGPROC;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using static OTSDataType.otsdataconst;
  12. namespace OTSModelSharp
  13. {
  14. public class CFieldPositionMgr
  15. {
  16. // measure area
  17. CDomain m_pMeasureArea;
  18. // measured field centre points list
  19. List<System.Drawing.Point> m_listMeasuredFieldCentrePoints;
  20. // image scan parameter
  21. COTSImgScanPrm m_poImageScanParam;
  22. const int RESOLUTION_ID_FIRST_TIE = 0;
  23. // field centre points list
  24. List<System.Drawing.Point> m_listFieldCentrePoints;
  25. // SEM data (measurement)
  26. CSEMDataMsr m_poSEMDataMsr;
  27. // unmeasured field centre points list
  28. List<System.Drawing.Point> m_listUnmeasuredFieldCentrePoints;
  29. CFieldMgrClr fieldmgrclr;
  30. public bool Init(CDomain a_pMeasureArea, COTSImgScanPrm a_poImageScanParam, CSEMDataMsr a_poSEMDataMsr, List<System.Drawing.Point> a_listMeasuredFieldCentrePoints)
  31. {
  32. // assign class member
  33. m_pMeasureArea = new CDomain(a_pMeasureArea);
  34. m_poImageScanParam = new COTSImgScanPrm (a_poImageScanParam);
  35. m_poSEMDataMsr = new CSEMDataMsr(a_poSEMDataMsr);
  36. if (m_listFieldCentrePoints == null)
  37. {
  38. m_listFieldCentrePoints = new List<System.Drawing.Point>();
  39. }
  40. if (m_listUnmeasuredFieldCentrePoints == null)
  41. {
  42. m_listUnmeasuredFieldCentrePoints = new List<System.Drawing.Point>();
  43. }
  44. if (m_listMeasuredFieldCentrePoints == null)
  45. {
  46. m_listMeasuredFieldCentrePoints = new List<System.Drawing.Point>();
  47. }
  48. var scanfieldsize = m_poSEMDataMsr.GetScanFieldSize();
  49. OTS_IMAGE_RESULOTION_OPTIONS nImageSizeId = GetImageScanParam().GetImageResulotion();
  50. long nResulotionId = RESOLUTION_ID_FIRST_TIE + (long)nImageSizeId;
  51. fieldmgrclr = new CFieldMgrClr(scanfieldsize, RESOLUTION_VALUE[nResulotionId]);
  52. CDomain domainclr = new CDomain(a_pMeasureArea.GetShape(),a_pMeasureArea.GetRectDomain());
  53. domainclr.SetPolygonPoint(a_pMeasureArea.GetPolygonPoint());
  54. System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  55. fieldmgrclr.Init(domainclr.GetClrDomainObj(), sizePixelImage,scanfieldsize, (int)m_poImageScanParam.GetFieldStartMode());
  56. m_listUnmeasuredFieldCentrePoints = fieldmgrclr.GetUnmeasuredFieldCentrePoints(a_listMeasuredFieldCentrePoints);
  57. m_listFieldCentrePoints = fieldmgrclr.GetFieldCentrePoints();
  58. return true;
  59. }
  60. // test if field is in the measured field centre points list
  61. public bool IsInMeasuredFieldList(System.Drawing.Point a_poiField)
  62. {
  63. for (int itr = 0; itr < m_listMeasuredFieldCentrePoints.Count; itr++)
  64. {
  65. if (m_listMeasuredFieldCentrePoints[itr] == a_poiField)
  66. {
  67. return a_poiField == m_listMeasuredFieldCentrePoints[itr];
  68. }
  69. }
  70. return false;
  71. }
  72. // calculate total fields
  73. public double CalculateTotalFields(CDomain a_pMeasureArea, double a_dScanFieldSizeX, System.Drawing.Size a_sizePixelImage)
  74. {
  75. CDomainClr domainclr = new CDomainClr((int)a_pMeasureArea.GetShape(), a_pMeasureArea.GetRectDomain());
  76. OTS_IMAGE_RESULOTION_OPTIONS nImageSizeId = m_poImageScanParam.GetImageResulotion();
  77. int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
  78. System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  79. return fieldmgrclr.CalculateTotalFields(domainclr, a_dScanFieldSizeX, sizePixelImage);
  80. }
  81. // field centre points list
  82. public List<System.Drawing.Point> GetFieldCentrePoints()
  83. {
  84. return m_listFieldCentrePoints;
  85. }
  86. // field centre points list
  87. public bool GetFieldRectByIndex(int a_nIndex,ref System.Drawing.Rectangle a_rectField)
  88. {
  89. // check input
  90. if (a_nIndex < 0 || a_nIndex > (int)m_listFieldCentrePoints.Count)
  91. {
  92. return false;
  93. }
  94. // get image size
  95. OTS_IMAGE_RESULOTION_OPTIONS nImageSizeId = m_poImageScanParam.GetImageResulotion();
  96. int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
  97. System.Drawing.Size sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  98. // scan field size (x, y)
  99. System.Drawing.Size sizeImage = new System.Drawing.Size();
  100. sizeImage.Width = m_poSEMDataMsr.GetScanFieldSize();
  101. sizeImage.Height = sizeImage.Width * sizePixelImage.Height/ sizePixelImage.Width;
  102. // get left top
  103. System.Drawing.Point ptLeftTop = m_listFieldCentrePoints[a_nIndex];
  104. // get field rectangle
  105. a_rectField =new Rectangle(ptLeftTop, sizeImage);
  106. return true;
  107. }
  108. public int GetTotalFields()
  109. {
  110. return (int)m_listFieldCentrePoints.Count;
  111. }
  112. public void SetFieldCentrePoints(List<System.Drawing.Point> listPoint)
  113. {
  114. foreach (var opt in listPoint)
  115. {
  116. m_listFieldCentrePoints.Add(opt);
  117. }
  118. }
  119. // unmeasured field centre points list
  120. public List<System.Drawing.Point> GetUnmeasuredFieldCentrePoints()
  121. {
  122. return m_listUnmeasuredFieldCentrePoints;
  123. }
  124. public void SetUnmeasuredFieldCentrePoints(List<System.Drawing.Point> listPoint)
  125. {
  126. m_listUnmeasuredFieldCentrePoints.Clear();
  127. foreach (var opt in listPoint)
  128. {
  129. m_listUnmeasuredFieldCentrePoints.Add(opt);
  130. }
  131. }
  132. // measured field centre points list
  133. public List<System.Drawing.Point> GetMeasuredFieldCentrePoints()
  134. {
  135. return m_listMeasuredFieldCentrePoints;
  136. }
  137. // measured field centre points list
  138. public void SetMeasuredFieldCentrePoints(List<System.Drawing.Point> listPoint)
  139. {
  140. foreach (var opt in listPoint)
  141. {
  142. m_listMeasuredFieldCentrePoints.Add(opt);
  143. }
  144. }
  145. // measure area
  146. public CDomain GetMeasureArea()
  147. {
  148. return m_pMeasureArea;
  149. }
  150. // measure area
  151. public void SetMeasureArea(CDomain a_pMeasureArea)
  152. {
  153. m_pMeasureArea = new CDomain(a_pMeasureArea);
  154. }
  155. // image scan parameter
  156. public COTSImgScanPrm GetImageScanParam()
  157. {
  158. return m_poImageScanParam;
  159. }
  160. // image scan parameter
  161. public void SetImageScanParam(COTSImgScanPrm a_poImageScanParam)
  162. {
  163. m_poImageScanParam = new COTSImgScanPrm (a_poImageScanParam);
  164. }
  165. // SEM data (measurement)
  166. public CSEMDataMsr GetSEMDataMsr()
  167. {
  168. return m_poSEMDataMsr;
  169. }
  170. // SEM data (measurement)
  171. public void SetSEMDataMsr(CSEMDataMsr a_poSEMDataMsr)
  172. {
  173. m_poSEMDataMsr = new CSEMDataMsr(a_poSEMDataMsr);
  174. }
  175. // check if this is a neighbor field centre
  176. // test if field is in or partly in the measure domain area
  177. public bool IsInMeasureArea(System.Drawing.Point a_poiField, System.Drawing.Size a_sizeImageSize)
  178. {
  179. // test field centre point first
  180. if (m_pMeasureArea.PtInDomain(a_poiField))
  181. {
  182. // centre in the measure domain area, return TRUE
  183. return true;
  184. }
  185. // get measure field centre
  186. System.Drawing.Point poiMsrAreaCentre = m_pMeasureArea.GetDomainCenter();
  187. // move to left top postion.
  188. a_poiField.X = a_poiField.X - (a_sizeImageSize.Width / 2);
  189. a_poiField.Y = a_poiField.Y - (a_sizeImageSize.Height / 2);
  190. Rectangle rectFiled = new Rectangle(a_poiField, a_sizeImageSize);
  191. // check field position
  192. if (rectFiled.Left <= poiMsrAreaCentre.X && rectFiled.Right>= poiMsrAreaCentre.X)
  193. {
  194. // centre column field or centre field
  195. return true;
  196. }
  197. else if (rectFiled.Top <= poiMsrAreaCentre.Y && rectFiled.Bottom>= poiMsrAreaCentre.Y)
  198. {
  199. // centre row field?
  200. return true;
  201. }
  202. else if (rectFiled.Right <= poiMsrAreaCentre.X)
  203. {
  204. // on the left side
  205. //up
  206. if (rectFiled.Top>= poiMsrAreaCentre.Y)
  207. {
  208. // on the top left side, need to test the bottom right corner
  209. if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Right, rectFiled.Top)))
  210. {
  211. return true;
  212. }
  213. }
  214. else if (rectFiled.Bottom <= poiMsrAreaCentre.Y) //down//
  215. {
  216. // on the bottom left side, need to test the top right corner
  217. if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Right,rectFiled.Bottom)))
  218. {
  219. return true;
  220. }
  221. }
  222. }
  223. else if (rectFiled.Left >= poiMsrAreaCentre.X)
  224. {
  225. // on the right side
  226. //up
  227. if (rectFiled.Top >= poiMsrAreaCentre.Y)
  228. {
  229. // on the top left side, need to test the bottom right corner
  230. if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Left , rectFiled.Top)))
  231. {
  232. return true;
  233. }
  234. }
  235. else if (rectFiled.Bottom <= poiMsrAreaCentre.Y) //down//
  236. {
  237. // on the bottom left side, need to test the top right corner
  238. if (m_pMeasureArea.PtInDomain(new System.Drawing.Point(rectFiled.Left, rectFiled.Bottom)))
  239. {
  240. return true;
  241. }
  242. }
  243. }
  244. // this field is not in the area at all, return FALSE.
  245. return false;
  246. }
  247. }
  248. }