OTSParticle.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 GetClassifyId() { return m_classifyId; }
  74. void SetClassifyId(int a_nType) { m_classifyId = a_nType; }
  75. // type
  76. OTS_PARTICLE_TYPE GetType() { return m_nType; }
  77. void SetType(OTS_PARTICLE_TYPE a_nType) { m_nType = 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 GetSEMPos() { return m_absolutPos; }
  88. void SetSEMPos(CPoint a_poiabsPos) { m_absolutPos = a_poiabsPos; }
  89. // feature
  90. COTSFeaturePtr GetFeature() { return m_pFeature; }
  91. void SetFeature(COTSFeaturePtr a_pFeautre);
  92. // Feret diameter
  93. double GetFeretDiameter() { return m_dFeretDiameter; }
  94. void SetFeretDiameter(double a_dFeretDiameter) { m_dFeretDiameter = a_dFeretDiameter; }
  95. //设置该颗粒的最小外接矩形的宽度
  96. void SetMinWidth(double w) { m_Width = w; }
  97. double GetMinWidth() { return m_Width; }
  98. //设置该颗粒的最小外接矩形的长度
  99. void SetMinHeight(double h) { m_Height = h; }
  100. double GetMinHeight() { return m_Height; }
  101. // chemical type
  102. GB_CHEMICAL_TYPE GetChemicalType() { return m_nChemical; }//for GB 30834 Method2
  103. void SetChemicalType(GB_CHEMICAL_TYPE a_nChemical) { m_nChemical = a_nChemical; }
  104. double GetPerimeter() { return m_Perimeter; }
  105. void SetPerimeter(double p) { m_Perimeter = p; }
  106. double GetDMax() { return m_DMax; }
  107. void SetDMax(double d) { m_DMax = d; }
  108. double GetDMin() { return m_DMin; }
  109. void SetDMin(double d) { m_DMin = d; }
  110. double GetDPerp() { return m_Dp; }
  111. void SetDPerp(double dp) { m_Dp = dp; }
  112. double GetDInscr() { return m_Di; }
  113. void SetDInscr(double di) { m_Di = di; }
  114. double GetDMean() { return m_Dm; }
  115. void SetDMean(double dm) { m_Dm = dm; }
  116. double GetOrientation() { return m_Orientation; }
  117. void SetOrientation(double Orien) { m_Orientation = Orien; }
  118. double GetDElong() { return m_De; }
  119. void SetDElong(double de) { m_De = de; }
  120. double GetAspectElong() { return m_De/ m_DMin; }
  121. double GetAspectRatio() { return m_DMax / m_DMin; }
  122. double GetVideo() {return m_cAveGray;}
  123. double GetEqualCircleDiameter()
  124. {
  125. double Diameter;
  126. double dSize = this->GetActualArea();
  127. Diameter = sqrt(dSize / Pi) * 2;
  128. return Diameter;
  129. }
  130. double GetImgPropertyValueByName(CString propertyName);
  131. std::string GetImgPortraitString();
  132. double CalculateSimilarity(COTSParticlePtr part);
  133. // calculate area, rect, average gray, and xRay pos
  134. BOOL CalCoverRectFromSegment();
  135. BOOL CalPixelArea();
  136. BOOL CalXRayPos();
  137. std::string GetClassifyName() const { return m_classifyName; }
  138. void SetClassifyName(std::string val) { m_classifyName = 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. int GetGroupId() { return (int)m_grpId; }
  155. void SetGroupId(int a_grpId) { m_grpId = (IDENTIFIED_INC_GRP_ID)a_grpId; }
  156. std::string GetGroupName() const { return m_grpName; }
  157. void SetGroupName(std::string val) { m_grpName = val; }
  158. std::string GetGroupColor() const { return m_grpColor; }
  159. void SetGroupColor(std::string val) { m_grpColor = val; }
  160. BOOL IsXrayParticle() const { return m_isXrayParticle; }
  161. void SetIsXrayParticle(bool value) { m_isXrayParticle = value; }
  162. protected:
  163. // cleanup
  164. void Cleanup();
  165. // initialization
  166. void Init();
  167. // duplication
  168. void Duplicate(const COTSParticle& a_oSource);
  169. double GetMorphologyVectorNorm();
  170. std::vector<double> GetMorphData();
  171. bool m_isXrayParticle;
  172. // area
  173. double m_dArea;
  174. double m_dPixelArea;
  175. // rectangle
  176. CRect m_rectParticle;
  177. COTSRect m_OTSRect;
  178. // Feret's diameter
  179. double m_dFeretDiameter;
  180. //最小外接矩形的宽度
  181. double m_Width;
  182. //最小外接矩形的长度
  183. double m_Height;
  184. // STD chemical type
  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. GB_CHEMICAL_TYPE m_nChemical;
  194. // gray
  195. BYTE m_cAveGray;
  196. // type
  197. int m_classifyId;
  198. OTS_PARTICLE_TYPE m_nType;
  199. IDENTIFIED_INC_GRP_ID m_grpId;
  200. std::string m_grpName;
  201. std::string m_grpColor;
  202. std::string m_classifyName;
  203. std::string m_TypeColor;
  204. std::string m_hardness;
  205. std::string m_density;
  206. std::string m_conductivity;
  207. std::string m_connectedParticlesName;
  208. std::vector<std::shared_ptr<COTSParticle>> m_subParticles;
  209. // tag id
  210. int m_nTagId;
  211. // search id
  212. //int m_nSearchId;
  213. // analysis id
  214. int m_nAnalysisId;
  215. // field id
  216. int m_nFieldId;
  217. // x-ray position
  218. CPoint m_poiXRayPos;
  219. std::vector<CPoint> m_MatrixPoints;
  220. std::vector<CPosXrayPtr> m_MatrixXrayInfo;
  221. CPoint m_absolutPos;//the ots coordinate position in the whole measure area. not the screen position.
  222. // feature
  223. COTSFeaturePtr m_pFeature;
  224. CPosXrayPtr m_pXRayInfo;
  225. double m_vectorNorm=0;
  226. };
  227. typedef std::vector<COTSParticlePtr> __declspec(dllexport) COTSParticleList;
  228. }