20240709 wavemodel初始化
parent
3f66cdb38f
commit
7a57aa4ee1
|
@ -0,0 +1,115 @@
|
|||
//
|
||||
// Created by wuxiaxin on 24-7-9.
|
||||
//
|
||||
|
||||
// You may need to build the project (run Qt uic code generator) to get "ui_wavemodel.h" resolved
|
||||
|
||||
#include "wavemodel.h"
|
||||
#include "ui_wavemodel.h"
|
||||
#include "MainWindow/MainWindow.h"
|
||||
#include "Settings/BusAPI.h"
|
||||
#include "Settings/GraphOption.h"
|
||||
#include <QSettings>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkRenderer.h>
|
||||
#include <vtkGenericOpenGLRenderWindow.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkActor.h>
|
||||
#include <vtkStructuredGrid.h>
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkFloatArray.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <QVBoxLayout>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
namespace wave {
|
||||
|
||||
wavemodel::wavemodel(GUI::MainWindow* _mainwindow, QWidget* parent)
|
||||
: QDialog(_mainwindow),
|
||||
_mainwindow(_mainwindow),
|
||||
ui(new Ui::wavemodel)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->ShowWave_pushButton, &QPushButton::clicked, this, &wavemodel::on_push_wave_models_slot);
|
||||
|
||||
initVTKView();
|
||||
|
||||
// Display default grid
|
||||
vtkSmartPointer<vtkStructuredGrid> grid = createDefaultGrid();
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
||||
mapper->SetInputData(grid);
|
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||
actor->SetMapper(mapper);
|
||||
|
||||
_render->AddActor(actor);
|
||||
_render->ResetCamera();
|
||||
_renderWindow->Render();
|
||||
}
|
||||
|
||||
wavemodel::~wavemodel()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void wavemodel::initVTKView() {
|
||||
// 添加控件
|
||||
_qvtkWidget = new QVTKOpenGLNativeWidget(this);
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(ui->modelViewContent);
|
||||
mainLayout->addWidget(_qvtkWidget);
|
||||
|
||||
// 初始化渲染器
|
||||
_renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
|
||||
_qvtkWidget->setRenderWindow(_renderWindow);
|
||||
|
||||
_render = vtkSmartPointer<vtkOpenGLRenderer>::New();
|
||||
_render->SetGradientBackground(true);
|
||||
|
||||
// 设置渲染背景色
|
||||
Setting::GraphOption *option = Setting::BusAPI::instance()->getGraphOption();
|
||||
QColor topcolor = option->getBackgroundTopColor();
|
||||
QColor bottomcolor = option->getBackgroundBottomColor();
|
||||
_render->SetBackground2(topcolor.redF(), topcolor.greenF(), topcolor.blueF());
|
||||
_render->SetBackground(bottomcolor.redF(), bottomcolor.greenF(), bottomcolor.blueF());
|
||||
|
||||
// 开启硬件加速特性
|
||||
_render->UseDepthPeelingOn();
|
||||
_render->SetUseFXAA(true);
|
||||
_interactor = _renderWindow->GetInteractor();
|
||||
_renderWindow->AddRenderer(_render);
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkStructuredGrid> wavemodel::createDefaultGrid()
|
||||
{
|
||||
vtkSmartPointer<vtkStructuredGrid> structuredGrid = vtkSmartPointer<vtkStructuredGrid>::New();
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
vtkSmartPointer<vtkFloatArray> heights = vtkSmartPointer<vtkFloatArray>::New();
|
||||
heights->SetName("Height");
|
||||
|
||||
int gridSize = 10; // Default grid size
|
||||
double spacing = 1.0; // Grid spacing
|
||||
|
||||
for (int i = 0; i < gridSize; ++i) {
|
||||
for (int j = 0; j < gridSize; ++j) {
|
||||
double x = i * spacing;
|
||||
double y = j * spacing;
|
||||
double z = sin(i) * cos(j); // Sample height value
|
||||
points->InsertNextPoint(x, y, z);
|
||||
heights->InsertNextValue(z);
|
||||
}
|
||||
}
|
||||
|
||||
structuredGrid->SetDimensions(gridSize, gridSize, 1);
|
||||
structuredGrid->SetPoints(points);
|
||||
structuredGrid->GetPointData()->SetScalars(heights);
|
||||
|
||||
return structuredGrid;
|
||||
}
|
||||
|
||||
void wavemodel::on_push_wave_models_slot() {
|
||||
|
||||
}
|
||||
|
||||
} // namespace wave
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// Created by wuxiaxin on 24-7-9.
|
||||
//
|
||||
|
||||
#ifndef LAMPCAE_WAVEMODEL_H
|
||||
#define LAMPCAE_WAVEMODEL_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "ModuleBase/graph3DWindow.h"
|
||||
#include <QString>
|
||||
#include "QVTKOpenGLNativeWidget.h"
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
#include <QListWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkRenderer.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkStructuredGrid.h>
|
||||
|
||||
namespace GUI {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
namespace wave {
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class wavemodel;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class wavemodel : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit wavemodel(GUI::MainWindow* _mainwindow, QWidget* parent = nullptr);
|
||||
~wavemodel() override;
|
||||
|
||||
public slots:
|
||||
void on_push_wave_models_slot();
|
||||
|
||||
private:
|
||||
GUI::MainWindow* _mainwindow;
|
||||
Ui::wavemodel* ui;
|
||||
|
||||
QVTKOpenGLNativeWidget* _qvtkWidget;
|
||||
vtkSmartPointer<vtkRenderer> _render;
|
||||
vtkSmartPointer<vtkGenericOpenGLRenderWindow> _renderWindow;
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> _interactor;
|
||||
|
||||
void initVTKView();
|
||||
vtkSmartPointer<vtkStructuredGrid> createDefaultGrid();
|
||||
|
||||
};
|
||||
} // namespace wave
|
||||
|
||||
#endif // LAMPCAE_WAVEMODEL_H
|
|
@ -0,0 +1,184 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>wave::wavemodel</class>
|
||||
<widget class="QWidget" name="wave::wavemodel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>994</width>
|
||||
<height>839</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>wavemodel</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>350</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>350</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<widget class="QLabel" name="label_t">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>100</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>请输入时间t(s):</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_v">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>170</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>请输入速度v(m/s):</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="ShowWave_pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>280</y>
|
||||
<width>310</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>确定</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="textEdit_t">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>100</x>
|
||||
<y>90</y>
|
||||
<width>141</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="textEdit_v">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>100</x>
|
||||
<y>160</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>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QWidget" name="modelViewContent" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>600</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>1000</width>
|
||||
<height>1000</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue