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