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_CubicBSplineInterpolateImageFunction3D_H
21 #define MIRTK_CubicBSplineInterpolateImageFunction3D_H
22 
23 #include "mirtk/BaseImage.h"
24 #include "mirtk/CubicBSplineInterpolateImageFunction.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Cubic B-spline interpolation of generic 3D image
32  */
33 template <class TImage>
34 class GenericCubicBSplineInterpolateImageFunction3D
35 : public GenericCubicBSplineInterpolateImageFunction<TImage>
36 {
37   mirtkObjectMacro(GenericCubicBSplineInterpolateImageFunction3D);
38   mirtkGenericInterpolatorTypes(GenericCubicBSplineInterpolateImageFunction);
39 
40 public:
41 
42   /// Default constructor
43   GenericCubicBSplineInterpolateImageFunction3D();
44 
45   /// Get value of given image at arbitrary location (in pixels)
46   ///
47   /// This function is used to interpolate the image value at arbitrary
48   /// locations when no extrapolator was set.
49   VoxelType Get(double, double, double, double = 0) const;
50 
51   /// Get value of given image at arbitrary location (in pixels)
52   ///
53   /// This function is used to only interpolate foreground image values.
54   /// If fully outside the foreground region, the _DefaultValue is returned.
55   VoxelType GetWithPadding(double, double, double, double = 0) const;
56 
57   /// Get value of given image at arbitrary location (in pixels)
58   ///
59   /// If the location is inside the finite domain of the image, an actual image
60   /// instance can be passed as first argument directly such as an instance of
61   /// GenericImage. Otherwise, an image function which extends the finite
62   /// image domain to an infinite lattice is needed, i.e., an instance of a
63   /// subclass of ExtrapolateImageFunction.
64   template <class TOtherImage> typename TOtherImage::VoxelType
65   Get(const TOtherImage *, double, double, double, double = 0) const;
66 
67   /// Get value of given image at arbitrary location (in pixels)
68   ///
69   /// This function is used to only interpolate foreground image values.
70   /// If fully outside the foreground region, the _DefaultValue is returned.
71   ///
72   /// If the location is inside the finite domain of the image, an actual image
73   /// instance can be passed as first argument directly such as an instance of
74   /// GenericImage. Otherwise, an image function which extends the finite
75   /// image domain to an infinite lattice is needed, i.e., an instance of a
76   /// subclass of ExtrapolateImageFunction.
77   template <class TOtherImage, class TCoefficient> typename TCoefficient::VoxelType
78   GetWithPadding(const TOtherImage *, const TCoefficient *,
79                  double, double, double, double = 0) const;
80 
81   /// Evaluate generic image without handling boundary conditions
82   ///
83   /// This version is faster than EvaluateOutside, but is only defined inside
84   /// the domain for which all image values required for interpolation are
85   /// defined and thus require no extrapolation of the finite image.
86   virtual VoxelType GetInside(double, double, double, double = 0) const;
87 
88   /// Evaluate generic image at an arbitrary location (in pixels)
89   virtual VoxelType GetOutside(double, double, double, double = 0) const;
90 
91   /// Evaluate generic image without handling boundary conditions
92   ///
93   /// This function is used to only interpolate foreground image values.
94   /// If fully outside the foreground region, the _DefaultValue is returned.
95   ///
96   /// This version is faster than GetWithPaddingOutside, but is only defined
97   /// inside the domain for which all image values required for interpolation
98   /// are defined and thus require no extrapolation of the finite image.
99   virtual VoxelType GetWithPaddingInside(double, double, double, double = 0) const;
100 
101   /// Evaluate generic image at an arbitrary location (in pixels)
102   ///
103   /// This function is used to only interpolate foreground image values.
104   /// If fully outside the foreground region, the _DefaultValue is returned.
105   virtual VoxelType GetWithPaddingOutside(double, double, double, double = 0) const;
106 
107 };
108 
109 /**
110  * Cubic B-spline interpolation of any 3D image
111  */
112 class CubicBSplineInterpolateImageFunction3D
113 : public GenericCubicBSplineInterpolateImageFunction3D<BaseImage>
114 {
115   mirtkObjectMacro(CubicBSplineInterpolateImageFunction3D);
116 
117 public:
118 
119   /// Constructor
CubicBSplineInterpolateImageFunction3D()120   CubicBSplineInterpolateImageFunction3D() {}
121 
122 };
123 
124 
125 } // namespace mirtk
126 
127 #endif // MIRTK_CubicBSplineInterpolateImageFunction3D_H
128