]> Creatis software - cpMesh.git/blob - lib/cpm/VTK/ThreadedDeformationObserver.hxx
First commit
[cpMesh.git] / lib / cpm / VTK / ThreadedDeformationObserver.hxx
1 #ifndef __CPM__VTK__THREADEDDEFORMATIONOBSERVER__HXX__
2 #define __CPM__VTK__THREADEDDEFORMATIONOBSERVER__HXX__
3
4 #include <vtksys/SystemTools.hxx>
5
6 // -------------------------------------------------------------------------
7 template< class F >
8 void cpm::VTK::ThreadedDeformationObserver< F >::
9 Configure( vtkRenderWindow* w )
10 {
11   this->m_Window = w;
12   this->Modified( );
13 }
14
15 // -------------------------------------------------------------------------
16 template< class F >
17 void cpm::VTK::ThreadedDeformationObserver< F >::
18 Execute( itk::Object* caller, const itk::EventObject& evt )
19 {
20   this->Execute( const_cast< const itk::Object* >( caller ), evt );
21 }
22
23 // -------------------------------------------------------------------------
24 template< class F >
25 void cpm::VTK::ThreadedDeformationObserver< F >::
26 Execute( const itk::Object* caller, const itk::EventObject& evt )
27 {
28   typedef typename F::AllMeshUpdatedEvent _TAllMeshEvt;
29
30   if( this->m_Window == NULL )
31     return;
32
33   const _TAllMeshEvt* mevt = dynamic_cast< const _TAllMeshEvt* >( &evt );
34   if( mevt != NULL )
35   {
36     this->m_MutexLock->Lock( );
37     this->m_Window->MakeCurrent( );
38     this->m_Window->Render( );
39 #ifdef CPM_VTK_THREADEDDEFORMATION_ON_LINUX
40     glXMakeCurrent(
41       ( Display* )( this->m_Window->GetGenericDisplayId( ) ), None, NULL
42       );
43 #else
44     wglMakeCurrent(
45       ( HDC__* )( this->m_Window->GetGenericDisplayId( ) ), NULL
46       );
47 #endif
48     this->m_MutexLock->Unlock( );
49     vtksys::SystemTools::Delay( 1 );
50
51   } // fi
52 }
53
54 // -------------------------------------------------------------------------
55 template< class F >
56 cpm::VTK::ThreadedDeformationObserver< F >::
57 ThreadedDeformationObserver( )
58   : Superclass( ),
59     m_Window( NULL )
60 {
61   this->m_MutexLock = vtkSmartPointer< vtkMutexLock >::New( );
62 }
63
64 // -------------------------------------------------------------------------
65 template< class F >
66 cpm::VTK::ThreadedDeformationObserver< F >::
67 ~ThreadedDeformationObserver( )
68 {
69 }
70
71 #endif // __CPM__VTK__THREADEDDEFORMATIONOBSERVER__HXX__
72
73 // eof - $RCSfile$