/*!
 * 2D wavelet noise
 * @param[in] nx,ny 解像度
 */
void rxWaveletNoise::GenerateNoiseTile2(int n)
{
	// MARK:GenerateNoiseTile2
	if(g_pNoiseTileData != NULL && n == g_iNoiseTileSize) return;

	if(n%2) n++; // tile size must be even

	int sz = n*n;

	RXREAL *temp1 = new RXREAL[sz];
	RXREAL *temp2 = new RXREAL[sz];
	RXREAL *noise = new RXREAL[sz];

	// Step 1. Fill the tile with random numbers in the range -1 to 1.
	for(int i = 0; i < n*n; ++i){
		noise[i] = GaussianNoise();
		temp1[i] = temp2[i] = 0;
	}

	// Steps 2 and 3. Downsample and Upsample the tile
	for(int iy = 0; iy < n; ++iy){ // each x row
		int idx = iy*n;
		Downsample(&noise[idx], &temp1[idx], n, 1);
		Upsample(  &temp1[idx], &temp2[idx], n, 1);
	}

	for(int ix = 0; ix < n; ++ix){ // each y row
		int idx = ix; 
		Downsample(&temp2[idx], &temp1[idx], n, n);
		Upsample(  &temp1[idx], &temp2[idx], n, n);
	}

	// Step 4. Subtract out the coarse-scale contribution
	for(int i = 0; i < n*n; ++i){
		noise[i] -= temp2[i];
	}

	// Avoid even/odd variance difference by adding odd-offset version of noise to itself.
	int offset = n/2;
	if(offset%2 == 0) offset++;

	for(int i = 0, ix = 0; ix < n; ++ix){
		for(int iy = 0; iy < n; ++iy){
			temp1[i++] = noise[ModW(ix+offset, n)+ModW(iy+offset, n)*n];
		}
	}

	for(int i = 0; i < n*n; ++i){
		noise[i] += temp1[i];
	}

	g_pNoiseTileData = noise;
	g_iNoiseTileSize = n;

	delete [] temp1;
	delete [] temp2;
}
/// Upsampler::Measure
double Upsampler::Measure(class ImageLayout *src,class ImageLayout *dest,double in)
{
  src->TestIfCompatible(dest);

  Upsample(m_ppucSource,src);
  Upsample(m_ppucDestination,dest);

  return in;
}
Beispiel #3
0
	static void UpsampleZ(float* to, const float* from, int sx,int sy, int sz) {
		
		for (int ix = 0; ix < sx; ix++) 
			for (int iy = 0; iy < sy; iy++) {
				const int i = ix + iy*sx;
				Upsample(&from[i], &to[i], sz, sx*sy);
			}
	}
Beispiel #4
0
	static void UpsampleY(float* to, const float* from, int sx,int sy, int sz) {
		
		for (int ix = 0; ix < sx; ix++) 
			for (int iz = 0; iz < sz; iz++) {
				const int i = ix + iz*sx*sy;
				Upsample(&from[i], &to[i], sy, sx);
			}
	}
Beispiel #5
0
	static void UpsampleX(float* to, const float* from, int sx,int sy, int sz) {
		
		for (int iy = 0; iy < sy; iy++) 
			for (int iz = 0; iz < sz; iz++) {
				const int i = iy * sx + iz*sx*sy;
				Upsample(&from[i], &to[i], sx, 1);
			}
	}
/*!
 * 3Dノイズタイル生成
 * @param[in] n タイルグリッド数
 */
RXREAL* rxWaveletNoise::GenerateNoiseTile4r(int &n, int &nt)
{
	if(n%2) n++; // tile size must be even

	long sz = n*n*n*nt;
	RXREAL *temp1 = new RXREAL[sz];
	RXREAL *temp2 = new RXREAL[sz];
	RXREAL *noise = new RXREAL[sz];

	// Step 1. Fill the tile with random numbers in the range -1 to 1.
	for(int i = 0; i < sz; ++i){
		noise[i] = GaussianNoise();
	}

	// Steps 2 and 3. Downsample and Upsample the tile
	for(int iy = 0; iy < n; ++iy){
		for(int iz = 0; iz < n; ++iz){
			for(int it = 0; it < nt; ++it){
				// each x row
				long idx = iy*n+iz*n*n+it*n*n*n;
				Downsample(&noise[idx], &temp1[idx], n, 1);
				Upsample(  &temp1[idx], &temp2[idx], n, 1);
			}
		}
	}

	for(int ix = 0; ix < n; ++ix){
		for(int iz = 0; iz < n; ++iz){
			for(int it = 0; it < nt; ++it){
				// each y row
				long idx = ix+iz*n*n+it*n*n*n;
				Downsample(&temp2[idx], &temp1[idx], n, n);
				Upsample(  &temp1[idx], &temp2[idx], n, n);
			}
		}
	}

	for(int ix = 0; ix < n; ++ix){
		for(int iy = 0; iy < n; ++iy){
			for(int it = 0; it < nt; ++it){
				// each z row
				long idx = ix+iy*n+it*n*n*n;
				Downsample(&temp2[idx], &temp1[idx], n, n*n);
				Upsample(  &temp1[idx], &temp2[idx], n, n*n);
			}
		}
	}

	for(int ix = 0; ix < n; ++ix){
		for(int iy = 0; iy < n; ++iy){
			for(int iz = 0; iz < n; ++iz){
				// each t row
				long idx = ix+iy*n+iz*n*n;
				Downsample(&temp2[idx], &temp1[idx], nt, n*n*n);
				Upsample(  &temp1[idx], &temp2[idx], nt, n*n*n);
			}
		}
	}

	// Step 4. Subtract out the coarse-scale contribution
	for(int i = 0; i < sz; ++i){
		noise[i] -= temp2[i];
	}

	// Avoid even/odd variance difference by adding odd-offset version of noise to itself.
	int offset = n/2;
	if(offset%2 == 0) offset++;

	for(int i = 0, ix = 0; ix < n; ++ix){
		for(int iy = 0; iy < n; ++iy){
			for(int iz = 0; iz < n; ++iz){
				for(int it = 0; it < nt; ++it){
					temp1[i++] = noise[ModW(ix+offset, n)+ModW(iy+offset, n)*n+ModW(iz+offset, n)*n*n+ModW(it+offset, nt)*n*n*n];
				}
			}
		}
	}

	for(int i = 0; i < sz; ++i){
		noise[i] += temp1[i];
	}

	delete [] temp1;
	delete [] temp2;

	return noise;
}
/*!
 * 
 * @param[in] 
 * @return 
 */
RXREAL* rxWaveletNoise::GenerateNoiseTile3r(int &nx, int &ny, int &nz)
{
	if(nx%2) nx++; // tile size must be even
	if(ny%2) ny++; // tile size must be even
	if(nz%2) nz++; // tile size must be even

	int sz = nx*ny*nz;
	RXREAL *temp1 = new RXREAL[sz];
	RXREAL *temp2 = new RXREAL[sz];
	RXREAL *noise = new RXREAL[sz];

	init_genrand((unsigned)time(NULL));
	//init_genrand(1234);

	// Step 1. Fill the tile with random numbers in the range -1 to 1.
	for(int i = 0; i < sz; ++i){
		noise[i] = GaussianNoise();
	}

	// Steps 2 and 3. Downsample and Upsample the tile
	for(int iy = 0; iy < ny; ++iy){
		for(int iz = 0; iz < nz; ++iz){
			// each x row
			int idx = iy*nx+iz*nx*ny;
			Downsample(&noise[idx], &temp1[idx], nx, 1);
			Upsample(  &temp1[idx], &temp2[idx], nx, 1);
		}
	}

	for(int ix = 0; ix < nx; ++ix){
		for(int iz = 0; iz < nz; ++iz){
			// each y row
			int idx = ix+iz*nx*ny;
			Downsample(&temp2[idx], &temp1[idx], ny, nx);
			Upsample(  &temp1[idx], &temp2[idx], ny, nx);
		}
	}

	for(int ix = 0; ix < nx; ++ix){
		for(int iy = 0; iy < ny; ++iy){
			// each z row
			int idx = ix+iy*nx;
			Downsample(&temp2[idx], &temp1[idx], nz, nx*ny);
			Upsample(  &temp1[idx], &temp2[idx], nz, nx*ny);
		}
	}

	// Step 4. Subtract out the coarse-scale contribution
	for(int i = 0; i < sz; ++i){
		noise[i] -= temp2[i];
	}

	// Avoid even/odd variance difference by adding odd-offset version of noise to itself.
	int offset = nx/2;
	if(offset%2 == 0) offset++;

	for(int i = 0, ix = 0; ix < nx; ++ix){
		for(int iy = 0; iy < ny; ++iy){
			for(int iz = 0; iz < nz; ++iz){
				temp1[i++] = noise[ModW(ix+offset, nx)+ModW(iy+offset, ny)*nx+ModW(iz+offset, nz)*nx*ny];
			}
		}
	}

	for(int i = 0; i < sz; ++i){
		noise[i] += temp1[i];
	}

	delete [] temp1;
	delete [] temp2;

	return noise;
}