ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkArray2D.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkArray2D_h
19 #define __itkArray2D_h
20 
21 #include "itkMacro.h"
22 #include "vnl/vnl_matrix.h"
23 
24 namespace itk
25 {
43 template< typename TValueType >
44 class Array2D:public vnl_matrix< TValueType >
45 {
46 public:
47 
49  typedef TValueType ValueType;
50  typedef Array2D Self;
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 
62  const Self & operator=(const VnlMatrixType & matrix);
63 
64  void Fill(TValueType const & v) { this->fill(v); }
65 
67  void SetSize(unsigned int m, unsigned int n);
68 
71  ~Array2D() {}
72 };
73 
74 template< typename TValueType >
75 std::ostream & operator<<(std::ostream & os, const Array2D< TValueType > & arr)
76 {
77  const unsigned int numberOfColumns = arr.cols();
78  const unsigned int numberOfRows = arr.rows();
79  const signed int lastColumn = (signed int)numberOfColumns - 1;
80 
81  for ( unsigned int r = 0; r < numberOfRows; ++r )
82  {
83  os << "[";
84  for ( signed int c = 0; c < lastColumn; ++c )
85  {
86  os << arr(r, c) << ", ";
87  }
88  if ( numberOfColumns >= 1 )
89  {
90  os << arr(r, lastColumn);
91  }
92  os << "]" << std::endl;
93  }
94 
95  return os;
96 }
97 } // namespace itk
98 
99 #ifndef ITK_MANUAL_INSTANTIATION
100 #include "itkArray2D.hxx"
101 #endif
102 
103 #endif
104