ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkImageHelper.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 __itkImageHelper_h
00019 #define __itkImageHelper_h
00020 
00021 #include "itkConceptChecking.h"
00022 
00023 namespace itk
00024 {
00048 // Forward reference ImageBase
00049 template<
00050   unsigned int NImageDimension
00051   >
00052 class ImageBase;
00053 
00054 template< unsigned int NImageDimension, unsigned int NLoop >
00055 class ImageHelper
00056 {
00057 public:
00058   typedef ImageBase< NImageDimension >              ImageType;
00059   typedef typename ImageType::IndexType             IndexType;
00060   typedef typename ImageType::OffsetType            OffsetType;
00061   typedef typename ImageType::OffsetValueType       OffsetValueType;
00062   typedef typename ImageType::IndexValueType        IndexValueType;
00063   typedef Concept::Detail::UniqueType_bool< false > UniqueTypeBoolFalse;
00064   typedef Concept::Detail::UniqueType_bool< true >  UniqueTypeBoolTrue;
00065 
00067   inline static void ComputeIndex(const IndexType & bufferedRegionIndex,
00068                                   OffsetValueType offset,
00069                                   const OffsetValueType offsetTable[],
00070                                   IndexType & index)
00071   {
00072     ImageHelper< NImageDimension, NLoop - 1 >::
00073     ComputeIndexInner( bufferedRegionIndex,
00074                        offset,
00075                        offsetTable,
00076                        index,
00077                        Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
00078   }
00079 
00080   inline static void ComputeIndexInner(const IndexType & bufferedRegionIndex,
00081                                        OffsetValueType & offset,
00082                                        const OffsetValueType offsetTable[],
00083                                        IndexType & index,
00084                                        const UniqueTypeBoolFalse &)
00085   {
00086     index[NLoop] = static_cast< IndexValueType >( offset / offsetTable[NLoop] );
00087     offset = offset - ( index[NLoop] * offsetTable[NLoop] );
00088     index[NLoop] = index[NLoop] + bufferedRegionIndex[NLoop];
00089     ImageHelper< NImageDimension, NLoop - 1 >::
00090     ComputeIndexInner( bufferedRegionIndex,
00091                        offset,
00092                        offsetTable,
00093                        index,
00094                        Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
00095   }
00096 
00097   inline static void ComputeIndexInner(const IndexType & bufferedRegionIndex,
00098                                        OffsetValueType & offset,
00099                                        const OffsetValueType[],
00100                                        IndexType & index,
00101                                        const UniqueTypeBoolTrue &)
00102   {
00103     // Do last
00104     index[0] = bufferedRegionIndex[0] + static_cast< IndexValueType >( offset );
00105   }
00106 
00107   // ComputeOffset
00108   //
00109   inline static void ComputeOffset(const IndexType & bufferedRegionIndex,
00110                                    const IndexType & index,
00111                                    const OffsetValueType offsetTable[],
00112                                    OffsetValueType & offset)
00113   {
00114     ImageHelper< NImageDimension, NLoop - 1 >::
00115     ComputeOffsetInner( bufferedRegionIndex,
00116                         index,
00117                         offsetTable,
00118                         offset,
00119                         Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
00120   }
00121 
00122   inline static void ComputeOffsetInner(const IndexType & bufferedRegionIndex,
00123                                         const IndexType & index,
00124                                         const OffsetValueType offsetTable[],
00125                                         OffsetValueType & offset,
00126                                         const UniqueTypeBoolFalse &)
00127   {
00128     offset = offset + ( index[NLoop] - bufferedRegionIndex[NLoop] ) * offsetTable[NLoop];
00129     ImageHelper< NImageDimension, NLoop - 1 >::
00130     ComputeOffsetInner( bufferedRegionIndex,
00131                         index,
00132                         offsetTable,
00133                         offset,
00134                         Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
00135   }
00136 
00137   inline static void ComputeOffsetInner(const IndexType & bufferedRegionIndex,
00138                                         const IndexType & index,
00139                                         const OffsetValueType[],
00140                                         OffsetValueType & offset,
00141                                         const UniqueTypeBoolTrue &)
00142   {
00143     // Do last
00144     offset = offset + index[0] - bufferedRegionIndex[0];
00145   }
00146 };
00147 } // end namespace itk
00148 
00149 #endif
00150