NeighborhoodOffsets.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2015 Imperial College London
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef MIRTK_NeighborhoodOffsets_H
20 #define MIRTK_NeighborhoodOffsets_H
21 
22 #include "mirtk/BaseImage.h"
23 
24 
25 namespace mirtk {
26 
27 
28 /// Type of image connectivity, i.e., number of neighbors for each voxel
30 {
31  CONNECTIVITY_4 = 4,
32  CONNECTIVITY_6 = 6,
33  CONNECTIVITY_18 = 18,
34  CONNECTIVITY_26 = 26
35 };
36 
37 
38 /**
39  * Image neighborhood offsets.
40  */
42 {
43  mirtkObjectMacro(NeighborhoodOffsets);
44 
45  // ---------------------------------------------------------------------------
46  // Types
47 
48 public:
49 
50  // ---------------------------------------------------------------------------
51  // Attributes
52 
53 private:
54 
55  /// Image connectivity
56  mirtkPublicAttributeMacro(ConnectivityType, Connectivity);
57 
58  /// Size of neighborhood
59  mirtkReadOnlyAttributeMacro(int, Size);
60 
61  /// Neighborhood offsets, set to maximum possible size
62  int _Offsets[26];
63 
64  // ---------------------------------------------------------------------------
65  // Construction/Destruction
66 
67 public:
68 
69  /// Constructor
71 
72  /// Constructor with image and connectivity specified
73  NeighborhoodOffsets(const BaseImage *, ConnectivityType = CONNECTIVITY_26);
74 
75  /// Initializer with image and connectivity specified
76  void Initialize(const BaseImage *, ConnectivityType = CONNECTIVITY_26);
77 
78  /// Initializer with slice dimensions and connectivity specified
79  void Initialize(int, int, ConnectivityType);
80 
81  /// Destructor
82  virtual ~NeighborhoodOffsets();
83 
84  /// Get i-th neighborhood offset
85  ///
86  /// \param[in] i Index of neighboring voxel.
87  ///
88  /// \returns Offset of neighboring voxel.
89  int operator()(int i) const;
90 
91 };
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 // Inline definitions
95 ////////////////////////////////////////////////////////////////////////////////
96 
97 // -----------------------------------------------------------------------------
98 inline int NeighborhoodOffsets::operator()(int i) const
99 {
100  return _Offsets[i];
101 }
102 
103 // =============================================================================
104 // Connectivity type / string conversion
105 // =============================================================================
106 
107 // -----------------------------------------------------------------------------
108 /// Convert image connectivity type to string
109 template <>
110 inline string ToString(const ConnectivityType &value, int w, char c, bool left)
111 {
112  return ToString(static_cast<int>(value), w, c, left);
113 }
114 
115 // -----------------------------------------------------------------------------
116 /// Convert string to image connectivity type
117 template <>
118 inline bool FromString(const char *str, ConnectivityType &value)
119 {
120  int n;
121  if (!FromString(str, n)) return false;
122  switch (n) {
123  case 4: value = CONNECTIVITY_4; break;
124  case 6: value = CONNECTIVITY_6; break;
125  case 18: value = CONNECTIVITY_18; break;
126  case 26: value = CONNECTIVITY_26; break;
127  default: return false;
128  }
129  return true;
130 }
131 
132 
133 } // namespace mirtk
134 
135 #endif // MIRTK_NeighborhoodOffsets_H
NeighborhoodOffsets()
Constructor.
void Initialize(const BaseImage *, ConnectivityType=CONNECTIVITY_26)
Initializer with image and connectivity specified.
virtual ~NeighborhoodOffsets()
Destructor.
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.
ConnectivityType
Type of image connectivity, i.e., number of neighbors for each voxel.