]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/VisualDebugger.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / VisualDebugger.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Image__VisualDebugger__hxx__
7 #define __fpa__Image__VisualDebugger__hxx__
8
9 // -------------------------------------------------------------------------
10 template< class _TFilter >
11 void fpa::Image::VisualDebugger< _TFilter >::
12 SetVisualization( vtkRenderer* renderer, vtkRenderWindowInteractor* iren )
13 {
14 #ifdef USE_ivq
15   this->m_Renderer = renderer;
16   this->m_Interactor = iren;
17   this->Modified( );
18 #endif // USE_ivq
19 }
20
21 // -------------------------------------------------------------------------
22 template< class _TFilter >
23 void fpa::Image::VisualDebugger< _TFilter >::
24 Execute( itk::Object* caller, const itk::EventObject& event )
25 {
26   this->Execute( const_cast< const itk::Object* >( caller ), event );
27 }
28
29 // -------------------------------------------------------------------------
30 template< class _TFilter >
31 void fpa::Image::VisualDebugger< _TFilter >::
32 Execute( const itk::Object* caller, const itk::EventObject& event )
33 {
34   typedef itk::StartEvent           _TStart;
35   typedef itk::EndEvent             _TEnd;
36   typedef typename _TFilter::TEvent _TEvent;
37
38   // Check validity
39   const TFilter* filter = dynamic_cast< const TFilter* >( caller );
40   if( filter == NULL )
41     return;
42
43   // Get correct event type
44   const _TEvent* ev_fpa = dynamic_cast< const _TEvent* >( &event );
45   const _TStart* ev_start = dynamic_cast< const _TStart* >( &event );
46   const _TEnd* ev_end = dynamic_cast< const _TEnd* >( &event );
47   if( ev_fpa != NULL )
48   {
49     if( this->m_Labels.IsNotNull( ) )
50     {
51       TLabel new_color;
52       if( ev_fpa->IntoQueue )
53         new_color = this->m_Colors[ this->m_Colors.size( ) - 2 ];
54       else
55         new_color =
56           this->m_Colors[
57             ( ev_fpa->FrontId - 1 ) % ( this->m_Colors.size( ) - 2 )
58             ];
59       TLabel old_color = this->m_Labels->GetPixel( ev_fpa->Vertex );
60       if( !( new_color == old_color ) )
61       {
62         this->m_Labels->SetPixel( ev_fpa->Vertex, new_color );
63         this->m_VTKLabels->Modified( );
64         this->Render( );
65
66       } // fi
67
68     } // fi
69   }
70   else if( ev_start != NULL )
71   {
72     const TImage* image = filter->GetInput( );
73     this->m_Labels = TLabels::New( );
74     this->m_Labels->
75       SetLargestPossibleRegion( image->GetLargestPossibleRegion( ) );
76     this->m_Labels->SetRequestedRegion( image->GetRequestedRegion( ) );
77     this->m_Labels->SetBufferedRegion( image->GetBufferedRegion( ) );
78     this->m_Labels->SetOrigin( image->GetOrigin( ) );
79     this->m_Labels->SetSpacing( image->GetSpacing( ) );
80     this->m_Labels->SetDirection( image->GetDirection( ) );
81     this->m_Labels->Allocate( );
82     this->m_Labels->FillBuffer( this->m_Colors.back( ) );
83 #ifdef USE_ivq
84     this->m_VTKLabels = TVTKLabels::New( );
85     this->m_VTKLabels->SetInput( this->m_Labels );
86     this->m_VTKLabels->Update( );
87     this->StartVisualization( );
88 #endif // USE_ivq
89   }
90   else if( ev_end != NULL )
91   {
92     this->EndVisualization( );
93     this->m_Labels = NULL;
94     this->m_VTKLabels = NULL;
95
96   } // fi
97 }
98
99 // -------------------------------------------------------------------------
100 template< class _TFilter >
101 fpa::Image::VisualDebugger< _TFilter >::
102 VisualDebugger( )
103   : Superclass( )
104 {
105   unsigned char colors[ 8 ][ 4 ] =
106   {
107     { 255,   0,   0, 128 },
108     {   0, 255,   0, 128 },
109     {   0,   0, 255, 128 },
110     {   0, 255, 255, 128 },
111     { 255,   0, 255, 128 },
112     { 255, 255,   0, 128 },
113     { 255, 128,  64, 255 },
114     {   0,   0,   0,   0 }
115   };
116   for( unsigned int i = 0; i < 8; ++i )
117     this->m_Colors.push_back( TLabel( colors[ i ] ) );
118
119 #ifdef USE_ivq
120   this->m_Renderer = NULL;
121   this->m_Interactor = NULL;
122 #endif // USE_ivq
123 }
124
125 // -------------------------------------------------------------------------
126 template< class _TFilter >
127 fpa::Image::VisualDebugger< _TFilter >::
128 ~VisualDebugger( )
129 {
130 }
131
132 #endif // __fpa__Image__VisualDebugger__h__
133
134 // eof - $RCSfile$