#include "ThreeDimensionDiagraph.h" #include "ui_ThreeDimensionDiagraph.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "DelimitedTextReader.h" #include #include #include "FarFieldDataGenerator.h" #include "NearFieldDataGenerator.h" #include "PostTools.h" namespace pst { ThreeDimensionDiagraph::ThreeDimensionDiagraph(QWidget* parent) : PostWindowBase(parent/*, caseID*//*, BaseModule::GraphWindowType::Post3dDrawing*/) , ui(new Ui::ThreeDimensionDiagraph()) , m_dataType(-1) , m_renderWindow3D(vtkSmartPointer ::New()) //, m_fieldGraphGenerator(std::shared_ptr(new pst::FieldGraphGenerator())) , m_mutiReader(std::shared_ptr(new pst::MutiVTKFilesReader())) , m_widgetCutter(std::shared_ptr(new pst::WidgetCutter())) , m_render3D(vtkSmartPointer::New()) , m_leftDownCornerAxes(vtkSmartPointer::New()) , m_leftDownCornerWidget(vtkSmartPointer::New()) //, m_viewResultDataID(viewResultDataID) , m_interactor(vtkSmartPointer::New()) //, m_caseID(caseID) //, m_iD(typeInnerID) , m_dataSet{ nullptr /*vtkSmartPointer< vtkDataSet>::New() */ } , m_dataMapper{ vtkSmartPointer::New() } , m_dataActor{ vtkSmartPointer::New() } , m_lookupTable{ vtkSmartPointer::New() } , m_scalarBarActor{ vtkSmartPointer::New() } , m_scalarBarWidget{ vtkSmartPointer::New() } , m_delimitedTextReader{ vtkSmartPointer::New() } , m_farFieldDataGenerator{ new FarFieldDataGenerator() } , m_nearFieldDataGenerator{ new NearFieldDataGenerator() } //, m_fileName{ fileName } , m_filePathToRead{ } , m_isReadDataSuc{ false } , m_scalarBarTitle{ } , m_isCutterAdded{ false } , m_cutterInputData{ nullptr } , m_emptyData(vtkSmartPointer::New()) , m_shouldLogTheData(false) , m_shouldNormalizeTheData(false) , m_logDefautFactory{ 1. } , m_logDataRRange{ 0,1 } , m_originalRRange{ 0,1 } { ui->setupUi(this); this->ui->qvtkWidget->setRenderWindow(m_renderWindow3D); m_renderWindow3D->AddRenderer(m_render3D); m_render3D->GetActiveCamera()->SetParallelProjection(true); m_render3D->AutomaticLightCreationOff(); m_render3D->SetUseDepthPeeling(1); vtkNew lightKit; lightKit->AddLightsToRenderer(m_render3D); lightKit->SetKeyLightWarmth(0.5); lightKit->SetFillLightWarmth(0.5); lightKit->SetBackLightWarmth(0.5); lightKit->SetHeadLightWarmth(0.5); //m_dataMapper->SetInputData(m_emptyData); m_dataActor->SetMapper(m_dataMapper); initUI(); InitDefaultLookupTable(); initScalarBarPipeLine(); //checkDataType(fileName); //importPreProcessWindowData(); /* if (!isNew) { auto m_curCaseModel = ProjectManager::CaseModelManager::getinstance()->getCurrentCase(); if (m_curCaseModel == nullptr) { BaseModule::MessageBoxButton bt; emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), QObject::tr("Get case model failed!"), BaseModule::MessageBoxType::Error, bt); } m_gain3DData = m_curCaseModel->getMOMDataManager()->getMOMSimulationData()->getThreeDimensionDataByID(m_iD).get(); if (m_gain3DData == nullptr) { BaseModule::MessageBoxButton bt; emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), QObject::tr("Get data manager Failed!"), BaseModule::MessageBoxType::Error, bt); } else { readDataFromDataManager(); restoreLogic(); } } auto iBaseSignal = IBaseSignalInstance; connect(iBaseSignal, &BaseModule::IBaseSignal::signal_refreshResultWindowTitle, this, &ThreeDimensionDiagraph::slot_refreshWindowTitle);*/ vtkNew axes; axes->SetOrigin(0, 0, 0); axes->SetTotalLength(0.2, 0.2, 0.2); m_render3D->AddActor(axes); vtkNew sphereSource; sphereSource->SetRadius(0.15); sphereSource->Update(); vtkNew sphereMapper; sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); vtkNew sphereActor; sphereActor->SetMapper(sphereMapper); m_render3D->AddActor(sphereActor); m_renderWindow3D->Render(); } ThreeDimensionDiagraph::~ThreeDimensionDiagraph() { if (m_isReadDataSuc) { //writeMOMData(); } delete ui; delete m_farFieldDataGenerator; m_farFieldDataGenerator = nullptr; delete m_nearFieldDataGenerator; m_nearFieldDataGenerator = nullptr; //emit this->windowClosed(m_caseID, m_viewResultDataID); } bool ThreeDimensionDiagraph::ReadFieldData(QString filePath) { m_mutiReader->SetFileName(filePath); if (!m_mutiReader->Update()) { return false; } auto data = m_mutiReader->GetOutput(); auto cellArraysNum = data->GetCellData()->GetNumberOfArrays(); if (cellArraysNum > 0) { data->GetCellData()->SetActiveAttribute(0, vtkDataSetAttributes::AttributeTypes::SCALARS); m_scalarBarAutoDataRange[0] = data->GetCellData()->GetArray(0)->GetRange()[0]; m_scalarBarAutoDataRange[1] = data->GetCellData()->GetArray(0)->GetRange()[1]; } return true; } QString ThreeDimensionDiagraph::generateFilePath(const QString& fileName, int index) { //auto caseModel = ProjectManager::CaseModelManager::getinstance()->getModelByID(m_caseID); //if (!caseModel) //{ // return QString(); //} //std::vector tempRes; //pst::CommonFunction::Stringsplit(fileName.toStdString(), ".", tempRes); //if (tempRes.size() != 2) //{ // std::cout << "Stringsplit first 1 column error!" << std::endl; // return false; //} //m_scalarBarTitle = QString::fromStdString(tempRes[0]); //auto newFileName = QString::fromStdString(tempRes[0] + "_" + std::to_string(index) + "." + tempRes[1]); //auto filePath = (caseModel->getCaseDir() + "/" + newFileName); //return filePath; return QString(); } QList ThreeDimensionDiagraph::getFreqFromSetting() { QList freqList; //auto simulationData = ProjectManager::CaseModelManager::getinstance()->getCurrentCase()->getMOMDataManager()->getMOMSimulationData(); //auto m_solverSet = QSharedPointer(new DataModel::SimulationMOMSolveSettingsData(*simulationData->getSolveSettingsData())); //m_solverSet->getFreqUnit(); //m_solverSet->getSweepFrequencyUnit(); //bool _isSweep = m_solverSet->getBSweepFreq(); //if (!_isSweep)//单频 //{ // freqList.append(QString::number(m_solverSet->getFreqValue())); //} //else//扫频 //{ // auto startFreq = m_solverSet->getStartFrequencyValue(); // auto endFreq = m_solverSet->getEndFrequencyValue(); // auto step = m_solverSet->getStepFrequencyValue(); // int num = (int)std::abs((endFreq - startFreq) / step) + 1; // for (int i = 0; i < num; i++) // { // freqList.append(QString::number(startFreq + i * step)); // } //} return freqList; } void ThreeDimensionDiagraph::initUI() { //slot_refreshWindowTitle(m_caseID, (int)BaseModule::ResultType::ResultThreeDimensionGraph, m_viewResultDataID); ui->splitter->setStretchFactor(0, 8); ui->splitter->setStretchFactor(1, 1); //设置频率下拉列表 auto freqList = getFreqFromSetting(); for (auto i : freqList) { ui->comboBoxFrequency->addItem(i); } for (int i = 1; i < 50; ++i) { ui->comboBoxSBFontSize->addItem(QString::number(i)); } ui->comboBoxSBFontSize->setCurrentIndex(23); ui->comboBoxSBTitleColor->setShowColorName(false); ui->comboBoxSBTitleColor->appendPredefinedColors(); //切片方向 ui->comboBox_sliceDirection->addItem("X"); ui->comboBox_sliceDirection->addItem("Y"); ui->comboBox_sliceDirection->addItem("Z"); //切片位置 generateSlicePosition(0); activeButtonAfterReadData(); } void ThreeDimensionDiagraph::checkDataType(const QString& fileName) { //根据文件名判断类型 //远场 if (fileName == "RCSFile.txt" || fileName == "GainDirectionFile.txt" || fileName == "monostatic_RCSFile.txt") { m_dataType = 0; } //近场 else if (fileName == "MagneticField.txt" || fileName == "ElectricField.txt") { m_dataType = 1; } //表面电流 else if (fileName == "SurfaceCurrentDensity.vtk") { m_dataType = 2; } } void ThreeDimensionDiagraph::decideLogFactory() { } void ThreeDimensionDiagraph::setLogNormalButtonState(bool state) { if (m_dataType == 0 || m_dataType == 1)//远场或者近场 { ui->checkBox_normalization->setEnabled(state); ui->checkBox_logarithm->setEnabled(state); } } void ThreeDimensionDiagraph::setSlicePositionButtonState() { if (m_dataType == 1) { ui->comboBox_slicePosition->setEnabled(true); } else { ui->comboBox_slicePosition->setEnabled(false); } } bool ThreeDimensionDiagraph::readData(const QString& filePath) { //远场 //远场 //远场 if (m_dataType == 0) { m_isReadDataSuc = readerDelimitedTextFromLocal(filePath); //if (!m_isReadDataSuc) //{ // BaseModule::MessageBoxButton bt; // emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), // QObject::tr("Data Illegal!"), BaseModule::MessageBoxType::Error, bt); // return false; //} //m_farFieldDataGenerator->setInputData(m_delimitedTextReader->GetOutput()); //auto suc = m_farFieldDataGenerator->update(); //if (!suc) //{ // BaseModule::MessageBoxButton bt; // emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), // QObject::tr("Data Illegal!"), BaseModule::MessageBoxType::Error, bt); // m_isReadDataSuc = false; // return false; //} m_dataSet = m_farFieldDataGenerator->getOutputData(); //structuredGrid m_scalarBarAutoDataRange[0] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[0]; m_scalarBarAutoDataRange[1] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[1]; } //近场 //近场 //近场 else if (m_dataType == 1) { m_isReadDataSuc = readerDelimitedTextFromLocal(filePath); if (!m_isReadDataSuc) { //BaseModule::MessageBoxButton bt; //emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), // QObject::tr("Data Illegal!"), BaseModule::MessageBoxType::Error, bt); //return false; } m_nearFieldDataGenerator->setInputData(m_delimitedTextReader->GetOutput()); //auto _currentCaseModel = ProjectManager::CaseModelManager::getinstance()->getCurrentCase(); //auto _nearFieldCoordinate = _currentCaseModel->getMOMDataManager()->getMOMSimulationData()->getNearFieldCoordinateData(); //int numX = 0; //int numY = 0; //int numZ = 0; //if (!qFuzzyCompare(0., _nearFieldCoordinate->getStepX())) //{ // numX = (_nearFieldCoordinate->getEndX() - _nearFieldCoordinate->getStartX()) / _nearFieldCoordinate->getStepX(); //} //if (!qFuzzyCompare(0., _nearFieldCoordinate->getStepY())) //{ // numY = (_nearFieldCoordinate->getEndY() - _nearFieldCoordinate->getStartY()) / _nearFieldCoordinate->getStepY(); //} //if (!qFuzzyCompare(0., _nearFieldCoordinate->getStepZ())) //{ // numZ = (_nearFieldCoordinate->getEndZ() - _nearFieldCoordinate->getStartZ()) / _nearFieldCoordinate->getStepZ(); //} //m_nearFieldDataGenerator->setTableExtends(numX, numY, numZ); //m_nearFieldDataGenerator->update(); m_dataSet = m_nearFieldDataGenerator->getOutputData(); //structuredGrid if (m_dataSet == nullptr || m_dataSet->GetPointData() == nullptr || m_dataSet->GetPointData()->GetArray(0) == nullptr) { //BaseModule::MessageBoxButton bt; //emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), // QObject::tr("Data Illegal!"), BaseModule::MessageBoxType::Error, bt); //m_isReadDataSuc = false; //return false; } m_scalarBarAutoDataRange[0] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[0]; m_scalarBarAutoDataRange[1] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[1]; } //表面流场 //表面流场 //表面流场 else if (m_dataType == 2) { m_isReadDataSuc = ReadFieldData(filePath); if (!m_isReadDataSuc) { //BaseModule::MessageBoxButton bt; //emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), // QObject::tr("Data Illegal!"), BaseModule::MessageBoxType::Error, bt); //m_isReadDataSuc = false; //return false; } m_dataSet = m_mutiReader->GetOutput(); } m_originalRRange[0] = m_scalarBarAutoDataRange[0]; m_originalRRange[1] = m_scalarBarAutoDataRange[1]; setScalarBarRange(); ui->lineEditSBTitleString->setText(m_scalarBarTitle.toStdString().c_str()); m_scalarBarActor->SetTitle(m_scalarBarTitle.toStdString().c_str()); m_scalarBarActor->SetUnconstrainedFontSize(true); generateResultActor(); m_render3D->AddActor(m_dataActor); m_render3D->AddActor(m_scalarBarActor); m_render3D->ResetCamera(); m_renderWindow3D->Render(); return true; } void ThreeDimensionDiagraph::generateResultActor() { m_dataMapper->SetInputData(m_dataSet); m_dataMapper->SetLookupTable(m_lookupTable); m_dataMapper->SetInterpolateScalarsBeforeMapping(true); m_dataMapper->SetUseLookupTableScalarRange(1); m_dataMapper->ScalarVisibilityOn(); } void ThreeDimensionDiagraph::InitDefaultLookupTable() { m_lookupTable->SetNumberOfColors(150); m_lookupTable->SetHueRange(0.67, 0.0); m_lookupTable->Build(); } void ThreeDimensionDiagraph::initScalarBarPipeLine() { //m_scalarBarActor->SetTitle("Gain"); m_scalarBarActor->SetBarRatio(0.25); m_scalarBarActor->GetTitleTextProperty()->SetJustificationToLeft(); m_scalarBarActor->SetPosition(0.9, 0.1); m_scalarBarActor->SetPosition2(0.05, 0.7); m_scalarBarActor->SetNumberOfLabels(10); m_scalarBarActor->SetLookupTable(m_lookupTable); m_scalarBarWidget->SetScalarBarActor(m_scalarBarActor); vtkScalarBarRepresentation* rep = vtkScalarBarRepresentation::SafeDownCast(m_scalarBarWidget->GetRepresentation()); rep->SetPosition(0.9, 0.1); rep->SetPosition2(0.05, 0.7); m_scalarBarWidget->SetInteractor(m_renderWindow3D->GetInteractor()); m_scalarBarWidget->On(); } void ThreeDimensionDiagraph::activeButtonAfterReadData() { setLogNormalButtonState(m_isReadDataSuc); ui->pb_exportData->setEnabled(m_isReadDataSuc); ui->tabWidget->setTabEnabled(1, m_isReadDataSuc); ui->tabWidget->setTabEnabled(2, m_isReadDataSuc); } void ThreeDimensionDiagraph::generateSlicePosition(int index) { ui->comboBox_slicePosition->clear(); if (m_dataType != 1) //只有近场有切片位置选项 { return; } //auto _currentCaseModel = ProjectManager::CaseModelManager::getinstance()->getCurrentCase(); //auto _nearFieldCoordinate = _currentCaseModel->getMOMDataManager()->getMOMSimulationData()->getNearFieldCoordinateData(); ////根据带求解项计算 //if (index == 0) //x //{ // int num = (_nearFieldCoordinate->getEndX() - _nearFieldCoordinate->getStartX()) / _nearFieldCoordinate->getStepX() + 1; // for (int i = 0; i < num; ++i) // { // ui->comboBox_slicePosition->addItem( // QString::number(_nearFieldCoordinate->getStartX() + i * _nearFieldCoordinate->getStepX())); // } //} //else if (index == 1) //{ // int num = (_nearFieldCoordinate->getEndY() - _nearFieldCoordinate->getStartY()) / _nearFieldCoordinate->getStepY() + 1; // for (int i = 0; i < num; ++i) // { // ui->comboBox_slicePosition->addItem( // QString::number(_nearFieldCoordinate->getStartY() + i * _nearFieldCoordinate->getStepY())); // } //} //else if (index == 2) //{ // int num = (_nearFieldCoordinate->getEndZ() - _nearFieldCoordinate->getStartZ()) / _nearFieldCoordinate->getStepZ() + 1; // for (int i = 0; i < num; ++i) // { // ui->comboBox_slicePosition->addItem( // QString::number(_nearFieldCoordinate->getStartZ() + i * _nearFieldCoordinate->getStepZ())); // } //} } //void ThreeDimensionDiagraph::writeMOMData() //{ // auto camera = m_render3D->GetActiveCamera(); // auto cameraViewUp = camera->GetViewUp(); // auto cameraPosition = camera->GetPosition(); // auto cameraFocalPoint = camera->GetFocalPoint(); // QList cameraViewUpList{ cameraViewUp[0],cameraViewUp[1],cameraViewUp[2] }; // QList cameraPositionList{ cameraPosition[0],cameraPosition[1],cameraPosition[2] }; // QList cameraFocalPointList{ cameraFocalPoint[0],cameraFocalPoint[1],cameraFocalPoint[2] }; // QString cameraViewUpListStr = BaseModule::GlobalHelper::convertDoubleListToQString(cameraViewUpList); // QString cameraPositionListStr = BaseModule::GlobalHelper::convertDoubleListToQString(cameraPositionList); // QString cameraFocalPointListStr = BaseModule::GlobalHelper::convertDoubleListToQString(cameraFocalPointList); // auto _titleColor = ui->comboBoxSBTitleColor->currentColor(); // QList titleColor{ _titleColor.redF(), _titleColor.greenF(), _titleColor.blueF() }; // QString titleColorStr = BaseModule::GlobalHelper::convertDoubleListToQString(titleColor); // QStringList _listPYCode; // _listPYCode.append(QString("postthreedimensiongraphdata = PostWidgets.PostThreeDimensionGraphData()")); // _listPYCode.append(QString("postthreedimensiongraphdata.setID(%1)").arg(m_iD)); // _listPYCode.append(QString("postthreedimensiongraphdata.setIsLogTheData(%1)").arg(m_shouldLogTheData)); // _listPYCode.append(QString("postthreedimensiongraphdata.setIsNormalizeTheData(%1)").arg(m_shouldNormalizeTheData)); // _listPYCode.append(QString("postthreedimensiongraphdata.setScalarBarProperty(\"%1\",\"%2\",%3,%4,%5,%6)") // .arg(ui->lineEditSBTitleString->text()) // .arg(titleColorStr) // .arg(ui->checkBoxScalarBarRangeAutomatic->isChecked()) // .arg(ui->doubleSpinBox_SBMinRange->value()) // .arg(ui->doubleSpinBox_SBMaxRange->value()) // .arg(ui->comboBoxSBFontSize->currentText().toInt())); // _listPYCode.append(QString("postthreedimensiongraphdata.setGraphOpacity(%1)").arg(ui->slider_ResultTransparency->value())); // _listPYCode.append(QString("postthreedimensiongraphdata.setMeshOpacity(%1)").arg(ui->slider_meshTransparency->value())); // _listPYCode.append(QString("postthreedimensiongraphdata.setScaleFactor(%1)").arg(ui->doubleSpinBox_resultScale->value())); // _listPYCode.append(QString("postthreedimensiongraphdata.setCameraParameters(\"%1\",\"%2\",\"%3\")") // .arg(cameraViewUpListStr) // .arg(cameraPositionListStr) // .arg(cameraFocalPointListStr)); // _listPYCode.append(QString("postthreedimensiongraphdata.setCurrentFreqIndex(%1)").arg(ui->comboBoxFrequency->currentIndex())); // _listPYCode.append(QString("postthreedimensiongraphdata.setIsEnableSlice(%1)").arg(ui->checkBox_enableSlice->isChecked())); // _listPYCode.append(QString("postthreedimensiongraphdata.setSliceDirectionIndex(%1)").arg(ui->comboBox_sliceDirection->currentIndex())); // _listPYCode.append(QString("postthreedimensiongraphdata.setSlicePositionIndex(%1)").arg(ui->comboBox_slicePosition->currentIndex())); // _listPYCode.append(QString("postthreedimensiongraphdata.setCurrentTagIndex(%1)").arg(ui->tabWidget->currentIndex())); // _listPYCode.append(QString("postthreedimensiongraphdata.savePostThreeDimensionGraphData()")); // emit IBaseSignalInstance->signal_execPYCode(_listPYCode); //} //void ThreeDimensionDiagraph::readDataFromDataManager() //{ // auto m_curCaseModel = ProjectManager::CaseModelManager::getinstance()->getCurrentCase(); // m_gain3DData = m_curCaseModel->getMOMDataManager()->getMOMSimulationData()->getThreeDimensionDataByID(m_iD).get(); // auto _currentFreqIndex = m_gain3DData->getFreqIndex(); // ui->comboBoxFrequency->setCurrentIndex(_currentFreqIndex); // //先设频率再读数据 // on_pushBtnApply_clicked(); // if (!m_isReadDataSuc) // { // return; // } // m_shouldLogTheData = m_gain3DData->getIsLogTheData(); // auto meshOpacity = m_gain3DData->getMeshOpacity(); // auto graphOpacity = m_gain3DData->getGraphOpacity(); // m_shouldNormalizeTheData = m_gain3DData->getIsNormalized(); // auto _isEnableSlice = m_gain3DData->getEnableSlice(); // auto _sliceDirectionIndex = m_gain3DData->getSliceDirectionIndex(); // auto _slicePositionIndex = m_gain3DData->getSlicePosition(); // auto _currentTagIndex = m_gain3DData->getCurrentTagIndex(); // //scalarBar属性 // QString scaleBarTitle(""); // bool scaleBarAutoRange{ false }; // double scaleBarMaunalMin{ 0. }; // double scaleBarMaunalMax{ 0. }; // QList _scaleBarTitleColor; // int titleFontSize{ 8 }; // m_gain3DData->getScalarBarProperty(scaleBarTitle, scaleBarAutoRange, // scaleBarMaunalMin, scaleBarMaunalMax, _scaleBarTitleColor, titleFontSize); // //=======设置到界面========== // ui->checkBox_normalization->setChecked(m_shouldNormalizeTheData); // ui->checkBox_logarithm->setChecked(m_shouldLogTheData); // ui->checkBoxScalarBarRangeAutomatic->setChecked(scaleBarAutoRange); // ui->doubleSpinBox_SBMinRange->setValue(scaleBarMaunalMin); // ui->doubleSpinBox_SBMaxRange->setValue(scaleBarMaunalMax); // ui->comboBoxSBFontSize->setCurrentText(QString::number(titleFontSize)); // ui->slider_meshTransparency->setValue(meshOpacity); // ui->slider_ResultTransparency->setValue(graphOpacity); // ui->checkBox_enableSlice->setChecked(_isEnableSlice); // ui->comboBox_sliceDirection->setCurrentIndex(_sliceDirectionIndex); // ui->comboBox_slicePosition->setCurrentIndex(_slicePositionIndex); // ui->tabWidget->setCurrentIndex(_currentTagIndex); // ui->lineEditSBTitleString->setText(scaleBarTitle); //} //void ThreeDimensionDiagraph::restoreLogic() //{ // if (!m_isReadDataSuc) // { // return; // } // on_comboBoxSBFontSize_currentIndexChanged(ui->comboBoxSBFontSize->currentIndex()); // if (m_dataType == 0 || m_dataType == 1) //表面电流没有归一化和取对数 // { // on_checkBox_normalization_stateChanged(ui->checkBox_normalization->isChecked()); // on_checkBox_logarithm_stateChanged(ui->checkBox_logarithm->isChecked()); // } // on_checkBoxScalarBarRangeAutomatic_stateChanged(ui->checkBoxScalarBarRangeAutomatic->isChecked()); // on_slider_meshTransparency_valueChanged(ui->slider_meshTransparency->value()); // on_slider_ResultTransparency_valueChanged(ui->slider_ResultTransparency->value()); // //on_comboBoxFrequency_currentIndexChanged(ui->comboBoxFrequency->currentIndex()); // on_checkBox_enableSlice_stateChanged(ui->checkBox_enableSlice->isChecked()); // on_comboBox_sliceDirection_currentIndexChanged(m_gain3DData->getSliceDirectionIndex()); // ui->comboBox_slicePosition->setCurrentIndex(m_gain3DData->getSlicePosition()); // auto scaleFactor = m_gain3DData->getScaleFactor(); // ui->doubleSpinBox_resultScale->setValue(scaleFactor); // //on_doubleSpinBox_resultScale_valueChanged(scaleFactor); // //相机参数 // QList viewUp{}; // QList position{}; // QList focalPoint{}; // m_gain3DData->getCameraParameters(viewUp, position, focalPoint); // auto camera = m_render3D->GetActiveCamera(); // camera->SetViewUp(viewUp[0], viewUp[1], viewUp[2]); // camera->SetPosition(position[0], position[1], position[2]); // camera->SetFocalPoint(focalPoint[0], focalPoint[1], focalPoint[2]); // camera->Modified(); // m_render3D->ResetCameraClippingRange(); //} //void ThreeDimensionDiagraph::importPreProcessWindowData() //{ // auto render = IWidgetSignalInstance->signal_getRenderer(); // if (render == nullptr) // { // return; // } // m_render3D->SetBackground(render->GetBackground()); // m_render3D->SetBackground2(render->GetBackground2()); // m_render3D->SetGradientBackground(render->GetGradientBackground()); // m_preWDmeshActorsList.clear(); // QList>> _preWDmeshActors; // IWidgetSignalInstance->signal_getAllMeshActors(_preWDmeshActors); // for (auto meshKernalActor : _preWDmeshActors)//每一个mesh // { // if (meshKernalActor.size() != 4) //4个actor 面、线、点、法线 // { // return; // } // for (int i = 0; i < 2; ++i)//只取面。线 // { // auto actorList = meshKernalActor[i];//面或者线 // for (auto _actor : actorList) // { // vtkActor* sourceActor = vtkActor::SafeDownCast(_actor); // if (sourceActor == nullptr) // { // return; // } // vtkNew copiedActor; // copyActor(sourceActor, copiedActor); // copiedActor->GetProperty()->SetOpacity(1); // copiedActor->SetVisibility(true); // m_preWDmeshActorsList.append(copiedActor); // m_render3D->AddActor(copiedActor); // } // } // } // m_render3D->ResetCamera(); // m_renderWindow3D->Render(); //} void ThreeDimensionDiagraph::on_comboBoxFrequency_currentIndexChanged(int index) { } void ThreeDimensionDiagraph::on_pushBtnApply_clicked() { //if (m_dataType != 0 && m_dataType != 1 && m_dataType != 2) //{ // return; //} //m_filePathToRead = generateFilePath(m_fileName, ui->comboBoxFrequency->currentIndex()); ////判别读哪个文件 //auto suc = readData(m_filePathToRead); //if (!suc) //{ // BaseModule::MessageBoxButton bt; // emit IBaseSignalInstance->signal_showMessageDialog(QObject::tr("ERROR"), // QObject::tr("Data read error!"), BaseModule::MessageBoxType::Error, bt); // return; //} activeButtonAfterReadData(); } void ThreeDimensionDiagraph::on_checkBox_normalization_stateChanged(int state) { m_shouldNormalizeTheData = state; if (m_dataType == 0) { m_farFieldDataGenerator->setNormalizeTheData(state); m_farFieldDataGenerator->update(); } else if (m_dataType == 1) { m_nearFieldDataGenerator->setNormalizeTheData(state); m_nearFieldDataGenerator->update(); } m_scalarBarAutoDataRange[0] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[0]; m_scalarBarAutoDataRange[1] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[1]; setScalarBarRange(); m_dataActor->Modified(); m_render3D->ResetCamera(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_checkBox_logarithm_stateChanged(int state) { m_shouldLogTheData = state; if (m_dataType == 0) { m_farFieldDataGenerator->setLogTheData(state); m_farFieldDataGenerator->update(); } else if (m_dataType == 1) { m_nearFieldDataGenerator->setLogTheData(state); m_nearFieldDataGenerator->update(); } m_scalarBarAutoDataRange[0] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[0]; m_scalarBarAutoDataRange[1] = m_dataSet->GetPointData()->GetArray(0)->GetRange()[1]; m_logDataRRange[0] = m_scalarBarAutoDataRange[0]; m_logDataRRange[1] = m_scalarBarAutoDataRange[1]; //防止处0和其他异常 if ((m_logDataRRange[1] != m_logDataRRange[0]) && (m_originalRRange[1] != m_originalRRange[0])) { m_logDefautFactory = (m_originalRRange[1] - m_originalRRange[0]) / (m_logDataRRange[1] - m_logDataRRange[0]); } on_doubleSpinBox_resultScale_valueChanged(ui->doubleSpinBox_resultScale->value()); setScalarBarRange(); m_dataActor->Modified(); m_render3D->ResetCamera(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_pushButton_fitView_clicked() { m_render3D->ResetCamera(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_btnTopView_clicked() { resetCameraViewDirection(m_render3D->GetActiveCamera(), 0, 0, -1, 0, 1, 0); } void ThreeDimensionDiagraph::on_btnBottomView_clicked() { resetCameraViewDirection(m_render3D->GetActiveCamera(), 0, 0, 1, 0, 1, 0); } void ThreeDimensionDiagraph::on_btnFrontView_clicked() { resetCameraViewDirection(m_render3D->GetActiveCamera(), -1, 0, 0, 0, 0, 1); } void ThreeDimensionDiagraph::on_btnBackView_clicked() { resetCameraViewDirection(m_render3D->GetActiveCamera(), 1, 0, 0, 0, 0, 1); } void ThreeDimensionDiagraph::on_btnLeftView_clicked() { resetCameraViewDirection(m_render3D->GetActiveCamera(), 0, 1, 0, 0, 0, 1); } void ThreeDimensionDiagraph::on_btnRightView_clicked() { resetCameraViewDirection(m_render3D->GetActiveCamera(), 0, -1, 0, 0, 0, 1); } void ThreeDimensionDiagraph::on_lineEditSBTitleString_editingFinished() { m_scalarBarActor->SetTitle(ui->lineEditSBTitleString->text().toStdString().c_str()); m_scalarBarActor->Modified(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_comboBoxSBTitleColor_activated(int index) { auto color = ui->comboBoxSBTitleColor->currentColor(); m_scalarBarActor->GetTitleTextProperty()->SetColor(color.redF(), color.greenF(), color.blueF()); m_scalarBarActor->Modified(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_comboBoxSBFontSize_currentIndexChanged(int index) { auto size = ui->comboBoxSBFontSize->currentText().toInt(); m_scalarBarActor->GetTitleTextProperty()->SetFontSize(size); m_scalarBarActor->Modified(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_checkBoxScalarBarRangeAutomatic_stateChanged(int state) { ui->doubleSpinBox_SBMinRange->setEnabled(!state); ui->doubleSpinBox_SBMaxRange->setEnabled(!state); setScalarBarRange(); m_scalarBarActor->Modified(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_doubleSpinBox_SBMinRange_valueChanged(double value) { m_lookupTable->SetRange(ui->doubleSpinBox_SBMinRange->value(), ui->doubleSpinBox_SBMaxRange->value()); m_widgetCutter->SetScalarBarRange(ui->doubleSpinBox_SBMinRange->value(), ui->doubleSpinBox_SBMaxRange->value()); m_scalarBarActor->Modified(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_doubleSpinBox_SBMaxRange_valueChanged(double value) { m_lookupTable->SetRange(ui->doubleSpinBox_SBMinRange->value(), ui->doubleSpinBox_SBMaxRange->value()); m_widgetCutter->SetScalarBarRange(ui->doubleSpinBox_SBMinRange->value(), ui->doubleSpinBox_SBMaxRange->value()); m_scalarBarActor->Modified(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_slider_meshTransparency_valueChanged(int value) { for (auto i : m_preWDmeshActorsList) { auto opa = 1 - value / 100.0; i->GetProperty()->SetOpacity(opa); auto backFaceProp = i->GetBackfaceProperty(); if (backFaceProp) { backFaceProp->SetOpacity(opa); } value == 100 ? i->SetVisibility(false) : i->SetVisibility(true); } QString str = QString::number(value) + "%"; ui->label_meshTransValue->setText(str); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_slider_ResultTransparency_valueChanged(int value) { auto opa = 1 - value / 100.0; m_dataActor->GetProperty()->SetOpacity(opa); m_scalarBarActor->Modified(); QString str = QString::number(value) + "%"; ui->label_resultTransValue->setText(str); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_checkBox_enableSlice_stateChanged(int state) { //调整界面上的控件 ui->comboBox_sliceDirection->setEnabled(state); if (m_dataType == 1) //近场 { ui->comboBox_slicePosition->setEnabled(state); on_comboBox_slicePosition_currentIndexChanged(ui->comboBox_slicePosition->currentIndex()); } AddCutter(); if (!m_isCutterAdded) { return; } m_widgetCutter->GetCutterActor()->SetVisibility(state); state ? m_widgetCutter->TurnWidgetOn() : m_widgetCutter->TurnAllWidgetOff(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::AddCutter() { if (m_isCutterAdded) { return; } m_widgetCutter->SetInteractor(m_renderWindow3D->GetInteractor()); m_widgetCutter->SetInputData(m_dataSet); m_widgetCutter->SetCenter(m_dataSet->GetCenter()); m_widgetCutter->GetPlaneWidget()->GetHandleProperty()->SetOpacity(0.4); m_widgetCutter->SetPlaneNormalDirection(pst::WidgetCutter::PlaneNormalDirection::X); setScalarBarRange(); m_widgetCutter->GetDataOutlineActor()->VisibilityOff(); m_widgetCutter->TurnAllWidgetOff(); m_widgetCutter->Update(); //m_widgetCutter->TurnAllWidgetOff(); m_widgetCutter->TurnWidgetOn(); m_render3D->AddActor(m_widgetCutter->GetCutterActor()); m_widgetCutter->GetScalarBar()->SetVisibility(false); generateSlicePosition(ui->comboBox_sliceDirection->currentIndex()); m_isCutterAdded = true; } void ThreeDimensionDiagraph::on_comboBox_sliceDirection_currentIndexChanged(int index) { if (!ui->checkBox_enableSlice->isChecked()) { return; } if (index == 0) { m_widgetCutter->SetPlaneNormalDirection(pst::WidgetCutter::PlaneNormalDirection::X); } else if (index == 1) { m_widgetCutter->SetPlaneNormalDirection(pst::WidgetCutter::PlaneNormalDirection::Y); } else if (index == 2) { m_widgetCutter->SetPlaneNormalDirection(pst::WidgetCutter::PlaneNormalDirection::Z); } generateSlicePosition(index); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_comboBox_slicePosition_currentIndexChanged(int index) { if (!ui->checkBox_enableSlice->isChecked()) { return; } auto bounds = m_dataSet->GetBounds();//边界范围 auto dataCenter = m_dataSet->GetCenter(); double center[3]{ dataCenter[0],dataCenter[1],dataCenter[2] }; if (ui->comboBox_sliceDirection->currentIndex() == 0)//x { center[0] = ui->comboBox_slicePosition->currentText().toDouble(); // 可能由于精度损失,切不到数据, // 将两端的切片位置中心移动一定范围 int num = ui->comboBox_slicePosition->count();//不同方向数量可能不同 if (index == 0)//最小 { center[0] += std::min((bounds[1] - bounds[0]) / 1000000., 0.0000001); } else if (index = num - 1) //最大 { center[0] -= std::min((bounds[1] - bounds[0]) / 1000000., 0.0000001); } } else if (ui->comboBox_sliceDirection->currentIndex() == 1)//y { center[1] = ui->comboBox_slicePosition->currentText().toDouble(); int num = ui->comboBox_slicePosition->count();//不同方向数量可能不同 if (index == 0)//最小 { center[1] += std::min((bounds[3] - bounds[2]) / 1000000., 0.0000001); } else if (index = num - 1) //最大 { center[1] -= std::min((bounds[3] - bounds[2]) / 1000000., 0.0000001); } } else if (ui->comboBox_sliceDirection->currentIndex() == 2)//z { center[2] = ui->comboBox_slicePosition->currentText().toDouble(); int num = ui->comboBox_slicePosition->count();//不同方向数量可能不同 if (index == 0)//最小 { center[2] += std::min((bounds[5] - bounds[4]) / 1000000., 0.0000001); } else if (index = num - 1) //最大 { center[2] -= std::min((bounds[5] - bounds[4]) / 1000000., 0.0000001); } } m_widgetCutter->SetCenter(center); m_widgetCutter->refreshWidget(); //m_widgetCutter->TurnAllWidgetOff(); //m_widgetCutter->Update(); m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::on_pb_exportData_clicked() { QString desFilePath(""); if (m_dataType == 0 || m_dataType == 1) { desFilePath = QFileDialog::getSaveFileName(this, tr("Export Data"), "", tr("TXT(*.txt)")); } else if (m_dataType == 2) { desFilePath = QFileDialog::getSaveFileName(this, tr("Export Data"), "", tr("VTK(*.vtk)")); } if (!m_filePathToRead.isEmpty() && !desFilePath.isEmpty()) { QFile file(desFilePath); if (file.exists()) { file.remove(); } QFile::copy(m_filePathToRead, desFilePath); } } void ThreeDimensionDiagraph::on_doubleSpinBox_resultScale_valueChanged(double value) { auto scale = ui->checkBox_logarithm->isChecked() ? m_logDefautFactory * value / 100. : value / 100.; m_dataActor->SetScale(scale); if (m_widgetCutter->GetCutterActor()) { m_widgetCutter->GetCutterActor()->SetScale(scale); } m_renderWindow3D->Render(); } void ThreeDimensionDiagraph::slot_refreshWindowTitle(int caseID, int resultType, int viewResultDataID) { //if (m_caseID <= 0 || m_caseID != caseID || m_viewResultDataID != viewResultDataID // || resultType != (int)BaseModule::ResultType::ResultThreeDimensionGraph) //{ // return; //} //auto caseModel = ProjectManager::CaseModelManager::getinstance()->getModelByID(caseID); //if (caseModel) //{ // if (caseModel->getTreeType() == BaseModule::SolverType::MOM) // { // auto viewResultData = caseModel->getMOMDataManager()->getMOMSimulationData()->getViewResultByID(viewResultDataID); // QString title = viewResultData->getName(); // setWindowTitle(title); // setBaseWindowTitle(title); // } // else if (caseModel->getTreeType() == BaseModule::SolverType::FEM) // { // auto viewResultData = caseModel->getFEMDataManager()->getFEMSimulationData()->getViewResultByID(viewResultDataID); // QString title = viewResultData->getName(); // setWindowTitle(title); // setBaseWindowTitle(title); // } //} } bool ThreeDimensionDiagraph::readerDelimitedTextFromLocal(const QString& fileName) { if (!vtksys::SystemTools::FileExists(fileName.toStdString(), true)) { return false; } m_delimitedTextReader->SetFileName(fileName.toStdString().c_str()); m_delimitedTextReader->SetHaveHeaders(true); m_delimitedTextReader->SetDetectNumericColumns(true); m_delimitedTextReader->SetFieldDelimiterCharacters(","); m_delimitedTextReader->SetUseStringDelimiter(true); m_delimitedTextReader->Update(); if (m_delimitedTextReader->GetOutput() == nullptr) { return false; } return true; } void ThreeDimensionDiagraph::resetCameraViewDirection( vtkCamera* camera, double look_x, double look_y, double look_z, double up_x, double up_y, double up_z) { double pos[3] = { 0, 0, 0 }; double focal_point[3] = { look_x, look_y, look_z }; double view_up[3] = { up_x, up_y, up_z }; camera->SetPosition(pos); camera->SetFocalPoint(focal_point); camera->SetViewUp(view_up); m_render3D->ResetCamera(); this->ui->qvtkWidget->renderWindow()->Render(); } void ThreeDimensionDiagraph::copyActor(vtkActor* sourceActor, vtkSmartPointer desActor) { //sourceActor->GetProperty()->SetRepresentationToWireframe(); auto sourceData = sourceActor->GetMapper()->GetInput(); auto sourceMapper = sourceActor->GetMapper(); auto sourceProperty = sourceActor->GetProperty(); auto sourceBackFaceProperty = sourceActor->GetBackfaceProperty(); vtkNew mapper; mapper->ShallowCopy(sourceMapper); mapper->SetInputData(sourceData); desActor->SetMapper(mapper); vtkNew property; property->DeepCopy(sourceProperty); desActor->SetProperty(property); if (sourceBackFaceProperty) { vtkNew backFaceProperty; backFaceProperty->DeepCopy(sourceBackFaceProperty); desActor->SetBackfaceProperty(backFaceProperty); } } void ThreeDimensionDiagraph::setScalarBarRange() { if (ui->checkBoxScalarBarRangeAutomatic->isChecked()) { m_lookupTable->SetRange(m_scalarBarAutoDataRange); m_widgetCutter->SetScalarBarRange(m_scalarBarAutoDataRange[0], m_scalarBarAutoDataRange[1]); } else { m_lookupTable->SetRange(ui->doubleSpinBox_SBMinRange->value(), ui->doubleSpinBox_SBMaxRange->value()); m_widgetCutter->SetScalarBarRange(ui->doubleSpinBox_SBMinRange->value(), ui->doubleSpinBox_SBMaxRange->value()); } } }