Salome HOME
Implementation of the "0022102: EDF 1496 SMESH : Displaying of discrete elements...
[modules/smesh.git] / src / OBJECT / SMESH_DeviceActor.cxx
index c82bbf30524a34ebea0025dc4c3737ebc80775b0..4a46932cc7f52eb89953f21da815187f584dc8b0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -119,13 +119,13 @@ SMESH_DeviceActor
   // Orientation of faces
   myIsFacesOriented = false;
 
-  vtkFloatingPointType anRGB[3] = { 1, 1, 1 };
+  double anRGB[3] = { 1, 1, 1 };
   SMESH::GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
 
   myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
 
   myFaceOrientationDataMapper = vtkPolyDataMapper::New();
-  myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
+  myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort());
 
   myFaceOrientation = vtkActor::New();
   myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
@@ -208,9 +208,9 @@ SMESH_DeviceActor
 {
   int anId = 0;
   if(theIsImplicitFunctionUsed)
-    myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() );
+    myPassFilter[ anId ]->SetInputConnection( myExtractGeometry->GetOutputPort() );
   else
-    myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() );
+    myPassFilter[ anId ]->SetInputConnection( myMergeFilter->GetOutputPort() );
     
   myIsImplicitFunctionUsed = theIsImplicitFunctionUsed;
   SetStoreClippingMapping(myStoreClippingMapping);
@@ -225,32 +225,37 @@ SMESH_DeviceActor
     //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
     myIsShrinkable = true;
 
-    myExtractUnstructuredGrid->SetInput(theGrid);
+    myExtractUnstructuredGrid->SetInputData(theGrid);
 
-    myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput());
+    myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort());
+    
+    //Pass diameters of the balls
+    if(myMapper->GetBallEnabled()) {
+      myMergeFilter->SetScalarsConnection(myExtractUnstructuredGrid->GetOutputPort());
+    }
 
-    myExtractGeometry->SetInput(myMergeFilter->GetOutput());
+    myExtractGeometry->SetInputConnection(myMergeFilter->GetOutputPort());
 
     int anId = 0;
     SetImplicitFunctionUsed(myIsImplicitFunctionUsed);
-    myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
+    myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
     
     anId++; // 1
-    myTransformFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
+    myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
     anId++; // 2
-    myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
-    myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
+    myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() );
+    myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
     anId++; // 3
-    myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
+    myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
     anId++; // 4
-    myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); 
-    myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
+    myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() ); 
+    myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
     anId++; // 5
-    myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
+    myMapper->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
     vtkLODActor::SetMapper( myMapper );
     Modified();
@@ -295,34 +300,46 @@ SMESH_DeviceActor
     vtkIdType aNbCells = aGrid->GetNumberOfCells();
     aScalars->SetNumberOfComponents(1);
     aScalars->SetNumberOfTuples(aNbCells);
+    double* range;// = aScalars->GetRange();
     
     myVisualObj->UpdateFunctor(theFunctor);
 
     using namespace SMESH::Controls;
-    if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get())){
+    if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get()))
+    {
       for(vtkIdType i = 0; i < aNbCells; i++){
         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
         double aValue = aNumericalFunctor->GetValue(anObjId);
         aScalars->SetValue(i,aValue);
       }
-    }else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get())){
+      range = aScalars->GetRange();
+      if ( range[1] - range[0] < ( qMax(qAbs(range[0]),qAbs(range[1])) + 1e-100 ) * 1e-6 )
+      {
+        range[1] = range[0];
+        for(vtkIdType i = 0; i < aNbCells; i++)
+          aScalars->SetValue(i,range[0]);
+      }
+    }
+    else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get()))
+    {
       for(vtkIdType i = 0; i < aNbCells; i++){
         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
         bool aValue = aPredicate->IsSatisfy(anObjId);
         aScalars->SetValue(i,aValue);
       }
+      range = aScalars->GetRange();
     }
 
     aDataSet->GetCellData()->SetScalars(aScalars);
     aScalars->Delete();
-        
-    theLookupTable->SetRange(aScalars->GetRange());
+
+    theLookupTable->SetRange( range );
     theLookupTable->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors());
     theLookupTable->Build();
     
-    myMergeFilter->SetScalars(aDataSet);
+    myMergeFilter->SetScalarsData(aDataSet);
     aDataSet->Delete();
   }
   GetMapper()->SetScalarVisibility(anIsInitialized);
@@ -402,7 +419,7 @@ SMESH_DeviceActor
       theLookupTable->SetRange(aScalars->GetRange());
       theLookupTable->Build();
       
-      myMergeFilter->SetScalars(aDataSet);
+      myMergeFilter->SetScalarsData(aDataSet);
       aDataSet->Delete();
     }
     else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
@@ -462,7 +479,7 @@ SMESH_DeviceActor
       theLookupTable->SetRange(aScalars->GetRange());
       theLookupTable->Build();
       
-      myMergeFilter->SetScalars(aDataSet);
+      myMergeFilter->SetScalarsData(aDataSet);
       aDataSet->Delete();
     }
   }
@@ -600,10 +617,10 @@ SMESH_DeviceActor
 ::SetShrink() 
 {
   if ( !myIsShrinkable ) return;
-  if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
+  if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
   {
-    myShrinkFilter->SetInput( aDataSet );
-    myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
+    myShrinkFilter->SetInputConnection( aDataSet );
+    myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() );
     myIsShrunk = true;
   }
 }
@@ -613,9 +630,9 @@ SMESH_DeviceActor
 ::UnShrink() 
 {
   if ( !myIsShrunk ) return;
-  if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
+  if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
   {    
-    myPassFilter[ 1 ]->SetInput( aDataSet );
+    myPassFilter[ 1 ]->SetInputConnection( aDataSet );
     myPassFilter[ 1 ]->Modified();
     myIsShrunk = false;
     Modified();
@@ -627,37 +644,37 @@ void
 SMESH_DeviceActor
 ::SetFacesOriented(bool theIsFacesOriented) 
 {
-  if ( vtkDataSet* aDataSet = myTransformFilter->GetOutput() )
+  if ( vtkAlgorithmOutput* aDataSet = myTransformFilter->GetOutputPort() )
   {
     myIsFacesOriented = theIsFacesOriented;
     if( theIsFacesOriented )
-      myFaceOrientationFilter->SetInput( aDataSet );
+      myFaceOrientationFilter->SetInputConnection( aDataSet );
     UpdateFaceOrientation();
   }
 }
 
 void
 SMESH_DeviceActor
-::SetFacesOrientationColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
+::SetFacesOrientationColor(double r,double g,double b)
 {
   myFaceOrientation->GetProperty()->SetColor( r, g, b );
 }
 
 void
 SMESH_DeviceActor
-::GetFacesOrientationColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
+::GetFacesOrientationColor(double& r,double& g,double& b)
 {
   myFaceOrientation->GetProperty()->GetColor( r, g, b );
 }
 
 void
 SMESH_DeviceActor
-::SetFacesOrientationScale(vtkFloatingPointType theScale)
+::SetFacesOrientationScale(double theScale)
 {
   myFaceOrientationFilter->SetOrientationScale( theScale );
 }
 
-vtkFloatingPointType
+double
 SMESH_DeviceActor
 ::GetFacesOrientationScale()
 {
@@ -780,13 +797,13 @@ SMESH_DeviceActor
   return aRetID;
 }
 
-vtkFloatingPointType* 
+double* 
 SMESH_DeviceActor
 ::GetNodeCoord(int theObjID)
 {
   vtkDataSet* aDataSet = myMergeFilter->GetOutput();
   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
-  vtkFloatingPointType* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
+  double* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
   if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
   return aCoord;
 }
@@ -829,7 +846,7 @@ SMESH_DeviceActor
 }
 
 
-vtkFloatingPointTyp
+doubl
 SMESH_DeviceActor
 ::GetShrinkFactor()
 {
@@ -838,7 +855,7 @@ SMESH_DeviceActor
 
 void
 SMESH_DeviceActor
-::SetShrinkFactor(vtkFloatingPointType theValue)
+::SetShrinkFactor(double theValue)
 {
   theValue = theValue > 0.1? theValue: 0.8;
   myShrinkFilter->SetShrinkFactor(theValue);
@@ -861,13 +878,13 @@ SMESH_DeviceActor
 ::Render(vtkRenderer *ren, vtkMapper* m)
 {
   int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
-  vtkFloatingPointType aStoredFactor, aStoredUnit; 
+  double aStoredFactor, aStoredUnit; 
   vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
 
   vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
-  vtkFloatingPointType aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
+  double aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
   if(myIsHighlited){
-    static vtkFloatingPointType EPS = .01;
+    static double EPS = .01;
     aUnits *= (1.0-EPS);
   }
   vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
@@ -880,8 +897,8 @@ SMESH_DeviceActor
 
 void
 SMESH_DeviceActor
-::SetPolygonOffsetParameters(vtkFloatingPointType factor, 
-                             vtkFloatingPointType units)
+::SetPolygonOffsetParameters(double factor, 
+                             double units)
 {
   myPolygonOffsetFactor = factor;
   myPolygonOffsetUnits = units;
@@ -903,14 +920,14 @@ bool SMESH_DeviceActor::GetQuadraticArcMode(){
 /*!
  * Set Max angle for representation 2D quadratic element as arked polygon
  */
-void SMESH_DeviceActor::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle){
+void SMESH_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){
   myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
 }
 
 /*!
  * Return Max angle of the representation 2D quadratic element as arked polygon
  */
-vtkFloatingPointType SMESH_DeviceActor::GetQuadraticArcAngle(){
+double SMESH_DeviceActor::GetQuadraticArcAngle(){
   return myGeomFilter->GetQuadraticArcAngle();
 }
 
@@ -923,6 +940,14 @@ void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
   myMapper->SetMarkerEnabled( theMarkerEnabled );
 }
 
+/*!
+ * Set point marker enabled
+ * \param theBallEnabled flag to enable/disable ball drawing
+ */
+void SMESH_DeviceActor::SetBallEnabled( bool theBallEnabled ) {
+  myMapper->SetBallEnabled( theBallEnabled );
+}
+
 /*!
  * Set standard point marker
  * \param theMarkerType type of the marker