ITK  5.0.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 "itkMacro.h" // For ITK_TEMPLATE_EXPORT.
22 #include <type_traits> // For true_type, false_type, and integral_constant.
23 
24 namespace itk
25 {
49 // Forward reference because of circular dependencies
50 template<
51  unsigned int NImageDimension
52  >
53 class ITK_TEMPLATE_EXPORT ImageBase;
54 
55 template< unsigned int NImageDimension, unsigned int NLoop >
57 {
58 public:
60  using IndexType = typename ImageType::IndexType;
64 
66  inline static void ComputeIndex(const IndexType & bufferedRegionIndex,
67  OffsetValueType offset,
68  const OffsetValueType offsetTable[],
69  IndexType & index)
70  {
72  ComputeIndexInner( bufferedRegionIndex,
73  offset,
74  offsetTable,
75  index,
76  std::integral_constant<bool, NLoop == 1>{} );
77  }
79 
80  inline static void ComputeIndexInner(const IndexType & bufferedRegionIndex,
81  OffsetValueType & offset,
82  const OffsetValueType offsetTable[],
83  IndexType & index,
84  std::false_type)
85  {
86  index[NLoop] = static_cast< IndexValueType >( offset / offsetTable[NLoop] );
87  offset -= ( index[NLoop] * offsetTable[NLoop] );
88  index[NLoop] += bufferedRegionIndex[NLoop];
90  ComputeIndexInner( bufferedRegionIndex,
91  offset,
92  offsetTable,
93  index,
94  std::integral_constant<bool, NLoop == 1>{} );
95  }
96 
97  inline static void ComputeIndexInner(const IndexType & bufferedRegionIndex,
98  OffsetValueType & offset,
99  const OffsetValueType[],
100  IndexType & index,
101  std::true_type)
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  std::integral_constant<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  std::false_type)
127  {
128  offset += ( index[NLoop] - bufferedRegionIndex[NLoop] ) * offsetTable[NLoop];
130  ComputeOffsetInner( bufferedRegionIndex,
131  index,
132  offsetTable,
133  offset,
134  std::integral_constant<bool, NLoop == 1>{} );
135  }
136 
137  inline static void ComputeOffsetInner(const IndexType & bufferedRegionIndex,
138  const IndexType & index,
139  const OffsetValueType[],
140  OffsetValueType & offset,
141  std::true_type)
142  {
143  // Do last
144  offset += index[0] - bufferedRegionIndex[0];
145  }
146 };
147 } // end namespace itk
148 
149 #endif
static void ComputeOffset(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType offsetTable[], OffsetValueType &offset)
static void ComputeOffsetInner(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType offsetTable[], OffsetValueType &offset, std::false_type)
static void ComputeIndexInner(const IndexType &bufferedRegionIndex, OffsetValueType &offset, const OffsetValueType offsetTable[], IndexType &index, std::false_type)
static void ComputeIndexInner(const IndexType &bufferedRegionIndex, OffsetValueType &offset, const OffsetValueType[], IndexType &index, std::true_type)
static void ComputeIndex(const IndexType &bufferedRegionIndex, OffsetValueType offset, const OffsetValueType offsetTable[], IndexType &index)
static void ComputeOffsetInner(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType[], OffsetValueType &offset, std::true_type)
typename ImageType::IndexValueType IndexValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:138
Offset< VImageDimension > OffsetType
Definition: itkImageBase.h:137
Index< VImageDimension > IndexType
Definition: itkImageBase.h:132
Base class for templated image classes.
Definition: itkImageBase.h:105
typename ImageType::IndexType IndexType
typename ImageType::OffsetValueType OffsetValueType
Fast Index/Offset computation.
typename ImageType::OffsetType OffsetType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:133