Changeset 851 for trunk/vizservers
- Timestamp:
- Jan 10, 2008 7:10:49 PM (16 years ago)
- Location:
- trunk/vizservers/nanovis
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/Command.cpp
r850 r851 52 52 #include "Camera.h" 53 53 #include <RenderContext.h> 54 #include <NvLIC.h> 54 55 55 56 // FOR testing new functions … … 266 267 NanoVis::bmp_write("nv>screenshot -bytes"); 267 268 268 // TEST 269 NanoVis::bmp_write_to_file(); 269 //NanoVis::bmp_write_to_file(); 270 270 271 271 NanoVis::resize_offscreen_buffer(old_win_width, old_win_height); … … 1866 1866 // Generate the latest frame and send it back to the client 1867 1867 // 1868 if (NanoVis::licRenderer && NanoVis::licRenderer->isActivated()) 1869 { 1870 NanoVis::licRenderer->convolve(); 1871 } 1872 1868 1873 if (NanoVis::particleRenderer && NanoVis::particleRenderer->isActivated()) 1869 1874 { … … 1875 1880 NanoVis::display(); 1876 1881 1877 /*1878 // TEST1879 glClearColor(1.0f, 0.0f, 1.0f, 1.0f);1880 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen1881 NanoVis::cam->activate();1882 1883 //glEnable(GL_COLOR_MATERIAL);1884 glEnable(GL_TEXTURE_RECTANGLE_NV);1885 //glEnable(GL_BLEND);1886 if (NanoVis::particleRenderer->flip)1887 {1888 glBindTexture(GL_TEXTURE_RECTANGLE_NV, NanoVis::particleRenderer->psys_tex[0]);1889 }1890 else1891 {1892 glBindTexture(GL_TEXTURE_RECTANGLE_NV, NanoVis::particleRenderer->psys_tex[1]);1893 }1894 1895 glColor3f(1.0f, 0.0f, 0.0f);1896 draw_quad(1, 1, 512, 512);1897 1898 glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);1899 glDisable(GL_TEXTURE_RECTANGLE_NV);1900 */1901 1902 1903 1882 // INSOO 1904 1883 #ifdef XINETD -
trunk/vizservers/nanovis/Makefile.in
r850 r851 57 57 ImageLoaderFactory.o \ 58 58 ImageLoaderImpl.o \ 59 Lic.o \60 59 MainWindow.o \ 61 60 Mat4x4.o \ … … 225 224 Camera.o: Camera.cpp Camera.h 226 225 ScreenSnapper.o: ScreenSnapper.cpp ScreenSnapper.h define.h 227 Lic.o: Lic.cpp Lic.h $(AUXSRC)228 226 Volume.o: Volume.cpp Volume.h $(AUXSRC) 229 227 ZincBlendeVolume.o: ZincBlendeVolume.cpp ZincBlendeVolume.h $(AUXSRC) -
trunk/vizservers/nanovis/Nv.cpp
r848 r851 19 19 { 20 20 CGerror lastError = cgGetError(); 21 21 22 if(lastError) { 22 23 const char *listing = cgGetLastListing(g_context); … … 27 28 printf("Cg error, exiting...\n"); 28 29 cgDestroyContext(g_context); 30 fflush(stdout); 29 31 exit(-1); 30 32 } 31 33 } 32 34 33 //init line integral convolution34 35 36 //init line integral convolution37 void NvInitLIC()38 {39 /*40 g_lic = new Lic(NMESH, win_width, win_height, 0.3, g_context, volume[1]->id,41 volume[1]->aspect_ratio_width,42 volume[1]->aspect_ratio_height,43 volume[1]->aspect_ratio_depth);44 */45 }46 47 void NvInitParticle()48 {49 /*50 //random placement on a slice51 float* data = new float[g_particleRenderer->psys_width * g_particleRenderer->psys_height * 4];52 bzero(data, sizeof(float)*4* g_particleRenderer->psys_width * g_particleRenderer->psys_height);53 54 int index;55 bool particle;56 for (int i=0; i<g_particleRenderer->psys_width; i++) {57 for (int j=0; j<g_particleRenderer->psys_height; j++) {58 index = i + g_particleRenderer->psys_height*j;59 particle = rand() % 256 > 150;60 if(particle)61 {62 //assign any location (x,y,z) in range [0,1]63 data[4*index] = lic_slice_x;64 data[4*index+1]= j/float(g_particleRenderer->psys_height);65 data[4*index+2]= i/float(g_particleRenderer->psys_width);66 data[4*index+3]= 30; //shorter life span, quicker iterations67 }68 else69 {70 data[4*index] = 0;71 data[4*index+1]= 0;72 data[4*index+2]= 0;73 data[4*index+3]= 0;74 }75 }76 }77 78 g_particleRenderer->initialize((Particle*)data);79 delete[] data;80 */81 }82 83 //init the particle system using vector field volume->[1]84 void NvInitParticleRenderer()85 {86 /*87 g_particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context,88 volume[1]->id,89 1./volume[1]->aspect_ratio_width,90 1./volume[1]->aspect_ratio_height,91 1./volume[1]->aspect_ratio_depth);92 93 NvInitParticle();94 */95 }96 97 98 35 void NvInit(char* path) 99 36 { 100 101 //g_color_table_renderer = new NvColorTableRenderer();102 // INSOO103 //g_color_table_renderer->setFonts(g_fonts);104 //105 106 107 108 NvInitParticleRenderer();109 110 37 printf("Nanovis GL Initialized\n"); 111 38 } -
trunk/vizservers/nanovis/NvLIC.cpp
r755 r851 4 4 * 5 5 * ====================================================================== 6 * AUTHOR: Wei Qiao <qiaow@purdue.edu>6 * AUTHOR: Insoo Woo <iwoo@purdue.edu, Wei Qiao <qiaow@purdue.edu> 7 7 * Purdue Rendering and Perceptualization Lab (PURPL) 8 8 * … … 21 21 #include <R2/R2FilePath.h> 22 22 #include "NvLIC.h" 23 24 NvLIC::NvLIC(int _size, int _width, int _height, float _offset, 25 CGcontext _context, NVISid _vector_field, 26 float scalex, float scaley, float scalez): 27 Renderable(Vector3(0.,0.,0.)), 28 size(_size), 29 offset(_offset), 30 m_g_context(_context), 23 #include <Trace.h> 24 25 NvLIC::NvLIC(int _size, int _width, int _height, float _offset, CGcontext _context) 26 : Renderable(Vector3(0.0f,0.0f,0.0f)), 27 disListID(0), 31 28 width(_width), 32 29 height(_height), 33 iframe(0), 30 size(_size), 31 scale(1.0f, 1.0f, 1.0f), 32 offset(_offset), 33 iframe(0), 34 34 Npat(64), 35 alpha( 0.12*255),35 alpha((int) 0.12*255), 36 36 tmax(NPIX/(SCALE*NPN)), 37 dmax(SCALE/NPIX) 38 { 39 scale = Vector3(scalex, scaley, scalez); 40 slice_vector = new float[size*size*4]; 41 42 //initialize the pattern texture 43 glGenTextures(1, &pattern_tex); 44 glBindTexture(GL_TEXTURE_2D, pattern_tex); 45 glTexParameteri(GL_TEXTURE_2D, 37 dmax(SCALE/NPIX), 38 max(1.0f), 39 m_g_context(_context), 40 vectorFieldID((NVISid) 0), 41 _activate(false) 42 { 43 slice_vector = new float[size*size*4]; 44 memset(slice_vector, 0, sizeof(float) * size * size * 4); 45 46 //initialize the pattern texture 47 glGenTextures(1, &pattern_tex); 48 glBindTexture(GL_TEXTURE_2D, pattern_tex); 49 glTexParameteri(GL_TEXTURE_2D, 46 50 GL_TEXTURE_WRAP_S, GL_REPEAT); 47 glTexParameteri(GL_TEXTURE_2D,51 glTexParameteri(GL_TEXTURE_2D, 48 52 GL_TEXTURE_WRAP_T, GL_REPEAT); 49 glTexParameteri(GL_TEXTURE_2D,53 glTexParameteri(GL_TEXTURE_2D, 50 54 GL_TEXTURE_MAG_FILTER, GL_LINEAR); 51 glTexParameteri(GL_TEXTURE_2D,55 glTexParameteri(GL_TEXTURE_2D, 52 56 GL_TEXTURE_MIN_FILTER, GL_LINEAR); 53 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 54 55 //initialize frame buffer objects 56 57 //render buffer for projecting 3D velocity onto a 2D plane 58 glGenFramebuffersEXT(1, &vel_fbo); 59 glGenTextures(1, &slice_vector_tex); 60 61 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 62 63 glBindTexture(GL_TEXTURE_RECTANGLE_NV, slice_vector_tex); 64 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 65 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 66 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 67 GL_FLOAT_RGBA32_NV, size, size, 0, GL_RGBA, GL_FLOAT, NULL); 68 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 57 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 58 59 //initialize frame buffer objects 60 //render buffer for projecting 3D velocity onto a 2D plane 61 glGenFramebuffersEXT(1, &vel_fbo); 62 glGenTextures(1, &slice_vector_tex); 63 64 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 65 66 glBindTexture(GL_TEXTURE_RECTANGLE_NV, slice_vector_tex); 67 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 68 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 69 70 // ADD INSOO 71 glTexParameteri(GL_TEXTURE_RECTANGLE_NV, 72 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 73 glTexParameteri(GL_TEXTURE_RECTANGLE_NV, 74 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 75 76 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 77 GL_FLOAT_RGBA32_NV, size, size, 0, GL_RGBA, GL_FLOAT, NULL); 78 79 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 69 80 GL_TEXTURE_RECTANGLE_NV, slice_vector_tex, 0); 70 81 71 82 72 //render buffer for the convolution 73 glGenFramebuffersEXT(1, &fbo); 74 glGenTextures(1, &color_tex); 75 76 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 77 78 //initialize color texture for lic 79 glBindTexture(GL_TEXTURE_2D, color_tex); 80 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 81 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 82 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, 83 GL_RGB, GL_INT, NULL); 84 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 83 //render buffer for the convolution 84 glGenFramebuffersEXT(1, &fbo); 85 glGenTextures(1, &color_tex); 86 87 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 88 89 //initialize color texture for lic 90 glBindTexture(GL_TEXTURE_2D, color_tex); 91 // INSOO 92 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 93 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 94 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 95 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 96 97 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, 98 GL_RGB, GL_INT, NULL); 99 100 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 85 101 GL_COLOR_ATTACHMENT0_EXT, 86 102 GL_TEXTURE_2D, color_tex, 0); 87 103 88 // Check framebuffer completeness at the end of initialization. 89 CHECK_FRAMEBUFFER_STATUS(); 90 assert(glGetError()==0); 91 92 R2string path = R2FilePath::getInstance()->getPath("render_vel.cg"); 93 m_render_vel_fprog = loadProgram(m_g_context, CG_PROFILE_FP30, CG_SOURCE, path); 94 m_vel_tex_param_render_vel = cgGetNamedParameter(m_render_vel_fprog, "vel_tex"); 95 m_plane_normal_param_render_vel = cgGetNamedParameter(m_render_vel_fprog, "plane_normal"); 96 cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vector_field); 97 98 get_slice(); 99 make_patterns(); 100 101 fprintf(stderr, "initialize lic ...\n"); 102 } 103 104 NvLIC::~NvLIC(){ 105 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 106 glDeleteTextures(1, &slice_vector_tex); 107 108 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 109 glDeleteTextures(1, &color_tex); 110 111 NVISid buffers[2] = {vel_fbo, fbo}; 112 glDeleteFramebuffersEXT(2, buffers); 113 114 delete slice_vector; 104 105 // Check framebuffer completeness at the end of initialization. 106 CHECK_FRAMEBUFFER_STATUS(); 107 108 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 109 110 R2string path = R2FilePath::getInstance()->getPath("render_vel.cg"); 111 m_render_vel_fprog = loadProgram(m_g_context, CG_PROFILE_FP30, CG_SOURCE, path); 112 m_vel_tex_param_render_vel = cgGetNamedParameter(m_render_vel_fprog, "vel_tex"); 113 m_plane_normal_param_render_vel = cgGetNamedParameter(m_render_vel_fprog, "plane_normal"); 114 m_max_param = cgGetNamedParameter(m_render_vel_fprog, "vmax"); 115 116 117 make_patterns(); 118 } 119 120 NvLIC::~NvLIC() 121 { 122 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 123 glDeleteTextures(1, &slice_vector_tex); 124 125 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 126 glDeleteTextures(1, &color_tex); 127 128 NVISid buffers[2] = {vel_fbo, fbo}; 129 glDeleteFramebuffersEXT(2, buffers); 130 131 glDeleteLists(disListID, Npat); 132 133 delete slice_vector; 115 134 } 116 135 117 136 void NvLIC::make_patterns() 118 137 { 138 Trace("begin make_patterns\n"); 139 140 disListID = glGenLists(Npat); 141 142 Trace("DisplayList : %d\n", disListID); 143 119 144 int lut[256]; 120 145 int phase[NPN][NPN]; … … 122 147 int i, j, k, t; 123 148 124 for (i = 0; i < 256; i++) lut[i] = i < 127 ? 0 : 255; 125 for (i = 0; i < NPN; i++) 126 for (j = 0; j < NPN; j++) phase[i][j] = rand() % 256; 149 for (i = 0; i < 256; i++) lut[i] = i < 127 ? 0 : 255; 150 for (i = 0; i < NPN; i++) 151 for (j = 0; j < NPN; j++) 152 { 153 phase[i][j] = rand() % 256; 154 } 127 155 128 156 for (k = 0; k < Npat; k++) { … … 136 164 } 137 165 138 glNewList( k + 1, GL_COMPILE);166 glNewList(disListID + k, GL_COMPILE); 139 167 glBindTexture(GL_TEXTURE_2D, pattern_tex); 140 168 glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, … … 142 170 glEndList(); 143 171 } 172 173 glBindTexture(GL_TEXTURE_2D, pattern_tex); 174 glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, 175 GL_RGBA, GL_UNSIGNED_BYTE, pat); 176 Trace("finish make_patterns\n"); 144 177 } 145 178 … … 147 180 void NvLIC::make_magnitudes() 148 181 { 149 150 GLubyte mag[NMESH][NMESH][4]; 151 152 //read vector filed 153 for(int i=0; i<NMESH; i++){ 154 for(int j=0; j<NMESH; j++){ 182 GLubyte mag[NMESH][NMESH][4]; 183 184 //read vector filed 185 for(int i=0; i<NMESH; i++){ 186 for(int j=0; j<NMESH; j++){ 155 187 156 188 float x=DM*i; … … 160 192 161 193 //from green to red 162 GLubyte r = floor(magnitude*255);194 GLubyte r = (GLubyte) floor(magnitude*255); 163 195 GLubyte g = 0; 164 196 GLubyte b = 255 - r; … … 169 201 mag[i][j][2] = b; 170 202 mag[i][j][3] = a; 203 } 171 204 } 172 } 173 174 glGenTextures(1, &mag_tex); 175 glBindTexture(GL_TEXTURE_2D, mag_tex); 176 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 180 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); 181 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NMESH, NMESH, 0, GL_RGBA, GL_UNSIGNED_BYTE, mag); 182 183 } 184 185 //project 3D vectors to a 2D slice for line integral convolution 186 void NvLIC::get_slice(){ 187 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 188 glBindTexture(GL_TEXTURE_RECTANGLE_NV, slice_vector_tex); 189 190 glClear(GL_COLOR_BUFFER_BIT); 191 192 glViewport(0, 0, NMESH, NMESH); 193 glMatrixMode(GL_PROJECTION); 194 glLoadIdentity(); 195 gluOrtho2D(0, NMESH, 0, NMESH); 196 glMatrixMode(GL_MODELVIEW); 197 glLoadIdentity(); 198 199 cgGLBindProgram(m_render_vel_fprog); 200 cgGLEnableTextureParameter(m_vel_tex_param_render_vel); 201 cgGLSetParameter4f(m_plane_normal_param_render_vel, 1., 1., 0., 0); 202 203 cgGLEnableProfile(CG_PROFILE_FP30); 204 glBegin(GL_QUADS); 205 glTexCoord3f(0., 0., offset); glVertex2f(0., 0.); 206 glTexCoord3f(1., 0., offset); glVertex2f(size, 0.); 207 glTexCoord3f(1., 1., offset); glVertex2f(size, size); 208 glTexCoord3f(0., 1., offset); glVertex2f(0., size); 209 glEnd(); 210 cgGLDisableProfile(CG_PROFILE_FP30); 205 206 glGenTextures(1, &mag_tex); 207 glBindTexture(GL_TEXTURE_2D, mag_tex); 208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 212 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); 213 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NMESH, NMESH, 0, GL_RGBA, GL_UNSIGNED_BYTE, mag); 214 glBindTexture(GL_TEXTURE_2D, 0); 215 } 216 217 void NvLIC::get_slice() 218 { 219 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 220 221 glClear(GL_COLOR_BUFFER_BIT); 222 223 glViewport(0, 0, size, size); 224 glMatrixMode(GL_PROJECTION); 225 glLoadIdentity(); 226 gluOrtho2D(0, size, 0, size); 227 glMatrixMode(GL_MODELVIEW); 228 glLoadIdentity(); 229 230 glEnable(GL_TEXTURE_3D); 231 glBindTexture(GL_TEXTURE_3D, vectorFieldID); 232 cgGLBindProgram(m_render_vel_fprog); 233 234 cgGLSetTextureParameter(m_vel_tex_param_render_vel, vectorFieldID); 235 cgGLEnableTextureParameter(m_vel_tex_param_render_vel); 236 cgGLSetParameter4f(m_plane_normal_param_render_vel, 1., 1., 0., 0); 237 cgGLSetParameter1f(m_max_param, max); 238 239 cgGLEnableProfile(CG_PROFILE_FP30); 240 241 glBegin(GL_QUADS); 242 glTexCoord3f(0., 0., offset); glVertex2f(0., 0.); 243 glTexCoord3f(1., 0., offset); glVertex2f(size, 0.); 244 glTexCoord3f(1., 1., offset); glVertex2f(size, size); 245 glTexCoord3f(0., 1., offset); glVertex2f(0., size); 246 glEnd(); 247 248 cgGLDisableProfile(CG_PROFILE_FP30); 211 249 212 cgGLDisableTextureParameter(m_vel_tex_param_render_vel); 213 214 //read the vectors 215 glReadPixels(0, 0, NMESH, NMESH, GL_RGBA, GL_FLOAT, slice_vector); 216 /* 217 for(int i=0; i<NMESH*NMESH; i++){ 218 fprintf(stderr, "%f,%f,%f,%f", slice_vector[4*i], slice_vector[4*i+1], slice_vector[4*i+2], slice_vector[4*i+3]); 219 } 220 */ 221 assert(glGetError()==0); 222 } 223 250 cgGLDisableTextureParameter(m_vel_tex_param_render_vel); 251 252 glBindTexture(GL_TEXTURE_3D, 0); 253 glDisable(GL_TEXTURE_3D); 254 255 //read the vectors 256 glReadPixels(0, 0, size, size, GL_RGBA, GL_FLOAT, slice_vector); 257 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 258 259 int lim = size * size * 4; 260 float* v= slice_vector; 261 for (int i = 0; i < lim; ++i) 262 { 263 if (isnan(*v)) *v = 0.0f; 264 ++v; 265 } 266 } 224 267 225 268 //line integral convolution 226 void NvLIC::convolve(){ 227 228 int i, j; 229 float x1, x2, y, px, py; 230 231 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 232 233 glViewport(0, 0, (GLsizei) NPIX, (GLsizei) NPIX); 234 glMatrixMode(GL_PROJECTION); 235 glLoadIdentity(); 236 glTranslatef(-1.0, -1.0, 0.0); 237 glScalef(2.0, 2.0, 1.0); 238 239 //sa = 0.010*cos(iframe*2.0*M_PI/200.0); 240 glBindTexture(GL_TEXTURE_2D, pattern_tex); 241 glEnable(GL_TEXTURE_2D); 242 sa = 0.01; 243 for (i = 0; i < NMESH-1; i++) { 244 x1 = DM*i; x2 = x1 + DM; 245 glBegin(GL_QUAD_STRIP); 246 for (j = 0; j < NMESH-1; j++) { 269 void NvLIC::convolve() 270 { 271 int i, j; 272 float x1, x2, y, px, py; 273 274 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 275 276 glMatrixMode(GL_PROJECTION); 277 glLoadIdentity(); 278 glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); 279 glViewport(0, 0, (GLsizei) NPIX, (GLsizei) NPIX); 280 //glTranslatef(-1.0, -1.0, 0.0); 281 //glScalef(2.0, 2.0, 1.0); 282 glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -10.0f, 10.0f); 283 284 glMatrixMode(GL_MODELVIEW); 285 glLoadIdentity(); 286 287 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 288 289 //sa = 0.010*cos(iframe*2.0*M_PI/200.0); 290 glEnable(GL_TEXTURE_2D); 291 glBindTexture(GL_TEXTURE_2D, pattern_tex); 292 sa = 0.01; 293 294 for (i = 0; i < NMESH-1; i++) 295 { 296 x1 = DM*i; x2 = x1 + DM; 297 glBegin(GL_QUAD_STRIP); 298 for (j = 0; j < NMESH-1; j++) { 247 299 y = DM*j; 248 300 glTexCoord2f(x1, y); … … 253 305 get_velocity(x2, y, &px, &py); 254 306 glVertex2f(px, py); 255 }256 glEnd();307 } 308 glEnd(); 257 309 } 258 310 iframe = iframe + 1; 259 311 260 312 glEnable(GL_BLEND); 261 glCallList(iframe % Npat + 1); 313 314 // INSOO ADD 315 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 316 317 glEnable(GL_TEXTURE_2D); 318 glCallList(iframe % Npat + disListID); 262 319 glBegin(GL_QUAD_STRIP); 263 320 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); … … 266 323 glTexCoord2f(tmax, tmax); glVertex2f(1.0, 1.0); 267 324 glEnd(); 325 glDisable(GL_TEXTURE_2D); 268 326 269 327 /* … … 278 336 glEnd(); 279 337 */ 338 339 /// INSOO ADDED 340 glDisable(GL_ALPHA_TEST); 280 341 281 342 glDisable(GL_BLEND); … … 294 355 glEnd(); 295 356 */ 357 358 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 359 360 glPopAttrib(); 361 362 glPopMatrix(); 363 glMatrixMode(GL_PROJECTION); 364 glPopMatrix(); 365 glMatrixMode(GL_MODELVIEW); 296 366 } 297 367 … … 299 369 300 370 301 void NvLIC::display() {302 371 void NvLIC::display() 372 { 303 373 glBindTexture(GL_TEXTURE_2D, color_tex); 304 374 glEnable(GL_TEXTURE_2D); … … 306 376 //draw line integral convolution quad 307 377 glEnable(GL_DEPTH_TEST); 378 308 379 glPushMatrix(); 309 glScalef(scale.x, scale.y, scale.z); 380 381 //glScalef(scale.x, scale.y, scale.z); 382 float w = 1.0f / scale.x; 383 glScalef(1.0f, 1.0f / scale.y / w, 1.0f / scale.z / w); 310 384 311 385 glBegin(GL_QUADS); … … 318 392 glPopMatrix(); 319 393 394 glBindTexture(GL_TEXTURE_2D,0); 395 320 396 glDisable(GL_DEPTH_TEST); 321 397 glDisable(GL_TEXTURE_2D); 322 } 323 398 399 } 400 /* 401 { 402 //Trace("RENDER LIC\n"); 403 //glBindTexture(GL_TEXTURE_2D, pattern_tex); 404 glCallList(1 % Npat + disListID); 405 glEnable(GL_TEXTURE_2D); 406 407 //draw line integral convolution quad 408 glEnable(GL_DEPTH_TEST); 409 410 glPushMatrix(); 411 412 glScalef(scale.x, scale.y, scale.z); 413 414 glColor3f(1, 0, 1); 415 glBegin(GL_QUADS); 416 glTexCoord2f(0, 0); glVertex3f(0, 0, offset); 417 glTexCoord2f(1, 0); glVertex3f(1, 0, offset); 418 glTexCoord2f(1, 1); glVertex3f(1, 1, offset); 419 glTexCoord2f(0, 1); glVertex3f(0, 1, offset); 420 glEnd(); 421 422 glPopMatrix(); 423 424 glBindTexture(GL_TEXTURE_2D,0); 425 glDisable(GL_TEXTURE_2D); 426 427 glDisable(GL_DEPTH_TEST); 428 glDisable(GL_TEXTURE_RECTANGLE_NV); 429 } 430 */ 431 432 433 void NvLIC::setVectorField(unsigned int texID, float scaleX, float scaleY, float scaleZ, float max) 434 { 435 Trace("NvLIC: vector field is assigned [%d]\n", texID); 436 vectorFieldID = texID; 437 scale = Vector3(scaleX, scaleY, scaleZ); 438 this->max = max; 439 440 get_slice(); 441 } 324 442 325 443 void NvLIC::get_velocity(float x, float y, float *px, float *py) 326 444 { 327 float dx, dy, vx, vy, r; 328 329 int xi = x*NMESH; 330 int yi = y*NMESH; 331 332 vx = slice_vector[4*(xi+yi*NMESH)]; 333 vy = slice_vector[4*(xi+yi*NMESH)+1]; 445 float vx, vy, r; 446 447 int xi = (int) (x*size); 448 int yi = (int) (y*size); 449 450 //Trace("(xi yi) = (%d %d), ", xi, yi); 451 vx = slice_vector[4 * (xi+yi*size)]; 452 vy = slice_vector[4 * (xi+yi*size)+1]; 334 453 r = vx*vx + vy*vy; 454 455 //Trace("(vx vx) = (%f %f), r=%f, ", vx, vy, r); 335 456 if (r > dmax*dmax) { 336 457 r = sqrt(r); … … 338 459 vy *= dmax/r; 339 460 } 461 340 462 *px = x + vx; 341 463 *py = y + vy; 464 465 //Trace("vel %f %f -> %f %f, (dmax = %f)\n", x, y, *px, *py, dmax); 342 466 } 343 467 -
trunk/vizservers/nanovis/NvLIC.h
r587 r851 38 38 39 39 private: 40 unsigned int disListID; 41 40 42 int width, height; 41 43 int size; //the lic is a square of size, it can be stretched … … 51 53 float tmax; 52 54 float dmax; 55 float max; 53 56 54 57 //CG shader parameters … … 57 60 CGparameter m_vel_tex_param_render_vel, m_plane_normal_param_render_vel; 58 61 CGprogram m_render_vel_fprog; 62 CGparameter m_max_param; 59 63 60 64 NVISid color_tex, pattern_tex, mag_tex; 61 65 NVISid fbo, vel_fbo, slice_vector_tex; //for projecting 3d vector to 2d vector on a plane 66 NVISid vectorFieldID; 62 67 63 68 Volume* vector_field; 64 69 70 /** 71 * flag for rendering 72 */ 73 bool _activate; 65 74 public: 66 75 Vector3 normal; //the normal vector of the NvLIC plane, 67 76 //the inherited Vector3 location is its center 68 NvLIC(int _size, int _width, int _height, float _offset, 69 CGcontext _context, NVISid _vector_field, 70 float scalex, float scaley, float scalez); 77 NvLIC(int _size, int _width, int _height, float _offset, CGcontext _context); 71 78 ~NvLIC(); 72 79 73 void convolve(); 80 /** 81 * @brief project 3D vectors to a 2D slice for line integral convolution 82 */ 83 void convolve(); 84 74 85 void display(); //display the convolution result 75 86 void render(); … … 80 91 void set_offset(float v); 81 92 93 void activate(); 94 void deactivate(); 95 bool isActivated() const; 96 97 void setVectorField(unsigned int texID, float scaleX, float scaleY, float scaleZ, float max); 82 98 }; 83 99 100 inline void NvLIC::activate() 101 { 102 _activate = true; 103 } 104 105 inline void NvLIC::deactivate() 106 { 107 _activate = false; 108 } 109 110 inline bool NvLIC::isActivated() const 111 { 112 return _activate; 113 } 114 84 115 #endif -
trunk/vizservers/nanovis/NvParticleAdvectionShader.cpp
r850 r851 33 33 _posTexParam = cgGetNamedParameter(_cgFP, "pos_tex"); 34 34 _scaleParam = cgGetNamedParameter(_cgFP, "scale"); 35 36 // TBD.37 //cgGLSetTextureParameter(_velTexParam, volume);38 //cgGLSetParameter3f(_scaleParam, scale.x, scale.y, scale.z);39 Trace("update_pos.cg loaded\n");40 35 } 41 36 -
trunk/vizservers/nanovis/NvParticleRenderer.cpp
r850 r851 260 260 glPushMatrix(); 261 261 262 glScaled( 1./scale.x, 1./scale.y, 1./scale.z);262 glScaled(scale.x, scale.y, scale.z); 263 263 264 264 glEnableClientState(GL_VERTEX_ARRAY); … … 276 276 void NvParticleRenderer::setVectorField(unsigned int texID, float scaleX, float scaleY, float scaleZ, float max) 277 277 { 278 _advectionShader->setScale(Vector3(scaleX, scaleY, scaleZ)); 278 scale.set(scaleX, scaleY, scaleZ); 279 _advectionShader->setScale(scale); 279 280 _advectionShader->setVelocityVolume(texID, max); 280 281 } -
trunk/vizservers/nanovis/NvShader.cpp
r776 r851 50 50 } 51 51 } 52 53 void NvShader::setErrorCallback(NvCgCallbackFunction callback) 54 { 55 cgSetErrorCallback(callback); 56 } 57 58 -
trunk/vizservers/nanovis/NvShader.h
r776 r851 4 4 #include <Cg/cg.h> 5 5 #include <Cg/cgGL.h> 6 7 typedef void NvCgCallbackFunction(void); 6 8 7 9 class NvShader { … … 18 20 protected : 19 21 void resetPrograms(); 22 23 public : 24 static void setErrorCallback(NvCgCallbackFunction callback); 20 25 public : 21 26 /** -
trunk/vizservers/nanovis/dxReader.cpp
r850 r851 140 140 141 141 float *data = new float[3*nx*ny*nz]; 142 memset(data, 0, sizeof(float) * 3 * nx * ny * nz); 142 143 143 144 std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl; 144 145 145 146 // generate the uniformly sampled data that we need for a volume 146 double vmin = 0.0;147 double vmax = 0.0;147 double vmin = 1e21; 148 double vmax = -1e21; 148 149 double nzero_min = 0.0; 149 150 int ngen = 0; … … 158 159 vy = yfield.value(xval,yval,zval); 159 160 vz = zfield.value(xval,yval,zval); 160 //vx = 1; 161 //vy = 1; 162 vz = 0; 161 163 162 double vm = sqrt(vx*vx + vy*vy + vz*vz); 164 163 … … 178 177 179 178 ngen = 0; 179 180 180 // scale should be accounted. 181 181 for (ngen=0; ngen < npts; ngen++) … … 184 184 } 185 185 186 NanoVis::load_volume(index, nx, ny, nz, 3, data, vmin, vmax, nzero_min); 186 NanoVis::load_volume(index, nx, ny, nz, 3, data, vmin, vmax, nzero_min); 187 187 188 delete [] data; 188 } else { 189 } 190 else { 189 191 std::cerr << "WARNING: data not found in stream" << std::endl; 190 192 } … … 195 197 */ 196 198 Rappture::Outcome 197 load_volume_stream2(int index, std::iostream& fin) { 199 load_volume_stream2(int index, std::iostream& fin) 200 { 198 201 Rappture::Outcome result; 199 202 -
trunk/vizservers/nanovis/nanovis.cpp
r850 r851 33 33 #include "PointSet.h" 34 34 #include "Util.h" 35 #include <NvLIC.h> 36 #include <Trace.h> 35 37 36 38 #include "nanovis.h" … … 89 91 NvParticleRenderer* NanoVis::particleRenderer = 0; 90 92 graphics::RenderContext* NanoVis::renderContext = 0; 93 NvLIC* NanoVis::licRenderer = 0; 91 94 92 95 // pointers to volumes, currently handle up to 10 volumes … … 118 121 // in Command.cpp 119 122 extern void xinetd_listen(); 120 extern void initTcl(); 121 122 123 // forward declarations 124 //void init_particles(); 125 void get_slice_vectors(); 123 extern void initTcl(); 126 124 127 125 //ParticleSystem* psys; … … 144 142 145 143 PerfQuery* perf; //perfromance counter 146 147 //Nvidia CG shaders and their parameters148 //INSOO149 //CGcontext g_context;150 144 151 145 CGprogram m_passthru_fprog; … … 177 171 #endif /*XINETD*/ 178 172 179 // Image based flow visualization variables180 173 // Image based flow visualization slice location 181 174 // FLOW 182 // TBD 183 static float lic_slice_x = 0.0f; 184 /* 185 static float lic_slice_y = 0.0f; 186 static float lic_slice_z = 0.3f; 187 188 static int iframe = 0; 189 static int Npat = 64; 190 static int alpha = (int)round(0.12*255); 191 static float sa; 192 static float tmax = NPIX/(SCALE*NPN); 193 static float dmax = SCALE/NPIX; 194 */ 175 float NanoVis::lic_slice_x = 1.0f; 176 float NanoVis::lic_slice_y = 0.0f; 177 float NanoVis::lic_slice_z = 0.5f; 195 178 196 179 /* … … 263 246 if(lastError) { 264 247 const char *listing = cgGetLastListing(g_context); 265 printf("\n---------------------------------------------------\n");266 printf("%s\n\n", cgGetErrorString(lastError));267 printf("%s\n", listing);268 printf("-----------------------------------------------------\n");269 printf("Cg error, exiting...\n");248 Trace("\n---------------------------------------------------\n"); 249 Trace("%s\n\n", cgGetErrorString(lastError)); 250 Trace("%s\n", listing); 251 Trace("-----------------------------------------------------\n"); 252 Trace("Cg error, exiting...\n"); 270 253 cgDestroyContext(g_context); 271 254 exit(-1); … … 536 519 } 537 520 538 539 #ifdef notdef540 //init line integral convolution541 void542 NanoVis::init_lic()543 {544 lic = new Lic(NMESH, win_width, win_height, 0.3, g_context, volume[1]->id,545 volume[1]->aspect_ratio_width,546 volume[1]->aspect_ratio_height,547 volume[1]->aspect_ratio_depth);548 }549 550 //init the particle system using vector field volume->[1]551 552 void init_particle_system()553 {554 psys = new ParticleSystem(NMESH, NMESH, g_context, volume[1]->id,555 1./volume[1]->aspect_ratio_width,556 1./volume[1]->aspect_ratio_height,557 1./volume[1]->aspect_ratio_depth);558 559 init_particles(); //fill initial particles560 }561 #endif562 563 521 void 564 522 make_test_2D_data() … … 586 544 587 545 int index; 588 bool particle;546 //bool particle; 589 547 for (int i=0; i<particleRenderer->psys_width; i++) { 590 548 for (int j=0; j<particleRenderer->psys_height; j++) { … … 618 576 } 619 577 578 void CgErrorCallback(void) 579 { 580 CGerror lastError = cgGetError(); 581 582 if(lastError) { 583 const char *listing = cgGetLastListing(g_context); 584 printf("\n---------------------------------------------------\n"); 585 printf("%s\n\n", cgGetErrorString(lastError)); 586 printf("%s\n", listing); 587 printf("-----------------------------------------------------\n"); 588 printf("Cg error, exiting...\n"); 589 cgDestroyContext(g_context); 590 fflush(stdout); 591 exit(-1); 592 } 593 } 594 620 595 void NanoVis::init(const char* path) 621 596 { … … 642 617 643 618 NvInitCG(); 644 619 NvShader::setErrorCallback(CgErrorCallback); 620 621 /* 645 622 fonts = new R2Fonts(); 646 623 fonts->addFont("verdana", "verdana.fnt"); 647 624 fonts->setFont("verdana"); 625 */ 648 626 649 627 color_table_renderer = new NvColorTableRenderer(); … … 651 629 652 630 particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context); 631 licRenderer = new NvLIC(NMESH, NPIX, NPIX, 0.5, g_context); 653 632 654 633 ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl()); … … 730 709 #endif 731 710 732 733 711 //create an 2D plane renderer 734 712 plane_render = new PlaneRenderer(g_context, win_width, win_height); … … 748 726 NanoVis::read_screen() 749 727 { 750 glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, 751 screen_buffer); 752 //assert(glGetError()==0); 728 glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer); 753 729 } 754 730 … … 1422 1398 //now render things in the scene 1423 1399 if (axis_on) { 1424 draw_3d_axis(); 1425 } 1426 if (grid->isVisible()) { 1400 draw_3d_axis(); 1401 } 1402 1403 if (grid->isVisible()) { 1427 1404 grid->render(); 1428 1405 } 1429 1406 1407 if (licRenderer && licRenderer->isActivated()) 1408 { 1409 licRenderer->render(); 1410 } 1411 1430 1412 if (particleRenderer && particleRenderer->isActivated()) 1431 1413 { -
trunk/vizservers/nanovis/nanovis.h
r850 r851 54 54 #include "PerfQuery.h" 55 55 #include "Event.h" 56 #include "Lic.h"57 56 #include "VolumeRenderer.h" 58 57 #include "PlaneRenderer.h" … … 99 98 }; 100 99 100 class NvLIC; 101 101 102 class NanoVis { 102 103 public: … … 104 105 static PointSetRenderer* pointset_renderer; 105 106 static NvParticleRenderer* particleRenderer; 107 static NvLIC* licRenderer; 106 108 static vector<PointSet*> pointSet; 107 109 static PlaneRenderer* plane_render; … … 121 123 static int updir; 122 124 static Camera *cam; 125 126 static float lic_slice_x; 127 static float lic_slice_y; 128 static float lic_slice_z; 123 129 124 130 static bool axis_on; … … 155 161 #endif 156 162 }; 163 157 164 #endif /* __NANOVIS_H__ */ -
trunk/vizservers/nanovis/shaders/render_vel.cg
r378 r851 17 17 float4 main(in float3 uvw : TEXCOORD0, 18 18 uniform sampler3D vel_tex, 19 uniform float4 plane_normal 19 uniform float4 plane_normal, 20 uniform float vmax 20 21 ) : COLOR 21 22 { 22 23 23 float3 ret; 24 24 25 float4 vel = float4(tex3D(vel_tex, uvw).xyz, 0); 26 ret.x = plane_normal.x * vel.x; 27 ret.y = plane_normal.y * vel.y; 28 ret.z = plane_normal.z * vel.z; 29 30 float3 tmp = ret*2.0 - float3(1,1,1); 31 return float4(tmp, 1); 25 float4 vel = float4(tex3D(vel_tex, uvw).xyz, 0) - float4(0.5, 0.5, 0.5, 0.0); 26 vel.x = vel.x * (vmax * 2); 27 vel.y = vel.y * (vmax * 2); 28 vel.z = vel.z * (vmax * 2); 29 ret.x = plane_normal.x * vel.x * 0.0005; 30 ret.y = plane_normal.y * vel.y * 0.0005; 31 ret.z = plane_normal.z * vel.z * 0.0005; 32 33 return float4(ret, 1); 32 34 } 35 -
trunk/vizservers/nanovis/shaders/update_pos.cg
r850 r851 23 23 ) : COLOR 24 24 { 25 26 25 // get previous position and velocity 27 26 float4 pos = texRECT(pos_tex, uv); … … 32 31 float4 vel = float4(tex3D(vel_tex, pos.xyz).xyz, 0) - float4(0.5, 0.5, 0.5, 0.0f); 33 32 vel = vel * (2 * max); 34 vel.x *= scale.x;35 vel.y *= scale.y;36 vel.z *= scale.z;33 //vel.x *= scale.x; 34 //vel.y *= scale.y; 35 //vel.z *= scale.z; 37 36 ret = pos; 38 ret.x -= vel.x * timestep;39 ret.y -= vel.y * timestep;40 ret.z -= vel.z * timestep;37 ret.x += vel.x * 0.0005; 38 ret.y += vel.y * 0.0005; 39 ret.z += vel.z * 0.0005; 41 40 42 41 //not drawing if the particle is out of bound
Note: See TracChangeset
for help on using the changeset viewer.