go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkVectorDataContainer.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
22/*=========================================================================
23
24 Program: Insight Segmentation & Registration Toolkit
25 Module: $RCSfile$
26 Date: $Date: 2008-04-15 19:54:41 +0200 (Tue, 15 Apr 2008) $
27 Version: $Revision: 1573 $
28
29 Copyright (c) Insight Software Consortium. All rights reserved.
30 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
31
32 This software is distributed WITHOUT ANY WARRANTY; without even
33 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
34 PURPOSE. See the above copyright notices for more information.
35
36=========================================================================*/
37#ifndef itkVectorDataContainer_h
38#define itkVectorDataContainer_h
39
40#include "itkDataObject.h"
41#include "itkObjectFactory.h"
42
43#include <utility>
44#include <vector>
45
46namespace itk
47{
48
71template <typename TElementIdentifier, typename TElement>
72class ITK_TEMPLATE_EXPORT VectorDataContainer
73 : public DataObject
74 , public std::vector<TElement>
75{
76public:
79 using Superclass = DataObject;
80 using Pointer = SmartPointer<Self>;
81 using ConstPointer = SmartPointer<const Self>;
82
84 using ElementIdentifier = TElementIdentifier;
85 using Element = TElement;
86
87private:
89 using VectorType = std::vector<Element>;
90 using size_type = typename VectorType::size_type;
91 using VectorIterator = typename VectorType::iterator;
92 using VectorConstIterator = typename VectorType::const_iterator;
93
94protected:
99 : DataObject()
100 , VectorType()
101 {}
103 : DataObject()
104 , VectorType(n)
105 {}
107 : DataObject()
108 , VectorType(n, x)
109 {}
111 : DataObject()
112 , VectorType(r)
113 {}
114 template <typename InputIterator>
115 VectorDataContainer(InputIterator first, InputIterator last)
116 : DataObject()
117 , VectorType(first, last)
118 {}
119
120public:
123
125 itkNewMacro(Self);
126
128 itkTypeMacro(VectorDataContainer, DataObject);
129
131 class Iterator;
132 class ConstIterator;
133
137 {
138 return dynamic_cast<STLContainerType &>(*this);
139 }
140
141
143 const STLContainerType &
145 {
146 return dynamic_cast<const STLContainerType &>(*this);
147 }
148
149
151 friend class Iterator;
152 friend class ConstIterator;
153
156 class Iterator
157 {
158 public:
159 Iterator() = default;
160 Iterator(size_type d, const VectorIterator & i)
161 : m_Pos(d)
162 , m_Iter(i)
163 {}
164
165 Iterator & operator*() { return *this; }
166 Iterator * operator->() { return this; }
167 Iterator &
168 operator++()
169 {
170 ++m_Pos;
171 ++m_Iter;
172 return *this;
173 }
174 Iterator
175 operator++(int)
176 {
177 Iterator temp(*this);
178 ++m_Pos;
179 ++m_Iter;
180 return temp;
181 }
182 Iterator
183 operator+=(int j)
184 {
185 m_Pos += j;
186 m_Iter += j;
187 return *this;
188 }
189 Iterator
190 operator-=(int j)
191 {
192 m_Pos -= j;
193 m_Iter -= j;
194 return *this;
195 }
196 Iterator &
197 operator--()
198 {
199 --m_Pos;
200 --m_Iter;
201 return *this;
202 }
203 Iterator
204 operator--(int)
205 {
206 Iterator temp(*this);
207 --m_Pos;
208 --m_Iter;
209 return temp;
210 }
211
212 bool
213 operator==(const Iterator & r) const
214 {
215 return m_Iter == r.m_Iter;
216 }
217 bool
218 operator!=(const Iterator & r) const
219 {
220 return m_Iter != r.m_Iter;
221 }
222 bool
223 operator==(const ConstIterator & r) const
224 {
225 return m_Iter == r.m_Iter;
226 }
227 bool
228 operator!=(const ConstIterator & r) const
229 {
230 return m_Iter != r.m_Iter;
231 }
232
234 ElementIdentifier
235 Index() const
236 {
237 return static_cast<ElementIdentifier>(m_Pos);
238 }
239
241 Element &
242 Value() const
243 {
244 return *m_Iter;
245 }
246
247 private:
248 size_type m_Pos;
249 VectorIterator m_Iter;
250 friend class ConstIterator;
251 };
252
255 class ConstIterator
256 {
257 public:
258 ConstIterator() = default;
259 ConstIterator(size_type d, const VectorConstIterator & i)
260 : m_Pos(d)
261 , m_Iter(i)
262 {}
263 ConstIterator(const Iterator & r)
264 {
265 m_Pos = r.m_Pos;
266 m_Iter = r.m_Iter;
267 }
268
269 ConstIterator & operator*() { return *this; }
270 ConstIterator * operator->() { return this; }
271 ConstIterator &
272 operator++()
273 {
274 ++m_Pos;
275 ++m_Iter;
276 return *this;
277 }
278 ConstIterator
279 operator++(int)
280 {
281 ConstIterator temp(*this);
282 ++m_Pos;
283 ++m_Iter;
284 return temp;
285 }
286 ConstIterator
287 operator+=(int j)
288 {
289 m_Pos += j;
290 m_Iter += j;
291 return *this;
292 }
293 ConstIterator
294 operator-=(int j)
295 {
296 m_Pos -= j;
297 m_Iter -= j;
298 return *this;
299 }
300 ConstIterator &
301 operator--()
302 {
303 --m_Pos;
304 --m_Iter;
305 return *this;
306 }
307 ConstIterator
308 operator--(int)
309 {
310 ConstIterator temp(*this);
311 --m_Pos;
312 --m_Iter;
313 return temp;
314 }
315
316 ConstIterator &
317 operator=(const Iterator & r)
318 {
319 m_Pos = r.m_Pos;
320 m_Iter = r.m_Iter;
321 return *this;
322 }
323
324 bool
325 operator==(const Iterator & r) const
326 {
327 return m_Iter == r.m_Iter;
328 }
329 bool
330 operator!=(const Iterator & r) const
331 {
332 return m_Iter != r.m_Iter;
333 }
334 bool
335 operator==(const ConstIterator & r) const
336 {
337 return m_Iter == r.m_Iter;
338 }
339 bool
340 operator!=(const ConstIterator & r) const
341 {
342 return m_Iter != r.m_Iter;
343 }
344
346 ElementIdentifier
347 Index() const
348 {
349 return static_cast<ElementIdentifier>(m_Pos);
350 }
351
353 const Element &
354 Value() const
355 {
356 return *m_Iter;
357 }
358
359 private:
360 size_type m_Pos;
361 VectorConstIterator m_Iter;
362 friend class Iterator;
363 };
364
365 /* Declare the public interface routines. */
366
376
384
394
400
406
413
419
425 bool
427
434
441
445 ConstIterator
446 Begin() const;
447
451 ConstIterator
452 End() const;
453
457 Iterator
459
463 Iterator
465
469 unsigned long
470 Size() const;
471
482
489 void
491
495 void
496 Initialize() override;
497};
498
499} // end namespace itk
500
501#ifndef ITK_MANUAL_INSTANTIATION
502# include "itkVectorDataContainer.hxx"
503#endif
504
505#endif // end itkVectorDataContainer_h
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
void Initialize() override
void InsertElement(ElementIdentifier, Element)
void CreateIndex(ElementIdentifier)
unsigned long Size() const
typename VectorType::size_type size_type
void DeleteIndex(ElementIdentifier)
typename VectorType::iterator VectorIterator
TElementIdentifier ElementIdentifier
ConstIterator End() const
Element GetElement(ElementIdentifier) const
VectorDataContainer(size_type n, const Element &x)
VectorDataContainer(InputIterator first, InputIterator last)
const Element & ElementAt(ElementIdentifier) const
ConstIterator Begin() const
SmartPointer< const Self > ConstPointer
Element & CreateElementAt(ElementIdentifier)
void Reserve(ElementIdentifier)
STLContainerType & CastToSTLContainer()
bool GetElementIfIndexExists(ElementIdentifier, Element *) const
bool IndexExists(ElementIdentifier) const
typename VectorType::const_iterator VectorConstIterator
Element & ElementAt(ElementIdentifier)
void SetElement(ElementIdentifier, Element)
const STLContainerType & CastToSTLConstContainer() const
std::vector< Element > VectorType
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)


Generated on Wed 12 Apr 2023 for elastix by doxygen 1.9.6 elastix logo