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); }
00153 
00157   void SetOrderEigenMagnitudes( const bool b ) 
00158     {  
00159     if (b) { m_OrderEigenValues = OrderByMagnitude; }
00160     else   { m_OrderEigenValues = DoNotOrder;       }
00161     } 
00162   bool GetOrderEigenMagnitudes() const { return (m_OrderEigenValues == OrderByMagnitude); }
00164 
00167   void SetDimension( const unsigned int n )
00168     {
00169     m_Dimension = n;
00170     if (m_Order == 0 ) 
00171       {
00172       m_Order = m_Dimension;
00173       }
00174     }
00176 
00179   unsigned int GetDimension() const { return m_Dimension; }
00180 
00181 
00182 private:
00183   unsigned int m_Dimension;
00184   unsigned int m_Order;
00185   EigenValueOrderType         m_OrderEigenValues;
00186 
00187  
00207   void ReduceToTridiagonalMatrix(double *inputMatrix, VectorType &d, 
00208                                  double *e, double *e2) const;
00209 
00210 
00211   
00233   void ReduceToTridiagonalMatrixAndGetTransformation(
00234                   double *inputMatrix, VectorType &diagonalElements, 
00235                   double *subDiagonalElements, double *transformMatrix) const;
00236 
00237 
00238   
00239   /* Finds the eigenvalues of a symmetric tridiagonal matrix by the ql method.
00240    *
00241    * On input:
00242    * 'd' contains the diagonal elements of the input matrix.           
00243    * 'e' contains the subdiagonal elements of the input matrix     
00244    * in its last n-1 positions.  e(1) is arbitrary.       
00245    * On Output:
00246    * 'd' contains the eigenvalues.
00247    * 'e' has been destroyed.                                           
00248    * 
00249    * Returns:                                                  
00250    *          zero       for normal return,                                 
00251    *          j          if the j-th eigenvalue has not been                
00252    *                     determined after 30 iterations.                    
00253    *                                                                        
00254    * 
00255    * Reference
00256    *     this subroutine is a translation of the algol procedure tql1,      
00257    *     num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and      
00258    *     wilkinson.                                                         
00259    *     handbook for auto. comp., vol.ii-linear algebra, 227-240(1971).    
00260    *     
00261    *     Questions and comments should be directed to burton s. garbow,     
00262    *     mathematics and computer science div, argonne national laboratory  
00263    *     this version dated august 1983.                                   
00264    *                                                                        
00265    *  Function Adapted from netlib/tql1.c. 
00266    *  [Changed: remove static vars, enforce const correctness.  
00267    *            Use vnl routines as necessary]                      */
00268   unsigned int ComputeEigenValuesUsingQL(
00269                          VectorType &d, double *e) const;
00270 
00271   
00272   /* Finds the eigenvalues and eigenvectors of a symmetric tridiagonal matrix 
00273    * by the ql method.
00274    *
00275    * On input:
00276    * 'd' contains the diagonal elements of the input matrix.           
00277    * 'e' contains the subdiagonal elements of the input matrix     
00278    * in its last n-1 positions.  e(1) is arbitrary.       
00279    * 'z' contains the transformation matrix produced in the reduction by  
00280    * ReduceToTridiagonalMatrixAndGetTransformation(), if performed. If the 
00281    * eigenvectors of the tridiagonal matrix are desired, z must contain         
00282    * the identity matrix.                                          
00283 
00284    * On Output:
00285    * 'd' contains the eigenvalues.
00286    * 'e' has been destroyed.                                           
00287    * 'z' contains orthonormal eigenvectors of the symmetric tridiagonal 
00288    * (or full) matrix. 
00289    * 
00290    * Returns:                                                  
00291    *          zero       for normal return,                                 
00292    *          j          if the j-th eigenvalue has not been                
00293    *                     determined after 1000 iterations.                    
00294    * 
00295    * Reference
00296    *     this subroutine is a translation of the algol procedure tql1,      
00297    *     num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and      
00298    *     wilkinson.                                                         
00299    *     handbook for auto. comp., vol.ii-linear algebra, 227-240(1971).    
00300    *     
00301    *     Questions and comments should be directed to burton s. garbow,     
00302    *     mathematics and computer science div, argonne national laboratory  
00303    *     this version dated august 1983.                                   
00304    *                                                                        
00305    *  Function Adapted from netlib/tql2.c. 
00306    *  [Changed: remove static vars, enforce const correctness.  
00307    *            Use vnl routines as necessary]                      
00308    */
00309   unsigned int ComputeEigenValuesAndVectorsUsingQL(
00310                                    VectorType &d, double *e, double *z) const;
00311   
00312 };
00313 
00314 template< typename TMatrix, typename TVector, typename TEigenMatrix >
00315 std::ostream & operator<<(std::ostream& os, 
00316     const SymmetricEigenAnalysis< TMatrix, TVector, TEigenMatrix > &s) 
00317 {
00318   os << "[ClassType: SymmetricEigenAnalysis]" << std::endl;
00319   os << "  Dimension : " << s.GetDimension() << std::endl;
00320   os << "  Order : " << s.GetOrder() << std::endl;
00321   os << "  OrderEigenValues: " << s.GetOrderEigenValues() << std::endl;
00322   os << "  OrderEigenMagnitudes: " << s.GetOrderEigenMagnitudes() << std::endl;
00323   return os;
00324 }
00325 
00326 } // end namespace itk
00327 
00328 
00329 #ifndef ITK_MANUAL_INSTANTIATION
00330 #include "itkSymmetricEigenAnalysis.txx"
00331 #endif
00332 
00333 #endif
00334 
00335 

Generated at Tue Jul 29 22:44:31 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000