]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Common/OriginalRandomWalker.h
...
[FrontAlgorithms.git] / lib / fpa / Common / OriginalRandomWalker.h
index 915cb1979c65012bf85c183086519dc8bb470b14..0c3a9f82f08a8219a10480b1062415a9d526dcf7 100644 (file)
@@ -6,9 +6,12 @@
 #define __fpa__Common__OriginalRandomWalker__h__
 
 #include <fpa/Config.h>
+#include <map>
 #include <vector>
 #include <itkImage.h>
 #include <itkImageToImageFilter.h>
+#include <itkSimpleFastMutexLock.h>
+#include <fpa/Functors/VertexFunction.h>
 
 namespace fpa
 {
@@ -36,27 +39,49 @@ namespace fpa
       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
         );
 
-      itkGetConstMacro( Beta, TScalar );
-      itkSetMacro( Beta, TScalar );
-
-      itkGetConstMacro( Epsilon, TScalar );
-      itkSetMacro( Epsilon, TScalar );
-
-      itkBooleanMacro( NormalizeWeights );
-      itkGetConstMacro( NormalizeWeights, bool );
-      itkSetMacro( NormalizeWeights, bool );
+      itkGetConstObjectMacro( EdgeFunction, TEdgeFunction );
+      itkGetObjectMacro( EdgeFunction, TEdgeFunction );
+      itkSetObjectMacro( EdgeFunction, TEdgeFunction );
 
       fpaFilterInputMacro( InputLabels, TLabels );
       fpaFilterOutputMacro( OutputProbabilities, TScalarImage );
 
-    public:
-      void AddSeed( const TIndex& seed, const TLabel& label );
+      /* TODO
+         public:
+         void AddSeed( const TIndex& seed, const TLabel& label );
+      */
 
     protected:
       OriginalRandomWalker( );
@@ -64,8 +89,69 @@ namespace fpa
 
       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 );
-      static TIndex _ND( const unsigned long& i, 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
@@ -73,12 +159,14 @@ namespace fpa
       Self& operator=( const Self& other );
 
     protected:
-      std::vector< TIndex > m_Seeds;
-      std::vector< TLabel > m_Labels;
+      /* TODO
+         std::vector< TIndex > m_Seeds;
+         std::vector< TLabel > m_Labels;
+      */
+
+      typename TEdgeFunction::Pointer m_EdgeFunction;
 
-      TScalar m_Beta;
-      TScalar m_Epsilon;
-      bool m_NormalizeWeights;
+      itk::SimpleFastMutexLock m_Mutex;
     };
 
   } // ecapseman