Exemplo n.º 1
0
void Terrain::loadHeightMap(string filename, int res_x, int res_y)
{
	PNG inputFile;
	inputFile.load(filename);
	dim_x = inputFile.width;
	dim_y = inputFile.height;
	unsigned char * data = inputFile.getData();

	int size = dim_x*dim_y;
	float * originalHeightMap = new float[size];
	int i,x,y;

	for (i=0; i<size; i++){
		originalHeightMap[i] = 256*data[2*i]+data[2*i + 1];
	}
	// recalculate to the given resolution (use linear interpolation...)
	size = res_x*res_y;
	heightMap = new float[size];
	float step_x = float(dim_x)/float(res_x);
	float step_y = float(dim_y)/float(res_y);
	
	for(x=0; x<res_x; x++)
	{
		for(y=0; y<res_y; y++)
		{
			heightMap[x*res_y + y] = getHeightAt(originalHeightMap, dim_x, dim_y, float(x*step_x), float(y*step_y));
		}
	}
	SAFE_DELETE_ARRAY_PTR(originalHeightMap);

}
Exemplo n.º 2
0
bool CTdata::loadFromFiles(const char * filename, int cnt, int scaleX, int scaleY, int scaleZ){
	int divide = 2;
	int chars = 0;
	scX = scaleX;
	scY = scaleY;
	scZ = scaleZ/divide;
	char filen [50];
	unsigned char * rawData;
	PNG ctfile;
	int width=0, height=0, width2, height2; 
	int x,y,z;
	float val;
	for(z=0; z<cnt; z++){
		sprintf(filen, filename, z+1);
		ctfile.clear();
		if (!ctfile.load(filen)){
			return false;
		}
		
		rawData		= ctfile.getData();
		height		= ctfile.height;
		width		= ctfile.width;
		width2		= width/float(divide);
		height2		= height/float(divide);
		if (data==NULL){
			data = new float[cnt*width2*height2]; //data = new float[cnt*width*height];
		}
		for (y=0; y<height2; y++){ //height
			for (x=0; x<width2; x++){ //width
				// 2x 8-bit to 1x 16-bit
				val = 256*rawData[(2*y*width + 2*x)*divide]+rawData[(2*y*width + 2*x)*divide + 1]; //val = 256*rawData[2*y*width + 2*x]+rawData[2*y*width + 2*x + 1];
				// save in array
				data[z*height2*width2 + y*width2 +(width2-1-x)] = val; //data[z*width*height + y*width +x] = val;
			}
		}
		BACKSPACE(chars);
		chars = printf("LOADING CT images: %03i %%",((z+1)*100)/cnt);
	
	}

	dimX = width2;
    dimY = height2;
	dimZ = cnt;
	

	szX = dimX * scX;
	szY = dimY * scY;
	szZ = dimZ * scZ;
	center.x = szX/2.0;
	center.y = szY/2.0;
	center.z = szZ/2.0;

	// backspace...
	BACKSPACE(chars);
	printf("LOADING CT images (%i) DONE\n", cnt);
	return true;
}