00001
00002
00003
00004
00005
00006 #ifndef VolRender_h
00007 #define VolRender_h
00008
00009 #ifdef WIN32
00010 #include <windows.h>
00011 #endif
00012
00013 #include "Vector.h"
00014
00015
00016 #include <GL/gl.h>
00017 #include <GL/glu.h>
00018
00019 #include <glux/glux.h>
00020
00021
00022 #include "Cg/cg.h"
00023 #include <Cg/cgGL.h>
00024
00025
00026 enum {X, Y, Z, W};
00027 enum {R, G, B, A};
00028
00029
00030
00031 class VolRender{
00032 IVector fieldSize;
00033
00034
00035 float *tex3ddata;
00036 bool my3ddata;
00037 GLuint texID;
00038 char nbComp;
00039
00040
00041 float *gradField;
00042 bool gradEnable;
00043 GLuint gradID;
00044
00045
00046 bool cut;
00047 GLint cutbias;
00048
00049
00050 GLfloat objangle[2];
00051
00052 int slices;
00053
00054
00055 int planesList;
00056
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00071 CGcontext shaderContext;
00072
00073 CGprofile vertexProfile;
00074 CGprofile fragmentProfile;
00075
00076 CGprogram vertexProgram;
00077 CGprogram fragmentProgram;
00078
00079 CGparameter cgParam_lightPos;
00081
00082
00083 void CheckCgError();
00084 int initCg();
00085 GLuint tableID;
00086
00087
00088 void drawCube();
00089
00090 void buildPlanes();
00091
00092 void updateDataTexture();
00093
00094
00095 public:
00096 VolRender(){
00097 tex3ddata=0; my3ddata=0;
00098
00099 glGenTextures(1, &texID);
00100 cut=0;
00101 cutbias = 50;
00102 objangle[0]=0; objangle[1]=0;
00103
00104 slices=200;
00105
00106 gradField=0;
00107
00108 fieldSize=IVector(128,128,128);
00109 nbComp=1;
00110 }
00111
00112 virtual ~VolRender(){}
00113
00114 int initExts();
00115
00116 int init();
00117
00118 void draw0();
00119 void draw();
00120
00121
00122
00123 void bindScalarField(float *sf, IVector size);
00124 void bindRGBAField(float *sf, IVector size);
00125
00126
00127 void updateDataTextureRegion(float *data, IVector pos, IVector size);
00128
00129
00130 void loadRawData(char *fich, IVector size, int nbcomp);
00131
00132 void loadRawDataPart(char *fich, IVector size, int nbcomp, IVector partPos, IVector partSize, IVector fsize=IVector(-1,-1,-1));
00133
00134
00135 void computeGradient();
00136
00137
00138 void setRotation(float x, float y){
00139 objangle[0]=x; objangle[1]=y;
00140 }
00141 void setSlices(int nb){
00142 slices=nb;
00143 buildPlanes();
00144 }
00145 int getSlices(){
00146 return slices;
00147 }
00148
00149 void setCutBias(int nb){
00150 cutbias=nb;
00151 }
00152 void setCut(bool enable){
00153 cut=enable;
00154 }
00155
00156 bool getCut(){ return cut; }
00157
00158
00159 void setLightPos(FVector pos){
00160 float tmp[]={pos.x, pos.y, pos.z};
00161 cgGLSetParameter3fv( cgParam_lightPos, tmp );
00162 }
00163
00164 void setPalette(float *pal);
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00183 class Error {
00184 public:
00185 char *errString;
00186
00187 Error(const char *es){
00188 if(es){
00189 errString = new char [strlen(es)+1];
00190 strcpy(errString, es);
00191
00192 }else{
00193 errString=new char[strlen("#Erreur indefinie#")+1];
00194 strcpy(errString, "#Erreur indefinie#");
00195 }
00196 }
00197 };
00198
00199 class CgError {
00200 public:
00201 char *errString;
00202 char *context;
00203
00204 CgError(const char *es, const char *c){
00205 if(es && c){
00206 errString = new char [strlen(es)+1];
00207 strcpy(errString, es);
00208 context=new char [strlen(c)+1];
00209 strcpy(context, c);
00210 }else{
00211 errString=new char[strlen("#Erreur indefinie#")+1];
00212 strcpy(errString, "#Erreur indefinie#");
00213
00214 context=new char[1];
00215 context[0]=0;
00216
00217 }
00218 }
00219 };
00220
00221
00222 };
00223
00224 #endif