From d6d9b55f418d15d9f11933fccfbaf00ad77a4643 Mon Sep 17 00:00:00 2001 From: apo Date: Wed, 21 Dec 2005 14:35:34 +0000 Subject: [PATCH] Fix for the Bug GVIEW10975 opacity forgotten --- src/SVTK/Makefile.in | 2 + src/SVTK/SVTK_Actor.cxx | 65 +----- src/SVTK/SVTK_Actor.h | 34 +-- src/SVTK/SVTK_DeviceActor.cxx | 419 ++++++++++++++++++++++++++++++++++ src/SVTK/SVTK_DeviceActor.h | 209 +++++++++++++++++ 5 files changed, 643 insertions(+), 86 deletions(-) create mode 100644 src/SVTK/SVTK_DeviceActor.cxx create mode 100644 src/SVTK/SVTK_DeviceActor.h diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index 73ac9bfe4..e60c3cc24 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -17,6 +17,7 @@ EXPORT_HEADERS= \ SVTK_Prs.h \ SVTK_Actor.h \ SALOME_Actor.h \ + SVTK_DeviceActor.h \ SVTK_FontWidget.h \ SVTK_CubeAxesActor2D.h \ SVTK_Functor.h \ @@ -43,6 +44,7 @@ LIB_SRC= \ SVTK_Prs.cxx \ SVTK_Actor.cxx \ SALOME_Actor.cxx \ + SVTK_DeviceActor.cxx \ SVTK_CubeAxesActor2D.cxx \ SVTK_NonIsometricDlg.cxx \ SVTK_CubeAxesDlg.cxx \ diff --git a/src/SVTK/SVTK_Actor.cxx b/src/SVTK/SVTK_Actor.cxx index f78ecc1e8..d68c772f7 100644 --- a/src/SVTK/SVTK_Actor.cxx +++ b/src/SVTK/SVTK_Actor.cxx @@ -18,8 +18,7 @@ // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org #include "SVTK_Actor.h" - -#include "VTKViewer_PassThroughFilter.h" +#include "SALOME_Actor.h" // VTK Includes #include @@ -29,7 +28,6 @@ #include #include -#include #include "utilities.h" @@ -66,21 +64,12 @@ SVTK_Actor { if(MYDEBUG) INFOS("SVTK_Actor - "<Delete(); myUnstructuredGrid->Allocate(); - - myIsShrunk = false; - myIsShrinkable = true; - myShrinkFilter = vtkShrinkFilter::New(); - - myMapper = vtkDataSetMapper::New(); - - SetResolveCoincidentTopology(false); } //---------------------------------------------------------------------------- @@ -88,8 +77,7 @@ void SVTK_Actor ::Initialize() { - myMapper->SetInput(GetSource()); - Superclass::InitPipeLine(myMapper); + SetInput(GetSource()); } @@ -103,11 +91,7 @@ SVTK_Actor myUnstructuredGrid = theUnstructuredGrid; - myMapper->SetInput(theUnstructuredGrid); - - Superclass::InitPipeLine(myMapper); - - Modified(); + SetInput(theUnstructuredGrid); } vtkUnstructuredGrid* @@ -118,52 +102,11 @@ SVTK_Actor } -//---------------------------------------------------------------------------- -void -SVTK_Actor -::SetShrinkFactor(float theValue) -{ - myShrinkFilter->SetShrinkFactor(theValue); - Modified(); -} - -void -SVTK_Actor -::SetShrink() -{ - if ( !myIsShrinkable ) return; - if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) - { - myShrinkFilter->SetInput( aDataSet ); - myPassFilter[1]->SetInput( myShrinkFilter->GetOutput() ); - myIsShrunk = true; - } -} - -void -SVTK_Actor -::UnShrink() -{ - if ( !myIsShrunk ) return; - if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) - { - myPassFilter[1]->SetInput( aDataSet ); - myPassFilter[1]->Modified(); - myIsShrunk = false; - Modified(); - } -} - - //---------------------------------------------------------------------------- SVTK_Actor ::~SVTK_Actor() { if(MYDEBUG) INFOS("~SVTK_Actor()"); - - myMapper->Delete(); - - myShrinkFilter->Delete(); } diff --git a/src/SVTK/SVTK_Actor.h b/src/SVTK/SVTK_Actor.h index cfb4d4b94..9d1dcb224 100644 --- a/src/SVTK/SVTK_Actor.h +++ b/src/SVTK/SVTK_Actor.h @@ -28,17 +28,19 @@ class vtkDataSetMapper; class vtkUnstructuredGrid; #include "SVTK.h" -#include "SALOME_Actor.h" +#include "SVTK_DeviceActor.h" + +#include + +class SALOME_Actor; //! This class used for internal SVTK package purpose (highlight and prehighlight) -class SVTK_EXPORT SVTK_Actor : public VTKViewer_Actor +class SVTK_EXPORT SVTK_Actor : public SVTK_DeviceActor { public: - virtual ~SVTK_Actor(); - static SVTK_Actor* New(); - vtkTypeMacro(SVTK_Actor,VTKViewer_Actor); + vtkTypeMacro(SVTK_Actor,SVTK_DeviceActor); //! Initialiaze the instance completely void @@ -52,20 +54,6 @@ public: vtkUnstructuredGrid* GetSource(); - //! To manage shrink functionality - void - SetShrinkFactor(float value); - - //! To manage shrink functionality - virtual - void - SetShrink(); - - //! To manage shrink functionality - virtual - void - UnShrink(); - //! Allow to recostruct selected cells from source SALOME_Actor and map of subindexes void MapCells(SALOME_Actor* theMapActor, @@ -88,14 +76,10 @@ public: TColStd_IndexedMapOfInteger myMapIndex; vtkSmartPointer myUnstructuredGrid; - vtkDataSetMapper* myMapper; - vtkRenderer* myRenderer; - - vtkShrinkFilter* myShrinkFilter; - bool myIsShrinkable; - bool myIsShrunk; SVTK_Actor(); + virtual + ~SVTK_Actor(); }; #endif diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx new file mode 100644 index 000000000..6ae876108 --- /dev/null +++ b/src/SVTK/SVTK_DeviceActor.cxx @@ -0,0 +1,419 @@ +// SVTK OBJECT : interactive object for SVTK visualization +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_DeviceActor.cxx +// Author : +// Module : +// $Header$ + + +#include "SVTK_DeviceActor.h" + +#include "VTKViewer_Transform.h" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_GeometryFilter.h" + +// VTK Includes +#include +#include + +#include +#include + +#include +#include + +using namespace std; + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_DeviceActor); + + +//---------------------------------------------------------------------------- +SVTK_DeviceActor +::SVTK_DeviceActor() +{ + myIsShrunk = false; + myIsShrinkable = true; + + myIsShaded = false; + myProperty = vtkProperty::New(); + myRepresentation = SVTK::Representation::Surface; + + myIsResolveCoincidentTopology = false; + vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, + myPolygonOffsetUnits); + + myMapper = vtkDataSetMapper::New(); + + myShrinkFilter = vtkShrinkFilter::New(); + + myGeomFilter = VTKViewer_GeometryFilter::New(); + + myTransformFilter = VTKViewer_TransformFilter::New(); + + for(int i = 0; i < 6; i++) + myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); +} + + +//---------------------------------------------------------------------------- +SVTK_DeviceActor +::~SVTK_DeviceActor() +{ + myMapper->Delete(); + + myProperty->Delete(); + + myGeomFilter->Delete(); + + myTransformFilter->Delete(); + + myShrinkFilter->Delete(); + + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) + myPassFilter[i]->Delete(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::SetMapper(vtkMapper* theMapper) +{ + InitPipeLine(theMapper); +} + +void +SVTK_DeviceActor +::InitPipeLine(vtkMapper* theMapper) +{ + if(theMapper){ + int anId = 0; + myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); + myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 1 + myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 2 + myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); + myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 3 + myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + + anId++; // 4 + myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); + myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 5 + if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)){ + aMapper->SetInput(myPassFilter[anId]->GetOutput()); + }else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)){ + aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); + } + }else + myPassFilter[ 0 ]->SetInput( NULL ); + Superclass::SetMapper(theMapper); +} + +//---------------------------------------------------------------------------- +vtkDataSet* +SVTK_DeviceActor +::GetInput() +{ + return myPassFilter.front()->GetOutput(); +} + +void +SVTK_DeviceActor +::SetInput(vtkDataSet* theDataSet) +{ + myMapper->SetInput(theDataSet); + InitPipeLine(myMapper); +} + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor:: +SetStoreMapping(bool theStoreMapping) +{ + myGeomFilter->SetStoreMapping(theStoreMapping); +} + + + +//---------------------------------------------------------------------------- +unsigned long int +SVTK_DeviceActor +::GetMTime() +{ + unsigned long mTime = this->Superclass::GetMTime(); + + mTime = max(mTime,myGeomFilter->GetMTime()); + + mTime = max(mTime,myTransformFilter->GetMTime()); + + if(myIsShrunk) + mTime = max(mTime,myShrinkFilter->GetMTime()); + + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) + max(mTime,myPassFilter[i]->GetMTime()); + + return mTime; +} + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::SetTransform(VTKViewer_Transform* theTransform) +{ + myTransformFilter->SetTransform(theTransform); +} + + +//---------------------------------------------------------------------------- +bool +SVTK_DeviceActor +::IsShrunkable() +{ + return myIsShrinkable; +} + +void +SVTK_DeviceActor +::SetShrinkable(bool theIsShrinkable) +{ + myIsShrinkable = theIsShrinkable; +} + +bool +SVTK_DeviceActor +::IsShrunk() +{ + return myIsShrunk; +} + +void +SVTK_DeviceActor +::SetShrink() +{ + if ( !myIsShrinkable ) + return; + if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + { + myShrinkFilter->SetInput( aDataSet ); + myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() ); + myIsShrunk = true; + } +} + +void +SVTK_DeviceActor +::UnShrink() +{ + if ( !myIsShrunk ) return; + if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + { + myPassFilter[ 1 ]->SetInput( aDataSet ); + myIsShrunk = false; + } +} + +float +SVTK_DeviceActor +::GetShrinkFactor() +{ + return myShrinkFilter->GetShrinkFactor(); +} + +void +SVTK_DeviceActor +::SetShrinkFactor(float theValue) +{ + myShrinkFilter->SetShrinkFactor(theValue); +} + + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::SetRepresentation(SVTK::Representation::Type theMode) +{ + using namespace SVTK::Representation; + if(IsShaded()){ + switch(myRepresentation){ + case Points : + case Wireframe : + myProperty->DeepCopy(GetProperty()); + } + + switch(theMode){ + case Points : + case Wireframe : + GetProperty()->DeepCopy(myProperty); + break; + default: + GetProperty()->SetAmbient(1.0); + GetProperty()->SetDiffuse(0.0); + GetProperty()->SetSpecular(0.0); + } + } + + switch(theMode){ + case Insideframe : + myGeomFilter->SetInside(true); + myGeomFilter->SetWireframeMode(true); + GetProperty()->SetRepresentation(1); + break; + case Points : + GetProperty()->SetPointSize(GetDefaultPointSize()); + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; + case Wireframe : + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(true); + myGeomFilter->SetInside(false); + break; + case Surface : + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetWireframeMode(false); + myGeomFilter->SetInside(false); + break; + } + + myRepresentation = theMode; +} + +SVTK::Representation::Type +SVTK_DeviceActor +::GetRepresentation() +{ + return myRepresentation; +} + +float +SVTK_DeviceActor +::GetDefaultPointSize() +{ + return 5; +} + +float +SVTK_DeviceActor +::GetDefaultLineWidth() +{ + return 3; +} + + +bool +SVTK_DeviceActor +::IsShaded() +{ + return myIsShaded; +} + +void +SVTK_DeviceActor +::SetShaded(bool theShaded) +{ + myIsShaded = theShaded; +} + + +//---------------------------------------------------------------------------- +int +SVTK_DeviceActor +::GetNodeObjId(int theVtkID) +{ + return theVtkID; +} + +float* +SVTK_DeviceActor +::GetNodeCoord(int theObjID) +{ + return GetInput()->GetPoint(theObjID); +} + + +vtkCell* +SVTK_DeviceActor +::GetElemCell(int theObjID) +{ + return GetInput()->GetCell(theObjID); +} + +int +SVTK_DeviceActor +::GetElemObjId(int theVtkID) +{ + return theVtkID; +} + + +//---------------------------------------------------------------------------- +void +SVTK_DeviceActor +::Render(vtkRenderer *ren, vtkMapper* m) +{ + if(myIsResolveCoincidentTopology){ + int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); + float aFactor, aUnit; + vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); + + vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); + vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, + myPolygonOffsetUnits); + Superclass::Render(ren,m); + + vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); + vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); + }else{ + Superclass::Render(ren,m); + } +} + + +void +SVTK_DeviceActor +::SetPolygonOffsetParameters(float factor, float units) +{ + myPolygonOffsetFactor = factor; + myPolygonOffsetUnits = units; +} + +void +SVTK_DeviceActor +::GetPolygonOffsetParameters(float& factor, float& units) +{ + factor = myPolygonOffsetFactor; + units = myPolygonOffsetUnits; +} diff --git a/src/SVTK/SVTK_DeviceActor.h b/src/SVTK/SVTK_DeviceActor.h new file mode 100644 index 000000000..f8a49bc36 --- /dev/null +++ b/src/SVTK/SVTK_DeviceActor.h @@ -0,0 +1,209 @@ +// SVTK OBJECT : interactive object for SVTK visualization +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_DeviceActor.h +// Author : +// Module : +// $Header$ + +#ifndef SVTK_DEVICE_ACTOR_H +#define SVTK_DEVICE_ACTOR_H + +#include + +#include +#include + +class VTKViewer_Transform; +class VTKViewer_TransformFilter; +class VTKViewer_PassThroughFilter; +class VTKViewer_GeometryFilter; + +class vtkCell; +class vtkDataSet; +class vtkShrinkFilter; +class vtkDataSetMapper; + +//---------------------------------------------------------------------------- +namespace SVTK +{ + namespace Representation + { + typedef int Type; + const Type Points = VTK_POINTS; + const Type Wireframe = VTK_WIREFRAME; + const Type Surface = VTK_SURFACE; + const Type Insideframe = Surface + 1; + } +} + + +//---------------------------------------------------------------------------- +class SVTK_DeviceActor: public vtkLODActor +{ + public: + vtkTypeMacro(SVTK_DeviceActor,vtkLODActor); + + static + SVTK_DeviceActor* + New(); + + //! Apply a view transformation + virtual + void + SetTransform(VTKViewer_Transform* theTransform); + + //! To insert some additional filters and then sets the given #vtkMapper + virtual + void + SetMapper(vtkMapper* theMapper); + + //! Allows to get initial #vtkDataSet + virtual + vtkDataSet* + GetInput(); + + //! Allows to set initial #vtkDataSet + virtual + void + SetInput(vtkDataSet* theDataSet); + + /** @name For selection mapping purpose */ + //@{ + virtual + int + GetNodeObjId(int theVtkID); + + virtual + float* + GetNodeCoord(int theObjID); + + virtual + int + GetElemObjId(int theVtkID); + + virtual + vtkCell* + GetElemCell(int theObjID); + + //! To provide VTK to Object and backward mapping + virtual + void + SetStoreMapping(bool theStoreMapping); + //@} + + virtual + unsigned long int + GetMTime(); + + /** @name For shrink mamnagement purpose */ + //@{ + float + GetShrinkFactor(); + + virtual + void + SetShrinkFactor(float value); + + virtual + void + SetShrinkable(bool theIsShrinkable); + + bool + IsShrunkable(); + + bool + IsShrunk(); + + virtual + void + SetShrink(); + + virtual + void + UnShrink(); + //@} + + /** @name For representation mamnagement purpose */ + virtual + void + SetRepresentation(SVTK::Representation::Type theMode); + + SVTK::Representation::Type + GetRepresentation(); + + virtual + float + GetDefaultPointSize(); + + virtual + float + GetDefaultLineWidth(); + + bool + IsShaded(); + + void + SetShaded(bool theShaded); + //@} + + virtual + void + Render(vtkRenderer *, vtkMapper *); + + protected: + SVTK::Representation::Type myRepresentation; + vtkProperty *myProperty; + bool myIsShaded; + + //! To initialize internal pipeline + void + InitPipeLine(vtkMapper* theMapper); + + VTKViewer_GeometryFilter *myGeomFilter; + VTKViewer_TransformFilter *myTransformFilter; + std::vector myPassFilter; + vtkShrinkFilter* myShrinkFilter; + vtkDataSetMapper* myMapper; + + bool myIsShrinkable; + bool myIsShrunk; + + bool myIsResolveCoincidentTopology; + float myPolygonOffsetFactor; + float myPolygonOffsetUnits; + + void SetPolygonOffsetParameters(float factor, float units); + void GetPolygonOffsetParameters(float& factor, float& units); + + SVTK_DeviceActor(); + ~SVTK_DeviceActor(); + + private: + SVTK_DeviceActor(const SVTK_DeviceActor&); // Not implemented + void operator=(const SVTK_DeviceActor&); // Not implemented + +}; + + +#endif //SVTK_DEVICE_ACTOR_H -- 2.39.2