ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSymmetricEigenAnalysisImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkSymmetricEigenAnalysisImageFilter_h
00019 #define __itkSymmetricEigenAnalysisImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkSymmetricEigenAnalysis.h"
00023 
00024 namespace itk
00025 {
00026 // This functor class invokes the computation of Eigen Analysis for
00027 // every pixel. The input pixel type must provide the API for the [][]
00028 // operator, while the output pixel type must provide the API for the
00029 // [] operator. Input pixel matrices should be symmetric.
00030 //
00031 // The default operation is to order eigen values in ascending order.
00032 // You may also use OrderEigenValuesBy( ) to order eigen values by
00033 // magnitude as is common with use of tensors in vessel extraction.
00034 namespace Functor
00035 {
00036 template< typename TInput, typename TOutput >
00037 class SymmetricEigenAnalysisFunction
00038 {
00039 public:
00040   typedef typename TInput::RealValueType RealValueType;
00041   SymmetricEigenAnalysisFunction() {}
00042   ~SymmetricEigenAnalysisFunction() {}
00043   typedef SymmetricEigenAnalysis< TInput, TOutput > CalculatorType;
00044   bool operator!=(const SymmetricEigenAnalysisFunction &) const
00045   {
00046     return false;
00047   }
00048 
00049   bool operator==(const SymmetricEigenAnalysisFunction & other) const
00050   {
00051     return !( *this != other );
00052   }
00053 
00054   inline TOutput operator()(const TInput & x) const
00055   {
00056     TOutput eigenValues;
00057 
00058     m_Calculator.ComputeEigenValues(x, eigenValues);
00059     return eigenValues;
00060   }
00061 
00063   void SetDimension(unsigned int n)
00064   {
00065     m_Calculator.SetDimension(n);
00066   }
00067 
00073   typedef enum {
00074     OrderByValue = 1,
00075     OrderByMagnitude,
00076     DoNotOrder
00077     } EigenValueOrderType;
00078 
00081   void OrderEigenValuesBy(EigenValueOrderType order)
00082   {
00083     if ( order == OrderByMagnitude )
00084       {
00085       m_Calculator.SetOrderEigenMagnitudes(true);
00086       }
00087     else if ( order == DoNotOrder )
00088       {
00089       m_Calculator.SetOrderEigenValues(false);
00090       }
00091   }
00093 
00094 private:
00095   CalculatorType m_Calculator;
00096 };
00097 }  // end namespace functor
00098 
00119 template< typename  TInputImage, typename  TOutputImage = TInputImage >
00120 class ITK_EXPORT SymmetricEigenAnalysisImageFilter:
00121   public
00122   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00123                            Functor::SymmetricEigenAnalysisFunction<
00124                              typename TInputImage::PixelType,
00125                              typename TOutputImage::PixelType > >
00126 {
00127 public:
00129   typedef SymmetricEigenAnalysisImageFilter Self;
00130   typedef UnaryFunctorImageFilter<
00131     TInputImage, TOutputImage,
00132     Functor::SymmetricEigenAnalysisFunction<
00133       typename TInputImage::PixelType,
00134       typename TOutputImage::PixelType > >   Superclass;
00135 
00136   typedef SmartPointer< Self >       Pointer;
00137   typedef SmartPointer< const Self > ConstPointer;
00138 
00139   typedef typename Superclass::OutputImageType OutputImageType;
00140   typedef typename TOutputImage::PixelType     OutputPixelType;
00141   typedef typename TInputImage::PixelType      InputPixelType;
00142   typedef typename InputPixelType::ValueType   InputValueType;
00143   typedef typename Superclass::FunctorType     FunctorType;
00144 
00150   typedef typename FunctorType::EigenValueOrderType EigenValueOrderType;
00151 
00154   void OrderEigenValuesBy(EigenValueOrderType order)
00155   {
00156     this->GetFunctor().OrderEigenValuesBy(order);
00157   }
00158 
00160   itkTypeMacro(SymmetricEigenAnalysisImageFilter, UnaryFunctorImageFilter);
00161 
00163   itkNewMacro(Self);
00164 
00166   void PrintSelf(std::ostream & os, Indent indent) const
00167   { this->Superclass::PrintSelf(os, indent); }
00168 
00171   void SetDimension(unsigned int p)
00172   {
00173     this->GetFunctor().SetDimension(p);
00174   }
00175 
00176 #ifdef ITK_USE_CONCEPT_CHECKING
00177 
00178   itkConceptMacro( InputHasNumericTraitsCheck,
00179                    ( Concept::HasNumericTraits< InputValueType > ) );
00180 
00182 #endif
00183 protected:
00184   SymmetricEigenAnalysisImageFilter() {}
00185   virtual ~SymmetricEigenAnalysisImageFilter() {}
00186 private:
00187   SymmetricEigenAnalysisImageFilter(const Self &); //purposely not implemented
00188   void operator=(const Self &);                    //purposely not implemented
00189 };
00190 } // end namespace itk
00192 
00193 #endif
00194