GenericImageIterator.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_GenericImageIterator_H
21 #define MIRTK_GenericImageIterator_H
22 
23 #include "mirtk/ImageIterator.h"
24 #include "mirtk/ConstImageIterator.h"
25 #include "mirtk/ImageAttributes.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * Non-const image iterator
33  */
34 template <class VoxelType>
36 {
37 public:
38 
39  /// Constructor
40  GenericImageIterator(const ImageAttributes &, VoxelType * = NULL);
41 
42  /// Constructor
44 
45  /// Constructor
47 
48  /// Copy constructor
50 
51  /// Assignment operator
53 
54  /// Destructor
56 
57  /// Get pointer to current iterator position
58  ///
59  /// The VoxelType template argument must match the actual scalar type of the image.
60  VoxelType *Current() const;
61 
62  /// Get pointer to current iterator position
63  ///
64  /// The VoxelType template argument must match the actual scalar type of the image.
65  ///
66  /// \param[in] t Channel/Component/Frame offset relative to current iterator position.
67  /// For example, set iterator region to only the first channel/frame and
68  /// then access other channels/vector components/frames using this method.
69  VoxelType *Current(int) const;
70 
71  /// Get pointer to current iterator position and post-increment iterator
72  ///
73  /// The VoxelType template argument must match the actual scalar type of the image.
74  VoxelType *Next();
75 
76  /// Get pointer to current iterator position and post-increment iterator
77  ///
78  /// The VoxelType template argument must match the actual scalar type of the image.
79  ///
80  /// \param[in] t Channel/Component/Frame offset relative to current iterator position.
81  /// For example, set iterator region to only the first channel/frame and
82  /// then access other channels/vector components/frames using this method.
83  VoxelType *Next(int);
84 
85  /// Get reference to voxel value at current iterator position
86  ///
87  /// The VoxelType template argument must match the actual scalar type of the image.
88  VoxelType &Value() const;
89 
90  /// Get reference to voxel value at current iterator position
91  ///
92  /// The VoxelType template argument must match the actual scalar type of the image.
93  ///
94  /// \param[in] t Channel/Component/Frame offset relative to current iterator position.
95  /// For example, set iterator region to only the first channel/frame and
96  /// then access other channels/vector components/frames using this method.
97  VoxelType &Value(int t) const;
98 
99  /// Get current voxel value casted to double
100  double ValueAsDouble() const;
101 
102  /// Get current voxel value casted to double
103  ///
104  /// \param[in] t Channel/Component/Frame offset relative to current iterator position.
105  /// For example, set iterator region to only the first channel/frame and
106  /// then access other channels/vector components/frames using this method.
107  double ValueAsDouble(int) const;
108 
109 };
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 // Inline definitions
113 ////////////////////////////////////////////////////////////////////////////////
114 
115 // ---------------------------------------------------------------------------
116 template <class VoxelType>
118 ::GenericImageIterator(const ImageAttributes &attr, VoxelType *data)
119 :
120  ImageIterator(attr, data, voxel_info<VoxelType>::type())
121 {
122 }
123 
124 // ---------------------------------------------------------------------------
125 template <class VoxelType>
127 :
128  ImageIterator(image)
129 {
130 }
131 
132 // ---------------------------------------------------------------------------
133 template <class VoxelType>
135 :
136  ImageIterator(image)
137 {
138 }
139 
140 // ---------------------------------------------------------------------------
141 template <class VoxelType>
143 :
144  ImageIterator(other)
145 {
146 }
147 
148 // ---------------------------------------------------------------------------
149 template <class VoxelType>
152 {
154  return *this;
155 }
156 
157 // ---------------------------------------------------------------------------
158 template <class VoxelType>
160 {
161 }
162 
163 // ---------------------------------------------------------------------------
164 template <class VoxelType>
166 {
167  return ImageIterator::Current<VoxelType>();
168 }
169 
170 // ---------------------------------------------------------------------------
171 template <class VoxelType>
172 inline VoxelType *GenericImageIterator<VoxelType>::Current(int t) const
173 {
174  return ImageIterator::Current<VoxelType>(t);
175 }
176 
177 // ---------------------------------------------------------------------------
178 template <class VoxelType>
180 {
181  return ImageIterator::Next<VoxelType>();
182 }
183 
184 // ---------------------------------------------------------------------------
185 template <class VoxelType>
187 {
188  return ImageIterator::Next<VoxelType>(t);
189 }
190 
191 // ---------------------------------------------------------------------------
192 template <class VoxelType>
193 inline VoxelType &GenericImageIterator<VoxelType>::Value() const
194 {
195  return ImageIterator::Value<VoxelType>();
196 }
197 
198 // ---------------------------------------------------------------------------
199 template <class VoxelType>
200 inline VoxelType &GenericImageIterator<VoxelType>::Value(int t) const
201 {
202  return ImageIterator::Value<VoxelType>(t);
203 }
204 
205 // ---------------------------------------------------------------------------
206 template <class VoxelType>
208 {
209  return static_cast<double>(Value());
210 }
211 
212 // ---------------------------------------------------------------------------
213 template <class VoxelType>
215 {
216  return static_cast<double>(Value(t));
217 }
218 
219 
220 } // namespace mirtk
221 
222 #endif // MIRTK_GenericImageIterator_H
GenericImageIterator(const ImageAttributes &, VoxelType *=NULL)
Constructor.
double ValueAsDouble() const
Get current voxel value casted to double.
ImageIterator & operator=(const ImageIterator &)
Assignment operator.
Definition: IOConfig.h:41
GenericImageIterator & operator=(const GenericImageIterator &)
Assignment operator.