20240710 wavemodel实现及存储

pull/1/head
wuxiaxin 2024-07-10 16:28:53 +08:00
parent 7a57aa4ee1
commit 030f571c75
3 changed files with 188 additions and 16 deletions

View File

@ -9,6 +9,7 @@
#include "MainWindow/MainWindow.h"
#include "Settings/BusAPI.h"
#include "Settings/GraphOption.h"
#include "Common/DebugLogger.h"
#include <QSettings>
#include <vtkSmartPointer.h>
#include <vtkRenderer.h>
@ -23,6 +24,11 @@
#include <cmath>
#include <cstdlib>
#include <vector>
#include <qDebug>
#include <vtkSTLWriter.h>
#include <QMessageBox>
#include <QFileInfo>
#include <QFileDialog>
namespace wave {
@ -33,6 +39,7 @@ namespace wave {
{
ui->setupUi(this);
connect(ui->ShowWave_pushButton, &QPushButton::clicked, this, &wavemodel::on_push_wave_models_slot);
connect(ui->SaveModel_pushButton, &QPushButton::clicked, this, &wavemodel::on_push_save_models_slot);
initVTKView();
@ -110,6 +117,97 @@ namespace wave {
void wavemodel::on_push_wave_models_slot() {
//清除所有模型
_render->RemoveAllViewProps();
// 获取 textEdit_t 和 textEdit_v 的输入值
QString text_t = ui->textEdit_t->toPlainText();
QString text_v = ui->textEdit_v->toPlainText();
QString text_r = ui->textEdit_r->toPlainText();
QString text_g = ui->textEdit_g->toPlainText();
_structuredGrid= vtkSmartPointer<vtkStructuredGrid>::New();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkFloatArray> heights = vtkSmartPointer<vtkFloatArray>::New();
heights->SetName("Height");
double t = text_t.toDouble();
double v = text_v.toDouble();
double rand = text_r.toDouble();
double grid = text_g.toDouble();
const double g = 9.8; // 重力加速度常数
const int m = 5; // theta 的段数
const int n = 5; // omg 的段数
const double T = 12.5; // 平均波浪周期
// const int grid_size = 101; // x 和 y 的大小为 101 (1500/15 + 1)
// 其他参数
double omg_0 = 2 * M_PI / T;
double min_omg = 0.3;
double max_omg = 0.8;
double d_omg = (max_omg - min_omg) / n;
double d_theta = M_PI / m;
double z = 0.0;
for (int xi = 0; xi < grid; ++xi) {
for(int yi = 0; yi < grid; ++yi) {
points->InsertNextPoint(15.0 * xi, 15.0 * yi, 0.0);
heights->InsertNextValue(0);
}
}
double temp,omg_i,k_i,theta_j,eps,S_omg,p,q,fi_u;
// 计算波浪高度
for (int i = 1; i <= n; ++i) {
double omg_i = (rand + i - 1) * d_omg + min_omg;
double k_i = omg_i * omg_i / g;
for (int j = 1; j <= m; ++j) {
theta_j = -M_PI / 2 + d_theta * j;
eps = M_PI / 2 * (rand);
S_omg = 6.65e-4 * g * g * std::exp(-0.35 * g /std::pow( (v * omg_i), 4)) / std::pow(omg_i, 5);
p = 0.5 + 0.82 * std::exp(-0.5 * std::pow(omg_i / omg_0, 4));
q = 0.32 * std::exp(-0.5 * std::pow(omg_i / omg_0, 4));
fi_u = 1 / M_PI * (1 + p * std::cos(2 * theta_j) + q * std::cos(4 * theta_j));
for(int pid=0;pid<points->GetNumberOfPoints();pid++){
double* ppoint=points->GetPoint(pid);
temp = k_i * 15*ppoint[0] * std::cos(theta_j) + k_i * 15*ppoint[1] * std::sin(theta_j) - omg_i * t + eps;
ppoint[2] = std::cos(temp) * std::sqrt(2 * S_omg * fi_u * d_omg * d_theta) + ppoint[2];
points->SetPoint(pid,ppoint[0],ppoint[1],ppoint[2]);
heights->SetValue(pid,ppoint[2]);
}
}
}
double range[2];
heights->GetRange(range);
double minvalue = range[0];
double maxvalue = range[1];
qDebug()<<"Minimum value: " << minvalue;
qDebug()<<"Maximum value: " << maxvalue;
_structuredGrid->SetDimensions(grid, grid, 1);
_structuredGrid->SetPoints(points);
_structuredGrid->GetPointData()->SetScalars(heights);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputData(_structuredGrid);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
_render->AddActor(actor);
_render->ResetCamera();
//更新渲染窗口
_renderWindow->Render();
_qvtkWidget->update();
}
} // namespace wave

View File

@ -40,6 +40,8 @@ namespace wave {
public slots:
void on_push_wave_models_slot();
void on_push_save_models_slot();
private:
GUI::MainWindow* _mainwindow;

View File

@ -72,7 +72,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>170</y>
<y>190</y>
<width>100</width>
<height>16</height>
</rect>
@ -97,7 +97,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>280</y>
<y>510</y>
<width>310</width>
<height>23</height>
</rect>
@ -109,7 +109,7 @@
<widget class="QTextEdit" name="textEdit_t">
<property name="geometry">
<rect>
<x>100</x>
<x>120</x>
<y>90</y>
<width>141</width>
<height>41</height>
@ -119,24 +119,96 @@
<widget class="QTextEdit" name="textEdit_v">
<property name="geometry">
<rect>
<x>100</x>
<y>160</y>
<x>120</x>
<y>180</y>
<width>141</width>
<height>41</height>
</rect>
</property>
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QFrame" name="frame_4">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4"/>
<widget class="QLabel" name="label_r">
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<width>100</width>
<height>16</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16</height>
</size>
</property>
<property name="text">
<string>请输入随机数种子(0-1)</string>
</property>
</widget>
<widget class="QTextEdit" name="textEdit_r">
<property name="geometry">
<rect>
<x>120</x>
<y>270</y>
<width>141</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_g">
<property name="geometry">
<rect>
<x>10</x>
<y>370</y>
<width>100</width>
<height>16</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16</height>
</size>
</property>
<property name="text">
<string>请输入网格大小:</string>
</property>
</widget>
<widget class="QTextEdit" name="textEdit_g">
<property name="geometry">
<rect>
<x>120</x>
<y>360</y>
<width>141</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="SaveModel_pushButton">
<property name="geometry">
<rect>
<x>0</x>
<y>610</y>
<width>310</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>保存模型stl文件</string>
</property>
</widget>
</widget>
</item>
</layout>