KWStyle - itkArray2D.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkArray2D.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:32 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkArray2D_h
18 #define __itkArray2D_h
19
20 #include "itkMacro.h"
21 #include "vnl/vnl_matrix.h"
22
23 namespace itk
24 {
25
26  
27 /** \class Array2D
28  *  \brief Array2D class representing a 2D array with size defined 
29  *  at construction time.
30  * 
31  * This class derives from the vnl_matrix<> class. 
32  * Its size is assigned at construction time (run time) and can not be
33  * changed afterwards.
34  *
35  * The class is templated over the type of the elements.
36  *
37  * Template parameters for class Array2D:
38  *
39  * - TValueType = Element type stored at each location in the array.
40  *
41  * \ingroup DataRepresentation 
42  */
43 template <typename TValueType >
44 class Array2D : public vnl_matrix< TValueType >
45 {
46 public:
47  
48   /** The element type stored at each location in the Array2D. */
49   typedef TValueType              ValueType;
50   typedef Array2D                 Self;
51   typedef vnl_matrix<TValueType>  VnlMatrixType;
52   
53 public:
54
55   Array2D();
56   Array2D(unsigned int rows,unsigned int cols);
57   Array2D( const Self & array );
58   Array2D( const VnlMatrixType & matrix );
59
60   const Self & operator=( const Self & array );
61   const Self & operator=( const VnlMatrixType & matrix );
62
63   void Fill (TValueType const& v) { fill(v); }
64   
65   /** Destructively set the size to that given.  Will lose data.  */
66   void SetSize(unsigned int m, unsigned int n);
67
68   /** This destructor is not virtual for performance reasons. However, this
69    * means that subclasses cannot allocate memory. */
70   ~Array2D() {};
71   
72 };
73
74
75   
76 template <typename TValueType >
77 std::ostream & operator<<(std::ostream &os, const Array2D<TValueType> &arr)
78 {
79   const unsigned int numberOfColumns = arr.cols();
80   const unsigned int numberOfRows    = arr.rows();
81   const signed int lastColumn = (signed int) numberOfColumns - 1;
82
83   for (unsigned int r=0; r < numberOfRows; ++r)
84     {
85     os << "[";
86     for ( signed int c=0; c < lastColumn; ++c)
87       {
88       os << arr(r,c) << ", ";
89       }
90     if (numberOfColumns >= 1)
91       {
92       os << arr(r,lastColumn);
93       }
94     os << "]" << std::endl;
95     }
96
97   return os;
98 }
99
100 // namespace itk
101
102
103 #ifndef ITK_MANUAL_INSTANTIATION
104 #include "itkArray2D.txx"
105 #endif
106
107
108 #endif
109

Generated by KWStyle 1.0b on Tuesday January,17 at 02:13:59PM
© Kitware Inc.