gtstandardlization.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Created by lloyd on 2020/9/28.
  3. //
  4. #include <iostream>
  5. #include "gtbaseparamanalysize.h"
  6. #include <vector>
  7. #include <cmath>
  8. #include "gtstandardlization.h"
  9. #include "gtrunconf.h"
  10. #include "gtcommonkits.h"
  11. #include "DataMapping/dgns_gtbaseparam.h"
  12. double gtstandardlization::x_Standardization(double S, double MinS, double MaxS) {
  13. return (S - MinS) / (MaxS - MinS) * (MaxX - MinX) + OffsetX;
  14. }
  15. double gtstandardlization::y_Standardization1(double F, double MinF, double MaxF) {
  16. return (F - MinF) / (MaxF - MinF) * (MaxY - MinY) + OffsetY;
  17. }
  18. double gtstandardlization::y_Standardization2(double F, double MaxF) {
  19. return F / MaxF * (MaxY - MinY) + OffsetY;
  20. }
  21. void gtstandardlization::standardization(dgns_gtbaseparam *_baseparam) {
  22. if (gt_Standard1.empty() == false) {
  23. gt_Standard1.clear();
  24. }
  25. if (gt_Standard2.empty() == false) {
  26. gt_Standard2.clear();
  27. }
  28. int i;
  29. if (_baseparam == NULL)return;
  30. for (i = 0; i < _baseparam->sgtpointnum; i++) {
  31. double x = x_Standardization(_baseparam->sgt[i][0],_baseparam->s_min,
  32. _baseparam->s_max); //其中param.S_Min, param.S_Max需要调用param对象
  33. double y1 = y_Standardization1(_baseparam->sgt[i][1], _baseparam->l_min,
  34. _baseparam->l_max); //其中param.MinLoad, param.MaxLoad需要调用param对象
  35. double y2 = y_Standardization2(_baseparam->sgt[i][1], _baseparam->l_max); //其中param.MaxLoad需要调用param对象
  36. std::vector<double> p1 = {x, y1};
  37. gt_Standard1.push_back(p1);
  38. std::vector<double> p2 = {x, y2};
  39. gt_Standard2.push_back(p2);
  40. }
  41. }
  42. int gtstandardlization::formateX(int x) {
  43. if (x < 0) return 0;
  44. if (x > MapX) return MapX;
  45. return x;
  46. }
  47. int gtstandardlization::formateY(int y) {
  48. if (y < 0) return 0;
  49. if (y > MapY) return MapY;
  50. return y;
  51. }
  52. int gtstandardlization::optimiNeedCount(std::vector<std::vector<double>> &temp) {
  53. double d = 0;
  54. int sizetmp = temp.size();
  55. for (int i = 0; i < sizetmp - 1; i++) {
  56. double xd = std::abs(temp[i][0] - temp[i + 1][0]);
  57. double yd = std::abs(temp[i][1] - temp[i + 1][1]);
  58. double di = sqrt(xd * xd + yd * yd);
  59. d += di;
  60. }
  61. int dint = ceil(d);
  62. return dint;
  63. }
  64. // 填充绘制
  65. void gtstandardlization::paddingMap() {
  66. if (mapGT_Standard1.empty() == false) mapGT_Standard1.clear();
  67. if (mapGT_Standard2.empty() == false) mapGT_Standard2.clear();
  68. if (gt_Standard1.empty() || gt_Standard2.empty()) return;
  69. if (gt_Standard1.size() <= 0 || gt_Standard2.size() <= 0) return;
  70. int n = 3;//初始阶数(其实阶数=点数-1,少于两个点pass)
  71. gtcommonkits cal;
  72. //计算平滑插值
  73. for (int i = 0; i < gt_Standard1.size() && i < gt_Standard2.size(); i += n - 1) {
  74. std::vector<std::vector<double>> temp_n1;
  75. std::vector<std::vector<double>> temp_n2;
  76. int k = i;
  77. for (; k - i < n && k < gt_Standard1.size() && k < gt_Standard2.size(); k++) {
  78. std::vector<double> temp_point1 = {gt_Standard1[k][0], gt_Standard1[k][1]};
  79. temp_n1.push_back(temp_point1);
  80. std::vector<double> temp_point2 = {gt_Standard2[k][0], gt_Standard2[k][1]};
  81. temp_n2.push_back(temp_point2);
  82. }
  83. if (k == gt_Standard1.size() || k == gt_Standard2.size()) {
  84. std::vector<double> temp_point1 = {gt_Standard1[0][0], gt_Standard1[0][1]};
  85. temp_n1.push_back(temp_point1);
  86. std::vector<double> temp_point2 = {gt_Standard2[0][0], gt_Standard2[0][1]};
  87. temp_n2.push_back(temp_point2);
  88. }
  89. int counttemp = optimiNeedCount(temp_n1);
  90. std::vector<std::vector<double>> r1 = cal.BezierInterpolation(temp_n1, counttemp, 2);
  91. std::vector<std::vector<double>> r2 = cal.BezierInterpolation(temp_n2, counttemp, 2);
  92. for (int j = 0; j < counttemp; j++) {
  93. std::vector<int> mapGT_unit1 = {formateX((int) round(r1[j][0])), formateY((int) round(r1[j][1]))};
  94. mapGT_Standard1.push_back(mapGT_unit1);
  95. std::vector<int> mapGT_unit2 = {formateX((int) round(r2[j][0])), formateY((int) round(r2[j][1]))};
  96. mapGT_Standard2.push_back(mapGT_unit2);
  97. }
  98. if (k == gt_Standard1.size() || k == gt_Standard2.size()) break;
  99. }
  100. }
  101. gtstandardlization::gtstandardlization() {
  102. MapX = mapgt_MapX;
  103. MapY = mapgt_MapY;
  104. MinX = mapgt_MinX;
  105. MaxX = mapgt_MaxX;
  106. MinY = mapgt_MinY;
  107. MaxY = mapgt_MaxY;
  108. // 偏移量x
  109. OffsetX = mapgt_OffsetX;
  110. // 偏移量y
  111. OffsetY = mapgt_OffsetY;
  112. }