You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
65 lines
1.6 KiB
3 days ago
|
#ifndef UICOMMON_H
|
||
|
#define UICOMMON_H
|
||
|
|
||
|
#include "enviroment.h"
|
||
|
#include <QThread>
|
||
|
#include <QJsonDocument>
|
||
|
#include <QJsonObject>
|
||
|
#include <QJsonArray>
|
||
|
|
||
|
class Calculator: QThread
|
||
|
{
|
||
|
private:
|
||
|
QJsonObject *data;
|
||
|
Enviroment *env;
|
||
|
int step;
|
||
|
public:
|
||
|
Calculator(Enviroment *init_env, QJsonObject *init_buffer, int init_step)
|
||
|
{
|
||
|
env = init_env;
|
||
|
data = init_buffer;
|
||
|
step = init_step;
|
||
|
}
|
||
|
|
||
|
void run() override
|
||
|
{
|
||
|
//QJsonObject().swap(*data); //清空data
|
||
|
|
||
|
for(int i=0; i<step; i++)
|
||
|
{
|
||
|
QJsonObject module;
|
||
|
QJsonArray adjArray;
|
||
|
QJsonArray coorArray;
|
||
|
env->RunOnce();
|
||
|
std::vector<std::vector<int>> adj = env->GetAdjMat();
|
||
|
std::vector<AgentState> coor = env->GetCoorMat();
|
||
|
|
||
|
// adjArray
|
||
|
for (const auto& row : adj) {
|
||
|
QJsonArray jsonRow;
|
||
|
for (double value : row) {
|
||
|
jsonRow.append(value);
|
||
|
}
|
||
|
adjArray.append(jsonRow);
|
||
|
}
|
||
|
|
||
|
// coorArray
|
||
|
for (const auto& row : coor) {
|
||
|
QJsonArray jsonRow;
|
||
|
jsonRow.append(row.x);
|
||
|
jsonRow.append(row.y);
|
||
|
jsonRow.append(row.head);
|
||
|
coorArray.append(jsonRow);
|
||
|
}
|
||
|
module["adj"] = adjArray;
|
||
|
module["coor"] = coorArray;
|
||
|
data->insert(QString::fromStdString(std::to_string(i)), module);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/*JsonArray转换为vector*/
|
||
|
std::vector<AgentState> ConvertToVec(QJsonArray arr);
|
||
|
|
||
|
#endif // UICOMMON_H
|