From 1e39f4e01b7103bbc1458cbdb94f4451bb14653c Mon Sep 17 00:00:00 2001 From: lanxingxing <14605265+lanxingxing16@user.noreply.gitee.com> Date: Sat, 31 Aug 2024 12:05:45 +0800 Subject: [PATCH] pre --- plugins/CA_PhysicalField/BoundarySetting.cpp | 5 + plugins/CA_PhysicalField/BoundarySetting.h | 3 + .../DisplacementLimitSettingWidget.cpp | 3 + .../DistributedLoadSettingWidget.cpp | 6 +- .../PropPickerInteractionStyle.cpp | 102 ++++++++++++++++-- .../PropPickerInteractionStyle.h | 3 + plugins/CA_PreProcessing/PreProcessing.cpp | 47 +++++++- plugins/CA_PreProcessing/PreProcessing.h | 7 +- .../CA_PreProcessing/processor/gen2DGrid.cpp | 5 + .../CA_PreProcessing/processor/gen2DGrid.h | 1 + public/services/PreProcessingService.h | 1 + 11 files changed, 170 insertions(+), 13 deletions(-) diff --git a/plugins/CA_PhysicalField/BoundarySetting.cpp b/plugins/CA_PhysicalField/BoundarySetting.cpp index bbe65f8..e5e8f7a 100644 --- a/plugins/CA_PhysicalField/BoundarySetting.cpp +++ b/plugins/CA_PhysicalField/BoundarySetting.cpp @@ -248,6 +248,11 @@ void BoundarySetting::setBoundarySettingStatus(int type) m_picker->setSelectModel(type); } +void BoundarySetting::set3DType(bool is3DType) +{ + m_picker->set3DType(is3DType); +} + int BoundarySetting::getFaceNum() { return m_faceNum; diff --git a/plugins/CA_PhysicalField/BoundarySetting.h b/plugins/CA_PhysicalField/BoundarySetting.h index a43746f..d707845 100644 --- a/plugins/CA_PhysicalField/BoundarySetting.h +++ b/plugins/CA_PhysicalField/BoundarySetting.h @@ -134,6 +134,9 @@ public: int getFaceIdToGridId(int id); int getPointIdToGridId(int id); vtkSmartPointer getPointActor(); + + //false 2D true 3D + void set3DType(bool is3DType); //GridPoint //0-ux,1-uy,2-uz diff --git a/plugins/CA_PhysicalField/DisplacementLimitSettingWidget.cpp b/plugins/CA_PhysicalField/DisplacementLimitSettingWidget.cpp index 9e2bd1d..c6ca0a2 100644 --- a/plugins/CA_PhysicalField/DisplacementLimitSettingWidget.cpp +++ b/plugins/CA_PhysicalField/DisplacementLimitSettingWidget.cpp @@ -91,6 +91,9 @@ void DisplacementLimitSettingWidget::showEvent(QShowEvent *event) m_boundarySetting->setStructure(m_preProcessingService->getGridStructure(),m_preProcessingService->getPointStructure()); m_boundarySetting->setFaceToPoint(m_preProcessingService->getFaceToPoint()); + + m_boundarySetting->set3DType(m_preProcessingService->is3DType()); + m_visualWidgetService->addActor(m_preProcessingService->getPointActor()); m_sphereSource = m_preProcessingService->getSphereSource(); diff --git a/plugins/CA_PhysicalField/DistributedLoadSettingWidget.cpp b/plugins/CA_PhysicalField/DistributedLoadSettingWidget.cpp index f26b512..c1b995a 100644 --- a/plugins/CA_PhysicalField/DistributedLoadSettingWidget.cpp +++ b/plugins/CA_PhysicalField/DistributedLoadSettingWidget.cpp @@ -104,6 +104,7 @@ void DistributedLoadSettingWidget::showEvent(QShowEvent *event) } qDebug()<setCellToGridMap(m_preProcessingService->getCellIdToGridIdMap()); m_boundarySetting->setBoundarySettingStatus(2); + + //3D 1 2D 2 + m_boundarySetting->set3DType(m_preProcessingService->is3DType()); ui->comboBox->clear(); for(int i=1;igetFaceToCell().size();i++) @@ -121,7 +125,7 @@ void DistributedLoadSettingWidget::showEvent(QShowEvent *event) // connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onBoxIndexChanged(int))); ui->allShowRadio->setChecked(true); // 再次选中 ui->allShowRadio->toggled(true); - + ui->clickSelectionCheckBox->setChecked(true); } diff --git a/plugins/CA_PhysicalField/PropPickerInteractionStyle.cpp b/plugins/CA_PhysicalField/PropPickerInteractionStyle.cpp index dc7f788..c385d8b 100644 --- a/plugins/CA_PhysicalField/PropPickerInteractionStyle.cpp +++ b/plugins/CA_PhysicalField/PropPickerInteractionStyle.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ PropPickerInteractionStyle::PropPickerInteractionStyle(BoundarySetting *boundary { m_boundarySetting = boundarySetting; m_visualWidgetService = ServiceRegistry::instance().getService(); + m_is3DType = true; } void PropPickerInteractionStyle::Execute(vtkObject *caller, unsigned long eventId, void *callData) @@ -120,6 +122,11 @@ void PropPickerInteractionStyle::clearSelectedFace() m_selectedFace.clear(); } +void PropPickerInteractionStyle::set3DType(bool is3DType) +{ + m_is3DType = is3DType; +} + void PropPickerInteractionStyle::setPointColor(QSetpoint,double color[3]) { vtkDataArray *pointColor = m_boundarySetting->getPointStructure()->GetPointData()->GetScalars(); @@ -188,15 +195,25 @@ void PropPickerInteractionStyle::clearPointColor() void PropPickerInteractionStyle::clearFaceColor() { vtkDataArray *faceColor = m_boundarySetting->getCellStructure()->GetCellData()->GetScalars(); - faceColor->FillComponent(0, 255); - faceColor->FillComponent(1, 255); - faceColor->FillComponent(2, 255); + if(m_is3DType) + { + faceColor->FillComponent(0, 255); + faceColor->FillComponent(1, 255); + faceColor->FillComponent(2, 255); + } + else + { + faceColor->FillComponent(0, 0); + faceColor->FillComponent(1, 0); + faceColor->FillComponent(2, 0); + } faceColor->Modified(); m_visualWidgetService->getrenderWindow()->Render(); } void PropPickerInteractionStyle::selectGridNode(vtkObject *caller, unsigned long eventId, void *callData) { + if(m_is3DType==0){ vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::SafeDownCast(caller); if (!interactor) return; @@ -278,6 +295,69 @@ void PropPickerInteractionStyle::selectGridNode(vtkObject *caller, unsigned long m_boundarySetting->showPointData(closestPointIdInPolyData); } + }} + else{ + vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::SafeDownCast(caller); + if (!interactor) + return; + + // ?????????? + int* clickPos = interactor->GetEventPosition(); + + // ?? + vtkSmartPointer picker = vtkSmartPointer::New(); + picker->SetTolerance(0.001); + picker->Pick(clickPos[0], clickPos[1], 0, interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()); + + vtkUnstructuredGrid *polyData = m_boundarySetting->getPointStructure(); + vtkIdType closestPointIdInPolyData = picker->GetPointId(); + std::cout<<"111111111111111111111111111111"<GetPoints()->GetPoint(closestPointIdInPolyData, closestPoint); + qDebug() <<"point: "<GetPointData()->GetScalars(); + + //??????????????? + if(m_selectedPoint.contains(closestPointIdInPolyData)) + { + m_selectedPoint.remove(closestPointIdInPolyData); + if(m_boundarySetting->isSelectedPoint(closestPointIdInPolyData))//????? + { + pointColor->SetComponent(closestPointIdInPolyData, 0, 255); + pointColor->SetComponent(closestPointIdInPolyData, 1, 0); + pointColor->SetComponent(closestPointIdInPolyData, 2, 255); + pointColor->Modified(); + } + else //?????? + { + pointColor->SetComponent(closestPointIdInPolyData, 0, 255); + pointColor->SetComponent(closestPointIdInPolyData, 1, 255); + pointColor->SetComponent(closestPointIdInPolyData, 2, 255); + pointColor->Modified(); + } + } + else + { + m_selectedPoint.insert(closestPointIdInPolyData); + pointColor->SetComponent(closestPointIdInPolyData, 0, 255); + pointColor->SetComponent(closestPointIdInPolyData, 1, 0); + pointColor->SetComponent(closestPointIdInPolyData, 2, 0); + pointColor->Modified(); + } + + m_boundarySetting->showPointData(closestPointIdInPolyData); + //} + } } } @@ -329,9 +409,19 @@ void PropPickerInteractionStyle::selectGridFace(vtkObject *caller, unsigned long } else //?????? { - cellcolor->SetComponent(cellId, 0, 255); - cellcolor->SetComponent(cellId, 1, 255); - cellcolor->SetComponent(cellId, 2, 255); + if(m_is3DType) + { + cellcolor->SetComponent(cellId, 0, 255); + cellcolor->SetComponent(cellId, 1, 255); + cellcolor->SetComponent(cellId, 2, 255); + } + else + { + cellcolor->SetComponent(cellId, 0, 0); + cellcolor->SetComponent(cellId, 1, 0); + cellcolor->SetComponent(cellId, 2, 0); + } + cellcolor->Modified(); } } diff --git a/plugins/CA_PhysicalField/PropPickerInteractionStyle.h b/plugins/CA_PhysicalField/PropPickerInteractionStyle.h index 51526a5..710f2fe 100644 --- a/plugins/CA_PhysicalField/PropPickerInteractionStyle.h +++ b/plugins/CA_PhysicalField/PropPickerInteractionStyle.h @@ -39,6 +39,7 @@ public: void faceRefresh(); void setFaceColor(int faceId, double color[]); void addSelectedFace(int faceId); + void set3DType(bool is3DType); private: void selectGridNode(vtkObject *caller, unsigned long eventId, void *callData); void selectGridFace(vtkObject *caller, unsigned long eventId, void *callData); @@ -47,6 +48,8 @@ private: QSetm_selectedPoint; QSetm_selectedFace; VisualWidgetService *m_visualWidgetService; + + bool m_is3DType; }; #endif // PROPPICKERINTERACTIONSTYLE_H diff --git a/plugins/CA_PreProcessing/PreProcessing.cpp b/plugins/CA_PreProcessing/PreProcessing.cpp index 810306a..1f2c04e 100644 --- a/plugins/CA_PreProcessing/PreProcessing.cpp +++ b/plugins/CA_PreProcessing/PreProcessing.cpp @@ -310,6 +310,13 @@ bool PreProcessing::isHaveStructured() return false; } +bool PreProcessing::is3DType() +{ + if(m_modelType == 1) + return false; + else + return true; +} vtkSmartPointer PreProcessing::getPointStructure() { @@ -1067,6 +1074,7 @@ void PreProcessing::generateGrid(float maxgrid) read->genProcess(); m_gridStructure = read->getStructure(); + m_gridStructure_origin = read->getStructureOrigin(); m_pointStructure = vtkSmartPointer::New(); m_pointStructure->DeepCopy(m_gridStructure); @@ -1079,22 +1087,52 @@ void PreProcessing::generateGrid(float maxgrid) //------------------------------------整体 vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputData(m_gridStructure); + mapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(-500.0,-500.0); + mapper->SetRelativeCoincidentTopologyLineOffsetParameters(-500.0,-500.0); + mapper->SetRelativeCoincidentTopologyPointOffsetParameter(-500.0); //设置颜色 vtkDataArray *cellcolor = vtkUnsignedCharArray::New(); cellcolor->SetNumberOfComponents(3); + //m_gridStructure->GetCellData()->SetScalars(cellcolor); m_gridStructure->GetCellData()->SetScalars(cellcolor); cellcolor->SetNumberOfTuples(m_gridStructure->GetNumberOfCells()); - cellcolor->FillComponent(0, 255); + cellcolor->FillComponent(0, 0); cellcolor->FillComponent(1, 0); cellcolor->FillComponent(2, 0); m_cellActor = vtkSmartPointer::New(); m_cellActor->SetMapper(mapper); m_cellActor->GetProperty()->EdgeVisibilityOn(); + m_cellActor->GetProperty()->SetLineWidth(5); + //m_cellActor->SetPickable(false); + + + vtkSmartPointer mapper2 = vtkSmartPointer::New(); + mapper2->SetInputData(m_gridStructure_origin); + mapper2->SetRelativeCoincidentTopologyPolygonOffsetParameters(500.0,500.0); + mapper2->SetRelativeCoincidentTopologyLineOffsetParameters(500.0,500.0); + mapper2->SetRelativeCoincidentTopologyPointOffsetParameter(500.0); + + //设置颜色 + vtkDataArray *cellcolor2 = vtkUnsignedCharArray::New(); + cellcolor2->SetNumberOfComponents(3); + //m_gridStructure->GetCellData()->SetScalars(cellcolor); + m_gridStructure->GetCellData()->SetScalars(cellcolor); + cellcolor2->SetNumberOfTuples(m_gridStructure_origin->GetNumberOfCells()); + cellcolor2->FillComponent(0, 0); + cellcolor2->FillComponent(1, 0); + cellcolor2->FillComponent(2, 0); + + m_cellActor2 = vtkSmartPointer::New(); + m_cellActor2->SetMapper(mapper2); + m_cellActor2->GetProperty()->EdgeVisibilityOn(); + m_cellActor2->SetPickable(false); + m_visualWidgetService->removeAllActor(); m_visualWidgetService->addActor(m_cellActor); + m_visualWidgetService->addActor(m_cellActor2); m_visualWidgetService->getRender()->ResetCamera(); m_visualWidgetService->getrenderWindow()->Render(); @@ -1112,11 +1150,14 @@ void PreProcessing::generateGrid(float maxgrid) glyphMapper->SetInputConnection(glyphFilter->GetOutputPort()); glyphMapper->ScalarVisibilityOn(); // Ensure colors are visible glyphMapper->SetScalarModeToUsePointData(); + + glyphMapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(-3000.0,-3000.0); + glyphMapper->SetRelativeCoincidentTopologyLineOffsetParameters(-3000.0,-3000.0); + glyphMapper->SetRelativeCoincidentTopologyPointOffsetParameter(-3000.0); m_pointActor = vtkSmartPointer::New(); m_pointActor->SetMapper(glyphMapper); - - + m_pointActor->SetPickable(false); //设置点颜色 diff --git a/plugins/CA_PreProcessing/PreProcessing.h b/plugins/CA_PreProcessing/PreProcessing.h index 525c8a0..2deb31d 100644 --- a/plugins/CA_PreProcessing/PreProcessing.h +++ b/plugins/CA_PreProcessing/PreProcessing.h @@ -47,6 +47,7 @@ public: void importGrid(QString fileName); vtkSmartPointer getGridStructure(); + vtkSmartPointer getGridStructureOrigin(); vtkSmartPointer getPointStructure(); QVector > getFaceToPoint(); QVector > getFaceToCell(); @@ -54,6 +55,7 @@ public: QMap getCellIdToGridIdMap(); vtkSmartPointer getSphereSource(); bool isHaveStructured(); + bool is3DType(); private: bool buildquad(ifstream &elements, vtkSmartPointer cells); bool buildcells(ifstream &elements, vtkSmartPointer cells, int state, vtkSmartPointer Grid); @@ -78,17 +80,16 @@ private: vtkSmartPointer m_gridStructure; + vtkSmartPointer m_gridStructure_origin; vtkSmartPointer m_pointStructure; vtkSmartPointer m_pointActor; vtkSmartPointer m_sphereSource; vtkSmartPointer m_cellActor; + vtkSmartPointer m_cellActor2; int m_modelType; int m_status; - - - float m_x,m_y,m_z; float m_ox,m_oy,m_oz; QMap,QString>m_map; diff --git a/plugins/CA_PreProcessing/processor/gen2DGrid.cpp b/plugins/CA_PreProcessing/processor/gen2DGrid.cpp index 75b43ee..614e720 100644 --- a/plugins/CA_PreProcessing/processor/gen2DGrid.cpp +++ b/plugins/CA_PreProcessing/processor/gen2DGrid.cpp @@ -714,6 +714,11 @@ vtkSmartPointer gen2DGrid::getStructure() return m_grid_surface; } +vtkSmartPointer gen2DGrid::getStructureOrigin() +{ + return m_grid; +} + QVector> gen2DGrid::getFaceToPoint() { return m_faceToPoint; diff --git a/plugins/CA_PreProcessing/processor/gen2DGrid.h b/plugins/CA_PreProcessing/processor/gen2DGrid.h index db99d3d..5eeeb19 100644 --- a/plugins/CA_PreProcessing/processor/gen2DGrid.h +++ b/plugins/CA_PreProcessing/processor/gen2DGrid.h @@ -134,6 +134,7 @@ public: QVector > getFaceToCell(); QMap getCellIdToGridIdMap(); vtkSmartPointer getStructure(); + vtkSmartPointer getStructureOrigin(); }; diff --git a/public/services/PreProcessingService.h b/public/services/PreProcessingService.h index cbd9e1e..3a4b17d 100644 --- a/public/services/PreProcessingService.h +++ b/public/services/PreProcessingService.h @@ -14,6 +14,7 @@ struct PreProcessingService { virtual vtkSmartPointer getGridStructure() = 0; virtual vtkSmartPointer getPointStructure() = 0; + virtual bool is3DType() = 0; virtual QVector > getFaceToPoint() = 0; virtual QVector > getFaceToCell() = 0; virtual vtkSmartPointer getPointActor() = 0;