// Module : VISU
// $Header$
-using namespace std;
#include "VISU_Actor.h"
-#include "VISU_LookupTable.hxx"
-#include "VISU_ScalarBarActor.hxx"
+#include "VISU_PipeLine.hxx"
+#include "VTKViewer_ShrinkFilter.h"
+#include "VTKViewer_GeometryFilter.h"
+#include "VTKViewer_PassThroughFilter.h"
+#include <stdexcept>
+
// VTK Includes
-#include <vtkActor.h>
#include <vtkProperty.h>
+
+#include <vtkDataSet.h>
+#include <vtkPolyData.h>
+#include <vtkUnstructuredGrid.h>
+
+#include <vtkShrinkFilter.h>
#include <vtkShrinkPolyData.h>
-#include <vtkFeatureEdges.h>
+
+#include <vtkDataSetMapper.h>
+#include <vtkGeometryFilter.h>
#include <vtkObjectFactory.h>
-static int VISU_POINT_SIZE = 3;
+#include "utilities.h"
+
+using namespace std;
+
+static int MYVTKDEBUG = 0;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
//=======================================================================
-VISU_Actor* VISU_Actor::New(){
- vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_Actor");
- if(ret) return (VISU_Actor*)ret;
- return new VISU_Actor;
-}
+vtkStandardNewMacro(VISU_Actor);
VISU_Actor::VISU_Actor(){
- myIsShrunk = false;
- myIsShrinkable = false;
+ SetDebug(MYVTKDEBUG);
myParent = this;
+ myPipeLine = NULL;
myPrs3d = NULL;
+ myStoreMapping = true;
+
+ myIsShrunk = false;
+ myIsShrinkable = false;
+ 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);
}
VISU_Actor::~VISU_Actor(){
- HighlightProperty->Delete();
+ SALOME_Actor::SetProperty(NULL);
+
+ myMapper->RemoveAllInputs();
+ myMapper->Delete();
+
+ if(myPipeLine)
+ myPipeLine->UnRegister(this);
+
+ myShrinkFilter->UnRegisterAllOutputs();
+ myShrinkFilter->Delete();
}
void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
myName = theIO->getName();
}
-void VISU_Actor::setPrs3d(VISU::Prs3d_i* thePrs3d){
+void VISU_Actor::SetPrs3d(VISU::Prs3d_i* thePrs3d){
myPrs3d = thePrs3d;
}
+void VISU_Actor::SetPipeLine(VISU_PipeLine* thePipeLine) {
+ if (myPipeLine != thePipeLine){
+ if (myPipeLine != NULL) myPipeLine->UnRegister(this);
+ myPipeLine = thePipeLine;
+ if (myPipeLine != NULL) myPipeLine->Register(this);
+ this->Modified();
+ vtkMapper *aMapper = myPipeLine->GetMapper();
+ vtkDataSet *aDataSet = aMapper->GetInput();
+
+ //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(thePipeLine->IsShrinkable());
+ //Now, we use vtkShrinkPolyData (not vtkShrinkFilter),
+ //and the class there is no such limitation.
+
+ myMapper->SetInput(aDataSet);
+ SetMapper(myMapper);
+ }
+}
+
void VISU_Actor::SetParent(VISU_Actor* theParent){
myParent = theParent;
}
-void VISU_Actor::SetMapper(vtkMapper* theMapper){
- SALOME_Actor::SetMapper(theMapper);
+void VISU_Actor::SetRepresentation(int theMode) {
+ SALOME_Actor::SetRepresentation(theMode);
+ if(myRepresentation == VTK_POINTS)
+ UnShrink();
+}
+
+void VISU_Actor::SetOpacity(float theValue){
+ GetProperty()->SetOpacity(theValue);
+}
+
+float VISU_Actor::GetOpacity(){
+ return GetProperty()->GetOpacity();
+}
+
+
+void VISU_Actor::SetShrink(){
+ if(!myIsShrinkable) return;
+ if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
+ myShrinkFilter->SetInput(aDataSet);
+ myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
+ myIsShrunk = true;
+ }
+}
+
+void VISU_Actor::UnShrink(){
+ if(!myIsShrunk) return;
+ if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
+ myPassFilter[1]->SetInput(aDataSet);
+ myPassFilter[1]->Modified();
+ myIsShrunk = false;
+ Modified();
+ }
}
void VISU_Actor::SetShrinkable(bool theIsShrinkable){
myIsShrinkable = theIsShrinkable;
}
-void VISU_Actor::setShrink(float theFactor){
- if(!myIsShrinkable || myIsShrunk) return;
- vtkShrinkPolyData *aShrinkFilter = vtkShrinkPolyData::New();
- aShrinkFilter->SetShrinkFactor(theFactor);
- // use for post-filtering
- aShrinkFilter->SetInput(myPassFilter[2]->GetPolyDataOutput());
- myPassFilter[3]->SetInput(aShrinkFilter->GetOutput());
- myPassFilter[3]->Modified();
- aShrinkFilter->Delete();
- myIsShrunk = true;
+void VISU_Actor::SetShrinkFactor(float theValue){
+ myShrinkFilter->SetShrinkFactor(theValue);
+ Modified();
}
-void VISU_Actor::unShrink(){
- if(!myIsShrunk) return;
- myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
- myPassFilter[3]->Modified();
- myIsShrunk = false;
+float VISU_Actor::GetShrinkFactor(){
+ return myShrinkFilter->GetShrinkFactor();
}
+
+//----------------------------------------------------------------------------
void VISU_Actor::SetVisibility(int theMode){
SALOME_Actor::SetVisibility(theMode);
}
return SALOME_Actor::GetVisibility();
}
-void VISU_Actor::SetProperty(vtkProperty* theProperty){
- SALOME_Actor::SetProperty(theProperty);
-}
-
-vtkProperty* VISU_Actor::GetProperty(){
- return SALOME_Actor::GetProperty();
-}
-
void VISU_Actor::SetLineWidth(float theLineWidth){
GetProperty()->SetLineWidth(theLineWidth);
}
return GetProperty()->GetLineWidth();
}
-void VISU_Actor::SetRepresentation(int theMode) {
- GetProperty()->SetRepresentation(theMode);
- if(theMode == 0)
- GetProperty()->SetPointSize(VISU_POINT_SIZE);
-}
-
-int VISU_Actor::GetRepresentation(){
- return GetProperty()->GetRepresentation();
-}
-
+//----------------------------------------------------------------------------
void VISU_Actor::ShallowCopy(vtkProp *prop){
VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
if(anActor != NULL){
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;
- }
-}
-
-//=======================================================================
-
-VISUScalarMap_Actor* VISUScalarMap_Actor::New(){
- vtkObject* ret = vtkObjectFactory::CreateInstance("VISUScalarMap_Actor");
- if(ret) return (VISUScalarMap_Actor*)ret;
- return new VISUScalarMap_Actor;
-}
-
-VISUScalarMap_Actor::VISUScalarMap_Actor(){
- myScalarBar = VISU_ScalarBarActor::New();
- GetProperty()->FrontfaceCullingOff();
- GetProperty()->BackfaceCullingOff();
-}
-
-VISUScalarMap_Actor::~VISUScalarMap_Actor(){
- myScalarBar->Delete();
-}
-
-void VISUScalarMap_Actor::AddToRender(vtkRenderer* theRenderer){
- SALOME_Actor::AddToRender(theRenderer);
- if(myScalarBar)
- theRenderer->AddActor2D(myScalarBar);
+//----------------------------------------------------------------------------
+int VISU_Actor::GetNodeObjId(int theVtkID){
+ if ( myIsShrunk )
+ return myShrinkFilter->GetNodeObjId(theVtkID);
+ return theVtkID;
}
-void VISUScalarMap_Actor::RemoveFromRender(vtkRenderer* theRenderer){
- SALOME_Actor::RemoveFromRender(theRenderer);
- if(myScalarBar)
- theRenderer->RemoveActor(myScalarBar);
+int VISU_Actor::GetElemObjId(int theVtkID){
+ return myGeomFilter->GetElemObjId(theVtkID);
}
-
-void VISUScalarMap_Actor::SetVisibility(int theMode){
- SALOME_Actor::SetVisibility(theMode);
- if(myScalarBar) myScalarBar->SetVisibility(*myBarVisibility && theMode);
-}
-
-int VISUScalarMap_Actor::GetVisibility(){
- return SALOME_Actor::GetVisibility();
-}
-
-void VISUScalarMap_Actor::SetBarVisibility(const bool* theMode){
- myBarVisibility = theMode;
- if(myScalarBar) myScalarBar->SetVisibility(*myBarVisibility);
-}
-
-//=======================================================================
-
-VISUMesh_Actor* VISUMesh_Actor::New(){
- vtkObject* ret = vtkObjectFactory::CreateInstance("VISUMesh_Actor");
- if(ret) return (VISUMesh_Actor*)ret;
- return new VISUMesh_Actor;
-}
-
-VISUMesh_Actor::VISUMesh_Actor(){
- myEdgeMapper = vtkPolyDataMapper::New();
- mySurfaceActor = VISU_Actor::New();
- mySurfaceActor->SetParent(this);
- mySurfaceActor->GetProperty()->SetPointSize(VISU_POINT_SIZE);
- mySurfaceActor->GetProperty()->FrontfaceCullingOff();
- mySurfaceActor->GetProperty()->BackfaceCullingOff();
- mySurfaceActor->SetRepresentation(2);
-
- myEdgeActor = VISU_Actor::New();
- myEdgeActor->SetParent(this);
- myEdgeActor->PickableOff();
- myEdgeActor->GetProperty()->SetPointSize(VISU_POINT_SIZE);
- myEdgeActor->GetProperty()->FrontfaceCullingOff();
- myEdgeActor->GetProperty()->BackfaceCullingOff();
- myEdgeActor->SetRepresentation(2);
-
- myRepresentation = 2; //SURFACE
- myVisibility = 1; //On
-}
-
-VISUMesh_Actor::~VISUMesh_Actor(){
- myEdgeMapper->Delete();
- mySurfaceActor->Delete();
- myEdgeActor->Delete();
-}
-
-void VISUMesh_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
- mySurfaceActor->setIO(theIO);
- myEdgeActor->setIO(theIO);
-}
-
-void VISUMesh_Actor::setPrs3d(VISU::Prs3d_i* thePrs3d){
- if(thePrs3d){
- VISU_Actor::setPrs3d(thePrs3d);
- mySurfaceActor->setPrs3d(thePrs3d);
- myEdgeActor->setPrs3d(thePrs3d);
- }
-}
-
-void VISUMesh_Actor::AddToRender(vtkRenderer* theRenderer){
- theRenderer->AddActor(mySurfaceActor);
- theRenderer->AddActor(myEdgeActor);
-}
-
-void VISUMesh_Actor::RemoveFromRender(vtkRenderer* theRenderer){
- theRenderer->RemoveActor(mySurfaceActor);
- theRenderer->RemoveActor(myEdgeActor);
-}
-
-void VISUMesh_Actor::SetMapper(vtkMapper* theMapper){
- VISU_Actor::SetMapper(theMapper);
- SALOME_PassThroughFilter* aPassFilter = SALOME_PassThroughFilter::New();
- aPassFilter->SetInput(theMapper->GetInput());
- vtkFeatureEdges *aFeatureEdges = vtkFeatureEdges::New();
- aFeatureEdges->SetInput(aPassFilter->GetPolyDataOutput());
- aFeatureEdges->BoundaryEdgesOn();
- aFeatureEdges->ManifoldEdgesOn();
- myEdgeMapper->SetInput(aFeatureEdges->GetOutput());
- aFeatureEdges->Delete();
- myEdgeMapper->ScalarVisibilityOff();
- myEdgeActor->SetMapper(myEdgeMapper);
- mySurfaceActor->SetMapper(theMapper);
-}
-
-void VISUMesh_Actor::SetTransform(SALOME_Transform* theTransform){
- mySurfaceActor->SetTransform(theTransform);
- myEdgeActor->SetTransform(theTransform);
-}
-
-void VISUMesh_Actor::SetShrinkable(bool theIsShrinkable){
- myIsShrinkable = theIsShrinkable;
- myEdgeActor->SetShrinkable(myIsShrinkable);
- mySurfaceActor->SetShrinkable(myIsShrinkable);
-}
-
-vtkProperty* VISUMesh_Actor::GetProperty(){
- mySurfaceActor->GetProperty();
-}
-
-void VISUMesh_Actor::SetProperty(vtkProperty* theProperty){
- mySurfaceActor->SetProperty(theProperty);
-}
-
-vtkProperty* VISUMesh_Actor::GetEdgeProperty(){
- myEdgeActor->GetProperty();
-}
-
-void VISUMesh_Actor::SetEdgeProperty(vtkProperty* theProperty){
- myEdgeActor->SetProperty(theProperty);
-}
-
-void VISUMesh_Actor::SetLineWidth(float theLineWidth){
- GetProperty()->SetLineWidth(theLineWidth);
- GetEdgeProperty()->SetLineWidth(theLineWidth);
-}
-
-float VISUMesh_Actor::GetLineWidth(){
- return GetProperty()->GetLineWidth();
-}
-
-void VISUMesh_Actor::setShrink(float theFactor){
- if(!myIsShrinkable || myIsShrunk || myRepresentation == 0) return;
- mySurfaceActor->setShrink(theFactor);
- myIsShrunk = true;
- SetRepresentation(myRepresentation);
-}
-
-void VISUMesh_Actor::unShrink(){
- if(!myIsShrunk) return;
- mySurfaceActor->unShrink();
- myIsShrunk = false;
- SetRepresentation(myRepresentation);
-}
-
-void VISUMesh_Actor::SetRepresentation(int theMode){
- if(theMode < 0 || theMode >2) return;
- myRepresentation = theMode;
- myEdgeActor->SetRepresentation(2);
- mySurfaceActor->SetRepresentation(myRepresentation);
- switch(theMode){
- case 0: //POINTS
- myEdgeActor->VisibilityOff();
- mySurfaceActor->VisibilityOn();
- break;
- case 1: //WIREFRAME
- myEdgeActor->VisibilityOff();
- mySurfaceActor->VisibilityOn();
- break;
- case 2: //SURFACE
- myEdgeActor->SetVisibility(!myIsShrunk);
- mySurfaceActor->VisibilityOn();
- break;
- }
- myRepresentation = theMode;
-}
-
-void VISUMesh_Actor::SetVisibility(int theMode){
- SetRepresentation(myRepresentation);
- myEdgeActor->SetVisibility(theMode);
- mySurfaceActor->SetVisibility(theMode);
- myVisibility = theMode;
-}
-
-//=======================================================================
-