]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/MultiplyImageAndDistanceMap.hxx
f78d2a130a10aa7fe7d17025ca06e30e60cdcedf
[FrontAlgorithms.git] / lib / fpa / Image / MultiplyImageAndDistanceMap.hxx
1 #ifndef __fpa__Image__MultiplyImageAndDistanceMap__hxx__
2 #define __fpa__Image__MultiplyImageAndDistanceMap__hxx__
3
4 #include <itkImageRegionConstIteratorWithIndex.h>
5 #include <itkImageRegionIteratorWithIndex.h>
6 #include <itkProgressReporter.h>
7
8 // -------------------------------------------------------------------------
9 template< class _TInput, class _TDistanceMap >
10 _TDistanceMap*
11 fpa::Image::MultiplyImageAndDistanceMap< _TInput, _TDistanceMap >::
12 GetDistanceMap( )
13 {
14   return(
15     dynamic_cast< _TDistanceMap* >(
16       this->itk::ProcessObject::GetInput( 1 )
17       )
18     );
19 }
20
21 // -------------------------------------------------------------------------
22 template< class _TInput, class _TDistanceMap >
23 const _TDistanceMap*
24 fpa::Image::MultiplyImageAndDistanceMap< _TInput, _TDistanceMap >::
25 GetDistanceMap( ) const
26 {
27   return(
28     dynamic_cast< const _TDistanceMap* >(
29       this->itk::ProcessObject::GetInput( 1 )
30       )
31     );
32 }
33
34 // -------------------------------------------------------------------------
35 template< class _TInput, class _TDistanceMap >
36 void fpa::Image::MultiplyImageAndDistanceMap< _TInput, _TDistanceMap >::
37 SetDistanceMap( _TDistanceMap* dmap )
38 {
39   this->itk::ProcessObject::SetNthInput( 1, dmap );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TInput, class _TDistanceMap >
44 fpa::Image::MultiplyImageAndDistanceMap< _TInput, _TDistanceMap >::
45 MultiplyImageAndDistanceMap( )
46   : Superclass( )
47 {
48   this->SetNumberOfRequiredInputs( 2 );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class _TInput, class _TDistanceMap >
53 fpa::Image::MultiplyImageAndDistanceMap< _TInput, _TDistanceMap >::
54 ~MultiplyImageAndDistanceMap( )
55 {
56 }
57
58 // -------------------------------------------------------------------------
59 template< class _TInput, class _TDistanceMap >
60 void fpa::Image::MultiplyImageAndDistanceMap< _TInput, _TDistanceMap >::
61 ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
62 {
63   typedef typename _TInput::PixelType _TPixel;
64   const typename TRegion::SizeType& regionSize = region.GetSize( );
65   if( regionSize[ 0 ] == 0 )
66     return;
67   const _TInput* input = this->GetInput( );
68   const _TDistanceMap* dmap = this->GetDistanceMap( );
69   _TInput* output = this->GetOutput( );
70   itk::ProgressReporter pr( this, threadId, region.GetNumberOfPixels( ) );
71
72   // Prepare iterators
73   itk::ImageRegionConstIteratorWithIndex< _TInput > iIt( input, region );
74   itk::ImageRegionConstIteratorWithIndex< _TDistanceMap > dIt( dmap, region );
75   itk::ImageRegionIteratorWithIndex< _TInput > oIt( output, region );
76   iIt.GoToBegin( );
77   dIt.GoToBegin( );
78   oIt.GoToBegin( );
79   for(
80     ; !iIt.IsAtEnd( ) && !dIt.IsAtEnd( ) && !oIt.IsAtEnd( );
81     ++iIt, ++dIt, ++oIt
82     )
83   {
84     double d = double( dIt.Get( ) );
85     if( !( d >= double( 0 ) ) )
86     {
87       /* TODO
88          double v = double( iIt.Get( ) );
89          if( v >= 0 )
90          oIt.Set( _TPixel( v / std::fabs( d ) ) );
91          else
92          oIt.Set( _TPixel( v * std::fabs( d ) ) );
93       */
94       oIt.Set( _TPixel( 0 ) );
95     }
96     else
97       oIt.Set( iIt.Get( ) );
98     pr.CompletedPixel( );
99
100   } // rof
101 }
102
103 #endif // __fpa__Image__MultiplyImageAndDistanceMap__hxx__
104
105 // eof - $RCSfile$