Changeset 587 for trunk


Ignore:
Timestamp:
Feb 22, 2007, 8:44:10 PM (17 years ago)
Author:
vrinside
Message:
 
Location:
trunk/gui/vizservers/nanovis
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/vizservers/nanovis/Lic.cpp

    r467 r587  
    340340}
    341341
    342 void Lic::set_offset(float v){
     342void Lic::set_offset(float v)
     343{
    343344  offset = v;
    344345  get_slice();
  • trunk/gui/vizservers/nanovis/Makefile

    r585 r587  
    66                NvZincBlendeVolumeShader.o NvShader.o NvVolumeShader.o NvRegularVolumeShader.o NvVolQDVolumeShader.o \
    77                NvLoadFile.o NvVolQDVolume.o NvDefaultTFData.o NvColorTableShader.o NvColorTableRenderer.o NvParticleAdvectionShader.o \
     8                NvEventLog.o NvParticleRenderer.o NvLIC.o \
    89                R2string.o R2FilePath.o R2Fonts.o R2Object.o
    910
     
    5253        gcc $(CFLAG) NvParticleAdvectionShader.cpp
    5354
     55NvParticleRenderer.o: NvParticleRenderer.cpp NvParticleRenderer.h
     56        gcc $(CFLAG) NvParticleRenderer.cpp
     57
    5458NvColorTableShader.o: NvColorTableShader.cpp NvColorTableShader.h
    5559        gcc $(CFLAG) NvColorTableShader.cpp
    5660
     61NvLIC.o: NvLIC.cpp NvLIC.h
     62        gcc $(CFLAG) NvLIC.cpp
     63
    5764NvColorTableRenderer.o: NvColorTableRenderer.cpp NvColorTableRenderer.h
    5865        gcc $(CFLAG) NvColorTableRenderer.cpp
     66
     67NvEventLog.o: NvEventLog.cpp NvEventLog.h
     68        gcc $(CFLAG) NvEventLog.cpp
    5969
    6070NvShader.o: NvShader.cpp NvShader.h
  • trunk/gui/vizservers/nanovis/Nv.cpp

    r582 r587  
    11#include "Nv.h"
    22#include "NvShader.h"
     3#include "NvParticleRenderer.h"
     4#include "NvColorTableRenderer.h"
     5#include "NvEventLog.h"
     6#include "VolumeRenderer.h"
    37#include <R2/R2FilePath.h>
    48#include <stdio.h>
     
    711
    812extern void NvInitCG(); // in NvShader.cpp
     13
     14NvParticleRenderer* g_particleRenderer;
     15NvColorTableRenderer* g_color_table_renderer;
     16VolumeRenderer* g_vol_render;
     17R2Fonts* g_fonts;
    918
    1019//query opengl information
     
    4554}
    4655
     56//init line integral convolution
     57void 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
     67void 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]
     104void 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
     117void NvInitVolumeRenderer()
     118{
     119}
     120
    47121void NvInit()
    48122{
     
    55129    NvInitGLEW();
    56130    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();
    57141   
    58142    printf("Nanovis GL Initialized\n");
     
    61145void NvExit()
    62146{
     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
    63161}
     162
  • trunk/gui/vizservers/nanovis/NvParticleAdvectionShader.h

    r585 r587  
    1919
    2020public :
    21     void bind();
     21    void bind(unsigned int texID);
    2222    void unbind();
    2323};
    2424
     25inline 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
     36inline void NvParticleAdvectionShader::unbind()
     37{
     38     cgGLDisableProfile(CG_PROFILE_FP30);
     39   
     40     cgGLDisableTextureParameter(_velTexParam);
     41     cgGLDisableTextureParameter(_posTexParam);
     42}
     43
    2544#endif //__NV_PARTICLE_ADV_SHADER_H__
  • trunk/gui/vizservers/nanovis/ParticleSystem.cpp

    r467 r587  
    2323
    2424ParticleSystem::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);
    2930 
    3031  psys_width = w;
     
    6465
    6566  //load related shaders
     67  /*
    6668  m_g_context = context;
    6769
     
    7375  cgGLSetTextureParameter(m_vel_tex_param, volume);
    7476  cgGLSetParameter3f(m_scale_param, scale_x, scale_y, scale_z);
     77  */
     78  _advectionShader = new NvParticleAdvectionShader(scale);
    7579
    7680  fprintf(stderr, "init_psys\n");
    7781}
    7882
    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);
     83ParticleSystem::~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
     96void 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
     112void 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
     125void ParticleSystem::advect()
     126{
     127    if (reborn)
     128        reset();
     129
     130    glDisable(GL_BLEND);
    124131   
    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     /*
    139148     cgGLBindProgram(m_pos_fprog);
    140149     cgGLSetParameter1f(m_pos_timestep_param, 0.05);
     
    144153
    145154     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     /*
    147158     cgGLDisableProfile(CG_PROFILE_FP30);
    148    
    149159     cgGLDisableTextureParameter(m_vel_tex_param);
    150160     cgGLDisableTextureParameter(m_pos_tex_param);
     161     */
    151162   }
    152163   else
    153164   {
    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     /*
    167180     cgGLBindProgram(m_pos_fprog);
    168181     cgGLSetParameter1f(m_pos_timestep_param, 0.05);
     
    170183     cgGLSetTextureParameter(m_pos_tex_param, psys_tex[1]);
    171184     cgGLEnableTextureParameter(m_pos_tex_param);
    172 
    173185     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     /*
    175191     cgGLDisableProfile(CG_PROFILE_FP30);
    176    
    177192     cgGLDisableTextureParameter(m_vel_tex_param);
    178193     cgGLDisableTextureParameter(m_pos_tex_param);
    179    }
     194     */
     195
     196    }
     197
     198    _advectionShader->unbind();
    180199
    181200   assert(glGetError()==0);
     
    184203   update_vertex_buffer();
    185204
    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    }
    193213
    194214   //fprintf(stderr, "advect: %d ", psys_frame);
    195215}
    196216
    197 
    198 void ParticleSystem::update_vertex_buffer(){
    199   m_vertex_array->Read(psys_width, psys_height);
     217void ParticleSystem::update_vertex_buffer()
     218{
     219    m_vertex_array->Read(psys_width, psys_height);
    200220  //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
     224void ParticleSystem::render()
     225{
     226    display_vertices();
     227}
     228
     229void 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  
    2929#include "Vector3.h"
    3030
    31 typedef struct Particle{
     31#include "NvParticleAdvectionShader.h"
     32
     33typedef struct Particle {
    3234  float x;
    3335  float y;
     
    4143
    4244
    43 class ParticleSystem : public Renderable{
     45class ParticleSystem : public Renderable {
    4446
    4547  NVISid psys_fbo[2];   //frame buffer objects: two are defined, flip them as input output every step
     
    5658
    5759  //Nvidia CG shaders and their parameters
     60  /*
    5861  CGcontext m_g_context;
    5962  CGprogram m_pos_fprog;
    6063  CGparameter m_vel_tex_param, m_pos_tex_param, m_scale_param;
    6164  CGparameter m_pos_timestep_param, m_pos_spherePos_param;
     65  */
     66  NvParticleAdvectionShader* _advectionShader;
    6267
    6368  Vector3 scale;
     
    7681  void reset();
    7782  void render();
    78 
    7983};
    8084
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r585 r587  
    4444#include "NvVolQDVolume.h"
    4545#include "NvColorTableRenderer.h"
     46#include "NvEventLog.h"
    4647
    4748// R2 headers
     
    5152//render server
    5253
    53 VolumeRenderer* vol_render;
     54extern VolumeRenderer* g_vol_render;
     55extern NvColorTableRenderer* g_color_table_renderer;
    5456PlaneRenderer* plane_render;
    55 NvColorTableRenderer* color_table_renderer;
    5657Camera* cam;
    5758
     
    8990}";
    9091
     92/*
    9193#ifdef XINETD
    9294FILE* xinetd_log;
     
    99101double cur_time;        //in seconds
    100102double get_time_interval();
     103*/
    101104
    102105int render_window;              //the handle of the render window;
    103106
    104107// forward declarations
    105 void init_particles();
     108//void init_particles();
    106109void get_slice_vectors();
    107110Rappture::Outcome load_volume_file(int index, char *fname);
     
    117120void read_screen();
    118121
    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;
    121124
    122125Lic* lic;
     
    126129NVISid final_fbo, final_color_tex, final_depth_rb;
    127130
    128 bool advect=false;
     131//bool advect=false;
    129132float vert[NMESH*NMESH*3];              //particle positions in main memory
    130133float slice_vector[NMESH*NMESH*4];      //per slice vectors in main memory
     
    152155CGparameter m_passthru_scale_param, m_passthru_bias_param;
    153156
    154 R2Fonts* g_fonts;
     157extern R2Fonts* g_fonts;
    155158
    156159/*
     
    316319    // TBD
    317320    Volume* vol = volume[0];
    318     TransferFunction* tf = vol_render->get_volume_shading(vol);
     321    TransferFunction* tf = g_vol_render->get_volume_shading(vol);
    319322    if (tf)
    320323    {
     
    324327        }
    325328        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());
    327330        delete plane;
    328331    }
     
    463466    }
    464467    if (ivol < n_volumes) {
    465         tf = vol_render->get_volume_shading(volume[ivol]);
     468        tf = g_vol_render->get_volume_shading(volume[ivol]);
    466469    }
    467470    if (tf == NULL) {
     
    879882            volume[n]->disable_cutplane(1);
    880883            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"));
    882885
    883886            return TCL_OK;
     
    979982            vector<int>::iterator iter = ivol.begin();
    980983            while (iter != ivol.end()) {
    981                 vol_render->shade_volume(volume[*iter], tf);
     984                g_vol_render->shade_volume(volume[*iter], tf);
    982985                ++iter;
    983986            }
     
    10971100        volume[n]->disable_cutplane(1);
    10981101        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"));
    11001103
    11011104        return TCL_OK;
     
    11101113        volume[n]->disable_cutplane(1);
    11111114        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"));
    11131116
    11141117        return TCL_OK;
     
    13881391    }
    13891392}
    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 
    14061393
    14071394/* Load a 3D vector field from a dx-format file
     
    19681955    // Tentatively
    19691956    TransferFunction* tf = new TransferFunction(256, tfdefaultdata);
    1970     vol_render->shade_volume(volume[index], tf);
     1957    g_vol_render->shade_volume(volume[index], tf);
    19711958}
    19721959
     
    20071994
    20081995//Update the transfer function using local GUI in the non-server mode
    2009 extern void update_tf_texture(){
     1996void update_tf_texture()
     1997{
    20101998  glutSetWindow(render_window);
    20111999
     
    20272015#ifdef EVENTLOG
    20282016  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());
    20302018  tmp->write(event_log);
    20312019  delete tmp;
     
    21432131
    21442132
    2145 void init_cg(){
    2146     cgSetErrorCallback(cgErrorCallback);
    2147     g_context = cgCreateContext();
    2148 
    2149 #ifdef NEW_CG
    2150     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 #endif
    2157 }
    2158 
    2159 
    2160 //switch shader to change render mode
    2161 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 slice
    2177   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.7
    2186                       && 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 iterations   
    2193       }
    2194       else
    2195       {
    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 
    22092133//init line integral convolution
    22102134void init_lic(){
     
    22162140
    22172141//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/*
     2143void 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
     2155void make_test_2D_data()
     2156{
    22292157
    22302158  int w = 300;
     
    22482176void initGL(void)
    22492177{
    2250    g_fonts = new R2Fonts();
    2251    g_fonts->addFont("verdana", "verdana.fnt");
    2252    g_fonts->setFont("verdana");
    2253 
    22542178   //buffer to store data read from the screen
    22552179   if (screen_buffer) {
     
    23082232
    23092233   //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
    23142236   
    23152237   /*
     
    23182240   memset(tmp_data, 0, 4*4*124);
    23192241   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);
    23212243   volume[0]->get_cutplane(0)->enabled = false;
    23222244   volume[0]->get_cutplane(1)->enabled = false;
     
    23242246
    23252247   //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);
    23272249   */
    23282250
     
    27102632void idle()
    27112633{
    2712   glutSetWindow(render_window);
    2713 
     2634    glutSetWindow(render_window);
    27142635 
    27152636  /*
     
    27192640  nanosleep(&ts, 0);
    27202641  */
    2721  
    27222642
    27232643#ifdef XINETD
    2724   xinetd_listen();
     2644    xinetd_listen();
    27252645#else
    2726   glutPostRedisplay();
     2646    glutPostRedisplay();
    27272647#endif
    27282648}
     
    28152735}
    28162736
    2817 
    2818 void soft_read_verts(){
     2737/*
     2738void soft_read_verts()
     2739{
    28192740  glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, vert);
    28202741  //fprintf(stderr, "soft_read_vert");
     
    28442765  free(p);
    28452766}
    2846 
    2847 
     2767*/
     2768
     2769/*
    28482770//display the content of a texture as a screen aligned quad
    2849 void display_texture(NVISid tex, int width, int height){
     2771void display_texture(NVISid tex, int width, int height)
     2772{
    28502773   glPushMatrix();
    28512774
     
    28732796   assert(glGetError()==0);
    28742797}
     2798*/
    28752799
    28762800
    28772801//draw vertices in the main memory
    2878 void soft_display_verts(){
     2802/*
     2803void soft_display_verts()
     2804{
    28792805  glDisable(GL_TEXTURE_2D);
    28802806  glEnable(GL_BLEND);
     
    28892815  //fprintf(stderr, "soft_display_vert");
    28902816}
    2891 
     2817*/
    28922818
    28932819#if 0
     
    29622888
    29632889
    2964 void draw_3d_axis(){
    2965   glDisable(GL_TEXTURE_2D);
    2966   glEnable(GL_DEPTH_TEST);
     2890void draw_3d_axis()
     2891{
     2892    glDisable(GL_TEXTURE_2D);
     2893    glEnable(GL_DEPTH_TEST);
    29672894
    29682895        //draw axes
     
    30442971        gluDeleteQuadric(obj);
    30452972
    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/*
    30512978void draw_axis()
    30522979{
    3053 
    30542980  glDisable(GL_TEXTURE_2D);
    30552981  glEnable(GL_DEPTH_TEST);
     
    30793005  glDisable(GL_DEPTH_TEST);
    30803006}
     3007*/
    30813008
    30823009
     
    30853012void display()
    30863013{
    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();
    31543078   }
    31553079   else {
    3156      //2D rendering mode
    3157      perf->enable();
    3158        plane_render->render();
    3159      perf->disable();
     3080        //2D rendering mode
     3081        perf->enable();
     3082        plane_render->render();
     3083        perf->disable();
    31603084   }
    31613085
    31623086#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));
    31653089#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
    31783092}
    31793093
     
    32453159        case 'q':
    32463160#ifdef XINETD
    3247                 end_service();
     3161        //end_service();
     3162        NvExitService();
    32483163#endif
    32493164                exit(0);
     
    32593174        case ',':
    32603175                lic_slice_x+=0.05;
    3261                 init_particles();
     3176                //init_particles();
    32623177                break;
    32633178        case '.':
    32643179                lic_slice_x-=0.05;
    3265                 init_particles();
     3180                //init_particles();
    32663181                break;
    32673182        case '1':
    3268                 advect = true;
     3183                //advect = true;
    32693184                break;
    32703185        case '2':
    3271                 psys_x+=0.05;
     3186                //psys_x+=0.05;
    32723187                break;
    32733188        case '3':
    3274                 psys_x-=0.05;
     3189                //psys_x-=0.05;
    32753190                break;
    32763191        case 'w': //zoom out
     
    32953210                break;
    32963211        case 'i':
    3297                 init_particles();
     3212                //init_particles();
    32983213                break;
    32993214        case 'v':
    3300                 vol_render->switch_volume_mode();
     3215                g_vol_render->switch_volume_mode();
    33013216                break;
    33023217        case 'b':
    3303                 vol_render->switch_slice_mode();
     3218                g_vol_render->switch_slice_mode();
    33043219                break;
    33053220        case 'n':
     
    33173232   if(log){
    33183233     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());
    33203235     tmp->write(event_log);
    33213236     delete tmp;
     
    33243239}
    33253240
    3326 void motion(int x, int y){
     3241void motion(int x, int y)
     3242{
    33273243
    33283244    int old_x, old_y;   
     
    33613277#ifdef EVENTLOG
    33623278    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);
    33653281    delete tmp;
    33663282#endif
     
    33693285}
    33703286
     3287/*
    33713288#ifdef XINETD
    33723289void init_service(){
     
    34103327  return interval;
    34113328}
     3329*/
    34123330
    34133331
     
    34163334{
    34173335#ifdef XINETD
    3418    init_service();
     3336   NvInitService();
    34193337#endif
    34203338
     
    34393357   NvInit();
    34403358
    3441 
    34423359   initGL();
    34433360   initTcl();
    34443361
    3445 
    3446 
    34473362#ifdef EVENTLOG
    3448    init_event_log();
     3363   NvInitEventLog();
    34493364#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();
    34593367
    34603368    NvExit();
Note: See TracChangeset for help on using the changeset viewer.