Version: 6.3.1

src/VTKViewer/VTKViewer_Algorithm.h

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00024 //  File   : VTKViewer_ViewFrame.h
00025 //  Author : Nicolas REJNERI
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/GUI/GUI_SRC/src/VTKViewer/VTKViewer_Algorithm.h,v 1.5.2.5.10.1.12.1 2011-06-01 13:53:43 vsr Exp $
00028 //
00029 #ifndef VTKViewer_Algorithm_H
00030 #define VTKViewer_Algorithm_H
00031 
00032 #include "VTKViewer.h"
00033 
00034 #include <vtkActorCollection.h>
00035 
00036 class vtkActor;
00037 
00038 namespace VTK
00039 {
00056   struct VTKVIEWER_EXPORT ActorCollectionCopy
00057   {
00058     vtkActorCollection* myActorCollection;
00059 
00060     ActorCollectionCopy( vtkActorCollection* theActorCollection );
00061     ~ActorCollectionCopy();
00062 
00063     vtkActorCollection* GetActors() const;
00064   };
00065 
00069     template<typename TActor, typename TFunction>
00070       TFunction ForEach(vtkActorCollection *theCollection, TFunction theFun)
00071       {
00072         if(theCollection){
00073           theCollection->InitTraversal();
00074           while(vtkActor *anAct = theCollection->GetNextActor())
00075             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
00076               theFun(anActor);
00077         }
00078         return theFun;
00079       }
00080   
00085     template<typename TActor, typename TPredicate, typename TFunction>
00086       TFunction ForEachIf(vtkActorCollection *theCollection, 
00087                           TPredicate thePredicate,
00088                           TFunction theFun)
00089       {
00090         if(theCollection){
00091           theCollection->InitTraversal();
00092           while(vtkActor *anAct = theCollection->GetNextActor())
00093             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
00094               if(thePredicate(anActor))
00095                 theFun(anActor);
00096         }
00097         return theFun;
00098       }
00099   
00104     template<typename TActor, typename TPredicate>
00105       TActor* Find(vtkActorCollection *theCollection, TPredicate thePredicate)
00106       {
00107         if(theCollection){
00108           theCollection->InitTraversal();
00109           while(vtkActor *anAct = theCollection->GetNextActor())
00110             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
00111               if(thePredicate(anActor))
00112                 return anActor;
00113         }
00114         return NULL;
00115       }
00116 
00117 }
00118 
00119 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS