1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Image__VisualDebugger__hxx__
7 #define __fpa__Image__VisualDebugger__hxx__
9 // -------------------------------------------------------------------------
10 template< class _TFilter >
11 void fpa::Image::VisualDebugger< _TFilter >::
12 SetVisualization( vtkRenderer* renderer, vtkRenderWindowInteractor* iren )
15 this->m_Renderer = renderer;
16 this->m_Interactor = iren;
21 // -------------------------------------------------------------------------
22 template< class _TFilter >
23 void fpa::Image::VisualDebugger< _TFilter >::
24 Execute( itk::Object* caller, const itk::EventObject& event )
26 this->Execute( const_cast< const itk::Object* >( caller ), event );
29 // -------------------------------------------------------------------------
30 template< class _TFilter >
31 void fpa::Image::VisualDebugger< _TFilter >::
32 Execute( const itk::Object* caller, const itk::EventObject& event )
34 typedef itk::StartEvent _TStart;
35 typedef itk::EndEvent _TEnd;
36 typedef typename _TFilter::TEvent _TEvent;
39 const TFilter* filter = dynamic_cast< const TFilter* >( caller );
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 );
49 if( this->m_Labels.IsNotNull( ) )
52 if( ev_fpa->IntoQueue )
53 new_color = this->m_Colors[ this->m_Colors.size( ) - 2 ];
57 ( ev_fpa->FrontId - 1 ) % ( this->m_Colors.size( ) - 2 )
59 TLabel old_color = this->m_Labels->GetPixel( ev_fpa->Vertex );
60 if( !( new_color == old_color ) )
62 this->m_Labels->SetPixel( ev_fpa->Vertex, new_color );
63 this->m_VTKLabels->Modified( );
70 else if( ev_start != NULL )
72 const TImage* image = filter->GetInput( );
73 this->m_Labels = TLabels::New( );
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( ) );
84 this->m_VTKLabels = TVTKLabels::New( );
85 this->m_VTKLabels->SetInput( this->m_Labels );
86 this->m_VTKLabels->Update( );
87 this->StartVisualization( );
90 else if( ev_end != NULL )
92 this->EndVisualization( );
93 this->m_Labels = NULL;
94 this->m_VTKLabels = NULL;
99 // -------------------------------------------------------------------------
100 template< class _TFilter >
101 fpa::Image::VisualDebugger< _TFilter >::
105 unsigned char colors[ 8 ][ 4 ] =
110 { 0, 255, 255, 128 },
111 { 255, 0, 255, 128 },
112 { 255, 255, 0, 128 },
113 { 255, 128, 64, 255 },
116 for( unsigned int i = 0; i < 8; ++i )
117 this->m_Colors.push_back( TLabel( colors[ i ] ) );
120 this->m_Renderer = NULL;
121 this->m_Interactor = NULL;
125 // -------------------------------------------------------------------------
126 template< class _TFilter >
127 fpa::Image::VisualDebugger< _TFilter >::
132 #endif // __fpa__Image__VisualDebugger__h__