Salome HOME
Initial version
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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     template<typename TActor, typename TFunction>
39       TFunction ForEach(vtkActorCollection *theCollection, TFunction theFun)
40       {
41         if(theCollection){
42           theCollection->InitTraversal();
43           while(vtkActor *anAct = theCollection->GetNextActor())
44             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
45               theFun(anActor);
46         }
47         return theFun;
48       }
49   
50
51     template<typename TActor, typename TPredicate, typename TFunction>
52       TFunction ForEachIf(vtkActorCollection *theCollection, 
53                           TPredicate thePredicate,
54                           TFunction theFun)
55       {
56         if(theCollection){
57           theCollection->InitTraversal();
58           while(vtkActor *anAct = theCollection->GetNextActor())
59             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
60               if(thePredicate(anActor))
61                 theFun(anActor);
62         }
63         return theFun;
64       }
65   
66
67     template<typename TActor, typename TPredicate>
68       TActor* Find(vtkActorCollection *theCollection, TPredicate thePredicate)
69       {
70         if(theCollection){
71           theCollection->InitTraversal();
72           while(vtkActor *anAct = theCollection->GetNextActor())
73             if(TActor *anActor = dynamic_cast<TActor*>(anAct))
74               if(thePredicate(anActor))
75                 return anActor;
76         }
77         return NULL;
78       }
79
80 }
81
82 #endif