From 7da356d60c68fa41d0dc07f6affdba43d9e04d95 Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 8 Jun 2012 14:35:04 +0000 Subject: [PATCH] Issue 0001105: External 20601: 3D Filters --- src/SVTK/SVTK_ViewModel.cxx | 7 +++-- src/VTKViewer/Makefile.am | 1 + src/VTKViewer/VTKViewer_Algorithm.cxx | 42 +++++++++++++++++++++++++++ src/VTKViewer/VTKViewer_Algorithm.h | 28 ++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/VTKViewer/VTKViewer_Algorithm.cxx diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 28cb85640..bbaf40ded 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -32,6 +32,7 @@ //#include "SVTK_MainWindow.h" #include "SVTK_Prs.h" +#include "VTKViewer_Algorithm.h" #include "VTKViewer_ViewModel.h" #include "SUIT_ViewModel.h" @@ -500,7 +501,8 @@ void SVTK_Viewer::EraseAll( const bool forced ) if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) if(SVTK_View* aView = aViewWindow->getView()){ vtkRenderer* aRenderer = aView->getRenderer(); - vtkActorCollection* anActorCollection = aRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* anActorCollection = aCopy.GetActors(); anActorCollection->InitTraversal(); while(vtkActor* anActor = anActorCollection->GetNextActor()){ if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ @@ -543,7 +545,8 @@ SALOME_Prs* SVTK_Viewer::CreatePrs( const char* entry ) if(SVTK_ViewWindow* aViewWindow = dynamic_cast(getViewManager()->getActiveView())) if(SVTK_View* aView = aViewWindow->getView()){ vtkRenderer* aRenderer = aView->getRenderer(); - vtkActorCollection* theActors = aRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* theActors = aCopy.GetActors(); theActors->InitTraversal(); vtkActor* ac; while( ( ac = theActors->GetNextActor() ) ) { diff --git a/src/VTKViewer/Makefile.am b/src/VTKViewer/Makefile.am index 467e104ac..567d46e76 100755 --- a/src/VTKViewer/Makefile.am +++ b/src/VTKViewer/Makefile.am @@ -58,6 +58,7 @@ dist_libVTKViewer_la_SOURCES = \ VTKViewer_Filter.cxx \ VTKViewer_GeometryFilter.cxx \ VTKViewer_AppendFilter.cxx \ + VTKViewer_Algorithm.cxx \ VTKViewer_InteractorStyle.cxx \ VTKViewer_RenderWindow.cxx \ VTKViewer_RenderWindowInteractor.cxx \ diff --git a/src/VTKViewer/VTKViewer_Algorithm.cxx b/src/VTKViewer/VTKViewer_Algorithm.cxx new file mode 100644 index 000000000..ce57a890d --- /dev/null +++ b/src/VTKViewer/VTKViewer_Algorithm.cxx @@ -0,0 +1,42 @@ +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "VTKViewer_Algorithm.h" + +namespace VTK +{ + ActorCollectionCopy::ActorCollectionCopy( vtkActorCollection* theActorCollection ) + { + myActorCollection = vtkActorCollection::New(); + theActorCollection->InitTraversal(); + while(vtkActor* anActor = theActorCollection->GetNextActor()) + myActorCollection->AddItem(anActor); + } + + ActorCollectionCopy::~ActorCollectionCopy() + { + myActorCollection->Delete(); + myActorCollection = NULL; + } + + vtkActorCollection* ActorCollectionCopy::GetActors() const + { + return myActorCollection; + } +} diff --git a/src/VTKViewer/VTKViewer_Algorithm.h b/src/VTKViewer/VTKViewer_Algorithm.h index b533f149b..d11c469f9 100644 --- a/src/VTKViewer/VTKViewer_Algorithm.h +++ b/src/VTKViewer/VTKViewer_Algorithm.h @@ -29,12 +29,40 @@ #ifndef VTKViewer_Algorithm_H #define VTKViewer_Algorithm_H +#include "VTKViewer.h" + #include class vtkActor; namespace VTK { + /*! + * This object should be used to avoid problems with recurring calls of GetActors() method of the vtkRenderer class. + * + * Instead of the following instructions: + * + * vtkRenderer* aRenderer = ...; + * vtkActorCollection* anActorCollection = aRenderer->GetActors(); + * DoSomething( anActorCollection ); // where GetActors() could be called again + * + * A code like the following should be used: + * + * vtkRenderer* aRenderer = ...; + * vtkActorCollection* anActorCollection = aRenderer->GetActors(); + * ActorCollectionCopy aCopy( anActorCollection ); + * DoSomething( aCopy.GetActors() ); + */ + struct VTKVIEWER_EXPORT ActorCollectionCopy + { + vtkActorCollection* myActorCollection; + + ActorCollectionCopy( vtkActorCollection* theActorCollection ); + ~ActorCollectionCopy(); + + vtkActorCollection* GetActors() const; + }; + /*!For each actor(for ex: someActor) from \a theCollection(that can be dynamic cast to type TActor)\n * Call method \a theFun(someActor) */ -- 2.39.2