OTSParticle.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. 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_DMin; }
  118. double GetAspectRatio() { return m_DMax / m_DMin; }
  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. std::string GetImgPortraitString();
  129. double CalculateSimilarity(COTSParticlePtr part);
  130. // calculate area, rect, average gray, and xRay pos
  131. BOOL CalCoverRectFromSegment();
  132. BOOL CalPixelArea();
  133. BOOL CalXRayPos();
  134. BOOL CalActualArea(double pixelsize);
  135. std::string GetClassifyName() const { return m_classifyName; }
  136. void SetClassifyName(std::string val) { m_classifyName = val; }
  137. std::string GetColor() const { return m_TypeColor; }
  138. void SetColor(std::string val) { m_TypeColor = val; }
  139. std::string GetHardness() const { return m_hardness; }
  140. void SetHardness(std::string val) { m_hardness = val; }
  141. std::string GetDensity() const { return m_density; }
  142. void SetDensity(std::string val) { m_density = val; }
  143. std::string GetConductivity() const { return m_conductivity; }
  144. void SetConductivity(std::string val) { m_conductivity = val; }
  145. std::string GetConnectedParticlesSequentialString() const { return m_connectedParticlesName; }
  146. void SetConnectedParticlesSequentialString(std::string val) { m_connectedParticlesName = val; }
  147. std::vector<std::shared_ptr<COTSParticle>> GetSubParticles() const { return m_subParticles; }
  148. void SetSubParticles(std::vector<std::shared_ptr<COTSParticle>> val) { m_subParticles = val; }
  149. void AddSubParticle(std::shared_ptr<COTSParticle> val) { m_subParticles.push_back(val); }
  150. void ClearSubParticles() { m_subParticles.clear(); }
  151. BOOL IsConnected(COTSParticle* a_p, int fldwidth, int fldheight, int direction);
  152. BOOL IfContain(CPoint pos);//determine if the point is in the region of this particle.
  153. int GetGroupId() { return (int)m_grpId; }
  154. void SetGroupId(int a_grpId) { m_grpId = (IDENTIFIED_INC_GRP_ID)a_grpId; }
  155. std::string GetGroupName() const { return m_grpName; }
  156. void SetGroupName(std::string val) { m_grpName = val; }
  157. std::string GetGroupColor() const { return m_grpColor; }
  158. void SetGroupColor(std::string val) { m_grpColor = val; }
  159. BOOL IsXrayParticle() const { return m_isXrayParticle; }
  160. void SetIsXrayParticle(bool value) { m_isXrayParticle = value; }
  161. protected:
  162. // cleanup
  163. void Cleanup();
  164. // initialization
  165. void Init();
  166. // duplication
  167. void Duplicate(const COTSParticle& a_oSource);
  168. double GetMorphologyVectorNorm();
  169. std::vector<double> GetMorphData();
  170. bool m_isXrayParticle;
  171. // area
  172. double m_dArea;
  173. double m_dPixelArea;
  174. // rectangle
  175. CRect m_rectParticle;
  176. COTSRect m_OTSRect;
  177. // Feret's diameter
  178. double m_dFeretDiameter;
  179. //最小外接矩形的宽度
  180. double m_Width;
  181. //最小外接矩形的长度
  182. double m_Height;
  183. // STD chemical type
  184. double m_Perimeter;
  185. double m_DMax;
  186. double m_DMin;
  187. double m_Dp;
  188. double m_Di;
  189. double m_Dm;
  190. double m_De;
  191. double m_Orientation;
  192. //GB_CHEMICAL_TYPE m_nChemical;
  193. // gray
  194. BYTE m_cAveGray;
  195. // type
  196. int m_classifyId;
  197. OTS_PARTICLE_TYPE m_nType;
  198. IDENTIFIED_INC_GRP_ID m_grpId;
  199. std::string m_grpName;
  200. std::string m_grpColor;
  201. std::string m_classifyName;
  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. // search id
  211. //int m_nSearchId;
  212. // analysis id
  213. int m_nAnalysisId;
  214. // field id
  215. int m_nFieldId;
  216. // x-ray position
  217. CPoint m_poiXRayPos;
  218. std::vector<CPoint> m_MatrixPoints;
  219. std::vector<CPosXrayPtr> m_MatrixXrayInfo;
  220. CPoint m_absolutPos;//the ots coordinate position in the whole measure area. not the screen position.
  221. // feature
  222. COTSFeaturePtr m_pFeature;
  223. CPosXrayPtr m_pXRayInfo;
  224. double m_vectorNorm=0;
  225. };
  226. typedef std::vector<COTSParticlePtr> __declspec(dllexport) COTSParticleList;
  227. }