ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkArray.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 #ifndef __itkArray_h
19 #define __itkArray_h
20 
21 #include "itkMacro.h"
22 
23 #include "vxl_version.h"
24 #if VXL_VERSION_DATE_FULL < 20110428
25 #error "System installed VXL version is too old. Please make sure the version date is later than 2011-04-28."
26 #endif
27 
28 #include "vnl/vnl_vector.h"
29 
30 namespace itk
31 {
49 template< typename TValueType >
50 class Array : public vnl_vector< TValueType >
51 {
52 public:
53 
55  typedef TValueType ValueType;
56  typedef Array Self;
57  typedef vnl_vector< TValueType > VnlVectorType;
58  typedef typename vnl_vector< TValueType>::size_type SizeValueType;
59 
60 public:
61 
64  Array();
65 
68  Array(const Array&);
69 
71  explicit Array(SizeValueType dimension);
72 
79  Array(ValueType *data, SizeValueType sz, bool LetArrayManageMemory = false);
80 
87  Array(const ValueType *data, SizeValueType sz,
88  bool LetArrayManageMemory = false);
89 
91  template< class TArrayValue >
93  {
94  this->m_LetArrayManageMemory = true;
95  this->SetSize( r.GetSize() );
96  for( SizeValueType i=0; i<r.GetSize(); i++ )
97  {
98  this->operator[](i) = static_cast< TValueType >( r[i] );
99  }
100  }
102 
104  void Fill(TValueType const & v)
105  {
106  this->fill(v);
107  }
108 
110  const Self & operator=(const Self & rhs);
111 
112  const Self & operator=(const VnlVectorType & rhs);
113 
115  SizeValueType Size(void) const
116  { return static_cast<SizeValueType >( this->size() ); }
117  unsigned int GetNumberOfElements(void) const
118  { return static_cast<SizeValueType >( this->size() ); }
120 
122  const TValueType & GetElement(SizeValueType i) const
123  { return this->operator[](i); }
124 
126  void SetElement(SizeValueType i, const TValueType & value)
127  { this->operator[](i) = value; }
128 
130  void SetSize(SizeValueType sz);
131 
132  SizeValueType GetSize(void) const
133  { return static_cast< SizeValueType >( this->size() ); }
134 
140  void SetData(TValueType *data, bool LetArrayManageMemory = false);
141 
151  void SetData(TValueType *data, SizeValueType sz,
152  bool LetArrayManageMemory = false);
153 
154 
155 #ifdef __INTEL_COMPILER
156 #pragma warning disable 444 //destructor for base class "itk::Array<>" is not virtual
157 #endif
158 
160  ~Array();
161 
162 private:
163 
165 };
166 
167 template< typename TValueType >
168 std::ostream & operator<<(std::ostream & os, const Array< TValueType > & arr)
169 {
170  os << "[";
171  const unsigned int length = arr.size();
172  if ( length >= 1 )
173  {
174  const unsigned int last = length - 1;
175  for ( unsigned int i = 0; i < last; ++i )
176  {
177  os << arr[i] << ", ";
178  }
179  os << arr[last];
180  }
181  os << "]";
182  return os;
183 }
184 
185 // declaration of specialization
186 template<> ITKCommon_EXPORT std::ostream & operator<< <double> (std::ostream & os, const Array< double > & arr);
187 template<> ITKCommon_EXPORT std::ostream & operator<< <float> (std::ostream & os, const Array< float > & arr);
188 
189 } // namespace itk
190 
191 #ifndef ITK_MANUAL_INSTANTIATION
192 #include "itkArray.hxx"
193 #endif
194 
195 #endif
196