Beispiel #1
0
	depth_render_texture2d::depth_render_texture2d(device* _dev, uvec2 size, pixel_format df)
		: texture2d(_dev, CD3D11_TEXTURE2D_DESC((DXGI_FORMAT)detail::get_texture_format_for_depth(df)/*DXGI_FORMAT_R24G8_TYPELESS*/, size.x, size.y, 1, 1, 
			D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE)), _vp(size)
	{
		CD3D11_DEPTH_STENCIL_VIEW_DESC dsvd(texd.Get(), D3D11_DSV_DIMENSION_TEXTURE2D, (DXGI_FORMAT)df /*DXGI_FORMAT_D24_UNORM_S8_UINT*/);
		chr(_dev->ddevice()->CreateDepthStencilView(texd.Get(), &dsvd, dsv.GetAddressOf()));
	}
Beispiel #2
0
	render_textureCube::render_textureCube(device* _dev, uint size, pixel_format f, pixel_format df)
		: _vp(vec2(size)), textureCube(_dev, CD3D11_TEXTURE2D_DESC((DXGI_FORMAT)f, size, size, 6, 1,
		D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
	{
		//create shared dsv
		CD3D11_TEXTURE2D_DESC dd(
			(DXGI_FORMAT)detail::get_texture_format_for_depth(df)/*DXGI_FORMAT_R24G8_TYPELESS*/, size, size);
		dd.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
		ComPtr<ID3D11Texture2D> dst;
		chr(_dev->ddevice()->CreateTexture2D(&dd, nullptr, &dst));
		CD3D11_DEPTH_STENCIL_VIEW_DESC dsvd(dst.Get(), D3D11_DSV_DIMENSION_TEXTURE2D, (DXGI_FORMAT)df);
		chr(_dev->ddevice()->CreateDepthStencilView(dst.Get(), &dsvd, dsv.GetAddressOf()));

		//create each face's resources
		CD3D11_RENDER_TARGET_VIEW_DESC rtvd(D3D11_RTV_DIMENSION_TEXTURE2DARRAY,
			(DXGI_FORMAT)f);
		rtvd.Texture2DArray.ArraySize = 1;
		rtvd.Texture2DArray.MipSlice = 0;
		for (int i = 0; i < 6; ++i)
		{
			rtx[i] = nullptr; 
			rtvd.Texture2DArray.FirstArraySlice = i;
			chr(_dev->ddevice()->CreateRenderTargetView(texd.Get(), &rtvd, &rtv[i]));
		}
	}
Beispiel #3
0
main()
{

 int i, j, k;
 FILE *f;


 double *X;
 X = (double*)malloc(isnp*ndof*sizeof(double));

 printf("reading input file \n");
 
 f = fopen("snapshot_u1", "r");
 k = -1;
 for (j=0; j<isnp; j++)
 {
  for (i=0; i<ndof; i++)
  {
   k++;
   fscanf(f,"%lf \n",&X[k]);
  }
 }
 fclose(f); 

 printf("finished reading input file \n");


 double **A;
 int row;

 // allocate an "array of arrays" of int
 A = (double**)malloc( ndof* sizeof(double*) ) ;
  
  for(row = 0; row < ndof; row++ )
  {
    A[row] = (double*)malloc( isnp*sizeof(double) ) ;
  }
 

 
 
 k = -1;
 for (i=0; i<ndof; i++)
 {
  for (j=0; j<isnp; j++)
  {
   k++;
   A[i][j] = X[k];
  }
 }

 free(X);

 
 double *w;
 w = (double*)malloc( isnp* sizeof(double*) ) ; 

 double **v;
 v = (double**)malloc( isnp* sizeof(double*) ) ;

  for(row = 0; row < isnp; row++ )
  {
    v[row] = (double*)malloc( isnp*sizeof(double) ) ;
  }
 

 dsvd(A,ndof,isnp,w,v);
  
 printf("done with svd \n");


 
 f = fopen ("w.dat", "w+");
 for (i=0; i<isnp; i++)
 {
  fprintf(f, "%d %f\n", i,w[i]);
 }
 fclose(f);

//--------------------------------
// check for orthonormality

 double **AT;
 
 // allocate an "array of arrays" of int
 AT = (double**)malloc( isnp* sizeof(double*) ) ;
  
  for(row = 0; row < isnp; row++ )
  {
    AT[row] = (double*)malloc( ndof*sizeof(double) ) ;
  }


 for (i=0; i<ndof; i++)
 {
  for (j=0; j<isnp; j++)
  {
   AT[j][i] = A[i][j];
  }
 }

 
 double **Iden;
 
 // allocate an "array of arrays" of int
 Iden = (double**)malloc( isnp* sizeof(double*) ) ;
  
  for(row = 0; row < isnp; row++ )
  {
    Iden[row] = (double*)malloc( isnp*sizeof(double) ) ;
  }



 matrix_mult(isnp,ndof,isnp,AT,A,Iden);


 printf("Identity matrix? \n");

 double s1 = 0.0;
 double s2 = 0.0; 

 for (i=0; i<isnp; i++)
 {
  for (j=0; j<isnp; j++)
  {
   if(i == j) s1 += Iden[i][j];
   else s2 += Iden[i][j];
  }
 }

 s1 /= (double)(isnp);
 s2 /= (double)(isnp*(isnp-1));

 printf("sum of diagonals = %f \n", s1);
 printf("sum of off-diagonals = %f \n", s2);
//------------------------------------



}
Beispiel #4
0
/**
   Compute Von Karman covariance function at separations computed from the grid
   size nx and sampling dx, with Fried parameter of r0, and outerscale of L0.  
   ninit is the initial side size of the atm array to start with.
*/
static vkcov_t* vkcov_calc(double r0, double L0, double dx, long n, long ninit){
    if(L0>9000) L0=INFINITY;/*L0 bigger than 9000 is treated as infinity. */
    vkcov_t *node=vkcov_get(r0, L0, dx, n, ninit);
    if(node) return node;
    node=mycalloc(1,vkcov_t);
    node->r0=r0;
    node->L0=L0;
    node->dx=dx;
    node->n=n;
    node->ninit=ninit;
    long nroot=(long)round(log2((double)n-1));
    node->next=head;
    if(r0>=L0){
	error("Illegal parameter: r0=%g, L0=%g\n", r0, L0);
    }
    head=node;
    dmat *r=dnew(2, nroot+2);
    double sqrt2=sqrt(2);
    IND(r,0,0)=0;
    IND(r,1,0)=0;
    for(long i=0; i<=nroot; i++){
	long j=1<<i;
	IND(r,0,i+1)=j*dx;
	IND(r,1,i+1)=j*dx*sqrt2;
    }
    double D=(n-1)*dx;
    node->cov=turbcov(r, D*sqrt(2), r0, L0);
    dfree(r);
    dmat *rc0=dnew(ninit*ninit, ninit*ninit);
    dmat*  rc=rc0;
    double dx2=dx*(n-1)/(ninit-1);
    for(long j=0; j<ninit; j++){
	double y=dx2*j;
	for(long i=0; i<ninit; i++){
	    double x=dx2*i;
	    long k=i+j*ninit;
	    for(long j2=0; j2<ninit; j2++){
		double y2=dx2*j2;
		for(long i2=0; i2<ninit; i2++){
		    double x2=dx2*i2;
		    long k2=i2+j2*ninit;
		    IND(rc,k2,k)=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
		}
	    }
	}
    }
    node->C=turbcov(rc0, D*sqrt(2), r0, L0);
    dfree(rc0);
    dmat *u=NULL, *s=NULL, *v=NULL;
    dsvd(&u, &s, &v, node->C);
    dcwpow(s, 1./2.);
    node->K=ddup(u);
    dmuldiag(node->K, s);

    dcwpow(s, -1);
    dmuldiag(u, s);
    node->KI=dtrans(u);
    dfree(u);
    dfree(v);
    dfree(s);
    /*we have: K*K'==C */
    return node;
}
Beispiel #5
0
void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_t *pipe,
                   dt_dev_pixelpipe_iop_t *piece)
{
  dt_iop_colorchecker_params_t *p = (dt_iop_colorchecker_params_t *)p1;
  dt_iop_colorchecker_data_t *d = (dt_iop_colorchecker_data_t *)piece->data;

  d->num_patches = p->num_patches;
  for(int k=0;k<p->num_patches;k++)
  {
    d->source_Lab[3*k+0] = p->source_L[k];
    d->source_Lab[3*k+1] = p->source_a[k];
    d->source_Lab[3*k+2] = p->source_b[k];
  }

#define N (d->num_patches) // number of patches
  // solve equation system to fit thin plate splines to our data
#ifdef _OPENMP
#pragma omp parallel default(shared)
#endif
  {
  double A[(N+4)*(N+4)];
  double target[N+4];
  memset(target, 0, sizeof(target));

  // find coeffs for three channels separately:
#ifdef _OPENMP
#pragma omp for
#endif
  for(int ch=0;ch<3;ch++)
  {
    if(ch==0) for(int k=0;k<N;k++) target[k] = p->target_L[k];
    if(ch==1) for(int k=0;k<N;k++) target[k] = p->target_a[k];
    if(ch==2) for(int k=0;k<N;k++) target[k] = p->target_b[k];
    // following JP's great siggraph course on scattered data interpolation,
    // construct system matrix A such that:
    // A c = f
    //
    // | R   P | |c| = |f|
    // | P^t 0 | |d|   |0|
    //
    // to interpolate values f_i with the radial basis function system matrix R and a polynomial term P.
    // P is a 3D linear polynomial a + b x + c y + d z
    //
    int wd = N+4;
    // radial basis function part R
    for(int j=0;j<N;j++)
      for(int i=j;i<N;i++)
        A[j*wd+i] = A[i*wd+j] = kernel(d->source_Lab+3*i, d->source_Lab+3*j);

    // polynomial part P: constant + 3x linear
    for(int i=0;i<N;i++) A[i*wd+N+0] = A[(N+0)*wd+i] = 1.0f;
    for(int i=0;i<N;i++) A[i*wd+N+1] = A[(N+1)*wd+i] = d->source_Lab[3*i+0];
    for(int i=0;i<N;i++) A[i*wd+N+2] = A[(N+2)*wd+i] = d->source_Lab[3*i+1];
    for(int i=0;i<N;i++) A[i*wd+N+3] = A[(N+3)*wd+i] = d->source_Lab[3*i+2];

    for(int j=N;j<wd;j++) for(int i=N;i<wd;i++) A[j*wd+i] = 0.0f;

    // coefficient vector:
    double c[N+4];
    memset(c, 0, sizeof(c));

    // svd to solve for c:
    // A * c = offsets
    // A = u w v => A-1 = v^t 1/w u^t
    // regularisation epsilon:
    const float eps = 0.001f;
    double w[N+4], v[(N+4)*(N+4)], tmp[N+4];
    memset(tmp, 0, sizeof(tmp));
    dsvd(A, N+4, N+4, N+4, w, v);

    for(int j=0;j<wd;j++)
      for(int i=0;i<wd;i++)
        tmp[j] += A[i*wd+j] * target[i];
    for(int i=0;i<wd;i++)
      tmp[i] *= w[i] / ((w[i] + eps)*(w[i] + eps));
    for(int j=0;j<wd;j++)
      for(int i=0;i<wd;i++)
        c[j] += v[j*wd+i] * tmp[i];
    if(ch==0) for(int i=0;i<N+4;i++) d->coeff_L[i] = c[i];
    if(ch==1) for(int i=0;i<N+4;i++) d->coeff_a[i] = c[i];
    if(ch==2) for(int i=0;i<N+4;i++) d->coeff_b[i] = c[i];
  }
  // for(int i=0;i<N+4;i++) fprintf(stderr, "coeff L[%d] = %f\n", i, d->coeff_L[i]);
  // for(int i=0;i<N+4;i++) fprintf(stderr, "coeff a[%d] = %f\n", i, d->coeff_a[i]);
  // for(int i=0;i<N+4;i++) fprintf(stderr, "coeff b[%d] = %f\n", i, d->coeff_b[i]);
#undef N
  }
}