bazar  1.3.1
growmat.cpp
Go to the documentation of this file.
1 #include "growmat.h"
2 
3 CvGrowMat::CvGrowMat(int maxlines, int maxcols, int type)
4 {
5  mat = cvCreateMat(maxlines, maxcols, type);
6  cvSetZero(mat);
7  cvGetSubRect(mat, this, cvRect(0,0,maxcols,maxlines));
8 }
9 
11 {
12  cvReleaseMat(&mat);
13 }
14 
15 void CvGrowMat::resize(int lines, int cols)
16 {
17  if (lines <= mat->rows && cols <= mat->cols) {
18  cvGetSubRect(mat, this, cvRect(0,0,cols,lines));
19  //this->rows = lines;
20  //this->cols = cols;
21  } else {
22  int nl = (lines > mat->rows ? lines*2 : mat->rows);
23  int nc = (cols > mat->cols ? cols*2 : mat->cols);
24  CvMat *nm = cvCreateMat(nl, nc, mat->type);
25  cvSetZero(nm);
26  if (this->rows && this->cols) {
27  CvMat sub;
28  cvGetSubRect(nm, &sub, cvRect(0,0,this->cols, this->rows));
29  cvCopy(this, &sub);
30  cvGetSubRect(nm, this, cvRect(0,0,cols, lines));
31  } else {
32  cvGetSubRect(nm, this, cvRect(0,0,mat->cols, mat->rows));
33  this->rows = lines;
34  this->cols = cols;
35  }
36  cvReleaseMat(&mat);
37  mat = nm;
38  }
39 }
40