ITK  5.4.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 
24 namespace itk
25 {
41 template <typename TInputImage, typename TCoordRep = float>
42 class ITK_TEMPLATE_EXPORT NearestNeighborExtrapolateImageFunction
43  : public ExtrapolateImageFunction<TInputImage, TCoordRep>
44 {
45 public:
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 
120 protected:
122  ~NearestNeighborExtrapolateImageFunction() override = default;
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
itk::NearestNeighborExtrapolateImageFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkNearestNeighborExtrapolateImageFunction.h:124
itk::ExtrapolateImageFunction
Base class for all image extrapolaters.
Definition: itkExtrapolateImageFunction.h:44
itk::NearestNeighborExtrapolateImageFunction::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkNearestNeighborExtrapolateImageFunction.h:71
itk::ImageFunction< TInputImage, NumericTraits< TInputImage::PixelType >::RealType, TCoordRep >::IndexType
typename InputImageType::IndexType IndexType
Definition: itkImageFunction.h:90
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::FunctionBase< Point< TCoordRep, TInputImage::ImageDimension >, NumericTraits< TInputImage::PixelType >::RealType >::OutputType
NumericTraits< TInputImage::PixelType >::RealType OutputType
Definition: itkFunctionBase.h:62
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkExtrapolateImageFunction.h
itk::NearestNeighborExtrapolateImageFunction::EvaluateAtIndex
OutputType EvaluateAtIndex(const IndexType &index) const override
Definition: itkNearestNeighborExtrapolateImageFunction.h:106
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ContinuousIndex< TCoordRep, Self::ImageDimension >
itk::NearestNeighborExtrapolateImageFunction::EvaluateAtContinuousIndex
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
Definition: itkNearestNeighborExtrapolateImageFunction.h:84
itk::NearestNeighborExtrapolateImageFunction
Nearest neighbor extrapolation of a scalar image.
Definition: itkNearestNeighborExtrapolateImageFunction.h:42