Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / VTKViewer / VTKViewer_Algorithm.h
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VTKViewer_ViewFrame.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef VTKViewer_Algorithm_H
30 #define VTKViewer_Algorithm_H
31
32 #include <vtkActorCollection.h>
33
34 class vtkActor;
35
36 namespace VTK
37 {
38   /*!For each actor(for ex: someActor) from \a theCollection(that can be dynamic cast to type TActor)\n
39    * Call method \a theFun(someActor)
40    */
41     template<typename TActor, typename TFunction>
42       TFunction ForEach(vtkActorCollection *theCollection, TFunction theFun)
43       {
44         if(theCollection){
45           theCollection->InitTraversal();
46           while(vtkActor *anAct = theCollection->GetNextActor())
47             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
48               theFun(anActor);
49         }
50         return theFun;
51       }
52   
53     /*!For each actor(for ex: someActor) from \a theCollection(that can be dynamic cast to type TActor and \n
54      * method \a thePredicate(someActor) return true) \n
55      * Call method \a theFun(someActor)
56      */
57     template<typename TActor, typename TPredicate, typename TFunction>
58       TFunction ForEachIf(vtkActorCollection *theCollection, 
59                           TPredicate thePredicate,
60                           TFunction theFun)
61       {
62         if(theCollection){
63           theCollection->InitTraversal();
64           while(vtkActor *anAct = theCollection->GetNextActor())
65             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
66               if(thePredicate(anActor))
67                 theFun(anActor);
68         }
69         return theFun;
70       }
71   
72     /*!Find actor from collection, that can be dynamicaly cast to \a TActor, \n
73      *and method \a thePredicate(someActor) return true) \n
74      *\retval someActor
75      */
76     template<typename TActor, typename TPredicate>
77       TActor* Find(vtkActorCollection *theCollection, TPredicate thePredicate)
78       {
79         if(theCollection){
80           theCollection->InitTraversal();
81           while(vtkActor *anAct = theCollection->GetNextActor())
82             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
83               if(thePredicate(anActor))
84                 return anActor;
85         }
86         return NULL;
87       }
88
89 }
90
91 #endif