Beispiel #1
0
mesh::mesh(long vertCnt, long faceCnt)
{
	/* data */
	update(matrixAlloc(vertCnt, 3), new face[faceCnt], vertCnt, faceCnt, false, true);
	mBox = matrixAlloc(8, 3);
	mBoxEx = matrixAlloc(8, 3);
	mAttrib = matrixAlloc(4, 4);
	mPartSys.mFreq = 0;
	mPartSys.mBucket = 0;
	mTreeNode = NULL;
	mName = NULL;
	mTag = NULL;

	/* attributes */
	mRadius = 0;
	setParams(0x808080, 0xC0C0C0, 0xFFFFFF, 0x0, 64);
	mMapDir = 0;
	mSkyBox = false;
	mVisible = true;
	mInFrust = false;
	mNext = NULL;

	/* default */
	setColor(0xFFFFFF);
}
Beispiel #2
0
Matrix *matrixMul (const Matrix *a, const Matrix *b)
{
  int column = 0, row = 0, c = 0;
  Matrix *retval;

  if (a->columns != b->rows && a->rows > b->rows)
    {
      const Matrix *tmp;
      tmp = a;
      a = b;
      b = tmp;
    }

  if (a->columns != b->rows)
    return NULL;

  retval = matrixAlloc (a->rows , b->columns);

  for (; column < b->columns; column++)
    {
      for (row = 0; row < a->rows; row++)
        {
          double val = 0;
          for (c = 0; c < a->columns; c++)
            {
              val += matrixGet (a, row, c) * matrixGet (b, c, column);
            }

          matrixSet (retval, row, column, val);
        }
    }
  return retval;
}
Beispiel #3
0
Mat matrixAllocMul(Mat a, Mat b) {
	Mat dest;

	dest = matrixAlloc(a.row, b.clm);
	matrixMul(dest, a, b);
	return dest;
}
Beispiel #4
0
Mat matrixAllocDup(Mat source) {
	Mat dest;

	dest = matrixAlloc(source.row, source.clm);
	matrixDup(dest, source);
	return dest;
}
Beispiel #5
0
Matrix *matrixAdd (const Matrix *a, const Matrix *b)
{
  Matrix *result;
  int column = a->columns, row = a->rows;

  if (a->columns != b->columns && a->rows != b->rows)
    return NULL;

  result = matrixAlloc (a->rows, a->columns);

  /* cycle through all rows */
  for (row = 0 ; row < a->rows ; row++)
    {
      /* cycle through all columns */
      for (column = 0 ; column < a->columns ; column++)
        {
          int val_1 = matrixGet (a, row, column);
          int val_2 = matrixGet (b, row, column);
          int val_res = val_1 / val_2;

          matrixSet (result, row, column, val_res);
        }
    }

  return result;
}
Beispiel #6
0
object::object()
{
	/* data */
	mTrans = matrixAlloc();
	mOrigin = new float[3];
	mOriginEx = new float[3];
	mAngle = new float[3];
	mScale = new float[3];
	matrixIdent(mTrans);
	vectorNull(mOrigin);
	vectorNull(mAngle);
	vectorUnit(mScale);

	/* physics */
	mPosVel = new float[3];
	mAngVel = new float[3];
	vectorNull(mPosVel);
	vectorNull(mAngVel);
	mPosAcc = new float[3];
	mAngAcc = new float[3];
	vectorNull(mPosAcc);
	vectorNull(mAngAcc);
	mMovSpdMax = BIG_NUMBER;
	mRotSpdMax = BIG_NUMBER;
	mStyle = 0;
	mCollide = true;
	mTicks = -1;
	mTarget = NULL;

	/* attributes */
	mParent = NULL;
	mChanged = true;
}
Beispiel #7
0
void object::applyTrans(float **result, float **vertex, long vertCnt, bool doProj, float **proj)
{
	long i;
	float **matrixA;
	float *tempA;

	if (doProj)
	{
		matrixA = matrixAlloc();
		tempA = new float[4];
		matrixMult(matrixA, mTrans, proj);
		for (i = 0; i < vertCnt; i++)
		{
			vectorMatrixMultEx(tempA, vertex[i], matrixA);
			result[i][0] = tempA[0] / tempA[3];
			result[i][1] = tempA[1] / tempA[3];
			result[i][2] = tempA[2] / tempA[3];
		}
		matrixFree(matrixA);
		delete []tempA;
	}
	else
		for (i = 0; i < vertCnt; i++)
			vectorMatrixMult(result[i], vertex[i], mTrans);
}
Beispiel #8
0
Mat matrixAllocTrans(Mat source) {
	Mat dest;

	dest = matrixAlloc(source.clm, source.row);
	matrixTrans(dest, source);
	return dest;
}
Beispiel #9
0
int main(int argc, char const *argv[]) {
  unsigned D;             // Numero de paginas. (Dimensão da matriz)
  double dampingFactor;   // Fator de Damping
  double **matriz = NULL; // Matriz a ser alocada.
  double **saida = NULL;  // Matriz de saida.
  unsigned i, j;          // Posições onde a matriz sera setada para 1

  scanf("%u %lf", &D, &dampingFactor);
  matrixAlloc(&matriz, D, D);

  while (scanf("%u %u", &i, &j) == 2) {
    matriz[i][j] = 1;
  }

  stochasticMatrix(matriz, D, D);
  dampMatrix(matriz, dampingFactor, D, D);

  copyMatrix(&saida, matriz, D, D);
  expontiationUntilConverge(&saida, matriz, D, 0);
  printIndexedVector(saida[0], D);

  matrixFree(saida, D);
  matrixFree(matriz, D);

  return 0;
}
Beispiel #10
0
Mat matrixAllocUnit(int dim) {
	Mat m;

	m = matrixAlloc(dim, dim);
	matrixUnit(m);
	return m;
}
Beispiel #11
0
Mat matrixAllocInv(Mat source) {
	Mat dest;

	dest = matrixAlloc(source.row, source.row);
	if(matrixInv(dest, source)) {
		dest.row = dest.clm = 0;
	}
	return dest;
}
Beispiel #12
0
/**
 * @brief
 *
 * @param
 *
 * @return
 */
screen
minitscr(FILE * stream, size_t x, size_t y, int mode)
{
    screen scr = malloc(sizeof(screen_t));
    if (scr != NULL){
        scr->stream = stream;
        scr->buffer = matrixAlloc(x, y);
        scr->x = x;
        scr->y = y;
        scr->mode = mode;
    }
    return scr;
}
Beispiel #13
0
/**
 * Calcula a diferença entre duas matrizes.
 * @param M          [description]
 * @param N          [description]
 * @param difference [description]
 * @param lines      [description]
 * @param columms    [description]
 */
void matrixDifference(double **M, double **N, double ***difference,
                      unsigned lines, unsigned columms) {
  unsigned i, j;
  double **D;
  matrixAlloc(&D, lines, columms);

  for (i = 0; i < lines; i++) {
    for (j = 0; j < columms; j++) {
      D[i][j] = M[i][j] - N[i][j];
    }
  }

  *difference = D;
}
Beispiel #14
0
//ハミング窓を作って返す
//大きさは FFT_SIZE * FFT_SIZE
Mat createWindowFunction(void)
{
  Mat ret = matrixAlloc( FFT_SIZE, FFT_SIZE);
  for(int h = 0; h < FFT_SIZE; ++h)
    {
      for(int w = 0 ; w < FFT_SIZE; ++w)
	{
	  double wh = 0.5 - 0.5*cos( (double)h * M_PI * 2.0 / (double)FFT_SIZE);
	  double ww = 0.5 - 0.5*cos( (double)w * M_PI * 2.0 / (double)FFT_SIZE);
	  ELEM0(ret, h, w) = wh * ww;
	}
    }
  return ret;
}
Beispiel #15
0
static int PCA( Mat input, Mat output, Vec ev )
{
    Mat     u;
    double  *m1, *m2;
    int     row, clm, min;
    int     i, j;

    row = input.row;
    clm = input.clm;
    min = (clm < row)? clm: row;
    if( row < 2 || clm < 2 )      return(-1);
    if( output.clm != input.clm ) return(-1);
    if( output.row != min )       return(-1);
    if( ev.clm != min )           return(-1);

    u = matrixAlloc( min, min );
    if( u.row != min || u.clm != min ) return(-1);
    if( row < clm ) {
        if( x_by_xt( input, u ) < 0 ) { matrixFree(u); return(-1); }
    }
    else {
        if( xt_by_x( input, u ) < 0 ) { matrixFree(u); return(-1); }
    }

    if( QRM( u, ev ) < 0 ) { matrixFree(u); return(-1); }

    if( row < clm ) {
        if( EV_create( input, u, output, ev ) < 0 ) {
            matrixFree(u);
            return(-1);
        }
    }
    else{
        m1 = u.m;
        m2 = output.m;
	for( i = 0; i < min; i++){
	    if( ev.v[i] < VZERO ) break;
            for( j = 0; j < min; j++ ) *(m2++) = *(m1++);
        }
	for( ; i < min; i++){
            ev.v[i] = 0.0;
            for( j = 0; j < min; j++ ) *(m2++) = 0.0;
        }
    }

    matrixFree(u);

    return( 0 );
}
Beispiel #16
0
/**
 * Exponecia a matriz até a norma da matriz ^ m ser semelhante à norma
 * da matriz ^ n, determinado por um valor de convergência.
 * @param matrixExp  [description]
 * @param matrixBase [description]
 * @param size       [description]
 * @param iteration  [description]
 */
void expontiationUntilConverge(double ***matrixExp, double **matrixBase,
                               unsigned size, unsigned iteration) {
  double **matrixExpPlusOne = NULL;
  matrixAlloc(&matrixExpPlusOne, size, size);

  squareMatrixMultiplication(*matrixExp, matrixBase, matrixExpPlusOne, size);

  if (!matrixHasConverged(matrixExpPlusOne, *matrixExp, size) &&
      iteration <= maximumExponent) {
    expontiationUntilConverge(&matrixExpPlusOne, matrixBase, size, ++iteration);
  }

  matrixFree(*matrixExp, size);
  *matrixExp = matrixExpPlusOne;
}
Beispiel #17
0
/**
 * @brief
 *
 * @param
 *
 * @return
 */
layer
newLayer(size_t x, size_t y, int x_offset, int y_offset)
{
    layer result = malloc(sizeof(layer_t));
    if (result != NULL){
        result->matrix = matrixAlloc(x, y);
        result->y = y;
        result->x = x;
        result->x_offset = x_offset;
        result->y_offset = y_offset;
        result->mode = LYR_NORMAL;
        result->name = NULL;
    }
    return result;
}
Beispiel #18
0
/**
 * Faz uma cópia de uma matriz para uma segunda matriz.
 * @param output  Ponteiro para a matriz que vai receber a cópia.
 * @param input   Ponteiro para a matriz que vai ser copiada.
 * @param lines   Linhas da matriz principal.
 * @param columms Colunas da matriz principal.
 */
void copyMatrix(double ***output, double **input, unsigned lines,
                unsigned columms) {
  unsigned i, j;
  double **newPointer;
  if (*output != NULL)
    matrixFree(*output, lines);

  matrixAlloc(&newPointer, lines, columms);
  for (i = 0; i < lines; i++) {
    for (j = 0; j < columms; j++) {
      newPointer[i][j] = input[i][j];
    }
  }

  *output = newPointer;
}
Beispiel #19
0
Matrix *matrixCopy (const Matrix *matrix)
{
  Matrix *retval;
  int column = matrix->columns, row = matrix->rows;

  retval = matrixAlloc (matrix->rows, matrix->columns);

  while (--row >=0)
    {
      column = matrix->columns;
      while (--column >= 0)
        matrixSet (retval, row, column,
                   matrixGet (matrix, row, column));
    }

  return retval;
}
Beispiel #20
0
/**
 * @brief
 *
 * @param
 *
 * @return
 */
layer
resizeLayer(layer l, size_t x, size_t y)
{
    int itr_y;
    char ** m = matrixAlloc(x, y);
    if (m != NULL && l != NULL){
        for (itr_y = 0; itr_y < MIN(l->y, y); itr_y++){
            memcpy(m[itr_y], l->matrix[itr_y], MIN(l->x, x));
        }
        freeMatrix(l->matrix, l->y);
        l->matrix = m;
        l->y = y;
        l->x = x;
    }
    return l;

}
Beispiel #21
0
Mat matrixAllocLoad(char *fname) {
	int row, clm;
	Mat m;
	FILE *fp;

	m.row = m.clm = 0;  /* m is ERR_MAT */
	fp = fopen(fname, "r");
	if(fp == NULL) {
		return m;
	}
	fread(&row, sizeof(int), 1, fp);
	fread(&clm, sizeof(int), 1, fp);
	m = matrixAlloc(row, clm);
	fread(m.m, sizeof(double), row * clm, fp);
	fclose(fp);

	return m;
}
Beispiel #22
0
IMG* deblur(const IMG* src, 
	    const IMG* psfBase,
	    const IMG* disparityMap,
	    double param[])
{
  int h,w;
  int maxDisparity = MAX_DISPARITY;
  int BlockRows = ceil( (double)src->height / (double)BLOCK_SIZE );
  int BlockCols = ceil( (double)src->width / (double)BLOCK_SIZE );

  
  //psf
  Complex psf[MAX_PSF_SIZE][CUT_OFF_SIZE][CUT_OFF_SIZE];
  createPSF(psf, psfBase, 1, MAX_PSF_SIZE-1);

  //窓関数
  Mat window = createWindowFunction();
  
  //最終的な結果を保存しておく場所
  Mat dstMat = matrixAlloc( src->height, src->width);
  Mat wegithMat = matrixAlloc( src->height, src->width);

  //0で初期化
  for( h = 0; h < dstMat.row; ++h){
    for( w = 0; w < dstMat.clm; ++w){
      ELEM0(dstMat, h, w) = 0.0;
      ELEM0(wegithMat, h, w) = 0.0;
    }
  }


  //作業用領域
  double srcIn[CUT_OFF_SIZE][CUT_OFF_SIZE];
  double dstIn[CUT_OFF_SIZE][CUT_OFF_SIZE];
  
  Complex srcF[CUT_OFF_SIZE][CUT_OFF_SIZE];
  Complex dstF[CUT_OFF_SIZE][CUT_OFF_SIZE];


  
  for(int row = 0; row < BlockRows; ++row){
    for(int col = 0 ; col < BlockCols; ++col){

      //copy & window function
      for( h = 0; h < CUT_OFF_SIZE; ++h){
	for( w = 0; w < CUT_OFF_SIZE; ++w){
	  srcIn[h][w] = 0.0;
	  
	  int y = h + row * BLOCK_SIZE + ( BLOCK_SIZE - CUT_OFF_SIZE ) / 2;
	  int x = w + col * BLOCK_SIZE + ( BLOCK_SIZE - CUT_OFF_SIZE ) / 2;

	  if( y < 0 || y >= src->height || w < 0 || w >= src->width){
	    continue;
	  }else{
	    srcIn[h][w] = (double)IMG_ELEM(src, y, x) * ELEM0(window, h, w);
	  }
	}
      }
      //copy done

      //kernel sizeの決定
      int disparity = (int)IMG_ELEM(disparityMap, row*BLOCK_SIZE + BLOCK_SIZE/2, col*BLOCK_SIZE + BLOCK_SIZE/2);
      int kernelSize =  param[0]*(double)disparity + param[1] ;
      
      //printf("disprity = %d, kernelSize = %d\n",disparity, kernelSize);

      //srcをDFT
      fourier(srcF, srcIn);

      //wiener deconvolution
      wienerdeconvolution(srcF, psf[kernelSize], dstF, SNR);

      //IDFT
      inverseFourier(dstIn, dstF);
      
      //copy to dstMat
      for(h=0;h<CUT_OFF_SIZE;++h){
	for(w=0;w<CUT_OFF_SIZE;++w){
	  int y = h + row * BLOCK_SIZE + (BLOCK_SIZE-CUT_OFF_SIZE)/2;
	  int x = w + col * BLOCK_SIZE + (BLOCK_SIZE-CUT_OFF_SIZE)/2;

	  if( y < 0 || y >= src->height || x < 0 || x >= src->width){
	    continue;
	  }else{
	    ELEM0(dstMat, y, x) += dstIn[h][w];
	    ELEM0(wegithMat, y, x) += ELEM0(window, h, w);
	  }

	}//w
      }//h
      


    }//col
  }//row

  printPassedTime();


  //最終的に返す構造体
  IMG* dst = createImage( src->height, src->width);

  //weright mean
  for(h=0;h<dstMat.row;++h){
    for(w=0;w<dstMat.clm;++w){
      ELEM0(dstMat, h, w) /= ELEM0(wegithMat, h, w);
    }
  }

  for( h = 0 ; h < dst->height ; ++h ){
    for( w = 0 ; w < dst->width ; ++w ){
      IMG_ELEM( dst, h, w) = fabs( ELEM0( dstMat, h, w) ) / 3.0;
    }
  }


  //後片付け
  matrixFree(dstMat);
  matrixFree(wegithMat);
  matrixFree(window);

  return dst;
}