123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //
- // Created by lloyd on 2020/9/28.
- //
- #include <iostream>
- #include "gtbaseparamanalysize.h"
- #include <vector>
- #include <cmath>
- #include "gtstandardlization.h"
- #include "gtrunconf.h"
- #include "gtcommonkits.h"
- #include "DataMapping/dgns_gtbaseparam.h"
- double gtstandardlization::x_Standardization(double S, double MinS, double MaxS) {
- return (S - MinS) / (MaxS - MinS) * (MaxX - MinX) + OffsetX;
- }
- double gtstandardlization::y_Standardization1(double F, double MinF, double MaxF) {
- return (F - MinF) / (MaxF - MinF) * (MaxY - MinY) + OffsetY;
- }
- double gtstandardlization::y_Standardization2(double F, double MaxF) {
- return F / MaxF * (MaxY - MinY) + OffsetY;
- }
- void gtstandardlization::standardization(dgns_gtbaseparam *_baseparam) {
- if (gt_Standard1.empty() == false) {
- gt_Standard1.clear();
- }
- if (gt_Standard2.empty() == false) {
- gt_Standard2.clear();
- }
- int i;
- if (_baseparam == NULL)return;
- for (i = 0; i < _baseparam->sgtpointnum; i++) {
- double x = x_Standardization(_baseparam->sgt[i][0],_baseparam->s_min,
- _baseparam->s_max); //其中param.S_Min, param.S_Max需要调用param对象
- double y1 = y_Standardization1(_baseparam->sgt[i][1], _baseparam->l_min,
- _baseparam->l_max); //其中param.MinLoad, param.MaxLoad需要调用param对象
- double y2 = y_Standardization2(_baseparam->sgt[i][1], _baseparam->l_max); //其中param.MaxLoad需要调用param对象
- std::vector<double> p1 = {x, y1};
- gt_Standard1.push_back(p1);
- std::vector<double> p2 = {x, y2};
- gt_Standard2.push_back(p2);
- }
- }
- int gtstandardlization::formateX(int x) {
- if (x < 0) return 0;
- if (x > MapX) return MapX;
- return x;
- }
- int gtstandardlization::formateY(int y) {
- if (y < 0) return 0;
- if (y > MapY) return MapY;
- return y;
- }
- int gtstandardlization::optimiNeedCount(std::vector<std::vector<double>> &temp) {
- double d = 0;
- int sizetmp = temp.size();
- for (int i = 0; i < sizetmp - 1; i++) {
- double xd = std::abs(temp[i][0] - temp[i + 1][0]);
- double yd = std::abs(temp[i][1] - temp[i + 1][1]);
- double di = sqrt(xd * xd + yd * yd);
- d += di;
- }
- int dint = ceil(d);
- return dint;
- }
- // 填充绘制
- void gtstandardlization::paddingMap() {
- if (mapGT_Standard1.empty() == false) mapGT_Standard1.clear();
- if (mapGT_Standard2.empty() == false) mapGT_Standard2.clear();
- if (gt_Standard1.empty() || gt_Standard2.empty()) return;
- if (gt_Standard1.size() <= 0 || gt_Standard2.size() <= 0) return;
- int n = 3;//初始阶数(其实阶数=点数-1,少于两个点pass)
- gtcommonkits cal;
- //计算平滑插值
- for (int i = 0; i < gt_Standard1.size() && i < gt_Standard2.size(); i += n - 1) {
- std::vector<std::vector<double>> temp_n1;
- std::vector<std::vector<double>> temp_n2;
- int k = i;
- for (; k - i < n && k < gt_Standard1.size() && k < gt_Standard2.size(); k++) {
- std::vector<double> temp_point1 = {gt_Standard1[k][0], gt_Standard1[k][1]};
- temp_n1.push_back(temp_point1);
- std::vector<double> temp_point2 = {gt_Standard2[k][0], gt_Standard2[k][1]};
- temp_n2.push_back(temp_point2);
- }
- if (k == gt_Standard1.size() || k == gt_Standard2.size()) {
- std::vector<double> temp_point1 = {gt_Standard1[0][0], gt_Standard1[0][1]};
- temp_n1.push_back(temp_point1);
- std::vector<double> temp_point2 = {gt_Standard2[0][0], gt_Standard2[0][1]};
- temp_n2.push_back(temp_point2);
- }
- int counttemp = optimiNeedCount(temp_n1);
- std::vector<std::vector<double>> r1 = cal.BezierInterpolation(temp_n1, counttemp, 2);
- std::vector<std::vector<double>> r2 = cal.BezierInterpolation(temp_n2, counttemp, 2);
- for (int j = 0; j < counttemp; j++) {
- std::vector<int> mapGT_unit1 = {formateX((int) round(r1[j][0])), formateY((int) round(r1[j][1]))};
- mapGT_Standard1.push_back(mapGT_unit1);
- std::vector<int> mapGT_unit2 = {formateX((int) round(r2[j][0])), formateY((int) round(r2[j][1]))};
- mapGT_Standard2.push_back(mapGT_unit2);
- }
- if (k == gt_Standard1.size() || k == gt_Standard2.size()) break;
- }
- }
- gtstandardlization::gtstandardlization() {
- MapX = mapgt_MapX;
- MapY = mapgt_MapY;
- MinX = mapgt_MinX;
- MaxX = mapgt_MaxX;
- MinY = mapgt_MinY;
- MaxY = mapgt_MaxY;
- // 偏移量x
- OffsetX = mapgt_OffsetX;
- // 偏移量y
- OffsetY = mapgt_OffsetY;
- }
|