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: 2009-03-03 15:09:43 $
00007   Version:   $Revision: 1.6 $
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 
00100   unsigned int ComputeEigenValues(
00101               const TMatrix  & A,
00102               TVector        & EigenValues) const;
00103 
00124   unsigned int ComputeEigenValuesAndVectors(
00125               const TMatrix  & A,
00126               TVector        & EigenValues,
00127               TEigenMatrix   & EigenVectors ) const;
00128 
00129 
00131   void SetOrder(const unsigned int n)
00132     {
00133     m_Order = n;
00134     }
00135 
00139   unsigned int GetOrder() const { return m_Order; }
00140 
00144   void SetOrderEigenValues( const bool b )
00145     {
00146     if (b) { m_OrderEigenValues = OrderByValue;     }
00147     else   { m_OrderEigenValues = DoNotOrder;       }
00148     }
00149   bool GetOrderEigenValues() const { return (m_OrderEigenValues == OrderByValue); }
00151 
00155   void SetOrderEigenMagnitudes( const bool b )
00156     {
00157     if (b) { m_OrderEigenValues = OrderByMagnitude; }
00158     else   { m_OrderEigenValues = DoNotOrder;       }
00159     }
00160   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     }
00174 
00177   unsigned int GetDimension() const { return m_Dimension; }
00178 
00179 
00180 private:
00181   unsigned int         m_Dimension;
00182   unsigned int         m_Order;
00183   EigenValueOrderType  m_OrderEigenValues;
00184 
00185 
00205   void ReduceToTridiagonalMatrix(double *inputMatrix, VectorType &d,
00206                                  double *e, double *e2) const;
00207 
00229   void ReduceToTridiagonalMatrixAndGetTransformation(
00230                   double *inputMatrix, VectorType &diagonalElements,
00231                   double *subDiagonalElements, double *transformMatrix) const;
00232 
00233   /* Finds the eigenvalues of a symmetric tridiagonal matrix by the ql method.
00234    *
00235    * On input:
00236    * 'd' contains the diagonal elements of the input matrix.
00237    * 'e' contains the subdiagonal elements of the input matrix
00238    * in its last n-1 positions.  e(1) is arbitrary.
00239    * On Output:
00240    * 'd' contains the eigenvalues.
00241    * 'e' has been destroyed.
00242    *
00243    * Returns:
00244    *          zero       for normal return,
00245    *          j          if the j-th eigenvalue has not been
00246    *                     determined after 30 iterations.
00247    *
00248    *
00249    * Reference
00250    *     this subroutine is a translation of the algol procedure tql1,
00251    *     num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and
00252    *     wilkinson.
00253    *     handbook for auto. comp., vol.ii-linear algebra, 227-240(1971).
00254    *
00255    *     Questions and comments should be directed to burton s. garbow,
00256    *     mathematics and computer science div, argonne national laboratory
00257    *     this version dated august 1983.
00258    *
00259    *  Function Adapted from netlib/tql1.c.
00260    *  [Changed: remove static vars, enforce const correctness.
00261    *            Use vnl routines as necessary]                      */
00262   unsigned int ComputeEigenValuesUsingQL(
00263                          VectorType &d, double *e) const;
00264 
00265 
00266   /* Finds the eigenvalues and eigenvectors of a symmetric tridiagonal matrix
00267    * by the ql method.
00268    *
00269    * On input:
00270    * 'd' contains the diagonal elements of the input matrix.
00271    * 'e' contains the subdiagonal elements of the input matrix
00272    * in its last n-1 positions.  e(1) is arbitrary.
00273    * 'z' contains the transformation matrix produced in the reduction by
00274    * ReduceToTridiagonalMatrixAndGetTransformation(), if performed. If the
00275    * eigenvectors of the tridiagonal matrix are desired, z must contain
00276    * the identity matrix.
00277 
00278    * On Output:
00279    * 'd' contains the eigenvalues.
00280    * 'e' has been destroyed.
00281    * 'z' contains orthonormal eigenvectors of the symmetric tridiagonal
00282    * (or full) matrix.
00283    *
00284    * Returns:
00285    *          zero       for normal return,
00286    *          j          if the j-th eigenvalue has not been
00287    *                     determined after 1000 iterations.
00288    *
00289    * Reference
00290    *     this subroutine is a translation of the algol procedure tql1,
00291    *     num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and
00292    *     wilkinson.
00293    *     handbook for auto. comp., vol.ii-linear algebra, 227-240(1971).
00294    *
00295    *     Questions and comments should be directed to burton s. garbow,
00296    *     mathematics and computer science div, argonne national laboratory
00297    *     this version dated august 1983.
00298    *
00299    *  Function Adapted from netlib/tql2.c.
00300    *  [Changed: remove static vars, enforce const correctness.
00301    *            Use vnl routines as necessary]
00302    */
00303   unsigned int ComputeEigenValuesAndVectorsUsingQL(
00304                                    VectorType &d, double *e, double *z) const;
00305 
00306 };
00307 
00308 template< typename TMatrix, typename TVector, typename TEigenMatrix >
00309 std::ostream & operator<<(std::ostream& os,
00310     const SymmetricEigenAnalysis< TMatrix, TVector, TEigenMatrix > &s)
00311 {
00312   os << "[ClassType: SymmetricEigenAnalysis]" << std::endl;
00313   os << "  Dimension : " << s.GetDimension() << std::endl;
00314   os << "  Order : " << s.GetOrder() << std::endl;
00315   os << "  OrderEigenValues: " << s.GetOrderEigenValues() << std::endl;
00316   os << "  OrderEigenMagnitudes: " << s.GetOrderEigenMagnitudes() << std::endl;
00317   return os;
00318 }
00319 
00320 } // end namespace itk
00321 
00322 
00323 #ifndef ITK_MANUAL_INSTANTIATION
00324 #include "itkSymmetricEigenAnalysis.txx"
00325 #endif
00326 
00327 #endif
00328 

Generated at Tue Sep 15 05:06:14 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000