From 4f2eb9e4a1264338068e8e3434a8d4cb85c2ecbd Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 13 Feb 2009 18:16:56 +0000 Subject: [PATCH] Fix for bug 0020121: EDF VISU 924: Gauss View + Deformed Shape + Picking + Display parent mesh element. --- src/OBJECT/VISU_GaussPtsAct.cxx | 126 ++++++++++++++++++++++++- src/OBJECT/VISU_GaussPtsAct.h | 6 ++ src/VISUGUI/VisuGUI_GaussPointsDlg.cxx | 4 + 3 files changed, 134 insertions(+), 2 deletions(-) diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 2653e428..8238406e 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -68,6 +69,8 @@ #include #include #include +#include +#include #include #include @@ -133,7 +136,9 @@ VISU_GaussPtsAct myPickingSettings(NULL), myInsideCursorSettings(NULL), myCurrentPL(NULL), - myMapper(vtkPolyDataMapper::New()) + myMapper(vtkPolyDataMapper::New()), + myWarpVector(vtkWarpVector::New()), + myCellDataToPointData(vtkCellDataToPointData::New()) { if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<Delete(); aMatrix->Delete(); + + myWarpVector->Delete(); + myCellDataToPointData->Delete(); } VISU_GaussPtsAct @@ -1121,12 +1129,126 @@ VISU_GaussPtsAct myCellSource->Reset(); myCellSource->Modified(); // a VTK bug vtkUnstructuredGrid* aDataSet = aParent->GetUnstructuredGridOutput(); - myCellSource->SetPoints(aDataSet->GetPoints()); VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId); vtkIdType aCellID = aGaussPointID.first; vtkCell* aCell = aParent->GetElemCell(aCellID); myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + + if (myGaussPointsPL->GetIsDeformed()) { + // find neighbour cells ids + vtkIdList* aNeighbourCells = vtkIdList::New(); + aNeighbourCells->Allocate(VTK_CELL_SIZE); + + vtkIdList* aCellPoints = aCell->GetPointIds(); + + vtkIdList *aPointCells = vtkIdList::New(); + aPointCells->Allocate(VTK_CELL_SIZE); + + vtkIdType aNbPoints = aCellPoints->GetNumberOfIds(); + for (vtkIdType i = 0; i < aNbPoints; i++) { + aDataSet->GetPointCells(aCellPoints->GetId(i), aPointCells); + + // add cell ids + vtkIdType aNbCells = aPointCells->GetNumberOfIds(); + for (vtkIdType j = 0; j < aNbCells; j++) + aNeighbourCells->InsertUniqueId(aPointCells->GetId(j)); + } + + aPointCells->Delete(); + + // get vector data + vtkDataArray* anInputVectors = aDataSetAttributes->GetVectors(); + if (!anInputVectors) + return; + + // insert neighbour cells to the special dataset + vtkUnstructuredGrid *aCellsToWarp = vtkUnstructuredGrid::New(); + aCellsToWarp->SetPoints(aDataSet->GetPoints()); + + vtkIdType aNbNeighbourCells = aNeighbourCells->GetNumberOfIds(); + + vtkDataArray *aVectorsToSet = vtkDataArray::CreateDataArray(anInputVectors->GetDataType()); + aVectorsToSet->SetNumberOfComponents(3); + aVectorsToSet->SetNumberOfTuples(aNbNeighbourCells); + + vtkDataArray *aCellVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType()); + aCellVectors->SetNumberOfComponents(3); + + int aNbComp = anInputVectors->GetNumberOfComponents(); + std::vector aTuple(aNbComp); + + for (vtkIdType i = 0; i < aNbNeighbourCells; i++) { + vtkIdType aVTKCellId = aNeighbourCells->GetId(i); + vtkIdType anObjCellId = aParent->GetElemObjID(aVTKCellId); + + vtkCell* aCurCell = aParent->GetElemCell(anObjCellId); + + vtkIdType aNewCellId = aCellsToWarp->InsertNextCell(aCurCell->GetCellType(), aCurCell->GetPointIds()); + + // get gauss points corresponding to the current cell + vtkIdType aPointVtkId = -1; + vtkIdType aLocalPntId = 0; + aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, aLocalPntId)); + + if (aPointVtkId >= 0) { + // Compute average vector + aCellVectors->Reset(); + while (aPointVtkId >= 0) { + anInputVectors->GetTuple(aPointVtkId, &aTuple[0]); + + if (aNbComp >= 3) + aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], aTuple[2]); + else if (aNbComp == 2) + aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], 0); + else if (aNbComp == 1) + aCellVectors->InsertNextTuple3(aTuple[0], 0, 0); + + aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, ++aLocalPntId)); + } + + double aXCoord = 0, anYCoord = 0, aZCoord = 0; + + vtkIdType aNbVectors = aCellVectors->GetNumberOfTuples(); + + for (vtkIdType aVecId = 0; aVecId < aNbVectors; aVecId++) { + aXCoord += aCellVectors->GetComponent(aVecId, 0); + anYCoord += aCellVectors->GetComponent(aVecId, 1); + aZCoord += aCellVectors->GetComponent(aVecId, 2); + } + + aXCoord = aXCoord / aNbVectors; + anYCoord = anYCoord / aNbVectors; + aZCoord = aZCoord / aNbVectors; + + // set vector data for the cell + aVectorsToSet->SetTuple3(aNewCellId, aXCoord, anYCoord, aZCoord); + } + else + aVectorsToSet->SetTuple3(aNewCellId, 0, 0, 0); + } + + aCellsToWarp->GetCellData()->SetVectors(aVectorsToSet); + + aVectorsToSet->Delete(); + aCellVectors->Delete(); + aNeighbourCells->Delete(); + + // warp + myWarpVector->SetScaleFactor(myGaussPointsPL->GetScale()); + + myCellDataToPointData->SetInput(aCellsToWarp); + myCellDataToPointData->PassCellDataOn(); + aCellsToWarp->Delete(); + + myWarpVector->SetInput(myCellDataToPointData->GetUnstructuredGridOutput()); + vtkUnstructuredGrid* aWarpedDataSet = myWarpVector->GetUnstructuredGridOutput(); + aWarpedDataSet->Update(); + myCellSource->SetPoints(aWarpedDataSet->GetPoints()); + } + else + myCellSource->SetPoints(aDataSet->GetPoints()); + myCellActor->SetVisibility(anIsVisible && theIsHighlight); myCellActor->SetRepresentation(VTK_WIREFRAME); } diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index f4a6b22a..a53d8fe5 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -55,6 +55,9 @@ class vtkUnstructuredGrid; class vtkPolyDataMapper; class vtkDataArray; +class vtkCellDataToPointData; +class vtkWarpVector; + class vtkInteractorObserver; class vtkCallbackCommand; @@ -329,6 +332,9 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_Actor vtkSmartPointer myCellSource; vtkSmartPointer myCellActor; + vtkSmartPointer myWarpVector; + vtkSmartPointer myCellDataToPointData; + bool myBarVisibility; vtkSmartPointer myScalarBarCtrl; diff --git a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx index a6143c1c..89bec1de 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx @@ -779,6 +779,10 @@ VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule): QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox ); myScaleSpinBox = new QtxDblSpinBox( 0.0, 10.0, 0.1, myDefShapeBox ); + // Set precision (bug 0020121) + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 ); + myScaleSpinBox->setPrecision( aPrecision*(-1) ); aDefShapeLayout->addWidget( aScaleLabel, 0, 0 ); aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 ); -- 2.39.2