ITK  4.9.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:
49 
53 
55  itkNewMacro(Self);
56 
58  typedef typename Superclass::OutputType OutputType;
59 
62 
64  itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
65 
67  typedef typename Superclass::IndexType IndexType;
69 
72 
81  const ContinuousIndexType & index) const ITK_OVERRIDE
82  {
83  IndexType nindex;
84 
85  for ( unsigned int j = 0; j < ImageDimension; j++ )
86  {
87  nindex[j] = Math::RoundHalfIntegerUp< IndexValueType >(index[j]);
88  if ( nindex[j] < this->GetStartIndex()[j] )
89  {
90  nindex[j] = this->GetStartIndex()[j];
91  }
92  else if ( nindex[j] > this->GetEndIndex()[j] )
93  {
94  nindex[j] = this->GetEndIndex()[j];
95  }
96  }
97  return static_cast< OutputType >( this->GetInputImage()->GetPixel(nindex) );
98  }
99 
108  const IndexType & index) const ITK_OVERRIDE
109  {
110  IndexType nindex;
111 
112  for ( unsigned int j = 0; j < ImageDimension; j++ )
113  {
114  if ( index[j] < this->GetStartIndex()[j] )
115  {
116  nindex[j] = this->GetStartIndex()[j];
117  }
118  else if ( index[j] > this->GetEndIndex()[j] )
119  {
120  nindex[j] = this->GetEndIndex()[j];
121  }
122  else
123  {
124  nindex[j] = index[j];
125  }
126  }
127  return static_cast< OutputType >( this->GetInputImage()->GetPixel(nindex) );
128  }
129 
130 protected:
133  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE
134  { Superclass::PrintSelf(os, indent); }
135 
136 private:
137  NearestNeighborExtrapolateImageFunction(const Self &) ITK_DELETE_FUNCTION;
138  void operator=(const Self &) ITK_DELETE_FUNCTION;
139 };
140 } // end namespace itk
141 
142 #endif
Light weight base class for most itk classes.
ExtrapolateImageFunction< TInputImage, TCoordRep > Superclass
signed long IndexValueType
Definition: itkIntTypes.h:150
Superclass::ContinuousIndexType ContinuousIndexType
Nearest neighbor extrapolation of a scalar image.
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
void PrintSelf(std::ostream &os, Indent indent) const override
Superclass::InputImageType InputImageType
void PrintSelf(std::ostream &os, Indent indent) const override
virtual OutputType EvaluateAtIndex(const IndexType &index) const override
Base class for all image interpolaters.
Base class for all image extrapolaters.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static const unsigned int ImageDimension