]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for bug 0020121: EDF VISU 924: Gauss View + Deformed Shape + Picking + Display... V4_1_0_maintainance_20090217 V4_1_0_maintainance_20090219 V4_1_0_maintainance_20090220
authormzn <mzn@opencascade.com>
Fri, 13 Feb 2009 18:16:56 +0000 (18:16 +0000)
committermzn <mzn@opencascade.com>
Fri, 13 Feb 2009 18:16:56 +0000 (18:16 +0000)
src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h
src/VISUGUI/VisuGUI_GaussPointsDlg.cxx

index 2653e428122be20cd8ec36caf4c4f93da8c58895..8238406e0471655a10a2d78c2b735b2cd810970f 100644 (file)
@@ -47,6 +47,7 @@
 #include <vtkTextProperty.h>
 
 #include <vtkPointData.h>
+#include <vtkCellData.h>
 #include <vtkDataArray.h>
 
 #include <vtkSphereSource.h>
@@ -68,6 +69,8 @@
 #include <vtkPolyDataMapper.h>
 #include <vtkRenderWindow.h>
 #include <vtkCellArray.h>
+#include <vtkWarpVector.h>
+#include <vtkCellDataToPointData.h>
 #include <vtkCell.h>
 #include <vtkMath.h>
 
@@ -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 = "<<this);
 
@@ -179,6 +184,9 @@ VISU_GaussPtsAct
 
   myMapper->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<vtkFloatingPointType> 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);
     }
index f4a6b22aba4ad14308d1809db8b26b1033017775..a53d8fe5f9947b8de7a2a5c7ca48da451c2e2b38 100644 (file)
@@ -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<vtkUnstructuredGrid> myCellSource;
   vtkSmartPointer<SVTK_Actor> myCellActor;
 
+  vtkSmartPointer<vtkWarpVector> myWarpVector;
+  vtkSmartPointer<vtkCellDataToPointData> myCellDataToPointData;
+
   bool myBarVisibility;
   vtkSmartPointer<VISU_ScalarBarCtrl> myScalarBarCtrl;
 
index a6143c1c9469a3f55183b76ed94254fd3fd2dfaa..89bec1de438e1349d4f41465814cd7756f6d1fbc 100644 (file)
@@ -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 );