ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkNearestNeighborExtrapolateImageFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
39 template< typename TInputImage, typename TCoordRep = float >
41  public ExtrapolateImageFunction< TInputImage, TCoordRep >
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_ASSIGN(NearestNeighborExtrapolateImageFunction);
45 
51 
55 
57  itkNewMacro(Self);
58 
61 
64 
66  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
67 
69  using IndexType = typename Superclass::IndexType;
71 
74 
83  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 
110  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 PrintSelf(std::ostream & os, Indent indent) const override
136  { Superclass::PrintSelf(os, indent); }
137 };
138 } // end namespace itk
139 
140 #endif
typename Superclass::IndexType IndexType
Light weight base class for most itk classes.
typename Superclass::OutputType OutputType
typename Superclass::InputImageType InputImageType
Nearest neighbor extrapolation of a scalar image.
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
OutputType EvaluateAtIndex(const IndexType &index) const override
void PrintSelf(std::ostream &os, Indent indent) const override
~NearestNeighborExtrapolateImageFunction() override=default
signed long IndexValueType
Definition: itkIntTypes.h:90
typename Superclass::ContinuousIndexType ContinuousIndexType
void PrintSelf(std::ostream &os, Indent indent) const override
Base class for all image interpolaters.
Base class for all image extrapolaters.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static constexpr unsigned int ImageDimension