Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkArray.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/07/09 01:35:05 $
00007   Version:   $Revision: 1.47 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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) { this->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 } // namespace itk
00160 
00161 // Define instantiation macro for this template.
00162 #define ITK_TEMPLATE_Array(_, EXPORT, x, y) namespace itk { \
00163   _(1(class EXPORT Array< ITK_TEMPLATE_1 x >)) \
00164   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00165                                      const Array< ITK_TEMPLATE_1 x >&))) \
00166   namespace Templates { typedef Array< ITK_TEMPLATE_1 x > Array##y; } \
00167   }
00168 
00169 
00170 #if ITK_TEMPLATE_EXPLICIT
00171 # include "Templates/itkArray+-.h"
00172 #endif
00173 
00174 #if ITK_TEMPLATE_TXX
00175 # include "itkArray.txx"
00176 #endif
00177 
00178 #endif
00179 

Generated at Tue Jul 29 19:07:11 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000