ConstExtrapolateImageFunction.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_ConstExtrapolateImageFunction_H
21 #define MIRTK_ConstExtrapolateImageFunction_H
22 
23 #include "mirtk/ExtrapolateImageFunction.h"
24 
25 #include "mirtk/VoxelCast.h"
26 #include "mirtk/BaseImage.h"
27 
28 
29 namespace mirtk {
30 
31 
32 /**
33  * Constant extrapolation (i.e., padding) of generic image
34  *
35  * This discrete image extrapolation function assumes a constant image value
36  * for image grid points outside the discrete domain on which the discrete image
37  * function is defined.
38  */
39 template <class TImage>
41 : public GenericExtrapolateImageFunction<TImage>
42 {
43  mirtkGenericExtrapolatorMacro(
45  Extrapolation_Const
46  );
47 
48 public:
49 
50  /// Default constructor
51  GenericConstExtrapolateImageFunction(double padding_value = .0)
52  {
53  this->_DefaultValue = padding_value;
54  }
55 
56  /// Destructor
58 
59  /// Get image value at an arbitrary discrete image location
60  virtual VoxelType Get(int i, int j, int k = 0, int l = 0) const
61  {
62  if (0 <= i && i < this->X() &&
63  0 <= j && j < this->Y() &&
64  0 <= k && k < this->Z() &&
65  0 <= l && l < this->T()) {
66  return this->Input()->Get(i, j, k, l);
67  } else {
68  return voxel_cast<VoxelType>(this->_DefaultValue);
69  }
70  }
71 
72 };
73 
74 
75 /**
76  * Constant extrapolation (i.e., padding) of any image
77  */
79 : public GenericConstExtrapolateImageFunction<BaseImage>
80 {
81  mirtkObjectMacro(ConstExtrapolateImageFunction);
82 
83 public:
84 
85  /// Constructor
86  ConstExtrapolateImageFunction(double padding_value = .0)
87  :
89  {}
90 
91  /// Destructor
93 
94 };
95 
96 
97 } // namespace mirtk
98 
99 #endif // MIRTK_ConstExtrapolateImageFunction_H
ConstExtrapolateImageFunction(double padding_value=.0)
Constructor.
virtual VoxelType Get(int i, int j, int k=0, int l=0) const
Get image value at an arbitrary discrete image location.
int T() const
Size of input image in t dimension.
int Z() const
Size of input image in z dimension.
int X() const
Size of input image in x dimension.
Definition: IOConfig.h:41
GenericConstExtrapolateImageFunction(double padding_value=.0)
Default constructor.
int Y() const
Size of input image in y dimension.
const ImageType * Input() const
Get input image.