Changeset 851 for trunk/vizservers


Ignore:
Timestamp:
Jan 10, 2008 7:10:49 PM (16 years ago)
Author:
vrinside
Message:

Got particle system and LIC (Line integral convolution) run.

Location:
trunk/vizservers/nanovis
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/vizservers/nanovis/Command.cpp

    r850 r851  
    5252#include "Camera.h"
    5353#include <RenderContext.h>
     54#include <NvLIC.h>
    5455
    5556// FOR testing new functions
     
    266267    NanoVis::bmp_write("nv>screenshot -bytes");
    267268
    268     // TEST
    269     NanoVis::bmp_write_to_file();
     269    //NanoVis::bmp_write_to_file();
    270270   
    271271    NanoVis::resize_offscreen_buffer(old_win_width, old_win_height);
     
    18661866    //  Generate the latest frame and send it back to the client
    18671867    //
     1868    if (NanoVis::licRenderer && NanoVis::licRenderer->isActivated())
     1869    {
     1870        NanoVis::licRenderer->convolve();
     1871    }
     1872
    18681873    if (NanoVis::particleRenderer && NanoVis::particleRenderer->isActivated())
    18691874    {
     
    18751880    NanoVis::display();
    18761881   
    1877 /*
    1878     // TEST
    1879     glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
    1880     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    1881     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     else
    1891     {
    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 
    19031882    // INSOO
    19041883#ifdef XINETD
  • trunk/vizservers/nanovis/Makefile.in

    r850 r851  
    5757        ImageLoaderFactory.o \
    5858        ImageLoaderImpl.o \
    59         Lic.o \
    6059        MainWindow.o \
    6160        Mat4x4.o \
     
    225224Camera.o: Camera.cpp Camera.h
    226225ScreenSnapper.o: ScreenSnapper.cpp ScreenSnapper.h define.h
    227 Lic.o: Lic.cpp Lic.h $(AUXSRC)
    228226Volume.o: Volume.cpp Volume.h $(AUXSRC)
    229227ZincBlendeVolume.o: ZincBlendeVolume.cpp ZincBlendeVolume.h $(AUXSRC)
  • trunk/vizservers/nanovis/Nv.cpp

    r848 r851  
    1919{
    2020    CGerror lastError = cgGetError();
     21
    2122    if(lastError) {
    2223        const char *listing = cgGetLastListing(g_context);
     
    2728        printf("Cg error, exiting...\n");
    2829        cgDestroyContext(g_context);
     30        fflush(stdout);
    2931        exit(-1);
    3032    }
    3133}
    3234
    33 //init line integral convolution
    34 
    35 
    36 //init line integral convolution
    37 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 slice
    51     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 iterations   
    67             }
    68             else
    69             {
    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 
    9835void NvInit(char* path)
    9936{
    100 
    101     //g_color_table_renderer = new NvColorTableRenderer();
    102     // INSOO
    103     //g_color_table_renderer->setFonts(g_fonts);
    104     //
    105 
    106 
    107 
    108     NvInitParticleRenderer();
    109    
    11037    printf("Nanovis GL Initialized\n");
    11138}
  • trunk/vizservers/nanovis/NvLIC.cpp

    r755 r851  
    44 *
    55 * ======================================================================
    6  *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
     6 *  AUTHOR:  Insoo Woo <iwoo@purdue.edu, Wei Qiao <qiaow@purdue.edu>
    77 *           Purdue Rendering and Perceptualization Lab (PURPL)
    88 *
     
    2121#include <R2/R2FilePath.h>
    2222#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
     25NvLIC::NvLIC(int _size, int _width, int _height, float _offset, CGcontext _context)
     26    : Renderable(Vector3(0.0f,0.0f,0.0f)),
     27    disListID(0),
    3128        width(_width),
    3229        height(_height),
    33         iframe(0),
     30        size(_size),
     31    scale(1.0f, 1.0f, 1.0f),
     32        offset(_offset),
     33    iframe(0),
    3434        Npat(64),
    35         alpha(0.12*255),
     35        alpha((int) 0.12*255),
    3636        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,
    4650                  GL_TEXTURE_WRAP_S, GL_REPEAT);
    47   glTexParameteri(GL_TEXTURE_2D,
     51    glTexParameteri(GL_TEXTURE_2D,
    4852                  GL_TEXTURE_WRAP_T, GL_REPEAT);
    49   glTexParameteri(GL_TEXTURE_2D,
     53    glTexParameteri(GL_TEXTURE_2D,
    5054                  GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    51   glTexParameteri(GL_TEXTURE_2D,
     55    glTexParameteri(GL_TEXTURE_2D,
    5256                  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,
    6980                  GL_TEXTURE_RECTANGLE_NV, slice_vector_tex, 0);
    7081
    7182
    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,
    85101                            GL_COLOR_ATTACHMENT0_EXT,
    86102                            GL_TEXTURE_2D, color_tex, 0);
    87103
    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
     120NvLIC::~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;
    115134}
    116135
    117136void NvLIC::make_patterns()
    118137{
     138    Trace("begin make_patterns\n");
     139
     140    disListID = glGenLists(Npat);
     141
     142    Trace("DisplayList : %d\n", disListID);
     143
    119144   int lut[256];
    120145   int phase[NPN][NPN];
     
    122147   int i, j, k, t;
    123148   
    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        }
    127155
    128156   for (k = 0; k < Npat; k++) {
     
    136164     }
    137165
    138      glNewList(k + 1, GL_COMPILE);
     166     glNewList(disListID + k, GL_COMPILE);
    139167     glBindTexture(GL_TEXTURE_2D, pattern_tex);
    140168     glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0,
     
    142170     glEndList();
    143171   }
     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");
    144177}
    145178
     
    147180void NvLIC::make_magnitudes()
    148181{
    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++){
    155187
    156188      float x=DM*i;
     
    160192     
    161193      //from green to red
    162       GLubyte r = floor(magnitude*255);
     194      GLubyte r = (GLubyte) floor(magnitude*255);
    163195      GLubyte g = 0;
    164196      GLubyte b = 255 - r;
     
    169201      mag[i][j][2] = b;
    170202      mag[i][j][3] = a;
     203        }
    171204    }
    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
     217void 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);
    211249   
    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}
    224267
    225268//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++) {
     269void 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++) {
    247299          y = DM*j;
    248300          glTexCoord2f(x1, y);
     
    253305          get_velocity(x2, y, &px, &py);
    254306          glVertex2f(px, py);
    255       }
    256       glEnd();
     307        }
     308        glEnd();
    257309   }
    258310   iframe = iframe + 1;
    259311
    260312   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);
    262319   glBegin(GL_QUAD_STRIP);
    263320      glTexCoord2f(0.0,  0.0);  glVertex2f(0.0, 0.0);
     
    266323      glTexCoord2f(tmax, tmax); glVertex2f(1.0, 1.0);
    267324   glEnd();
     325    glDisable(GL_TEXTURE_2D);
    268326
    269327   /*
     
    278336   glEnd();
    279337   */
     338
     339    /// INSOO ADDED
     340    glDisable(GL_ALPHA_TEST);
    280341
    281342   glDisable(GL_BLEND);
     
    294355   glEnd();
    295356   */
     357
     358   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     359
     360    glPopAttrib();
     361
     362    glPopMatrix();
     363    glMatrixMode(GL_PROJECTION);
     364    glPopMatrix();
     365    glMatrixMode(GL_MODELVIEW);
    296366}
    297367
     
    299369
    300370
    301 void NvLIC::display(){
    302 
     371void NvLIC::display()
     372{
    303373  glBindTexture(GL_TEXTURE_2D, color_tex);
    304374  glEnable(GL_TEXTURE_2D);
     
    306376  //draw line integral convolution quad
    307377  glEnable(GL_DEPTH_TEST);
     378
    308379  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);
    310384
    311385  glBegin(GL_QUADS);
     
    318392  glPopMatrix();
    319393
     394  glBindTexture(GL_TEXTURE_2D,0);
     395
    320396  glDisable(GL_DEPTH_TEST);
    321397  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
     433void 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}
    324442
    325443void NvLIC::get_velocity(float x, float y, float *px, float *py)
    326444{
    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];
    334453   r  = vx*vx + vy*vy;
     454
     455    //Trace("(vx vx) = (%f %f), r=%f, ", vx, vy, r);
    335456   if (r > dmax*dmax) {
    336457      r  = sqrt(r);
     
    338459      vy *= dmax/r;
    339460   }
     461
    340462   *px = x + vx;         
    341463   *py = y + vy;
     464
     465    //Trace("vel %f %f -> %f %f, (dmax = %f)\n", x, y, *px, *py, dmax);
    342466}
    343467
  • trunk/vizservers/nanovis/NvLIC.h

    r587 r851  
    3838
    3939private:
     40    unsigned int disListID;
     41
    4042  int width, height;
    4143  int size;             //the lic is a square of size, it can be stretched
     
    5153  float tmax;
    5254  float dmax;
     55    float max;
    5356
    5457  //CG shader parameters
     
    5760  CGparameter m_vel_tex_param_render_vel, m_plane_normal_param_render_vel;
    5861  CGprogram m_render_vel_fprog;
     62  CGparameter m_max_param;
    5963
    6064  NVISid color_tex, pattern_tex, mag_tex;
    6165  NVISid fbo, vel_fbo, slice_vector_tex;  //for projecting 3d vector to 2d vector on a plane
     66  NVISid vectorFieldID;
    6267
    6368  Volume* vector_field;
    6469
     70    /**
     71     * flag for rendering
     72     */
     73    bool _activate;
    6574public:
    6675  Vector3 normal; //the normal vector of the NvLIC plane,
    6776                  //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);
    7178  ~NvLIC();
    7279
    73   void convolve();
     80    /**
     81     * @brief project 3D vectors to a 2D slice for line integral convolution
     82     */
     83    void convolve();
     84
    7485  void display();       //display the convolution result
    7586  void render();
     
    8091  void set_offset(float v);
    8192
     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);
    8298};
    8399
     100inline void NvLIC::activate()
     101{
     102    _activate = true;
     103}
     104
     105inline void NvLIC::deactivate()
     106{
     107    _activate = false;
     108}
     109
     110inline bool NvLIC::isActivated() const
     111{
     112    return _activate;
     113}
     114
    84115#endif
  • trunk/vizservers/nanovis/NvParticleAdvectionShader.cpp

    r850 r851  
    3333    _posTexParam = cgGetNamedParameter(_cgFP, "pos_tex");
    3434    _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");
    4035}
    4136
  • trunk/vizservers/nanovis/NvParticleRenderer.cpp

    r850 r851  
    260260    glPushMatrix();
    261261
    262     glScaled(1./scale.x, 1./scale.y, 1./scale.z);
     262    glScaled(scale.x, scale.y, scale.z);
    263263
    264264    glEnableClientState(GL_VERTEX_ARRAY);
     
    276276void NvParticleRenderer::setVectorField(unsigned int texID, float scaleX, float scaleY, float scaleZ, float max)
    277277{
    278   _advectionShader->setScale(Vector3(scaleX, scaleY, scaleZ));
     278    scale.set(scaleX, scaleY, scaleZ);
     279  _advectionShader->setScale(scale);
    279280  _advectionShader->setVelocityVolume(texID, max);
    280281}
  • trunk/vizservers/nanovis/NvShader.cpp

    r776 r851  
    5050    }
    5151}
     52
     53void NvShader::setErrorCallback(NvCgCallbackFunction callback)
     54{
     55    cgSetErrorCallback(callback);
     56}
     57
     58
  • trunk/vizservers/nanovis/NvShader.h

    r776 r851  
    44#include <Cg/cg.h>
    55#include <Cg/cgGL.h>
     6
     7typedef void NvCgCallbackFunction(void);
    68
    79class NvShader {
     
    1820protected :
    1921    void resetPrograms();
     22
     23public :
     24    static void setErrorCallback(NvCgCallbackFunction callback);
    2025public :
    2126    /**
  • trunk/vizservers/nanovis/dxReader.cpp

    r850 r851  
    140140
    141141        float *data = new float[3*nx*ny*nz];
     142        memset(data, 0, sizeof(float) * 3 * nx * ny * nz);
    142143
    143144        std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl;
    144145
    145146        // 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;
    148149        double nzero_min = 0.0;
    149150        int ngen = 0;
     
    158159                    vy = yfield.value(xval,yval,zval);
    159160                    vz = zfield.value(xval,yval,zval);
    160                     //vx = 1;
    161                     //vy = 1;
    162                     vz = 0;
     161
    163162                    double vm = sqrt(vx*vx + vy*vy + vz*vz);
    164163
     
    178177
    179178        ngen = 0;
     179
    180180        // scale should be accounted.
    181181        for (ngen=0; ngen < npts; ngen++)
     
    184184        }
    185185
    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
    187188        delete [] data;
    188     } else {
     189    }
     190    else {
    189191        std::cerr << "WARNING: data not found in stream" << std::endl;
    190192    }
     
    195197 */
    196198Rappture::Outcome
    197 load_volume_stream2(int index, std::iostream& fin) {
     199load_volume_stream2(int index, std::iostream& fin)
     200{
    198201    Rappture::Outcome result;
    199202
  • trunk/vizservers/nanovis/nanovis.cpp

    r850 r851  
    3333#include "PointSet.h"
    3434#include "Util.h"
     35#include <NvLIC.h>
     36#include <Trace.h>
    3537
    3638#include "nanovis.h"
     
    8991NvParticleRenderer* NanoVis::particleRenderer = 0;
    9092graphics::RenderContext* NanoVis::renderContext = 0;
     93NvLIC* NanoVis::licRenderer = 0;
    9194
    9295// pointers to volumes, currently handle up to 10 volumes
     
    118121// in Command.cpp
    119122extern void xinetd_listen();
    120 extern void initTcl();
    121 
    122 
    123 // forward declarations
    124 //void init_particles();
    125 void get_slice_vectors();
     123extern void initTcl();
    126124
    127125//ParticleSystem* psys;
     
    144142
    145143PerfQuery* perf;                        //perfromance counter
    146 
    147 //Nvidia CG shaders and their parameters
    148 //INSOO
    149 //CGcontext g_context;
    150144
    151145CGprogram m_passthru_fprog;
     
    177171#endif /*XINETD*/
    178172
    179 // Image based flow visualization variables
    180173// Image based flow visualization slice location
    181174// 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 */
     175float NanoVis::lic_slice_x = 1.0f;
     176float NanoVis::lic_slice_y = 0.0f;
     177float NanoVis::lic_slice_z = 0.5f;
    195178
    196179/*
     
    263246    if(lastError) {
    264247        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");
    270253        cgDestroyContext(g_context);
    271254        exit(-1);
     
    536519}
    537520
    538 
    539 #ifdef notdef
    540 //init line integral convolution
    541 void
    542 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 particles
    560 }
    561 #endif
    562 
    563521void
    564522make_test_2D_data()
     
    586544
    587545    int index;
    588     bool particle;
     546    //bool particle;
    589547    for (int i=0; i<particleRenderer->psys_width; i++) {
    590548        for (int j=0; j<particleRenderer->psys_height; j++) {
     
    618576}
    619577
     578void 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
    620595void NanoVis::init(const char* path)
    621596{
     
    642617
    643618    NvInitCG();
    644 
     619    NvShader::setErrorCallback(CgErrorCallback);
     620
     621/*
    645622    fonts = new R2Fonts();
    646623    fonts->addFont("verdana", "verdana.fnt");
    647624    fonts->setFont("verdana");
     625*/
    648626
    649627    color_table_renderer = new NvColorTableRenderer();
     
    651629   
    652630    particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context);
     631    licRenderer = new NvLIC(NMESH, NPIX, NPIX, 0.5, g_context);
    653632
    654633    ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl());
     
    730709#endif
    731710
    732 
    733711   //create an 2D plane renderer
    734712   plane_render = new PlaneRenderer(g_context, win_width, win_height);
     
    748726NanoVis::read_screen()
    749727{
    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);
    753729}
    754730
     
    14221398        //now render things in the scene
    14231399        if (axis_on) {
    1424             draw_3d_axis();
    1425         }
    1426         if (grid->isVisible()) {
     1400                draw_3d_axis();
     1401            }
     1402
     1403        if (grid->isVisible()) {
    14271404            grid->render();
    14281405        }
    14291406       
     1407        if (licRenderer && licRenderer->isActivated())
     1408        {
     1409            licRenderer->render();
     1410        }
     1411
    14301412        if (particleRenderer && particleRenderer->isActivated())
    14311413        {
  • trunk/vizservers/nanovis/nanovis.h

    r850 r851  
    5454#include "PerfQuery.h"
    5555#include "Event.h"
    56 #include "Lic.h"
    5756#include "VolumeRenderer.h"
    5857#include "PlaneRenderer.h"
     
    9998};
    10099
     100class NvLIC;
     101
    101102class NanoVis {
    102103public:
     
    104105    static PointSetRenderer* pointset_renderer;
    105106    static NvParticleRenderer* particleRenderer;
     107    static NvLIC* licRenderer;
    106108    static vector<PointSet*> pointSet;
    107109    static PlaneRenderer* plane_render;
     
    121123    static int updir;
    122124    static Camera *cam;
     125
     126    static float lic_slice_x;
     127    static float lic_slice_y;
     128    static float lic_slice_z;
    123129
    124130    static bool axis_on;
     
    155161#endif
    156162};
     163
    157164#endif  /* __NANOVIS_H__ */
  • trunk/vizservers/nanovis/shaders/render_vel.cg

    r378 r851  
    1717float4 main(in float3 uvw : TEXCOORD0,
    1818            uniform sampler3D vel_tex,
    19             uniform float4 plane_normal
     19            uniform float4 plane_normal,
     20            uniform float vmax
    2021            ) : COLOR
    2122{
    22 
    2323    float3 ret;
    2424
    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);
    3234}
     35
  • trunk/vizservers/nanovis/shaders/update_pos.cg

    r850 r851  
    2323            ) : COLOR
    2424{
    25 
    2625    // get previous position and velocity
    2726    float4 pos = texRECT(pos_tex, uv);
     
    3231    float4 vel = float4(tex3D(vel_tex, pos.xyz).xyz, 0) - float4(0.5, 0.5, 0.5, 0.0f);
    3332    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;
    3736    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;
    4140
    4241    //not drawing if the particle is out of bound
Note: See TracChangeset for help on using the changeset viewer.