ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkImageHelper.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkImageHelper_h
19 #define itkImageHelper_h
20 
21 #include "itkConceptChecking.h"
22 
23 namespace itk
24 {
48 // Forward reference ImageBase
49 template<
50  unsigned int NImageDimension
51  >
52 class ImageBase;
53 
54 template< unsigned int NImageDimension, unsigned int NLoop >
56 {
57 public:
59  typedef typename ImageType::IndexType IndexType;
65 
67  inline static void ComputeIndex(const IndexType & bufferedRegionIndex,
68  OffsetValueType offset,
69  const OffsetValueType offsetTable[],
70  IndexType & index)
71  {
73  ComputeIndexInner( bufferedRegionIndex,
74  offset,
75  offsetTable,
76  index,
77  Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
78  }
79 
80  inline static void ComputeIndexInner(const IndexType & bufferedRegionIndex,
81  OffsetValueType & offset,
82  const OffsetValueType offsetTable[],
83  IndexType & index,
84  const UniqueTypeBoolFalse &)
85  {
86  index[NLoop] = static_cast< IndexValueType >( offset / offsetTable[NLoop] );
87  offset = offset - ( index[NLoop] * offsetTable[NLoop] );
88  index[NLoop] = index[NLoop] + bufferedRegionIndex[NLoop];
90  ComputeIndexInner( bufferedRegionIndex,
91  offset,
92  offsetTable,
93  index,
94  Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
95  }
96 
97  inline static void ComputeIndexInner(const IndexType & bufferedRegionIndex,
98  OffsetValueType & offset,
99  const OffsetValueType[],
100  IndexType & index,
101  const UniqueTypeBoolTrue &)
102  {
103  // Do last
104  index[0] = bufferedRegionIndex[0] + static_cast< IndexValueType >( offset );
105  }
106 
107  // ComputeOffset
108  //
109  inline static void ComputeOffset(const IndexType & bufferedRegionIndex,
110  const IndexType & index,
111  const OffsetValueType offsetTable[],
112  OffsetValueType & offset)
113  {
115  ComputeOffsetInner( bufferedRegionIndex,
116  index,
117  offsetTable,
118  offset,
119  Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
120  }
121 
122  inline static void ComputeOffsetInner(const IndexType & bufferedRegionIndex,
123  const IndexType & index,
124  const OffsetValueType offsetTable[],
125  OffsetValueType & offset,
126  const UniqueTypeBoolFalse &)
127  {
128  offset = offset + ( index[NLoop] - bufferedRegionIndex[NLoop] ) * offsetTable[NLoop];
130  ComputeOffsetInner( bufferedRegionIndex,
131  index,
132  offsetTable,
133  offset,
134  Concept::Detail::UniqueType_bool< ( NLoop == 1 ) >() );
135  }
136 
137  inline static void ComputeOffsetInner(const IndexType & bufferedRegionIndex,
138  const IndexType & index,
139  const OffsetValueType[],
140  OffsetValueType & offset,
141  const UniqueTypeBoolTrue &)
142  {
143  // Do last
144  offset = offset + index[0] - bufferedRegionIndex[0];
145  }
146 };
147 } // end namespace itk
148 
149 #endif
Represent the offset between two n-dimensional indexes in a n-dimensional image.
Definition: itkOffset.h:55
static void ComputeOffset(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType offsetTable[], OffsetValueType &offset)
ImageType::IndexType IndexType
Concept::Detail::UniqueType_bool< false > UniqueTypeBoolFalse
static void ComputeIndex(const IndexType &bufferedRegionIndex, OffsetValueType offset, const OffsetValueType offsetTable[], IndexType &index)
ImageType::IndexValueType IndexValueType
static void ComputeOffsetInner(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType[], OffsetValueType &offset, const UniqueTypeBoolTrue &)
ImageType::OffsetType OffsetType
ImageType::OffsetValueType OffsetValueType
static void ComputeIndexInner(const IndexType &bufferedRegionIndex, OffsetValueType &offset, const OffsetValueType offsetTable[], IndexType &index, const UniqueTypeBoolFalse &)
OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:143
static void ComputeIndexInner(const IndexType &bufferedRegionIndex, OffsetValueType &offset, const OffsetValueType[], IndexType &index, const UniqueTypeBoolTrue &)
Base class for templated image classes.
Definition: itkImageBase.h:112
ImageBase< NImageDimension > ImageType
Fast Index/Offset computation.
static void ComputeOffsetInner(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType offsetTable[], OffsetValueType &offset, const UniqueTypeBoolFalse &)
Concept::Detail::UniqueType_bool< true > UniqueTypeBoolTrue
IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:138