]> Creatis software - cpPlugins.git/commitdiff
Kalman completely ported
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 25 Aug 2015 00:21:22 +0000 (19:21 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 25 Aug 2015 00:21:22 +0000 (19:21 -0500)
lib/cpPlugins/Extensions/Algorithms/IsoImageSlicer.h
lib/cpPlugins/Extensions/Algorithms/KalmanConstantFilter.cxx [new file with mode: 0644]
lib/cpPlugins/Extensions/Algorithms/KalmanConstantFilter.h [new file with mode: 0644]
lib/cpPlugins/Extensions/Algorithms/KalmanFilter.cxx
lib/cpPlugins/Extensions/Algorithms/KalmanFilter.h
lib/cpPlugins/Extensions/Algorithms/KalmanVelocityFilter.cxx [new file with mode: 0644]
lib/cpPlugins/Extensions/Algorithms/KalmanVelocityFilter.h [new file with mode: 0644]

index cda4130cf585f43cd9228e0d0db7f43001f615f4..e623670924c01dddcf6574139d51b9b7dc140cd9 100644 (file)
@@ -167,15 +167,16 @@ namespace cpPlugins
     namespace Algorithms
     {
       CPPLUGINS_DEFINE_ISOIMAGESLICER(
-    IsoImageSlicer,
-    itk::ResampleImageFilter,
-    itk::InterpolateImageFunction
-    );
+        IsoImageSlicer,
+        itk::ResampleImageFilter,
+        itk::InterpolateImageFunction
+        );
       CPPLUGINS_DEFINE_ISOIMAGESLICER(
-    VectorIsoImageSlicer,
-    itk::VectorResampleImageFilter,
-    itk::VectorInterpolateImageFunction
-    );
+        VectorIsoImageSlicer,
+        itk::VectorResampleImageFilter,
+        itk::VectorInterpolateImageFunction
+        );
+
     } // ecapseman
 
   } // ecapseman
diff --git a/lib/cpPlugins/Extensions/Algorithms/KalmanConstantFilter.cxx b/lib/cpPlugins/Extensions/Algorithms/KalmanConstantFilter.cxx
new file mode 100644 (file)
index 0000000..219aff4
--- /dev/null
@@ -0,0 +1,51 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#include <cpPlugins/Extensions/Algorithms/KalmanConstantFilter.h>
+
+// -------------------------------------------------------------------------
+template< typename T >
+void cpPlugins::Extensions::Algorithms::KalmanConstantFilter< T >::
+Configure( unsigned int m )
+{
+  this->Superclass::Configure( m, 1, m );
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+void cpPlugins::Extensions::Algorithms::KalmanConstantFilter< T >::
+Initialize( )
+{
+  this->Superclass::Initialize( );
+
+  this->m_A.set_identity( );
+  this->m_B.fill( TScalar( 0 ) );
+  this->m_H.set_identity( );
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+cpPlugins::Extensions::Algorithms::KalmanConstantFilter< T >::
+KalmanConstantFilter( )
+  : Superclass( )
+{
+  this->Configure( 1 );
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+cpPlugins::Extensions::Algorithms::KalmanConstantFilter< T >::
+~KalmanConstantFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+// Explicit instantiations
+
+using namespace cpPlugins::Extensions::Algorithms;
+
+template class KalmanConstantFilter< float >;
+template class KalmanConstantFilter< double >;
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Extensions/Algorithms/KalmanConstantFilter.h b/lib/cpPlugins/Extensions/Algorithms/KalmanConstantFilter.h
new file mode 100644 (file)
index 0000000..b8c61bc
--- /dev/null
@@ -0,0 +1,60 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANCONSTANTFILTER__H__
+#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANCONSTANTFILTER__H__
+
+#include <cpPlugins/Extensions/Algorithms/KalmanFilter.h>
+
+namespace cpPlugins
+{
+  namespace Extensions
+  {
+    namespace Algorithms
+    {
+      /**
+       */
+      template< typename T >
+      class KalmanConstantFilter
+        : public KalmanFilter< T >
+      {
+      public:
+        typedef KalmanConstantFilter            Self;
+        typedef KalmanFilter< T >               Superclass;
+        typedef itk::SmartPointer< Self >       Pointer;
+        typedef itk::SmartPointer< const Self > ConstPointer;
+
+        typedef typename Superclass::TScalar TScalar;
+        typedef typename Superclass::TMatrix TMatrix;
+        typedef typename Superclass::TVector TVector;
+
+      public:
+        itkNewMacro( Self );
+        itkTypeMacro( KalmanConstantFilter, KalmanFilter );
+
+      public:
+        void Configure( unsigned int m );
+
+        /// Iteration methods
+        virtual void Initialize( );
+
+      protected:
+        KalmanConstantFilter( );
+        virtual ~KalmanConstantFilter( );
+
+      private:
+        // Purposely not implemented.
+        KalmanConstantFilter( const Self& );
+        void operator=( const Self& );
+      };
+
+    } // ecapseman
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANCONSTANTFILTER__H__
+
+// eof - $RCSfile$
index 9542026453a815c18eeccefe1131df89c6045d41..c7f650d560cb999dd56fff701ffaf4aecd183f6e 100644 (file)
@@ -3,21 +3,6 @@
 #include <cstdlib>
 #include <vnl/algo/vnl_matrix_inverse.h>
 
-// -------------------------------------------------------------------------
-template< typename T >
-cpPlugins::Extensions::Algorithms::KalmanFilter< T >::
-KalmanFilter( unsigned int s, unsigned int i, unsigned int m )
-{
-  this->Configure( s, i, m );
-}
-
-// -------------------------------------------------------------------------
-template< typename T >
-cpPlugins::Extensions::Algorithms::KalmanFilter< T >::
-~KalmanFilter( )
-{
-}
-
 // -------------------------------------------------------------------------
 template< typename T >
 void cpPlugins::Extensions::Algorithms::KalmanFilter< T >::
@@ -127,6 +112,22 @@ Filtrate( )
   } // fi
 }
 
+// -------------------------------------------------------------------------
+template< typename T >
+cpPlugins::Extensions::Algorithms::KalmanFilter< T >::
+KalmanFilter( )
+  : Superclass( )
+{
+  this->Configure( 1, 1, 1 );
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+cpPlugins::Extensions::Algorithms::KalmanFilter< T >::
+~KalmanFilter( )
+{
+}
+
 // -------------------------------------------------------------------------
 // Explicit instantiations
 
index ac5d9e261bc2f7a836dc9f0c8b904b02ca613821..74b0f3ad1009594bde4a677e426c673793a37630 100644 (file)
@@ -5,23 +5,15 @@
 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANFILTER__H__
 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANFILTER__H__
 
+#include <itkObject.h>
+#include <itkObjectFactory.h>
 #include <vnl/vnl_matrix.h>
 #include <vnl/vnl_vector.h>
 
 // -------------------------------------------------------------------------
-#define kalmanGetMacro( type, name )            \
-  virtual type Get##name( ) const               \
-  { return( this->m_##name ); }
-
-// -------------------------------------------------------------------------
-#define kalmanSetMacro( type, name )            \
-  virtual void Set##name( const type& m )       \
-  { this->m_##name = m; }
-
-// -------------------------------------------------------------------------
-#define kalmanGetSetMacro( type, name )         \
-  kalmanGetMacro( type, name );                 \
-  kalmanSetMacro( type, name );
+#define kalmanGetSetMacro( type, name )    \
+  itkGetConstMacro( name, type );          \
+  itkSetMacro( name, type );
 
 // -------------------------------------------------------------------------
 #define kalmanGetMatrixMacro( var, name )       \
@@ -31,7 +23,7 @@
 // -------------------------------------------------------------------------
 #define kalmanSetMatrixMacro( var, name )       \
   virtual void Set##name( const TMatrix& m )    \
-  { this->m_##var = m; }
+  { this->Set##var( m ); }
 
 // -------------------------------------------------------------------------
 #define kalmanGetSetMatrixMacro( var, name )    \
@@ -46,7 +38,7 @@
 // -------------------------------------------------------------------------
 #define kalmanSetVectorMacro( var, name )       \
   virtual void Set##name( const TVector& v )    \
-  { this->m_##var = v; }
+  { this->Set##var( v ); }
 
 // -------------------------------------------------------------------------
 #define kalmanGetSetVectorMacro( var, name )    \
@@ -66,9 +58,13 @@ namespace cpPlugins
        */
       template< typename T >
       class KalmanFilter
+        : public itk::Object
       {
       public:
-        typedef KalmanFilter Self;
+        typedef KalmanFilter                    Self;
+        typedef itk::Object                     Superclass;
+        typedef itk::SmartPointer< Self >       Pointer;
+        typedef itk::SmartPointer< const Self > ConstPointer;
 
         // Template parameters types
         typedef T TScalar;
@@ -86,10 +82,13 @@ namespace cpPlugins
         };
 
       public:
+        itkNewMacro( Self );
+        itkTypeMacro( KalmanFilter, itkObject );
+
         // Values
-        kalmanGetMacro( unsigned int, StateSize );
-        kalmanGetMacro( unsigned int, InputSize );
-        kalmanGetMacro( unsigned int, MeasureSize );
+        itkGetConstMacro( StateSize, unsigned int );
+        itkGetConstMacro( InputSize, unsigned int );
+        itkGetConstMacro( MeasureSize, unsigned int );
 
         // Matrices
         kalmanGetSetMacro( TMatrix, A );
@@ -128,10 +127,6 @@ namespace cpPlugins
         kalmanGetSetVectorMacro( xp, APosterioriState );
 
       public:
-        KalmanFilter(
-          unsigned int s = 1, unsigned int i = 1, unsigned int m = 1
-          );
-        virtual ~KalmanFilter( );
 
         void Configure( unsigned int s, unsigned int i, unsigned int m );
 
@@ -156,6 +151,10 @@ namespace cpPlugins
         unsigned char CurrentStep( ) const
           { return( this->m_Step ); }
 
+      protected:
+        KalmanFilter( );
+        virtual ~KalmanFilter( );
+
       private:
         // Purposely not implemented
         KalmanFilter( const Self& );
diff --git a/lib/cpPlugins/Extensions/Algorithms/KalmanVelocityFilter.cxx b/lib/cpPlugins/Extensions/Algorithms/KalmanVelocityFilter.cxx
new file mode 100644 (file)
index 0000000..6ec3295
--- /dev/null
@@ -0,0 +1,92 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#include <cpPlugins/Extensions/Algorithms/KalmanVelocityFilter.h>
+#include <cmath>
+
+// -------------------------------------------------------------------------
+template< typename T >
+void cpPlugins::Extensions::Algorithms::KalmanVelocityFilter< T >::
+Configure( unsigned int m )
+{
+  this->Superclass::Configure( m << 1, 1, m );
+
+  this->m_TimeOffset.set_size( 2, 2 );
+  this->SetTimeOffset( TScalar( 1 ) );
+
+  this->m_Sigma.set_size( this->m_MeasureSize, this->m_MeasureSize );
+  this->m_Sigma.set_identity( );
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+typename cpPlugins::Extensions::Algorithms::KalmanVelocityFilter< T >::
+TScalar cpPlugins::Extensions::Algorithms::KalmanVelocityFilter< T >::
+GetTimeOffset( ) const
+{
+  return( TScalar( std::sqrt( double( this->m_TimeOffset[ 1 ][ 1 ] ) ) ) );
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+void cpPlugins::Extensions::Algorithms::KalmanVelocityFilter< T >::
+SetTimeOffset( TScalar t )
+{
+  TScalar t2 = t * t;
+  TScalar t3 = t2 * t;
+  TScalar t4 = t3 * t;
+  this->m_TimeOffset[ 0 ][ 0 ] = t4 / TScalar( 4 );
+  this->m_TimeOffset[ 1 ][ 1 ] = t2;
+
+  this->m_TimeOffset[ 0 ][ 1 ] = t3 / TScalar( 2 );
+  this->m_TimeOffset[ 1 ][ 0 ] = this->m_TimeOffset[ 0 ][ 1 ];
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+void cpPlugins::Extensions::Algorithms::KalmanVelocityFilter< T >::
+Initialize( )
+{
+  this->Superclass::Initialize( );
+
+  Self::Kronecker( this->m_Q, this->m_Sigma, this->m_TimeOffset );
+
+  this->m_A.set_identity( );
+  this->m_B.fill( TScalar( 0 ) );
+  this->m_H.fill( TScalar( 0 ) );
+
+  TScalar tOff = this->GetTimeOffset( );
+  for( unsigned int i = 0; i < this->m_MeasureSize; i++ )
+  {
+    this->m_A[ i ][ this->m_MeasureSize + i ] = tOff;
+    this->m_H[ i ][ i ] = TScalar( 1 );
+
+  } // rof
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+cpPlugins::Extensions::Algorithms::KalmanVelocityFilter< T >::
+KalmanVelocityFilter( )
+  : Superclass( )
+{
+  this->Configure( 1 );
+}
+
+// -------------------------------------------------------------------------
+template< typename T >
+cpPlugins::Extensions::Algorithms::KalmanVelocityFilter< T >::
+~KalmanVelocityFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+// Explicit instantiations
+
+using namespace cpPlugins::Extensions::Algorithms;
+
+template class KalmanVelocityFilter< float >;
+template class KalmanVelocityFilter< double >;
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Extensions/Algorithms/KalmanVelocityFilter.h b/lib/cpPlugins/Extensions/Algorithms/KalmanVelocityFilter.h
new file mode 100644 (file)
index 0000000..0454ec3
--- /dev/null
@@ -0,0 +1,70 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANVELOCITYFILTER__H__
+#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANVELOCITYFILTER__H__
+
+#include <cpPlugins/Extensions/Algorithms/KalmanFilter.h>
+
+namespace cpPlugins
+{
+  namespace Extensions
+  {
+    namespace Algorithms
+    {
+      /**
+       */
+      template< typename T >
+      class KalmanVelocityFilter
+        : public KalmanFilter< T >
+      {
+      public:
+        typedef KalmanVelocityFilter            Self;
+        typedef KalmanFilter< T >               Superclass;
+        typedef itk::SmartPointer< Self >       Pointer;
+        typedef itk::SmartPointer< const Self > ConstPointer;
+
+        typedef typename Superclass::TScalar TScalar;
+        typedef typename Superclass::TMatrix TMatrix;
+        typedef typename Superclass::TVector TVector;
+
+      public:
+        itkNewMacro( Self );
+        itkTypeMacro( KalmanVelocityFilter, KalmanFilter );
+
+        kalmanGetSetMacro( TMatrix, Sigma );
+        kalmanGetSetMatrixMacro( Sigma, AccelerationNoise );
+
+      public:
+        void Configure( unsigned int m );
+
+        TScalar GetTimeOffset( ) const;
+        void SetTimeOffset( TScalar t );
+
+        /// Iteration methods
+        virtual void Initialize( );
+
+      protected:
+        KalmanVelocityFilter( );
+        virtual ~KalmanVelocityFilter( );
+
+      private:
+        // Purposely not implemented.
+        KalmanVelocityFilter( const Self& );
+        void operator=( const Self& );
+
+      protected:
+        TMatrix m_TimeOffset;
+        TMatrix m_Sigma;
+      };
+
+    } // ecapseman
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__KALMANVELOCITYFILTER__H__
+
+// eof - $RCSfile$