00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _XVMATRIX_ICC_
00015 #define _XVMATRIX_ICC_
00016
00017
00018
00019
00020 inline
00021 RefCounter*
00022 XVMatrix::ref()
00023 {
00024 if (refPtr == NULL) {
00025 refPtr = new RefCounter;
00026 refPtr->data = data;
00027 refPtr->refCount = 0;
00028 }
00029 refPtr->refCount++;
00030 return refPtr;
00031 }
00032
00033 inline
00034 void
00035 XVMatrix::unref() {refPtr->refCount--;}
00036
00037 inline
00038 int
00039 XVMatrix::dataShared() {return ((refPtr!=NULL) && (refPtr->refCount > 0));};
00040
00041 inline
00042 XVMatrix::XVMatrix(XVMatrix &m, int startr, int startc, int nrows, int ncols)
00043 {
00044 if ( (startr<0) || (startc<0) )
00045 _panic("Illegal submatrix operation \n");
00046 if (((startr + nrows) > m.rowNum) || ((startc + ncols) > m.colNum))
00047 _panic ("Submatrix larger than matrix \n");
00048
00049 init(m,startr,startc,nrows,ncols);
00050 }
00051
00052 inline
00053 XVMatrix::XVMatrix()
00054 {
00055 init_empty();
00056 }
00057
00058 inline
00059 XVMatrix::XVMatrix(int rr,int cc)
00060 {
00061 init_empty();
00062 resize(rr, cc);
00063 }
00064
00065 inline
00066 int
00067 XVMatrix::n_of_rows() const { return rowNum; }
00068
00069 inline
00070 int
00071 XVMatrix::n_of_cols() const { return colNum; }
00072
00073
00074 #ifndef NO_BOUNDS_CHECK
00075 inline
00076 _rowvec
00077 XVMatrix::operator[](int n)
00078 {
00079 if((n<0) || (n >= rowNum)) {
00080 printf("n=%d, rowNum=%d\n", n, rowNum); fflush(stdout);
00081 _panic("Bounds error on first matrix subscript");
00082 }
00083 return _rowvec(rowPtrs[n],colNum);
00084 }
00085 #else
00086 inline
00087 FrReal*
00088 XVMatrix::operator[](int n) {return rowPtrs[n];}
00089 #endif
00090
00091 inline
00092 FrReal*
00093 XVMatrix::operator[](int n) const {return rowPtrs[n];}
00094
00095 #ifdef SUBSCRIPT_START_WITH_1
00096
00097 inline
00098 XVMatrix
00099 XVMatrix::operator()(int sr, int lr, int sc, int lc)
00100 {return XVMatrix(*this,sr-1,sc-1,lr-sr+1,lc-sc+1);}
00101
00102 inline
00103 XVMatrix
00104 XVMatrix::Rows(int first_row, int last_row)
00105 {return XVMatrix(*this, first_row-1, 0, last_row-first_row+1, colNum);}
00106
00107 inline
00108 XVMatrix
00109 XVMatrix::Columns(int first_col, int last_col)
00110 {return XVMatrix(*this, 0, first_col-1, rowNum, last_col-first_col+1);}
00111
00112 #else
00113
00114
00115 inline
00116 XVMatrix
00117 XVMatrix::operator()(int sr, int lr, int sc, int lc)
00118 {return XVMatrix(*this,sr,sc,lr-sr+1,lc-sc+1);}
00119
00120 inline
00121 XVMatrix
00122 XVMatrix::Rows(int first_row, int last_row)
00123 {return XVMatrix(*this, first_row, 0, last_row-first_row+1, colNum);}
00124
00125 inline
00126 XVMatrix
00127 XVMatrix::Columns(int first_col, int last_col)
00128 {return XVMatrix(*this, 0, first_col, rowNum, last_col-first_col+1);}
00129
00130 #endif // SUBSCRIPT_START_WITH_1
00131
00132
00133
00134
00135 inline
00136 XVRowVector::XVRowVector() : XVMatrix() {;}
00137
00138 inline
00139 XVRowVector::XVRowVector(int nn) : XVMatrix(1,nn){;}
00140
00141 inline
00142 void
00143 XVRowVector::resize(int i)
00144 {
00145 XVMatrix::resize(1, i);
00146 }
00147
00148 inline
00149 void
00150 XVColVector::resize(int i)
00151 {
00152 XVMatrix::resize(i, 1);
00153 }
00154
00155 inline
00156 FrReal&
00157 XVRowVector::operator [](int n)
00158 {
00159 #ifndef NO_BOUNDS_CHECK
00160 if ((n < 0) || (n >= colNum))
00161 _panic("XVRowVector::operator[]: index out of range");
00162 #endif
00163 return rowPtrs[0][n];
00164 }
00165
00166 inline
00167 const FrReal&
00168 XVRowVector::operator [](int n) const
00169 {
00170 #ifndef NO_BOUNDS_CHECK
00171 if ((n < 0) || (n >= colNum))
00172 _panic("XVRowVector:operator[]: index out of range");
00173 #endif
00174 return rowPtrs[0][n];
00175 }
00176
00177
00178
00179
00180
00181 inline
00182 XVColVector::XVColVector (XVColVector &m, int startr, int nrows)
00183 {
00184 if (startr<0)
00185 _panic("Illegal submatrix operation in Colvector\n");
00186 if ( (startr+nrows) > m.rowNum )
00187 _panic("Submatrix larger than matrix in Colvector\n");
00188 init(m, startr, 0, nrows, 1);
00189 }
00190
00191 inline
00192 XVColVector::XVColVector() : XVMatrix() {;}
00193
00194 inline
00195 XVColVector::XVColVector(int nn) : XVMatrix(nn,1) {;}
00196
00197 inline
00198 XVColVector::~XVColVector() {;}
00199
00200 inline
00201 FrReal&
00202 XVColVector::operator [](int n)
00203 {
00204 #ifndef NO_BOUNDS_CHECK
00205 if ((n < 0) || (n >= rowNum))
00206 _panic("XVColVector::operator[]: index out of range");
00207 #endif
00208 return rowPtrs[n][0];
00209 }
00210
00211 inline
00212 const FrReal&
00213 XVColVector::operator [](int n) const
00214 {
00215 #ifndef NO_BOUNDS_CHECK
00216 if ((n < 0) || (n >= rowNum))
00217 _panic("XVColVector::operator[]: index out of range");
00218 #endif
00219 return rowPtrs[n][0];
00220 }
00221
00222
00223 #ifdef SUBSCRIPT_START_WITH_1
00224
00225 inline
00226 XVColVector
00227 XVColVector::Rows(int first_row, int last_row)
00228 { return XVColVector(*this, first_row-1, last_row-first_row+1); }
00229
00230 #else
00231
00232 inline
00233 XVColVector
00234 XVColVector::Rows(int first_row, int last_row)
00235 { return XVColVector(*this, first_row, last_row-first_row+1); }
00236
00237 #endif
00238
00239
00240
00241
00242
00243 inline
00244 XVRowVector::XVRowVector (const XVRowVector &v) : XVMatrix(v) {};
00245
00246 inline
00247 XVColVector::XVColVector (const XVColVector &v) : XVMatrix(v) {};
00248
00249 inline
00250 XVRowVector::XVRowVector (XVMatrix &m, int i) :
00251 XVMatrix(m, i, 0, 1, m.colNum) {};
00252
00253 inline
00254 XVColVector::XVColVector (XVMatrix &m, int j) :
00255 XVMatrix(m, 0, j, m.rowNum, 1) {};
00256
00257 #ifdef SUBSCRIPT_START_WITH_1
00258
00259 inline XVRowVector XVMatrix::row(int i) { return XVRowVector(*this, i-1); }
00260 inline XVRowVector XVMatrix::Row(int i) { return XVRowVector(*this, i-1); }
00261 inline XVColVector XVMatrix::col(int j) { return XVColVector(*this, j-1); }
00262 inline XVColVector XVMatrix::Column(int j) { return XVColVector(*this, j-1); }
00263
00264 #else
00265
00266 inline XVRowVector XVMatrix::row(int i) { return XVRowVector(*this, i); }
00267 inline XVRowVector XVMatrix::Row(int i) { return XVRowVector(*this, i); }
00268 inline XVColVector XVMatrix::col(int j) { return XVColVector(*this, j); }
00269 inline XVColVector XVMatrix::Column(int j) { return XVColVector(*this, j); }
00270
00271 #endif // SUBSCRIPT_START_WITH_1
00272
00273
00274
00275
00276
00277
00278 inline
00279 XVDiagonalMatrix::XVDiagonalMatrix(int n) : t(n) {;}
00280
00281 inline
00282 XVDiagonalMatrix::XVDiagonalMatrix(const XVColVector &tin) : t(tin) {;}
00283
00284 inline
00285 int
00286 XVDiagonalMatrix::n_of_cols() const {return t.n_of_rows();}
00287
00288 inline
00289 int
00290 XVDiagonalMatrix::n_of_rows() const {return t.n_of_rows();}
00291
00292 inline
00293 XVColVector&
00294 XVDiagonalMatrix::diagonal() {return t;}
00295
00296 inline
00297 void
00298 XVDiagonalMatrix::resize(int n) {t.resize(n);}
00299
00300 inline
00301 FrReal&
00302 XVDiagonalMatrix::operator() (int n) {return t[n];}
00303
00304 inline
00305 FrReal
00306 XVDiagonalMatrix::operator() (int n) const {return t[n];}
00307
00308 inline
00309 XVDiagonalMatrix&
00310 XVDiagonalMatrix::operator = (const XVDiagonalMatrix &m) {t = m.t; return *this;}
00311
00312 inline
00313 XVDiagonalMatrix&
00314 XVDiagonalMatrix::operator = (FrReal x) {t = x; return *this;}
00315
00316
00317
00318
00319
00320
00321 #include <XVImageScalar.h>
00322
00323 template <class T>
00324 XVColVector&
00325 operator <<(XVColVector &t,const XVImageScalar<T> &x)
00326 {
00327 int i;
00328 const T *ptr = x.data();
00329
00330 t.resize(x.Width()*x.Height());
00331 for (i=0;i<t.n_of_rows();i++)
00332 t[i] = (FrReal)(*ptr++);
00333
00334 return t;
00335 }
00336
00337
00338 template <class T>
00339 XVRowVector&
00340 operator << (const XVRowVector &t,XVImageScalar<T> &x)
00341 {
00342 int i;
00343 const T *ptr = x.data();
00344
00345 t.resize(x.Width()*x.Height());
00346 for (i=0;i<t.n_of_cols();i++)
00347 t[i] = (FrReal)(*ptr++);
00348
00349 return t;
00350 }
00351
00352
00353
00354
00355
00356 template <class T>
00357 XVImageScalar<T>&
00358 operator >>(const XVColVector &t, XVImageScalar<T> &x)
00359 {
00360 int i,j,k;
00361
00362 if (x.Width()*x.Height() != t.n_of_rows())
00363 _panic("Image/matrix injection size mismatch");
00364
00365 k=0;
00366 for (i=0;i<x.Height();i++)
00367 for (j=0;j<x.Width();j++)
00368 x[i][j] = T(t[k++]);
00369
00370 return x;
00371 }
00372
00373 template <class T>
00374 XVImageScalar<T>&
00375 operator >>(const XVRowVector &t, XVImageScalar<T> &x)
00376 {
00377 int i,j,k;
00378
00379 if (x.Width()*x.Height() != t.n_of_cols())
00380 _panic("Image/matrix injection size mismatch");
00381
00382 k=0;
00383 for (i=0;i<x.Height();i++)
00384 for (j=0;j<x.Width();j++)
00385 x[i][j] = T(t[k++]);
00386
00387 return x;
00388 }
00389
00390 template <class T>
00391 XVMatrix add_column(XVMatrix &x, XVImageScalar<T> &I)
00392 {
00393 XVColVector temp;
00394 temp << I;
00395 return add_column(x,temp);
00396 }
00397
00398 #endif
00399
00400
00401
00402