From 9eacabb3444deacabf15a12647681bd6849f1c07 Mon Sep 17 00:00:00 2001 From: mkr Date: Thu, 12 Jan 2012 16:21:55 +0000 Subject: [PATCH] Fix for PAL21179: 1) draw outlines (borders) of the shapes, 2) material properties. --- src/SVTK/SVTK_DeviceActor.cxx | 11 ++- src/SVTK/SVTK_DeviceActor.h | 19 +--- src/SVTK/SVTK_View.cxx | 94 ++++++++++++++++++- src/SVTK/SVTK_View.h | 23 +++++ src/VTKViewer/VTKViewer_Actor.cxx | 53 +++++++++-- src/VTKViewer/VTKViewer_Actor.h | 29 ++++++ .../VTKViewer_RenderWindowInteractor.cxx | 26 ++++- .../VTKViewer_RenderWindowInteractor.h | 2 + 8 files changed, 226 insertions(+), 31 deletions(-) diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx index a02db5ce9..c8dd1484c 100644 --- a/src/SVTK/SVTK_DeviceActor.cxx +++ b/src/SVTK/SVTK_DeviceActor.cxx @@ -63,7 +63,7 @@ SVTK_DeviceActor myIsShaded = true; myProperty = vtkProperty::New(); - myRepresentation = SVTK::Representation::Surface; + myRepresentation = VTKViewer::Representation::Surface; myIsResolveCoincidentTopology = true; vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, @@ -458,13 +458,14 @@ SVTK_DeviceActor */ void SVTK_DeviceActor -::SetRepresentation(SVTK::Representation::Type theMode) +::SetRepresentation(VTKViewer::Representation::Type theMode) { - using namespace SVTK::Representation; + using namespace VTKViewer::Representation; if(IsShaded()){ switch(myRepresentation){ case Points : case Surface : + case SurfaceWithEdges : myProperty->SetAmbient(GetProperty()->GetAmbient()); myProperty->SetDiffuse(GetProperty()->GetDiffuse()); myProperty->SetSpecular(GetProperty()->GetSpecular()); @@ -473,6 +474,7 @@ SVTK_DeviceActor switch(theMode){ case Points : case Surface : + case SurfaceWithEdges : GetProperty()->SetAmbient(myProperty->GetAmbient()); GetProperty()->SetDiffuse(myProperty->GetDiffuse()); GetProperty()->SetSpecular(myProperty->GetSpecular()); @@ -502,6 +504,7 @@ SVTK_DeviceActor myGeomFilter->SetInside(false); break; case Surface : + case SurfaceWithEdges : GetProperty()->SetRepresentation(VTK_SURFACE); myGeomFilter->SetWireframeMode(false); myGeomFilter->SetInside(false); @@ -516,7 +519,7 @@ SVTK_DeviceActor /*! \return current representation mode */ -SVTK::Representation::Type +VTKViewer::Representation::Type SVTK_DeviceActor ::GetRepresentation() { diff --git a/src/SVTK/SVTK_DeviceActor.h b/src/SVTK/SVTK_DeviceActor.h index 0215bcefd..c4ef4cd6d 100644 --- a/src/SVTK/SVTK_DeviceActor.h +++ b/src/SVTK/SVTK_DeviceActor.h @@ -31,6 +31,7 @@ #include "SVTK.h" #include "VTKViewer.h" +#include "VTKViewer_Actor.h" #include "VTKViewer_MarkerDef.h" #include @@ -49,18 +50,6 @@ class vtkFeatureEdges; class VTKViewer_DataSetMapper; class vtkPassThroughFilter; -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; - } -} - #ifdef WIN32 #pragma warning ( disable:4251 ) #endif @@ -201,9 +190,9 @@ class SVTK_EXPORT SVTK_DeviceActor: public vtkLODActor /** @name For representation mamnagement purpose */ virtual void - SetRepresentation(SVTK::Representation::Type theMode); + SetRepresentation(VTKViewer::Representation::Type theMode); - SVTK::Representation::Type + VTKViewer::Representation::Type GetRepresentation(); virtual @@ -256,7 +245,7 @@ class SVTK_EXPORT SVTK_DeviceActor: public vtkLODActor virtual vtkFloatingPointType GetQuadraticArcAngle(); protected: - SVTK::Representation::Type myRepresentation; + VTKViewer::Representation::Type myRepresentation; vtkProperty *myProperty; bool myIsShaded; diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index b27096c50..0b00015ce 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -39,6 +39,7 @@ #include #include +#include /*! Constructor @@ -359,8 +360,12 @@ SVTK_View { if(theMode == 0) ChangeRepresentationToWireframe(); - else + else if (theMode == 1) ChangeRepresentationToSurface(); + else if (theMode == 2) { + ChangeRepresentationToSurfaceWithEdges(); + theMode++; + } myDisplayMode = theMode; } @@ -404,6 +409,17 @@ SVTK_View ChangeRepresentationToSurface(aCopy.GetActors()); } +/*! + Change all actors to shading with edges +*/ +void +SVTK_View +::ChangeRepresentationToSurfaceWithEdges() +{ + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ChangeRepresentationToSurfaceWithEdges(aCopy.GetActors()); +} + /*! Change to wireframe a list of vtkactor theCollection - list of vtkactor @@ -434,6 +450,21 @@ SVTK_View Repaint(); } +/*! + Change to shading with edges a list of vtkactor + theCollection - list of vtkactor +*/ +void +SVTK_View +::ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* theCollection) +{ + using namespace SVTK; + ForEach(theCollection, + TSetFunction + (&SALOME_Actor::setDisplayMode,3)); + Repaint(); +} + namespace SVTK { struct TErase @@ -714,6 +745,67 @@ SVTK_View return QColor(0,0,0); } +/*! + Change material + \param theIObject - object + \param thePropF - property contained new properties of front material + \param thePropB - property contained new properties of back material +*/ +void +SVTK_View +::SetMaterial(const Handle(SALOME_InteractiveObject)& theIObject, + vtkProperty* thePropF, + vtkProperty* thePropB) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + std::vector aProps; + aProps.push_back( thePropF ); + aProps.push_back( thePropB ); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TSetFunction > + (&SALOME_Actor::SetMaterial,aProps)); +} + +/*! + Get current front material + \param theIObject - object + \return property contained front material properties of the given object +*/ +vtkProperty* +SVTK_View +::GetFrontMaterial(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + SALOME_Actor* anActor = + Find(aCopy.GetActors(), + TIsSameIObject(theIObject)); + if(anActor) + return anActor->GetFrontMaterial(); + return NULL; +} + +/*! + Get current back material + \param theIObject - object + \return property contained back material properties of the given object +*/ +vtkProperty* +SVTK_View +::GetBackMaterial(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + SALOME_Actor* anActor = + Find(aCopy.GetActors(), + TIsSameIObject(theIObject)); + if(anActor) + return anActor->GetBackMaterial(); + return NULL; +} + /*! \Collect objects visible in viewer \param theList - visible objects collection diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 098f490d9..cff14c922 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -36,6 +36,7 @@ class vtkActorCollection; class vtkRenderer; +class vtkProperty; class SVTK_ViewWindow; class SVTK_Renderer; @@ -174,6 +175,10 @@ public: void ChangeRepresentationToSurface(); + //! Change all actors to surface with edges + void + ChangeRepresentationToSurfaceWithEdges(); + //! Change to wireframe a list of vtkactor void ChangeRepresentationToWireframe(vtkActorCollection* theListofActors); @@ -182,6 +187,10 @@ public: void ChangeRepresentationToSurface(vtkActorCollection* theListofActors); + //! Change to surface with edges a list of vtkactor + void + ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* theListofActors); + //! Change transparency void SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, @@ -200,6 +209,20 @@ public: QColor GetColor(const Handle(SALOME_InteractiveObject)& theIObject); + //! Change material + void + SetMaterial(const Handle(SALOME_InteractiveObject)& theIObject, + vtkProperty* thePropF, + vtkProperty* thePropB); + + //! Get current front material + vtkProperty* + GetFrontMaterial(const Handle(SALOME_InteractiveObject)& theIObject); + + //! Get current back material + vtkProperty* + GetBackMaterial(const Handle(SALOME_InteractiveObject)& theIObject); + //---------------------------------------------------------------------------- // Erase Display functions //! To erase all existing VTK presentations diff --git a/src/VTKViewer/VTKViewer_Actor.cxx b/src/VTKViewer/VTKViewer_Actor.cxx index cf9244565..d5c9a6603 100755 --- a/src/VTKViewer/VTKViewer_Actor.cxx +++ b/src/VTKViewer/VTKViewer_Actor.cxx @@ -44,7 +44,6 @@ #include #include #include -#include #include #include @@ -70,7 +69,7 @@ VTKViewer_Actor myOpacity(1.0), myIsHighlighted(false), myIsPreselected(false), - myRepresentation(VTK_SURFACE), + myRepresentation(VTKViewer::Representation::Surface), myDisplayMode(1), myProperty(vtkProperty::New()), PreviewProperty(NULL), @@ -363,9 +362,11 @@ void VTKViewer_Actor ::SetRepresentation(int theMode) { + using namespace VTKViewer::Representation; switch(myRepresentation){ - case VTK_POINTS : - case VTK_SURFACE : + case Points : + case Surface : + case SurfaceWithEdges : myProperty->SetAmbient(GetProperty()->GetAmbient()); myProperty->SetDiffuse(GetProperty()->GetDiffuse()); myProperty->SetSpecular(GetProperty()->GetSpecular()); @@ -373,8 +374,9 @@ VTKViewer_Actor } switch(theMode){ - case VTK_POINTS : - case VTK_SURFACE : + case Points : + case Surface : + case SurfaceWithEdges : GetProperty()->SetAmbient(myProperty->GetAmbient()); GetProperty()->SetDiffuse(myProperty->GetDiffuse()); GetProperty()->SetSpecular(myProperty->GetSpecular()); @@ -386,23 +388,24 @@ VTKViewer_Actor } switch(theMode){ - case 3 : + case Insideframe : myGeomFilter->SetInside(true); myGeomFilter->SetWireframeMode(true); GetProperty()->SetRepresentation(VTK_WIREFRAME); break; - case VTK_POINTS : + case Points : GetProperty()->SetPointSize(VTKViewer_POINT_SIZE); GetProperty()->SetRepresentation(theMode); myGeomFilter->SetWireframeMode(false); myGeomFilter->SetInside(false); break; - case VTK_WIREFRAME : + case Wireframe : GetProperty()->SetRepresentation(theMode); myGeomFilter->SetWireframeMode(true); myGeomFilter->SetInside(false); break; - case VTK_SURFACE : + case Surface : + case SurfaceWithEdges : GetProperty()->SetRepresentation(theMode); myGeomFilter->SetWireframeMode(false); myGeomFilter->SetInside(false); @@ -613,6 +616,36 @@ VTKViewer_Actor } +/*! + Change material +*/ +void +VTKViewer_Actor +::SetMaterial(std::vector theProps) +{ +} + +/*! + Get current front material +*/ +vtkProperty* +VTKViewer_Actor +::GetFrontMaterial() +{ + return NULL; +} + +/*! + Get current back material +*/ +vtkProperty* +VTKViewer_Actor +::GetBackMaterial() +{ + return NULL; +} + + /*! \return display mode */ diff --git a/src/VTKViewer/VTKViewer_Actor.h b/src/VTKViewer/VTKViewer_Actor.h index 83b705fa6..e2d026211 100755 --- a/src/VTKViewer/VTKViewer_Actor.h +++ b/src/VTKViewer/VTKViewer_Actor.h @@ -35,6 +35,7 @@ #include #include +#include class vtkCell; class vtkPointPicker; @@ -52,6 +53,19 @@ class VTKViewer_TransformFilter; extern int VTKViewer_POINT_SIZE; extern int VTKViewer_LINE_WIDTH; +namespace VTKViewer +{ + 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; + const Type SurfaceWithEdges = Insideframe + 1; + } +} + #ifdef WIN32 #pragma warning ( disable:4251 ) #endif @@ -107,6 +121,21 @@ class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor void SetColor(const vtkFloatingPointType theRGB[3]); + //! Change material + virtual + void + SetMaterial(std::vector theProps); + + //! Get current front material + virtual + vtkProperty* + GetFrontMaterial(); + + //! Get current back material + virtual + vtkProperty* + GetBackMaterial(); + //---------------------------------------------------------------------------- // For selection mapping purpose //! Maps VTK index of a node to corresponding object index diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index 3053a9a12..3009d35fd 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -491,8 +491,12 @@ int VTKViewer_RenderWindowInteractor::GetDisplayMode() { void VTKViewer_RenderWindowInteractor::SetDisplayMode(int theMode) { if(theMode == 0) ChangeRepresentationToWireframe(); - else + else if (theMode == 1) ChangeRepresentationToSurface(); + else if (theMode == 2) { + ChangeRepresentationToSurfaceWithEdges(); + theMode++; + } myDisplayMode = theMode; } @@ -512,6 +516,14 @@ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface() ChangeRepresentationToSurface(aCopy.GetActors()); } +/*!Change all actors to surface with edges*/ +void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurfaceWithEdges() +{ + using namespace VTK; + ActorCollectionCopy aCopy(GetRenderer()->GetActors()); + ChangeRepresentationToSurfaceWithEdges(aCopy.GetActors()); +} + /*!Change all actors from \a theCollection to wireframe and * emit render window modified. */ @@ -536,6 +548,18 @@ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCol emit RenderWindowModified(); } +/*!Change all actors from \a theCollection to surface with edges and + * emit render window modified. + */ +void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* theCollection) +{ + using namespace VTK; + ForEach(theCollection, + TSetFunction + (&VTKViewer_Actor::setDisplayMode,3)); + emit RenderWindowModified(); +} + /*!Gets renderer.*/ vtkRenderer* VTKViewer_RenderWindowInteractor::GetRenderer() { diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h index 88fbf739d..d396591e7 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h @@ -136,12 +136,14 @@ public: //@{ void ChangeRepresentationToWireframe(); void ChangeRepresentationToSurface(); + void ChangeRepresentationToSurfaceWithEdges(); //@} /** @name Change to wireframe or surface a list of vtkactor*/ //@{ void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors); void ChangeRepresentationToSurface(vtkActorCollection* ListofActors); + void ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* ListofActors); //@} /** @name Erase Display functions*/ -- 2.39.2