1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Common__RandomWalker__h__
6 #define __fpa__Common__RandomWalker__h__
8 #include <fpa/Config.h>
12 #include <itkImageToImageFilter.h>
13 #include <itkSimpleFastMutexLock.h>
14 #include <fpa/Functors/VertexFunction.h>
22 template< class _TImage, class _TLabels, class _TScalar = float >
24 : public itk::ImageToImageFilter< _TImage, _TLabels >
27 typedef _TImage TImage;
28 typedef _TLabels TLabels;
29 typedef _TScalar TScalar;
31 typedef RandomWalker Self;
32 typedef itk::ImageToImageFilter< TImage, TLabels > Superclass;
33 typedef itk::SmartPointer< Self > Pointer;
34 typedef itk::SmartPointer< const Self > ConstPointer;
36 typedef itk::Image< TScalar, TImage::ImageDimension > TScalarImage;
37 typedef typename TImage::IndexType TIndex;
38 typedef typename TImage::PixelType TPixel;
39 typedef typename TImage::RegionType TRegion;
40 typedef typename TLabels::PixelType TLabel;
42 typedef fpa::Functors::VertexFunction< TIndex, TScalar > TEdgeFunction;
45 struct _TBoundaryThreadStruct
49 std::map< TLabel, unsigned long >* Labels;
52 struct _TLaplacianThreadStruct
60 struct _TOutputThreadStruct
65 const std::vector< TLabel >* InvLabels;
71 fpa::Common::RandomWalker, itk::ImageToImageFilter
74 itkGetConstObjectMacro( EdgeFunction, TEdgeFunction );
75 itkGetObjectMacro( EdgeFunction, TEdgeFunction );
76 itkSetObjectMacro( EdgeFunction, TEdgeFunction );
78 ivqITKInputMacro( InputLabels, TLabels );
79 ivqITKOutputMacro( OutputProbabilities, TScalarImage );
83 virtual ~RandomWalker( );
85 virtual void GenerateData( ) override;
87 virtual TScalar _L( const TIndex& i, const TIndex& j );
89 // Boundary construction
90 template< class _TTriplets >
93 std::map< TLabel, unsigned long >& labels
96 template< class _TTriplets >
97 static ITK_THREAD_RETURN_TYPE _BoundaryCbk( void* arg );
99 template< class _TTriplets >
100 void _ThreadedBoundary(
101 const TRegion& region, const itk::ThreadIdType& id,
103 std::map< TLabel, unsigned long >* labels
106 // Laplacian construction
107 template< class _TTriplets >
109 _TTriplets& A, _TTriplets& R, const _TTriplets& B
112 template< class _TTriplets >
113 static ITK_THREAD_RETURN_TYPE _LaplacianCbk( void* arg );
115 template< class _TTriplets >
116 void _ThreadedLaplacian(
117 const TRegion& region, const itk::ThreadIdType& id,
118 _TTriplets* A, _TTriplets* R, const _TTriplets* B
122 template< class _TMatrix, class _TTriplets >
124 const _TMatrix& X, const _TTriplets& S,
125 const std::vector< TLabel >& invLabels
128 template< class _TMatrix, class _TTriplets >
129 static ITK_THREAD_RETURN_TYPE _OutputCbk( void* arg );
131 template< class _TMatrix, class _TTriplets >
132 void _ThreadedOutput(
133 const TRegion& region, const itk::ThreadIdType& id,
134 const _TMatrix* X, const _TTriplets* S,
135 const std::vector< TLabel >* invLabels
138 // Array-Image conversion
139 static unsigned long _1D( const TIndex& idx, const TRegion& region );
141 template< class _TTriplets >
142 static unsigned long _SeedIndex(
143 const unsigned long& i, const _TTriplets& t
146 template< class _TTriplets >
147 static unsigned long _NearSeedIndex(
148 const unsigned long& i, const _TTriplets& t
152 // Purposely not implemented
153 RandomWalker( const Self& other );
154 Self& operator=( const Self& other );
157 typename TEdgeFunction::Pointer m_EdgeFunction;
158 itk::SimpleFastMutexLock m_Mutex;
165 #ifndef ITK_MANUAL_INSTANTIATION
166 # include <fpa/Common/RandomWalker.hxx>
167 #endif // ITK_MANUAL_INSTANTIATION
168 #endif // __fpa__Common__RandomWalker__h__