NearestNeighborInterpolateImageFunction.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_NearestNeighborInterpolateImageFunction_H
21 #define MIRTK_NearestNeighborInterpolateImageFunction_H
22 
23 #include "mirtk/InterpolateImageFunction.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Nearest neighbor interpolation of generic image
31  */
32 template <class TImage>
34 : public GenericInterpolateImageFunction<TImage>
35 {
36  mirtkGenericInterpolatorMacro(
38  Interpolation_NN
39  );
40 
41 public:
42 
43  // ---------------------------------------------------------------------------
44  // Construction/Destruction
45 
46  /// Default constructor
48 
49  /// Destructor
51 
52  // ---------------------------------------------------------------------------
53  // Domain checks
54 
55  /// Returns interval of discrete image indices whose values are needed for
56  /// interpolation of the image value at a given continuous coordinate
57  virtual void BoundingInterval(double, int &, int &) const;
58 
59  // ---------------------------------------------------------------------------
60  // Evaluation
61 
62  /// Get value of given image at arbitrary location (in pixels)
63  ///
64  /// This function is used to interpolate the image value at arbitrary
65  /// locations when no extrapolator was set. If the nearest image location is
66  /// outside the finite domain of the image, the _DefaultValue is returned.
67  VoxelType Get(double, double, double = 0, double = 0) const;
68 
69  /// Get value of given image at arbitrary location (in pixels)
70  ///
71  /// This function is used to only interpolate foreground image values.
72  /// If fully outside the foreground region, the _DefaultValue is returned.
73  VoxelType GetWithPadding(double, double, double = 0, double = 0) const;
74 
75  /// Get value of given image at arbitrary location (in pixels)
76  ///
77  /// If the location is inside the finite domain of the image, an actual image
78  /// instance can be passed as first argument directly such as an instance of
79  /// GenericImage. Otherwise, an image function which extends the finite
80  /// image domain to an infinite lattice is needed, i.e., an instance of a
81  /// subclass of ExtrapolateImageFunction.
82  template <class TOtherImage> typename TOtherImage::VoxelType
83  Get(const TOtherImage *, double, double, double = 0, double = 0) const;
84 
85  /// Get value of given image at arbitrary location (in pixels)
86  ///
87  /// This function is used to only interpolate foreground image values.
88  /// If fully outside the foreground region, the _DefaultValue is returned.
89  ///
90  /// If the location is inside the finite domain of the image, an actual image
91  /// instance can be passed as first argument directly such as an instance of
92  /// GenericImage. Otherwise, an image function which extends the finite
93  /// image domain to an infinite lattice is needed, i.e., an instance of a
94  /// subclass of ExtrapolateImageFunction.
95  template <class TOtherImage> typename TOtherImage::VoxelType
96  GetWithPadding(const TOtherImage *, double, double, double = 0, double = 0) const;
97 
98  /// Evaluate generic image without handling boundary conditions
99  ///
100  /// This version is faster than EvaluateOutside, but is only defined inside
101  /// the domain for which all image values required for interpolation are
102  /// defined and thus require no extrapolation of the finite image.
103  virtual VoxelType GetInside(double, double, double = 0, double = 0) const;
104 
105  /// Evaluate generic image at an arbitrary location (in pixels)
106  virtual VoxelType GetOutside(double, double, double = 0, double = 0) const;
107 
108  /// Evaluate generic image without handling boundary conditions
109  ///
110  /// If the location is partially inside the foreground region of the image,
111  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
112  /// is returned.
113  ///
114  /// This version is faster than GetWithPaddingOutside, but is only defined
115  /// inside the domain for which all image values required for interpolation
116  /// are defined and thus require no extrapolation of the finite image.
117  virtual VoxelType GetWithPaddingInside(double, double, double = 0, double = 0) const;
118 
119  /// Evaluate generic image at an arbitrary location (in pixels)
120  ///
121  /// If the location is partially inside the foreground region of the image,
122  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
123  /// is returned.
124  virtual VoxelType GetWithPaddingOutside(double, double, double = 0, double = 0) const;
125 
126 };
127 
128 
129 /**
130  * Nearest neighbor interpolation of any scalar image
131  */
134 {
135  mirtkObjectMacro(NearestNeighborInterpolateImageFunction);
136 
137 public:
138 
139  /// Constructor
141 
142 };
143 
144 
145 } // namespace mirtk
146 
147 #endif // MIRTK_NearestNeighorInterpolateImageFunction_H
virtual VoxelType GetOutside(double, double, double=0, double=0) const
Evaluate generic image at an arbitrary location (in pixels)
virtual VoxelType GetInside(double, double, double=0, double=0) const
virtual VoxelType GetWithPaddingInside(double, double, double=0, double=0) const
virtual VoxelType GetWithPaddingOutside(double, double, double=0, double=0) const
Definition: IOConfig.h:41
VoxelType GetWithPadding(double, double, double=0, double=0) const