Salome HOME
Update Help for VISU module.
[modules/visu.git] / src / OBJECT / VISU_Actor.cxx
index a3f440c72931120dd08d3b0d023fc7a41b68c8b9..e38b8cd3a139f4aec69ef7ec76bac64a61138d5a 100644 (file)
 
 #include "VISU_Actor.h"
 #include "VISU_PipeLine.hxx"
-#include "SALOME_PassThroughFilter.h"
-#include "utilities.h"
+#include "VTKViewer_ShrinkFilter.h"
+#include "VTKViewer_GeometryFilter.h"
+#include "VTKViewer_PassThroughFilter.h"
  
+#include <stdexcept>
+
 // VTK Includes
 #include <vtkProperty.h>
-#include <vtkDataSetMapper.h>
+
+#include <vtkDataSet.h>
+#include <vtkPolyData.h>
+#include <vtkUnstructuredGrid.h>
+
+#include <vtkShrinkFilter.h>
 #include <vtkShrinkPolyData.h>
+
+#include <vtkDataSetMapper.h>
 #include <vtkGeometryFilter.h>
 #include <vtkObjectFactory.h>
 
+#include "utilities.h"
+
 using namespace std;
 
 static int MYVTKDEBUG = 0;
 
 #ifdef _DEBUG_
 static int MYDEBUG = 1;
-static int MYDEBUGWITHFILES = 0;
 #else
 static int MYDEBUG = 0;
-static int MYDEBUGWITHFILES = 0;
 #endif
 
 //=======================================================================
@@ -64,36 +74,24 @@ VISU_Actor::VISU_Actor(){
 
   myIsShrunk = false;
   myIsShrinkable = false;
-  myShrinkFilter = vtkShrinkPolyData::New();
+  myShrinkFilter = VTKViewer_ShrinkFilter::New();
+  myShrinkFilter->SetStoreMapping(true);
+  SetShrinkFactor();
+  
+  myMapper = vtkDataSetMapper::New();
 
   myIO = NULL;
   myName = "";
-
-  ishighlighted = false;
-  IsHighlighting = true;
-  HighlightProperty = vtkProperty::New();
-  HighlightProperty->SetAmbient(0.5);            
-  HighlightProperty->SetDiffuse(0.3);            
-  HighlightProperty->SetSpecular(0.2);           
-  HighlightProperty->SetRepresentationToSurface();
-  HighlightProperty->SetAmbientColor(1, 1, 1);
-  HighlightProperty->SetDiffuseColor(1, 1, 1);
-  HighlightProperty->SetSpecularColor(0.5, 0.5, 0.5);
-
-  vtkProperty* aProperty = this->GetProperty();
-  aProperty->SetAmbient(0.5); 
-  aProperty->SetDiffuse(0.2);
-  aProperty->SetSpecular(0.2);
-  aProperty->SetAmbientColor(1, 1, 1);
-  aProperty->SetDiffuseColor(1, 1, 1);
-  aProperty->SetSpecularColor(0.5, 0.5, 0.5);
-  this->SetProperty(aProperty);
 }
 
 VISU_Actor::~VISU_Actor(){
   SALOME_Actor::SetProperty(NULL);
-  HighlightProperty->Delete();
-  if(myPipeLine) myPipeLine->UnRegister(this);
+
+  myMapper->RemoveAllInputs();
+  myMapper->Delete();
+
+  if(myPipeLine) 
+    myPipeLine->UnRegister(this);
 
   myShrinkFilter->UnRegisterAllOutputs();
   myShrinkFilter->Delete();
@@ -116,24 +114,25 @@ void VISU_Actor::SetPipeLine(VISU_PipeLine* thePipeLine) {
     this->Modified();
     vtkMapper *aMapper = myPipeLine->GetMapper();
     vtkDataSet *aDataSet = aMapper->GetInput();
-    if(!aDataSet)
-      throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data !!!");
-    aDataSet->Update();
-    static float eps = VTK_LARGE_FLOAT * 0.1 ;
-    if(aDataSet->GetLength() > eps)
-      throw std::runtime_error("VISU_Actor::SetPipeLine >> Diagonal of the actor is too large !!!");
-    if(!aDataSet->GetNumberOfCells())
-      throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no visible elements");
+
+    //This code has been moved into VISU::Prs3d_i::UpdateActor() for bug 9808
+    //if(!aDataSet)
+    //  throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data !!!");
+    //aDataSet->Update();
+    //static float eps = VTK_LARGE_FLOAT * 0.1 ;
+    //if(aDataSet->GetLength() > eps)
+    //  throw std::runtime_error("VISU_Actor::SetPipeLine >> Diagonal of the actor is too large !!!");
+    //if(!aDataSet->GetNumberOfCells())
+    //  throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no visible elements");
+
     //Bug SAL4221:  Mesh with less than 10 cells : shrink mode disable
     //SetShrinkable(aDataSet->GetNumberOfCells() > 10);
-    SetShrinkable(true);
+    SetShrinkable(thePipeLine->IsShrinkable());
     //Now, we use vtkShrinkPolyData (not vtkShrinkFilter), 
     //and the class there is no such limitation.
-    
-    vtkDataSetMapper* aNewMapper = vtkDataSetMapper::New();
-    aNewMapper->SetInput(aDataSet);
-    SetMapper(aNewMapper);
-    aNewMapper->Delete();
+
+    myMapper->SetInput(aDataSet);
+    SetMapper(myMapper);
   }
 }
 
@@ -143,6 +142,8 @@ void VISU_Actor::SetParent(VISU_Actor* theParent){
 
 void VISU_Actor::SetRepresentation(int theMode) { 
   SALOME_Actor::SetRepresentation(theMode);
+  if(myRepresentation == VTK_POINTS)
+    UnShrink();
 }
 
 void VISU_Actor::SetOpacity(float theValue){
@@ -153,48 +154,47 @@ float VISU_Actor::GetOpacity(){
   return GetProperty()->GetOpacity();
 }
 
-void VISU_Actor::SetShrinkable(bool theIsShrinkable){
-  myIsShrinkable = theIsShrinkable;
-}
 
-void VISU_Actor::SetShrink(float theFactor){
+void VISU_Actor::SetShrink(){
   if(!myIsShrinkable) return;
-  //_CS_PhB operator []  if(vtkPolyData* aDataSet = myPassFilter.at(1)->GetPolyDataOutput()){
-  if(vtkPolyData* aDataSet = myPassFilter[1]->GetPolyDataOutput()){
-    myShrinkFilter->SetShrinkFactor(theFactor);
+  if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
     myShrinkFilter->SetInput(aDataSet);
-  //_CS_PhB operator [] myPassFilter.at(2)->SetInput(myShrinkFilter->GetOutput());
-    myPassFilter[2]->SetInput(myShrinkFilter->GetOutput());
+    myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
     myIsShrunk = true;
   }
 }
 
 void VISU_Actor::UnShrink(){
   if(!myIsShrunk) return;
-  //_CS_PhB operator [] if(vtkPolyData* aDataSet = myPassFilter.at(1)->GetPolyDataOutput()){
-  if(vtkPolyData* aDataSet = myPassFilter[1]->GetPolyDataOutput()){
-  //_CS_PhB operator []  myPassFilter.at(2)->SetInput(aDataSet);
-  //_CS_PhB operator []  myPassFilter.at(2)->Modified();
-    myPassFilter[2]->SetInput(aDataSet);
-    myPassFilter[2]->Modified();
+  if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
+    myPassFilter[1]->SetInput(aDataSet);
+    myPassFilter[1]->Modified();
     myIsShrunk = false;
+    Modified();
   }
 }
 
-void VISU_Actor::SetVisibility(int theMode){
-  SALOME_Actor::SetVisibility(theMode);
+void VISU_Actor::SetShrinkable(bool theIsShrinkable){
+  myIsShrinkable = theIsShrinkable;
 }
 
-int VISU_Actor::GetVisibility(){
-  return SALOME_Actor::GetVisibility();
+void VISU_Actor::SetShrinkFactor(float theValue){
+  myShrinkFilter->SetShrinkFactor(theValue);
+  Modified();
 }
 
-void VISU_Actor::SetProperty(vtkProperty* theProperty){
-  SALOME_Actor::SetProperty(theProperty);
+float VISU_Actor::GetShrinkFactor(){
+  return myShrinkFilter->GetShrinkFactor();
 }
 
-vtkProperty* VISU_Actor::GetProperty(){
-  return SALOME_Actor::GetProperty();
+
+//----------------------------------------------------------------------------
+void VISU_Actor::SetVisibility(int theMode){
+  SALOME_Actor::SetVisibility(theMode);
+}
+
+int VISU_Actor::GetVisibility(){
+  return SALOME_Actor::GetVisibility();
 }
 
 void VISU_Actor::SetLineWidth(float theLineWidth){
@@ -205,6 +205,7 @@ float VISU_Actor::GetLineWidth(){
   return GetProperty()->GetLineWidth();
 }
 
+//----------------------------------------------------------------------------
 void VISU_Actor::ShallowCopy(vtkProp *prop){
   VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
   if(anActor != NULL){
@@ -214,21 +215,13 @@ void VISU_Actor::ShallowCopy(vtkProp *prop){
   SALOME_Actor::ShallowCopy(prop);
 }
 
-void VISU_Actor::highlight(Standard_Boolean highlight) {
-  if (this->IsHighlighting) {
-    if(highlight && !ishighlighted) {
-      ishighlighted=true;
-      this->SetProperty(HighlightProperty);
-    }else if (!highlight)
-      if(ishighlighted)        ishighlighted=false;
-  }
-}
-
-int VISU_Actor::GetObjId(int theVtkID){
-  if (GetRepresentation() == 0) return -1; // points    
-  return myGeomFilter->GetObjId(theVtkID);
+//----------------------------------------------------------------------------
+int VISU_Actor::GetNodeObjId(int theVtkID){
+  if ( myIsShrunk ) 
+    return myShrinkFilter->GetNodeObjId(theVtkID);
+  return theVtkID;
 }
 
-VISU_Actor::TVectorId VISU_Actor::GetVtkId(int theObjID){
-  return myGeomFilter->GetVtkId(theObjID);
+int VISU_Actor::GetElemObjId(int theVtkID){
+  return myGeomFilter->GetElemObjId(theVtkID);
 }