]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Filters/Image/Interface.hxx
...
[FrontAlgorithms.git] / lib / fpa / Filters / Image / Interface.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Filters__Image__Interface__hxx__
6 #define __fpa__Filters__Image__Interface__hxx__
7
8 // -------------------------------------------------------------------------
9 template< class _TTraits >
10 fpa::Filters::Image::Interface< _TTraits >::
11 Interface( )
12   : Superclass( ),
13     m_NeighborhoodOrder( 1 )
14 {
15   fpaFilterOutputConfigureMacro( Marks, TMarksImage );
16 }
17
18 // -------------------------------------------------------------------------
19 template< class _TTraits >
20 fpa::Filters::Image::Interface< _TTraits >::
21 ~Interface( )
22 {
23 }
24
25 // -------------------------------------------------------------------------
26 template< class _TTraits >
27 void fpa::Filters::Image::Interface< _TTraits >::
28 _AssignOutputValue( const TNode& n )
29 {
30   this->GetOutput( )->SetPixel( n.Vertex, n.Value );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class _TTraits >
35 void fpa::Filters::Image::Interface< _TTraits >::
36 _ConfigureOutputs( )
37 {
38   const TInputImage* in = this->GetInput( );
39
40   TOutputImage* out = this->GetOutput( );
41   out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
42   out->SetRequestedRegion( in->GetRequestedRegion( ) );
43   out->SetBufferedRegion( in->GetBufferedRegion( ) );
44   out->SetSpacing( in->GetSpacing( ) );
45   out->SetOrigin( in->GetOrigin( ) );
46   out->SetDirection( in->GetDirection( ) );
47   out->Allocate( );
48   out->FillBuffer( this->GetInitValue( ) );
49
50   TMarksImage* marks = this->GetMarks( );
51   marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
52   marks->SetRequestedRegion( in->GetRequestedRegion( ) );
53   marks->SetBufferedRegion( in->GetBufferedRegion( ) );
54   marks->SetSpacing( in->GetSpacing( ) );
55   marks->SetOrigin( in->GetOrigin( ) );
56   marks->SetDirection( in->GetDirection( ) );
57   marks->Allocate( );
58   marks->FillBuffer( TMark( 0 ) );
59 }
60
61 // -------------------------------------------------------------------------
62 template< class _TTraits >
63 typename fpa::Filters::Image::Interface< _TTraits >::
64 TInputValue fpa::Filters::Image::Interface< _TTraits >::
65 _GetInputValue( const TVertex& v ) const
66 {
67   return( this->GetInput( )->GetPixel( v ) );
68 }
69
70 // -------------------------------------------------------------------------
71 template< class _TTraits >
72 typename fpa::Filters::Image::Interface< _TTraits >::
73 TOutputValue fpa::Filters::Image::Interface< _TTraits >::
74 _GetOutputValue( const TVertex& v ) const
75 {
76   return( this->GetOutput( )->GetPixel( v ) );
77 }
78
79 // -------------------------------------------------------------------------
80 template< class _TTraits >
81 typename fpa::Filters::Image::Interface< _TTraits >::
82 TNeighborhood fpa::Filters::Image::Interface< _TTraits >::
83 _GetNeighbors( const TVertex& v ) const
84 {
85   typename TInputImage::RegionType region =
86     this->GetInput( )->GetRequestedRegion( );
87   TNeighborhood neighborhood;
88   if( this->m_NeighborhoodOrder == 1 )
89   {
90     for( unsigned int d = 0; d < TTraits::Dimension; ++d )
91     {
92       for( int s = -1; s <= 1; s += 2 )
93       {
94         TVertex n = v;
95         n[ d ] += s;
96         if( region.IsInside( n ) )
97           neighborhood.push_back( n );
98
99       } // rof
100
101     } // rof
102   }
103   else if( this->m_NeighborhoodOrder == 2 )
104   {
105     // TODO
106
107   } // fi
108   return( neighborhood );
109 }
110
111 // -------------------------------------------------------------------------
112 template< class _TTraits >
113 unsigned long fpa::Filters::Image::Interface< _TTraits >::
114 _GetMark( const TVertex& v ) const
115 {
116   return( this->GetMarks( )->GetPixel( v ) );
117 }
118
119 // -------------------------------------------------------------------------
120 template< class _TTraits >
121 bool fpa::Filters::Image::Interface< _TTraits >::
122 _IsMarked( const TVertex& v ) const
123 {
124   return( this->GetMarks( )->GetPixel( v ) != TMark( 0 ) );
125 }
126
127 // -------------------------------------------------------------------------
128 template< class _TTraits >
129 void fpa::Filters::Image::Interface< _TTraits >::
130 _Mark( const TNode& n )
131 {
132   this->GetMarks( )->SetPixel( n.Vertex, TMark( n.FrontId ) );
133 }
134
135 #endif // __fpa__Filters__Image__Interface__hxx__
136 // eof - $RCSfile$