]> Creatis software - cpMesh.git/blob - lib/cpm/VTK/ThreadedDeformation.hxx
First commit
[cpMesh.git] / lib / cpm / VTK / ThreadedDeformation.hxx
1 #ifndef __CPM__VTK__THREADEDDEFORMATION__HXX__
2 #define __CPM__VTK__THREADEDDEFORMATION__HXX__
3
4 #include <cpm/VTK/ThreadedDeformationObserver.h>
5
6 // -------------------------------------------------------------------------
7 template< class F >
8 typename cpm::VTK::ThreadedDeformation< F >::
9 Self* cpm::VTK::ThreadedDeformation< F >::
10 New( )
11 {
12   return( new Self( ) );
13 }
14
15 // -------------------------------------------------------------------------
16 template< class F >
17 void cpm::VTK::ThreadedDeformation< F >::
18 InitThreadSupport( )
19 {
20 #ifdef CPM_VTK_THREADEDDEFORMATION_ON_LINUX
21   XInitThreads( );
22 #endif
23 }
24
25 // -------------------------------------------------------------------------
26 template< class F >
27 int cpm::VTK::ThreadedDeformation< F >::
28 ExecuteFilter( F* filter, vtkRenderWindow* window )
29 {
30   static _TData data;
31   data.first = filter;
32   data.second = window;
33   return( this->SpawnThread( Self::_Function, &data ) );
34 }
35
36 // -------------------------------------------------------------------------
37 template< class F >
38 cpm::VTK::ThreadedDeformation< F >::
39 ThreadedDeformation( )
40   : Superclass( )
41 {
42 }
43
44 // -------------------------------------------------------------------------
45 template< class F >
46 cpm::VTK::ThreadedDeformation< F >::
47 ~ThreadedDeformation( )
48 {
49 }
50
51 // -------------------------------------------------------------------------
52 template< class F >
53 void* cpm::VTK::ThreadedDeformation< F >::
54 _Function( void* arg )
55 {
56   typedef cpm::VTK::ThreadedDeformationObserver< F > _TObserver;
57   typedef Superclass::ThreadInfo                     _TInfo;
58   typedef typename F::AllMeshUpdatedEvent            _TEvt;
59
60   // Get inputs
61   _TInfo* info = reinterpret_cast< _TInfo* >( arg );
62   if( info == NULL )
63     return( 0 );
64   _TData* data = reinterpret_cast< _TData* >( info->UserData );
65   if( data == NULL )
66     return( 0 );
67   F* filter = data->first;
68   vtkRenderWindow* window = data->second;
69
70   // Add observers, execute and remove observers
71   typename _TObserver::Pointer obs = _TObserver::New( );
72   obs->Configure( window );
73   unsigned long id = filter->AddObserver( _TEvt( ), obs );
74   filter->Update( );
75   filter->RemoveObserver( id );
76   return( 0 );
77 }
78
79 #endif // __CPM__VTK__THREADEDDEFORMATION__HXX__
80
81 // eof - $RCSfile$