]> Creatis software - FrontAlgorithms.git/commitdiff
Some bugs...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 7 Apr 2015 02:42:16 +0000 (21:42 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 7 Apr 2015 02:42:16 +0000 (21:42 -0500)
appli/examples/example_Image_RegionGrow_GaussianModelEstimation.cxx
lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h [new file with mode: 0644]
lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx [new file with mode: 0644]

index 919409aa948c2838cc253fb39eb7d2f20c392383..2d278783ecbfe66bb98c7cf91d24e0f3348d3e96 100644 (file)
 #include <vtkSeedWidget.h>
 #include <vtkSmartPointer.h>
 
-#include <cpPlugins/Extensions/Algorithms/IterativeGaussianModelEstimator.h>
-#include <cpPlugins/Extensions/Algorithms/RGBToYPbPrFunction.h>
-
 #include <fpa/Image/RegionGrow.h>
-#include <fpa/Base/Functors/TautologyFunction.h>
 #include <fpa/VTK/Image2DObserver.h>
+#include <fpa/Image/Functors/GaussianModelEstimatorFunction.h>
 
 // -------------------------------------------------------------------------
 const unsigned int Dim = 2;
@@ -37,81 +34,6 @@ typedef itk::Image< itk::RGBPixel< TPixel >, Dim > TColorImage;
 typedef itk::Image< TPixel, Dim >                  TImage;
 typedef itk::ImageToVTKImageFilter< TColorImage >  TVTKImage;
 
-// -------------------------------------------------------------------------
-template< class I, class S >
-class GaussianFunction
-  : public itk::FunctionBase< typename I::PixelType, bool >
-{
-public:
-  // Type-related and pointers
-  typedef GaussianFunction                                 Self;
-  typedef itk::FunctionBase< typename I::PixelType, bool > Superclass;
-  typedef itk::SmartPointer< Self >                        Pointer;
-  typedef itk::SmartPointer< const Self >                  ConstPointer;
-
-  // Superclass' types
-  typedef cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, 3 > TEstimator;
-  typedef cpPlugins::Extensions::Algorithms::RGBToYPbPrFunction< S > TYPbPrFunction;
-
-public:
-  itkNewMacro( Self );
-  itkTypeMacro( GaussianFunction, itkFunctionBase );
-
-  itkGetConstMacro( ModelSupport, unsigned long );
-  itkSetMacro( ModelSupport, unsigned long );
-
-public:
-  virtual bool Evaluate( const typename I::PixelType& rgb ) const
-    {
-      /* TODO
-      if( !this->m_Estimating )
-      {
-        this->m_Estimator->AddSample( this->m_YPbPrFunction( rgb ) );
-        if( this->m_Estimator->GetNumberOfSamples( ) == this->m_ModelSupport )
-        {
-          this->m_Estimating = true;
-          this->m_Estimator->UpdateModel( );
-          std::cout << this->m_Estimator->GetMinimumProbability( ) << std::endl;
-          std::cout << this->m_Estimator->GetMaximumProbability( ) << std::endl;
-
-        } // fi
-        return( true );
-      }
-      else
-      {
-        S p = this->m_Estimator->Probability( this->m_YPbPrFunction( rgb ) );
-        return( p > this->m_Estimator->GetMinimumProbability( ) );
-
-      } // fi
-      */
-      return( true );
-    }
-
-protected:
-  GaussianFunction( )
-    : Superclass( ),
-      m_ModelSupport( 10 )
-    {
-      this->m_Estimator = TEstimator::New( );
-      this->m_Estimator->Clear( );
-      this->m_Estimating = false;
-    }
-  virtual ~GaussianFunction( )
-    { }
-
-private:
-  // Purposely not implemented
-  GaussianFunction( const Self& );
-  void operator=( const Self& );
-
-protected:
-  typename TEstimator::Pointer m_Estimator;
-  TYPbPrFunction m_YPbPrFunction;
-
-  unsigned long m_ModelSupport;
-  mutable bool m_Estimating;
-};
-
 // -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
@@ -198,7 +120,7 @@ int main( int argc, char* argv[] )
   interactor->Start( );
 
   // Prepare region grow function
-  typedef GaussianFunction< TColorImage, TScalar > TFunction;
+  typedef fpa::Image::Functors::GaussianModelEstimatorFunction< TColorImage, TScalar > TFunction;
   TFunction::Pointer function = TFunction::New( );
   function->SetModelSupport( support );
 
@@ -239,6 +161,10 @@ int main( int argc, char* argv[] )
   // Go!
   filter->Update( );
 
+  window->Render( );
+  widget->Off( );
+  interactor->Start( );
+
   return( 0 );
 }
 
diff --git a/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h
new file mode 100644 (file)
index 0000000..1017803
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__H__
+#define __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__H__
+
+#include <cpPlugins/Extensions/Algorithms/IterativeGaussianModelEstimator.h>
+#include <cpPlugins/Extensions/Algorithms/RGBToYPbPrFunction.h>
+#include <itkFunctionBase.h>
+
+namespace fpa
+{
+  namespace Image
+  {
+    namespace Functors
+    {
+      /**
+       */
+      template< class I, class S >
+      class GaussianModelEstimatorFunction
+        : public itk::FunctionBase< typename I::PixelType, bool >
+      {
+      public:
+        // Type-related and pointers
+        typedef GaussianModelEstimatorFunction                   Self;
+        typedef itk::FunctionBase< typename I::PixelType, bool > Superclass;
+        typedef itk::SmartPointer< Self >                        Pointer;
+        typedef itk::SmartPointer< const Self >                  ConstPointer;
+
+        // Superclass' types
+        typedef cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, 3 > TEstimator;
+        typedef cpPlugins::Extensions::Algorithms::RGBToYPbPrFunction< S > TYPbPrFunction;
+
+      public:
+        itkNewMacro( Self );
+        itkTypeMacro( GaussianModelEstimatorFunction, itkFunctionBase );
+
+        itkGetConstMacro( ModelSupport, unsigned long );
+        itkSetMacro( ModelSupport, unsigned long );
+
+      public:
+        virtual bool Evaluate( const typename I::PixelType& rgb ) const;
+
+      protected:
+        GaussianModelEstimatorFunction( );
+        virtual ~GaussianModelEstimatorFunction( );
+
+      private:
+        // Purposely not implemented
+        GaussianModelEstimatorFunction( const Self& );
+        void operator=( const Self& );
+
+      protected:
+        typename TEstimator::Pointer m_Estimator;
+        TYPbPrFunction m_YPbPrFunction;
+
+        unsigned long m_ModelSupport;
+        mutable bool m_Estimating;
+      };
+
+    } // ecapseman
+
+  } // ecapseman
+
+} // ecapseman
+
+#include <fpa/Image/Functors/GaussianModelEstimatorFunction.hxx>
+
+#endif // __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__H__
+
+// eof - $RCSfile$
diff --git a/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx
new file mode 100644 (file)
index 0000000..a90a39a
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__
+#define __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__
+
+// -------------------------------------------------------------------------
+template< class I, class S >
+bool fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
+Evaluate( const typename I::PixelType& rgb ) const
+{
+  if( !this->m_Estimating )
+  {
+    this->m_Estimator->AddSample( this->m_YPbPrFunction( rgb ) );
+    if( this->m_Estimator->GetNumberOfSamples( ) == this->m_ModelSupport )
+    {
+      this->m_Estimating = true;
+      this->m_Estimator->UpdateModel( );
+
+    } // fi
+    return( true );
+  }
+  else
+  {
+    S p = this->m_Estimator->Probability( this->m_YPbPrFunction( rgb ) );
+    return( p > this->m_Estimator->GetMinimumProbability( ) );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class I, class S >
+fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
+GaussianModelEstimatorFunction( )
+  : Superclass( ),
+    m_ModelSupport( 10 )
+{
+  this->m_Estimator = TEstimator::New( );
+  this->m_Estimator->Clear( );
+  this->m_Estimating = false;
+}
+
+// -------------------------------------------------------------------------
+template< class I, class S >
+fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
+~GaussianModelEstimatorFunction( )
+{
+}
+
+#endif // __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__
+
+// eof - $RCSfile$