RepeatExtrapolateImageFunction.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_RepeatExtrapolateImageFunction_H
21 #define MIRTK_RepeatExtrapolateImageFunction_H
22 
23 #include "mirtk/ExtrapolateImageFunction.h"
24 
25 #include "mirtk/Math.h"
26 #include "mirtk/BaseImage.h"
27 
28 
29 namespace mirtk {
30 
31 
32 /**
33  * Extrapolation of generic image by tiling/repeating it
34  *
35  * This extrapolation implements a periodic extension of the finite image.
36  */
37 template <class TImage>
39 : public IndexExtrapolateImageFunction<TImage>
40 {
41  mirtkExtrapolatorMacro(
43  Extrapolation_Repeat
44  );
45 
46 public:
47 
48  /// Constructor
50 
51  /// Destructor
53 
54  /// Transform index such that it is inside the range [0, max]
55  /// \note Use static function as RepeatExtrapolateImageFunction::Apply.
56  static void Apply(int &index, int max)
57  {
58  if (index < 0 ) index = max + (index + 1) % (max + 1);
59  else if (index > max) index = index % (max + 1);
60  }
61 
62  /// Transform continuous index such that it is inside the range [0, max + 1)
63  /// \note Use static function as RepeatExtrapolateImageFunction::Apply.
64  static void Apply(double &cindex, int max)
65  {
66  int index = ifloor(cindex);
67  double fraction = cindex - index;
68  Apply(index, max);
69  cindex = index + fraction;
70  }
71 
72  /// Transform index such that it is inside the range [0, max]
73  virtual void TransformIndex(int &index, int max) const
74  {
75  Apply(index, max);
76  }
77 
78 };
79 
80 
81 /**
82  * Extrapolation of any image by tiling/repeating it
83  *
84  * This extrapolation implements a periodic extension of the finite image.
85  */
87 : public GenericRepeatExtrapolateImageFunction<BaseImage>
88 {
89  mirtkObjectMacro(RepeatExtrapolateImageFunction);
90 
91 public:
92 
93  /// Constructor
95 
96  /// Destructor
98 
99 };
100 
101 
102 } // namespace mirtk
103 
104 #endif // MIRTK_RepeatExtrapolateImageFunction_H
virtual void TransformIndex(int &index, int max) const
Transform index such that it is inside the range [0, max].
MIRTKCU_API int ifloor(T x)
Round floating-point value to next smaller integer and cast to int.
Definition: Math.h:154
Definition: IOConfig.h:41