// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __fpa__Common__OriginalRandomWalker__h__ #define __fpa__Common__OriginalRandomWalker__h__ #include #include #include #include #include #include #include namespace fpa { namespace Common { /** */ template< class _TImage, class _TLabels, class _TScalar = float > class OriginalRandomWalker : public itk::ImageToImageFilter< _TImage, _TLabels > { public: typedef _TImage TImage; typedef _TLabels TLabels; typedef _TScalar TScalar; typedef OriginalRandomWalker Self; typedef itk::ImageToImageFilter< TImage, TLabels > Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; typedef itk::Image< TScalar, TImage::ImageDimension > TScalarImage; typedef typename TImage::IndexType TIndex; typedef typename TImage::PixelType TPixel; typedef typename TImage::RegionType TRegion; typedef typename TLabels::PixelType TLabel; typedef fpa::Functors::VertexFunction< TIndex, TScalar > TEdgeFunction; protected: struct _TBoundaryThreadStruct { Pointer Filter; void* Triplets; std::map< TLabel, unsigned long >* Labels; }; struct _TLaplacianThreadStruct { Pointer Filter; void* A; void* R; const void* B; }; struct _TOutputThreadStruct { Pointer Filter; const void* X; const void* S; const std::vector< TLabel >* InvLabels; }; public: itkNewMacro( Self ); itkTypeMacro( fpa::Common::OriginalRandomWalker, itk::ImageToImageFilter ); itkGetConstObjectMacro( EdgeFunction, TEdgeFunction ); itkGetObjectMacro( EdgeFunction, TEdgeFunction ); itkSetObjectMacro( EdgeFunction, TEdgeFunction ); fpaFilterInputMacro( InputLabels, TLabels ); fpaFilterOutputMacro( OutputProbabilities, TScalarImage ); /* TODO public: void AddSeed( const TIndex& seed, const TLabel& label ); */ protected: OriginalRandomWalker( ); virtual ~OriginalRandomWalker( ); virtual void GenerateData( ) override; virtual TScalar _L( const TIndex& i, const TIndex& j ); // Boundary construction template< class _TTriplets > void _Boundary( _TTriplets& B, std::map< TLabel, unsigned long >& labels ); template< class _TTriplets > static ITK_THREAD_RETURN_TYPE _BoundaryCbk( void* arg ); template< class _TTriplets > void _ThreadedBoundary( const TRegion& region, const itk::ThreadIdType& id, _TTriplets* B, std::map< TLabel, unsigned long >* labels ); // Laplacian construction template< class _TTriplets > void _Laplacian( _TTriplets& A, _TTriplets& R, const _TTriplets& B ); template< class _TTriplets > static ITK_THREAD_RETURN_TYPE _LaplacianCbk( void* arg ); template< class _TTriplets > void _ThreadedLaplacian( const TRegion& region, const itk::ThreadIdType& id, _TTriplets* A, _TTriplets* R, const _TTriplets* B ); // Output filling template< class _TMatrix, class _TTriplets > void _Output( const _TMatrix& X, const _TTriplets& S, const std::vector< TLabel >& invLabels ); template< class _TMatrix, class _TTriplets > static ITK_THREAD_RETURN_TYPE _OutputCbk( void* arg ); template< class _TMatrix, class _TTriplets > void _ThreadedOutput( const TRegion& region, const itk::ThreadIdType& id, const _TMatrix* X, const _TTriplets* S, const std::vector< TLabel >* invLabels ); // Array-Image conversion static unsigned long _1D( const TIndex& idx, const TRegion& region ); template< class _TTriplets > static unsigned long _SeedIndex( const unsigned long& i, const _TTriplets& t ); template< class _TTriplets > static unsigned long _NearSeedIndex( const unsigned long& i, const _TTriplets& t ); private: // Purposely not implemented OriginalRandomWalker( const Self& other ); Self& operator=( const Self& other ); protected: /* TODO std::vector< TIndex > m_Seeds; std::vector< TLabel > m_Labels; */ typename TEdgeFunction::Pointer m_EdgeFunction; itk::SimpleFastMutexLock m_Mutex; }; } // ecapseman } // ecapseman #ifndef ITK_MANUAL_INSTANTIATION # include #endif // ITK_MANUAL_INSTANTIATION #endif // __fpa__Common__OriginalRandomWalker__h__ // eof - $RCSfile$