ITK  6.0.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 
23 namespace itk
24 {
48 // Forward reference because of circular dependencies
49 template <unsigned int VImageDimension>
50 class ITK_TEMPLATE_EXPORT ImageBase;
51 
52 template <unsigned int VImageDimension, unsigned int VLoop>
54 {
55 public:
57  using IndexType = typename ImageType::IndexType;
61 
63  static inline 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  static inline 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
itk::ImageBase::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:147
itk::ImageHelper::ComputeIndex
static void ComputeIndex(const IndexType &bufferedRegionIndex, OffsetValueType offset, [[maybe_unused]] const OffsetValueType offsetTable[], IndexType &index)
Definition: itkImageHelper.h:64
itk::ImageBase
Base class for templated image classes.
Definition: itkImageBase.h:114
itk::ImageHelper::IndexType
typename ImageType::IndexType IndexType
Definition: itkImageHelper.h:57
itk::ImageBase::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:142
itk::ImageBase::IndexType
Index< VImageDimension > IndexType
Definition: itkImageBase.h:141
itk::ImageBase::OffsetType
Offset< VImageDimension > OffsetType
Definition: itkImageBase.h:146
itkMacro.h
itk::ImageHelper::ComputeOffset
static void ComputeOffset(const IndexType &bufferedRegionIndex, const IndexType &index, [[maybe_unused]] const OffsetValueType offsetTable[], OffsetValueType &offset)
Definition: itkImageHelper.h:92
itk::ImageHelper::OffsetType
typename ImageType::OffsetType OffsetType
Definition: itkImageHelper.h:58
itk::ImageHelper
Fast Index/Offset computation.
Definition: itkImageHelper.h:53
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ImageHelper::OffsetValueType
typename ImageType::OffsetValueType OffsetValueType
Definition: itkImageHelper.h:59
itk::ImageHelper::IndexValueType
typename ImageType::IndexValueType IndexValueType
Definition: itkImageHelper.h:60