OTSParticle.h 8.0 KB

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