itkArray2D.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkArray2D_h
00018 #define __itkArray2D_h
00019
00020 #include "itkMacro.h"
00021 #include "vnl/vnl_matrix.h"
00022
00023 namespace itk
00024 {
00025
00026
00043 template <typename TValueType >
00044 class Array2D : public vnl_matrix< TValueType >
00045 {
00046 public:
00047
00049 typedef TValueType ValueType;
00050 typedef Array2D Self;
00051 typedef vnl_matrix<TValueType> VnlMatrixType;
00052
00053 public:
00054
00055 Array2D();
00056 Array2D(unsigned int rows,unsigned int cols);
00057 Array2D( const Self & array );
00058 Array2D( const VnlMatrixType & matrix );
00059
00060 const Self & operator=( const Self & array );
00061 const Self & operator=( const VnlMatrixType & matrix );
00062
00063 void Fill (TValueType const& v) { this->fill(v); }
00064
00066 void SetSize(unsigned int m, unsigned int n);
00067
00070 ~Array2D() {};
00071
00072 };
00073
00074
00075
00076 template <typename TValueType >
00077 std::ostream & operator<<(std::ostream &os, const Array2D<TValueType> &arr)
00078 {
00079 const unsigned int numberOfColumns = arr.cols();
00080 const unsigned int numberOfRows = arr.rows();
00081 const signed int lastColumn = (signed int) numberOfColumns - 1;
00082
00083 for (unsigned int r=0; r < numberOfRows; ++r)
00084 {
00085 os << "[";
00086 for ( signed int c=0; c < lastColumn; ++c)
00087 {
00088 os << arr(r,c) << ", ";
00089 }
00090 if (numberOfColumns >= 1)
00091 {
00092 os << arr(r,lastColumn);
00093 }
00094 os << "]" << std::endl;
00095 }
00096
00097 return os;
00098 }
00099
00100 }
00101
00102
00103
00104 #define ITK_TEMPLATE_Array2D(_, EXPORT, x, y) namespace itk { \
00105 _(1(class EXPORT Array2D< ITK_TEMPLATE_1 x >)) \
00106 _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00107 const Array2D< ITK_TEMPLATE_1 x >&))) \
00108 namespace Templates { typedef Array2D< ITK_TEMPLATE_1 x > Array2D##y; } \
00109 }
00110
00111
00112 #if ITK_TEMPLATE_EXPLICIT
00113 # include "Templates/itkArray2D+-.h"
00114 #endif
00115
00116 #if ITK_TEMPLATE_TXX
00117 # include "itkArray2D.txx"
00118 #endif
00119
00120 #endif
00121