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>
14 #include <fpa/Functors/VertexFunction.h>
22 template< class _TImage, class _TLabels, class _TScalar = float >
23 class OriginalRandomWalker
24 : public itk::ImageToImageFilter< _TImage, _TLabels >
27 typedef _TImage TImage;
28 typedef _TLabels TLabels;
29 typedef _TScalar TScalar;
31 typedef OriginalRandomWalker 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::OriginalRandomWalker, itk::ImageToImageFilter
74 itkGetConstObjectMacro( EdgeFunction, TEdgeFunction );
75 itkGetObjectMacro( EdgeFunction, TEdgeFunction );
76 itkSetObjectMacro( EdgeFunction, TEdgeFunction );
78 fpaFilterInputMacro( InputLabels, TLabels );
79 fpaFilterOutputMacro( OutputProbabilities, TScalarImage );
83 void AddSeed( const TIndex& seed, const TLabel& label );
87 OriginalRandomWalker( );
88 virtual ~OriginalRandomWalker( );
90 virtual void GenerateData( ) override;
92 virtual TScalar _L( const TIndex& i, const TIndex& j );
94 // Boundary construction
95 template< class _TTriplets >
98 std::map< TLabel, unsigned long >& labels
101 template< class _TTriplets >
102 static ITK_THREAD_RETURN_TYPE _BoundaryCbk( void* arg );
104 template< class _TTriplets >
105 void _ThreadedBoundary(
106 const TRegion& region, const itk::ThreadIdType& id,
108 std::map< TLabel, unsigned long >* labels
111 // Laplacian construction
112 template< class _TTriplets >
114 _TTriplets& A, _TTriplets& R, const _TTriplets& B
117 template< class _TTriplets >
118 static ITK_THREAD_RETURN_TYPE _LaplacianCbk( void* arg );
120 template< class _TTriplets >
121 void _ThreadedLaplacian(
122 const TRegion& region, const itk::ThreadIdType& id,
123 _TTriplets* A, _TTriplets* R, const _TTriplets* B
127 template< class _TMatrix, class _TTriplets >
129 const _TMatrix& X, const _TTriplets& S,
130 const std::vector< TLabel >& invLabels
133 template< class _TMatrix, class _TTriplets >
134 static ITK_THREAD_RETURN_TYPE _OutputCbk( void* arg );
136 template< class _TMatrix, class _TTriplets >
137 void _ThreadedOutput(
138 const TRegion& region, const itk::ThreadIdType& id,
139 const _TMatrix* X, const _TTriplets* S,
140 const std::vector< TLabel >* invLabels
143 // Array-Image conversion
144 static unsigned long _1D( const TIndex& idx, const TRegion& region );
146 template< class _TTriplets >
147 static unsigned long _SeedIndex(
148 const unsigned long& i, const _TTriplets& t
151 template< class _TTriplets >
152 static unsigned long _NearSeedIndex(
153 const unsigned long& i, const _TTriplets& t
157 // Purposely not implemented
158 OriginalRandomWalker( const Self& other );
159 Self& operator=( const Self& other );
163 std::vector< TIndex > m_Seeds;
164 std::vector< TLabel > m_Labels;
167 typename TEdgeFunction::Pointer m_EdgeFunction;
169 itk::SimpleFastMutexLock m_Mutex;
176 #ifndef ITK_MANUAL_INSTANTIATION
177 # include <fpa/Common/OriginalRandomWalker.hxx>
178 #endif // ITK_MANUAL_INSTANTIATION
179 #endif // __fpa__Common__OriginalRandomWalker__h__