2 Star 0 Fork 1

LeoPkuCs/PhysLeo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
QtGuiApplication.cpp 8.54 KB
一键复制 编辑 原始数据 按行查看 历史
MikeXuPku 提交于 2018-06-13 12:15 . PG multiBodyCollision
#include <string>
#include <fstream>
#include <iostream>
#include "QtGuiApplication.h"
#include "qvalidator.h"
#include "Utilities/cuda_utilities.h"
using namespace std;
QtGuiApplication::QtGuiApplication(QWidget *parent): QMainWindow(parent)
{
ui.setupUi(this);
QDoubleValidator* doubleValidator = new QDoubleValidator(ui.velDampInput);
ui.gravityXInput->setValidator(doubleValidator);
ui.gravityYInput->setValidator(doubleValidator);
ui.gravityZInput->setValidator(doubleValidator);
ui.velDampInput->setValidator(doubleValidator);
ui.saveFrames->setValidator(new QIntValidator(ui.saveFEMSurf));
ui.slipFrames->setValidator(new QIntValidator(ui.slipFrames));
QObject::connect(ui.startButton, SIGNAL(clicked()), this, SLOT(run()));
QObject::connect(ui.stopButton, SIGNAL(clicked()), this, SLOT(stop()));
QObject::connect(ui.SingleStepButton, SIGNAL(clicked()), this, SLOT(singleStep()));
QObject::connect(ui.NoneLearnButton, SIGNAL(clicked()), this, SLOT(noneLearn()));
QObject::connect(ui.StaticLearnButton, SIGNAL(clicked()), this, SLOT(staticLearn()));
QObject::connect(ui.DynamicLearnButton, SIGNAL(clicked()), this, SLOT(dynamicLearn()));
QObject::connect(ui.femFShow, SIGNAL(clicked()), this, SLOT(showFemForce()));
QObject::connect(ui.femFHide, SIGNAL(clicked()), this, SLOT(hideFemForce()));
QObject::connect(ui.pdmFShow, SIGNAL(clicked()), this, SLOT(showPdmForce()));
QObject::connect(ui.pdmFHide, SIGNAL(clicked()), this, SLOT(hidePdmForce()));
QObject::connect(ui.deltaFShow, SIGNAL(clicked()), this, SLOT(showDeltaForce()));
QObject::connect(ui.deltaFHide, SIGNAL(clicked()), this, SLOT(hideDeltaForce()));
QObject::connect(ui.FEMMesh, SIGNAL(clicked()), this, SLOT(FEMMesh()));
QObject::connect(ui.PDMMesh, SIGNAL(clicked()), this, SLOT(PDMMesh()));
QObject::connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(reset()));
QObject::connect(ui.gravityXInput, SIGNAL(editingFinished()), this, SLOT(setGravity()));
QObject::connect(ui.gravityYInput, SIGNAL(editingFinished()), this, SLOT(setGravity()));
QObject::connect(ui.gravityZInput, SIGNAL(editingFinished()), this, SLOT(setGravity()));
QObject::connect(ui.velDampInput, SIGNAL(editingFinished()), this, SLOT(setDamping()));
QObject::connect(ui.saveFEMSurf, SIGNAL(clicked()), this, SLOT(saveFEM()));
QObject::connect(ui.savePDMSurf, SIGNAL(clicked()), this, SLOT(savePDM()));
QObject::connect(ui.saveMaterial, SIGNAL(clicked()), this, SLOT(saveMaterial()));
QObject::connect(ui.loadMaterial, SIGNAL(clicked()), this, SLOT(loadMaterial()));
QObject::connect(ui.fixPlane, SIGNAL(currentIndexChanged(int)), this, SLOT(fixPlane(int)));
QObject::connect(ui.extPlane, SIGNAL(currentIndexChanged(int)), this, SLOT(externalForcePlane(int)));
QObject::connect(ui.slipPlane, SIGNAL(currentIndexChanged(int)), this, SLOT(slipPlane(int)));
QObject::connect(ui.extforceX, SIGNAL(editingFinished()), this, SLOT(setExtForce()));
QObject::connect(ui.extforceY, SIGNAL(editingFinished()), this, SLOT(setExtForce()));
QObject::connect(ui.extforceZ, SIGNAL(editingFinished()), this, SLOT(setExtForce()));
QObject::connect(ui.SlipX, SIGNAL(editingFinished()), this, SLOT(setSlipDirection()));
QObject::connect(ui.SlipY, SIGNAL(editingFinished()), this, SLOT(setSlipDirection()));
QObject::connect(ui.SlipZ, SIGNAL(editingFinished()), this, SLOT(setSlipDirection()));
QObject::connect(ui.slipFrames, SIGNAL(editingFinished()), this, SLOT(setSlipDirection()));
QObject::connect(ui.exportDataButton, SIGNAL(clicked()), this, SLOT(exportLearnData()));
}
void QtGuiApplication::setGravity()
{
double x = std::stod(ui.gravityXInput->text().toStdString());
double y = std::stod(ui.gravityYInput->text().toStdString());
double z = std::stod(ui.gravityZInput->text().toStdString());
gravity->setGravity(make_float3(x, y, z));
}
void QtGuiApplication::setDamping()
{
double dampingCoef = std::stod(ui.velDampInput->text().toStdString());
damping->setDampingCoef(dampingCoef);
}
void QtGuiApplication::saveMaterial()
{
std::fstream fileout(materialFile->c_str(),std::ios::out|std::ios::trunc);
assert(fileout.is_open());
Data<float>* material = dynamic_cast<Data<float>*>(simDataPDM->getData("material"));
float* tempMaterial = material->getPtrCPU();
for (int i = 0; i < material->getSize(); ++i)
{
fileout << tempMaterial[i] << std::endl;
}
fileout.close();
cout << "save material!" << endl;
}
void QtGuiApplication::loadMaterial()
{
std::fstream filein(materialFile->c_str(),std::ios::in);
assert(filein.is_open());
Data<float>* material = dynamic_cast<Data<float>*>(simDataPDM->getData("material"));
float* tempMaterial = material->getPtrCPU();
for (int i = 0; i < material->getSize(); ++i)
{
filein >> tempMaterial[i];
}
material->CPU2GPU();
filein.close();
cout << "load material!" << endl;
}
void QtGuiApplication::fixPlane(int index)
{
cout << "change fix plane" << endl;
// 10x10x10
vector<int> fix;
//fix.resize(25);
//for(int i=0;i<5;++i)
// for (int j = 0; j < 5; ++j)
// {
// if (index == 0)//xplane
// fix[i * 5 + j] = i * 5 + j;
// else if (index == 1)//ypalne
// fix[i * 5 + j] = i * 25 + j;
// else if (index == 2)//zplane
// fix[i * 5 + j] = i * 25 + j * 5;
// }
//if (simDataFEM != nullptr)
//{
// Data fixPointFEM = simDataFEM->getData("fixedPoint");
// cudaCheck(cudaMemcpy(fixPointFEM.ptr, fix.data(), 25 * sizeof(int), cudaMemcpyHostToDevice));
//}
//if (simDataPDM != nullptr)
//{
// Data fixPointPDM = simDataPDM->getData("fixedPoint");
// cudaCheck(cudaMemcpy(fixPointPDM.ptr, fix.data(), 25 * sizeof(int), cudaMemcpyHostToDevice));
//}
fix.resize(100);
for (int i = 0; i<10; ++i)
for (int j = 0; j < 10; ++j)
{
if (index == 0)//xplane
fix[i * 10 + j] = i * 10 + j;
else if (index == 1)//ypalne
fix[i * 10 + j] = i * 100 + j;
else if (index == 2)//zplane
fix[i * 10 + j] = i * 100 + j * 10;
}
if (simDataFEM != nullptr)
{
Data<int>* fixPointFEM = dynamic_cast<Data<int>*>(simDataFEM->getData("fixedPoint"));
cudaCheck(cudaMemcpy(fixPointFEM->getPtrGPU(), fix.data(), 100 * sizeof(int), cudaMemcpyHostToDevice));
}
if (simDataPDM != nullptr)
{
Data<int>* fixPointPDM = dynamic_cast<Data<int>*>(simDataPDM->getData("fixedPoint"));
cudaCheck(cudaMemcpy(fixPointPDM->getPtrGPU(), fix.data(), 100 * sizeof(int), cudaMemcpyHostToDevice));
}
}
void QtGuiApplication::externalForcePlane(int index)
{
cout << "change external force plane" << endl;
vector<int> external;
external.resize(25);
for (int i = 0; i<5; ++i)
for (int j = 0; j < 5; ++j)
{
if (index == 0)//x=4plane
external[i * 5 + j] = 4 * 25 + i * 5 + j;
else if (index == 1)//y=4palne
external[i * 5 + j] = i * 25 + 4 * 5 + j;
else if (index == 2)//z=4plane
external[i * 5 + j] = i * 25 + j * 5 + 4;
}
Data<int>* extPointFEM = dynamic_cast<Data<int>*>(simDataFEM->getData("externalForcePoint"));
Data<int>* extPointPDM = dynamic_cast<Data<int>*>(simDataPDM->getData("externalForcePoint"));
cudaCheck(cudaMemcpy(extPointFEM->getPtrGPU(), external.data(), 25 * sizeof(int), cudaMemcpyHostToDevice));
cudaCheck(cudaMemcpy(extPointPDM->getPtrGPU(), external.data(), 25 * sizeof(int), cudaMemcpyHostToDevice));
}
void QtGuiApplication::setExtForce()
{
double x = std::stod(ui.extforceX->text().toStdString());
double y = std::stod(ui.extforceY->text().toStdString());
double z = std::stod(ui.extforceZ->text().toStdString());
externalForce->setForce(make_float3(x, y, z));
}
void QtGuiApplication::slipPlane(int index)
{
cout << "change slip plane" << endl;
vector<int> slip;
slip.resize(25);
for (int i = 0; i<5; ++i)
for (int j = 0; j < 5; ++j)
{
if (index == 0)//x=4plane
slip[i * 5 + j] = 4 * 25 + i * 5 + j;
else if (index == 1)//y=4palne
slip[i * 5 + j] = i * 25 + 4 * 5 + j;
else if (index == 2)//z=4plane
slip[i * 5 + j] = i * 25 + j * 5 + 4;
}
Data<int>* slipPointFEM = dynamic_cast<Data<int>*>(simDataFEM->getData("slipPoint"));
Data<int>* slipPointPDM = dynamic_cast<Data<int>*>(simDataPDM->getData("slipPoint"));
cudaCheck(cudaMemcpy(slipPointFEM->getPtrGPU(), slip.data(), 25 * sizeof(int), cudaMemcpyHostToDevice));
cudaCheck(cudaMemcpy(slipPointPDM->getPtrGPU(), slip.data(), 25 * sizeof(int), cudaMemcpyHostToDevice));
}
void QtGuiApplication::setSlipDirection()
{
double x = std::stod(ui.SlipX->text().toStdString());
double y = std::stod(ui.SlipY->text().toStdString());
double z = std::stod(ui.SlipZ->text().toStdString());
slipPoint->setSlipDirection(make_float3(x, y, z), std::stoi(ui.slipFrames->text().toStdString()));
}
void QtGuiApplication::exportLearnData()
{
exportLearnDataPtr->setExportFile(ui.exportDataPath->text().toStdString());
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/LeoPkuCs/PhysLeo.git
git@gitee.com:LeoPkuCs/PhysLeo.git
LeoPkuCs
PhysLeo
PhysLeo
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385