#include "trueeyes.h" #include "VolumeDataStruct.h" #include "TextureDataStruct.h" #include //list of volume objects for rendering vector VolumeList; //list of texture objects used for transfer functions vector TextureList; void CreateAutoVolume() { int s = 64; unsigned char* volume = new unsigned char[s*s*s*3]; memset(volume, 0, s*s*s*3); int x, y, z; for(x=0; x v = vector3D(x-s/2, y-s/2, z-s/2); volume[z*s*s*3 + y*s*3 + x*3 + 0] = x*(255/s); volume[z*s*s*3 + y*s*3 + x*3 + 1] = y*(255/s); volume[z*s*s*3 + y*s*3 + x*3 + 2] = z*(255/s); } if(VolumeList.size() > 0) { VolumeList[0].Texture.Clean(); VolumeList.clear(); } //create an OpenGL texture map rts_glTextureMap newTexture; newTexture.Init(volume, GL_TEXTURE_3D, s, s, s, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, GL_LINEAR); //create the volume data structure VolumeData newVolume; newVolume.Name = "volume"; newVolume.Texture = newTexture; newVolume.FileType = VOLUME_FILE_AUTO; newVolume.Dim = vector3D(s, s, s); newVolume.ExternalComponents = 3; newVolume.ExternalDatatype = GL_UNSIGNED_BYTE; newVolume.InternalComponents = 3; newVolume.InternalDatatype = GL_UNSIGNED_BYTE; //add the volume structure to the list of volumes VolumeList.push_back(newVolume); } //define macros for bit swapping (little endian to big endian in Windows) #define SWAP_2(x) ( (((x) & 0xff) << 8) | ((unsigned short)(x) >> 8) ) #define SWAP_4(x) ( ((x) << 24) | \ (((x) << 8) & 0x00ff0000) | \ (((x) >> 8) & 0x0000ff00) | \ ((x) >> 24) ) #define FIX_SHORT(x) (*(unsigned short *)&(x) = SWAP_2(*(unsigned short *)&(x))) #define FIX_INT(x) (*(unsigned int *)&(x) = SWAP_4(*(unsigned int *)&(x))) #define FIX_FLOAT(x) FIX_INT(x) void FlipBits(void* bits, int bpp, int size) { int i; if(bpp == 2) { unsigned short* short_bits = (unsigned short*)bits; for(i=0; i 4) { LoadHighComponentRawVolume(newVolume, 0, 2); LoadHighComponentRawVolume(newVolume, 3, 5); return 0; } //get the volume size and allocate space int sx = newVolume.Dim.x; int sy = newVolume.Dim.y; //the total z dimension is the dimension of each file times the number of files int sz = newVolume.Dim.z; int file_z; if(newVolume.Filenames.size() == 1) file_z = sz; else if(newVolume.Filenames.size() > 1) { file_z = 1; sz = file_z * newVolume.Filenames.size(); } int components = newVolume.ExternalComponents; int precision = newVolume.GetByteSize(newVolume.ExternalDatatype); cout<<"Loading RAW volume----------------"<(sx, sy, sz); newVolume.ExternalComponents = components; newVolume.ExternalDatatype = GL_UNSIGNED_BYTE; newVolume.InternalComponents = components; newVolume.InternalDatatype = GL_UNSIGNED_BYTE; //newVolume.Name = newVolume.Filenames[0].getPrefix(); rts_glTextureMap newTexture; /*newTexture.Init(bits, GL_TEXTURE_3D, sx, sy, sz, newVolume.getInternalFormat(), newVolume.getExternalFormat(), newVolume.ExternalDatatype);*/ newTexture.Init(bits, GL_TEXTURE_3D, sx, sy, sz, newVolume.getInternalFormat(), newVolume.getExternalFormat(), newVolume.ExternalDatatype); free(bits); newVolume.Texture = newTexture; VolumeList.push_back(newVolume); return 0; } int LoadTexture(TextureData& newTexture) { //*******currently, this only supports image formats with 8bpp //load the image QImage I(newTexture.Filename.getString().c_str()); //swap because for some reason QImage returns a BGR image as a pointer I = I.rgbSwapped(); int sx = I.width(); int sy = I.height(); //find the number of color components int components = I.depth()/8; //allocate memory for the image char* bits = (char*)malloc(sx*sy*components); cout<<"Image size: "<