bool PARDISOSolver< valueType, zeroBased >::analyzePattern( int m, int n, int* rowIndex, int* columns, int nNonZeroes ) { int structureOptions = MKL_DSS_SYMMETRIC; int retval = dss_define_structure( m_handle, structureOptions, rowIndex, m, n, columns, nNonZeroes ); bool succeeded = ( retval == MKL_DSS_SUCCESS ); assert( succeeded ); if( succeeded ) { m_nRowsA = m; m_nColsA = n; int reorderOptions = MKL_DSS_AUTO_ORDER; retval = dss_reorder( m_handle, reorderOptions, NULL ); succeeded = ( retval == MKL_DSS_SUCCESS ); assert( succeeded ); } return succeeded; }
void CPoissonExt::poissonExtend(cv::Mat &dst,int size) { cv::Mat gx=Mat::zeros(h+2*ex,w+2*ex,CV_32FC4); cv::Mat gy=Mat::zeros(h+2*ex,w+2*ex,CV_32FC4); #pragma omp parallel for for(int y=0;y<h+ex*2;y++) for (int x=0;x<w+ex*2;x++) { if(type[y*(w+2*ex)+x]>1) { Vec4f BGRA0; Vec4f BGRA1; BGRA1=dst.at<Vec4b>(y,x); if(x>0) { if(type[y*(w+2*ex)+x-1]>1) { BGRA0=dst.at<Vec4b>(y,x-1); if(BGRA0!=Vec4f(255,0,255,0)&&BGRA1!=Vec4f(255,0,255,0)) gx.at<Vec4f>(y,x)=BGRA1-BGRA0; } } if(y>0) { if(type[(y-1)*(w+2*ex)+x]>1) { BGRA0=dst.at<Vec4b>(y-1,x); if(BGRA0!=Vec4f(255,0,255,0)&&BGRA1!=Vec4f(255,0,255,0)) gy.at<Vec4f>(y,x)=BGRA1-BGRA0; } } } } //matrix float *A=new float[5*size]; _INTEGER_t *columns=new _INTEGER_t[5*size]; _INTEGER_t *rowindex=new _INTEGER_t[size+1]; float *B0=new float[size]; float *B1=new float[size]; float *B2=new float[size]; float *B3=new float[size]; float *X0=new float[size]; float *X1=new float[size]; float *X2=new float[size]; //float *X3=new float[size]; _INTEGER_t nNonZeros=0; memset(A,0,5*size*sizeof(float)); memset(columns,0,5*size*sizeof(int)); memset(rowindex,0,(size+1)*sizeof(int)); memset(B0,0,size*sizeof(float)); memset(B1,0,size*sizeof(float)); memset(B2,0,size*sizeof(float)); memset(B3,0,size*sizeof(float)); memset(X0,0,size*sizeof(float)); memset(X1,0,size*sizeof(float)); memset(X2,0,size*sizeof(float)); //memset(X3,0,size*sizeof(float)); Vec4f BGRA; for(int y=0;y<h+ex*2;y++) for (int x=0;x<w+ex*2;x++) { float a[5]; a[0]=a[1]=a[2]=a[3]=a[4]=0.0f; int ii=y*(w+2*ex)+x; switch(type[ii]) { case 0://inside break; case 1://boundary a[2]+=1.0f; BGRA=dst.at<Vec4b>(y,x); B0[index[ii]]+=BGRA[0]; B1[index[ii]]+=BGRA[1]; B2[index[ii]]+=BGRA[2]; //B3[index[ii]]+=BGRA[3]; case 2://outside if(y-1>=0&&type[ii-(w+2*ex)]>0) { a[2]+=1.0f; a[0]-=1.0f; BGRA=gy.at<Vec4f>(y,x); B0[index[ii]]+=BGRA[0]; B1[index[ii]]+=BGRA[1]; B2[index[ii]]+=BGRA[2]; //B3[index[ii]]+=BGRA[3]; } if(x-1>=0&&type[ii-1]>0) { a[2]+=1.0f; a[1]-=1.0f; BGRA=gx.at<Vec4f>(y,x); B0[index[ii]]+=BGRA[0]; B1[index[ii]]+=BGRA[1]; B2[index[ii]]+=BGRA[2]; //B3[index[ii]]+=BGRA[3]; } if(x+1<w+2*ex&&type[ii+1]>0) { a[2]+=1.0f; a[3]-=1.0f; BGRA=gx.at<Vec4f>(y,x+1); B0[index[ii]]-=BGRA[0]; B1[index[ii]]-=BGRA[1]; B2[index[ii]]-=BGRA[2]; //B3[index[ii]]-=BGRA[3]; } if(y+1<h+2*ex&&type[ii+(w+2*ex)]>0) { a[2]+=1.0f; a[4]-=1.0f; BGRA=gy.at<Vec4f>(y+1,x); B0[index[ii]]-=BGRA[0]; B1[index[ii]]-=BGRA[1]; B2[index[ii]]-=BGRA[2]; //B3[index[ii]]-=BGRA[3]; } //put into A if(a[0]!=0) { A[nNonZeros]=a[0]; columns[nNonZeros]=index[ii-(w+2*ex)]; nNonZeros++; } if(a[1]!=0) { A[nNonZeros]=a[1]; columns[nNonZeros]=index[ii-1]; nNonZeros++; } if(a[2]!=0) { A[nNonZeros]=a[2]; columns[nNonZeros]=index[ii]; nNonZeros++; } if(a[3]!=0) { A[nNonZeros]=a[3]; columns[nNonZeros]=index[ii+1]; nNonZeros++; } if(a[4]!=0) { A[nNonZeros]=a[4]; columns[nNonZeros]=index[ii+(w+2*ex)]; nNonZeros++; } rowindex[index[ii]+1]=nNonZeros; break; } } //SOLVER _INTEGER_t error; _MKL_DSS_HANDLE_t solver; _INTEGER_t opt=MKL_DSS_MSG_LVL_WARNING + MKL_DSS_TERM_LVL_ERROR + MKL_DSS_SINGLE_PRECISION + MKL_DSS_ZERO_BASED_INDEXING; _INTEGER_t sym=MKL_DSS_NON_SYMMETRIC; _INTEGER_t typ=MKL_DSS_POSITIVE_DEFINITE; _INTEGER_t ord=MKL_DSS_AUTO_ORDER; _INTEGER_t sov=MKL_DSS_DEFAULTS; _INTEGER_t nRhs = 1; _INTEGER_t size_l=size; error= dss_create(solver, opt); error = dss_define_structure(solver,sym, rowindex, size_l, size_l,columns, nNonZeros); error = dss_reorder( solver,ord, 0); error = dss_factor_real( solver, typ, A ); error = dss_solve_real( solver, sov, B0, nRhs, X0 ); error = dss_solve_real( solver, sov, B1, nRhs, X1 ); error = dss_solve_real( solver, sov, B2, nRhs, X2 ); //error = dss_solve_real( solver, sov, B3, nRhs, X3 ); error = dss_delete( solver, opt ); //paste #pragma omp parallel for for(int y=0;y<h+ex*2;y++) for (int x=0;x<w+ex*2;x++) { int ii=y*(w+2*ex)+x; if(type[ii]>0) { int B=MIN(MAX(X0[index[ii]],0),255); int G=MIN(MAX(X1[index[ii]],0),255); int R=MIN(MAX(X2[index[ii]],0),255); int A=0; dst.at<Vec4b>(y,x)=Vec4b(B,G,R,A); } } delete[] A; delete[] B0; delete[] B1; delete[] B2; delete[] B3; delete[] X0; delete[] X1; delete[] X2; //delete[] X3; delete[] columns; delete[] rowindex; }