OTSParticle.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #pragma once
  2. #include "afx.h"
  3. #include "OTSFeature.h"
  4. #include "otsdataconst.h"
  5. #include "BSEImg.h"
  6. #include "PosXray.h"
  7. #include "OTSRect.h"
  8. namespace OTSDATA {
  9. const double Pi = 3.14159;
  10. class COTSParticle;
  11. typedef std::shared_ptr<COTSParticle> __declspec(dllexport) COTSParticlePtr;
  12. class __declspec(dllexport) COTSParticle : public xmls::ISlo
  13. {
  14. public:
  15. // constructor
  16. COTSParticle(); // constructor
  17. COTSParticle(const COTSParticle&); // copy constructor
  18. COTSParticle(COTSParticle*); // copy constructor
  19. COTSParticle& operator=(const COTSParticle&); // =operator
  20. BOOL operator==(const COTSParticle&); // ==operator
  21. virtual ~COTSParticle(); // destructor
  22. //void Serialize(CArchive& ar); // serialization
  23. void Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode);
  24. // tag id
  25. int GetParticleId() { return m_nTagId; }
  26. void SetParticleId(int a_nTagId)
  27. {
  28. m_nTagId = a_nTagId;
  29. if (m_pXRayInfo != nullptr)
  30. {
  31. m_pXRayInfo->SetPartTagId(a_nTagId);
  32. }
  33. }
  34. // analysis id
  35. int GetAnalysisId() { return m_nAnalysisId; }
  36. void SetAnalysisId(int a_nAnalysisId)
  37. {
  38. m_nAnalysisId = a_nAnalysisId;
  39. if (m_pXRayInfo != nullptr)
  40. {
  41. m_pXRayInfo->SetIndex(a_nAnalysisId);
  42. }
  43. }
  44. // field id
  45. int GetFieldId() { return m_nFieldId; }
  46. void SetFieldId(int a_nFieldId) { m_nFieldId = a_nFieldId; }
  47. // area
  48. double GetActualArea() { return m_dArea; }
  49. void SetActualArea(double a_nArea) { m_dArea = a_nArea; }
  50. // Pixel area
  51. double GetPixelArea()
  52. {
  53. if (m_dPixelArea == 0) CalPixelArea();
  54. return m_dPixelArea;
  55. }
  56. void SetPixelArea(double a_nArea) { m_dPixelArea = a_nArea; }
  57. // rectangle
  58. CRect GetParticleRect()
  59. {
  60. if (m_rectParticle.Width() == 0)
  61. {
  62. CalCoverRectFromSegment();
  63. }
  64. return m_rectParticle;
  65. }
  66. void SetParticleRect(CRect& a_rectParticle) { m_rectParticle = a_rectParticle; }
  67. COTSRect GetOTSRect() { return m_OTSRect; }
  68. void SetOTSRect(COTSRect r) { m_OTSRect = r; }
  69. // gray
  70. BYTE GetAveGray() { return m_cAveGray; }
  71. void SetAveGray(char a_cAveGray) { m_cAveGray = a_cAveGray; }
  72. // type
  73. int GetTypeId() { return m_TypeId; }
  74. void SetTypeId(int a_nType) { m_TypeId = a_nType; }
  75. // type
  76. OTS_PARTICLE_BASIC_CLASSIFY GetBasicClassifyID() { return m_basicClassifyId; }
  77. void SetBasicClassifyId(OTS_PARTICLE_BASIC_CLASSIFY a_nType) { m_basicClassifyId = a_nType; }
  78. // x-ray position
  79. CPoint GetXRayPos() { return m_poiXRayPos; }
  80. void SetXRayPos(CPoint a_poiXRayPos) { m_poiXRayPos = a_poiXRayPos; }
  81. CPosXrayPtr GetXrayInfo() const { return m_pXRayInfo; }
  82. void SetXrayInfo(CPosXrayPtr val) { m_pXRayInfo = val; }
  83. std::vector<CPoint> GetXrayMatrixPoints() {
  84. return m_MatrixPoints;
  85. }
  86. void SetXrayMatrixPoints(std::vector<CPoint> points) { m_MatrixPoints = points; }
  87. CPoint GetFieldSEMPos() { return m_FieldSEMPos; }
  88. void SetFieldSEMPos(CPoint a_poiabsPos) { m_FieldSEMPos = a_poiabsPos; }//scan field sem coordinate position of the whole measure area,redundant design for compatibility and convenience
  89. CPoint GetOTSScanFieldPos() { return m_FieldSEMPos; }
  90. void SetOTSScanFieldPos(CPoint a_poiabsPos) { m_FieldSEMPos = a_poiabsPos; }//scan field OTS coordinate position of the whole measure area,redundant design for compatibility and convenience
  91. // feature
  92. COTSFeaturePtr GetFeature() { return m_pFeature; }
  93. void SetFeature(COTSFeaturePtr a_pFeautre);
  94. // Feret diameter
  95. double GetFeretDiameter() { return m_dFeretDiameter; }
  96. void SetFeretDiameter(double a_dFeretDiameter) { m_dFeretDiameter = a_dFeretDiameter; }
  97. //设置该颗粒的最小外接矩形的宽度
  98. void SetMinWidth(double w) { m_Width = w; }
  99. double GetMinWidth() { return m_Width; }
  100. //设置该颗粒的最小外接矩形的长度
  101. void SetMinHeight(double h) { m_Height = h; }
  102. double GetMinHeight() { return m_Height; }
  103. double GetPerimeter() { return m_Perimeter; }
  104. void SetPerimeter(double p) { m_Perimeter = p; }
  105. double GetDMax() { return m_DMax; }
  106. void SetDMax(double d) { m_DMax = d; }
  107. double GetDMin() { return m_DMin; }
  108. void SetDMin(double d) { m_DMin = d; }
  109. double GetDPerp() { return m_Dp; }
  110. void SetDPerp(double dp) { m_Dp = dp; }
  111. double GetDInscr() { return m_Di; }
  112. void SetDInscr(double di) { m_Di = di; }
  113. double GetDMean() { return m_Dm; }
  114. void SetDMean(double dm) { m_Dm = dm; }
  115. double GetOrientation() { return m_Orientation; }
  116. void SetOrientation(double Orien) { m_Orientation = Orien; }
  117. double GetDElong() { return m_De; }
  118. void SetDElong(double de) { m_De = de; }
  119. double GetAspectElong() { return m_De/ m_DMin; }
  120. double GetAspectRatio() { return m_DMax / m_DMin; }
  121. double GetVideo() {return m_cAveGray;}
  122. double GetEqualCircleDiameter()
  123. {
  124. double Diameter;
  125. double dSize = this->GetActualArea();
  126. Diameter = sqrt(dSize / Pi) * 2;
  127. return Diameter;
  128. }
  129. double GetImgPropertyValueByName(CString propertyName);
  130. std::string GetImgPortraitString();
  131. double CalculateSimilarity(COTSParticlePtr part);
  132. // calculate area, rect, average gray, and xRay pos
  133. BOOL CalCoverRectFromSegment();
  134. BOOL CalPixelArea();
  135. BOOL CalXRayPos();
  136. BOOL CalActualArea(double pixelsize);
  137. std::string GetTypeName() const { return m_TypeName; }
  138. void SetTypeName(std::string val) { m_TypeName = val; }
  139. std::string GetColor() const { return m_TypeColor; }
  140. void SetColor(std::string val) { m_TypeColor = val; }
  141. std::string GetHardness() const { return m_hardness; }
  142. void SetHardness(std::string val) { m_hardness = val; }
  143. std::string GetDensity() const { return m_density; }
  144. void SetDensity(std::string val) { m_density = val; }
  145. std::string GetConductivity() const { return m_conductivity; }
  146. void SetConductivity(std::string val) { m_conductivity = val; }
  147. std::string GetConnectedParticlesSequentialString() const { return m_connectedParticlesName; }
  148. void SetConnectedParticlesSequentialString(std::string val) { m_connectedParticlesName = val; }
  149. std::vector<std::shared_ptr<COTSParticle>> GetSubParticles() const { return m_subParticles; }
  150. void SetSubParticles(std::vector<std::shared_ptr<COTSParticle>> val) { m_subParticles = val; }
  151. void AddSubParticle(std::shared_ptr<COTSParticle> val) { m_subParticles.push_back(val); }
  152. void ClearSubParticles() { m_subParticles.clear(); }
  153. BOOL IsConnected(COTSParticle* a_p, int fldwidth, int fldheight, int direction);
  154. BOOL IfContain(CPoint pos);//determine if the point is in the region of this particle.
  155. int GetGroupId() { return (int)m_grpId; }
  156. void SetGroupId(int a_grpId) { m_grpId = (IDENTIFIED_INC_GRP_ID)a_grpId; }
  157. std::string GetGroupName() const { return m_grpName; }
  158. void SetGroupName(std::string val) { m_grpName = val; }
  159. std::string GetGroupColor() const { return m_grpColor; }
  160. void SetGroupColor(std::string val) { m_grpColor = val; }
  161. BOOL IsXrayParticle() const { return m_isXrayParticle; }
  162. void SetIsXrayParticle(bool value) { m_isXrayParticle = value; }
  163. protected:
  164. // cleanup
  165. void Cleanup();
  166. // initialization
  167. void Init();
  168. // duplication
  169. void Duplicate(const COTSParticle& a_oSource);
  170. double GetMorphologyVectorNorm();
  171. std::vector<double> GetMorphData();
  172. bool m_isXrayParticle;
  173. // area
  174. double m_dArea;
  175. double m_dPixelArea;
  176. // rectangle
  177. CRect m_rectParticle;
  178. COTSRect m_OTSRect;
  179. // Feret's diameter
  180. double m_dFeretDiameter;
  181. //最小外接矩形的宽度
  182. double m_Width;
  183. //最小外接矩形的长度
  184. double m_Height;
  185. double m_Perimeter;
  186. double m_DMax;
  187. double m_DMin;
  188. double m_Dp;
  189. double m_Di;
  190. double m_Dm;
  191. double m_De;
  192. double m_Orientation;
  193. // gray
  194. BYTE m_cAveGray;
  195. // type
  196. int m_TypeId;
  197. OTS_PARTICLE_BASIC_CLASSIFY m_basicClassifyId;
  198. IDENTIFIED_INC_GRP_ID m_grpId;
  199. std::string m_grpName;
  200. std::string m_grpColor;
  201. std::string m_TypeName;
  202. std::string m_TypeColor;
  203. std::string m_hardness;
  204. std::string m_density;
  205. std::string m_conductivity;
  206. std::string m_connectedParticlesName;
  207. std::vector<std::shared_ptr<COTSParticle>> m_subParticles;
  208. // tag id
  209. int m_nTagId;
  210. // analysis id
  211. int m_nAnalysisId;
  212. // field id
  213. int m_nFieldId;
  214. // x-ray position
  215. CPoint m_poiXRayPos;
  216. std::vector<CPoint> m_MatrixPoints;
  217. std::vector<CPosXrayPtr> m_MatrixXrayInfo;
  218. CPoint m_FieldSEMPos;//the correlate field sem coordinate position in the whole measure area. not the screen position.
  219. CPoint m_OTSScanFieldPos;//the ots coordinate position of the scan field in the whole measure area.
  220. // feature
  221. COTSFeaturePtr m_pFeature;
  222. CPosXrayPtr m_pXRayInfo;
  223. double m_vectorNorm=0;
  224. };
  225. typedef std::vector<COTSParticlePtr> __declspec(dllexport) COTSParticleList;
  226. }