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