]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
0013557: field values display
authorsln <sln@opencascade.com>
Tue, 9 Dec 2008 12:25:04 +0000 (12:25 +0000)
committersln <sln@opencascade.com>
Tue, 9 Dec 2008 12:25:04 +0000 (12:25 +0000)
Now you can display values applied to the cells or nodes of 3D presentation intended for visualization of calculation data. New methods are provided in actor.

virtual void SetValuesLabeled( const bool theIsValLabeled );
virtual bool GetValuesLabeled() const;

virtual vtkDataSet* GetValLabelsInput() const;
vtkTextProperty* GetsValLabelsProps() const;

src/OBJECT/VISU_Actor.cxx
src/OBJECT/VISU_Actor.h

index f001de9a99807c3575bc9b8f6e6de77421b66a42..cb8245af0e25297f4ead1edd7b2d755bf6b3f0a8 100644 (file)
 #include <vtkUnstructuredGrid.h>
 #include <vtkPassThroughFilter.h>
 #include <vtkFeatureEdges.h>
+#include <vtkActor2D.h>
+#include <vtkMaskPoints.h>
+#include <vtkLabeledDataMapper.h>
+#include <vtkSelectVisiblePoints.h>
+#include <vtkTextProperty.h>
+#include <vtkProperty2D.h>
 
 #include <vtkShrinkFilter.h>
 #include <vtkShrinkPolyData.h>
@@ -139,6 +145,44 @@ VISU_Actor
     aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent, 
                                  myEventCallbackCommand.GetPointer(), 
                                  myPriority);
+                                 
+  //Definition of values labeling pipeline
+
+  myValLblDataSet = vtkUnstructuredGrid::New();
+
+  myValCellCenters = vtkCellCenters::New();
+  myValCellCenters->SetInput(myValLblDataSet);
+
+  myValMaskPoints = vtkMaskPoints::New();
+  myValMaskPoints->SetInput(myValCellCenters->GetOutput());
+  myValMaskPoints->SetOnRatio(1);
+    
+  myValSelectVisiblePoints = vtkSelectVisiblePoints::New();
+  myValSelectVisiblePoints->SetInput(myValMaskPoints->GetOutput());
+  myValSelectVisiblePoints->SelectInvisibleOff();
+  myValSelectVisiblePoints->SetTolerance(0.1);
+    
+  myValLabeledDataMapper = vtkLabeledDataMapper::New();
+  myValLabeledDataMapper->SetInput(myValSelectVisiblePoints->GetOutput());
+  myValLabeledDataMapper->SetLabelFormat("%g");
+  myValLabeledDataMapper->SetLabelModeToLabelScalars();
+    
+  vtkTextProperty* aClsTextProp = vtkTextProperty::New();
+  aClsTextProp->SetFontFamilyToTimes();
+  static int aCellsFontSize = 12;
+  aClsTextProp->SetFontSize(aCellsFontSize);
+  aClsTextProp->SetBold(1);
+  aClsTextProp->SetItalic(0);
+  aClsTextProp->SetShadow(0);
+  myValLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
+  aClsTextProp->Delete();
+    
+  myIsValLabeled = false;
+
+  myValLabels = vtkActor2D::New();
+  myValLabels->SetMapper(myValLabeledDataMapper);
+  myValLabels->GetProperty()->SetColor(0,1,0);
+  myValLabels->SetVisibility( myIsValLabeled );
 }
 
 //----------------------------------------------------------------------------
@@ -182,6 +226,15 @@ VISU_Actor
 VISU_Actor
 ::~VISU_Actor()
 {
+  // Deleting of values labeling pipeline
+  myValLblDataSet->Delete();
+  myValLabeledDataMapper->RemoveAllInputs();
+  myValLabeledDataMapper->Delete();
+  myValSelectVisiblePoints->Delete();
+  myValMaskPoints->Delete();
+  myValCellCenters->Delete();
+  myValLabels->Delete();
+
   if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<<this);
   Superclass::SetProperty(NULL);
   SetDebug(MYVTKDEBUG);
@@ -475,6 +528,10 @@ VISU_Actor
   Superclass::AddToRender(theRenderer);
   theRenderer->AddActor(myAnnotationActor.GetPointer());
   theRenderer->AddActor(myTextActor.GetPointer());
+
+  myValSelectVisiblePoints->SetRenderer( theRenderer );
+  theRenderer->AddActor2D( myValLabels );
+
 }
 
 //==================================================================
@@ -487,10 +544,20 @@ VISU_Actor
 {
   theRenderer->RemoveActor(myAnnotationActor.GetPointer());
   theRenderer->RemoveActor(myTextActor.GetPointer());
+  theRenderer->RemoveActor(myValLabels);
   Superclass::RemoveFromRender(theRenderer); 
   myDestroySignal(this);
 }
 
+//----------------------------------------------------------------------------
+void 
+VISU_Actor
+::SetVisibility(int theMode)
+{
+  Superclass::SetVisibility( theMode );
+  myValLabels->SetVisibility( myIsValLabeled && theMode );
+}
+
 //----------------------------------------------------------------------------
 void 
 VISU_Actor
@@ -1101,3 +1168,92 @@ VISU_Actor
 
   Update();
 }
+
+// ---------------------------------------------------------------
+
+void VISU_Actor::SetValuesLabeled( const bool theIsValLabeled )
+{
+  vtkDataSet* aGrid = GetValLabelsInput();
+  if ( !aGrid )
+    return;
+  
+  bool isOnPnt = VISU::IsDataOnPoints( aGrid );
+  bool isOnCell = VISU::IsDataOnCells( aGrid );
+  if ( !isOnPnt && !isOnCell )
+  {
+    // try to specify location of scalars "manually"
+    vtkCellData* aCData = aGrid->GetCellData();
+    if ( aCData )
+    {
+      vtkDataArray* anArr = aCData->GetScalars();
+      if ( anArr && anArr->GetNumberOfTuples() )
+        isOnCell = true;
+    }
+
+    if ( !isOnCell )
+    {
+      vtkPointData* aPData = aGrid->GetPointData();
+      if ( aPData )
+      {
+        vtkDataArray* anArr = aPData->GetScalars();
+        if ( anArr && anArr->GetNumberOfTuples() )
+          isOnPnt = true;
+      }
+    }
+
+    if ( !isOnPnt && !isOnCell )
+    {
+      myValLabels->SetVisibility( false );
+      return;
+    }
+  }
+  
+  myIsValLabeled = theIsValLabeled;
+
+  if ( myIsValLabeled )
+  {
+    vtkDataSet* aDataSet = aGrid;
+
+    if ( isOnCell )
+    {
+      myValCellCenters->SetInput( aDataSet );
+      myValMaskPoints->SetInput( myValCellCenters->GetOutput() );
+    }
+    else if ( isOnPnt )
+      myValMaskPoints->SetInput( aDataSet );
+
+    myValLabels->SetVisibility( GetVisibility() );
+  }
+  else
+    myValLabels->SetVisibility( false );
+  
+  Modified();
+}
+
+//----------------------------------------------------------------------------
+
+bool VISU_Actor::GetValuesLabeled() const
+{
+  return myIsValLabeled;
+}
+
+//----------------------------------------------------------------------------
+
+vtkTextProperty* VISU_Actor::GetsValLabelsProps() const
+{
+  return myValLabeledDataMapper->GetLabelTextProperty();  
+}
+
+//----------------------------------------------------------------------------
+
+vtkDataSet* VISU_Actor::GetValLabelsInput()
+{
+  vtkDataSet* aDataSet = 0;
+  VISU_PipeLine* aPL = GetPipeLine();
+  if ( aPL )
+    aDataSet = aPL->GetOutput();
+  if ( !aDataSet )
+    aDataSet = GetInput();
+  return aDataSet;
+}
+
index 34c1dcc8988d1373d01a03e4d26b3746f7b4d91b..69fcf141420a76d59cad98e4a2409a9ca69dd315 100644 (file)
@@ -49,6 +49,12 @@ class VISU_PipeLine;
 class vtkPlane;
 class vtkImplicitFunctionCollection;
 class vtkFeatureEdges;
+class vtkTextProperty;
+class vtkCellCenters;
+class vtkSelectVisiblePoints;
+class vtkLabeledDataMapper;
+class vtkMaskPoints;
+class vtkActor2D;
 
 class VISU_FramedTextActor;
 
@@ -107,6 +113,10 @@ class VTKOCC_EXPORT VISU_Actor : public VISU_ActorBase
   virtual
   void
   RemoveFromRender();
+  
+  virtual
+  void
+  SetVisibility(int theMode);
 
   //----------------------------------------------------------------------------
   virtual
@@ -308,6 +318,22 @@ class VTKOCC_EXPORT VISU_Actor : public VISU_ActorBase
   UpdatePickingSettings();
 
   //----------------------------------------------------------------------------
+  //! Methods for values labeling
+  virtual 
+  void 
+  SetValuesLabeled( const bool theIsValLabeled );
+
+  virtual 
+  bool 
+  GetValuesLabeled() const;
+
+  virtual
+  vtkDataSet*
+  GetValLabelsInput();
+
+  vtkTextProperty* 
+  GetsValLabelsProps() const;
+  
  protected:
   VISU_Actor();
 
@@ -364,6 +390,15 @@ class VTKOCC_EXPORT VISU_Actor : public VISU_ActorBase
 
   Selection_Mode myLastSelectionMode;
   bool myIsSubElementsHighlighted;
+  
+  // fields for values labeling
+  bool                    myIsValLabeled;
+  vtkDataSet*             myValLblDataSet;
+  vtkActor2D*             myValLabels;
+  vtkMaskPoints*          myValMaskPoints;
+  vtkCellCenters*         myValCellCenters;
+  vtkLabeledDataMapper*   myValLabeledDataMapper;
+  vtkSelectVisiblePoints* myValSelectVisiblePoints;
 };
 
 #endif //VISU_ACTOR_H