ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkExtractImageFilterRegionCopier.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 /*=========================================================================
00019  *
00020  *  Portions of this file are subject to the VTK Toolkit Version 3 copyright.
00021  *
00022  *  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00023  *
00024  *  For complete copyright, license and disclaimer of warranty information
00025  *  please refer to the NOTICE file at the top of the ITK source tree.
00026  *
00027  *=========================================================================*/
00028 #ifndef __itkExtractImageFilterRegionCopier_h
00029 #define __itkExtractImageFilterRegionCopier_h
00030 
00031 #include "itkImageToImageFilterDetail.h"
00032 
00033 namespace itk
00034 {
00035 namespace ImageToImageFilterDetail
00036 {
00040 template< unsigned int T1, unsigned int T2 >
00041 void ExtractImageFilterCopyRegion(const typename
00042                                   BinaryUnsignedIntDispatch< T1, T2 >::FirstEqualsSecondType & firstEqualsSecond,
00043                                   ImageRegion< T1 > & destRegion,
00044                                   const ImageRegion< T2 > & srcRegion,
00045                                   const ImageRegion< T1 > &)
00046 {
00047   ImageToImageFilterDefaultCopyRegion< T1, T2 >(firstEqualsSecond, destRegion, srcRegion);
00048 }
00049 
00053 template< unsigned int T1, unsigned int T2 >
00054 void ExtractImageFilterCopyRegion(const typename
00055                                   BinaryUnsignedIntDispatch< T1, T2 >::FirstLessThanSecondType & firstLessThanSecond,
00056                                   ImageRegion< T1 > & destRegion,
00057                                   const ImageRegion< T2 > & srcRegion,
00058                                   const ImageRegion< T1 > & totalInputExtractionRegion)
00059 {
00060   (void) totalInputExtractionRegion;
00061   ImageToImageFilterDefaultCopyRegion< T1, T2 >(firstLessThanSecond, destRegion, srcRegion);
00062 }
00064 
00081 template< unsigned int T1, unsigned int T2 >
00082 void ExtractImageFilterCopyRegion(const typename
00083                                   BinaryUnsignedIntDispatch< T1, T2 >::FirstGreaterThanSecondType &,
00084                                   ImageRegion< T1 > & destRegion,
00085                                   const ImageRegion< T2 > & srcRegion,
00086                                   const ImageRegion< T1 > & totalInputExtractionRegion)
00087 {
00088   // Source dimension is less than the destination dimension, so look
00089   // at the m_TotalExtractionRegion and see what values in size are 0.
00090   // With these values, lock the destRegion.Index to the corresponding index
00091   unsigned int dim;
00092 
00093   Index< T1 >         destIndex;
00094   Size< T1 >          destSize;
00095   const Index< T2 > & srcIndex = srcRegion.GetIndex();
00096   const Size< T2 > &  srcSize = srcRegion.GetSize();
00097   int                 count = 0;
00098   for ( dim = 0; dim < T1; ++dim )
00099     {
00100     //for dimensions to be removed
00101     if ( !totalInputExtractionRegion.GetSize()[dim] )
00102       {
00103       destIndex[dim] = totalInputExtractionRegion.GetIndex()[dim];
00104       destSize[dim] = 1;
00105       }
00106     //for all other dimension
00107     else
00108       {
00109       destIndex[dim] = srcIndex[count];
00110       destSize[dim] = srcSize[count];
00111       count++;
00112       }
00113     }
00114   destRegion.SetIndex(destIndex);
00115   destRegion.SetSize(destSize);
00116 }
00117 
00139 template< unsigned int T1, unsigned int T2 >
00140 class ITK_EXPORT ExtractImageFilterRegionCopier:
00141   public ImageRegionCopier< T1, T2 >
00142 {
00143 public:
00144   virtual void operator()(ImageRegion< T1 > & destRegion,
00145                           const ImageRegion< T2 > & srcRegion,
00146                           const ImageRegion< T1 > & totalInputExtractionRegion) const
00147   {
00148     typedef typename BinaryUnsignedIntDispatch< T1, T2 >::ComparisonType ComparisonType;
00149     ExtractImageFilterCopyRegion< T1, T2 >(ComparisonType(),
00150                                            destRegion, srcRegion, totalInputExtractionRegion);
00151   }
00152 
00154   virtual void operator()(ImageRegion< T1 > & destRegion,
00155                           const ImageRegion< T2 > & srcRegion) const
00156   {
00157     ImageRegionCopier< T1, T2 >::operator()(destRegion, srcRegion);
00158   }
00159 };
00160 } //end namespace ImageToImageFilterDetail
00161 } //end namespace itk
00163 
00164 #endif
00165