From: mzn Date: Fri, 13 Feb 2009 18:14:34 +0000 (+0000) Subject: Fix for bug 0020121: EDF VISU 924: Gauss View + Deformed Shape + Picking + Display... X-Git-Tag: mergeto_trunk_16Feb09 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FBR_V5_DEV;p=modules%2Fvisu.git Fix for bug 0020121: EDF VISU 924: Gauss View + Deformed Shape + Picking + Display parent mesh element. --- diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 8ce6c380..a26d58fb 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -52,6 +52,7 @@ #include #include +#include #include #include @@ -73,6 +74,8 @@ #include #include #include +#include +#include #include #include @@ -138,7 +141,9 @@ VISU_GaussPtsAct myCurrentPL(NULL), myMapper(vtkPolyDataMapper::New()), myPolyDataExtractor(SALOME_ExtractPolyDataGeometry::New()), - myFunction(vtkImplicitBoolean::New()) + myFunction(vtkImplicitBoolean::New()), + myWarpVector(vtkWarpVector::New()), + myCellDataToPointData(vtkCellDataToPointData::New()) { if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<Initialize(); myCellActor->SetRepresentation(VTK_WIREFRAME); myCellActor->SetSource(myCellSource.GetPointer()); - + myCellActor->SetVisibility(0); myCellActor->SetPickable(0); myCellActor->GetProperty()->SetAmbient(1.0); @@ -181,6 +186,9 @@ VISU_GaussPtsAct myMapper->Delete(); aMatrix->Delete(); + myWarpVector->Delete(); + myCellDataToPointData->Delete(); + myPolyDataExtractor->SetImplicitFunction(myFunction); //myPolyDataExtractor->ExtractBoundaryCellsOn(); @@ -1145,12 +1153,127 @@ VISU_GaussPtsAct myCellSource->Reset(); myCellSource->Modified(); // a VTK bug vtkUnstructuredGrid* aCellDataSet = aParent->GetUnstructuredGridOutput(); - myCellSource->SetPoints(aCellDataSet->GetPoints()); - // + + // get parent cell and insert it to myCellSource 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++) { + aCellDataSet->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(aCellDataSet->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(aCellDataSet->GetPoints()); + myCellActor->SetVisibility(anIsVisible && theIsHighlight && aShowCellActor); } } diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index 375c96b9..891f391b 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -56,6 +56,9 @@ class vtkUnstructuredGrid; class vtkPolyDataMapper; class vtkDataArray; +class vtkCellDataToPointData; +class vtkWarpVector; + class vtkInteractorObserver; class vtkCallbackCommand; @@ -339,6 +342,9 @@ class VISU_OBJECT_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 d5b59c79..fd3bf170 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx +++ b/src/VISUGUI/VisuGUI_GaussPointsDlg.cxx @@ -830,10 +830,13 @@ VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule): aDefShapeLayout->setAlignment(Qt::AlignTop); aDefShapeLayout->setSpacing(6); aDefShapeLayout->setMargin(11); + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 ); QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox ); - myScaleSpinBox = new QtxDoubleSpinBox( 0.0, 10.0, 0.1, myDefShapeBox ); - + myScaleSpinBox = new QtxDoubleSpinBox( 0.0, 10.0, 0.1, aPrecision*(-1), 32, myDefShapeBox ); + aDefShapeLayout->addWidget( aScaleLabel, 0, 0 ); aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 );