ITK  4.2.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< class TInputImage, class TCoordRep = float >
41  public ExtrapolateImageFunction< TInputImage, TCoordRep >
42 {
43 public:
49 
53 
55  itkNewMacro(Self);
56 
58  typedef typename Superclass::OutputType OutputType;
59 
61  typedef typename Superclass::InputImageType InputImageType;
62 
64  itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
65 
67  typedef typename Superclass::IndexType IndexType;
69 
71  typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
72 
80  virtual OutputType EvaluateAtContinuousIndex(
81  const ContinuousIndexType & index) const
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 
107  virtual OutputType EvaluateAtIndex(
108  const IndexType & index) const
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
134  { Superclass::PrintSelf(os, indent); }
135 private:
136  NearestNeighborExtrapolateImageFunction(const Self &); //purposely not
137  // implemented
138  void operator=(const Self &); //purposely not
139 
140  // implemented
141 };
142 } // end namespace itk
143 
144 #endif
145