ITK  5.3.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 
23 namespace itk
24 {
40 template <typename TInputImage, typename TCoordRep = float>
41 class ITK_TEMPLATE_EXPORT NearestNeighborExtrapolateImageFunction
42  : public ExtrapolateImageFunction<TInputImage, TCoordRep>
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_MOVE(NearestNeighborExtrapolateImageFunction);
46 
52 
55 
57  itkNewMacro(Self);
58 
60  using typename Superclass::OutputType;
61 
63  using typename Superclass::InputImageType;
64 
66  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
67 
69  using typename Superclass::IndexType;
71 
73  using typename Superclass::ContinuousIndexType;
74 
83  EvaluateAtContinuousIndex(const ContinuousIndexType & index) const override
84  {
85  IndexType nindex;
86 
87  for (unsigned int j = 0; j < ImageDimension; ++j)
88  {
89  nindex[j] = Math::RoundHalfIntegerUp<IndexValueType>(index[j]);
90  if (nindex[j] < this->GetStartIndex()[j])
91  {
92  nindex[j] = this->GetStartIndex()[j];
93  }
94  else if (nindex[j] > this->GetEndIndex()[j])
95  {
96  nindex[j] = this->GetEndIndex()[j];
97  }
98  }
99  return static_cast<OutputType>(this->GetInputImage()->GetPixel(nindex));
100  }
101 
109  OutputType
110  EvaluateAtIndex(const IndexType & index) const override
111  {
112  IndexType nindex;
113 
114  for (unsigned int j = 0; j < ImageDimension; ++j)
115  {
116  if (index[j] < this->GetStartIndex()[j])
117  {
118  nindex[j] = this->GetStartIndex()[j];
119  }
120  else if (index[j] > this->GetEndIndex()[j])
121  {
122  nindex[j] = this->GetEndIndex()[j];
123  }
124  else
125  {
126  nindex[j] = index[j];
127  }
128  }
129  return static_cast<OutputType>(this->GetInputImage()->GetPixel(nindex));
130  }
131 
132 protected:
134  ~NearestNeighborExtrapolateImageFunction() override = default;
135  void
136  PrintSelf(std::ostream & os, Indent indent) const override
137  {
138  Superclass::PrintSelf(os, indent);
139  }
140 };
141 } // end namespace itk
142 
143 #endif
itk::NearestNeighborExtrapolateImageFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkNearestNeighborExtrapolateImageFunction.h:136
itk::ExtrapolateImageFunction
Base class for all image extrapolaters.
Definition: itkExtrapolateImageFunction.h:44
itk::NearestNeighborExtrapolateImageFunction::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkNearestNeighborExtrapolateImageFunction.h:70
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:110
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:83
itk::NearestNeighborExtrapolateImageFunction
Nearest neighbor extrapolation of a scalar image.
Definition: itkNearestNeighborExtrapolateImageFunction.h:41