ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkComposeImageFilter.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 __itkComposeImageFilter_h
00019 #define __itkComposeImageFilter_h
00020 
00021 #include "itkImageToImageFilter.h"
00022 #include "itkVectorImage.h"
00023 #include "itkImageRegionConstIterator.h"
00024 #include <vector>
00025 
00026 namespace itk
00027 {
00056 template< class TInputImage, class TOutputImage=VectorImage<typename TInputImage::PixelType, TInputImage::ImageDimension> >
00057 class ITK_EXPORT ComposeImageFilter:
00058   public ImageToImageFilter< TInputImage, TOutputImage >
00059 {
00060 public:
00061 
00062   typedef ComposeImageFilter                               Self;
00063   typedef SmartPointer< Self >                             Pointer;
00064   typedef SmartPointer< const Self >                       ConstPointer;
00065   typedef ImageToImageFilter< TInputImage, TOutputImage >  Superclass;
00066   itkNewMacro(Self);
00067   itkTypeMacro(ComposeImageFilter, ImageToImageFilter);
00068 
00069   itkStaticConstMacro(Dimension, unsigned int, TInputImage::ImageDimension);
00070 
00071   typedef TInputImage                          InputImageType;
00072   typedef TOutputImage                         OutputImageType;
00073   typedef typename InputImageType::PixelType   InputPixelType;
00074   typedef typename OutputImageType::PixelType  OutputPixelType;
00075   typedef typename InputImageType::RegionType  RegionType;
00076 
00077   void SetInput1(const InputImageType *image1);
00078   void SetInput2(const InputImageType *image2);
00079   void SetInput3(const InputImageType *image3);
00080 
00081 #ifdef ITK_USE_CONCEPT_CHECKING
00082 
00083   itkConceptMacro( InputCovertibleToOutputCheck,
00084                    ( Concept::Convertible< InputPixelType, typename NumericTraits<OutputPixelType>::ValueType > ) );
00085 
00087 #endif
00088 protected:
00089   ComposeImageFilter();
00090 
00091   virtual void GenerateOutputInformation(void);
00092 
00093   virtual void BeforeThreadedGenerateData();
00094 
00095   virtual void ThreadedGenerateData(const RegionType & outputRegionForThread, ThreadIdType);
00096 
00097 private:
00098   ComposeImageFilter(const Self &); //purposely not implemented
00099   void operator=(const Self &);           //purposely not implemented
00100 
00101 
00102   // we have to specialize the code for complex, because it provides no operator[]
00103   // method
00104   typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
00105   typedef std::vector< InputIteratorType >           InputIteratorContainerType;
00106 
00107   template<class T>
00108   void ComputeOutputPixel(std::complex<T> & pix, InputIteratorContainerType & inputItContainer )
00109     {
00110     pix = std::complex<T>(inputItContainer[0].Get(), inputItContainer[1].Get());
00111     ++( inputItContainer[0] );
00112     ++( inputItContainer[1] );
00113     }
00114   template<class TPixel>
00115   void ComputeOutputPixel(TPixel & pix, InputIteratorContainerType & inputItContainer)
00116     {
00117     for ( unsigned int i = 0; i < this->GetNumberOfInputs(); i++ )
00118       {
00119       pix[i] = static_cast<typename NumericTraits<OutputPixelType>::ValueType >(inputItContainer[i].Get());
00120       ++( inputItContainer[i] );
00121       }
00122     }
00123 };
00124 }
00125 
00126 #ifndef ITK_MANUAL_INSTANTIATION
00127 #include "itkComposeImageFilter.hxx"
00128 #endif
00129 
00130 #endif
00131