OTSParticleClr.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "OTSParticleClr.h"
  4. #include "../OTSLog/COTSUtilityDllFunExport.h"
  5. namespace OTSCLRINTERFACE {
  6. COTSParticleClr::COTSParticleClr()
  7. {
  8. m_Particle = new COTSParticlePtr(new COTSParticle());
  9. }
  10. COTSParticleClr::COTSParticleClr(COTSParticlePtr pParticle) // copy constructor
  11. {
  12. ASSERT(pParticle);
  13. if (!pParticle)
  14. {
  15. LogErrorTrace(__FILE__, __LINE__, _T("COTSParticleClr: Generate COTSParticleClr pointer failed."));
  16. return;
  17. }
  18. m_Particle = new COTSParticlePtr(pParticle);
  19. }
  20. COTSParticleClr::COTSParticleClr(COTSParticleClr^ a_pSource)
  21. {
  22. auto src = a_pSource->GetOTSParticlePtr();
  23. m_Particle = new COTSParticlePtr(new COTSParticle(src.get()));
  24. }
  25. COTSParticleClr::COTSParticleClr(COTSParticle* a_pSource) // copy constructor
  26. {
  27. ASSERT(a_pSource);
  28. if (!a_pSource)
  29. {
  30. LogErrorTrace(__FILE__, __LINE__, _T("COTSParticleClr: Generate COTSParticleClr pointer failed."));
  31. return;
  32. }
  33. m_Particle = new COTSParticlePtr(new COTSParticle(a_pSource));
  34. }
  35. COTSParticleClr::~COTSParticleClr()
  36. {
  37. if (m_Particle != nullptr)
  38. {
  39. delete m_Particle;
  40. m_Particle = nullptr;
  41. }
  42. }
  43. COTSParticleClr::!COTSParticleClr()
  44. {
  45. if (m_Particle != nullptr)
  46. {
  47. delete m_Particle;
  48. m_Particle = nullptr;
  49. }
  50. }
  51. COTSParticlePtr COTSParticleClr::GetOTSParticlePtr()
  52. {
  53. return *m_Particle;
  54. }
  55. System::Drawing::Rectangle^ COTSParticleClr::GetParticleRect()
  56. {
  57. COTSParticlePtr prt = *m_Particle;
  58. CRect Crec = prt->GetParticleRect();
  59. System::Drawing::Rectangle^ r = gcnew System::Drawing::Rectangle((int)Crec.left, (int)Crec.top, (int)Crec.Width(), (int)Crec.Height());
  60. return r;
  61. }
  62. void COTSParticleClr::SetParticleRect(System::Drawing::Rectangle^ a_rectParticle)
  63. {
  64. CRect r(a_rectParticle->Left, a_rectParticle->Top, a_rectParticle->Right, a_rectParticle->Bottom);
  65. m_Particle->get()->SetParticleRect(r);
  66. }
  67. //represent the global position of this object
  68. void COTSParticleClr::SetOTSRect(int left, int top, int right, int bottom)
  69. {
  70. COTSRect r = COTSRect(left, top, right, bottom);
  71. m_Particle->get()->SetOTSRect(r);
  72. }
  73. bool COTSParticleClr::GetOTSRect(int% left, int% top, int% right, int% bottom)
  74. {
  75. COTSRect r = m_Particle->get()->GetOTSRect();
  76. left = r.GetTopLeft().x;
  77. right = r.GetBottomRight().x;
  78. top = r.GetTopLeft().y;
  79. bottom = r.GetBottomRight().y;
  80. return true;
  81. }
  82. int COTSParticleClr::GetType()
  83. {
  84. int nType = -1;
  85. if (m_Particle != nullptr)
  86. {
  87. nType =(int) m_Particle->get()->GetType();
  88. }
  89. return nType;
  90. }
  91. void COTSParticleClr::SetType(int a_nType)
  92. {
  93. if (m_Particle != nullptr)
  94. {
  95. m_Particle->get()->SetType((OTS_PARTICLE_TYPE)a_nType);
  96. }
  97. }
  98. int COTSParticleClr::GetClassifyId()
  99. {
  100. int nType = -1;
  101. if (m_Particle != nullptr)
  102. {
  103. nType = m_Particle->get()->GetClassifyId();
  104. }
  105. return nType;
  106. }
  107. void COTSParticleClr::SetClassifyId(int a_nType)
  108. {
  109. if (m_Particle != nullptr)
  110. {
  111. m_Particle->get()->SetClassifyId(a_nType);
  112. }
  113. }
  114. double COTSParticleClr::GetActualArea()
  115. {
  116. double nArea = -1;
  117. if (m_Particle != nullptr)
  118. {
  119. nArea = m_Particle->get()->GetActualArea();
  120. }
  121. return nArea;
  122. }
  123. double COTSParticleClr::GetPixelArea()
  124. {
  125. double nArea = -1;
  126. if (m_Particle != nullptr)
  127. {
  128. nArea = m_Particle->get()->GetPixelArea();
  129. }
  130. return nArea;
  131. }
  132. void COTSParticleClr::SetActualArea(double a_dArea)
  133. {
  134. if (m_Particle != nullptr)
  135. {
  136. m_Particle->get()->SetActualArea(a_dArea);
  137. }
  138. }
  139. BYTE COTSParticleClr::GetAveGray()
  140. {
  141. BYTE nAveGray = -1;
  142. if (m_Particle != nullptr)
  143. {
  144. nAveGray = m_Particle->get()->GetAveGray();
  145. }
  146. return nAveGray;
  147. }
  148. void COTSParticleClr::SetAveGray(BYTE a_cAveGray)
  149. {
  150. if (m_Particle != nullptr)
  151. {
  152. m_Particle->get()->SetAveGray(a_cAveGray);
  153. }
  154. }
  155. Point^ COTSParticleClr::GetXRayPos()
  156. {
  157. Point^ XRayPosClr;
  158. if (m_Particle != nullptr)
  159. {
  160. CPoint P = m_Particle->get()->GetXRayPos();
  161. XRayPosClr = gcnew Point(P.x, P.y);
  162. }
  163. return XRayPosClr;
  164. }
  165. void COTSParticleClr::SetXRayPos(Point^ a_pXRayPos)
  166. {
  167. ASSERT(a_pXRayPos);
  168. if (!a_pXRayPos)
  169. {
  170. LogErrorTrace(__FILE__, __LINE__, _T("SetFileVersion: invalid version."));
  171. }
  172. if (m_Particle != nullptr)
  173. {
  174. CPoint P = CPoint(a_pXRayPos->X, a_pXRayPos->Y);
  175. m_Particle->get()->SetXRayPos(P);
  176. }
  177. }
  178. cli::array<System::Drawing::Point^>^ COTSParticleClr::GetXrayMatrixPoints()
  179. {
  180. auto ps = m_Particle->get()->GetXrayMatrixPoints();
  181. cli::array<System::Drawing::Point^>^ matrixPs = gcnew cli::array<System::Drawing::Point^>(ps.size());
  182. int i=0;
  183. for (auto p : ps)
  184. {
  185. System::Drawing::Point^ p1 = gcnew System::Drawing::Point(p.x, p.y);
  186. matrixPs[i] = p1;
  187. i++;
  188. }
  189. return matrixPs;
  190. }
  191. void COTSParticleClr::SetXrayMatrixPoints(cli::array<System::Drawing::Point^>^ points)
  192. {
  193. std::vector<CPoint> matrixPs;
  194. int L = points->Length;
  195. for (int i = 0; i < L; i++)
  196. {
  197. CPoint p = CPoint(points[i]->X, points[i]->Y);
  198. matrixPs.push_back(p);
  199. }
  200. m_Particle->get()->SetXrayMatrixPoints(matrixPs);
  201. }
  202. void COTSParticleClr::SetSEMPos(System::Drawing::Point^ a_pAbsPos)
  203. {
  204. m_Particle->get()->SetSEMPos(CPoint(a_pAbsPos->X, a_pAbsPos->Y));
  205. }
  206. COTSFeatureClr^ COTSParticleClr::GetFeature()
  207. {
  208. COTSFeatureClr^ FeatureClr;
  209. if (m_Particle != nullptr)
  210. {
  211. COTSFeaturePtr Feature = m_Particle->get()->GetFeature();
  212. FeatureClr = gcnew COTSFeatureClr(Feature);
  213. }
  214. return FeatureClr;
  215. }
  216. void COTSParticleClr::SetFeature(COTSFeatureClr^ a_pFeautre)
  217. {
  218. ASSERT(a_pFeautre);
  219. if (!a_pFeautre)
  220. {
  221. LogErrorTrace(__FILE__, __LINE__, _T("SetFeature: invalid feature pointer."));
  222. return;
  223. }
  224. if (m_Particle != nullptr)
  225. {
  226. COTSFeaturePtr pSetElement = a_pFeautre->GetOTSFeaturePtr();
  227. ASSERT(pSetElement);
  228. if (!pSetElement)
  229. {
  230. LogErrorTrace(__FILE__, __LINE__, _T("SetElement: invalid part Element pointer."));
  231. return;
  232. }
  233. m_Particle->get()->SetFeature(pSetElement);
  234. }
  235. }
  236. void COTSParticleClr::SetXray(CPosXrayClr^ xray)
  237. {
  238. m_Particle->get()->SetXrayInfo(xray->GetPosXrayPtr());
  239. }
  240. CPosXrayClr^ COTSParticleClr::GetXray()
  241. {
  242. auto xray = m_Particle->get()->GetXrayInfo();
  243. if (xray != nullptr)
  244. {
  245. return gcnew CPosXrayClr(m_Particle->get()->GetXrayInfo());
  246. }
  247. else
  248. {
  249. return gcnew CPosXrayClr();
  250. }
  251. }
  252. int COTSParticleClr::GetParticleId()
  253. {
  254. int nTagId = -1;
  255. if (m_Particle != nullptr)
  256. {
  257. nTagId = m_Particle->get()->GetParticleId();
  258. }
  259. return nTagId;
  260. }
  261. void COTSParticleClr::SetParticleId(int a_nTagId)
  262. {
  263. if (m_Particle != nullptr)
  264. {
  265. m_Particle->get()->SetParticleId(a_nTagId);
  266. }
  267. }
  268. int COTSParticleClr::GetAnalysisId()
  269. {
  270. int AnalysisId = -1;
  271. if (m_Particle != nullptr)
  272. {
  273. AnalysisId = m_Particle->get()->GetAnalysisId();
  274. }
  275. return AnalysisId;
  276. }
  277. void COTSParticleClr::SetAnalysisId(int a_nAnalysisId)
  278. {
  279. if (m_Particle != nullptr)
  280. {
  281. m_Particle->get()->SetAnalysisId(a_nAnalysisId);
  282. }
  283. }
  284. int COTSParticleClr::GetFieldId()
  285. {
  286. int FieldId = -1;
  287. if (m_Particle != nullptr)
  288. {
  289. FieldId = m_Particle->get()->GetFieldId();
  290. }
  291. return FieldId;
  292. }
  293. void COTSParticleClr::SetFieldId(int a_nFieldId)
  294. {
  295. if (m_Particle != nullptr)
  296. {
  297. m_Particle->get()->SetFieldId(a_nFieldId);
  298. }
  299. }
  300. double COTSParticleClr::CalculateSimilarity(COTSParticleClr^ part)
  301. {
  302. return m_Particle->get()->CalculateSimilarity(part->GetOTSParticlePtr());
  303. }
  304. }