#include #include #include #include #include "../QVTKRenderer/qvtkrenderer.h" #include "../mesh/mesh.h" #include "../MeshDS/MeshBase.h" #include "../mesh/mesh_ugrid.h" #include "../display/contourdisplay.h" #include "../display/linedisplay.h" #include "../display/slicewidget.h" #include "../display/solidsurfacewidget.h" #include "../display/streamwidget.h" #include "../display/vectordisplay.h" #include "../display/contourinimationdisplay.h" #include "../visualization_VTK/vtkVISUnContour.h" #include "../visualization_VTK/vtkvisunstructuredgridsource.h" #include "ResultMeshManager.h" #include "../visualization_VTK/vtkVISMeshToVTKSource.h" #include "../mesh/mesh_tecplot.h" #include "../mesh/Mesh_Frd.h" #include "../visualization_VTK/vtkvisunshademesh.h" #include "../visualization_VTK/vtkVISUnGlyph.h" //#include "contourinimation.h" #include "../display/slicewidget.h" //#include "streamwidget.h" //#include "xyplot_2d.h" #include #include #include #include #include "../visualization_VTK/vtkvismeshbasetovtksource.h" #include "vtkPoints.h" #include "../widget/linedisplayWidget.h" #include "../widget/contourdispalyWidget.h" #include "../widget/slicedisplaywidget.h" #include "../widget/solidsurfaceDisplaywidget.h" #include "../widget/Sslicewidget.h" #include "../widget/streamDisplaywidget.h" #include "../widget/vectorDisplaywidget.h" #include "../widget/contourinimationw.h" //ResultMeshManager* ResultMeshManager::m_pInstance = 0; /** * @brief singleton methed, get class instance. * * @param[in] * @return the class instance. * @author zhaoyu * @date 20221202 */ //ResultMeshManager* ResultMeshManager::getInstance() //{ // if (m_pInstance == 0) // { // m_pInstance = new ResultMeshManager; // } // return m_pInstance; //} /** * @brief the constructor. * * @param[in] * @return * @author zhaoyu * @date 20221202 */ ResultMeshManager::ResultMeshManager() { meshObj_ = 0; m_currId = -1; scalarIndex = -1; range_[0] = 0; range_[1] = 0; scalarLeave = 10; titleSize_ = 6; labelSize_ = 5; animationWidget_ = NULL; contourWidget_ = NULL; lineWidget_ = NULL; vectorWidget_ = NULL; solidSurfaceW_ = NULL; sliceW_ = NULL; streamW_ = NULL; // xyplot2dW_ = NULL; changeRangeFlag = false; surfaceHideFlag = true; displayType = -1; scaleFactor_ = 0.02; solveTimes_.clear(); zoneNameVec_.clear(); currShowZoneNameSet_.clear(); surfaceActorColor_.clear(); scalarName_.clear(); allZoneScalarName_.clear(); surfaceActorColor_.push_back(0); surfaceActorColor_.push_back(0); surfaceActorColor_.push_back(1); surfaceActorTransparency_ = 1; addDataSource_ = NULL; currAddDataSource_ = NULL; unSliceVec_.clear(); streamLine_ = NULL; render_ = NULL; titleText_ = NULL; MeshVec_.clear(); ModalMeshVec_.clear(); initPointsData = NULL; dispNameVec.clear(); HaveModalMeshFlag = false; meshType = 0; xyplot2dSlice_ = NULL; currentVISGridVec_.clear(); showHideVec_.clear(); vectorScalarIndexVec.clear(); TimeMeshVec_.clear(); source = NULL; unmesh = NULL; uncontour = NULL; uncontourVec_.clear(); } /** * @brief the destructor. * * @param[in] * @return * @author zhaoyu * @date 20221202 */ ResultMeshManager::~ResultMeshManager() { this->Clear(); } /** * @brief clear the mesh information. * * @param[in] * @return * @author zhaoyu * @date 20221202 */ void ResultMeshManager::Clear() { if (meshObj_) { //delete meshObj_; meshObj_ = NULL; } m_currId = -1; scalarIndex = -1; range_[0] = 0; range_[1] = 0; scalarLeave = 10; titleSize_ = 6; labelSize_ = 5; changeRangeFlag = false; surfaceHideFlag = true; displayType = -1; scaleFactor_ = 0.02; solveTimes_.clear(); zoneNameVec_.clear(); currShowZoneNameSet_.clear(); nameTypeMap_.clear(); showHideVec_.clear(); surfaceActorColor_.clear(); scalarName_.clear(); allZoneScalarName_.clear(); //vtk vis procs. for(map>::iterator it = vtkVisZoneMeshMap_.begin(); it != vtkVisZoneMeshMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneMeshMap_.clear(); for(map>::iterator it = vtkVisZoneUnShadeMeshMap_.begin(); it != vtkVisZoneUnShadeMeshMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneUnShadeMeshMap_.clear(); for(map>::iterator it = vtkVisZoneGlyphMap_.begin(); it != vtkVisZoneGlyphMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneGlyphMap_.clear(); if (!unSliceVec_.empty()) { for (int i = 0; i < unSliceVec_.size(); i ++) { if(unSliceVec_.at(i) != NULL) { unSliceVec_.at(i)->Delete(); unSliceVec_.at(i) = NULL; } } unSliceVec_.clear(); } if (currentVISGridVec_.size() != 0) { /*for (int i = 0; i < currentVISGridVec_.size(); i ++) { delete currentVISGridVec_.at(i); }*/ currentVISGridVec_.clear(); } if (addDataSource_ != NULL) { delete addDataSource_; addDataSource_ = NULL; } if (currAddDataSource_ != NULL) { delete currAddDataSource_; currAddDataSource_ = NULL; } DeleteAllStream(); if (streamLine_ != NULL) { streamLine_->Delete(); streamLine_ = NULL; } if (xyplot2dSlice_ != NULL) { xyplot2dSlice_->Delete(); xyplot2dSlice_ = NULL; } surfaceActorColor_.push_back(0); surfaceActorColor_.push_back(0); surfaceActorColor_.push_back(1); surfaceActorTransparency_ = 1; // if (animationWidget_ != NULL) // { // animationWidget_->RestoreWidget(); // } if (contourWidget_ != NULL) { contourWidget_->RestoreWidget(); } if (lineWidget_ != NULL) { lineWidget_->RestoreWidget(); } if (vectorWidget_ != NULL) { //vectorWidget_->RestoreWidget(); /*vectorWidget_->dataU.clear(); vectorWidget_->dataV.clear(); vectorWidget_->dataW.clear(); vectorWidget_->SetScaleFactor(0.02);*/ } if (solidSurfaceW_ != NULL) { //solidSurfaceW_->RestoreWidget(); //solidSurfaceW_->SetShowHideState(true); //solidSurfaceW_->SetTransparency(1); } if (sliceW_ != NULL) { /*sliceW_->scalarNameVec.clear(); sliceW_->zoneIdVec.clear(); sliceW_->index = 0; sliceW_->oldIndex = -1;*/ // sliceW_->RestoreWidget(); } if (streamW_ != NULL) { //streamW_->RestoreWidget(); /*streamW_->dataU.clear(); streamW_->dataV.clear(); streamW_->dataW.clear(); streamW_->current_direction = "both"; streamW_->showstate = true; streamW_->toolstate = true;*/ } // if (xyplot2dW_ != NULL) // { // xyplot2dW_->RestoreWidget(); // } if (render_ != NULL) { render_->HideAllActors(); render_ = NULL; } MeshVec_.clear(); TimeMeshVec_.clear(); ModalMeshVec_.clear(); if (initPointsData != NULL) { delete initPointsData; } initPointsData = NULL; dispNameVec.clear(); HaveModalMeshFlag = false; meshType = 0; if(source!=NULL){ source->Delete(); source = NULL; } if(unmesh != NULL){ unmesh->Delete(); unmesh = NULL; } if(uncontour != NULL){ uncontour->Delete(); uncontour = NULL; } if(!uncontourVec_.empty()){ qDeleteAll(uncontourVec_); } } /** * @brief load result mesh from file. * * @param[in] the mesh file path. * @return loading mesh is sucessful or not. * @author zhaoyu * @date 20221202 */ bool ResultMeshManager::LoadData(QString name) { bool loadstate = false; QFileInfo meshinfo(name); QString extType(meshinfo.completeSuffix().toLower()); if (extType == "tec" || extType == "plt" ) { meshObj_ = new Mesh_Tecplot; if (extType == "tec") ; else if (extType == "plt" ) loadstate = meshObj_->Load_Binary(name.toStdString()); }else if (extType.contains("frd")) { Mesh_Frd* mfrd = new Mesh_Frd; loadstate = mfrd->Load_Ascii(name.toStdString()); if (loadstate) { dispNameVec = mfrd->GetDispVec(); initPointsData = mfrd->GetBase()->GetPoints(); TimeMeshVec_ = mfrd->GetMeshVec(); ModalMeshVec_ = mfrd->GetModalMeshVec(); if (ModalMeshVec_.size() != 0) HaveModalMeshFlag = true; MeshVec_ = TimeMeshVec_; } }else if(extType == "dat"){ meshObj_ = new Mesh_Tecplot; loadstate = meshObj_->Load_Ascii(name.toStdString());//0614append } else { QMessageBox::information(NULL,"Error","The import of this file format is temporarily not supported.",QMessageBox::Ok); } return loadstate; } /** * @brief display mesh in renderer. vtk vis mode. * * @param[in] the renderer to draw mesh. * @return * @author shiting * @date 20220729 */ void ResultMeshManager::DisplayMesh(QVTKRenderer *qvtkRenderer) { if (MeshVec_.size() == 0)//frd { render_ = qvtkRenderer; if (meshObj_ == 0) return; if (qvtkRenderer == 0) return; solveTimes_.insert(meshObj_->GetSovleTime()); size_t nzone = meshObj_->GetZoneNumber(); vtkVISMeshToVTKSource* source = new vtkVISMeshToVTKSource; map contourMap; map glyphMap; map unMeshMap; source->MeshToVTK(meshObj_); int type = source->GetType(); if (type == -1)//unKnow { }else if (type == 0)//structured { }else if (type == 1)//unstructured { for (int i = 0; i < nzone; i ++) { if (source->GetVtkUnMesh(i) != NULL) { map>::iterator contourIt = vtkVisZoneMeshMap_.find(meshObj_->GetSovleTime());//key sovletime if (contourIt != vtkVisZoneMeshMap_.end()) { contourMap = contourIt->second; } map>::iterator unMeshIt = vtkVisZoneUnShadeMeshMap_.find(meshObj_->GetSovleTime()); if (unMeshIt != vtkVisZoneUnShadeMeshMap_.end()) { unMeshMap = unMeshIt->second; } map>::iterator glyphIt = vtkVisZoneGlyphMap_.find(meshObj_->GetSovleTime()); if (glyphIt != vtkVisZoneGlyphMap_.end()) { glyphMap = glyphIt->second; } vtkVISUnstructuredGridSource* unGrid = source->GetVtkUnMesh(i); vtkVISUnContour* visobj = vtkVISUnContour::New();//contour visobj->SetRenderTo(qvtkRenderer->GetRenderer()); vtkVISUnGlyph* unGlyph = vtkVISUnGlyph::New();//glyph3d unGlyph->SetRenderTo(qvtkRenderer->GetRenderer()); vtkVISUnShadeMesh* unMesh = vtkVISUnShadeMesh::New();//unShadeMesh unMesh->SetRenderTo(qvtkRenderer->GetRenderer()); visobj->SetDataSource(unGrid); unGlyph->SetDataSource(unGrid); unMesh->SetDataSource(unGrid); unMesh->CreateShadeMeshSurfaceDisplay(true); string zoneName = meshObj_->GetZoneName().at(i); if (!count(zoneNameVec_.begin(), zoneNameVec_.end(), zoneName)) { zoneNameVec_.push_back(zoneName); } contourMap[zoneName] = visobj; glyphMap[zoneName] = unGlyph; unMeshMap[zoneName] = unMesh; } } } vtkVisZoneMeshMap_[meshObj_->GetSovleTime()] = contourMap; vtkVisZoneGlyphMap_[meshObj_->GetSovleTime()] = glyphMap; vtkVisZoneUnShadeMeshMap_[meshObj_->GetSovleTime()] = unMeshMap; } else { /*meshObj_ = MeshVec_.at(0); vtkVISMeshToVTKSource* source = new vtkVISMeshToVTKSource; source->MeshToVTK(meshObj_); vtkVISUnShadeMesh* unMesh = vtkVISUnShadeMesh::New(); unMesh->SetRenderTo(qvtkRenderer->GetRenderer()); unMesh->SetDataSource(source->GetVtkUnMesh(0)); unMesh->CreateShadeMeshSurfaceDisplay(true); qvtkRenderer->ZoomToExtents();*/ for (int i = 0; i < MeshVec_.size(); i ++) { meshObj_ = MeshVec_.at(i); render_ = qvtkRenderer; if (meshObj_ == 0) return; if (qvtkRenderer == 0) return; solveTimes_.insert(meshObj_->GetSovleTime()); size_t nzone = meshObj_->GetZoneNumber(); vtkVISMeshToVTKSource* source = new vtkVISMeshToVTKSource; map contourMap; map glyphMap; map unMeshMap; source->MeshToVTK(meshObj_); int type = source->GetType(); if (type == -1)//unKnow { }else if (type == 0)//structured { }else if (type == 1)//unstructured { for (int i = 0; i < nzone; i ++) { if (source->GetVtkUnMesh(i) != NULL) { map>::iterator contourIt = vtkVisZoneMeshMap_.find(meshObj_->GetSovleTime()); if (contourIt != vtkVisZoneMeshMap_.end()) { contourMap = contourIt->second; } map>::iterator unMeshIt = vtkVisZoneUnShadeMeshMap_.find(meshObj_->GetSovleTime()); if (unMeshIt != vtkVisZoneUnShadeMeshMap_.end()) { unMeshMap = unMeshIt->second; } map>::iterator glyphIt = vtkVisZoneGlyphMap_.find(meshObj_->GetSovleTime()); if (glyphIt != vtkVisZoneGlyphMap_.end()) { glyphMap = glyphIt->second; } vtkVISUnstructuredGridSource* unGrid = source->GetVtkUnMesh(i); vtkVISUnContour* visobj = vtkVISUnContour::New();//contour visobj->SetRenderTo(qvtkRenderer->GetRenderer()); vtkVISUnGlyph* unGlyph = vtkVISUnGlyph::New();//glyph3d unGlyph->SetRenderTo(qvtkRenderer->GetRenderer()); vtkVISUnShadeMesh* unMesh = vtkVISUnShadeMesh::New();//unShadeMesh unMesh->SetRenderTo(qvtkRenderer->GetRenderer()); visobj->SetDataSource(unGrid); unGlyph->SetDataSource(unGrid); unMesh->SetDataSource(unGrid); unMesh->CreateShadeMeshSurfaceDisplay(true); string zoneName = meshObj_->GetZoneName().at(i); if (!count(zoneNameVec_.begin(), zoneNameVec_.end(), zoneName)) { zoneNameVec_.push_back(zoneName); } contourMap[zoneName] = visobj; glyphMap[zoneName] = unGlyph; unMeshMap[zoneName] = unMesh; } } } vtkVisZoneMeshMap_[meshObj_->GetSovleTime()] = contourMap; vtkVisZoneGlyphMap_[meshObj_->GetSovleTime()] = glyphMap; vtkVisZoneUnShadeMeshMap_[meshObj_->GetSovleTime()] = unMeshMap; } } } /** * @brief set show or hide state * * @param[in] vector * @return * @author zhaoyu * @date 20221209 */ void ResultMeshManager::SetShowHideState(vector vec) { currShowZoneNameSet_.clear(); showHideVec_.clear(); showHideVec_ = vec; int i = 0; for (vector::iterator it = zoneNameVec_.begin(); it != zoneNameVec_.end(); it ++) { if (vec.at(i)) { currShowZoneNameSet_.insert(*it); } i ++; } } /** * @brief show all zones * * @param[in] * @return * @author zhaoyu * @date 20221209 */ void ResultMeshManager::ShowAll() { if (meshObj_ == 0) return; currShowZoneNameSet_.clear(); for (int i = 0; i < zoneNameVec_.size(); i ++) { currShowZoneNameSet_.insert(zoneNameVec_.at(i)); } showHideVec_.clear(); for (int i = 0; i < zoneNameVec_.size(); i ++) { showHideVec_.push_back(true); } } /** * @brief display the mesh by index * * @param[in] mesh index * @return * @author zhaoyu * @date 20221205 */ void ResultMeshManager::DisplayMeshByIndex(int index) { bool scalarBarState = true; m_currId = index; HideSliceActors(); HideXyplot2dSliceActors(); int num = 0; double time = 0.0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == m_currId) { time = *it; break; } num ++; } if (index >= 0 && index <= vtkVisZoneUnShadeMeshMap_.size()) { map>::iterator unMehsIt = vtkVisZoneUnShadeMeshMap_.find(time); //unshademesh if (surfaceHideFlag) { for (map::iterator it2= unMehsIt->second.begin(); it2 != unMehsIt->second.end(); it2 ++) { if (currShowZoneNameSet_.count(it2->first)) { it2->second->SetColor(surfaceActorColor_[0], surfaceActorColor_[1], surfaceActorColor_[2]); it2->second->SetOpacity(surfaceActorTransparency_); it2->second->ShowOn(); }else { it2->second->ShowOff(); } } }else { for (map::iterator it2= unMehsIt->second.begin(); it2 != unMehsIt->second.end(); it2 ++) { it2->second->ShowOff(); } } //contour or line if (displayType == 0 || displayType == 2) { HideAllGlyphActors(); map>::iterator contourIt = vtkVisZoneMeshMap_.find(time); InitRange(index); for (map::iterator it2 = contourIt->second.begin(); it2 != contourIt->second.end(); it2 ++) { if (currShowZoneNameSet_.count(it2->first)) { it2->second->SetContourType(displayType); it2->second->SetContourLevel(scalarLeave); /*if (scalarName_ != it2->second->GetScalarName()) { char* name = (char*)scalarName_.c_str(); it2->second->ModifyContourDisplay(name); it2->second->DeleteScalarBar(); it2->second->CreateScalarBar(); }*/ char* name = (char*)scalarName_.c_str(); it2->second->ModifyContourDisplay(name); it2->second->DeleteScalarBar(); it2->second->CreateScalarBar(); it2->second->ModifyDisplayScalarRange(range_[0], range_[1]); it2->second->ShowOffScalarBar(); it2->second->ShowOn(); if (scalarBarState) { scalarBarState = !(it2->second->UpdataScalarBar()); if (!scalarBarState) { it2->second->ShowOnScalarBar(); } } }else { it2->second->ShowOff(); it2->second->ShowOffScalarBar(); } } /*for (map::iterator it2= unMehsIt->second.begin(); it2 != unMehsIt->second.end(); it2 ++) { it2->second->SetOpacity(0); it2->second->ShowOn(); }*/ }else if (displayType == 3)//unglyph { HideAllContourActors(); map>::iterator glyphIt = vtkVisZoneGlyphMap_.find(time); for (map::iterator it2= glyphIt->second.begin(); it2 != glyphIt->second.end(); it2 ++) { if (currShowZoneNameSet_.count(it2->first)) { it2->second->InitGlyphDisplay(vectorScalarIndexVec.at(0), vectorScalarIndexVec.at(1), vectorScalarIndexVec.at(2));//cuode it2->second->SetGlyphScaleFactor(scaleFactor_); it2->second->ShowOn(); }else { it2->second->ShowOff(); } } } } render_->ZoomToExtents(); } /** * @brief hide all actors in the renderer * * @param[in] * @return * @author zhaoyu * @date 20230224 */ void ResultMeshManager::HideAllActors() { render_->HideAllActors(); } /** * @brief hide all contour actors in the renderer * * @param[in] * @return * @author zhaoyu * @date 20230224 */ void ResultMeshManager::HideAllUnshadeMeshActors() { if (meshObj_ == 0) return; int num = 0; double time = 0.0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == m_currId) { time = *it; break; } num ++; } map>::iterator unMehsIt = vtkVisZoneUnShadeMeshMap_.find(time); for (map::iterator it2= unMehsIt->second.begin(); it2 != unMehsIt->second.end(); it2 ++) { it2->second->ShowOff(); } } /** * @brief hide all contour actors in the renderer * * @param[in] * @return * @author zhaoyu * @date 20230224 */ void ResultMeshManager::HideAllContourActors() { if (meshObj_ == 0) return; int num = 0; double time = 0.0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == m_currId) { time = *it; break; } num ++; } map>::iterator contourIt = vtkVisZoneMeshMap_.find(time); for (map::iterator it2 = contourIt->second.begin(); it2 != contourIt->second.end(); it2 ++) { it2->second->ShowOff(); it2->second->ShowOffScalarBar(); } } /** * @brief hide all vector actors in the renderer * * @param[in] * @return * @author zhaoyu * @date 20230224 */ void ResultMeshManager::HideAllGlyphActors() { if (meshObj_ == 0) return; int num = 0; double time = 0.0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == m_currId) { time = *it; break; } num ++; } map>::iterator glyphIt = vtkVisZoneGlyphMap_.find(time); for (map::iterator it2= glyphIt->second.begin(); it2 != glyphIt->second.end(); it2 ++) { it2->second->ShowOff(); } } /** * @brief set index * * @param[in] index * @return * @author zhaoyu * @date 20221205 */ void ResultMeshManager::SetSaveIndex(int index) { m_currId = index; } int ResultMeshManager::GetCurrIndex() { return m_currId; } /** * @brief get zone name vector * * @param[in] * @return zoneNameVec_ * @author zhaoyu * @date 20221206 */ vector ResultMeshManager::GetZoneNameVec() { return zoneNameVec_; } /** * @brief get solve time vector * * @param[in] * @return solveTimes_ * @author zhaoyu * @date 20221206 */ set ResultMeshManager::GetSolveTime() { return solveTimes_; } /** * @brief add map data by mesh data * * @param[in] * @return * @author zhaoyu * @date 20221206 */ void ResultMeshManager::SetNameTypeMap() { if (meshObj_ == 0) return; for (int i = 0; i < meshObj_->GetScalarNumber(); i ++) { string name = meshObj_->GetScalarName().at(i); nameTypeMap_[name] = meshObj_->GetZoneScalarType().at(0).at(i + 3); //cout << name << ", " << meshObj_->GetZoneScalarType().at(0).at(i + 3) << endl; } } /** * @brief get name type map * * @param[in] * @return nameTypeMap_ * @author zhaoyu * @date 20221206 */ map ResultMeshManager::GetNameTypeMap() { return nameTypeMap_; } /** * @brief get scalar name vector * * @param[in] * @return vector nameVec * @author zhaoyu * @date 20221208 */ vector ResultMeshManager::GetMeshScalarNameVec() { if (meshObj_ == 0) { vector nullVec; return nullVec; } return meshObj_->GetScalarName(); } /** * @brief init scalar range * * @param[in] int current step * @return * @author zhaoyu * @date 20221209 */ void ResultMeshManager::InitRange(int index) { if(changeRangeFlag)//user set range { changeRangeFlag = false; }else// program calculated range { set set_; int num = 0; double time = 0.0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == index) { time = *it; break; } num ++; } map>::iterator it1 = vtkVisZoneMeshMap_.find(time); set::iterator it3; for (map::iterator unIt = it1->second.begin(); unIt != it1->second.end(); unIt ++) { if (currShowZoneNameSet_.count(unIt->first)) { double range[2]; //string str = meshObj_->GetScalarName().at(scalarIndex); char* scalarName = (char*)scalarName_.c_str(); unIt->second->GetScalarRange(range, scalarName); set_.insert(range[0]); set_.insert(range[1]); } } if (set_.size() == 0) { range_[0] = 0; range_[1] = 0; }else { it3 = set_.begin(); range_[0] = *it3; it3 = --set_.end(); range_[1] = *it3; //cout << range_[0] << ", " << range_[1] << endl; } } SetWidgetRange();//init widget range parameter*/ } /** * @brief Get scalar min range * * @param[in] * @return double min * @author zhaoyu * @date 20221210 */ double* ResultMeshManager::GetScalarRange() { return range_; } /** * @brief change scalar display * * @param[in] index * @return * @author zhaoyu * @date 20221210 */ void ResultMeshManager::ModifyScalarDisplay(int index) { if (scalarIndex != index) { scalarIndex = index; } } /** * @brief change scalar display * * @param[in] index * @return * @author zhaoyu * @date 20221210 */ void ResultMeshManager::ModifyScalarDisplay(string name) { if (scalarName_ != name && !(name.empty())) { scalarName_ = name; SetWidgetScalarName(); InitRange(m_currId); } } /** * @brief get scalar display * * @param[in] * @return scalarIndex * @author zhaoyu * @date 20221210 */ int ResultMeshManager::GetScalarIndex() { return scalarIndex; } /** * @brief set scalar level * * @param[in] int level * @return * @author zhaoyu * @date 20221210 */ void ResultMeshManager::SetContourLevel(int level) { scalarLeave = level; } /** * @brief get scalar display * * @param[in] * @return scalarIndex * @author zhaoyu * @date 20221210 */ int ResultMeshManager::GetContourLevel() { return scalarLeave; } /** * @brief init contourWidget pointer * * @param[in] ContourDisplayW pointer * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetCotourWidget(ContourDisplayW* w) { contourWidget_ = w; if (meshObj_ != NULL) { contourWidget_->SetNameTypeMap(GetNameTypeMap()); contourWidget_->SetScalarNameVec(GetMeshScalarNameVec()); SetWidgetRange(); SetWidgetScalarName(); } } /** * @brief init lineWidget pointer * * @param[in] LineDisplayW pointer * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetLineWidget(LineDisplayW* w) { lineWidget_ = w; if (meshObj_ != NULL) { lineWidget_->SetNameTypeMap(GetNameTypeMap()); lineWidget_->SetScalarNameVec(GetMeshScalarNameVec()); SetWidgetRange(); SetWidgetScalarName(); }// } /** * @brief init vector Widget pointer * * @param[in] VectorW pointer * @return * @author zhaoyu * @date 20221226 */ void ResultMeshManager::SetVectorWidget(VectorW* w) { vectorWidget_ = w; if (meshObj_ != NULL) { vector tmp = GetMeshScalarNameVec();//0504 append去除容器里元素的"\0000" //for(auto &p:tmp){ //p=deleteSpaces(p); //} vectorWidget_->GetData_u(tmp); vectorWidget_->GetData_v(tmp); vectorWidget_->GetData_w(tmp); vectorWidget_->SetScaleFactor(scaleFactor_); } } void ResultMeshManager::SetAnimationWidget(ContourInimationW *w) { animationWidget_ = w; if (meshObj_ != NULL) { w->SetTypeEnable(HaveModalMeshFlag); animationWidget_->SetSolveTime(GetSolveTime()); animationWidget_->SetZoneNameVector(zoneNameVec_); } } void ResultMeshManager::SetSurfaceSolidWidget(SolidSurfaceWidget* w) { solidSurfaceW_ = w; } /** * @brief init slice Widget pointer * * @param[in] SsliceWidget pointer * @return * @author zhaoyu * @date 20230301 */ void ResultMeshManager::SetSliceWidget(SsliceWidget* w) { sliceW_ = w; if (meshObj_ != NULL) { sliceW_->GetZoneId(GetShowZoneId()); sliceW_->GetScalarName(GetMeshScalarNameVec()); } } /** * @brief init stream Widget pointer * * @param[in] stresmWidget pointer * @return * @author zhaoyu * @date 20230303 */ void ResultMeshManager::SetStremWidget(StreamDisplayWidget* w) { streamW_ = w; if (meshObj_ != NULL) { streamW_->SetData_u(GetMeshScalarNameVec()); streamW_->SetData_v(GetMeshScalarNameVec()); streamW_->SetData_w(GetMeshScalarNameVec()); } } void ResultMeshManager::SetXyplotWidget(XYPlot_2D *w) { } /** * @brief init xyplot2d Widget pointer * * @param[in] xyplot2d pointer * @return * @author zhaoyu * @date 20230411 */ //void ResultMeshManager::SetXyplotWidget(XYPlot_2D* w) //{ // xyplot2dW_ = w; // if (meshObj_ != NULL) // { // xyplot2dW_->SetArea(zoneNameVec_); // xyplot2dW_->SetYAxis(GetMeshScalarNameVec()); // } //} /** * @brief init widgets range parameter * * @param[in] * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetWidgetRange() { if (contourWidget_ != NULL) { contourWidget_->SetRange(range_); } if (lineWidget_ != NULL) { lineWidget_->SetRange(range_); } } /** * @brief init widgets scalar name * * @param[in] * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetWidgetScalarName() { if (meshObj_ != NULL && (!scalarName_.empty())) { string name = scalarName_; if (contourWidget_ != NULL) { contourWidget_->SetCurrScalar(name); } if (lineWidget_ != NULL) { lineWidget_->SetCurrScalar(name); } } } /** * @brief set title size * * @param[in] int size * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetTitleSize(double size) { titleSize_ = size; //SetWidgetTitleSize(); } /** * @brief init widget title size * * @param[in] * @return * @author zhaoyu * @date 20221213 */ //void ResultMeshManager::SetWidgetTitleSize() //{ // if (contourWidget_ != NULL) // { // contourWidget_->SetTitleFont(titleSize_); // } //} /** * @brief set label size * * @param[in] int label size * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetLabelSize(double size) { labelSize_ = size; //SetWidgetLabelSize(); } /** * @brief set widget label size * * @param[in] * @return * @author zhaoyu * @date 20221213 */ //void ResultMeshManager::SetWidgetLabelSize() //{ // if (contourWidget_ != NULL) // { // contourWidget_->SetLabelFont(labelSize_); // } //} /** * @brief set level * * @param[in] int level * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetLevel(int level) { scalarLeave = level; SetWidgetLevel(); } /** * @brief set widget level * * @param[in] * @return * @author zhaoyu * @date 20221213 */ void ResultMeshManager::SetWidgetLevel() { if (contourWidget_ != NULL) { contourWidget_->SetLevel(scalarLeave); } if (lineWidget_ != NULL) { lineWidget_->SetLevel(scalarLeave); } } /** * @brief user set range * * @param[in] * @return * @author zhaoyu * @date 20221214 */ void ResultMeshManager::SetRange(double* range) { range_[0] = range[0]; range_[1] = range[1]; changeRangeFlag = true; } /** * @brief user set range * * @param[in] type 0 is contour * type 2 is line * @return * @author zhaoyu * @date 20221214 */ void ResultMeshManager::SetDisplayType(int type) { displayType = type; } /** * @brief init contour widget and line widget parameter * * @param[in] * @return * @author zhaoyu * @date 20230110 */ void ResultMeshManager::InitWidgetsParameter() { if (animationWidget_ != NULL) { animationWidget_->SetTypeEnable(HaveModalMeshFlag); animationWidget_->SetSolveTime(GetSolveTime()); animationWidget_->SetZoneNameVector(zoneNameVec_); } if (contourWidget_ != NULL) { contourWidget_->SetNameTypeMap(GetNameTypeMap()); contourWidget_->SetScalarNameVec(GetMeshScalarNameVec()); SetWidgetRange(); SetWidgetScalarName(); } if (lineWidget_ != NULL) { lineWidget_->SetNameTypeMap(GetNameTypeMap()); lineWidget_->SetScalarNameVec(GetMeshScalarNameVec()); SetWidgetRange(); SetWidgetScalarName(); } if (vectorWidget_ != NULL) { vectorWidget_->GetData_u(GetMeshScalarNameVec()); vectorWidget_->GetData_v(GetMeshScalarNameVec()); vectorWidget_->GetData_w(GetMeshScalarNameVec()); vectorWidget_->SetScaleFactor(scaleFactor_); } if (sliceW_ != NULL) { sliceW_->GetScalarName(GetMeshScalarNameVec()); sliceW_->GetZoneId(GetShowZoneId()); } if (streamW_ != NULL) { streamW_->SetData_u(GetMeshScalarNameVec()); streamW_->SetData_v(GetMeshScalarNameVec()); streamW_->SetData_w(GetMeshScalarNameVec()); } // if (xyplot2dW_ != NULL) // { // xyplot2dW_->SetArea(zoneNameVec_); // xyplot2dW_->SetYAxis(GetMeshScalarNameVec()); // } } /** * @brief init contour widget and line widget parameter * * @param[in] * @return * @author zhaoyu * @date 20221226 */ void ResultMeshManager::SetVectorScalarIndex(vector indexVec) { vectorScalarIndexVec.clear(); if (indexVec.at(0) == -1 || indexVec.at(1) == -1 || indexVec.at(2) == -1) { return; }else { vectorScalarIndexVec = indexVec; DisplayMeshByIndex(m_currId); } } /** * @brief set scaleFactor * * @param[in]double factor * @return * @author zhaoyu * @date 20230103 */ void ResultMeshManager::SetVectorScaleFactor(double factor) { scaleFactor_ = factor; } /** * @brief set surface actor color * * @param[in]color * @return * @author zhaoyu * @date 20230110 */ void ResultMeshManager::SetSurfaceColor(vector color) { surfaceActorColor_ = color; } /** * @brief set surface actor transparency * * @param[in]value * @return * @author zhaoyu * @date 20230110 */ void ResultMeshManager::SetSurfaceTransparency(double value) { surfaceActorTransparency_ = value; } /** * @brief set surface actor state * * @param[in]bool flag * @return * @author zhaoyu * @date 20230110 */ void ResultMeshManager::SetSurfaceShowHideFlag(bool flag) { surfaceHideFlag = flag; } /** * @brief set scalar name * * @param[in]char* name * @return * @author zhaoyu * @date 20230111 */ void ResultMeshManager::SetScalarName(string name) { scalarName_ = name; } vector ResultMeshManager::GetShowZoneId() { vector zoneId; zoneId.clear(); set::iterator it; for (int i = 0; i < showHideVec_.size(); i ++) { if (showHideVec_.at(i)) { zoneId.push_back(i); } } return zoneId; } void ResultMeshManager::InitSliceWidget() { HideAllUnshadeMeshActors(); HideAllGlyphActors(); HideAllContourActors(); HideStreamActors(); HideXyplot2dSliceActors(); if (solidSurfaceW_ != NULL) { solidSurfaceW_->SetShowHideState(true); } } /** * @brief creat a vtkVISunstructuredGrid source that is added by all the show zone * * @param[in] time step * @return * @author zhaoyu * @date 20230217 */ void ResultMeshManager::MakeVISUnStructGrid() { if (meshObj_ == 0) return; int num = 0; double time = 0.0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == m_currId) { time = *it; break; } num ++; } vector vec; map>::iterator it = vtkVisZoneMeshMap_.find(time); if (it != vtkVisZoneMeshMap_.end()) { for (map::iterator it2= it->second.begin(); it2 != it->second.end(); it2 ++) { if (currShowZoneNameSet_.count(it2->first)) { vtkVISUnstructuredGridSource* unGrid = vtkVISUnstructuredGridSource::New(); unGrid = it2->second->GetDatSource(); vec.push_back(unGrid); } } /*if (addDataSource_ != NULL) { //delete addDataSource_; addDataSource_ = NULL; }*/ addDataSource_ = new vtkVISAddUnGridDataSource(); addDataSource_->SetVISUnGridDataSource(vec); currentVISGridVec_.push_back(addDataSource_); } } /** * @brief get unslice position * * @param[in] unslice id * @return * @author zhaoyu * @date 20230221 */ vector ResultMeshManager::GetUnslicePosition(int index) { double* data2; data2 = unSliceVec_.at(index)->GetSlicePlaneOrigin(); vector origin; origin.push_back(data2[0]); origin.push_back(data2[1]); origin.push_back(data2[2]); return origin; } /** * @brief get unslice source bounds * * @param[in] unslice id * @return * @author zhaoyu * @date 20230221 */ vector ResultMeshManager::GetUnsliceSourceBounds(int index) { vector bounds; if (unSliceVec_.at(index) != NULL) { double b[6]; unSliceVec_.at(index)->GetSourceBounds_FD(b); for (int i = 0; i < 6; i ++) { bounds.push_back(b[i]); } } return bounds; } /** * @brief display a vtkVISUnstructGrid * * @param[in] * @return * @author zhaoyu * @date 20230221 */ void ResultMeshManager::DisplayUnstructGrid() { if (render_ == NULL) { return; } vtkVISUnSlice* unSlice_ = vtkVISUnSlice::New(); unSlice_->SetRenderTo(render_->GetRenderer()); string name = GetMeshScalarNameVec().at(0); unSlice_->SetDataSource(addDataSource_->GetSource()); char* s = (char*)(name.c_str()); char* v = NULL; unSlice_->SetSliceSource_FD(s, v); unSlice_->CreatUnShadeMeshDisplay(); unSlice_->CreateSliceWidget_FD(); unSlice_->CreateUnSliceContourDisplay_FD(); unSlice_->CreateUnSliceContourLinesDisplay_FD(); unSlice_->ShowOffUnSliceContourLinesDisplay(); unSlice_->CreateUnSliceContourLinesLabelDisplay_FD(); unSlice_->ShowOffUnSliceContourLinesLabelDisplay(); unSliceVec_.push_back(unSlice_); render_->Update(); } /** * @brief hide all slice actors in the renderer * * @param[in] * @return * @author zhaoyu * @date 20230225 */ void ResultMeshManager::HideSliceActors() { if (!unSliceVec_.empty()) { for (int i = 0; i < unSliceVec_.size(); i ++) { if (unSliceVec_.at(i) != NULL) { unSliceVec_.at(i)->ShowOffSlicePlane(); unSliceVec_.at(i)->ShowOffSlicePlaneWidget(); unSliceVec_.at(i)->ShowOffUnShadeMesh(); unSliceVec_.at(i)->ShowOffUnSliceMesh(); unSliceVec_.at(i)->ShowOffUnSliceShade(); unSliceVec_.at(i)->ShowOffCutActor(); } } } } /** * @brief set slice state * * @param[in] all sliceWidget parameter * @return * @author zhaoyu * @date 20230225 */ void ResultMeshManager::SetAllSliceState(vector sliceId, vector solidState, vector planeWidgetState, vector> nomal, vector> posision, vector type, vector contourName, vector level, vector planeState, vectorlabelState) { for (int i = 0; i < sliceId.size(); i ++) { if (solidState.at(i)) { unSliceVec_.at(sliceId.at(i))->ShowOnUnshadeMesh(); }else { unSliceVec_.at(sliceId.at(i))->ShowOffUnShadeMesh(); } if (planeWidgetState.at(i)) { unSliceVec_.at(sliceId.at(i))->ShowOnSlicePlane(); unSliceVec_.at(sliceId.at(i))->ShowOnSlicePlaneWidget(); }else { unSliceVec_.at(sliceId.at(i))->ShowOffSlicePlane(); unSliceVec_.at(sliceId.at(i))->ShowOffSlicePlaneWidget(); } unSliceVec_.at(sliceId.at(i))->SetSlicePlaneNormal(nomal.at(i).at(0), nomal.at(i).at(1),nomal.at(i).at(2)); unSliceVec_.at(sliceId.at(i))->SetSlicePlaneOrigin(posision.at(i).at(0), posision.at(i).at(1),posision.at(i).at(2)); if (type.at(i) == "contour") { unSliceVec_.at(sliceId.at(i))->ShowOnUnSliceContourDisplay(); unSliceVec_.at(sliceId.at(i))->ShowOffUnSliceContourLinesDisplay(); }else if(type.at(i) == "line") { unSliceVec_.at(sliceId.at(i))->ShowOnUnSliceContourLinesDisplay(); unSliceVec_.at(sliceId.at(i))->ShowOffUnSliceContourDisplay(); } char* name = (char*)(contourName.at(i).c_str()); unSliceVec_.at(sliceId.at(i))->ModifySliceSourceScalar_FD(name); unSliceVec_.at(sliceId.at(i))->ModifyUnSliceContourLevel(level.at(i)); if (planeState.at(i)) { //unSliceVec_.at(sliceId.at(i))->ShowOnSlicePlane(); }else { unSliceVec_.at(sliceId.at(i))->ShowOffCutActor(); } if (labelState.at(i)) { unSliceVec_.at(sliceId.at(i))->ShowOnUnSliceContourLinesLabelDisplay(); }else { unSliceVec_.at(sliceId.at(i))->ShowOffUnSliceContourLinesLabelDisplay(); } } for (int i = 0; i < unSliceVec_.size(); i ++) { if (find(sliceId.begin(), sliceId.end(), i) == sliceId.end()) { if (unSliceVec_.at(i) != NULL) { unSliceVec_.at(i)->ShowOffSlicePlane(); unSliceVec_.at(i)->ShowOffSlicePlaneWidget(); unSliceVec_.at(i)->ShowOffUnShadeMesh(); unSliceVec_.at(i)->ShowOffUnSliceMesh(); unSliceVec_.at(i)->ShowOffUnSliceShade(); unSliceVec_.at(i)->ShowOffCutActor(); unSliceVec_.at(i)->Delete(); unSliceVec_.at(i) = NULL; } } } render_->Update(); } /** * @brief updata slice widget parameter * * @param[in] * @return * @author zhaoyu * @date 20230301 */ void ResultMeshManager::UpdataSliceWidgetParameter() { if (sliceW_ == NULL) { return; } vector sliceWId = sliceW_->GetSliceId(); vector> normalVec; vector> originVec; for (int i = 0; i < sliceWId.size(); i ++) { double *data; data = unSliceVec_.at(sliceWId.at(i))->GetSlicePlaneNormal(); vector normal; normal.push_back(data[0]); normal.push_back(data[1]); normal.push_back(data[2]); normalVec.push_back(normal); double *data2; data2 = unSliceVec_.at(sliceWId.at(i))->GetSlicePlaneOrigin(); vector origin; origin.push_back(data2[0]); origin.push_back(data2[1]); origin.push_back(data2[2]); originVec.push_back(origin); } sliceW_->normal.clear(); sliceW_->position.clear(); sliceW_->normal = normalVec; sliceW_->position = originVec; } /** * @brief updata the source consisting of all current grids * * @param[in] * @return * @author zhaoyu * @date 20230306 */ void ResultMeshManager::UpdataCurrUnstructSource() { double time = 0.0; int num = 0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == m_currId) { time = *it; break; } num ++; } vector vec; map>::iterator it = vtkVisZoneMeshMap_.find(time); if (it != vtkVisZoneMeshMap_.end()) { for (map::iterator it2= it->second.begin(); it2 != it->second.end(); it2 ++) { if (currShowZoneNameSet_.count(it2->first)) { vtkVISUnstructuredGridSource* unGrid = vtkVISUnstructuredGridSource::New(); unGrid = it2->second->GetDatSource(); vec.push_back(unGrid); } } if (currAddDataSource_ != NULL) { delete currAddDataSource_; currAddDataSource_ = NULL; } currAddDataSource_ = new vtkVISAddUnGridDataSource(); currAddDataSource_->SetVISUnGridDataSource(vec); } } /** * @brief creat a vector from the scalar name passed in * * @param[in] three scalar names * @return * @author zhaoyu * @date 20230302 */ void ResultMeshManager::CreatVectorSource(string u, string v, string w) { UpdataCurrUnstructSource(); char* v1 = (char*)(u.c_str()); char* v2 = (char*)(v.c_str()); char* v3 = (char*)(w.c_str()); if (streamLine_ != NULL) { streamLine_->ShowOffStreamWidget(); streamLine_->ShowOffStreamTraceLines(); streamLine_->Delete(); streamLine_ = NULL; } if (currAddDataSource_ != NULL) { streamLine_ = vtkVISUnStreamTrace::New(); streamLine_->SetRenderTo(render_->GetRenderer()); streamLine_->SetDataSource(currAddDataSource_->GetSource()); streamLine_->SetStreamTraceSource(v1,v2,v3); string type = "line"; streamLine_->SetSeedsType(type); streamLine_->CreateStreamTraceDisplayByVector(); if (streamW_ != NULL) { streamW_->SetInitStepData(streamLine_->GetInitialStep()); streamW_->SetMaxPropgationData(streamLine_->GetMaxPropagation()); streamW_->SetMinStepData(streamLine_->GetMinimumStep()); } } //create_streamTrace(x,y,z); } /** * @brief display stream line * * @param[in] * @return * @author zhaoyu * @date 20230302 */ void ResultMeshManager::DisplayStreamLine(string direction, string type, double initStrp, double maxPropgation, double minStep, bool showState, bool ToolState) { if (streamLine_ != NULL) { char* direc = (char*)(direction.c_str()); streamLine_->ModifyIntegraDirection(direc); //type streamLine_->ShowOffStreamTraceLines(); char* streamType = (char*)type.c_str(); streamLine_->ModifyStreamStyle(streamType); streamLine_->ModifyInitialStep(initStrp); streamLine_->ModifyMaxPropagation(maxPropgation); streamLine_->ModifyMinimumStep(minStep); if (showState) { streamLine_->ShowOnStreamTraceLines(); }else { streamLine_->ShowOffStreamTraceLines(); } if (ToolState) { streamLine_->ShowOnStreamWidget(); }else { streamLine_->ShowOffStreamWidget(); } } render_->Update(); } /** * @brief set select state, true is On, false is OFF * * @param[in] * @return * @author zhaoyu * @date 20230310 */ void ResultMeshManager::SetStreamSelectState(bool flag) { if (streamLine_ == NULL) return; if (flag) { streamLine_->vtkSelectPointOn(); }else { streamLine_->vtkSelectPointOff(); } } /** * @brief delete all Stream * * @param[in] * @return * @author zhaoyu * @date 20230310 */ void ResultMeshManager::DeleteAllStream() { if (streamLine_ != NULL) { streamLine_->ShowOffStreamWidget(); streamLine_->ShowOffStreamTraceLines(); streamLine_->vtkSelectPointOff(); render_->Update(); streamLine_->Delete(); streamLine_ = NULL; } } /** * @brief export the current render picture * * @param[in] * @return * @author hejingjing * @date 20230315 */ //void ResultMeshManager::GetExportPictures(QString file) //{ // QFileInfo info(file); // if (render_!= NULL && (render_->GetRenderer()->VisibleActorCount() > 0)) // { // captureF = vtkVISCaptureFigure::New(); // captureF->SetCaptureFigureSource(render_->GetRenderer()); // QString extType = info.suffix(); // qDebug() << extType; // string st = file.toStdString(); // char *str = (char*)st.c_str();//qstring转char // if(extType.contains( "JPEG" )) // { // captureF->CaptureRenderFigureAsJPEG(str); // } // else if(extType.contains("BMP")) // { // captureF->CaptureRenderFigureAsBMP(str); // } // else if(extType.contains("PNG")) // { // captureF->CaptureRenderFigureAsPNG(str); // } // else if(extType.contains("TIFF")) // { // captureF->CaptureRenderFigureAsTIFF(str); // } // else if(extType.contains("PNM")) // { // captureF->CaptureRenderFigureAsPNM(str); // } // } //} /** * @brief hide streamLine and lineWidget * * @param[in] * @return * @author zhaoyu * @date 20230320 * * */ void ResultMeshManager::HideStreamActors() { DeleteAllStream(); } //void ResultMeshManager::SetTextWidget(TextWidget *w) //{ // textW_ = w; //} /** * @brief set textwidget state * * @param[in] all textwidget parameter * @return * @author hejingjing * @date 20230321 */ void ResultMeshManager::GetActorText(string text_, vector position_XY, double fontsize,vector color) { if(titleText_ != NULL) { titleText_->SetVisibility(false); titleText_->Delete(); } titleText_ = vtkTextActor::New(); if(!text_.empty()) { const char *TitleText = text_.c_str(); titleText_->SetInput(TitleText); titleText_->SetDisplayPosition(position_XY.at(0),position_XY.at(1)); titleText_->GetTextProperty()->SetFontSize(fontsize); titleText_->GetTextProperty()->SetColor(color.at(0),color.at(1),color.at(2)); render_->GetRenderer()->AddActor2D(titleText_); render_->Update(); } } /** * @brief update the scaled model * * @param[in] double scaled factor * @return * @author zhaoyu * @date 20230406 */ void ResultMeshManager::UpdataZoomModel(double factor) { if (initPointsData == NULL) return; if (dispNameVec.size() == 0) return; if (MeshVec_.size() == 0) return; ///creat old data for(map>::iterator it = vtkVisZoneMeshMap_.begin(); it != vtkVisZoneMeshMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneMeshMap_.clear(); for(map>::iterator it = vtkVisZoneUnShadeMeshMap_.begin(); it != vtkVisZoneUnShadeMeshMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneUnShadeMeshMap_.clear(); for(map>::iterator it = vtkVisZoneGlyphMap_.begin(); it != vtkVisZoneGlyphMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneGlyphMap_.clear(); for (int i = 0; i < MeshVec_.size(); i ++) { for (int j = 0; j < MeshVec_.at(i)->GetZoneNumber(); j ++) { double* X; double* Y; double* Z; PointsDS* p = new PointsDS; p->SetPointNumber(initPointsData->GetPointNumber()); for (int k = 0; k < MeshVec_.at(i)->GetScalarName().size(); k ++) { if (MeshVec_.at(i)->GetScalarName().at(k) == dispNameVec.at(0)) { X = MeshVec_.at(i)->GetScalarData().at(j).at(k + 3); }else if (MeshVec_.at(i)->GetScalarName().at(k) == dispNameVec.at(1)) { Y = MeshVec_.at(i)->GetScalarData().at(j).at(k + 3); }else if (MeshVec_.at(i)->GetScalarName().at(k) == dispNameVec.at(2)) { Z = MeshVec_.at(i)->GetScalarData().at(j).at(k + 3); } } for (int k = 0; k < initPointsData->GetPointNumber(); k ++) { double xyz[3]; initPointsData->GetPoint(k, xyz); double x = xyz[0] + (factor*X[k]); double y = xyz[1] + (factor*Y[k]); double z = xyz[2] + (factor*Z[k]); p->SetPoint(k, x, y, z); } MeshVec_.at(i)->GetZoneMesh(j)->SetPoints(p); } } DisplayMesh(render_); HideAllActors(); DisplayMeshByIndex(0); animationWidget_->SlotStart(); render_->ZoomToExtents(); } /** * @brief refill mesh vector by type * * @param[in] int type, 0 is time step, 1 is modal step * @return * @author zhaoyu * @date 20230410 */ void ResultMeshManager::ChangeMeshType(int type) { if (meshType != type) { meshType = type; if (meshObj_) { //delete meshObj_; meshObj_ = NULL; } m_currId = -1; scalarIndex = -1; range_[0] = 0; range_[1] = 0; scalarLeave = 10; titleSize_ = 6; labelSize_ = 5; changeRangeFlag = false; surfaceHideFlag = true; displayType = -1; scaleFactor_ = 0.02; solveTimes_.clear(); zoneNameVec_.clear(); currShowZoneNameSet_.clear(); nameTypeMap_.clear(); showHideVec_.clear(); surfaceActorColor_.clear(); scalarName_.clear(); allZoneScalarName_.clear(); //vtk vis procs. for(map>::iterator it = vtkVisZoneMeshMap_.begin(); it != vtkVisZoneMeshMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneMeshMap_.clear(); for(map>::iterator it = vtkVisZoneUnShadeMeshMap_.begin(); it != vtkVisZoneUnShadeMeshMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneUnShadeMeshMap_.clear(); for(map>::iterator it = vtkVisZoneGlyphMap_.begin(); it != vtkVisZoneGlyphMap_.end(); ++it) { for(map::iterator itin = it->second.begin(); itin != it->second.end(); ++itin) { itin->second->Delete(); } it->second.clear(); } vtkVisZoneGlyphMap_.clear(); if (!unSliceVec_.empty()) { for (int i = 0; i < unSliceVec_.size(); i ++) { if(unSliceVec_.at(i) != NULL) { unSliceVec_.at(i)->Delete(); unSliceVec_.at(i) = NULL; } } unSliceVec_.clear(); } if (addDataSource_ != NULL) { delete addDataSource_; addDataSource_ = NULL; } if (currAddDataSource_ != NULL) { delete currAddDataSource_; currAddDataSource_ = NULL; } DeleteAllStream(); if (streamLine_ != NULL) { streamLine_->Delete(); streamLine_ = NULL; } if (xyplot2dSlice_ != NULL) { xyplot2dSlice_->Delete(); xyplot2dSlice_ = NULL; } surfaceActorColor_.push_back(0); surfaceActorColor_.push_back(0); surfaceActorColor_.push_back(1); surfaceActorTransparency_ = 1; // if (contourWidget_ != NULL) // { // contourWidget_->RestoreWidget(); // } // if (lineWidget_ != NULL) // { // lineWidget_->RestoreWidget(); // } // if (vectorWidget_ != NULL) // { // vectorWidget_->RestoreWidget(); // } // if (solidSurfaceW_ != NULL) // { // solidSurfaceW_->RestoreWidget(); // } // if (sliceW_ != NULL) // { // sliceW_->RestoreWidget(); // } // if (streamW_ != NULL) // { // streamW_->RestoreWidget(); // } // if (xyplot2dW_ != NULL) // { // xyplot2dW_->RestoreWidget(); // } render_->HideAllActors(); if (type == 0) { MeshVec_ = TimeMeshVec_; DisplayMesh(render_); HideAllActors(); ShowAll(); DisplayMeshByIndex(0); SetNameTypeMap(); InitWidgetsParameter(); animationWidget_->SlotStart(); animationWidget_->InitScaleFactor(); render_->ZoomToExtents(); }else if (type == 1) { MeshVec_ = ModalMeshVec_; DisplayMesh(render_); HideAllActors(); ShowAll(); DisplayMeshByIndex(0); SetNameTypeMap(); InitWidgetsParameter(); animationWidget_->SlotStart(); animationWidget_->InitScaleFactor(); render_->ZoomToExtents(); } } } /** * @brief display select zone to slice * * @param[in] int meshindex, int scalarindex, int normalIndex * @return * @author zhaoyu * @date 20230411 */ void ResultMeshManager::DisplayXyplot2dSlice(int meshIndex, int sIndex) { if (render_ == NULL) { return; } if (xyplot2dSlice_ != NULL) { xyplot2dSlice_->Delete(); xyplot2dSlice_ = NULL; } if (meshObj_ == 0) return; int num = 0; double time = 0.0; for(set::iterator it = solveTimes_.begin(); it != solveTimes_.end(); it ++) { if (num == m_currId) { time = *it; break; } num ++; } vtkVISUnstructuredGridSource* source = NULL; map>::iterator it = vtkVisZoneMeshMap_.find(time); if (it != vtkVisZoneMeshMap_.end()) { map::iterator it2= it->second.find(zoneNameVec_.at(meshIndex)); if (it2 != it->second.end()) { source = it2->second->GetDatSource(); } } if (source == NULL) { cout << "source data error" << endl; return; } vtkVISUnSlice* unSlice_ = vtkVISUnSlice::New(); unSlice_->SetRenderTo(render_->GetRenderer()); string name = GetMeshScalarNameVec().at(sIndex); unSlice_->SetDataSource(source); char* s = (char*)(name.c_str()); char* v = NULL; unSlice_->SetSliceSource_FD(s, v); unSlice_->CreatUnShadeMeshDisplay(); unSlice_->CreateSliceWidget_FD(); unSlice_->CreateUnSliceContourDisplay_FD(); unSlice_->CreateUnSliceContourLinesDisplay_FD(); unSlice_->ShowOffUnSliceContourLinesDisplay(); unSlice_->CreateUnSliceContourLinesLabelDisplay_FD(); unSlice_->ShowOffUnSliceContourLinesLabelDisplay(); xyplot2dSlice_ = unSlice_; render_->ZoomToExtents(); } /** * @brief get xyplot 2d unslice position * * @param[in] * @return * @author zhaoyu * @date 20230411 */ vector ResultMeshManager::GetXyplot2dUnslicePosition() { double* data2; vector origin; if (xyplot2dSlice_ != NULL) { data2 = xyplot2dSlice_->GetSlicePlaneOrigin(); origin.push_back(data2[0]); origin.push_back(data2[1]); origin.push_back(data2[2]); }else { origin.push_back(0); origin.push_back(0); origin.push_back(0); } return origin; } /** * @brief set xyplot 2d unslice normal * * @param[in] int normal index * @return * @author zhaoyu * @date 20230411 */ void ResultMeshManager::SetXyplot2dSliceNormal(int normalIndex) { if (xyplot2dSlice_ != NULL) { if (normalIndex == 0) { xyplot2dSlice_->SetSlicePlaneNormalToX(); }else if (normalIndex == 1) { xyplot2dSlice_->SetSlicePlaneNormalToY(); }else if (normalIndex == 2) { xyplot2dSlice_->SetSlicePlaneNormalToZ(); } } render_->Update(); } /** * @brief set xyplot 2d unslice scalar index * * @param[in] int scalar index * @return * @author zhaoyu * @date 20230411 */ void ResultMeshManager::SetXyplot2dSliceScalarIndex(int index) { if (xyplot2dSlice_ != NULL) { string name = GetMeshScalarNameVec().at(index); char* s = (char*)(name.c_str()); xyplot2dSlice_->ModifySliceSourceScalar_FD(s); } render_->Update(); } /** * @brief Hide xyplot 2d unslice * * @param[in] * @return * @author zhaoyu * @date 20230411 */ void ResultMeshManager::HideXyplot2dSliceActors() { if (xyplot2dSlice_ != NULL) { xyplot2dSlice_->ShowOffSlicePlane(); xyplot2dSlice_->ShowOffSlicePlaneWidget(); xyplot2dSlice_->ShowOffUnShadeMesh(); xyplot2dSlice_->ShowOffUnSliceMesh(); xyplot2dSlice_->ShowOffUnSliceShade(); xyplot2dSlice_->ShowOffCutActor(); } } void ResultMeshManager::GetExportPictures(QString file) { } /** * @brief set xyplot2d unslice position * * @param[in] vector p * @return * @author zhaoyu * @date 20230411 */ void ResultMeshManager::SetXyplot2dSlicePosition(vector p) { if (xyplot2dSlice_ != NULL) { xyplot2dSlice_->SetSlicePlaneOrigin(p[0], p[1], p[2]); } render_->Update(); } /* * @brief: get private scalar name * @param: void * @ret: scalarName * @birth: created by czm in 20230421 */ string ResultMeshManager::getScalarName() { return this->scalarName_; } /* * @brief: get private range * @param: void * @ret: range * @birth: created by czm in 20230421 */ double *ResultMeshManager::getRange() { return this->range_; } /* * @brief: get private meshobj_ * @param: void * @ret: meshobj_ * @birth: created by czm in 20230421 */ Mesh *ResultMeshManager::getMeshObj_() { return this->meshObj_; } void ResultMeshManager::create_streamTrace(double x, double y, double z) { if(streamLine_!=NULL){ streamLine_->SetStreamLineStartPosition(x,y,z); streamLine_->CreateOneStreamLine(); } } /** * @brief get xyplot2d unslice data * * @param[in] * @return x1 value1 x2 value2 * @author zhaoyu * @date 20230411 */ //vector> ResultMeshManager::GetXyplot2dUnsliceData() //{ // vector> xyplot2dVec; // string xName; // string yName; // yName = GetMeshScalarNameVec().at(xyplot2dW_->GetYName()); // vector> totalVector; // totalVector.clear(); // if (xyplot2dSlice_ != NULL) // { // vector vec; // vec = xyplot2dSlice_->GetSliceData(); // string xAxis = xyplot2dW_->GetXAxis(); // double range[2]; // double middle = 0; // int normalIndex = xyplot2dW_->GetNormalIndex(); // int referenceIndex; // vector x1; // vector value1; // vector x2; // vector value2; // if (xAxis == "X") // { // xName = "X"; // if (xyplot2dW_->GetNormalIndex() == 1) // { // vec.at(0)->GetRange(range, 2); // referenceIndex = 2; // middle = (range[0] + range[1])/2.0; // }else if (xyplot2dW_->GetNormalIndex() == 2) // { // vec.at(0)->GetRange(range, 1); // referenceIndex = 1; // middle = (range[0] + range[1])/2.0; // } // for (int i = 0; i < vec.at(0)->GetNumberOfTuples(); i ++) // { // double reference = vec.at(0)->GetTuple(i)[referenceIndex]; // if (reference < middle || reference == middle) // { // x1.push_back(vec.at(0)->GetTuple(i)[0]); // value1.push_back(vec.at(1)->GetValue(i)); // }else // { // x2.push_back(vec.at(0)->GetTuple(i)[0]); // value2.push_back(vec.at(1)->GetValue(i)); // } // } // }else if (xAxis == "Y") // { // xName = "Y"; // if (xyplot2dW_->GetNormalIndex() == 0) // { // vec.at(0)->GetRange(range, 2); // referenceIndex = 2; // middle = (range[0] + range[1])/2.0; // }else if (xyplot2dW_->GetNormalIndex() == 2) // { // vec.at(0)->GetRange(range, 0); // referenceIndex = 0; // middle = (range[0] + range[1])/2.0; // } // for (int i = 0; i < vec.at(0)->GetNumberOfTuples(); i ++) // { // double reference = vec.at(0)->GetTuple(i)[referenceIndex]; // if (reference < middle || reference == middle) // { // x1.push_back(vec.at(0)->GetTuple(i)[1]); // value1.push_back(vec.at(1)->GetValue(i)); // }else // { // x2.push_back(vec.at(0)->GetTuple(i)[1]); // value2.push_back(vec.at(1)->GetValue(i)); // } // } // }else if (xAxis == "Z") // { // xName = "Z"; // if (xyplot2dW_->GetNormalIndex() == 0) // { // vec.at(0)->GetRange(range, 1); // referenceIndex = 1; // middle = (range[0] + range[1])/2.0; // }else if (xyplot2dW_->GetNormalIndex() == 1) // { // vec.at(0)->GetRange(range, 0); // referenceIndex = 0; // middle = (range[0] + range[1])/2.0; // } // for (int i = 0; i < vec.at(0)->GetNumberOfTuples(); i ++) // { // double reference = vec.at(0)->GetTuple(i)[referenceIndex]; // if (reference < middle || reference == middle) // { // x1.push_back(vec.at(0)->GetTuple(i)[2]); // value1.push_back(vec.at(1)->GetValue(i)); // }else // { // x2.push_back(vec.at(0)->GetTuple(i)[2]); // value2.push_back(vec.at(1)->GetValue(i)); // } // } // } // totalVector.push_back(x1); // totalVector.push_back(value1); // totalVector.push_back(x2); // totalVector.push_back(value2); // } // return totalVector; //} /** * @brief get xyplot2d axis name * * @param[in] * @return xName and yName * @author zhaoyu * @date 20230414 */ //vector ResultMeshManager::GetXyplot2dAxisName() //{ // vector xyplotwdNameVec; // xyplotwdNameVec.clear(); // string xAxis = "X"; // string yName = "Y"; // if (xyplot2dSlice_ != NULL) // { // xAxis = xyplot2dW_->GetXAxis(); // yName; // yName = GetMeshScalarNameVec().at(xyplot2dW_->GetYName()); // } // xyplotwdNameVec.push_back(xAxis); // xyplotwdNameVec.push_back(yName); // return xyplotwdNameVec; //} /** * @brief get qvtkrenderer * * @param[in] * @return QVTKRenderer *render_ * @author zhaoyu * @date 20230417 */ QVTKRenderer *ResultMeshManager::GetQVtkRender() { return render_; } /* * @brief: remove string's spaces * @param: string * @ret: string * @birth: created by czm in 20230504 */ string ResultMeshManager::deleteSpaces(string str) { QChar h0 = 0x00; QString str_; if(QString::fromStdString(str).contains(h0)){ str_=QString::fromStdString(str).replace(h0,""); } return str_.toStdString(); }