添加model

main
还不如一只猪威武 11 months ago
parent ebb9887739
commit 1725e238ae

@ -0,0 +1,33 @@
#include "bessel.h"
vector<Point> Bessel::run(const vector<Point> &points, double step) {
vector<Point> 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<Point> &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;
}

@ -0,0 +1,30 @@
#ifndef CSCI_BESSEL_H
#define CSCI_BESSEL_H
#include <vector>
#include <cmath>
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<Point> run(const vector<Point>& points, double step);
private:
static int binomial(int n, int i);
static Point bezier_curve(const vector<Point>& points, double t);
};
#endif //CSCI_BESSEL_H

@ -1,2 +1,49 @@
#include "operator.h"
void Operator::init(int modelType, int signalType, const QMap<QString, QVariant> &params) {
// 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 "";
}

@ -2,33 +2,43 @@
#ifndef CSCI_OPERATOR_H
#define CSCI_OPERATOR_H
#include <QVariant>
#include <QCryptographicHash>
class Operator {
public:
private:
int _modeType;
int _signalType;
QMap<QString, QVariant> _params;
QString _paramsHash;
/// 初始化
void init();
QString _motionLib;
QString _signalLib;
/// 更新
void update();
/// 上报状态
void report();
QList<QVariant> _states;
///
private:
void _deduceMotionLib();
private:
/// 模型参数
int model;
void _deduceSignalLib();
QString _hash();
public:
/// 初始化
void init(int modelType, int signalType, const QMap<QString, QVariant>& params);
/// 更新
void update();
/// 上报状态
QVariant report(int beat);
bool shouldUpdate();
};

@ -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"){

@ -131,6 +131,24 @@ void boost_test(){
}
}
#include "./compute/bessel.h"
void bessel_test(){
vector<Point> 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<Point> 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();

Loading…
Cancel
Save