MAS_AlgoDef.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. #ifndef __MAS_ALGO_DEF_H
  2. #define __MAS_ALGO_DEF_H
  3. #include "MAS_Definition.h"
  4. #include "TZJson.h"
  5. NAMESPACE_MAS_BEGIN
  6. typedef enum __DET_INIT_TYPE_CODE {
  7. DIT_INT = 0x00,
  8. DIT_DOUBLE = 0x01,
  9. DIT_STRING = 0x02,
  10. DIT_BOOL = 0x03,
  11. DIT_FORM = 0x04
  12. } EN_INIT_CODE;
  13. typedef enum __DET_DET_AREA_CODE {
  14. DDA_ROI = 0x00,
  15. DDA_IGNORE = 0x01,
  16. DDA_LINE = 0x02
  17. } EN_DET_AREA_CODE;
  18. typedef enum __STRA_RESTLT_TYPE {
  19. SRT_NONE,
  20. SRT_EVENT,
  21. SRT_ALARM,
  22. SRT_NOT_SHOW = 0x1000,
  23. } EN_STRA_RESULT;
  24. struct TextInfo {
  25. std::string Text;
  26. TZ_FLOAT TextLTX;
  27. TZ_FLOAT TextLTY;
  28. std::string TextColor;
  29. TZ_INT TextSize;
  30. TZ_INT TextThickness;
  31. std::string BackgroundColor;
  32. TextInfo() : Text(""), TextLTX(-1),
  33. TextLTY(-1), TextColor("#000000"),
  34. TextSize(2), TextThickness(1),
  35. BackgroundColor("") {}
  36. TextInfo(std::string text, TZ_FLOAT x, TZ_FLOAT y,
  37. const std::string & color = "#000000",
  38. TZ_INT size = 2, TZ_INT thickness = 1,
  39. std::string backgroundColor = "") :
  40. Text(text), TextLTX(x), TextLTY(y), TextColor(color),
  41. TextSize(size), TextThickness(thickness),
  42. BackgroundColor(backgroundColor) {}
  43. TextInfo(const TextInfo & origin) :
  44. Text(origin.Text), TextLTX(origin.TextLTX),
  45. TextLTY(origin.TextLTY), TextColor(origin.TextColor),
  46. TextSize(origin.TextSize), TextThickness(origin.TextThickness),
  47. BackgroundColor(origin.BackgroundColor) {}
  48. std::string toJson() const
  49. {
  50. tzc::json::JsonDoc document;
  51. document.SetObject();
  52. tzc::json::setFiled(document, "Text", Text);
  53. tzc::json::setFiled(document, "TextLTX", TextLTX);
  54. tzc::json::setFiled(document, "TextLTY", TextLTY);
  55. tzc::json::setFiled(document, "TextColor", TextColor);
  56. tzc::json::setFiled(document, "TextSize", TextSize);
  57. tzc::json::setFiled(document, "TextThickness", TextThickness);
  58. tzc::json::setFiled(document, "BackgroundColor", BackgroundColor);
  59. return tzc::json::ValueToJson(document);
  60. }
  61. static TZ_BOOL fromJson(const std::string & json, TextInfo & value)
  62. {
  63. tzc::json::JsonDoc document;
  64. document.Parse(json.c_str());
  65. if (document.HasParseError())
  66. {
  67. return FALSE;
  68. }
  69. value.Text = tzc::json::getFiled(document, "Text", "");
  70. value.TextLTX = tzc::json::getFiled(document, "TextLTX", 0.0f);
  71. value.TextLTY = tzc::json::getFiled(document, "TextLTY", 0.0f);
  72. value.TextColor = tzc::json::getFiled(document, "TextColor", "#000000");
  73. value.TextSize = tzc::json::getFiled(document, "TextSize", 0);
  74. value.TextThickness = tzc::json::getFiled(document, "TextThickness", 0);
  75. value.BackgroundColor = tzc::json::getFiled(document, "BackgroundColor", "");
  76. return TRUE;
  77. }
  78. };
  79. struct RectInfo {
  80. TZ_FLOAT LTX;
  81. TZ_FLOAT LTY;
  82. TZ_FLOAT RBX;
  83. TZ_FLOAT RBY;
  84. std::string Color;
  85. TZ_INT Thickness;
  86. TextInfo Text;
  87. RectInfo() : LTX(-1), LTY(-1), RBX(-1), RBY(-1),
  88. Color("#000000"), Thickness(1), Text(TextInfo()) {}
  89. RectInfo(TZ_FLOAT x1, TZ_FLOAT y1, TZ_FLOAT x2, TZ_FLOAT y2,
  90. const std::string & color = "#000000", TZ_INT thickness = 1,
  91. const TextInfo & text = TextInfo()) :
  92. LTX(x1) , LTY(y1), RBX(x2), RBY(y2), Color(color),
  93. Thickness(thickness), Text(text) {}
  94. std::string toJson() const
  95. {
  96. tzc::json::JsonDoc document;
  97. document.SetObject();
  98. tzc::json::setFiled(document, "LTX", LTX);
  99. tzc::json::setFiled(document, "LTY", LTY);
  100. tzc::json::setFiled(document, "RBX", RBX);
  101. tzc::json::setFiled(document, "RBY", RBY);
  102. tzc::json::setFiled(document, "Color", Color);
  103. tzc::json::setFiled(document, "Thickness", Thickness);
  104. tzc::json::setFiledParams(document, "Text", Text);
  105. return tzc::json::ValueToJson(document);
  106. }
  107. static TZ_BOOL fromJson(const std::string & json, RectInfo & value)
  108. {
  109. tzc::json::JsonDoc document;
  110. document.Parse(json.c_str());
  111. if (document.HasParseError())
  112. {
  113. return FALSE;
  114. }
  115. value.LTX = tzc::json::getFiled(document, "LTX", 0.0f);
  116. value.LTY = tzc::json::getFiled(document, "LTY", 0.0f);
  117. value.RBX = tzc::json::getFiled(document, "RBX", 0.0f);
  118. value.RBY = tzc::json::getFiled(document, "RBY", 0.0f);
  119. value.Color = tzc::json::getFiled(document, "Color", "#000000");
  120. value.Thickness = tzc::json::getFiled(document, "Thickness", 0);
  121. tzc::json::getFiledParams(document, "Text", value.Text);
  122. return TRUE;
  123. }
  124. };
  125. struct PointInfo {
  126. TZ_FLOAT X;
  127. TZ_FLOAT Y;
  128. std::string Color;
  129. TZ_INT Thickness;
  130. TZ_INT Shape;
  131. TextInfo Text;
  132. PointInfo() : X(-1), Y(-1), Color("#000000"), Thickness(0),
  133. Shape(-1), Text(TextInfo()) {}
  134. PointInfo(TZ_FLOAT x, TZ_FLOAT y,
  135. const std::string & color = "#000000",
  136. TZ_INT thickness = 0, TZ_INT shape = 0,
  137. const TextInfo & text = TextInfo()) :
  138. X(x), Y(y), Color(color),
  139. Thickness(thickness), Shape(shape), Text(text) {}
  140. std::string toJson() const
  141. {
  142. tzc::json::JsonDoc document;
  143. document.SetObject();
  144. tzc::json::setFiled(document, "X", X);
  145. tzc::json::setFiled(document, "Y", Y);
  146. tzc::json::setFiled(document, "Color", Color);
  147. tzc::json::setFiled(document, "Thickness", Thickness);
  148. tzc::json::setFiled(document, "Shape", Shape);
  149. tzc::json::setFiledParams(document, "Text", Text);
  150. return tzc::json::ValueToJson(document);
  151. }
  152. static TZ_BOOL fromJson(const std::string & json, PointInfo & value)
  153. {
  154. tzc::json::JsonDoc document;
  155. document.Parse(json.c_str());
  156. if (document.HasParseError())
  157. {
  158. return FALSE;
  159. }
  160. value.X = tzc::json::getFiled(document, "X", 0.0f);
  161. value.Y = tzc::json::getFiled(document, "Y", 0.0f);
  162. value.Color = tzc::json::getFiled(document, "Color", "#000000");
  163. value.Thickness = tzc::json::getFiled(document, "Thickness", 0);
  164. value.Shape = tzc::json::getFiled(document, "Shape", 0);
  165. tzc::json::getFiledParams(document, "Text", value.Text);
  166. return TRUE;
  167. }
  168. };
  169. struct LineInfo {
  170. TZ_FLOAT StartX;
  171. TZ_FLOAT StartY;
  172. TZ_FLOAT EndX;
  173. TZ_FLOAT EndY;
  174. std::string Color;
  175. TZ_INT Thickness;
  176. TZ_INT Shape;
  177. TextInfo Text;
  178. LineInfo() : StartX(-1), StartY(-1), EndX(-1), EndY(-1),
  179. Color("#000000"), Thickness(0),
  180. Shape(-1), Text(TextInfo()) {}
  181. LineInfo(TZ_FLOAT x1, TZ_FLOAT y1, TZ_FLOAT x2, TZ_FLOAT y2,
  182. const std::string & color = "#000000",
  183. TZ_INT thickness = 0, TZ_INT shape = 0,
  184. const TextInfo & text = TextInfo()) :
  185. StartX(x1), StartY(y1), EndX(x2), EndY(y2), Color(color),
  186. Thickness(thickness), Shape(shape), Text(text) {}
  187. std::string toJson() const
  188. {
  189. tzc::json::JsonDoc document;
  190. document.SetObject();
  191. tzc::json::setFiled(document, "StartX", StartX);
  192. tzc::json::setFiled(document, "StartY", StartY);
  193. tzc::json::setFiled(document, "EndX", EndX);
  194. tzc::json::setFiled(document, "EndY", EndY);
  195. tzc::json::setFiled(document, "Color", Color);
  196. tzc::json::setFiled(document, "Thickness", Thickness);
  197. tzc::json::setFiled(document, "Shape", Shape);
  198. tzc::json::setFiledParams(document, "Text", Text);
  199. return tzc::json::ValueToJson(document);
  200. }
  201. static TZ_BOOL fromJson(const std::string & json, LineInfo & value)
  202. {
  203. tzc::json::JsonDoc document;
  204. document.Parse(json.c_str());
  205. if (document.HasParseError())
  206. {
  207. return FALSE;
  208. }
  209. value.StartX = tzc::json::getFiled(document, "StartX", 0.0f);
  210. value.StartY = tzc::json::getFiled(document, "StartY", 0.0f);
  211. value.EndX = tzc::json::getFiled(document, "EndX", 0.0f);
  212. value.EndY = tzc::json::getFiled(document, "EndY", 0.0f);
  213. value.Color = tzc::json::getFiled(document, "Color", "#000000");
  214. value.Thickness = tzc::json::getFiled(document, "Thickness", 0);
  215. value.Shape = tzc::json::getFiled(document, "Shape", 0);
  216. tzc::json::getFiledParams(document, "Text", value.Text);
  217. return TRUE;
  218. }
  219. };
  220. struct DrawInfo {
  221. std::vector<RectInfo> Rects;
  222. std::vector<PointInfo> Points;
  223. std::vector<LineInfo> Lines;
  224. std::string toJson() const
  225. {
  226. tzc::json::JsonDoc document;
  227. document.SetObject();
  228. tzc::json::setFiledArrayObject(document, "Rects", Rects);
  229. tzc::json::setFiledArrayObject(document, "Points", Points);
  230. tzc::json::setFiledArrayObject(document, "Lines", Lines);
  231. return tzc::json::ValueToJson(document);
  232. }
  233. static TZ_BOOL fromJson(const std::string & json, DrawInfo & value)
  234. {
  235. tzc::json::JsonDoc document;
  236. document.Parse(json.c_str());
  237. if (document.HasParseError())
  238. {
  239. return FALSE;
  240. }
  241. TZ_BOOL rst = TRUE;
  242. rst &= tzc::json::ConverArrayObject(document, "Rects", value.Rects);
  243. rst &= tzc::json::ConverArrayObject(document, "Points", value.Points);
  244. rst &= tzc::json::ConverArrayObject(document, "Lines", value.Lines);
  245. return TRUE;
  246. }
  247. void clear()
  248. {
  249. Rects.clear();
  250. Points.clear();
  251. Lines.clear();
  252. }
  253. };
  254. struct DetectCfg {
  255. TZ_INT Type; // EN_INIT_CODE
  256. std::string Key;
  257. std::string Name;
  258. std::string DefaultValue;
  259. std::string MinValue;
  260. std::string MaxValue;
  261. std::string StepValue;
  262. std::vector<std::string> Form; // 用于 Yolo。待改进 TODO
  263. DetectCfg() {}
  264. DetectCfg(TZ_INT type, const std::string & key, const std::string & name,
  265. const std::string & defaultValue, const std::string & minValue,
  266. const std::string & maxValue, const std::string & stepValue,
  267. const std::vector<std::string> & form = {}) :
  268. Type(type), Key(key), Name(name), DefaultValue(defaultValue),
  269. MinValue(minValue), MaxValue(maxValue), StepValue(stepValue),
  270. Form(form) {}
  271. DetectCfg(const DetectCfg & origin) :
  272. Type(origin.Type), Key(origin.Key), Name(origin.Name),
  273. DefaultValue(origin.DefaultValue), MinValue(origin.MinValue),
  274. MaxValue(origin.MaxValue), StepValue(origin.StepValue),
  275. Form(origin.Form) {}
  276. std::string toJson() const
  277. {
  278. tzc::json::JsonDoc document;
  279. document.SetObject();
  280. tzc::json::setFiled(document, "Type", Type);
  281. tzc::json::setFiled(document, "Key", Key);
  282. tzc::json::setFiled(document, "Name", Name);
  283. tzc::json::setFiled(document, "DefaultValue", DefaultValue);
  284. tzc::json::setFiled(document, "MinValue", MinValue);
  285. tzc::json::setFiled(document, "MaxValue", MaxValue);
  286. tzc::json::setFiled(document, "StepValue", StepValue);
  287. tzc::json::setFiledParams(document, "Form", Form);
  288. return tzc::json::ValueToJson(document);
  289. }
  290. static TZ_BOOL fromJson(const std::string & json, DetectCfg & value)
  291. {
  292. tzc::json::JsonDoc document;
  293. document.Parse(json.c_str());
  294. if (document.HasParseError())
  295. {
  296. return false;
  297. }
  298. value.Type = tzc::json::getFiled(document, "Type", 0);
  299. value.Key = tzc::json::getFiled(document, "Key", "");
  300. value.Name = tzc::json::getFiled(document, "Name", "");
  301. value.DefaultValue = tzc::json::getFiled(document, "DefaultValue", "");
  302. value.MinValue = tzc::json::getFiled(document, "MinValue", "");
  303. value.MaxValue = tzc::json::getFiled(document, "MaxValue", "");
  304. value.StepValue = tzc::json::getFiled(document, "StepValue", "");
  305. tzc::json::getFiledParams(document, "Form", value.Form);
  306. return TRUE;
  307. }
  308. };
  309. struct StraCfg {
  310. TZ_INT Type; // EN_INIT_CODE
  311. std::string Key;
  312. std::string Name;
  313. std::string Value;
  314. std::string DefaultValue;
  315. std::string MinValue;
  316. std::string MaxValue;
  317. std::string StepValue;
  318. std::string Explanation;
  319. StraCfg() {}
  320. StraCfg(TZ_INT type, const std::string & key, const std::string & name,
  321. const std::string & defaultvalue, const std::string & minValue,
  322. const std::string & maxValue, const std::string & step,
  323. const std::string & explanation) :
  324. Type(type), Key(key), Name(name), DefaultValue(defaultvalue),
  325. MinValue(minValue), MaxValue(maxValue), StepValue(step),
  326. Explanation(explanation) {}
  327. std::string toJson() const
  328. {
  329. tzc::json::JsonDoc document;
  330. document.SetObject();
  331. tzc::json::setFiled(document, "Type", Type);
  332. tzc::json::setFiled(document, "Key", Key);
  333. tzc::json::setFiled(document, "Name", Name);
  334. tzc::json::setFiled(document, "DefaultValue", DefaultValue);
  335. tzc::json::setFiled(document, "MinValue", MinValue);
  336. tzc::json::setFiled(document, "MaxValue", MaxValue);
  337. tzc::json::setFiled(document, "StepValue", StepValue);
  338. tzc::json::setFiled(document, "Explanation", Explanation);
  339. return tzc::json::ValueToJson(document);
  340. }
  341. static TZ_BOOL fromJson(const std::string & json, StraCfg & value)
  342. {
  343. tzc::json::JsonDoc document;
  344. document.Parse(json.c_str());
  345. if (document.HasParseError())
  346. {
  347. return FALSE;
  348. }
  349. value.Type = tzc::json::getFiled(document, "Type", 0);
  350. value.Key = tzc::json::getFiled(document, "Key", "");
  351. value.Name = tzc::json::getFiled(document, "Name", "");
  352. value.DefaultValue = tzc::json::getFiled(document, "DefaultValue", "");
  353. value.MinValue = tzc::json::getFiled(document, "MinValue", "");
  354. value.MaxValue = tzc::json::getFiled(document, "MaxValue", "");
  355. value.StepValue = tzc::json::getFiled(document, "StepValue", "");
  356. value.Explanation = tzc::json::getFiled(document, "Explanation", "");
  357. return TRUE;
  358. }
  359. };
  360. struct DetectorInfo {
  361. std::string Key;
  362. std::string Name;
  363. std::string Version;
  364. std::string Author;
  365. std::string UpdateDate;
  366. std::string ParamTemp; // 参数配置模板
  367. std::string RstTemp; // 结果模板
  368. std::string BuildTemp; // 创建条件模板
  369. std::string AreaTemp; // 检测区域设置模板
  370. TZ_INT Id;
  371. TZ_INT InputType; // 输入数据类型 EN_BUFFER_TYPE
  372. std::string Path;
  373. std::string InitParam;
  374. std::string Description;
  375. std::string toJson() const
  376. {
  377. tzc::json::JsonDoc document;
  378. document.SetObject();
  379. tzc::json::setFiled(document, "Id", Id);
  380. tzc::json::setFiled(document, "InputType", InputType);
  381. tzc::json::setFiled(document, "Path", Path);
  382. tzc::json::setFiled(document, "InitParam", InitParam);
  383. tzc::json::setFiled(document, "Description", Description);
  384. tzc::json::setFiled(document, "Key", Key);
  385. tzc::json::setFiled(document, "Name", Name);
  386. tzc::json::setFiled(document, "Version", Version);
  387. tzc::json::setFiled(document, "Author", Author);
  388. tzc::json::setFiled(document, "UpdateDate", UpdateDate);
  389. tzc::json::setFiled(document, "ParamTemp", ParamTemp);
  390. tzc::json::setFiled(document, "RstTemp", RstTemp);
  391. tzc::json::setFiled(document, "BuildTemp", BuildTemp);
  392. tzc::json::setFiled(document, "AreaTemp", AreaTemp);
  393. return tzc::json::ValueToJson(document);
  394. }
  395. static TZ_BOOL fromJson(const std::string & json, DetectorInfo & value)
  396. {
  397. tzc::json::JsonDoc document;
  398. document.Parse(json.c_str());
  399. if (document.HasParseError())
  400. {
  401. return FALSE;
  402. }
  403. value.Id = tzc::json::getFiled(document, "Id", 0);
  404. value.InputType = tzc::json::getFiled(document, "InputType", 0);
  405. value.Path = tzc::json::getFiled(document, "Path", "");
  406. value.InitParam = tzc::json::getFiled(document, "InitParam", "");
  407. value.Description = tzc::json::getFiled(document, "Description", "");
  408. value.Key = tzc::json::getFiled(document, "Key", "");
  409. value.Name = tzc::json::getFiled(document, "Name", "");
  410. value.Version = tzc::json::getFiled(document, "Version", "");
  411. value.Author = tzc::json::getFiled(document, "Author", "");
  412. value.UpdateDate = tzc::json::getFiled(document, "UpdateDate", "");
  413. value.ParamTemp = tzc::json::getFiled(document, "ParamTemp", "");
  414. value.RstTemp = tzc::json::getFiled(document, "RstTemp", "");
  415. value.BuildTemp = tzc::json::getFiled(document, "BuildTemp", "");
  416. value.AreaTemp = tzc::json::getFiled(document, "AreaTemp", "");
  417. return TRUE;
  418. }
  419. };
  420. struct StraDet {
  421. TZ_INT DetId;
  422. TZ_INT Idx;
  423. TZ_INT SIdx;
  424. std::string Key;
  425. std::string Name;
  426. StraDet() {}
  427. StraDet(TZ_INT idx, TZ_INT sidx,
  428. const std::string & key, const std::string & name) :
  429. Idx(idx), SIdx(sidx), Key(key), Name(name) {}
  430. std::string toJson() const
  431. {
  432. tzc::json::JsonDoc document;
  433. document.SetObject();
  434. tzc::json::setFiled(document, "DetId", DetId);
  435. tzc::json::setFiled(document, "Idx", Idx);
  436. tzc::json::setFiled(document, "SIdx", SIdx);
  437. tzc::json::setFiled(document, "Key", Key);
  438. tzc::json::setFiled(document, "Name", Name);
  439. return tzc::json::ValueToJson(document);
  440. }
  441. static TZ_BOOL fromJson(const std::string & json, StraDet & value)
  442. {
  443. tzc::json::JsonDoc document;
  444. document.Parse(json.c_str());
  445. if (document.HasParseError())
  446. {
  447. return FALSE;
  448. }
  449. value.DetId = tzc::json::getFiled(document, "DetId", 0);
  450. value.Idx = tzc::json::getFiled(document, "Idx", 0);
  451. value.SIdx = tzc::json::getFiled(document, "SIdx", 0);
  452. value.Key = tzc::json::getFiled(document, "Key", "");
  453. value.Name = tzc::json::getFiled(document, "Name", "");
  454. return TRUE;
  455. }
  456. };
  457. struct StraRst {
  458. TZ_INT RstType; // EN_STRA_RESULT
  459. TZ_INT SceneId;
  460. std::string RstName;
  461. std::string SceneName;
  462. TZ_Int64 BeginTime;
  463. std::string Externs;
  464. StraRst()
  465. {
  466. RstType = SRT_NONE;
  467. SceneId = -1;
  468. RstName = "";
  469. SceneName = "";
  470. BeginTime = 0;
  471. Externs = "";
  472. }
  473. std::string toJson() const
  474. {
  475. tzc::json::JsonDoc document;
  476. document.SetObject();
  477. tzc::json::setFiled(document, "RstType", RstType);
  478. tzc::json::setFiled(document, "SceneId", SceneId);
  479. tzc::json::setFiled(document, "RstName", RstName);
  480. tzc::json::setFiled(document, "SceneName", SceneName);
  481. tzc::json::setFiled(document, "BeginTime", BeginTime);
  482. tzc::json::setFiled(document, "Externs", Externs);
  483. return tzc::json::ValueToJson(document);
  484. }
  485. static TZ_BOOL fromJson(const std::string & json, StraRst & value)
  486. {
  487. tzc::json::JsonDoc document;
  488. document.Parse(json.c_str());
  489. if (document.HasParseError())
  490. {
  491. return FALSE;
  492. }
  493. value.RstType = tzc::json::getFiled(document, "RstType", 0);
  494. value.SceneId = tzc::json::getFiled(document, "SceneId", 0);
  495. value.RstName = tzc::json::getFiled(document, "RstName", "");
  496. value.SceneName = tzc::json::getFiled(document, "SceneName", "");
  497. value.BeginTime = tzc::json::getFiled(document, "BeginTime", 0);
  498. value.Externs = tzc::json::getFiled(document, "Externs", "");
  499. return TRUE;
  500. }
  501. };
  502. struct StraSamples {
  503. TZ_INT Type;
  504. std::string Name;
  505. StraSamples() {}
  506. StraSamples(TZ_INT type, const std::string & name) :
  507. Type(type), Name(name) {}
  508. std::string toJson() const
  509. {
  510. tzc::json::JsonDoc document;
  511. document.SetObject();
  512. tzc::json::setFiled(document, "Type", Type);
  513. tzc::json::setFiled(document, "Name", Name);
  514. return tzc::json::ValueToJson(document);
  515. }
  516. static TZ_BOOL fromJson(const std::string & json, StraSamples & value)
  517. {
  518. tzc::json::JsonDoc document;
  519. document.Parse(json.c_str());
  520. if (document.HasParseError())
  521. {
  522. return FALSE;
  523. }
  524. value.Type = tzc::json::getFiled(document, "Type", 0);
  525. value.Name = tzc::json::getFiled(document, "Name", "");
  526. return TRUE;
  527. }
  528. };
  529. struct StrategyInfo {
  530. std::string Key;
  531. std::string Name;
  532. std::string Version;
  533. std::string Author;
  534. std::string UpdateDate;
  535. std::string Description;
  536. std::vector<StraDet> StraDets; // 关联检测单元列表
  537. std::vector<StraCfg> StraCfgs; // 详细配置项模板列表
  538. std::vector<StraSamples> StraRsts; // 结果模板列表
  539. TZ_INT Id;
  540. std::string Path;
  541. std::string toJson() const
  542. {
  543. tzc::json::JsonDoc document;
  544. document.SetObject();
  545. tzc::json::setFiled(document, "Id", Id);
  546. tzc::json::setFiled(document, "Path", Path);
  547. tzc::json::setFiled(document, "Key", Key);
  548. tzc::json::setFiled(document, "Name", Name);
  549. tzc::json::setFiled(document, "Version", Version);
  550. tzc::json::setFiled(document, "Author", Author);
  551. tzc::json::setFiled(document, "UpdateDate", UpdateDate);
  552. tzc::json::setFiled(document, "Description", Description);
  553. tzc::json::setFiledParams(document, "StraDets", StraDets);
  554. tzc::json::setFiledParams(document, "StraCfgs", StraCfgs);
  555. tzc::json::setFiledParams(document, "StraRsts", StraRsts);
  556. return tzc::json::ValueToJson(document);
  557. }
  558. static TZ_BOOL fromJson(const std::string & json, StrategyInfo & value)
  559. {
  560. tzc::json::JsonDoc document;
  561. document.Parse(json.c_str());
  562. if (document.HasParseError())
  563. {
  564. return FALSE;
  565. }
  566. value.Id = tzc::json::getFiled(document, "Id", 0);
  567. value.Path = tzc::json::getFiled(document, "Path", "");
  568. value.Key = tzc::json::getFiled(document, "Key", "");
  569. value.Name = tzc::json::getFiled(document, "Name", "");
  570. value.Version = tzc::json::getFiled(document, "Version", "");
  571. value.Author = tzc::json::getFiled(document, "Author", "");
  572. value.UpdateDate = tzc::json::getFiled(document, "UpdateDate", "");
  573. value.Description = tzc::json::getFiled(document, "Description", "");
  574. TZ_BOOL rst = TRUE;
  575. rst &= tzc::json::getFiledParams(document, "StraDets", value.StraDets);
  576. rst &= tzc::json::getFiledParams(document, "StraCfgs", value.StraCfgs);
  577. rst &= tzc::json::getFiledParams(document, "StraRsts", value.StraRsts);
  578. return TRUE;
  579. }
  580. };
  581. // ROI
  582. struct AreaBox {
  583. TZ_DOUBLE LTX;
  584. TZ_DOUBLE LTY;
  585. TZ_DOUBLE RBX;
  586. TZ_DOUBLE RBY;
  587. std::string toJson() const
  588. {
  589. tzc::json::JsonDoc document;
  590. document.SetObject();
  591. tzc::json::setFiled(document, "LTX", LTX);
  592. tzc::json::setFiled(document, "LTY", LTY);
  593. tzc::json::setFiled(document, "RBX", RBX);
  594. tzc::json::setFiled(document, "RBY", RBY);
  595. return tzc::json::ValueToJson(document);
  596. }
  597. static TZ_BOOL fromJson(const std::string & json, AreaBox & value)
  598. {
  599. tzc::json::JsonDoc document;
  600. document.Parse(json.c_str());
  601. if (document.HasParseError())
  602. {
  603. return FALSE;
  604. }
  605. value.LTX = tzc::json::getFiled(document, "LTX", -1.0f);
  606. value.LTY = tzc::json::getFiled(document, "LTY", -1.0f);
  607. value.RBX = tzc::json::getFiled(document, "RBX", -1.0f);
  608. value.RBY = tzc::json::getFiled(document, "RBY", -1.0f);
  609. return TRUE;
  610. }
  611. };
  612. NAMESPACE_MAS_END
  613. #endif