ITK  5.2.0
Insight Toolkit
itkImageHelper.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 <unsigned int NImageDimension>
51 class ITK_TEMPLATE_EXPORT ImageBase;
52 
53 template <unsigned int NImageDimension, unsigned int NLoop>
55 {
56 public:
58  using IndexType = typename ImageType::IndexType;
62 
64  inline static void
65  ComputeIndex(const IndexType & bufferedRegionIndex,
66  OffsetValueType offset,
67  const OffsetValueType offsetTable[],
68  IndexType & index)
69  {
71  bufferedRegionIndex, offset, offsetTable, index, std::integral_constant<bool, NLoop == 1>{});
72  }
74 
75  inline static void
76  ComputeIndexInner(const IndexType & bufferedRegionIndex,
77  OffsetValueType & offset,
78  const OffsetValueType offsetTable[],
79  IndexType & index,
80  std::false_type)
81  {
82  index[NLoop] = static_cast<IndexValueType>(offset / offsetTable[NLoop]);
83  offset -= (index[NLoop] * offsetTable[NLoop]);
84  index[NLoop] += bufferedRegionIndex[NLoop];
86  bufferedRegionIndex, offset, offsetTable, index, std::integral_constant<bool, NLoop == 1>{});
87  }
88 
89  inline static void
90  ComputeIndexInner(const IndexType & bufferedRegionIndex,
91  OffsetValueType & offset,
92  const OffsetValueType[],
93  IndexType & index,
94  std::true_type)
95  {
96  // Do last
97  index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
98  }
99 
100  // ComputeOffset
101  //
102  inline static void
103  ComputeOffset(const IndexType & bufferedRegionIndex,
104  const IndexType & index,
105  const OffsetValueType offsetTable[],
106  OffsetValueType & offset)
107  {
109  bufferedRegionIndex, index, offsetTable, offset, std::integral_constant<bool, NLoop == 1>{});
110  }
111 
112  inline static void
113  ComputeOffsetInner(const IndexType & bufferedRegionIndex,
114  const IndexType & index,
115  const OffsetValueType offsetTable[],
116  OffsetValueType & offset,
117  std::false_type)
118  {
119  offset += (index[NLoop] - bufferedRegionIndex[NLoop]) * offsetTable[NLoop];
121  bufferedRegionIndex, index, offsetTable, offset, std::integral_constant<bool, NLoop == 1>{});
122  }
123 
124  inline static void
125  ComputeOffsetInner(const IndexType & bufferedRegionIndex,
126  const IndexType & index,
127  const OffsetValueType[],
128  OffsetValueType & offset,
129  std::true_type)
130  {
131  // Do last
132  offset += index[0] - bufferedRegionIndex[0];
133  }
134 };
135 } // end namespace itk
136 
137 #endif
itk::ImageHelper::ComputeOffsetInner
static void ComputeOffsetInner(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType offsetTable[], OffsetValueType &offset, std::false_type)
Definition: itkImageHelper.h:113
itk::ImageBase::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:138
itk::ImageHelper::ComputeOffsetInner
static void ComputeOffsetInner(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType[], OffsetValueType &offset, std::true_type)
Definition: itkImageHelper.h:125
itk::ImageBase
Base class for templated image classes.
Definition: itkImageBase.h:105
itk::ImageHelper::OffsetValueType
typename ImageType::OffsetValueType OffsetValueType
Definition: itkImageHelper.h:60
itk::ImageBase::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:133
itk::ImageBase::IndexType
Index< VImageDimension > IndexType
Definition: itkImageBase.h:132
itk::ImageBase::OffsetType
Offset< VImageDimension > OffsetType
Definition: itkImageBase.h:137
itk::ImageHelper::ComputeIndexInner
static void ComputeIndexInner(const IndexType &bufferedRegionIndex, OffsetValueType &offset, const OffsetValueType offsetTable[], IndexType &index, std::false_type)
Definition: itkImageHelper.h:76
itkMacro.h
itk::ImageHelper::OffsetType
typename ImageType::OffsetType OffsetType
Definition: itkImageHelper.h:59
itk::ImageHelper::IndexValueType
typename ImageType::IndexValueType IndexValueType
Definition: itkImageHelper.h:61
itk::ImageHelper::IndexType
typename ImageType::IndexType IndexType
Definition: itkImageHelper.h:58
itk::ImageHelper
Fast Index/Offset computation.
Definition: itkImageHelper.h:54
itk::ImageHelper::ComputeIndexInner
static void ComputeIndexInner(const IndexType &bufferedRegionIndex, OffsetValueType &offset, const OffsetValueType[], IndexType &index, std::true_type)
Definition: itkImageHelper.h:90
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageHelper::ComputeIndex
static void ComputeIndex(const IndexType &bufferedRegionIndex, OffsetValueType offset, const OffsetValueType offsetTable[], IndexType &index)
Definition: itkImageHelper.h:65
itk::ImageHelper::ComputeOffset
static void ComputeOffset(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType offsetTable[], OffsetValueType &offset)
Definition: itkImageHelper.h:103