ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkArray.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkArray_h
00019 #define __itkArray_h
00020 
00021 #include "itkMacro.h"
00022 
00023 #include "vxl_version.h"
00024 #if VXL_VERSION_DATE_FULL < 20110428
00025 #error "System installed VXL version is too old. Please make sure the version date is later than 2011-04-28."
00026 #endif
00027 
00028 #include "vnl/vnl_vector.h"
00029 
00030 namespace itk
00031 {
00049 template< typename TValueType >
00050 class Array:public vnl_vector< TValueType >
00051 {
00052 public:
00053 
00055   typedef TValueType                                   ValueType;
00056   typedef Array                                        Self;
00057   typedef vnl_vector< TValueType >                     VnlVectorType;
00058   typedef typename vnl_vector< TValueType>::size_type  SizeValueType;
00059 
00060 public:
00061 
00064   Array();
00065 
00068   Array(const Array&);
00069 
00071   explicit Array(SizeValueType dimension);
00072 
00079   Array(ValueType *data, SizeValueType sz, bool LetArrayManageMemory = false);
00080 
00087   Array(const ValueType *data, SizeValueType sz,
00088         bool LetArrayManageMemory = false);
00089 
00091   template< class TArrayValue >
00092   Array(const Array< TArrayValue > & r)
00093   {
00094     this->m_LetArrayManageMemory = true;
00095     this->SetSize( r.GetSize() );
00096     for( SizeValueType i=0; i<r.GetSize(); i++ )
00097       {
00098       this->operator[](i) = static_cast< TValueType >( r[i] );
00099       }
00100   }
00102 
00104   void Fill(TValueType const & v) { this->fill(v); }
00105 
00107   const Self & operator=(const Self & rhs);
00108 
00109   const Self & operator=(const VnlVectorType & rhs);
00110 
00112   SizeValueType Size(void) const
00113   { return static_cast<SizeValueType >( this->size() ); }
00114   unsigned int GetNumberOfElements(void) const
00115   { return static_cast<SizeValueType >( this->size() ); }
00117 
00119   const TValueType & GetElement(SizeValueType i) const
00120   { return this->operator[](i); }
00121 
00123   void SetElement(SizeValueType i, const TValueType & value)
00124   { this->operator[](i) = value; }
00125 
00127   void SetSize(SizeValueType sz);
00128 
00129   SizeValueType GetSize(void) const
00130   { return static_cast< SizeValueType >( this->size() ); }
00131 
00137   void SetData(TValueType *data, bool LetArrayManageMemory = false);
00138 
00148   void SetData(TValueType *data, SizeValueType sz,
00149                bool LetArrayManageMemory = false);
00150 
00151 
00152 #ifdef __INTEL_COMPILER
00153 #pragma warning disable 444 //destructor for base class "itk::Array<>" is not virtual
00154 #endif
00155 
00157   ~Array();
00158 private:
00159 
00160   bool m_LetArrayManageMemory;
00161 };
00162 
00163 template< typename TValueType >
00164 std::ostream & operator<<(std::ostream & os, const Array< TValueType > & arr)
00165 {
00166   const unsigned int length = arr.size();
00167   const signed int   last   = (unsigned int)length - 1;
00168 
00169   os << "[";
00170   for ( signed int i = 0; i < last; ++i )
00171     {
00172     os << arr[i] << ", ";
00173     }
00174   if ( length >= 1 )
00175     {
00176     os << arr[last];
00177     }
00178   os << "]";
00179   return os;
00180 }
00181 } // namespace itk
00182 
00183 // Define instantiation macro for this template.
00184 #define ITK_TEMPLATE_Array(_, EXPORT, TypeX, TypeY)                                  \
00185   namespace itk                                                                      \
00186   {                                                                                  \
00187   _( 1 ( class EXPORT Array< ITK_TEMPLATE_1 TypeX > ) )                              \
00188   _( 1 ( EXPORT std::ostream & operator<<(std::ostream &,                            \
00189                                           const Array< ITK_TEMPLATE_1 TypeX > &) ) ) \
00190   namespace Templates                                                                \
00191   {                                                                                  \
00192   typedef Array< ITK_TEMPLATE_1 TypeX > Array##TypeY;                              \
00193   }                                                                                  \
00194   }
00195 
00196 #if ITK_TEMPLATE_EXPLICIT
00197 #include "Templates/itkArray+-.h"
00198 #endif
00199 
00200 #if ITK_TEMPLATE_TXX
00201 #include "itkArray.hxx"
00202 #endif
00203 
00204 #endif
00205