00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkArray_h
00018 #define __itkArray_h
00019
00020 #include "itkMacro.h"
00021 #include "vnl/vnl_vector.h"
00022
00023 namespace itk
00024 {
00025
00026
00043 template <typename TValueType >
00044 class Array : public vnl_vector< TValueType >
00045 {
00046 public:
00047
00049 typedef TValueType ValueType;
00050 typedef Array Self;
00051 typedef vnl_vector<TValueType> VnlVectorType;
00052
00053 public:
00054
00057 Array();
00058
00060 Array(unsigned int dimension);
00061
00068 Array( ValueType* data, unsigned int sz, bool LetArrayManageMemory = false);
00069
00076 Array( const ValueType* data, unsigned int sz,
00077 bool LetArrayManageMemory = false);
00078
00079
00081 void Fill (TValueType const& v) { fill(v); }
00082
00084 const Self & operator=( const Self &rhs );
00085 const Self & operator=( const VnlVectorType & rhs );
00087
00089 unsigned int Size (void ) const
00090 { return static_cast<unsigned int>( this->size() ); }
00091 unsigned int GetNumberOfElements(void) const
00092 { return static_cast<unsigned int>( this->size() ); }
00094
00096 const TValueType & GetElement( unsigned int i ) const
00097 { return this->operator[]( i ); }
00098
00100 void SetElement( unsigned int i, const TValueType & value )
00101 { this->operator[]( i ) = value; }
00102
00104 void SetSize(unsigned int sz);
00105 unsigned int GetSize(void) const
00106 { return static_cast<unsigned int>( this->size() ); }
00108
00114 void SetData(TValueType* data,bool LetArrayManageMemory = false);
00115
00125 void SetData(TValueType* data, unsigned int sz,
00126 bool LetArrayManageMemory = false);
00127
00128
00131 ~Array();
00132
00133 private:
00134
00135 bool m_LetArrayManageMemory;
00136
00137 };
00138
00139
00140 template <typename TValueType >
00141 std::ostream & operator<<(std::ostream &os, const Array<TValueType> &arr)
00142 {
00143 const unsigned int length = arr.size();
00144 const signed int last = (unsigned int) length - 1;
00145
00146 os << "[";
00147 for (signed int i=0; i < last; ++i)
00148 {
00149 os << arr[i] << ", ";
00150 }
00151 if (length >= 1)
00152 {
00153 os << arr[last];
00154 }
00155 os << "]";
00156 return os;
00157 }
00158
00159 }
00160
00161
00162 #ifndef ITK_MANUAL_INSTANTIATION
00163 #include "itkArray.txx"
00164 #endif
00165
00166
00167 #endif
00168