ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkVectorRescaleIntensityImageFilter.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 __itkVectorRescaleIntensityImageFilter_h
00019 #define __itkVectorRescaleIntensityImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 
00023 namespace itk
00024 {
00025 // This functor class applies a scaling transformation A.x
00026 // to input values.
00027 namespace Functor
00028 {
00029 template< typename TInput, typename  TOutput >
00030 class VectorMagnitudeLinearTransform
00031 {
00032 public:
00033   typedef typename NumericTraits< typename TInput::ValueType >::RealType RealType;
00034   VectorMagnitudeLinearTransform() {}
00035   ~VectorMagnitudeLinearTransform() {}
00036   void SetFactor(RealType a) { m_Factor = a; }
00037   itkStaticConstMacro(VectorDimension, unsigned int, TInput::Dimension);
00038   bool operator!=(const VectorMagnitudeLinearTransform & other) const
00039   {
00040     if ( m_Factor != other.m_Factor )
00041       {
00042       return true;
00043       }
00044     return false;
00045   }
00046 
00047   bool operator==(const VectorMagnitudeLinearTransform & other) const
00048   {
00049     return !( *this != other );
00050   }
00051 
00052   inline TOutput operator()(const TInput & x) const
00053   {
00054     TOutput result;
00055 
00056     for ( unsigned int i = 0; i < VectorDimension; i++ )
00057       {
00058       const RealType scaledComponent = static_cast< RealType >( x[i] ) * m_Factor;
00059       result[i] = static_cast< typename TOutput::ValueType >( scaledComponent );
00060       }
00061     return result;
00062   }
00063 
00064 private:
00065   RealType m_Factor;
00066 };
00067 }  // end namespace functor
00068 
00091 template< typename  TInputImage, typename  TOutputImage = TInputImage >
00092 class ITK_EXPORT VectorRescaleIntensityImageFilter:
00093   public
00094   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00095                            Functor::VectorMagnitudeLinearTransform<
00096                              typename TInputImage::PixelType,
00097                              typename TOutputImage::PixelType >   >
00098 {
00099 public:
00101   typedef VectorRescaleIntensityImageFilter Self;
00102   typedef UnaryFunctorImageFilter<
00103     TInputImage, TOutputImage,
00104     Functor::VectorMagnitudeLinearTransform<
00105       typename TInputImage::PixelType,
00106       typename TOutputImage::PixelType > >    Superclass;
00107 
00108   typedef SmartPointer< Self >       Pointer;
00109   typedef SmartPointer< const Self > ConstPointer;
00110 
00111   typedef typename TOutputImage::PixelType                    OutputPixelType;
00112   typedef typename TInputImage::PixelType                     InputPixelType;
00113   typedef typename InputPixelType::ValueType                  InputValueType;
00114   typedef typename OutputPixelType::ValueType                 OutputValueType;
00115   typedef typename NumericTraits< InputValueType >::RealType  InputRealType;
00116   typedef typename NumericTraits< OutputValueType >::RealType OutputRealType;
00117 
00118   typedef typename Superclass::InputImageType    InputImageType;
00119   typedef typename Superclass::InputImagePointer InputImagePointer;
00120 
00122   itkTypeMacro(VectorRescaleIntensityImageFilter, UnaryFunctorImageFilter);
00123 
00125   itkNewMacro(Self);
00126 
00127   itkSetMacro(OutputMaximumMagnitude, OutputRealType);
00128   itkGetConstReferenceMacro(OutputMaximumMagnitude, OutputRealType);
00129 
00133   itkGetConstReferenceMacro(Scale, InputRealType);
00134   itkGetConstReferenceMacro(Shift, InputRealType);
00136 
00139   itkGetConstReferenceMacro(InputMaximumMagnitude, InputRealType);
00140 
00142   void BeforeThreadedGenerateData(void);
00143 
00145   void PrintSelf(std::ostream & os, Indent indent) const;
00146 
00147 #ifdef ITK_USE_CONCEPT_CHECKING
00148 
00149   itkConceptMacro( InputHasNumericTraitsCheck,
00150                    ( Concept::HasNumericTraits< InputValueType > ) );
00151   itkConceptMacro( OutputHasNumericTraitsCheck,
00152                    ( Concept::HasNumericTraits< OutputValueType > ) );
00153 
00155 #endif
00156 protected:
00157   VectorRescaleIntensityImageFilter();
00158   virtual ~VectorRescaleIntensityImageFilter() {}
00159 private:
00160   VectorRescaleIntensityImageFilter(const Self &); //purposely not implemented
00161   void operator=(const Self &);                    //purposely not implemented
00163 
00164   InputRealType m_Scale;
00165   InputRealType m_Shift;
00166 
00167   InputRealType  m_InputMaximumMagnitude;
00168   OutputRealType m_OutputMaximumMagnitude;
00169 };
00170 } // end namespace itk
00171 
00172 #ifndef ITK_MANUAL_INSTANTIATION
00173 #include "itkVectorRescaleIntensityImageFilter.hxx"
00174 #endif
00175 
00176 #endif
00177