ITK  5.4.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 * https://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
23namespace itk
24{
48// Forward reference because of circular dependencies
49template <unsigned int VImageDimension>
50class ITK_TEMPLATE_EXPORT ImageBase;
51
52template <unsigned int VImageDimension, unsigned int VLoop>
54{
55public:
61
63 inline static void
64 ComputeIndex(const IndexType & bufferedRegionIndex,
65 OffsetValueType offset,
66 [[maybe_unused]] const OffsetValueType offsetTable[],
67 IndexType & index)
68 {
69 static_assert(VLoop <= VImageDimension);
70
71 if constexpr (VLoop > 1)
72 {
73 constexpr unsigned int loopIndex{ VLoop - 1 };
74
75 index[loopIndex] = static_cast<IndexValueType>(offset / offsetTable[loopIndex]);
76 offset -= (index[loopIndex] * offsetTable[loopIndex]);
77 index[loopIndex] += bufferedRegionIndex[loopIndex];
78 ImageHelper<VImageDimension, loopIndex>::ComputeIndex(bufferedRegionIndex, offset, offsetTable, index);
79 }
80 else
81 {
82 static_assert(VLoop == 1);
83
84 // Do last
85 index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
86 }
87 }
88
89 // ComputeOffset
90 //
91 inline static void
92 ComputeOffset(const IndexType & bufferedRegionIndex,
93 const IndexType & index,
94 [[maybe_unused]] const OffsetValueType offsetTable[],
95 OffsetValueType & offset)
96 {
97 static_assert(VLoop <= VImageDimension);
98
99 if constexpr (VLoop > 1)
100 {
101 constexpr unsigned int loopIndex{ VLoop - 1 };
102
103 offset += (index[loopIndex] - bufferedRegionIndex[loopIndex]) * offsetTable[loopIndex];
104 ImageHelper<VImageDimension, loopIndex>::ComputeOffset(bufferedRegionIndex, index, offsetTable, offset);
105 }
106 else
107 {
108 static_assert(VLoop == 1);
109
110 // Do last
111 offset += index[0] - bufferedRegionIndex[0];
112 }
113 }
114};
115} // end namespace itk
116
117#endif
Base class for templated image classes.
Definition: itkImageBase.h:115
Index< VImageDimension > IndexType
Definition: itkImageBase.h:141
Offset< VImageDimension > OffsetType
Definition: itkImageBase.h:146
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:147
typename IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:142
Fast Index/Offset computation.
typename ImageType::IndexType IndexType
typename ImageType::OffsetValueType OffsetValueType
static void ComputeIndex(const IndexType &bufferedRegionIndex, OffsetValueType offset, const OffsetValueType offsetTable[], IndexType &index)
typename ImageType::IndexValueType IndexValueType
typename ImageType::OffsetType OffsetType
static void ComputeOffset(const IndexType &bufferedRegionIndex, const IndexType &index, const OffsetValueType offsetTable[], OffsetValueType &offset)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....