00001 #include "GLView.h"
00002
00003 #include <QFile>
00004 #include <QDebug>
00005
00006 const int getNextPowerOfTwo(const int number)
00007 {
00008 int powerOfTwoNumber = 1;
00009
00010 while(powerOfTwoNumber < number)
00011 powerOfTwoNumber = powerOfTwoNumber * 2;
00012
00013 return powerOfTwoNumber;
00014 };
00015
00016 VolumeDesc::VolumeDesc()
00017 {
00018 volumeTexture = 0;
00019 hasChanged = false;
00020 }
00021
00022 void VolumeDesc::set(GLuint realWidth, GLuint realHeight, GLuint realDepth)
00023 {
00024 this->realWidth = realWidth;
00025 this->realHeight = realHeight;
00026 this->realDepth = realDepth;
00027 width = getNextPowerOfTwo(realWidth);
00028 height = getNextPowerOfTwo(realHeight);
00029 depth = getNextPowerOfTwo(realDepth);
00030 xOffset = (width - realWidth) / 2;
00031 yOffset = (height - realHeight) / 2;
00032 zOffset = (depth - realDepth) / 2;
00033 xNormOffset = (GLfloat)(width - realWidth) / (width * 2);
00034 yNormOffset = (GLfloat)(height - realHeight) / (height * 2);
00035 zNormOffset = (GLfloat)(depth - realDepth) / (depth * 2);
00036 xNormLength = (GLfloat)realWidth / width;
00037 yNormLength = (GLfloat)realHeight / height;
00038 zNormLength = (GLfloat)realDepth / depth;
00039 maxSideLength = max(max(realWidth, realHeight), realDepth);
00040 stepDist = 1.0f / maxSideLength;
00041
00042 qDebug() << "maxSideLength: " << maxSideLength;
00043 qDebug() << "stepDist: " << stepDist;
00044
00045 hasChanged = true;
00046 }
00047
00048 TransferFunctionDesc::TransferFunctionDesc()
00049 {
00050 transferFunction = new unsigned int[4096];
00051
00052 hasChanged = true;
00053 }
00054
00055 TransferFunctionDesc::~TransferFunctionDesc()
00056 {
00057 delete [] transferFunction;
00058 }
00059
00060 StateDesc::StateDesc()
00061 {
00062 shaderIndex = 0;
00063 shaderChanged = false;
00064 }
00065
00066 void StateDesc::setShaderIndex(int shaderIndex)
00067 {
00068 this->shaderIndex = shaderIndex;
00069 shaderChanged = true;
00070 }
00071
00072 void TransferFunctionDesc::set(unsigned int *transferFunction, int length)
00073 {
00074
00075 memcpy(this->transferFunction, transferFunction, length * 4);
00076 hasChanged = true;
00077 }
00078
00079 GLView::GLView()
00080 {
00081 }
00082
00083 void GLView::setData(QGLWidget *parent, VolumeDesc *volumeDesc, TransferFunctionDesc *transferFunctionDesc, StateDesc *stateDesc)
00084 {
00085 this->parent = parent;
00086 this->volumeDesc = volumeDesc;
00087 this->transferFunctionDesc = transferFunctionDesc;
00088 this->stateDesc = stateDesc;
00089 }