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  This file is part of the elastix software.
4 
5  Copyright (c) University Medical Center Utrecht. All rights reserved.
6  See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
7  details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 ======================================================================*/
14 
18 /*=========================================================================
19 
20  Program: Insight Segmentation & Registration Toolkit
21  Module: $RCSfile$
22  Language: C++
23  Date: $Date: 2008-04-15 19:54:41 +0200 (Tue, 15 Apr 2008) $
24  Version: $Revision: 1573 $
25 
26  Copyright (c) Insight Software Consortium. All rights reserved.
27  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
28 
29  This software is distributed WITHOUT ANY WARRANTY; without even
30  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31  PURPOSE. See the above copyright notices for more information.
32 
33 =========================================================================*/
34 #ifndef __itkVectorDataContainer_h
35 #define __itkVectorDataContainer_h
36 
37 #include "itkDataObject.h"
38 #include "itkObjectFactory.h"
39 
40 #include <utility>
41 #include <vector>
42 
43 namespace itk
44 {
45 
68 template<
69 typename TElementIdentifier,
70 typename TElement
71 >
73  public DataObject,
74  public std::vector< TElement >
75 {
76 public:
77 
80  typedef DataObject Superclass;
81  typedef SmartPointer< Self > Pointer;
82  typedef SmartPointer< const Self > ConstPointer;
83 
85  typedef TElementIdentifier ElementIdentifier;
86  typedef TElement Element;
87 
88 private:
89 
91  typedef std::vector< Element > VectorType;
92  typedef typename VectorType::size_type size_type;
93  typedef typename VectorType::iterator VectorIterator;
94  typedef typename VectorType::const_iterator VectorConstIterator;
95 
96 protected:
97 
102  DataObject(), VectorType() {}
104  DataObject(), VectorType( n ) {}
106  DataObject(), VectorType( n, x ) {}
107  VectorDataContainer( const Self & r ) :
108  DataObject(), VectorType( r ) {}
109  template< typename InputIterator >
110  VectorDataContainer( InputIterator first, InputIterator last ) :
111  DataObject(), VectorType( first, last ) {}
112 
113 public:
114 
117 
119  itkNewMacro( Self );
120 
122  itkTypeMacro( VectorDataContainer, DataObject );
123 
125  class Iterator;
126  class ConstIterator;
127 
130  {
131  return dynamic_cast< STLContainerType & >( *this );
132  }
133 
134 
137  {
138  return dynamic_cast< const STLContainerType & >( *this );
139  }
140 
141 
143  friend class Iterator;
144  friend class ConstIterator;
145 
148  class Iterator
149  {
150 public:
151 
152  Iterator() {}
153  Iterator( size_type d, const VectorIterator & i ) : m_Pos( d ), m_Iter( i ) {}
154 
155  Iterator & operator*() { return *this; }
156  Iterator * operator->() { return this; }
157  Iterator & operator++() { ++m_Pos; ++m_Iter; return *this; }
158  Iterator operator++( int ) { Iterator temp( *this ); ++m_Pos; ++m_Iter; return temp; }
159  Iterator operator+=( int j ){ m_Pos += j; m_Iter += j; return *this; }
160  Iterator operator-=( int j ){ m_Pos -= j; m_Iter -= j; return *this; }
161  Iterator & operator--() { --m_Pos; --m_Iter; return *this; }
162  Iterator operator--( int ) { Iterator temp( *this ); --m_Pos; --m_Iter; return temp; }
163 
164  bool operator==( const Iterator & r ) const { return m_Iter == r.m_Iter; }
165  bool operator!=( const Iterator & r ) const { return m_Iter != r.m_Iter; }
166  bool operator==( const ConstIterator & r ) const { return m_Iter == r.m_Iter; }
167  bool operator!=( const ConstIterator & r ) const { return m_Iter != r.m_Iter; }
168 
170  ElementIdentifier Index( void ) const { return static_cast< ElementIdentifier >( m_Pos ); }
171 
173  Element & Value( void ) const { return *m_Iter; }
174 
175 private:
176 
177  size_type m_Pos;
178  VectorIterator m_Iter;
179  friend class ConstIterator;
180  };
181 
184  class ConstIterator
185  {
186 public:
187 
188  ConstIterator() {}
189  ConstIterator( size_type d, const VectorConstIterator & i ) : m_Pos( d ), m_Iter( i ) {}
190  ConstIterator( const Iterator & r ) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; }
191 
192  ConstIterator & operator*() { return *this; }
193  ConstIterator * operator->() { return this; }
194  ConstIterator & operator++() { ++m_Pos; ++m_Iter; return *this; }
195  ConstIterator operator++( int ) { ConstIterator temp( *this ); ++m_Pos; ++m_Iter; return temp; }
196  ConstIterator operator+=( int j ){ m_Pos += j; m_Iter += j; return *this; }
197  ConstIterator operator-=( int j ){ m_Pos -= j; m_Iter -= j; return *this; }
198  ConstIterator & operator--() { --m_Pos; --m_Iter; return *this; }
199  ConstIterator operator--( int ) { ConstIterator temp( *this ); --m_Pos; --m_Iter; return temp; }
200 
201  ConstIterator & operator=( const Iterator & r ) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; return *this; }
202 
203  bool operator==( const Iterator & r ) const { return m_Iter == r.m_Iter; }
204  bool operator!=( const Iterator & r ) const { return m_Iter != r.m_Iter; }
205  bool operator==( const ConstIterator & r ) const { return m_Iter == r.m_Iter; }
206  bool operator!=( const ConstIterator & r ) const { return m_Iter != r.m_Iter; }
207 
209  ElementIdentifier Index( void ) const { return static_cast< ElementIdentifier >( m_Pos ); }
210 
212  const Element & Value( void ) const { return *m_Iter; }
213 
214 private:
215 
216  size_type m_Pos;
217  VectorConstIterator m_Iter;
218  friend class Iterator;
219  };
220 
221  /* Declare the public interface routines. */
222 
232 
239  const Element & ElementAt( ElementIdentifier ) const;
240 
250 
256 
262 
269 
274  bool IndexExists( ElementIdentifier ) const;
275 
282 
289 
296 
300  ConstIterator Begin( void ) const;
301 
305  ConstIterator End( void ) const;
306 
310  Iterator Begin( void );
311 
315  Iterator End( void );
316 
320  unsigned long Size( void ) const;
321 
331  void Reserve( ElementIdentifier );
332 
339  void Squeeze( void );
340 
344  void Initialize( void );
345 
346 };
347 
348 } // end namespace itk
349 
350 #ifndef ITK_MANUAL_INSTANTIATION
351 #include "itkVectorDataContainer.hxx"
352 #endif
353 
354 #endif // end __itkVectorDataContainer_h
ConstIterator Begin(void) const
ConstIterator End(void) const
bool GetElementIfIndexExists(ElementIdentifier, Element *) const
bool IndexExists(ElementIdentifier) const
void DeleteIndex(ElementIdentifier)
Element & CreateElementAt(ElementIdentifier)
__host__ __device__ void operator-=(int2 &a, int2 b)
SmartPointer< const Self > ConstPointer
VectorDataContainer(size_type n, const Element &x)
STLContainerType & CastToSTLContainer()
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
__host__ __device__ int2 operator*(int2 a, int2 b)
void CreateIndex(ElementIdentifier)
void SetElement(ElementIdentifier, Element)
const STLContainerType & CastToSTLConstContainer() const
std::vector< Element > VectorType
VectorType::size_type size_type
SmartPointer< Self > Pointer
void InsertElement(ElementIdentifier, Element)
Element GetElement(ElementIdentifier) const
VectorDataContainer(InputIterator first, InputIterator last)
unsigned long Size(void) const
Element & ElementAt(ElementIdentifier)
__host__ __device__ void operator+=(int2 &a, int2 b)
void Reserve(ElementIdentifier)
VectorType::iterator VectorIterator
VectorType::const_iterator VectorConstIterator
TElementIdentifier ElementIdentifier


Generated on 27-04-2014 for elastix by doxygen 1.8.6 elastix logo