ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkExtractImageFilter.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 __itkExtractImageFilter_h
00019 #define __itkExtractImageFilter_h
00020 
00021 #include "itkInPlaceImageFilter.h"
00022 #include "itkSmartPointer.h"
00023 #include "itkExtractImageFilterRegionCopier.h"
00024 
00025 namespace itk
00026 {
00089 template< class TInputImage, class TOutputImage >
00090 class ITK_EXPORT ExtractImageFilter:
00091   public InPlaceImageFilter< TInputImage, TOutputImage >
00092 {
00093 public:
00095   typedef ExtractImageFilter                              Self;
00096   typedef InPlaceImageFilter< TInputImage, TOutputImage > Superclass;
00097   typedef SmartPointer< Self >                            Pointer;
00098   typedef SmartPointer< const Self >                      ConstPointer;
00099 
00101   itkNewMacro(Self);
00102 
00104   itkTypeMacro(ExtractImageFilter, ImageToImageFilter);
00105 
00107   typedef TInputImage  InputImageType;
00108   typedef TOutputImage OutputImageType;
00109 
00111   typedef typename TOutputImage::RegionType OutputImageRegionType;
00112   typedef typename TInputImage::RegionType  InputImageRegionType;
00113 
00115   typedef typename TOutputImage::PixelType OutputImagePixelType;
00116   typedef typename TInputImage::PixelType  InputImagePixelType;
00117 
00119   typedef typename TOutputImage::IndexType OutputImageIndexType;
00120   typedef typename TInputImage::IndexType  InputImageIndexType;
00121   typedef typename TOutputImage::SizeType  OutputImageSizeType;
00122   typedef typename TInputImage::SizeType   InputImageSizeType;
00123 
00124   typedef enum DirectionCollapseStrategyEnum {
00125     DIRECTIONCOLLAPSETOUNKOWN=0,
00126     DIRECTIONCOLLAPSETOIDENTITY=1,
00127     DIRECTIONCOLLAPSETOSUBMATRIX=2,
00128     DIRECTIONCOLLAPSETOGUESS=3
00129   } DIRECTIONCOLLAPSESTRATEGY;
00130 
00131 
00156   void SetDirectionCollapseToStrategy(const DIRECTIONCOLLAPSESTRATEGY choosenStrategy)
00157     {
00158     switch(choosenStrategy)
00159       {
00160     case DIRECTIONCOLLAPSETOGUESS:
00161     case DIRECTIONCOLLAPSETOIDENTITY:
00162     case DIRECTIONCOLLAPSETOSUBMATRIX:
00163       break;
00164     case DIRECTIONCOLLAPSETOUNKOWN:
00165     default:
00166       itkExceptionMacro( << "Invalid Strategy Choosen for itk::ExtractImageFilter" );
00167       }
00169 
00170     this->m_DirectionCollapseStrategy=choosenStrategy;
00171     this->Modified();
00172     }
00173 
00182   DIRECTIONCOLLAPSESTRATEGY GetDirectionCollapseToStrategy() const
00183     {
00184     return this->m_DirectionCollapseStrategy;
00185     }
00186 
00188   void SetDirectionCollapseToGuess()
00189     {
00190     this->SetDirectionCollapseToStrategy(DIRECTIONCOLLAPSETOGUESS);
00191     }
00192 
00194   void SetDirectionCollapseToIdentity()
00195     {
00196     this->SetDirectionCollapseToStrategy(DIRECTIONCOLLAPSETOIDENTITY);
00197     }
00198 
00200   void SetDirectionCollapseToSubmatrix()
00201     {
00202     this->SetDirectionCollapseToStrategy(DIRECTIONCOLLAPSETOSUBMATRIX);
00203     }
00204 
00205 
00207   itkStaticConstMacro(InputImageDimension, unsigned int,
00208                       TInputImage::ImageDimension);
00209   itkStaticConstMacro(OutputImageDimension, unsigned int,
00210                       TOutputImage::ImageDimension);
00212 
00213   typedef ImageToImageFilterDetail::ExtractImageFilterRegionCopier<
00214     itkGetStaticConstMacro(InputImageDimension),
00215     itkGetStaticConstMacro(OutputImageDimension) > ExtractImageFilterRegionCopierType;
00216 
00222   void SetExtractionRegion(InputImageRegionType extractRegion);
00223   itkGetConstMacro(ExtractionRegion, InputImageRegionType);
00225 
00226 #ifdef ITK_USE_CONCEPT_CHECKING
00227 
00228   itkConceptMacro( InputCovertibleToOutputCheck,
00229                    ( Concept::Convertible< InputImagePixelType, OutputImagePixelType > ) );
00230 
00232 #endif
00233 protected:
00234   ExtractImageFilter();
00235   ~ExtractImageFilter() {}
00236   void PrintSelf(std::ostream & os, Indent indent) const;
00238 
00247   virtual void GenerateOutputInformation();
00248 
00259   virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType & destRegion,
00260                                                  const OutputImageRegionType & srcRegion);
00261 
00271   void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
00272                             ThreadIdType threadId);
00273 
00277   void GenerateData();
00278 
00279   InputImageRegionType m_ExtractionRegion;
00280 
00281   OutputImageRegionType m_OutputImageRegion;
00282 private:
00283   ExtractImageFilter(const Self &); //purposely not implemented
00284   void operator=(const Self &);     //purposely not implemented
00285 
00286   DIRECTIONCOLLAPSESTRATEGY m_DirectionCollapseStrategy;
00287 };
00288 } // end namespace itk
00289 
00290 #ifndef ITK_MANUAL_INSTANTIATION
00291 #include "itkExtractImageFilter.hxx"
00292 #endif
00293 
00294 #endif
00295