From 1933d8d1876041f5bc36d9e73c1eebab6ed759c1 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 22 Jul 2009 10:32:08 +0000 Subject: [PATCH] Fix of the problem with vtkRenderer::GetActors() method --- src/LightApp/LightApp_VTKSelector.cxx | 3 +- src/SVTK/SALOME_Actor.cxx | 13 ++-- src/SVTK/SVTK_InteractorStyle.cxx | 4 +- src/SVTK/SVTK_Renderer.cxx | 10 +++- src/SVTK/SVTK_Trihedron.cxx | 5 +- src/SVTK/SVTK_UpdateRateDlg.cxx | 6 +- src/SVTK/SVTK_View.cxx | 60 ++++++++++++------- src/SVTK/SVTK_ViewModel.cxx | 14 ++--- src/VTKViewer/Makefile.am | 1 + src/VTKViewer/VTKViewer_Algorithm.cxx | 44 ++++++++++++++ src/VTKViewer/VTKViewer_Algorithm.h | 26 ++++++++ .../VTKViewer_RenderWindowInteractor.cxx | 19 ++++-- src/VTKViewer/VTKViewer_Trihedron.cxx | 4 +- src/VTKViewer/VTKViewer_Utilities.cxx | 10 +++- 14 files changed, 166 insertions(+), 53 deletions(-) create mode 100644 src/VTKViewer/VTKViewer_Algorithm.cxx diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx index 3556c0812..cb27f6aee 100644 --- a/src/LightApp/LightApp_VTKSelector.cxx +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -113,7 +113,8 @@ LightApp_SVTKDataOwner { if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){ using namespace SVTK; - return Find(aViewWindow->getRenderer()->GetActors(),TIsSameIObject(IO())); + VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors()); + return Find(aCopy.GetActors(),TIsSameIObject(IO())); } return NULL; diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 4e5613ee0..6e9e766b4 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -33,6 +33,7 @@ #include "SALOME_Actor.h" #include "SALOME_InteractiveObject.hxx" +#include "VTKViewer_Algorithm.h" #include "VTKViewer_Transform.h" #include "VTKViewer_TransformFilter.h" #include "VTKViewer_GeometryFilter.h" @@ -493,7 +494,8 @@ SALOME_Actor if( !theIsHighlight ) { SetPreSelected( false ); - vtkActorCollection* theActors = aRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* theActors = aCopy.GetActors(); theActors->InitTraversal(); while( vtkActor *ac = theActors->GetNextActor() ) if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) @@ -592,7 +594,8 @@ SALOME_Actor if( !mySelector->IsSelected( myIO ) ) { SetPreSelected( true ); - vtkActorCollection* theActors = aRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* theActors = aCopy.GetActors(); theActors->InitTraversal(); while( vtkActor *anAct = theActors->GetNextActor() ) { if( anAct != this ) @@ -889,12 +892,11 @@ void SALOME_Actor ::UpdateNameActors() { - // the code is temporarily disabled due to bug 20383 -#ifdef FEATURE_19818 if( vtkRenderer* aRenderer = GetRenderer() ) { int anOffset[2] = { 0, 0 }; - vtkActorCollection* aCollection = aRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* aCollection = aCopy.GetActors(); for( int anIndex = 0, aNbItems = aCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++ ) { if( SALOME_Actor* anActor = dynamic_cast( aCollection->GetItemAsObject( anIndex ) ) ) @@ -914,7 +916,6 @@ SALOME_Actor } } myNameActor->SetVisibility( GetVisibility() && IsDisplayNameActor() ); -#endif } /*! diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 6c8a04fd0..54d91bc72 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -27,6 +27,7 @@ // #include "SVTK_InteractorStyle.h" +#include "VTKViewer_Algorithm.h" #include "VTKViewer_Utilities.h" #include "SVTK_GenericRenderWindowInteractor.h" @@ -1062,7 +1063,8 @@ void SVTK_InteractorStyle::onFinishOperation() if(!myShiftState) GetSelector()->ClearIObjects(); - vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors(); + VTK::ActorCollectionCopy aCopy(GetCurrentRenderer()->GetActors()); + vtkActorCollection* aListActors = aCopy.GetActors(); aListActors->InitTraversal(); while(vtkActor* aActor = aListActors->GetNextActor()) { diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index 26ad2455d..d1c7e82e1 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -33,6 +33,7 @@ #include "SALOME_Actor.h" #include "VTKViewer_Actor.h" +#include "VTKViewer_Algorithm.h" #include "VTKViewer_Transform.h" #include "VTKViewer_Utilities.h" @@ -159,7 +160,8 @@ SVTK_Renderer SVTK_Renderer ::~SVTK_Renderer() { - vtkActorCollection* anActors = GetDevice()->GetActors(); + VTK::ActorCollectionCopy aCopy(GetDevice()->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); vtkActorCollection* anActors2 = vtkActorCollection::New(); anActors->InitTraversal(); @@ -313,7 +315,8 @@ SVTK_Renderer myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); AdjustActors(); - vtkActorCollection* anActors = GetDevice()->GetActors(); + VTK::ActorCollectionCopy aCopy(GetDevice()->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); anActors->InitTraversal(); while(vtkActor* anAct = anActors->GetNextActor()) if(SALOME_Actor* anActor = dynamic_cast(anAct)) @@ -418,7 +421,8 @@ SVTK_Renderer myTrihedron->SetSize( myTrihedronSize ); // iterate through displayed objects and set size if necessary - vtkActorCollection* anActors = GetDevice()->GetActors(); + VTK::ActorCollectionCopy aCopy(GetDevice()->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); anActors->InitTraversal(); while(vtkActor* anAct = anActors->GetNextActor()){ if(SALOME_Actor* anActor = dynamic_cast(anAct)){ diff --git a/src/SVTK/SVTK_Trihedron.cxx b/src/SVTK/SVTK_Trihedron.cxx index f7b2b452e..65f337b33 100644 --- a/src/SVTK/SVTK_Trihedron.cxx +++ b/src/SVTK/SVTK_Trihedron.cxx @@ -22,6 +22,8 @@ #include "SVTK_Trihedron.h" #include "SALOME_Actor.h" +#include "VTKViewer_Algorithm.h" + #include #include #include @@ -44,7 +46,8 @@ int SVTK_Trihedron ::GetVisibleActorCount(vtkRenderer* theRenderer) { - vtkActorCollection* aCollection = theRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(theRenderer->GetActors()); + vtkActorCollection* aCollection = aCopy.GetActors(); aCollection->InitTraversal(); int aCount = 0; while(vtkActor* aProp = aCollection->GetNextActor()) { diff --git a/src/SVTK/SVTK_UpdateRateDlg.cxx b/src/SVTK/SVTK_UpdateRateDlg.cxx index eaf1be83b..783b4a495 100644 --- a/src/SVTK/SVTK_UpdateRateDlg.cxx +++ b/src/SVTK/SVTK_UpdateRateDlg.cxx @@ -105,7 +105,8 @@ namespace vtkFloatingPointType theUpdateRate) { if(vtkRenderer *aRenderer = theRWInteractor->getRenderer()){ - if(vtkActorCollection *anActorCollection = aRenderer->GetActors()){ + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + if(vtkActorCollection *anActorCollection = aCopy.GetActors()){ TRenderTimeMultiplier aMultiplier; using namespace VTK; aMultiplier = ForEach(anActorCollection, @@ -146,7 +147,8 @@ namespace GetNumberOfCells(SVTK_RenderWindowInteractor* theRWInteractor) { if(vtkRenderer *aRenderer = theRWInteractor->getRenderer()){ - if(vtkActorCollection *anActorCollection = aRenderer->GetActors()){ + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + if(vtkActorCollection *anActorCollection = aCopy.GetActors()){ TCellsCounter aCounter; using namespace VTK; aCounter = ForEach(anActorCollection, diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index d55865565..7a57c6f15 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -142,7 +142,8 @@ void SVTK_SignalHandler ::onSelectionChanged() { - vtkActorCollection* anActors = myMainWindow->getRenderer()->GetActors(); + VTK::ActorCollectionCopy aCopy(myMainWindow->getRenderer()->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); using namespace SVTK; ForEach(anActors, @@ -184,7 +185,8 @@ SVTK_View ::unHighlightAll() { using namespace SVTK; - ForEach(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), THighlightAction( false )); Repaint(); } @@ -202,7 +204,8 @@ SVTK_View bool theIsUpdate ) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject( theIO ), THighlightAction(theIsHighlight)); Repaint(); @@ -217,8 +220,9 @@ SVTK_View ::FindIObject(const char* theEntry) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), + Find(aCopy.GetActors(), TIsSameEntry(theEntry)); if(anActor != NULL) return anActor->getIO(); @@ -273,8 +277,9 @@ SVTK_View ::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), + Find(aCopy.GetActors(), TIsSameIObject(theIObject)); return anActor != NULL; } @@ -308,7 +313,8 @@ SVTK_View { using namespace SVTK; bool aResult; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TIsActorVisibleAction(aResult)); return aResult; @@ -325,7 +331,8 @@ SVTK_View const QString& theName) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::setName,theName.toLatin1().data())); @@ -367,7 +374,8 @@ SVTK_View int theMode) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::setDisplayMode,theMode)); @@ -380,7 +388,8 @@ void SVTK_View ::ChangeRepresentationToWireframe() { - ChangeRepresentationToWireframe(getRenderer()->GetActors()); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ChangeRepresentationToWireframe(aCopy.GetActors()); } /*! @@ -390,7 +399,8 @@ void SVTK_View ::ChangeRepresentationToSurface() { - ChangeRepresentationToSurface(getRenderer()->GetActors()); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ChangeRepresentationToSurface(aCopy.GetActors()); } /*! @@ -452,7 +462,8 @@ SVTK_View ::EraseAll() { using namespace SVTK; - ForEach(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), TErase()); Repaint(); } @@ -465,7 +476,8 @@ SVTK_View ::DisplayAll() { using namespace SVTK; - ForEach(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), TSetVisibility(true)); Repaint(); } @@ -498,7 +510,8 @@ SVTK_View bool theIsUpdate) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TErase()); if(theIsUpdate) @@ -529,7 +542,8 @@ SVTK_View bool theIsUpdate) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TSetVisibility(true)); @@ -574,7 +588,8 @@ SVTK_View bool theIsUpdate) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TRemoveAction(GetRenderer())); if(theIsUpdate) @@ -602,7 +617,8 @@ SVTK_View ::RemoveAll(bool theIsUpdate) { vtkRenderer* aRenderer = getRenderer(); - if(vtkActorCollection* anActors = aRenderer->GetActors()){ + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + if(vtkActorCollection* anActors = aCopy.GetActors()){ anActors->InitTraversal(); while(vtkActor *anAct = anActors->GetNextActor()){ if(SALOME_Actor* aSAct = SALOME_Actor::SafeDownCast(anAct)){ @@ -625,8 +641,9 @@ SVTK_View ::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), + Find(aCopy.GetActors(), TIsSameIObject(theIObject)); if(anActor) return 1.0 - anActor->GetOpacity(); @@ -646,7 +663,8 @@ SVTK_View { vtkFloatingPointType anOpacity = 1.0 - theTrans; using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::SetOpacity,anOpacity)); @@ -665,7 +683,8 @@ SVTK_View vtkFloatingPointType aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), TIsSameIObject(theIObject), TSetFunction (&SALOME_Actor::SetColor,aColor)); @@ -681,8 +700,9 @@ SVTK_View ::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), + Find(aCopy.GetActors(), TIsSameIObject(theIObject)); if(anActor){ vtkFloatingPointType r,g,b; diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index a8151edcd..d772b6d91 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -35,6 +35,7 @@ //#include "SVTK_MainWindow.h" #include "SVTK_Prs.h" +#include "VTKViewer_Algorithm.h" #include "VTKViewer_ViewModel.h" #include "SUIT_ViewModel.h" @@ -505,17 +506,11 @@ 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(); - // another way is used to cycle over the actor collection to avoid problems - // with the similar cycle inside SALOME_Actor::UpdateNameActors() called from - // SALOME_Actor::SetVisibility(...), which is called below - /* + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* anActorCollection = aCopy.GetActors(); anActorCollection->InitTraversal(); while(vtkActor* anActor = anActorCollection->GetNextActor()){ if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ - */ - for(int anIndex = 0, aNbItems = anActorCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++){ - if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActorCollection->GetItemAsObject(anIndex))){ // Set visibility flag // Temporarily commented to avoid awful dependecy on SALOMEDS // TODO: better mechanism of storing display/erse status in a study @@ -554,7 +549,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 e89b79601..7d94c6cc0 100755 --- a/src/VTKViewer/Makefile.am +++ b/src/VTKViewer/Makefile.am @@ -60,6 +60,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..b80ec9cc4 --- /dev/null +++ b/src/VTKViewer/VTKViewer_Algorithm.cxx @@ -0,0 +1,44 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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.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 fefcb3a8a..2bf45fc55 100644 --- a/src/VTKViewer/VTKViewer_Algorithm.h +++ b/src/VTKViewer/VTKViewer_Algorithm.h @@ -34,6 +34,32 @@ 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 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) */ diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index 907e85ed1..4bb2dfab7 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -498,13 +498,17 @@ void VTKViewer_RenderWindowInteractor::SetDisplayMode(int theMode) { /*!Change all actors to wireframe*/ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe() { - ChangeRepresentationToWireframe(GetRenderer()->GetActors()); + using namespace VTK; + ActorCollectionCopy aCopy(GetRenderer()->GetActors()); + ChangeRepresentationToWireframe(aCopy.GetActors()); } /*!Change all actors to surface*/ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface() { - ChangeRepresentationToSurface(GetRenderer()->GetActors()); + using namespace VTK; + ActorCollectionCopy aCopy(GetRenderer()->GetActors()); + ChangeRepresentationToSurface(aCopy.GetActors()); } /*!Change all actors from \a theCollection to wireframe and @@ -550,8 +554,8 @@ void VTKViewer_RenderWindowInteractor::EraseAll() void VTKViewer_RenderWindowInteractor::DisplayAll() { using namespace VTK; - vtkActorCollection* aCollection = GetRenderer()->GetActors(); - ForEach(aCollection,TSetVisibility(true)); + ActorCollectionCopy aCopy(GetRenderer()->GetActors()); + ForEach(aCopy.GetActors(),TSetVisibility(true)); emit RenderWindowModified() ; } @@ -577,8 +581,10 @@ void VTKViewer_RenderWindowInteractor::Remove( VTKViewer_Actor* SActor, bool upd */ void VTKViewer_RenderWindowInteractor::RemoveAll( const bool updateViewer ) { + using namespace VTK; vtkRenderer* aRenderer = GetRenderer(); - vtkActorCollection* anActors = aRenderer->GetActors(); + ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); if ( anActors ) { anActors->InitTraversal(); @@ -627,7 +633,8 @@ struct TUpdateAction{ void VTKViewer_RenderWindowInteractor::Update() { using namespace VTK; vtkRenderer* aRen = GetRenderer(); - ForEach(aRen->GetActors(),TUpdateAction()); + ActorCollectionCopy aCopy(aRen->GetActors()); + ForEach(aCopy.GetActors(),TUpdateAction()); aRen->ResetCamera(); diff --git a/src/VTKViewer/VTKViewer_Trihedron.cxx b/src/VTKViewer/VTKViewer_Trihedron.cxx index 0cd2f1f22..f847ad91b 100755 --- a/src/VTKViewer/VTKViewer_Trihedron.cxx +++ b/src/VTKViewer/VTKViewer_Trihedron.cxx @@ -21,6 +21,7 @@ // #include "VTKViewer_Trihedron.h" #include "VTKViewer_Actor.h" +#include "VTKViewer_Algorithm.h" // VTK Includes #include @@ -445,7 +446,8 @@ int VTKViewer_Trihedron::GetVisibleActorCount(vtkRenderer* theRenderer) { //TVisibility aVis = GetVisibility(); //SetVisibility(eOff); - vtkActorCollection* aCollection = theRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(theRenderer->GetActors()); + vtkActorCollection* aCollection = aCopy.GetActors(); aCollection->InitTraversal(); int aCount = 0; while(vtkActor* prop = aCollection->GetNextActor()) { diff --git a/src/VTKViewer/VTKViewer_Utilities.cxx b/src/VTKViewer/VTKViewer_Utilities.cxx index c6fe7e9ea..3714c74aa 100755 --- a/src/VTKViewer/VTKViewer_Utilities.cxx +++ b/src/VTKViewer/VTKViewer_Utilities.cxx @@ -21,6 +21,7 @@ // #include "VTKViewer_Utilities.h" #include "VTKViewer_Actor.h" +#include "VTKViewer_Algorithm.h" #include @@ -115,7 +116,8 @@ ComputeVisiblePropBounds(vtkRenderer* theRenderer, theBounds[1] = theBounds[3] = theBounds[5] = -VTK_LARGE_FLOAT; // loop through all props - vtkActorCollection* aCollection = theRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(theRenderer->GetActors()); + vtkActorCollection* aCollection = aCopy.GetActors(); aCollection->InitTraversal(); while (vtkActor* aProp = aCollection->GetNextActor()) { // if it's invisible, or has no geometry, we can skip the rest @@ -227,7 +229,8 @@ bool IsBBEmpty(vtkRenderer* theRenderer) aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT; // iterate through displayed objects and set size if necessary - vtkActorCollection* anActors = theRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(theRenderer->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); anActors->InitTraversal(); bool isAny = false; while(vtkActor* anAct = anActors->GetNextActor()) @@ -257,7 +260,8 @@ bool ComputeBBCenter(vtkRenderer* theRenderer, vtkFloatingPointType theCenter[3] aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT; // iterate through displayed objects and set size if necessary - vtkActorCollection* anActors = theRenderer->GetActors(); + VTK::ActorCollectionCopy aCopy(theRenderer->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); anActors->InitTraversal(); bool isAny = false; while(vtkActor* anAct = anActors->GetNextActor()) -- 2.39.2