ITK  5.2.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  * http://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>
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_MOVE(NearestNeighborExtrapolateImageFunction);
45 
51 
54 
56  itkNewMacro(Self);
57 
60 
63 
65  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
66 
68  using IndexType = typename Superclass::IndexType;
70 
73 
82  EvaluateAtContinuousIndex(const ContinuousIndexType & index) const override
83  {
84  IndexType nindex;
85 
86  for (unsigned int j = 0; j < ImageDimension; j++)
87  {
88  nindex[j] = Math::RoundHalfIntegerUp<IndexValueType>(index[j]);
89  if (nindex[j] < this->GetStartIndex()[j])
90  {
91  nindex[j] = this->GetStartIndex()[j];
92  }
93  else if (nindex[j] > this->GetEndIndex()[j])
94  {
95  nindex[j] = this->GetEndIndex()[j];
96  }
97  }
98  return static_cast<OutputType>(this->GetInputImage()->GetPixel(nindex));
99  }
100 
108  OutputType
109  EvaluateAtIndex(const IndexType & index) const override
110  {
111  IndexType nindex;
112 
113  for (unsigned int j = 0; j < ImageDimension; j++)
114  {
115  if (index[j] < this->GetStartIndex()[j])
116  {
117  nindex[j] = this->GetStartIndex()[j];
118  }
119  else if (index[j] > this->GetEndIndex()[j])
120  {
121  nindex[j] = this->GetEndIndex()[j];
122  }
123  else
124  {
125  nindex[j] = index[j];
126  }
127  }
128  return static_cast<OutputType>(this->GetInputImage()->GetPixel(nindex));
129  }
130 
131 protected:
133  ~NearestNeighborExtrapolateImageFunction() override = default;
134  void
135  PrintSelf(std::ostream & os, Indent indent) const override
136  {
137  Superclass::PrintSelf(os, indent);
138  }
139 };
140 } // end namespace itk
141 
142 #endif
itk::NearestNeighborExtrapolateImageFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkNearestNeighborExtrapolateImageFunction.h:135
itk::ExtrapolateImageFunction
Base class for all image extrapolaters.
Definition: itkExtrapolateImageFunction.h:44
itk::ExtrapolateImageFunction::IndexType
typename Superclass::IndexType IndexType
Definition: itkExtrapolateImageFunction.h:73
itk::NearestNeighborExtrapolateImageFunction::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkNearestNeighborExtrapolateImageFunction.h:69
itk::ImageFunction< TInputImage, NumericTraits< TInputImage::PixelType >::RealType, TCoordRep >::GetEndIndex
virtual const IndexType & GetEndIndex() const
itk::ExtrapolateImageFunction::ImageDimension
static constexpr unsigned int ImageDimension
Definition: itkExtrapolateImageFunction.h:67
itk::ExtrapolateImageFunction::InputImageType
typename Superclass::InputImageType InputImageType
Definition: itkExtrapolateImageFunction.h:64
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ExtrapolateImageFunction::OutputType
typename Superclass::OutputType OutputType
Definition: itkExtrapolateImageFunction.h:61
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::NearestNeighborExtrapolateImageFunction::NearestNeighborExtrapolateImageFunction
NearestNeighborExtrapolateImageFunction()=default
itkExtrapolateImageFunction.h
itk::NearestNeighborExtrapolateImageFunction::EvaluateAtIndex
OutputType EvaluateAtIndex(const IndexType &index) const override
Definition: itkNearestNeighborExtrapolateImageFunction.h:109
itk::NearestNeighborExtrapolateImageFunction::~NearestNeighborExtrapolateImageFunction
~NearestNeighborExtrapolateImageFunction() override=default
itk::ExtrapolateImageFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkExtrapolateImageFunction.h:115
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::NearestNeighborExtrapolateImageFunction::OutputType
typename Superclass::OutputType OutputType
Definition: itkNearestNeighborExtrapolateImageFunction.h:59
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ImageFunction< TInputImage, NumericTraits< TInputImage::PixelType >::RealType, TCoordRep >::GetStartIndex
virtual const IndexType & GetStartIndex() const
itk::ExtrapolateImageFunction::ContinuousIndexType
typename Superclass::ContinuousIndexType ContinuousIndexType
Definition: itkExtrapolateImageFunction.h:76
itk::NearestNeighborExtrapolateImageFunction::EvaluateAtContinuousIndex
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
Definition: itkNearestNeighborExtrapolateImageFunction.h:82
itk::ImageFunction< TInputImage, NumericTraits< TInputImage::PixelType >::RealType, TCoordRep >::GetInputImage
const InputImageType * GetInputImage() const
Definition: itkImageFunction.h:108
itk::NearestNeighborExtrapolateImageFunction::ImageDimension
static constexpr unsigned int ImageDimension
Definition: itkNearestNeighborExtrapolateImageFunction.h:65
itk::InterpolateImageFunction
Base class for all image interpolators.
Definition: itkInterpolateImageFunction.h:45
itk::NearestNeighborExtrapolateImageFunction
Nearest neighbor extrapolation of a scalar image.
Definition: itkNearestNeighborExtrapolateImageFunction.h:41