ITK  6.0.0
Insight Toolkit
itkNearestNeighborExtrapolateImageFunction.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 itkNearestNeighborExtrapolateImageFunction_h
19#define itkNearestNeighborExtrapolateImageFunction_h
20
22#include <algorithm> // For clamp.
23
24namespace itk
25{
41template <typename TInputImage, typename TCoordRep = float>
43 : public ExtrapolateImageFunction<TInputImage, TCoordRep>
44{
45public:
46 ITK_DISALLOW_COPY_AND_MOVE(NearestNeighborExtrapolateImageFunction);
47
53
55 itkOverrideGetNameOfClassMacro(NearestNeighborExtrapolateImageFunction);
56
58 itkNewMacro(Self);
59
61 using typename Superclass::OutputType;
62
64 using typename Superclass::InputImageType;
65
67 static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
68
70 using typename Superclass::IndexType;
72
74 using typename Superclass::ContinuousIndexType;
75
84 EvaluateAtContinuousIndex(const ContinuousIndexType & index) const override
85 {
86 IndexType nindex;
87
88 const IndexType startIndex = this->GetStartIndex();
89 const IndexType endIndex = this->GetEndIndex();
90
91 for (unsigned int j = 0; j < ImageDimension; ++j)
92 {
93 nindex[j] = std::clamp(Math::RoundHalfIntegerUp<IndexValueType>(index[j]), startIndex[j], endIndex[j]);
94 }
95 return static_cast<OutputType>(this->GetInputImage()->GetPixel(nindex));
96 }
97
105 OutputType
106 EvaluateAtIndex(const IndexType & index) const override
107 {
108 IndexType nindex;
109
110 const IndexType startIndex = this->GetStartIndex();
111 const IndexType endIndex = this->GetEndIndex();
112
113 for (unsigned int j = 0; j < ImageDimension; ++j)
114 {
115 nindex[j] = std::clamp(index[j], startIndex[j], endIndex[j]);
116 }
117 return static_cast<OutputType>(this->GetInputImage()->GetPixel(nindex));
118 }
119
120protected:
123 void
124 PrintSelf(std::ostream & os, Indent indent) const override
125 {
126 Superclass::PrintSelf(os, indent);
127 }
128};
129} // end namespace itk
130
131#endif
Base class for all image extrapolaters.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Nearest neighbor extrapolation of a scalar image.
OutputType EvaluateAtIndex(const IndexType &index) const override
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
~NearestNeighborExtrapolateImageFunction() override=default
void PrintSelf(std::ostream &os, Indent indent) const override
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long IndexValueType
Definition: itkIntTypes.h:93