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