diff --git a/compute/bessel.cpp b/compute/bessel.cpp new file mode 100644 index 0000000..84bf8b3 --- /dev/null +++ b/compute/bessel.cpp @@ -0,0 +1,33 @@ + +#include "bessel.h" + +vector Bessel::run(const vector &points, double step) { + vector res; + for (float t = 0; t <= 1; t += step) { + Point p = bezier_curve(points, t); + res.push_back(p); + } + return res; +} + +// 计算n次贝塞尔曲线上的点 +Point Bessel::bezier_curve(const vector &points, double t) { + int n = points.size() - 1; + Point res; + for (int i = 0; i <= n; ++i) { + double b = binomial(n, i)* pow(t, i) * pow(1 - t, n - i); + res.x = res.x + points[i].x * b; + res.y = res.y + points[i].y * b; + res.z = res.z + points[i].z * b; + } + return res; +} + +// 计算组合数 +int Bessel::binomial(int n, int i) { + int res = 1; + for (int j = 1; j <= i; ++j) { + res *= (n - j + 1) / (double)j; //(double)十分关键,不然j=i=n时,j为分数=0; + } + return res; +} diff --git a/compute/bessel.h b/compute/bessel.h new file mode 100644 index 0000000..74cbc6e --- /dev/null +++ b/compute/bessel.h @@ -0,0 +1,30 @@ + +#ifndef CSCI_BESSEL_H +#define CSCI_BESSEL_H + +#include +#include + +using namespace std; + +struct Point { + double x, y, z; + Point(double x = 0, double y = 0 ,double z=0):x(x),y(y),z(z){} +}; + +class Bessel { + +public: + + static vector run(const vector& points, double step); + +private: + + static int binomial(int n, int i); + + static Point bezier_curve(const vector& points, double t); + +}; + + +#endif //CSCI_BESSEL_H diff --git a/compute/operator.cpp b/compute/operator.cpp index ec9af47..5d50df6 100644 --- a/compute/operator.cpp +++ b/compute/operator.cpp @@ -1,2 +1,49 @@ #include "operator.h" + +void Operator::init(int modelType, int signalType, const QMap ¶ms) { + // TODO + _modeType = modelType; + _signalType = signalType; + _params = params; + + _deduceMotionLib(); + _deduceSignalLib(); +} + +void Operator::_deduceMotionLib() { + // TODO + _motionLib = ""; +} + +void Operator::_deduceSignalLib() { + // TODO + _signalLib = ""; +} + +void Operator::update() { + // TODO 加载库并执行 + +} + +QVariant Operator::report(int beat) { + + if (shouldUpdate()) { + update(); + } + + return _states.at(beat); +} + +bool Operator::shouldUpdate() { + return _hash() == _paramsHash; +} + +QString Operator::_hash() { + + // TODO 对参数排序求hash + +// QCryptographicHash::hash (_params, QCryptographicHash::Md5 ) + + return ""; +} diff --git a/compute/operator.h b/compute/operator.h index 9ffb420..37bf10b 100644 --- a/compute/operator.h +++ b/compute/operator.h @@ -2,33 +2,43 @@ #ifndef CSCI_OPERATOR_H #define CSCI_OPERATOR_H +#include +#include class Operator { -public: +private: + int _modeType; + int _signalType; + QMap _params; + QString _paramsHash; - /// 初始化 - void init(); + QString _motionLib; + QString _signalLib; - /// 更新 - void update(); - - /// 上报状态 - void report(); + QList _states; - /// +private: + void _deduceMotionLib(); -private: - /// 模型参数 - int model; + void _deduceSignalLib(); + QString _hash(); +public: + /// 初始化 + void init(int modelType, int signalType, const QMap& params); + /// 更新 + void update(); + /// 上报状态 + QVariant report(int beat); + bool shouldUpdate(); }; diff --git a/controller/map_controller.cpp b/controller/map_controller.cpp index 3aac631..479b2c0 100644 --- a/controller/map_controller.cpp +++ b/controller/map_controller.cpp @@ -6,16 +6,13 @@ bool MapController::loadMap(long mapId) { qDebug() << mapEntity.mapName; - // TODO 获取数据 // 分析模型 // 初始化 - return false; } void MapController::route(const QString& key, const QString& message) { - qDebug() << key << ":" << message; // TODO route to function if(key == "loadMap"){ diff --git a/main.cpp b/main.cpp index 26d7962..0f607d4 100644 --- a/main.cpp +++ b/main.cpp @@ -131,6 +131,24 @@ void boost_test(){ } } +#include "./compute/bessel.h" + +void bessel_test(){ + + vector points = {{0.0,0.0,0.0}, {20.0, 80.0,70.0},{40.0,120.0,68.0},{80.0,240.0,68.0}}; + + vector res = Bessel::run(points, 0.02); + + string filename = R"(test_1.csv)"; + ofstream ofs(filename); + ofs << "x,y,z" << endl; + + for (const auto &item: res){ + ofs << item.x << "," << item.y << "," << item.z << endl; + } + ofs.close(); +} + /// TODO 当前是将消息广播全部消费者自行判断是否消费,该种机制是否合理后续在进行论证 int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); @@ -149,7 +167,8 @@ int main(int argc, char *argv[]) { // headers->add("token", "safdasgdagafgafdsghfsjh"); // KafkaHandler::message("test_topic" , msg, key , headers); - boost_test(); +// boost_test(); + bessel_test(); /// test -end return QCoreApplication::exec();