ExtrapolationMode.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_ExtrapolationMode_H
21 #define MIRTK_ExtrapolationMode_H
22 
23 #include "mirtk/String.h"
24 
25 
26 namespace mirtk {
27 
28 
29 // ----------------------------------------------------------------------------
30 /// Image extrapolation modes
32  Extrapolation_Default, // i.e., not specified
33  Extrapolation_None, // i.e., partial interpolation or default value
34  Extrapolation_Const,
35  Extrapolation_NN,
36  Extrapolation_Repeat, // i.e., periodic
37  Extrapolation_Mirror,
38  Extrapolation_ConstWithPeriodicTime,
39  // Add new enumeration values above
40  Extrapolation_Last
41 };
42 
43 // ----------------------------------------------------------------------------
44 template <>
45 inline string ToString(const ExtrapolationMode &m, int w, char c, bool left)
46 {
47  const char *str;
48  switch(m) {
49  case Extrapolation_Default: str = "Default"; break;
50  case Extrapolation_None: str = "None"; break;
51  case Extrapolation_Const: str = "Const"; break;
52  case Extrapolation_NN: str = "NN"; break;
53  case Extrapolation_Repeat: str = "Repeat"; break;
54  case Extrapolation_Mirror: str = "Mirror"; break;
55  case Extrapolation_ConstWithPeriodicTime: str = "ConstWithPeriodicTime"; break;
56  default: str = "Unknown"; break;
57  }
58  return ToString(str, w, c, left);
59 }
60 
61 // ----------------------------------------------------------------------------
62 /// Get corresponding extrapolation with periodic time
64 {
65  switch(m) {
66  case Extrapolation_ConstWithPeriodicTime:
67  case Extrapolation_Const: return Extrapolation_ConstWithPeriodicTime;
68  case Extrapolation_Repeat: return Extrapolation_Repeat;
69  default: return Extrapolation_None;
70  }
71 }
72 
73 // ----------------------------------------------------------------------------
74 /// Get corresponding extrapolation without periodic time
76 {
77  switch(m) {
78  case Extrapolation_Const:
79  case Extrapolation_ConstWithPeriodicTime: return Extrapolation_Const;
80  // Note: Extrapolation_Repeat remains periodic in all dimensions
81  default: return m;
82  }
83 }
84 
85 // ----------------------------------------------------------------------------
86 template <>
87 inline bool FromString(const char *str, ExtrapolationMode &m)
88 {
89  string lstr = ToLower(str);
90  if (lstr == "default" ) m = Extrapolation_Default;
91  else if (lstr == "none" ) m = Extrapolation_None;
92  else if (lstr == "const" ) m = Extrapolation_Const;
93  else if (lstr == "nn" ) m = Extrapolation_NN;
94  else if (lstr == "repeat" || lstr == "tile") m = Extrapolation_Repeat;
95  else if (lstr == "mirror" ) m = Extrapolation_Mirror;
96  else if (lstr == "constwithperiodictime" ) m = Extrapolation_ConstWithPeriodicTime;
97  else return false;
98  return true;
99 }
100 
101 
102 } // namespace mirtk
103 
104 #endif // MIRTK_ExtrapolationMode_H
ExtrapolationMode ExtrapolationWithPeriodicTime(ExtrapolationMode m)
Get corresponding extrapolation with periodic time.
ExtrapolationMode ExtrapolationWithoutPeriodicTime(ExtrapolationMode m)
Get corresponding extrapolation without periodic time.
string ToLower(const string &)
Convert string to lowercase letters.
Definition: IOConfig.h:41
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
ExtrapolationMode
Image extrapolation modes.