AbandClipCfg.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #ifndef __ABANDCLIP_CFG_H
  2. #define __ABANDCLIP_CFG_H
  3. #include "MAS_AlgoDef.h"
  4. #define NAMESPACE_ABANDCLIP_BEGIN namespace abandclip {
  5. #define NAMESPACE_ABANDCLIP_END };
  6. NAMESPACE_MAS_BEGIN
  7. NAMESPACE_ABANDCLIP_BEGIN
  8. struct DataItem {
  9. TZ_FLOAT val;
  10. std::string toJson() const
  11. {
  12. tzc::json::JsonDoc document;
  13. document.SetObject();
  14. tzc::json::setFiled(document, "val", val);
  15. return tzc::json::ValueToJson(document);
  16. }
  17. static TZ_BOOL fromJson(const std::string& json, DataItem& value)
  18. {
  19. tzc::json::JsonDoc document;
  20. document.Parse(json.c_str());
  21. if (document.HasParseError())
  22. {
  23. return FALSE;
  24. }
  25. value.val = tzc::json::getFiled(document, "val", 0.0f);
  26. return TRUE;
  27. }
  28. };
  29. struct TextFeature {
  30. std::string text;
  31. std::vector<DataItem> features;
  32. std::string toJson() const
  33. {
  34. tzc::json::JsonDoc document;
  35. document.SetObject();
  36. tzc::json::setFiled(document, "text", text);
  37. tzc::json::setFiledArrayObject(document, "features", features);
  38. return tzc::json::ValueToJson(document);
  39. }
  40. static TZ_BOOL fromJson(const std::string & json, TextFeature & value)
  41. {
  42. tzc::json::JsonDoc document;
  43. document.Parse(json.c_str());
  44. if (document.HasParseError())
  45. {
  46. return false;
  47. }
  48. value.text = tzc::json::getFiled(document, "text", "");
  49. TZ_BOOL rst = TRUE;
  50. rst &= tzc::json::ConverArrayObject(document, "features", value.features);
  51. return true;
  52. }
  53. };
  54. struct AbandClipCfg {
  55. TZ_DOUBLE FeatureThreshold;
  56. std::string FeatureFilePath;
  57. AbandClipCfg() : FeatureThreshold(10.0){}
  58. std::string toJson() const
  59. {
  60. tzc::json::JsonDoc document;
  61. document.SetObject();
  62. tzc::json::setFiled(document, "FeatureThreshold", FeatureThreshold);
  63. tzc::json::setFiled(document, "FeatureFilePath", FeatureFilePath);
  64. return tzc::json::ValueToJson(document);
  65. }
  66. static TZ_BOOL fromJson(const std::string & json, AbandClipCfg & value)
  67. {
  68. tzc::json::JsonDoc document;
  69. document.Parse(json.c_str());
  70. if (document.HasParseError())
  71. {
  72. return false;
  73. }
  74. value.FeatureThreshold = tzc::json::getFiled(document, "FeatureThreshold", 10.0);
  75. value.FeatureFilePath = tzc::json::getFiled(document, "FeatureFilePath", "");
  76. return true;
  77. }
  78. };
  79. struct AbandClipStrategyExterns {
  80. std::string Description;
  81. AbandClipStrategyExterns() : Description("") {}
  82. std::string toJson() const
  83. {
  84. tzc::json::JsonDoc document;
  85. document.SetObject();
  86. tzc::json::setFiled(document, "Description", Description);
  87. return tzc::json::ValueToJson(document);
  88. }
  89. static TZ_BOOL fromJson(const std::string & json, AbandClipStrategyExterns & value)
  90. {
  91. tzc::json::JsonDoc document;
  92. document.Parse(json.c_str());
  93. if (document.HasParseError())
  94. {
  95. return false;
  96. }
  97. value.Description = tzc::json::getFiled(document, "Description", "");
  98. return true;
  99. }
  100. };
  101. NAMESPACE_ABANDCLIP_END
  102. NAMESPACE_MAS_END
  103. #endif