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

index 8ce6c380153558f5caf10bb8cfbc6f59f7bf3662..a26d58fbe969b7c5dea4364bd7f9176223a31294 100644 (file)
@@ -52,6 +52,7 @@
 #include <vtkPlane.h>
 
 #include <vtkPointData.h>
+#include <vtkCellData.h>
 #include <vtkDataArray.h>
 
 #include <vtkSphereSource.h>
@@ -73,6 +74,8 @@
 #include <vtkPolyDataMapper.h>
 #include <vtkRenderWindow.h>
 #include <vtkCellArray.h>
+#include <vtkWarpVector.h>
+#include <vtkCellDataToPointData.h>
 #include <vtkCell.h>
 #include <vtkMath.h>
 
@@ -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 = "<<this);
 
@@ -170,7 +175,7 @@ VISU_GaussPtsAct
   myCellActor->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<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(aCellDataSet->GetPoints());
+    
     myCellActor->SetVisibility(anIsVisible && theIsHighlight && aShowCellActor);
   }
 }
index 375c96b95f4b2e4689dd612555f00d7f5e0282e7..891f391b9c7097a604a113f30dffe7fa23bbbd1e 100644 (file)
@@ -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<vtkUnstructuredGrid> myCellSource;
   vtkSmartPointer<SVTK_Actor> myCellActor;
 
+  vtkSmartPointer<vtkWarpVector> myWarpVector;
+  vtkSmartPointer<vtkCellDataToPointData> myCellDataToPointData;
+
   bool myBarVisibility;
   vtkSmartPointer<VISU_ScalarBarCtrl> myScalarBarCtrl;
 
index d5b59c79c9990317758804fbc5b2f6fbfe0dd274..fd3bf17039a144bbefb638f8a2371bf4c5542049 100644 (file)
@@ -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 );