Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSymmetricEigenAnalysis.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSymmetricEigenAnalysis.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/07/09 22:43:35 $
00007   Version:   $Revision: 1.5 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkSymmetricEigenAnalysis_h
00018 #define __itkSymmetricEigenAnalysis_h
00019 
00020 #include "itkMacro.h"
00021 
00022 namespace itk
00023 {
00024   
00059 template < typename TMatrix, typename TVector, typename TEigenMatrix=TMatrix >
00060 class SymmetricEigenAnalysis
00061 {
00062 public:
00063   typedef enum {
00064     OrderByValue=1,
00065     OrderByMagnitude,
00066     DoNotOrder
00067   }EigenValueOrderType;
00068   
00069   SymmetricEigenAnalysis():
00070       m_Dimension(0),
00071       m_Order(0),
00072       m_OrderEigenValues(OrderByValue)
00073     {} ;
00074   
00075   SymmetricEigenAnalysis( const unsigned int dimension ):
00076       m_Dimension(dimension),
00077       m_Order(dimension),
00078       m_OrderEigenValues(OrderByValue)
00079     {} ;
00080 
00081   ~SymmetricEigenAnalysis() {};
00082 
00083   typedef TMatrix      MatrixType;
00084   typedef TEigenMatrix EigenMatrixType;
00085   typedef TVector      VectorType;
00086 
00087 
00088 
00102   unsigned int ComputeEigenValues( 
00103               const TMatrix  & A,
00104               TVector        & EigenValues) const;
00105               
00126   unsigned int ComputeEigenValuesAndVectors(
00127               const TMatrix  & A,
00128               TVector        & EigenValues,
00129               TEigenMatrix   & EigenVectors ) const;
00130 
00131   
00133   void SetOrder(const unsigned int n)
00134     {
00135     m_Order = n;
00136     }
00137   
00141   unsigned int GetOrder() const { return m_Order; }
00142 
00146   void SetOrderEigenValues( const bool b ) 
00147     {  
00148     if (b) { m_OrderEigenValues = OrderByValue;     }
00149     else   { m_OrderEigenValues = DoNotOrder;       }
00150     }
00151   bool GetOrderEigenValues() const { return (m_OrderEigenValues == OrderByValue); }
00152 
00156   void SetOrderEigenMagnitudes( const bool b ) 
00157     {  
00158     if (b) { m_OrderEigenValues = OrderByMagnitude; }
00159     else   { m_OrderEigenValues = DoNotOrder;       }
00160     } 
00161   bool GetOrderEigenMagnitudes() const { return (m_OrderEigenValues == OrderByMagnitude); }
00162 
00165   void SetDimension( const unsigned int n )
00166     {
00167     m_Dimension = n;
00168     if (m_Order == 0 ) 
00169       {
00170       m_Order = m_Dimension;
00171       }
00172     }
00173   
00176   unsigned int GetDimension() const { return m_Dimension; }
00177 
00178 
00179 private:
00180   unsigned int m_Dimension;
00181   unsigned int m_Order;
00182   EigenValueOrderType         m_OrderEigenValues;
00183 
00184  
00204   void ReduceToTridiagonalMatrix(double *inputMatrix, VectorType &d, 
00205                                  double *e, double *e2) const;
00206 
00207 
00208   
00230   void ReduceToTridiagonalMatrixAndGetTransformation(
00231                   double *inputMatrix, VectorType &diagonalElements, 
00232                   double *subDiagonalElements, double *transformMatrix) const;
00233   
00234 
00235   
00236   /* Finds the eigenvalues of a symmetric tridiagonal matrix by the ql method.
00237    *
00238    * On input:
00239    * 'd' contains the diagonal elements of the input matrix.           
00240    * 'e' contains the subdiagonal elements of the input matrix     
00241    * in its last n-1 positions.  e(1) is arbitrary.       
00242    * On Output:
00243    * 'd' contains the eigenvalues.
00244    * 'e' has been destroyed.                                           
00245    * 
00246    * Returns:                                                  
00247    *          zero       for normal return,                                 
00248    *          j          if the j-th eigenvalue has not been                
00249    *                     determined after 30 iterations.                    
00250    *                                                                        
00251    * 
00252    * Reference
00253    *     this subroutine is a translation of the algol procedure tql1,      
00254    *     num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and      
00255    *     wilkinson.                                                         
00256    *     handbook for auto. comp., vol.ii-linear algebra, 227-240(1971).    
00257    *     
00258    *     Questions and comments should be directed to burton s. garbow,     
00259    *     mathematics and computer science div, argonne national laboratory  
00260    *     this version dated august 1983.                                   
00261    *                                                                        
00262    *  Function Adapted from netlib/tql1.c. 
00263    *  [Changed: remove static vars, enforce const correctness.  
00264    *            Use vnl routines as necessary]                      */
00265   unsigned int ComputeEigenValuesUsingQL(
00266                          VectorType &d, double *e) const;
00267 
00268   
00269   /* Finds the eigenvalues and eigenvectors of a symmetric tridiagonal matrix 
00270    * by the ql method.
00271    *
00272    * On input:
00273    * 'd' contains the diagonal elements of the input matrix.           
00274    * 'e' contains the subdiagonal elements of the input matrix     
00275    * in its last n-1 positions.  e(1) is arbitrary.       
00276    * 'z' contains the transformation matrix produced in the reduction by  
00277    * ReduceToTridiagonalMatrixAndGetTransformation(), if performed. If the 
00278    * eigenvectors of the tridiagonal matrix are desired, z must contain         
00279    * the identity matrix.                                          
00280 
00281    * On Output:
00282    * 'd' contains the eigenvalues.
00283    * 'e' has been destroyed.                                           
00284    * 'z' contains orthonormal eigenvectors of the symmetric tridiagonal 
00285    * (or full) matrix. 
00286    * 
00287    * Returns:                                                  
00288    *          zero       for normal return,                                 
00289    *          j          if the j-th eigenvalue has not been                
00290    *                     determined after 1000 iterations.                    
00291    * 
00292    * Reference
00293    *     this subroutine is a translation of the algol procedure tql1,      
00294    *     num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and      
00295    *     wilkinson.                                                         
00296    *     handbook for auto. comp., vol.ii-linear algebra, 227-240(1971).    
00297    *     
00298    *     Questions and comments should be directed to burton s. garbow,     
00299    *     mathematics and computer science div, argonne national laboratory  
00300    *     this version dated august 1983.                                   
00301    *                                                                        
00302    *  Function Adapted from netlib/tql2.c. 
00303    *  [Changed: remove static vars, enforce const correctness.  
00304    *            Use vnl routines as necessary]                      
00305    */
00306   unsigned int ComputeEigenValuesAndVectorsUsingQL(
00307                                    VectorType &d, double *e, double *z) const;
00308   
00309 };
00310 
00311 template< typename TMatrix, typename TVector, typename TEigenMatrix >
00312 std::ostream & operator<<(std::ostream& os, 
00313     const SymmetricEigenAnalysis< TMatrix, TVector, TEigenMatrix > &s) 
00314 {
00315   os << "[ClassType: SymmetricEigenAnalysis]" << std::endl;
00316   os << "  Dimension : " << s.GetDimension() << std::endl;
00317   os << "  Order : " << s.GetOrder() << std::endl;
00318   os << "  OrderEigenValues: " << s.GetOrderEigenValues() << std::endl;
00319   os << "  OrderEigenMagnitudes: " << s.GetOrderEigenMagnitudes() << std::endl;
00320   return os;
00321 }
00322 
00323 } // end namespace itk
00324 
00325 
00326 #ifndef ITK_MANUAL_INSTANTIATION
00327 #include "itkSymmetricEigenAnalysis.txx"
00328 #endif
00329 
00330 #endif
00331 

Generated at Thu May 25 00:07:13 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000