1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Common__OriginalRandomWalker__h__
6 #define __fpa__Common__OriginalRandomWalker__h__
8 #include <fpa/Config.h>
12 #include <itkImageToImageFilter.h>
13 #include <itkSimpleFastMutexLock.h>
21 template< class _TImage, class _TLabels, class _TScalar = float >
22 class OriginalRandomWalker
23 : public itk::ImageToImageFilter< _TImage, _TLabels >
26 typedef _TImage TImage;
27 typedef _TLabels TLabels;
28 typedef _TScalar TScalar;
30 typedef OriginalRandomWalker Self;
31 typedef itk::ImageToImageFilter< TImage, TLabels > Superclass;
32 typedef itk::SmartPointer< Self > Pointer;
33 typedef itk::SmartPointer< const Self > ConstPointer;
35 typedef itk::Image< TScalar, TImage::ImageDimension > TScalarImage;
36 typedef typename TImage::IndexType TIndex;
37 typedef typename TImage::PixelType TPixel;
38 typedef typename TImage::RegionType TRegion;
39 typedef typename TLabels::PixelType TLabel;
42 struct _TBoundaryThreadStruct
46 std::map< TLabel, unsigned long >* Labels;
49 struct _TLaplacianThreadStruct
57 struct _TOutputThreadStruct
62 const std::vector< TLabel >* InvLabels;
68 fpa::Common::OriginalRandomWalker, itk::ImageToImageFilter
71 itkGetConstMacro( Beta, TScalar );
72 itkSetMacro( Beta, TScalar );
74 itkGetConstMacro( Epsilon, TScalar );
75 itkSetMacro( Epsilon, TScalar );
77 itkBooleanMacro( NormalizeWeights );
78 itkGetConstMacro( NormalizeWeights, bool );
79 itkSetMacro( NormalizeWeights, bool );
81 fpaFilterInputMacro( InputLabels, TLabels );
82 fpaFilterOutputMacro( OutputProbabilities, TScalarImage );
85 void AddSeed( const TIndex& seed, const TLabel& label );
88 OriginalRandomWalker( );
89 virtual ~OriginalRandomWalker( );
91 virtual void GenerateData( ) override;
93 virtual TScalar _W( const TIndex& i, const TIndex& j );
94 virtual TScalar _L( const TIndex& i, const TIndex& j );
96 // Boundary construction
97 template< class _TTriplets >
100 std::map< TLabel, unsigned long >& labels
103 template< class _TTriplets >
104 static ITK_THREAD_RETURN_TYPE _BoundaryCbk( void* arg );
106 template< class _TTriplets >
107 void _ThreadedBoundary(
108 const TRegion& region, const itk::ThreadIdType& id,
110 std::map< TLabel, unsigned long >* labels
113 // Laplacian construction
114 template< class _TTriplets >
116 _TTriplets& A, _TTriplets& R, const _TTriplets& B
119 template< class _TTriplets >
120 static ITK_THREAD_RETURN_TYPE _LaplacianCbk( void* arg );
122 template< class _TTriplets >
123 void _ThreadedLaplacian(
124 const TRegion& region, const itk::ThreadIdType& id,
125 _TTriplets* A, _TTriplets* R, const _TTriplets* B
129 template< class _TMatrix, class _TTriplets >
131 const _TMatrix& X, const _TTriplets& S,
132 const std::vector< TLabel >& invLabels
135 template< class _TMatrix, class _TTriplets >
136 static ITK_THREAD_RETURN_TYPE _OutputCbk( void* arg );
138 template< class _TMatrix, class _TTriplets >
139 void _ThreadedOutput(
140 const TRegion& region, const itk::ThreadIdType& id,
141 const _TMatrix* X, const _TTriplets* S,
142 const std::vector< TLabel >* invLabels
145 // Array-Image conversion
146 static unsigned long _1D( const TIndex& idx, const TRegion& region );
148 template< class _TTriplets >
149 static unsigned long _SeedIndex(
150 const unsigned long& i, const _TTriplets& t
153 template< class _TTriplets >
154 static unsigned long _NearSeedIndex(
155 const unsigned long& i, const _TTriplets& t
159 // Purposely not implemented
160 OriginalRandomWalker( const Self& other );
161 Self& operator=( const Self& other );
164 std::vector< TIndex > m_Seeds;
165 std::vector< TLabel > m_Labels;
169 bool m_NormalizeWeights;
171 itk::SimpleFastMutexLock m_Mutex;
178 #ifndef ITK_MANUAL_INSTANTIATION
179 # include <fpa/Common/OriginalRandomWalker.hxx>
180 #endif // ITK_MANUAL_INSTANTIATION
181 #endif // __fpa__Common__OriginalRandomWalker__h__