ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
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 __itkArray2D_h 00019 #define __itkArray2D_h 00020 00021 #include "itkMacro.h" 00022 #include "vnl/vnl_matrix.h" 00023 00024 namespace itk 00025 { 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 public: 00053 00054 Array2D(); 00055 Array2D(unsigned int rows, unsigned int cols); 00056 Array2D(const Self & array); 00057 Array2D(const VnlMatrixType & matrix); 00058 00059 const Self & operator=(const Self & array); 00060 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 template< typename TValueType > 00074 std::ostream & operator<<(std::ostream & os, const Array2D< TValueType > & arr) 00075 { 00076 const unsigned int numberOfColumns = arr.cols(); 00077 const unsigned int numberOfRows = arr.rows(); 00078 const signed int lastColumn = (signed int)numberOfColumns - 1; 00079 00080 for ( unsigned int r = 0; r < numberOfRows; ++r ) 00081 { 00082 os << "["; 00083 for ( signed int c = 0; c < lastColumn; ++c ) 00084 { 00085 os << arr(r, c) << ", "; 00086 } 00087 if ( numberOfColumns >= 1 ) 00088 { 00089 os << arr(r, lastColumn); 00090 } 00091 os << "]" << std::endl; 00092 } 00093 00094 return os; 00095 } 00096 } // namespace itk 00097 00098 // Define instantiation macro for this template. 00099 #define ITK_TEMPLATE_Array2D(_, EXPORT, TypeX, TypeY) \ 00100 namespace itk \ 00101 { \ 00102 _( 1 ( class EXPORT Array2D< ITK_TEMPLATE_1 TypeX > ) ) \ 00103 _( 1 ( EXPORT std::ostream & operator<<(std::ostream &, \ 00104 const Array2D< ITK_TEMPLATE_1 TypeX > &) ) ) \ 00105 namespace Templates \ 00106 { \ 00107 typedef Array2D< ITK_TEMPLATE_1 TypeX > Array2D##TypeY; \ 00108 } \ 00109 } 00110 00111 #if ITK_TEMPLATE_EXPLICIT 00112 #include "Templates/itkArray2D+-.h" 00113 #endif 00114 00115 #if ITK_TEMPLATE_TXX 00116 #include "itkArray2D.hxx" 00117 #endif 00118 00119 #endif 00120