- Timestamp:
- Feb 22, 2007, 8:44:10 PM (18 years ago)
- Location:
- trunk/gui/vizservers/nanovis
- Files:
-
- 9 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/Lic.cpp
r467 r587 340 340 } 341 341 342 void Lic::set_offset(float v){ 342 void Lic::set_offset(float v) 343 { 343 344 offset = v; 344 345 get_slice(); -
trunk/gui/vizservers/nanovis/Makefile
r585 r587 6 6 NvZincBlendeVolumeShader.o NvShader.o NvVolumeShader.o NvRegularVolumeShader.o NvVolQDVolumeShader.o \ 7 7 NvLoadFile.o NvVolQDVolume.o NvDefaultTFData.o NvColorTableShader.o NvColorTableRenderer.o NvParticleAdvectionShader.o \ 8 NvEventLog.o NvParticleRenderer.o NvLIC.o \ 8 9 R2string.o R2FilePath.o R2Fonts.o R2Object.o 9 10 … … 52 53 gcc $(CFLAG) NvParticleAdvectionShader.cpp 53 54 55 NvParticleRenderer.o: NvParticleRenderer.cpp NvParticleRenderer.h 56 gcc $(CFLAG) NvParticleRenderer.cpp 57 54 58 NvColorTableShader.o: NvColorTableShader.cpp NvColorTableShader.h 55 59 gcc $(CFLAG) NvColorTableShader.cpp 56 60 61 NvLIC.o: NvLIC.cpp NvLIC.h 62 gcc $(CFLAG) NvLIC.cpp 63 57 64 NvColorTableRenderer.o: NvColorTableRenderer.cpp NvColorTableRenderer.h 58 65 gcc $(CFLAG) NvColorTableRenderer.cpp 66 67 NvEventLog.o: NvEventLog.cpp NvEventLog.h 68 gcc $(CFLAG) NvEventLog.cpp 59 69 60 70 NvShader.o: NvShader.cpp NvShader.h -
trunk/gui/vizservers/nanovis/Nv.cpp
r582 r587 1 1 #include "Nv.h" 2 2 #include "NvShader.h" 3 #include "NvParticleRenderer.h" 4 #include "NvColorTableRenderer.h" 5 #include "NvEventLog.h" 6 #include "VolumeRenderer.h" 3 7 #include <R2/R2FilePath.h> 4 8 #include <stdio.h> … … 7 11 8 12 extern void NvInitCG(); // in NvShader.cpp 13 14 NvParticleRenderer* g_particleRenderer; 15 NvColorTableRenderer* g_color_table_renderer; 16 VolumeRenderer* g_vol_render; 17 R2Fonts* g_fonts; 9 18 10 19 //query opengl information … … 45 54 } 46 55 56 //init line integral convolution 57 void NvInitLIC() 58 { 59 /* 60 g_lic = new Lic(NMESH, win_width, win_height, 0.3, g_context, volume[1]->id, 61 volume[1]->aspect_ratio_width, 62 volume[1]->aspect_ratio_height, 63 volume[1]->aspect_ratio_depth); 64 */ 65 } 66 67 void NvInitParticle() 68 { 69 /* 70 //random placement on a slice 71 float* data = new float[g_particleRenderer->psys_width * g_particleRenderer->psys_height * 4]; 72 bzero(data, sizeof(float)*4* g_particleRenderer->psys_width * g_particleRenderer->psys_height); 73 74 int index; 75 bool particle; 76 for (int i=0; i<g_particleRenderer->psys_width; i++) { 77 for (int j=0; j<g_particleRenderer->psys_height; j++) { 78 index = i + g_particleRenderer->psys_height*j; 79 particle = rand() % 256 > 150; 80 if(particle) 81 { 82 //assign any location (x,y,z) in range [0,1] 83 data[4*index] = lic_slice_x; 84 data[4*index+1]= j/float(g_particleRenderer->psys_height); 85 data[4*index+2]= i/float(g_particleRenderer->psys_width); 86 data[4*index+3]= 30; //shorter life span, quicker iterations 87 } 88 else 89 { 90 data[4*index] = 0; 91 data[4*index+1]= 0; 92 data[4*index+2]= 0; 93 data[4*index+3]= 0; 94 } 95 } 96 } 97 98 g_particleRenderer->initialize((Particle*)data); 99 delete[] data; 100 */ 101 } 102 103 //init the particle system using vector field volume->[1] 104 void NvInitParticleRenderer() 105 { 106 /* 107 g_particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context, 108 volume[1]->id, 109 1./volume[1]->aspect_ratio_width, 110 1./volume[1]->aspect_ratio_height, 111 1./volume[1]->aspect_ratio_depth); 112 113 NvInitParticle(); 114 */ 115 } 116 117 void NvInitVolumeRenderer() 118 { 119 } 120 47 121 void NvInit() 48 122 { … … 55 129 NvInitGLEW(); 56 130 NvInitCG(); 131 132 g_fonts = new R2Fonts(); 133 g_fonts->addFont("verdana", "verdana.fnt"); 134 g_fonts->setFont("verdana"); 135 136 g_color_table_renderer = new NvColorTableRenderer(); 137 g_color_table_renderer->setFonts(g_fonts); 138 139 NvInitVolumeRenderer(); 140 NvInitParticleRenderer(); 57 141 58 142 printf("Nanovis GL Initialized\n"); … … 61 145 void NvExit() 62 146 { 147 if (g_particleRenderer) 148 { 149 delete g_particleRenderer; 150 g_particleRenderer; 151 } 152 153 #ifdef EVENTLOG 154 NvExitEventLog(); 155 #endif 156 157 #ifdef XINETD 158 NvExitService(); 159 #endif 160 63 161 } 162 -
trunk/gui/vizservers/nanovis/NvParticleAdvectionShader.h
r585 r587 19 19 20 20 public : 21 void bind( );21 void bind(unsigned int texID); 22 22 void unbind(); 23 23 }; 24 24 25 inline void NvParticleAdvectionShader::bind(unsigned int texID) 26 { 27 cgGLBindProgram(_cgFP); 28 cgGLSetParameter1f(_posTimestepParam, 0.05); 29 cgGLEnableTextureParameter(_velTexParam); 30 cgGLSetTextureParameter(_posTexParam, texID); 31 cgGLEnableTextureParameter(_posTexParam); 32 33 cgGLEnableProfile(CG_PROFILE_FP30); 34 } 35 36 inline void NvParticleAdvectionShader::unbind() 37 { 38 cgGLDisableProfile(CG_PROFILE_FP30); 39 40 cgGLDisableTextureParameter(_velTexParam); 41 cgGLDisableTextureParameter(_posTexParam); 42 } 43 25 44 #endif //__NV_PARTICLE_ADV_SHADER_H__ -
trunk/gui/vizservers/nanovis/ParticleSystem.cpp
r467 r587 23 23 24 24 ParticleSystem::ParticleSystem(int w, int h, CGcontext context, NVISid volume, float scale_x, 25 float scale_y, float scale_z){ 26 27 fprintf(stderr, "%f, %f, %f\n", scale_x, scale_y, scale_z); 28 scale = Vector3(scale_x, scale_y, scale_z); 25 float scale_y, float scale_z) 26 { 27 28 fprintf(stderr, "%f, %f, %f\n", scale_x, scale_y, scale_z); 29 scale = Vector3(scale_x, scale_y, scale_z); 29 30 30 31 psys_width = w; … … 64 65 65 66 //load related shaders 67 /* 66 68 m_g_context = context; 67 69 … … 73 75 cgGLSetTextureParameter(m_vel_tex_param, volume); 74 76 cgGLSetParameter3f(m_scale_param, scale_x, scale_y, scale_z); 77 */ 78 _advectionShader = new NvParticleAdvectionShader(scale); 75 79 76 80 fprintf(stderr, "init_psys\n"); 77 81 } 78 82 79 80 ParticleSystem::~ParticleSystem(){ 81 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]); 82 glDeleteTextures(1, psys_tex); 83 84 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]); 85 glDeleteTextures(1, psys_tex+1); 86 87 glDeleteFramebuffersEXT(2, psys_fbo); 88 89 free(data); 90 } 91 92 93 void ParticleSystem::initialize(Particle* p){ 94 //also store the data on main memory for next initialization 95 memcpy(data, p, psys_width*psys_height*sizeof(Particle)); 96 97 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 98 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)p); 99 100 assert(glGetError()==0); 101 102 flip = true; 103 reborn = false; 104 105 //fprintf(stderr, "init particles\n"); 106 } 107 108 void ParticleSystem::reset(){ 109 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 110 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)data); 111 112 assert(glGetError()==0); 113 114 flip = true; 115 reborn = false; 116 psys_frame = 0; 117 } 118 119 120 void ParticleSystem::advect(){ 121 if(reborn) reset(); 122 123 glDisable(GL_BLEND); 83 ParticleSystem::~ParticleSystem() 84 { 85 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]); 86 glDeleteTextures(1, psys_tex); 87 88 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]); 89 glDeleteTextures(1, psys_tex+1); 90 91 glDeleteFramebuffersEXT(2, psys_fbo); 92 93 free(data); 94 } 95 96 void ParticleSystem::initialize(Particle* p) 97 { 98 //also store the data on main memory for next initialization 99 memcpy(data, p, psys_width*psys_height*sizeof(Particle)); 100 101 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 102 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)p); 103 104 assert(glGetError()==0); 105 106 flip = true; 107 reborn = false; 108 109 //fprintf(stderr, "init particles\n"); 110 } 111 112 void ParticleSystem::reset() 113 { 114 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 115 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)data); 116 117 assert(glGetError()==0); 118 119 flip = true; 120 reborn = false; 121 psys_frame = 0; 122 } 123 124 125 void ParticleSystem::advect() 126 { 127 if (reborn) 128 reset(); 129 130 glDisable(GL_BLEND); 124 131 125 if(flip){ 126 127 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]); 128 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 129 130 glClear(GL_COLOR_BUFFER_BIT); 131 132 glViewport(0, 0, psys_width, psys_height); 133 glMatrixMode(GL_PROJECTION); 134 glLoadIdentity(); 135 gluOrtho2D(0, psys_width, 0, psys_height); 136 glMatrixMode(GL_MODELVIEW); 137 glLoadIdentity(); 138 132 if(flip){ 133 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]); 134 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 135 136 glClear(GL_COLOR_BUFFER_BIT); 137 138 glViewport(0, 0, psys_width, psys_height); 139 glMatrixMode(GL_PROJECTION); 140 glLoadIdentity(); 141 gluOrtho2D(0, psys_width, 0, psys_height); 142 glMatrixMode(GL_MODELVIEW); 143 glLoadIdentity(); 144 145 _advectionShader->bind(psys_tex[0]); 146 147 /* 139 148 cgGLBindProgram(m_pos_fprog); 140 149 cgGLSetParameter1f(m_pos_timestep_param, 0.05); … … 144 153 145 154 cgGLEnableProfile(CG_PROFILE_FP30); 146 draw_quad(psys_width, psys_height, psys_width, psys_height); 155 */ 156 draw_quad(psys_width, psys_height, psys_width, psys_height); 157 /* 147 158 cgGLDisableProfile(CG_PROFILE_FP30); 148 149 159 cgGLDisableTextureParameter(m_vel_tex_param); 150 160 cgGLDisableTextureParameter(m_pos_tex_param); 161 */ 151 162 } 152 163 else 153 164 { 154 155 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]); 156 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]); 157 158 glClear(GL_COLOR_BUFFER_BIT); 159 160 glViewport(0, 0, psys_width, psys_height); 161 glMatrixMode(GL_PROJECTION); 162 glLoadIdentity(); 163 gluOrtho2D(0, psys_width, 0, psys_height); 164 glMatrixMode(GL_MODELVIEW); 165 glLoadIdentity(); 166 165 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]); 166 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]); 167 168 glClear(GL_COLOR_BUFFER_BIT); 169 170 glViewport(0, 0, psys_width, psys_height); 171 glMatrixMode(GL_PROJECTION); 172 glLoadIdentity(); 173 gluOrtho2D(0, psys_width, 0, psys_height); 174 glMatrixMode(GL_MODELVIEW); 175 glLoadIdentity(); 176 177 _advectionShader->bind(psys_tex[1]); 178 179 /* 167 180 cgGLBindProgram(m_pos_fprog); 168 181 cgGLSetParameter1f(m_pos_timestep_param, 0.05); … … 170 183 cgGLSetTextureParameter(m_pos_tex_param, psys_tex[1]); 171 184 cgGLEnableTextureParameter(m_pos_tex_param); 172 173 185 cgGLEnableProfile(CG_PROFILE_FP30); 174 draw_quad(psys_width, psys_height, psys_width, psys_height); 186 */ 187 188 draw_quad(psys_width, psys_height, psys_width, psys_height); 189 190 /* 175 191 cgGLDisableProfile(CG_PROFILE_FP30); 176 177 192 cgGLDisableTextureParameter(m_vel_tex_param); 178 193 cgGLDisableTextureParameter(m_pos_tex_param); 179 } 194 */ 195 196 } 197 198 _advectionShader->unbind(); 180 199 181 200 assert(glGetError()==0); … … 184 203 update_vertex_buffer(); 185 204 186 flip = (!flip); 187 188 psys_frame++; 189 if(psys_frame==max_life){ 190 psys_frame=0; 191 reborn = true; 192 } 205 flip = (!flip); 206 207 psys_frame++; 208 if(psys_frame==max_life) 209 { 210 psys_frame=0; 211 reborn = true; 212 } 193 213 194 214 //fprintf(stderr, "advect: %d ", psys_frame); 195 215 } 196 216 197 198 void ParticleSystem::update_vertex_buffer(){199 m_vertex_array->Read(psys_width, psys_height);217 void ParticleSystem::update_vertex_buffer() 218 { 219 m_vertex_array->Read(psys_width, psys_height); 200 220 //m_vertex_array->LoadData(vert); //does not work?? 201 assert(glGetError()==0); 202 } 203 204 205 void ParticleSystem::render(){ display_vertices(); } 206 207 void ParticleSystem::display_vertices(){ 208 glDisable(GL_TEXTURE_2D); 209 glDisable(GL_BLEND); 210 glEnable(GL_DEPTH_TEST); 211 212 glPointSize(1.2); 213 glColor4f(.2,.2,.8,1.); 214 215 glPushMatrix(); 216 glScaled(1./scale.x, 1./scale.y, 1./scale.z); 217 218 m_vertex_array->SetPointer(0); 219 //glEnableVertexAttribArray(0); 220 glEnableClientState(GL_VERTEX_ARRAY); 221 glDrawArrays(GL_POINTS, 0, psys_width*psys_height); 222 //glDisableVertexAttribArray(0); 223 glDisableClientState(GL_VERTEX_ARRAY); 224 225 glPopMatrix(); 226 227 glDisable(GL_DEPTH_TEST); 228 assert(glGetError()==0); 229 } 230 231 221 assert(glGetError()==0); 222 } 223 224 void ParticleSystem::render() 225 { 226 display_vertices(); 227 } 228 229 void ParticleSystem::display_vertices() 230 { 231 glDisable(GL_TEXTURE_2D); 232 glDisable(GL_BLEND); 233 glEnable(GL_DEPTH_TEST); 234 235 glPointSize(1.2); 236 glColor4f(.2,.2,.8,1.); 237 238 glPushMatrix(); 239 glScaled(1./scale.x, 1./scale.y, 1./scale.z); 240 241 m_vertex_array->SetPointer(0); 242 glEnableClientState(GL_VERTEX_ARRAY); 243 glDrawArrays(GL_POINTS, 0, psys_width*psys_height); 244 glDisableClientState(GL_VERTEX_ARRAY); 245 246 glPopMatrix(); 247 248 glDisable(GL_DEPTH_TEST); 249 assert(glGetError()==0); 250 } 251 252 -
trunk/gui/vizservers/nanovis/ParticleSystem.h
r401 r587 29 29 #include "Vector3.h" 30 30 31 typedef struct Particle{ 31 #include "NvParticleAdvectionShader.h" 32 33 typedef struct Particle { 32 34 float x; 33 35 float y; … … 41 43 42 44 43 class ParticleSystem : public Renderable {45 class ParticleSystem : public Renderable { 44 46 45 47 NVISid psys_fbo[2]; //frame buffer objects: two are defined, flip them as input output every step … … 56 58 57 59 //Nvidia CG shaders and their parameters 60 /* 58 61 CGcontext m_g_context; 59 62 CGprogram m_pos_fprog; 60 63 CGparameter m_vel_tex_param, m_pos_tex_param, m_scale_param; 61 64 CGparameter m_pos_timestep_param, m_pos_spherePos_param; 65 */ 66 NvParticleAdvectionShader* _advectionShader; 62 67 63 68 Vector3 scale; … … 76 81 void reset(); 77 82 void render(); 78 79 83 }; 80 84 -
trunk/gui/vizservers/nanovis/nanovis.cpp
r585 r587 44 44 #include "NvVolQDVolume.h" 45 45 #include "NvColorTableRenderer.h" 46 #include "NvEventLog.h" 46 47 47 48 // R2 headers … … 51 52 //render server 52 53 53 VolumeRenderer* vol_render; 54 extern VolumeRenderer* g_vol_render; 55 extern NvColorTableRenderer* g_color_table_renderer; 54 56 PlaneRenderer* plane_render; 55 NvColorTableRenderer* color_table_renderer;56 57 Camera* cam; 57 58 … … 89 90 }"; 90 91 92 /* 91 93 #ifdef XINETD 92 94 FILE* xinetd_log; … … 99 101 double cur_time; //in seconds 100 102 double get_time_interval(); 103 */ 101 104 102 105 int render_window; //the handle of the render window; 103 106 104 107 // forward declarations 105 void init_particles();108 //void init_particles(); 106 109 void get_slice_vectors(); 107 110 Rappture::Outcome load_volume_file(int index, char *fname); … … 117 120 void read_screen(); 118 121 119 ParticleSystem* psys;120 float psys_x=0.4, psys_y=0, psys_z=0;122 //ParticleSystem* psys; 123 //float psys_x=0.4, psys_y=0, psys_z=0; 121 124 122 125 Lic* lic; … … 126 129 NVISid final_fbo, final_color_tex, final_depth_rb; 127 130 128 bool advect=false;131 //bool advect=false; 129 132 float vert[NMESH*NMESH*3]; //particle positions in main memory 130 133 float slice_vector[NMESH*NMESH*4]; //per slice vectors in main memory … … 152 155 CGparameter m_passthru_scale_param, m_passthru_bias_param; 153 156 154 R2Fonts* g_fonts;157 extern R2Fonts* g_fonts; 155 158 156 159 /* … … 316 319 // TBD 317 320 Volume* vol = volume[0]; 318 TransferFunction* tf = vol_render->get_volume_shading(vol);321 TransferFunction* tf = g_vol_render->get_volume_shading(vol); 319 322 if (tf) 320 323 { … … 324 327 } 325 328 Texture2D* plane = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data); 326 color_table_renderer->render(1024, 1024, plane, tf, vol->range_min(), vol->range_max());329 g_color_table_renderer->render(1024, 1024, plane, tf, vol->range_min(), vol->range_max()); 327 330 delete plane; 328 331 } … … 463 466 } 464 467 if (ivol < n_volumes) { 465 tf = vol_render->get_volume_shading(volume[ivol]);468 tf = g_vol_render->get_volume_shading(volume[ivol]); 466 469 } 467 470 if (tf == NULL) { … … 879 882 volume[n]->disable_cutplane(1); 880 883 volume[n]->disable_cutplane(2); 881 vol_render->add_volume(volume[n], get_transfunc("default"));884 g_vol_render->add_volume(volume[n], get_transfunc("default")); 882 885 883 886 return TCL_OK; … … 979 982 vector<int>::iterator iter = ivol.begin(); 980 983 while (iter != ivol.end()) { 981 vol_render->shade_volume(volume[*iter], tf);984 g_vol_render->shade_volume(volume[*iter], tf); 982 985 ++iter; 983 986 } … … 1097 1100 volume[n]->disable_cutplane(1); 1098 1101 volume[n]->disable_cutplane(2); 1099 vol_render->add_volume(volume[n], get_transfunc("default"));1102 g_vol_render->add_volume(volume[n], get_transfunc("default")); 1100 1103 1101 1104 return TCL_OK; … … 1110 1113 volume[n]->disable_cutplane(1); 1111 1114 volume[n]->disable_cutplane(2); 1112 vol_render->add_volume(volume[n], get_transfunc("default"));1115 g_vol_render->add_volume(volume[n], get_transfunc("default")); 1113 1116 1114 1117 return TCL_OK; … … 1388 1391 } 1389 1392 } 1390 1391 1392 void init_glew(){1393 GLenum err = glewInit();1394 if (GLEW_OK != err)1395 {1396 //glew init failed, exit.1397 fprintf(stderr, "Error: %s\n", glewGetErrorString(err));1398 getchar();1399 assert(false);1400 }1401 1402 fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));1403 }1404 1405 1406 1393 1407 1394 /* Load a 3D vector field from a dx-format file … … 1968 1955 // Tentatively 1969 1956 TransferFunction* tf = new TransferFunction(256, tfdefaultdata); 1970 vol_render->shade_volume(volume[index], tf);1957 g_vol_render->shade_volume(volume[index], tf); 1971 1958 } 1972 1959 … … 2007 1994 2008 1995 //Update the transfer function using local GUI in the non-server mode 2009 extern void update_tf_texture(){ 1996 void update_tf_texture() 1997 { 2010 1998 glutSetWindow(render_window); 2011 1999 … … 2027 2015 #ifdef EVENTLOG 2028 2016 float param[3] = {0,0,0}; 2029 Event* tmp = new Event(EVENT_ROTATE, param, get_time_interval());2017 Event* tmp = new Event(EVENT_ROTATE, param, NvGetTimeInterval()); 2030 2018 tmp->write(event_log); 2031 2019 delete tmp; … … 2143 2131 2144 2132 2145 void init_cg(){2146 cgSetErrorCallback(cgErrorCallback);2147 g_context = cgCreateContext();2148 2149 #ifdef NEW_CG2150 m_posvel_fprog = loadProgram(g_context, CG_PROFILE_FP40, CG_SOURCE, "/opt/nanovis/lib/shaders/update_pos_vel.cg");2151 m_posvel_timestep_param = cgGetNamedParameter(m_posvel_fprog, "timestep");2152 m_posvel_damping_param = cgGetNamedParameter(m_posvel_fprog, "damping");2153 m_posvel_gravity_param = cgGetNamedParameter(m_posvel_fprog, "gravity");2154 m_posvel_spherePos_param = cgGetNamedParameter(m_posvel_fprog, "spherePos");2155 m_posvel_sphereVel_param = cgGetNamedParameter(m_posvel_fprog, "sphereVel");2156 #endif2157 }2158 2159 2160 //switch shader to change render mode2161 void switch_shader(int choice){2162 2163 switch (choice){2164 case 0:2165 break;2166 2167 case 1:2168 break;2169 2170 default:2171 break;2172 }2173 }2174 2175 void init_particles(){2176 //random placement on a slice2177 float* data = new float[psys->psys_width * psys->psys_height * 4];2178 bzero(data, sizeof(float)*4* psys->psys_width * psys->psys_height);2179 2180 for (int i=0; i<psys->psys_width; i++){2181 for (int j=0; j<psys->psys_height; j++){2182 int index = i + psys->psys_height*j;2183 bool particle = rand() % 256 > 150;2184 //particle = true;2185 if(particle) /*&& i/float(psys->psys_width)>0.3 && i/float(psys->psys_width)<0.72186 && j/float(psys->psys_height)>0.1 && j/float(psys->psys_height)<0.4)*/2187 {2188 //assign any location (x,y,z) in range [0,1]2189 data[4*index] = lic_slice_x;2190 data[4*index+1]= j/float(psys->psys_height);2191 data[4*index+2]= i/float(psys->psys_width);2192 data[4*index+3]= 30; //shorter life span, quicker iterations2193 }2194 else2195 {2196 data[4*index] = 0;2197 data[4*index+1]= 0;2198 data[4*index+2]= 0;2199 data[4*index+3]= 0;2200 }2201 }2202 }2203 2204 psys->initialize((Particle*)data);2205 delete[] data;2206 }2207 2208 2209 2133 //init line integral convolution 2210 2134 void init_lic(){ … … 2216 2140 2217 2141 //init the particle system using vector field volume->[1] 2218 void init_particle_system(){ 2219 psys = new ParticleSystem(NMESH, NMESH, g_context, volume[1]->id, 2220 1./volume[1]->aspect_ratio_width, 2221 1./volume[1]->aspect_ratio_height, 2222 1./volume[1]->aspect_ratio_depth); 2223 2224 init_particles(); //fill initial particles 2225 } 2226 2227 2228 void make_test_2D_data(){ 2142 /* 2143 void init_particle_system() 2144 { 2145 psys = new ParticleSystem(NMESH, NMESH, g_context, volume[1]->id, 2146 1./volume[1]->aspect_ratio_width, 2147 1./volume[1]->aspect_ratio_height, 2148 1./volume[1]->aspect_ratio_depth); 2149 2150 init_particles(); //fill initial particles 2151 } 2152 */ 2153 2154 2155 void make_test_2D_data() 2156 { 2229 2157 2230 2158 int w = 300; … … 2248 2176 void initGL(void) 2249 2177 { 2250 g_fonts = new R2Fonts();2251 g_fonts->addFont("verdana", "verdana.fnt");2252 g_fonts->setFont("verdana");2253 2254 2178 //buffer to store data read from the screen 2255 2179 if (screen_buffer) { … … 2308 2232 2309 2233 //create volume renderer and add volumes to it 2310 vol_render = new VolumeRenderer(g_context); 2311 2312 color_table_renderer = new NvColorTableRenderer(); 2313 color_table_renderer->setFonts(g_fonts); 2234 g_vol_render = new VolumeRenderer(g_context); 2235 2314 2236 2315 2237 /* … … 2318 2240 memset(tmp_data, 0, 4*4*124); 2319 2241 TransferFunction* tmp_tf = new TransferFunction(124, tmp_data); 2320 vol_render->add_volume(volume[0], tmp_tf);2242 g_vol_render->add_volume(volume[0], tmp_tf); 2321 2243 volume[0]->get_cutplane(0)->enabled = false; 2322 2244 volume[0]->get_cutplane(1)->enabled = false; … … 2324 2246 2325 2247 //volume[1]->move(Vector3(0.5, 0.6, 0.7)); 2326 // vol_render->add_volume(volume[1], tmp_tf);2248 //g_vol_render->add_volume(volume[1], tmp_tf); 2327 2249 */ 2328 2250 … … 2710 2632 void idle() 2711 2633 { 2712 glutSetWindow(render_window); 2713 2634 glutSetWindow(render_window); 2714 2635 2715 2636 /* … … 2719 2640 nanosleep(&ts, 0); 2720 2641 */ 2721 2722 2642 2723 2643 #ifdef XINETD 2724 xinetd_listen();2644 xinetd_listen(); 2725 2645 #else 2726 glutPostRedisplay();2646 glutPostRedisplay(); 2727 2647 #endif 2728 2648 } … … 2815 2735 } 2816 2736 2817 2818 void soft_read_verts(){ 2737 /* 2738 void soft_read_verts() 2739 { 2819 2740 glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, vert); 2820 2741 //fprintf(stderr, "soft_read_vert"); … … 2844 2765 free(p); 2845 2766 } 2846 2847 2767 */ 2768 2769 /* 2848 2770 //display the content of a texture as a screen aligned quad 2849 void display_texture(NVISid tex, int width, int height){ 2771 void display_texture(NVISid tex, int width, int height) 2772 { 2850 2773 glPushMatrix(); 2851 2774 … … 2873 2796 assert(glGetError()==0); 2874 2797 } 2798 */ 2875 2799 2876 2800 2877 2801 //draw vertices in the main memory 2878 void soft_display_verts(){ 2802 /* 2803 void soft_display_verts() 2804 { 2879 2805 glDisable(GL_TEXTURE_2D); 2880 2806 glEnable(GL_BLEND); … … 2889 2815 //fprintf(stderr, "soft_display_vert"); 2890 2816 } 2891 2817 */ 2892 2818 2893 2819 #if 0 … … 2962 2888 2963 2889 2964 void draw_3d_axis(){ 2965 glDisable(GL_TEXTURE_2D); 2966 glEnable(GL_DEPTH_TEST); 2890 void draw_3d_axis() 2891 { 2892 glDisable(GL_TEXTURE_2D); 2893 glEnable(GL_DEPTH_TEST); 2967 2894 2968 2895 //draw axes … … 3044 2971 gluDeleteQuadric(obj); 3045 2972 3046 glEnable(GL_TEXTURE_2D);3047 glDisable(GL_DEPTH_TEST);3048 } 3049 3050 2973 glEnable(GL_TEXTURE_2D); 2974 glDisable(GL_DEPTH_TEST); 2975 } 2976 2977 /* 3051 2978 void draw_axis() 3052 2979 { 3053 3054 2980 glDisable(GL_TEXTURE_2D); 3055 2981 glEnable(GL_DEPTH_TEST); … … 3079 3005 glDisable(GL_DEPTH_TEST); 3080 3006 } 3007 */ 3081 3008 3082 3009 … … 3085 3012 void display() 3086 3013 { 3087 3088 assert(glGetError()==0); 3089 3090 //lic->convolve(); //flow line integral convolution 3091 //psys->advect(); //advect particles 3092 3093 // INSOO 3094 //offscreen_buffer_capture(); //enable offscreen render 3095 3096 //start final rendering 3097 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen 3098 3099 if (volume_mode) { 3100 //3D rendering mode 3101 glEnable(GL_TEXTURE_2D); 3102 glEnable(GL_DEPTH_TEST); 3103 3104 //camera setting activated 3105 cam->activate(); 3106 3107 //set up the orientation of items in the scene. 3108 glPushMatrix(); 3109 switch (updir) { 3110 case 1: // x 3111 glRotatef(90, 0, 0, 1); 3112 glRotatef(90, 1, 0, 0); 3113 break; 3114 3115 case 2: // y 3116 // this is the default 3117 break; 3118 3119 case 3: // z 3120 glRotatef(-90, 1, 0, 0); 3121 glRotatef(-90, 0, 0, 1); 3122 break; 3123 3124 case -1: // -x 3125 glRotatef(-90, 0, 0, 1); 3126 break; 3127 3128 case -2: // -y 3129 glRotatef(180, 0, 0, 1); 3130 glRotatef(-90, 0, 1, 0); 3131 break; 3132 3133 case -3: // -z 3134 glRotatef(90, 1, 0, 0); 3135 break; 3136 } 3137 3138 //now render things in the scene 3139 draw_3d_axis(); 3140 3141 //lic->render(); //display the line integral convolution result 3142 //soft_display_verts(); 3143 //perf->enable(); 3144 // psys->render(); 3145 //perf->disable(); 3146 //fprintf(stderr, "particle pixels: %d\n", perf->get_pixel_count()); 3147 //perf->reset(); 3148 3149 perf->enable(); 3150 vol_render->render_all(); 3151 perf->disable(); 3152 3153 glPopMatrix(); 3014 assert(glGetError()==0); 3015 3016 //lic->convolve(); //flow line integral convolution 3017 //psys->advect(); //advect particles 3018 3019 //start final rendering 3020 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen 3021 3022 if (volume_mode) 3023 { 3024 //3D rendering mode 3025 glEnable(GL_TEXTURE_2D); 3026 glEnable(GL_DEPTH_TEST); 3027 3028 //camera setting activated 3029 cam->activate(); 3030 3031 //set up the orientation of items in the scene. 3032 glPushMatrix(); 3033 switch (updir) { 3034 case 1: // x 3035 glRotatef(90, 0, 0, 1); 3036 glRotatef(90, 1, 0, 0); 3037 break; 3038 3039 case 2: // y 3040 // this is the default 3041 break; 3042 3043 case 3: // z 3044 glRotatef(-90, 1, 0, 0); 3045 glRotatef(-90, 0, 0, 1); 3046 break; 3047 3048 case -1: // -x 3049 glRotatef(-90, 0, 0, 1); 3050 break; 3051 3052 case -2: // -y 3053 glRotatef(180, 0, 0, 1); 3054 glRotatef(-90, 0, 1, 0); 3055 break; 3056 3057 case -3: // -z 3058 glRotatef(90, 1, 0, 0); 3059 break; 3060 } 3061 3062 //now render things in the scene 3063 draw_3d_axis(); 3064 3065 //lic->render(); //display the line integral convolution result 3066 //soft_display_verts(); 3067 //perf->enable(); 3068 //psys->render(); 3069 //perf->disable(); 3070 //fprintf(stderr, "particle pixels: %d\n", perf->get_pixel_count()); 3071 //perf->reset(); 3072 3073 perf->enable(); 3074 g_vol_render->render_all(); 3075 perf->disable(); 3076 3077 glPopMatrix(); 3154 3078 } 3155 3079 else { 3156 //2D rendering mode3157 perf->enable();3158 plane_render->render();3159 perf->disable();3080 //2D rendering mode 3081 perf->enable(); 3082 plane_render->render(); 3083 perf->disable(); 3160 3084 } 3161 3085 3162 3086 #ifdef XINETD 3163 float cost = perf->get_pixel_count();3164 write(3, &cost, sizeof(cost));3087 float cost = perf->get_pixel_count(); 3088 write(3, &cost, sizeof(cost)); 3165 3089 #endif 3166 perf->reset(); 3167 3168 /* 3169 #ifdef XINETD 3170 read_screen(); 3171 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 3172 #else 3173 display_offscreen_buffer(); //display the final rendering on screen 3174 read_screen(); 3175 glutSwapBuffers(); 3176 #endif 3177 */ 3090 perf->reset(); 3091 3178 3092 } 3179 3093 … … 3245 3159 case 'q': 3246 3160 #ifdef XINETD 3247 end_service(); 3161 //end_service(); 3162 NvExitService(); 3248 3163 #endif 3249 3164 exit(0); … … 3259 3174 case ',': 3260 3175 lic_slice_x+=0.05; 3261 init_particles();3176 //init_particles(); 3262 3177 break; 3263 3178 case '.': 3264 3179 lic_slice_x-=0.05; 3265 init_particles();3180 //init_particles(); 3266 3181 break; 3267 3182 case '1': 3268 advect = true;3183 //advect = true; 3269 3184 break; 3270 3185 case '2': 3271 psys_x+=0.05;3186 //psys_x+=0.05; 3272 3187 break; 3273 3188 case '3': 3274 psys_x-=0.05;3189 //psys_x-=0.05; 3275 3190 break; 3276 3191 case 'w': //zoom out … … 3295 3210 break; 3296 3211 case 'i': 3297 init_particles();3212 //init_particles(); 3298 3213 break; 3299 3214 case 'v': 3300 vol_render->switch_volume_mode();3215 g_vol_render->switch_volume_mode(); 3301 3216 break; 3302 3217 case 'b': 3303 vol_render->switch_slice_mode();3218 g_vol_render->switch_slice_mode(); 3304 3219 break; 3305 3220 case 'n': … … 3317 3232 if(log){ 3318 3233 float param[3] = {live_obj_x, live_obj_y, live_obj_z}; 3319 Event* tmp = new Event(EVENT_MOVE, param, get_time_interval());3234 Event* tmp = new Event(EVENT_MOVE, param, NvGetTimeInterval()); 3320 3235 tmp->write(event_log); 3321 3236 delete tmp; … … 3324 3239 } 3325 3240 3326 void motion(int x, int y){ 3241 void motion(int x, int y) 3242 { 3327 3243 3328 3244 int old_x, old_y; … … 3361 3277 #ifdef EVENTLOG 3362 3278 float param[3] = {live_rot_x, live_rot_y, live_rot_z}; 3363 Event* tmp = new Event(EVENT_ROTATE, param, get_time_interval());3364 /tmp->write(event_log);3279 Event* tmp = new Event(EVENT_ROTATE, param, NvGetTimeInterval()); 3280 tmp->write(event_log); 3365 3281 delete tmp; 3366 3282 #endif … … 3369 3285 } 3370 3286 3287 /* 3371 3288 #ifdef XINETD 3372 3289 void init_service(){ … … 3410 3327 return interval; 3411 3328 } 3329 */ 3412 3330 3413 3331 … … 3416 3334 { 3417 3335 #ifdef XINETD 3418 init_service();3336 NvInitService(); 3419 3337 #endif 3420 3338 … … 3439 3357 NvInit(); 3440 3358 3441 3442 3359 initGL(); 3443 3360 initTcl(); 3444 3361 3445 3446 3447 3362 #ifdef EVENTLOG 3448 init_event_log();3363 NvInitEventLog(); 3449 3364 #endif 3450 //event loop 3451 glutMainLoop(); 3452 #ifdef EVENTLOG 3453 end_event_log(); 3454 #endif 3455 3456 #ifdef XINETD 3457 end_service(); 3458 #endif 3365 //event loop 3366 glutMainLoop(); 3459 3367 3460 3368 NvExit();
Note: See TracChangeset
for help on using the changeset viewer.