00001 #ifndef CVOLUME_H
00002 #define CVOLUME_H
00003
00004
00005
00006
00007
00008
00009 #include <QFile>
00010 #include <QFileInfo>
00011 #include <QSize>
00012 #include <QVector>
00013
00014
00015 #include "Definitions.h"
00016 #include "Memory/mmgr.h"
00017 #include "Memory/IManagedObject.h"
00018 #include "Memory/TSmartPointer.h"
00019 #include "GLProgram.h"
00020 #include "modules/Display/Light/CLight.h"
00021 #include "CTransferProperty.h"
00022 #include "Math/TVector3.h"
00023 #include "Math/TVector2.h"
00024 #include "Input/IInputHandler.h"
00025
00026
00027
00028
00029
00030
00031 class CVolumeFormat;
00032
00033
00034 #define MODE_NOTSET -1
00035 #define MODE_BACK_TEX 0
00036 #define MODE_BACK_FRONT_TEX 1
00037 #define MODE_DEPTH_TEX 2
00038 #define MODE_SLICE 3
00039 #define MODE_SLICE_OBJECT 4
00040
00041
00042 struct Slice
00043 {
00044 Slice():depth(0.0),bEnabled(false){}
00045
00046 bool bEnabled;
00047 CVector3f pos;
00048 float depth;
00049 float scaleX;
00050 float scaleY;
00051 };
00052
00053
00054
00055
00056 class CVolume : public IInputHandler
00057 {
00058
00059
00060
00061 public:
00062
00063 CVolume(std::string & fileName);
00064 virtual ~CVolume();
00065
00066 virtual bool Create(TSmartPointer<CGLProgram>, int mode, int fboSize,float stepSize,int maxSamples,bool applyNoise,float minClip,
00067 bool shadowEnabled, float shadowQuality, float shadowTreshold);
00068
00069 virtual bool CreateOpenGL();
00070 virtual bool DestroyOpenGL();
00071 virtual void Render();
00072
00073 std::string & GetFileName(){return fileName;}
00074 CVolumeFormat & GetVolumeDataInfo(){return *pFormat;}
00075 CVector2f GetOrientation(){return CVector2f(rotX,rotY);}
00076
00077 void SetRenderMode(int renderMode);
00078 void SetFboSize(int fboSize);
00079 void SetStepSize(float stepSize);
00080 void SetMaxSamples(int maxSamples);
00081 void SetMinClip(float minClip);
00082 void SetApplyNoise(bool applyNoise);
00083 void SetLight(TSmartPointer<CLight> pL){pLight = pL;}
00084 void SetShadowEnabled(bool tf);
00085 void SetShadowTreshold(float t);
00086 void SetShadowQuality(float q);
00087 void AddTransferProperty(TSmartPointer<CTransferProperty>);
00088
00089 void SetHighQuality(bool tf);
00090 void SwitchProgram(TSmartPointer<CGLProgram>);
00091
00092 void SetSliceInViewSpace(bool);
00093 void SetRenderSlice(bool bxSlice,bool bySlice, bool bzSlice);
00094 void SetSliceDepth(int slizePlaneID,float depth);
00095
00096 void ViewAspectChange(float newAspect){viewAspect = newAspect;}
00097 void SetOrientation(float nrotX, float nrotY){rotX = nrotX; rotY = nrotY;}
00098
00099 virtual bool OnMouseMove(sdword sdwX, sdword sdwY, sdword sdwZ);
00100 virtual bool OnMouseKeyDown(byte bKey);
00101 virtual bool OnMouseKeyUp(byte bKey);
00102
00103
00104
00105
00106 protected:
00107
00108 virtual void Destroy();
00109 bool CreateFboTextures();
00110 void UpdateUniform();
00111
00112
00113
00114
00115 private:
00116
00117
00118 std::string fileName;
00119
00120 bool created;
00121
00122
00123 static int CVolume::sverts[];
00124 static int CVolume::stexCoords[];
00125 static int CVolume::snormals[];
00126 static float CVolume::scolors[];
00127 static unsigned char CVolume::sindices[];
00128
00129 int * pCubeVertices;
00130 int * pCubeNormals;
00131 int * pCubeTexCoords;
00132 float * pCubeColors;
00133 unsigned char * pCubeIndices;
00134
00135 unsigned int cubeDispList;
00136
00137 uchar * noiseTex;
00138 int noiseTexSize;
00139
00140 CVolumeFormat * pFormat;
00141
00142 TSmartPointer<CGLProgram> pProgram;
00143
00144 TSmartPointer<CLight> pLight;
00145 CVector3f gradDelta;
00146
00147 unsigned int txVol,txColorFront,txColorBack,txDepthFront,txDepthBack,txTransfer,txNoise;
00148
00149 unsigned int frameBuffer;
00150
00151 bool cullFaceEnabled;
00152 bool needUpdateUniform,needUpdateFBO;
00153
00154 int renderMode,fboSize;
00155 float stepSize,minClip;
00156 bool applyNoise;
00157 int maxSamples;
00158 bool shadowEnabled;
00159 float shadowTreshold;
00160 float shadowQuality;
00161
00162 unsigned int loc;
00163
00164 QVector< TSmartPointer<CShaderProperty> > propertyList;
00165
00166 bool bSliceInViewSpace;
00167 Slice xSlice;
00168 Slice ySlice;
00169 Slice zSlice;
00170 int nmbActiveSlices;
00171 float viewAspect;
00172
00173 float rotX;
00174 float rotY;
00175 };
00176
00177
00178
00179
00180 class CVolumeFormat
00181 {
00182 public:
00183
00184 CVolumeFormat(){}
00185 virtual ~CVolumeFormat(){}
00186
00187 virtual char * getVolumeHeader(){return (char*)&sizeX;}
00188 virtual char * getVolumeData(){return data;}
00189
00190 virtual void setVolumeData(char *newData)
00191 {
00192 float normalize = 4096*max(max(sizeX,sizeY),sizeZ);
00193
00194 scX = (float)scaleX * sizeX / normalize;
00195 scY = (float)scaleY * sizeY / normalize;
00196 scZ = (float)scaleZ * sizeZ / normalize;
00197 scNX = (float)scaleX / (4096 * sizeX);
00198 scNY = (float)scaleY / (4096 * sizeY);
00199 scNZ = (float)scaleZ / (4096 * sizeZ);
00200 scSX = 1.0 / ((float)scaleX / 4096);
00201 scSY = 1.0 / ((float)scaleY / 4096);
00202 scSZ = 1.0 / ((float)scaleZ / 4096);
00203
00204 data = newData;
00205 }
00206
00207 virtual int getSizeX(){return sizeX;}
00208 virtual int getSizeY(){return sizeY;}
00209 virtual int getSizeZ(){return sizeZ;}
00210
00211 virtual float getScaleX(){return (float)scaleX/(4096);}
00212 virtual float getScaleY(){return (float)scaleY/(4096);}
00213 virtual float getScaleZ(){return (float)scaleZ/(4096);}
00214
00215 virtual char getVolumeHeaderSize() = 0;
00216 virtual int getVolumeDataSize() = 0;
00217 virtual int getBitDepth() = 0;
00218
00219
00220 float scX,scY,scZ;
00221
00222 float scSX,scSY,scSZ;
00223
00224 float scNX,scNY,scNZ;
00225
00226 protected:
00227
00228
00229 unsigned short sizeX;
00230 unsigned short sizeY;
00231 unsigned short sizeZ;
00232
00233 unsigned short scaleX;
00234 unsigned short scaleY;
00235 unsigned short scaleZ;
00236
00237 char *data;
00238 };
00239
00240
00241 class CVolumeFormatVOL8 : public CVolumeFormat
00242 {
00243 public:
00244
00245 CVolumeFormatVOL8(){data = NULL;}
00246 ~CVolumeFormatVOL8(){delete [] data;}
00247
00248 char getVolumeHeaderSize(){return 12;}
00249 int getVolumeDataSize(){return sizeX*sizeY*sizeZ;}
00250 int getBitDepth(){return 8;}
00251 };
00252
00253
00254 class CVolumeFormatVOL12 : public CVolumeFormat
00255 {
00256 public:
00257
00258 CVolumeFormatVOL12(){data = NULL;}
00259 ~CVolumeFormatVOL12(){delete [] data;}
00260
00261 char getVolumeHeaderSize(){return 12;}
00262 int getVolumeDataSize(){return sizeX*sizeY*sizeZ*2;}
00263 int getBitDepth(){return 12;}
00264 };
00265
00266
00267 class CVolumeFormatVOL16 : public CVolumeFormat
00268 {
00269 public:
00270
00271 CVolumeFormatVOL16(){data = NULL;}
00272 ~CVolumeFormatVOL16(){delete [] data;}
00273
00274 char getVolumeHeaderSize(){return 12;}
00275 int getVolumeDataSize(){return sizeX*sizeY*sizeZ*2;}
00276 int getBitDepth(){return 16;}
00277 };
00278
00279
00280 class CVolumeFormatLU_DAT : public CVolumeFormat
00281 {
00282 public:
00283
00284 CVolumeFormatLU_DAT(){data = NULL; scaleX = scaleY = scaleZ = 4096;}
00285 ~CVolumeFormatLU_DAT(){delete [] data;}
00286
00287 char getVolumeHeaderSize(){return 6;}
00288 int getVolumeDataSize(){return sizeX*sizeY*sizeZ*2;}
00289 int getBitDepth(){return 16;}
00290
00291 virtual void setVolumeData(char *newData)
00292 {
00293 float normalize = 4096*max(max(sizeX,sizeY),sizeZ);
00294
00295 scX = (float)scaleX * sizeX / normalize;
00296 scY = (float)scaleY * sizeY / normalize;
00297 scZ = (float)scaleZ * sizeZ / normalize;
00298 scNX = (float)scaleX / (4096 * sizeX);
00299 scNY = (float)scaleY / (4096 * sizeY);
00300 scNZ = (float)scaleZ / (4096 * sizeZ);
00301 scSX = 1.0 / ((float)scaleX / 4096);
00302 scSY = 1.0 / ((float)scaleY / 4096);
00303 scSZ = 1.0 / ((float)scaleZ / 4096);
00304
00305 data = newData;
00306 }
00307 };
00308
00309 #endif //CVOLUME_H