master
lanxingxing 2024-08-31 12:05:45 +08:00
parent 0d72b07729
commit 1e39f4e01b
11 changed files with 170 additions and 13 deletions

View File

@ -248,6 +248,11 @@ void BoundarySetting::setBoundarySettingStatus(int type)
m_picker->setSelectModel(type); m_picker->setSelectModel(type);
} }
void BoundarySetting::set3DType(bool is3DType)
{
m_picker->set3DType(is3DType);
}
int BoundarySetting::getFaceNum() int BoundarySetting::getFaceNum()
{ {
return m_faceNum; return m_faceNum;

View File

@ -134,6 +134,9 @@ public:
int getFaceIdToGridId(int id); int getFaceIdToGridId(int id);
int getPointIdToGridId(int id); int getPointIdToGridId(int id);
vtkSmartPointer<vtkActor> getPointActor(); vtkSmartPointer<vtkActor> getPointActor();
//false 2D true 3D
void set3DType(bool is3DType);
//GridPoint //GridPoint
//0-ux,1-uy,2-uz //0-ux,1-uy,2-uz

View File

@ -91,6 +91,9 @@ void DisplacementLimitSettingWidget::showEvent(QShowEvent *event)
m_boundarySetting->setStructure(m_preProcessingService->getGridStructure(),m_preProcessingService->getPointStructure()); m_boundarySetting->setStructure(m_preProcessingService->getGridStructure(),m_preProcessingService->getPointStructure());
m_boundarySetting->setFaceToPoint(m_preProcessingService->getFaceToPoint()); m_boundarySetting->setFaceToPoint(m_preProcessingService->getFaceToPoint());
m_boundarySetting->set3DType(m_preProcessingService->is3DType());
m_visualWidgetService->addActor(m_preProcessingService->getPointActor()); m_visualWidgetService->addActor(m_preProcessingService->getPointActor());
m_sphereSource = m_preProcessingService->getSphereSource(); m_sphereSource = m_preProcessingService->getSphereSource();

View File

@ -104,6 +104,7 @@ void DistributedLoadSettingWidget::showEvent(QShowEvent *event)
} }
qDebug()<<QStringLiteral("开始设置均布载荷"); qDebug()<<QStringLiteral("开始设置均布载荷");
//----------------------更新颜色 //----------------------更新颜色
@ -112,6 +113,9 @@ void DistributedLoadSettingWidget::showEvent(QShowEvent *event)
m_boundarySetting->setCellToGridMap(m_preProcessingService->getCellIdToGridIdMap()); m_boundarySetting->setCellToGridMap(m_preProcessingService->getCellIdToGridIdMap());
m_boundarySetting->setBoundarySettingStatus(2); m_boundarySetting->setBoundarySettingStatus(2);
//3D 1 2D 2
m_boundarySetting->set3DType(m_preProcessingService->is3DType());
ui->comboBox->clear(); ui->comboBox->clear();
for(int i=1;i<m_preProcessingService->getFaceToCell().size();i++) for(int i=1;i<m_preProcessingService->getFaceToCell().size();i++)
@ -121,7 +125,7 @@ void DistributedLoadSettingWidget::showEvent(QShowEvent *event)
// connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onBoxIndexChanged(int))); // connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onBoxIndexChanged(int)));
ui->allShowRadio->setChecked(true); // 再次选中 ui->allShowRadio->setChecked(true); // 再次选中
ui->allShowRadio->toggled(true); ui->allShowRadio->toggled(true);
ui->clickSelectionCheckBox->setChecked(true); ui->clickSelectionCheckBox->setChecked(true);
} }

View File

@ -16,6 +16,7 @@
#include<vtkDataSetMapper.h> #include<vtkDataSetMapper.h>
#include <QToolButton> #include <QToolButton>
#include <vtkCellPicker.h> #include <vtkCellPicker.h>
#include <vtkPointPicker.h>
#include <vtkVertexGlyphFilter.h> #include <vtkVertexGlyphFilter.h>
#include <vtkSphereSource.h> #include <vtkSphereSource.h>
#include <set> #include <set>
@ -50,6 +51,7 @@ PropPickerInteractionStyle::PropPickerInteractionStyle(BoundarySetting *boundary
{ {
m_boundarySetting = boundarySetting; m_boundarySetting = boundarySetting;
m_visualWidgetService = ServiceRegistry<VisualWidgetService>::instance().getService(); m_visualWidgetService = ServiceRegistry<VisualWidgetService>::instance().getService();
m_is3DType = true;
} }
void PropPickerInteractionStyle::Execute(vtkObject *caller, unsigned long eventId, void *callData) void PropPickerInteractionStyle::Execute(vtkObject *caller, unsigned long eventId, void *callData)
@ -120,6 +122,11 @@ void PropPickerInteractionStyle::clearSelectedFace()
m_selectedFace.clear(); m_selectedFace.clear();
} }
void PropPickerInteractionStyle::set3DType(bool is3DType)
{
m_is3DType = is3DType;
}
void PropPickerInteractionStyle::setPointColor(QSet<int>point,double color[3]) void PropPickerInteractionStyle::setPointColor(QSet<int>point,double color[3])
{ {
vtkDataArray *pointColor = m_boundarySetting->getPointStructure()->GetPointData()->GetScalars(); vtkDataArray *pointColor = m_boundarySetting->getPointStructure()->GetPointData()->GetScalars();
@ -188,15 +195,25 @@ void PropPickerInteractionStyle::clearPointColor()
void PropPickerInteractionStyle::clearFaceColor() void PropPickerInteractionStyle::clearFaceColor()
{ {
vtkDataArray *faceColor = m_boundarySetting->getCellStructure()->GetCellData()->GetScalars(); vtkDataArray *faceColor = m_boundarySetting->getCellStructure()->GetCellData()->GetScalars();
faceColor->FillComponent(0, 255); if(m_is3DType)
faceColor->FillComponent(1, 255); {
faceColor->FillComponent(2, 255); 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(); faceColor->Modified();
m_visualWidgetService->getrenderWindow()->Render(); m_visualWidgetService->getrenderWindow()->Render();
} }
void PropPickerInteractionStyle::selectGridNode(vtkObject *caller, unsigned long eventId, void *callData) void PropPickerInteractionStyle::selectGridNode(vtkObject *caller, unsigned long eventId, void *callData)
{ {
if(m_is3DType==0){
vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::SafeDownCast(caller); vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::SafeDownCast(caller);
if (!interactor) if (!interactor)
return; return;
@ -278,6 +295,69 @@ void PropPickerInteractionStyle::selectGridNode(vtkObject *caller, unsigned long
m_boundarySetting->showPointData(closestPointIdInPolyData); m_boundarySetting->showPointData(closestPointIdInPolyData);
} }
}}
else{
vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::SafeDownCast(caller);
if (!interactor)
return;
// ??????????
int* clickPos = interactor->GetEventPosition();
// ??
vtkSmartPointer<vtkPointPicker> picker = vtkSmartPointer<vtkPointPicker>::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"<<std::endl;
qDebug()<<"cellid "<<(int)(closestPointIdInPolyData);
//qDebug()<<"cellid "<<cellId;
//if (cellId != -1) {
if (closestPointIdInPolyData != -1) {
double closestPoint[3];
polyData->GetPoints()->GetPoint(closestPointIdInPolyData, closestPoint);
qDebug() <<"point: "<<closestPointIdInPolyData+1;
qDebug() << "Closest point coordinates: ("
<< closestPoint[0] << ", "
<< closestPoint[1] << ", "
<< closestPoint[2] << ")";
vtkDataArray *pointColor = polyData->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 //?????? else //??????
{ {
cellcolor->SetComponent(cellId, 0, 255); if(m_is3DType)
cellcolor->SetComponent(cellId, 1, 255); {
cellcolor->SetComponent(cellId, 2, 255); 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(); cellcolor->Modified();
} }
} }

View File

@ -39,6 +39,7 @@ public:
void faceRefresh(); void faceRefresh();
void setFaceColor(int faceId, double color[]); void setFaceColor(int faceId, double color[]);
void addSelectedFace(int faceId); void addSelectedFace(int faceId);
void set3DType(bool is3DType);
private: private:
void selectGridNode(vtkObject *caller, unsigned long eventId, void *callData); void selectGridNode(vtkObject *caller, unsigned long eventId, void *callData);
void selectGridFace(vtkObject *caller, unsigned long eventId, void *callData); void selectGridFace(vtkObject *caller, unsigned long eventId, void *callData);
@ -47,6 +48,8 @@ private:
QSet<int>m_selectedPoint; QSet<int>m_selectedPoint;
QSet<int>m_selectedFace; QSet<int>m_selectedFace;
VisualWidgetService *m_visualWidgetService; VisualWidgetService *m_visualWidgetService;
bool m_is3DType;
}; };
#endif // PROPPICKERINTERACTIONSTYLE_H #endif // PROPPICKERINTERACTIONSTYLE_H

View File

@ -310,6 +310,13 @@ bool PreProcessing::isHaveStructured()
return false; return false;
} }
bool PreProcessing::is3DType()
{
if(m_modelType == 1)
return false;
else
return true;
}
vtkSmartPointer<vtkUnstructuredGrid> PreProcessing::getPointStructure() vtkSmartPointer<vtkUnstructuredGrid> PreProcessing::getPointStructure()
{ {
@ -1067,6 +1074,7 @@ void PreProcessing::generateGrid(float maxgrid)
read->genProcess(); read->genProcess();
m_gridStructure = read->getStructure(); m_gridStructure = read->getStructure();
m_gridStructure_origin = read->getStructureOrigin();
m_pointStructure = vtkSmartPointer<vtkUnstructuredGrid>::New(); m_pointStructure = vtkSmartPointer<vtkUnstructuredGrid>::New();
m_pointStructure->DeepCopy(m_gridStructure); m_pointStructure->DeepCopy(m_gridStructure);
@ -1079,22 +1087,52 @@ void PreProcessing::generateGrid(float maxgrid)
//------------------------------------整体 //------------------------------------整体
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputData(m_gridStructure); mapper->SetInputData(m_gridStructure);
mapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(-500.0,-500.0);
mapper->SetRelativeCoincidentTopologyLineOffsetParameters(-500.0,-500.0);
mapper->SetRelativeCoincidentTopologyPointOffsetParameter(-500.0);
//设置颜色 //设置颜色
vtkDataArray *cellcolor = vtkUnsignedCharArray::New(); vtkDataArray *cellcolor = vtkUnsignedCharArray::New();
cellcolor->SetNumberOfComponents(3); cellcolor->SetNumberOfComponents(3);
//m_gridStructure->GetCellData()->SetScalars(cellcolor);
m_gridStructure->GetCellData()->SetScalars(cellcolor); m_gridStructure->GetCellData()->SetScalars(cellcolor);
cellcolor->SetNumberOfTuples(m_gridStructure->GetNumberOfCells()); cellcolor->SetNumberOfTuples(m_gridStructure->GetNumberOfCells());
cellcolor->FillComponent(0, 255); cellcolor->FillComponent(0, 0);
cellcolor->FillComponent(1, 0); cellcolor->FillComponent(1, 0);
cellcolor->FillComponent(2, 0); cellcolor->FillComponent(2, 0);
m_cellActor = vtkSmartPointer<vtkActor>::New(); m_cellActor = vtkSmartPointer<vtkActor>::New();
m_cellActor->SetMapper(mapper); m_cellActor->SetMapper(mapper);
m_cellActor->GetProperty()->EdgeVisibilityOn(); m_cellActor->GetProperty()->EdgeVisibilityOn();
m_cellActor->GetProperty()->SetLineWidth(5);
//m_cellActor->SetPickable(false);
vtkSmartPointer<vtkDataSetMapper> mapper2 = vtkSmartPointer<vtkDataSetMapper>::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<vtkActor>::New();
m_cellActor2->SetMapper(mapper2);
m_cellActor2->GetProperty()->EdgeVisibilityOn();
m_cellActor2->SetPickable(false);
m_visualWidgetService->removeAllActor(); m_visualWidgetService->removeAllActor();
m_visualWidgetService->addActor(m_cellActor); m_visualWidgetService->addActor(m_cellActor);
m_visualWidgetService->addActor(m_cellActor2);
m_visualWidgetService->getRender()->ResetCamera(); m_visualWidgetService->getRender()->ResetCamera();
m_visualWidgetService->getrenderWindow()->Render(); m_visualWidgetService->getrenderWindow()->Render();
@ -1112,11 +1150,14 @@ void PreProcessing::generateGrid(float maxgrid)
glyphMapper->SetInputConnection(glyphFilter->GetOutputPort()); glyphMapper->SetInputConnection(glyphFilter->GetOutputPort());
glyphMapper->ScalarVisibilityOn(); // Ensure colors are visible glyphMapper->ScalarVisibilityOn(); // Ensure colors are visible
glyphMapper->SetScalarModeToUsePointData(); glyphMapper->SetScalarModeToUsePointData();
glyphMapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(-3000.0,-3000.0);
glyphMapper->SetRelativeCoincidentTopologyLineOffsetParameters(-3000.0,-3000.0);
glyphMapper->SetRelativeCoincidentTopologyPointOffsetParameter(-3000.0);
m_pointActor = vtkSmartPointer<vtkActor>::New(); m_pointActor = vtkSmartPointer<vtkActor>::New();
m_pointActor->SetMapper(glyphMapper); m_pointActor->SetMapper(glyphMapper);
m_pointActor->SetPickable(false); m_pointActor->SetPickable(false);
//设置点颜色 //设置点颜色

View File

@ -47,6 +47,7 @@ public:
void importGrid(QString fileName); void importGrid(QString fileName);
vtkSmartPointer<vtkUnstructuredGrid> getGridStructure(); vtkSmartPointer<vtkUnstructuredGrid> getGridStructure();
vtkSmartPointer<vtkUnstructuredGrid> getGridStructureOrigin();
vtkSmartPointer<vtkUnstructuredGrid> getPointStructure(); vtkSmartPointer<vtkUnstructuredGrid> getPointStructure();
QVector<QSet<int> > getFaceToPoint(); QVector<QSet<int> > getFaceToPoint();
QVector<QVector<int> > getFaceToCell(); QVector<QVector<int> > getFaceToCell();
@ -54,6 +55,7 @@ public:
QMap<int, int> getCellIdToGridIdMap(); QMap<int, int> getCellIdToGridIdMap();
vtkSmartPointer<vtkSphereSource> getSphereSource(); vtkSmartPointer<vtkSphereSource> getSphereSource();
bool isHaveStructured(); bool isHaveStructured();
bool is3DType();
private: private:
bool buildquad(ifstream &elements, vtkSmartPointer<vtkCellArray> cells); bool buildquad(ifstream &elements, vtkSmartPointer<vtkCellArray> cells);
bool buildcells(ifstream &elements, vtkSmartPointer<vtkCellArray> cells, int state, vtkSmartPointer<vtkUnstructuredGrid> Grid); bool buildcells(ifstream &elements, vtkSmartPointer<vtkCellArray> cells, int state, vtkSmartPointer<vtkUnstructuredGrid> Grid);
@ -78,17 +80,16 @@ private:
vtkSmartPointer<vtkUnstructuredGrid> m_gridStructure; vtkSmartPointer<vtkUnstructuredGrid> m_gridStructure;
vtkSmartPointer<vtkUnstructuredGrid> m_gridStructure_origin;
vtkSmartPointer<vtkUnstructuredGrid> m_pointStructure; vtkSmartPointer<vtkUnstructuredGrid> m_pointStructure;
vtkSmartPointer<vtkActor> m_pointActor; vtkSmartPointer<vtkActor> m_pointActor;
vtkSmartPointer<vtkSphereSource> m_sphereSource; vtkSmartPointer<vtkSphereSource> m_sphereSource;
vtkSmartPointer<vtkActor> m_cellActor; vtkSmartPointer<vtkActor> m_cellActor;
vtkSmartPointer<vtkActor> m_cellActor2;
int m_modelType; int m_modelType;
int m_status; int m_status;
float m_x,m_y,m_z; float m_x,m_y,m_z;
float m_ox,m_oy,m_oz; float m_ox,m_oy,m_oz;
QMap<vtkSmartPointer<vtkActor>,QString>m_map; QMap<vtkSmartPointer<vtkActor>,QString>m_map;

View File

@ -714,6 +714,11 @@ vtkSmartPointer<vtkUnstructuredGrid> gen2DGrid::getStructure()
return m_grid_surface; return m_grid_surface;
} }
vtkSmartPointer<vtkUnstructuredGrid> gen2DGrid::getStructureOrigin()
{
return m_grid;
}
QVector<QSet<int>> gen2DGrid::getFaceToPoint() QVector<QSet<int>> gen2DGrid::getFaceToPoint()
{ {
return m_faceToPoint; return m_faceToPoint;

View File

@ -134,6 +134,7 @@ public:
QVector<QVector<int> > getFaceToCell(); QVector<QVector<int> > getFaceToCell();
QMap<int, int> getCellIdToGridIdMap(); QMap<int, int> getCellIdToGridIdMap();
vtkSmartPointer<vtkUnstructuredGrid> getStructure(); vtkSmartPointer<vtkUnstructuredGrid> getStructure();
vtkSmartPointer<vtkUnstructuredGrid> getStructureOrigin();
}; };

View File

@ -14,6 +14,7 @@ struct PreProcessingService
{ {
virtual vtkSmartPointer<vtkUnstructuredGrid> getGridStructure() = 0; virtual vtkSmartPointer<vtkUnstructuredGrid> getGridStructure() = 0;
virtual vtkSmartPointer<vtkUnstructuredGrid> getPointStructure() = 0; virtual vtkSmartPointer<vtkUnstructuredGrid> getPointStructure() = 0;
virtual bool is3DType() = 0;
virtual QVector<QSet<int> > getFaceToPoint() = 0; virtual QVector<QSet<int> > getFaceToPoint() = 0;
virtual QVector<QVector<int> > getFaceToCell() = 0; virtual QVector<QVector<int> > getFaceToCell() = 0;
virtual vtkSmartPointer<vtkActor> getPointActor() = 0; virtual vtkSmartPointer<vtkActor> getPointActor() = 0;