00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 namespace CIMPL
00060 {
00061
00062
00063
00064 template< class T >
00065 MatrixList<T>::MatrixList(void)
00066 {
00067 planes = 0;
00068 xDim = 0;
00069 yDim = 0;
00070 list = 0;
00071 }
00072
00073
00074 template< class T >
00075 MatrixList<T>::MatrixList(MatrixList<T>& ml)
00076 {
00077 planes = ml.planes;
00078 xDim = ml.xDim;
00079 yDim = ml.yDim;
00080 list = new (std::nothrow) Matrix<T>[ml.planes];
00081 Utility::CheckPointer(list);
00082 for(int i=0; i<planes; i++)
00083 {
00084 list[i] = ml.list[i];
00085 }
00086 }
00087
00088 template< class T >
00089 MatrixList<T>::MatrixList(Matrix<T>& m)
00090 {
00091 planes = 1;
00092 list = new (std::nothrow) Matrix<T>[1];
00093 Utility::CheckPointer(list);
00094 xDim = m.Columns();
00095 yDim = m.Rows();
00096 list[0] = m;
00097 }
00098
00099
00100 template< class T >
00101 MatrixList<T>::MatrixList(Matrix<T>& m1, Matrix<T>& m2, Matrix<T>& m3)
00102 {
00103 if(m1.Rows() != m2.Rows() || m1.Rows() != m3.Rows() || m2.Rows() != m3.Rows() || m1.Columns() != m2.Columns() || m1.Columns() != m3.Columns() || m2.Columns() != m3.Columns())
00104 {
00105 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00106 Utility::RunTimeError("Matrix dimensions does not match to each other!");
00107 }
00108 planes = 3;
00109 list = new (std::nothrow) Matrix<T>[3];
00110 Utility::CheckPointer(list);
00111 xDim = m1.Columns();
00112 yDim = m1.Rows();
00113 list[0] = m1;
00114 list[1] = m2;
00115 list[2] = m3;
00116 }
00117
00118
00119 template< class T >
00120 MatrixList<T>::MatrixList(int l, int rows, int cols)
00121 {
00122 planes = l;
00123 xDim = cols;
00124 yDim = rows;
00125
00126 list = new (std::nothrow) Matrix<T>[l];
00127 Utility::CheckPointer(list);
00128
00129 for(int i=0; i<l; i++)
00130 {
00131 list[i] = Matrix<T>(rows, cols);
00132 }
00133 }
00134
00135
00136 template< class T >
00137 MatrixList<T>::~MatrixList(void)
00138 {
00139 delete [] list;
00140 }
00141
00142
00143 template< class T >
00144 void MatrixList<T>::PushBack(Matrix<T>& m)
00145 {
00146 if(list ==0)
00147 {
00148 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00149 Utility::RunTimeError("MatrixList needs to be initialized first before appending new matrices!");
00150 }
00151 if(m.Rows() != yDim || m.Columns() != xDim)
00152 {
00153 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00154 Utility::RunTimeError("Matrix dimensions does not match to MatrixList!");
00155 }
00156
00157 Matrix<T> *temp = new (std::nothrow) Matrix<T>[planes+1];
00158 Utility::CheckPointer(temp);
00159 for(int i=0;i<planes;i++)
00160 {
00161 temp[i] = list[i];
00162 }
00163 temp[planes] = m;
00164 planes++;
00165 delete [] list;
00166 list = temp;
00167 }
00168
00169
00170 template< class T >
00171 void MatrixList<T>::PushFront(Matrix<T>& m)
00172 {
00173 if(list ==0)
00174 {
00175 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00176 Utility::RunTimeError("MatrixList needs to be initialized first before appending new matrices!");
00177 }
00178 if(m.Rows() != yDim || m.Columns() != xDim)
00179 {
00180 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00181 Utility::RunTimeError("Matrix dimensions does not match to MatrixList!");
00182 }
00183
00184 Matrix<T> *temp = new (std::nothrow) Matrix<T>[planes+1];
00185 Utility::CheckPointer(temp);
00186 for(int i=0;i<planes;i++)
00187 {
00188 temp[i+1] = list[i];
00189 }
00190 temp[0] = m;
00191 planes++;
00192 delete [] list;
00193 list = temp;
00194 }
00195
00196
00197
00198 template< class T >
00199 int MatrixList<T>::Planes() const
00200 {
00201 return planes;
00202 }
00203
00204 template< class T >
00205 int MatrixList<T>::Rows() const
00206 {
00207 return yDim;
00208 }
00209
00210 template< class T >
00211 int MatrixList<T>::Columns() const
00212 {
00213 return xDim;
00214 }
00215
00216
00217 template< class T >
00218 int MatrixList<T>::XDim() const
00219 {
00220 return xDim;
00221 }
00222
00223 template< class T >
00224 int MatrixList<T>::YDim() const
00225 {
00226 return yDim;
00227 }
00228
00229
00230 template< class T >
00231 MatrixList<T>& MatrixList<T>::operator= (MatrixList<T>& ml)
00232 {
00233 planes = ml.planes;
00234 xDim = ml.xDim;
00235 yDim = ml.yDim;
00236
00237 delete [] list;
00238 list = new (std::nothrow) Matrix<T>[ml.planes];
00239 Utility::CheckPointer(list);
00240 for(int i=0; i<planes; i++)
00241 {
00242 list[i] = ml.list[i];
00243 }
00244
00245 return *this;
00246 }
00247
00248
00249
00250 template< class T >
00251 Matrix<T>& MatrixList<T>::operator[] (const int i)
00252 {
00253 return list[i];
00254 }
00255
00256
00257
00258 template< class T >
00259 Matrix<T>& MatrixList<T>::operator() (const int i)
00260 {
00261 if(i<0 || i>=planes)
00262 {
00263 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00264 Utility::RunTimeError("Index outside bounds!");
00265 }
00266 return list[i];
00267 }
00268
00269
00270
00271
00272
00273
00274 };
00275
00276