Changeset 580


Ignore:
Timestamp:
Feb 20, 2007 4:15:00 PM (17 years ago)
Author:
vrinside
Message:
 
Location:
trunk/gui/vizservers/nanovis
Files:
37 added
10 edited

Legend:

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

    r431 r580  
    1717#include "Camera.h"
    1818
    19 Camera::Camera(int w, int h,
     19Camera::Camera(int startx, int starty, int w, int h,
    2020                double loc_x, double loc_y, double loc_z,
    2121                double target_x, double target_y, double target_z,
    2222                int angle_x, int angle_y, int angle_z):
     23     startX(startx),
     24     startY(starty),
    2325         width(w),
    2426         height(h),
     
    4648void Camera::activate(){
    4749  //fprintf(stderr, "camera: %d, %d\n", width, height);
    48   glViewport(0, 0, width, height);
     50  glViewport(startX, startY, width, height);
    4951  glMatrixMode(GL_PROJECTION);
    5052  glLoadIdentity();
    51   gluPerspective(30, (GLdouble)width/(GLdouble)height, 0.1, 50.0);
     53  gluPerspective(30, (GLdouble)(width - startX)/(GLdouble)(height - startY), 0.1, 50.0);
    5254
    5355  glMatrixMode(GL_MODELVIEW);
     
    6365}
    6466
    65 void Camera::set_screen_size(int w, int h){
     67void Camera::set_screen_size(int sx, int sy, int w, int h){
    6668  width = w; height = h;
     69  startX = sx; startY = sy;
    6770}
  • trunk/gui/vizservers/nanovis/Camera.h

    r423 r580  
    3030        int width;      //screen size
    3131        int height;     //screen size
     32    int startX;
     33    int startY;
    3234
    3335        ~Camera();
    34         Camera(int w, int h,
     36        Camera(int startx, int starty, int w, int h,
    3537                double loc_x, double loc_y, double loc_z,
    3638                double target_x, double target_y, double target_z,
     
    4042        void rotate(double angle_x, double angle_y, double angle_z); //change target point
    4143        void activate();//make the camera setting active, this has to be called before drawing things.
    42         void set_screen_size(int w, int h);
     44        void set_screen_size(int startx, int starty, int w, int h);
    4345};
    4446
  • trunk/gui/vizservers/nanovis/Volume.h

    r524 r580  
    4040
    4141
    42 enum {CUBIC, ZINCBLENDE};
     42enum {CUBIC, VOLQD, ZINCBLENDE};
    4343
    4444
  • trunk/gui/vizservers/nanovis/VolumeRenderer.cpp

    r524 r580  
    3030}
    3131
    32 
    33 VolumeRenderer::~VolumeRenderer(){}
     32VolumeRenderer::~VolumeRenderer()
     33{
     34    delete m_zincBlendeShader;
     35    delete m_regularVolumeShader;
     36    delete m_volQDVolumeShader;
     37}
    3438
    3539//initialize the volume shaders
     
    4347
    4448  //volume rendering shader: one cubic volume
    45   m_one_volume_fprog = loadProgram(g_context, CG_PROFILE_FP30, CG_SOURCE, "/opt/nanovis/lib/shaders/one_volume.cg");
    46   m_vol_one_volume_param = cgGetNamedParameter(m_one_volume_fprog, "volume");
    47   //cgGLSetTextureParameter(m_vol_one_volume_param, _vol->id);
    48   m_tf_one_volume_param = cgGetNamedParameter(m_one_volume_fprog, "tf");
    49   //m_tf_cut_one_volume_param = cgGetNamedParameter(m_one_volume_fprog, "tf_cutplane");
    50   //cgGLSetTextureParameter(m_tf_one_volume_param, _tf->id);
    51   m_mvi_one_volume_param = cgGetNamedParameter(m_one_volume_fprog, "modelViewInv");
    52   m_mv_one_volume_param = cgGetNamedParameter(m_one_volume_fprog, "modelView");
    53   m_render_param_one_volume_param = cgGetNamedParameter(m_one_volume_fprog, "renderParameters");
    54 
    55 
     49  m_regularVolumeShader = new NvRegularVolumeShader();
    5650
    5751  //volume rendering shader: one zincblende orbital volume.
     
    6357  //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
    6458  //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
    65   m_zincblende_volume_fprog = loadProgram(g_context, CG_PROFILE_FP30, CG_SOURCE,
    66                                         "/opt/nanovis/lib/shaders/zincblende_volume.cg");
    67 
    68   m_zincblende_tf_param = cgGetNamedParameter(m_zincblende_volume_fprog, "tf");
    69   m_zincblende_volume_a_param = cgGetNamedParameter(m_zincblende_volume_fprog, "volumeA");
    70   m_zincblende_volume_b_param = cgGetNamedParameter(m_zincblende_volume_fprog, "volumeB");
    71   m_zincblende_cell_size_param = cgGetNamedParameter(m_zincblende_volume_fprog, "cellSize");
    72   m_zincblende_mvi_param = cgGetNamedParameter(m_zincblende_volume_fprog, "modelViewInv");
    73   m_zincblende_render_param = cgGetNamedParameter(m_zincblende_volume_fprog, "renderParameters");
    74 
     59  m_zincBlendeShader = new NvZincBlendeVolumeShader();
     60
     61  m_volQDVolumeShader = new NvVolQDVolumeShader();
    7562}
    7663
     
    125112
    126113
    127 void VolumeRenderer::render_all(){
     114void VolumeRenderer::render_all()
     115{
    128116  int total_rendered_slices = 0;
    129117
     
    239227
    240228    ConvexPolygon static_poly;
    241     for(int i=0; i<volume[volume_index]->get_cutplane_count(); i++){
     229    for(int i=0; i<volume[volume_index]->get_cutplane_count(); i++)
     230    {
    242231      if(!volume[volume_index]->cutplane_is_enabled(i))
    243232        continue;
     
    692681  {
    693682    //regular cubic volume
    694     //
    695 
    696     cgGLSetStateMatrixParameter(m_mvi_one_volume_param, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE);
    697     cgGLSetStateMatrixParameter(m_mv_one_volume_param, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
    698     cgGLSetTextureParameter(m_vol_one_volume_param, volume[volume_index]->id);
    699     cgGLSetTextureParameter(m_tf_one_volume_param, tf[volume_index]->id);
    700     //cgGLSetTextureParameter(m_tf_cut_one_volume_param, tf_cut[volume_index]->id);
    701     cgGLEnableTextureParameter(m_vol_one_volume_param);
    702     cgGLEnableTextureParameter(m_tf_one_volume_param);
    703     //cgGLEnableTextureParameter(m_tf_cut_one_volume_param);
    704 
    705     if(!slice_mode)
    706       cgGLSetParameter4f(m_render_param_one_volume_param,
    707                   volume[volume_index]->get_n_slice(),
    708                   volume[volume_index]->get_opacity_scale(),
    709                   volume[volume_index]->get_diffuse(),
    710                   volume[volume_index]->get_specular());
    711     else
    712       cgGLSetParameter4f(m_render_param_one_volume_param,
    713                   0.,
    714                   volume[volume_index]->get_opacity_scale(),
    715                   volume[volume_index]->get_diffuse(),
    716                   volume[volume_index]->get_specular());
    717 
    718     cgGLBindProgram(m_one_volume_fprog);
    719     cgGLEnableProfile(CG_PROFILE_FP30);
     683    m_regularVolumeShader->bind(tf[volume_index]->id, volume[volume_index], slice_mode);
    720684  }
    721685
    722686  else if (volume[volume_index]->volume_type == ZINCBLENDE)
    723687  {
    724     //zinc blende volume
    725     ZincBlendeVolume* vol = (ZincBlendeVolume*) volume[volume_index];
    726 
    727     cgGLSetStateMatrixParameter(m_zincblende_mvi_param, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE);
    728     cgGLSetTextureParameter(m_zincblende_tf_param, tf[volume_index]->id);
    729     cgGLSetParameter4f(m_zincblende_cell_size_param, vol->cell_size.x, vol->cell_size.y, vol->cell_size.z, 0.);
    730 
    731     cgGLSetTextureParameter(m_zincblende_volume_a_param, vol->zincblende_tex[0]->id);
    732     cgGLSetTextureParameter(m_zincblende_volume_b_param, vol->zincblende_tex[1]->id);
    733     cgGLEnableTextureParameter(m_zincblende_volume_a_param);
    734     cgGLEnableTextureParameter(m_zincblende_volume_b_param);
    735 
    736     if(!slice_mode)
    737       cgGLSetParameter4f(m_zincblende_render_param,
    738                   vol->get_n_slice(),
    739                   vol->get_opacity_scale(),
    740                   vol->get_diffuse(),
    741                   vol->get_specular());
    742     else
    743       cgGLSetParameter4f(m_zincblende_render_param,
    744                   0.,
    745                   vol->get_opacity_scale(),
    746                   vol->get_diffuse(),
    747                   vol->get_specular());
    748 
    749     cgGLBindProgram(m_zincblende_volume_fprog);
    750     cgGLEnableProfile(CG_PROFILE_FP30);
    751 
    752   }
    753 }
    754 
    755 
    756 void VolumeRenderer::deactivate_volume_shader(){
     688    m_zincBlendeShader->bind(tf[volume_index]->id, volume[volume_index], slice_mode);
     689  }
     690  else if (volume[volume_index]->volume_type == VOLQD)
     691  {
     692    m_volQDVolumeShader->bind(tf[volume_index]->id, volume[volume_index], slice_mode);
     693  }
     694}
     695
     696
     697void VolumeRenderer::deactivate_volume_shader()
     698{
    757699  cgGLDisableProfile(CG_PROFILE_VP30);
    758   cgGLDisableProfile(CG_PROFILE_FP30);
    759 
    760   cgGLDisableTextureParameter(m_vol_one_volume_param);
    761   cgGLDisableTextureParameter(m_tf_one_volume_param);
    762 
    763   cgGLDisableTextureParameter(m_zincblende_volume_a_param);
    764   cgGLDisableTextureParameter(m_zincblende_volume_b_param);
    765   cgGLDisableTextureParameter(m_zincblende_tf_param);
     700
     701  m_regularVolumeShader->unbind();
     702  m_zincBlendeShader->unbind();
    766703}
    767704
  • trunk/gui/vizservers/nanovis/VolumeRenderer.h

    r524 r580  
    3434#include "ZincBlendeVolume.h"
    3535#include "PerfQuery.h"
     36#include "NvRegularVolumeShader.h"
     37#include "NvVolQDVolumeShader.h"
     38#include "NvZincBlendeVolumeShader.h"
    3639
    3740using namespace std;
    3841
    39 class VolumeRenderer{
     42class VolumeRenderer {
    4043
    4144private:
     
    5255
    5356  //shader parameters for rendering a single cubic volume
    54   CGprogram m_one_volume_fprog;
    55   CGparameter m_vol_one_volume_param;
    56   CGparameter m_tf_one_volume_param;
    57   CGparameter m_mvi_one_volume_param;
    58   CGparameter m_mv_one_volume_param;
    59   CGparameter m_render_param_one_volume_param;
     57  NvRegularVolumeShader* m_regularVolumeShader;
     58  NvVolQDVolumeShader* m_volQDVolumeShader;
    6059
    6160
     
    6867  //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
    6968  //This is equivalent to rendering 4 unrelated data sets occupying the same space.
    70   CGprogram m_zincblende_volume_fprog;
    71   CGparameter m_zincblende_tf_param;  //four transfer functions
    72   CGparameter m_zincblende_volume_a_param, m_zincblende_volume_b_param; //two cubic volumes (one zincblende orbital)
    73   CGparameter m_zincblende_cell_size_param; //cell size in texture space
    74   CGparameter m_zincblende_mvi_param; //modelview inverse matrix
    75   CGparameter m_zincblende_render_param; //render parameters
     69  NvZincBlendeVolumeShader* m_zincBlendeShader;
     70 
    7671 
    7772 
  • trunk/gui/vizservers/nanovis/ZincBlendeVolume.cpp

    r524 r580  
    2222                                        int w, int h, int d, float s, int n,
    2323                                        float* dataVolumeA, float* dataVolumeB,
    24                                         double v0, double v1)
    25                 : Volume(x, y, z, w, h, d, s, n, dataVolumeA, v0, v1)
     24                                        double v0, double v1, const Vector3& cellSize)
     25                : Volume(x, y, z, w, h, d, s, n, dataVolumeA, v0, v1), cell_size(cellSize)
    2626{
    2727 
  • trunk/gui/vizservers/nanovis/ZincBlendeVolume.h

    r524 r580  
    3636                int width, int height, int depth, float size, int n_component,
    3737                float* dataVolumeA, float* dataVolumeB,
    38                 double vmin, double vmax);
     38                double vmin, double vmax, const Vector3& cellSize);
    3939
    4040        ~ZincBlendeVolume();
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r524 r580  
    2626#include <fcntl.h>
    2727
     28#include "Nv.h"
     29
    2830#include "nanovis.h"
    2931#include "RpField1D.h"
     
    3840#include "transfer-function/ColorPaletteWindow.h"
    3941#include "transfer-function/MainWindow.h"
     42#include "ZincBlendeVolume.h"
     43#include "NvLoadFile.h"
     44#include "NvVolQDVolume.h"
     45#include "NvColorTableRenderer.h"
     46
     47// R2 headers
     48#include <R2/R2FilePath.h>
     49#include <R2/R2Fonts.h>
    4050
    4151//render server
     
    4353VolumeRenderer* vol_render;
    4454PlaneRenderer* plane_render;
     55NvColorTableRenderer* color_table_renderer;
    4556Camera* cam;
    4657
     
    90101
    91102int render_window;              //the handle of the render window;
     103
    92104// forward declarations
    93105void init_particles();
     
    100112void bmp_header_add_int(unsigned char* header, int& pos, int data);
    101113void bmp_write(const char* cmd);
     114void bmp_write_to_file();
     115void display();
     116void read_screen();
    102117
    103118ParticleSystem* psys;
     
    130145
    131146//Nvidia CG shaders and their parameters
    132 CGcontext g_context;
     147//INSOO
     148//CGcontext g_context;
    133149
    134150CGprogram m_passthru_fprog;
    135151CGparameter m_passthru_scale_param, m_passthru_bias_param;
    136152
     153R2Fonts* g_fonts;
     154
     155/*
    137156CGprogram m_copy_texcoord_fprog;
    138 
    139157CGprogram m_one_volume_fprog;
    140158CGparameter m_vol_one_volume_param;
     
    143161CGparameter m_mv_one_volume_param;
    144162CGparameter m_render_param_one_volume_param;
    145 
     163*/
     164
     165/*
    146166CGprogram m_vert_std_vprog;
    147167CGparameter m_mvp_vert_std_param;
    148168CGparameter m_mvi_vert_std_param;
     169*/
    149170
    150171using namespace std;
     
    155176static Tcl_DString cmdbuffer;
    156177
     178static int ScreenShotCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    157179static int CameraCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    158180static int CutplaneCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
     
    257279                "\": should be aim, angle, or zoom", (char*)NULL);
    258280        return TCL_ERROR;
     281}
     282
     283/*
     284{
     285  glEnable(GL_TEXTURE_2D);
     286  glEnable(GL_BLEND);
     287
     288  glViewport(0, 0, 1024, 1024);
     289  glMatrixMode(GL_PROJECTION);
     290  glLoadIdentity();
     291  gluOrtho2D(0, render_width, 0, render_height);
     292  glMatrixMode(GL_MODELVIEW);
     293  glLoadIdentity();
     294
     295  glBegin(GL_QUADS);
     296  glTexCoord2f(0, 0); glVertex2f(30, 30);
     297  glTexCoord2f(1, 0); glVertex2f(1024 - 60, 30);
     298  glTexCoord2f(1, 1); glVertex2f(1024 - 60, 1024 - 60);
     299  glTexCoord2f(0, 1); glVertex2f(30, 1024 - 60);
     300  glEnd();
     301}
     302*/
     303
     304static int
     305ScreenShotCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     306{
     307    int old_win_width = win_width;
     308    int old_win_height = win_height;
     309#ifdef XINETD
     310    resize_offscreen_buffer(1024, 1024);
     311    cam->set_screen_size(30, 90, 1024 - 60, 1024 - 120);
     312    offscreen_buffer_capture();  //enable offscreen render
     313    display();
     314
     315    // TBD
     316    Volume* vol = volume[0];
     317    TransferFunction* tf = vol_render->get_volume_shading(vol);
     318    if (tf)
     319    {
     320        float data[512];
     321        for (int i=0; i < 256; i++) {
     322            data[i] = data[i+256] = (float)(i/255.0);
     323        }
     324        Texture2D* plane = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data);
     325        color_table_renderer->render(1024, 1024, plane, tf, vol->range_min(), vol->range_max());
     326        delete plane;
     327    }
     328
     329    read_screen();
     330    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     331    // INSOO
     332    // TBD
     333    bmp_write_to_file();
     334    //bmp_write("nv>screenshot -bytes");
     335    resize_offscreen_buffer(old_win_width, old_win_height);
     336#endif
     337
     338
     339        return TCL_OK;
    259340}
    260341
     
    415496    plane_render->render();
    416497
     498// INSOO
    417499    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer);
     500    //glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, screen_buffer); // INSOO's
    418501
    419502    std::ostringstream result;
     
    568651        }
    569652
     653        //INSOO
     654        FILE* f = fopen("/tmp/aa.cpp", "wt");
     655        fprintf(f, "float tfdata[] = {\n");
     656        fprintf(f, "    ");
     657        int num = nslots * 4;
     658        for (i=0; i < num; i++) {
     659            if (((i + 1) % 4) == 0)
     660            {
     661                fprintf(f, "\n    ");
     662            }
     663            fprintf(f, "%f, ", data[i]);
     664        }
     665        fclose(f);
     666
    570667        // find or create this transfer function
    571668        int newEntry;
     
    584681        return TCL_OK;
    585682    }
     683
     684
    586685    Tcl_AppendResult(interp, "bad option \"", argv[1],
    587686        "\": should be define", (char*)NULL);
     
    640739 * ----------------------------------------------------------------------
    641740 */
     741void NvLoadVolumeBinFile2(int index, char* filename);
    642742static int
    643743VolumeCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     
    9851085            ++iter;
    9861086        }
     1087        return TCL_OK;
     1088    }
     1089    else if (c == 'v' && strcmp(argv[1],"volqd") == 0) {
     1090        int n = n_volumes;
     1091
     1092        NvLoadVolumeBinFile(n, "/home/nanohub/vrinside/grid_1_0");
     1093
     1094        volume[n]->set_n_slice(256-n);
     1095        volume[n]->disable_cutplane(0);
     1096        volume[n]->disable_cutplane(1);
     1097        volume[n]->disable_cutplane(2);
     1098        vol_render->add_volume(volume[n], get_transfunc("default"));
     1099
     1100        return TCL_OK;
     1101    }
     1102    else if (c == 'z' && strcmp(argv[1],"zinc") == 0) {
     1103        int n = n_volumes;
     1104
     1105        NvLoadVolumeBinFile2(n, "/home/nanohub/vrinside/grid_1_0");
     1106
     1107        volume[n]->set_n_slice(256-n);
     1108        volume[n]->disable_cutplane(0);
     1109        volume[n]->disable_cutplane(1);
     1110        volume[n]->disable_cutplane(2);
     1111        vol_render->add_volume(volume[n], get_transfunc("default"));
     1112
     1113        return TCL_OK;
     1114    }
     1115    else if (c == 't' && strcmp(argv[1],"test2") == 0) {
     1116        volume[1]->disable_data();
     1117        volume[1]->disable();
    9871118        return TCL_OK;
    9881119    }
     
    18101941}
    18111942
     1943//INSOO
     1944extern float tfdefaultdata[];
     1945void load_volqd_volume(int index, int width, int height, int depth,
     1946    int n_component, float* data, double vmin, double vmax, Vector3& cellSize)
     1947{
     1948    while (n_volumes <= index) {
     1949        volume.push_back(NULL);
     1950        n_volumes++;
     1951    }
     1952
     1953    if (volume[index] != NULL) {
     1954        delete volume[index];
     1955        volume[index] = NULL;
     1956    }
     1957
     1958    volume[index] = new NvVolQDVolume(0.f, 0.f, 0.f, width, height, depth, 1.,
     1959                                 n_component, data, vmin, vmax, cellSize);
     1960
     1961    float dx0 = -0.5;
     1962    float dy0 = -0.5*height/width;
     1963    float dz0 = -0.5*depth/width;
     1964    volume[index]->move(Vector3(dx0, dy0, dz0));
     1965
     1966    // INSOO
     1967    // Tentatively
     1968    TransferFunction* tf = new TransferFunction(256, tfdefaultdata);
     1969    vol_render->shade_volume(volume[index], tf);
     1970}
     1971
     1972// INSOO
     1973void load_zinc_volume(int index, int width, int height, int depth,
     1974    int n_component, float* data, double vmin, double vmax, Vector3& cellSize)
     1975{
     1976    while (n_volumes <= index) {
     1977        volume.push_back(NULL);
     1978        n_volumes++;
     1979    }
     1980
     1981    if (volume[index] != NULL) {
     1982        delete volume[index];
     1983        volume[index] = NULL;
     1984    }
     1985
     1986    volume[index] = new ZincBlendeVolume(0.f, 0.f, 0.f, width, height, depth, 1.,
     1987                                 n_component, data, data, vmin, vmax, cellSize);
     1988
     1989    float dx0 = -0.5;
     1990    float dy0 = -0.5*height/width;
     1991    float dz0 = -0.5*depth/width;
     1992    volume[index]->move(Vector3(dx0, dy0, dz0));
     1993}
    18121994
    18131995// get a colormap 1D texture by name
     
    18522034
    18532035//initialize frame buffer objects for offscreen rendering
    1854 void init_offscreen_buffer(){
     2036void init_offscreen_buffer()
     2037{
    18552038
    18562039  //initialize final fbo for final display
     
    18962079
    18972080  //fprintf(stderr, "screen_buffer size: %d\n", sizeof(screen_buffer));
     2081  printf("screen_buffer size: %d %d\n", w, h);
    18982082
    18992083  if (screen_buffer) {
     
    19012085      screen_buffer = NULL;
    19022086  }
     2087
    19032088  screen_buffer = new unsigned char[4*win_width*win_height];
    19042089  assert(screen_buffer != NULL);
     
    19142099
    19152100  //change the camera setting
    1916   cam->set_screen_size(win_width, win_height);
     2101  cam->set_screen_size(0, 0, win_width, win_height);
    19172102  plane_render->set_screen_size(win_width, win_height);
    19182103
     
    20622247void initGL(void)
    20632248{
    2064    system_info();
    2065    init_glew();
     2249   g_fonts = new R2Fonts();
     2250   g_fonts->addFont("verdana", "verdana.fnt");
     2251   g_fonts->setFont("verdana");
    20662252
    20672253   //buffer to store data read from the screen
     
    20742260
    20752261   //create the camera with default setting
    2076    cam = new Camera(win_width, win_height,
     2262   cam = new Camera(0, 0, win_width, win_height,
    20772263                   live_obj_x, live_obj_y, live_obj_z,
    20782264                   0., 0., 100.,
     
    20822268   glShadeModel(GL_FLAT);
    20832269   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     2270
    20842271   glClearColor(0,0,0,1);
    20852272   glClear(GL_COLOR_BUFFER_BIT);
     
    21182305
    21192306   init_offscreen_buffer();    //frame buffer object for offscreen rendering
    2120    init_cg();   //create cg shader context
    21212307
    21222308   //create volume renderer and add volumes to it
    21232309   vol_render = new VolumeRenderer(g_context);
    21242310
     2311   color_table_renderer = new NvColorTableRenderer();
     2312   color_table_renderer->setFonts(g_fonts);
    21252313   
    21262314   /*
     
    21872375        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
    21882376
     2377    // get screenshot
     2378    Tcl_CreateCommand(interp, "screenshot", ScreenShotCmd,
     2379        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     2380
    21892381    // create a default transfer function
    21902382    if (Tcl_Eval(interp, def_transfunc) != TCL_OK) {
     
    21952387
    21962388
    2197 void read_screen(){
    2198   //glBindTexture(GL_TEXTURE_2D, 0);
    2199   //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
    2200  
     2389void read_screen()
     2390{
    22012391  glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer);
    22022392  assert(glGetError()==0);
     
    22532443}
    22542444
     2445// INSOO
     2446// FOR DEBUGGING
    22552447void
    2256 bmp_write(const char* cmd)
     2448bmp_write_to_file()
    22572449{
    22582450    unsigned char header[54];
     
    23172509    }
    23182510
     2511    FILE* f;
     2512    f = fopen("/tmp/image.bmp", "wb");
     2513    fwrite((void*) header, sizeof(header), 1, f);
     2514    fwrite((void*) screen_buffer, (3*win_width+pad)*win_height, 1, f);
     2515    fclose(f);
     2516}
     2517
     2518void
     2519bmp_write(const char* cmd)
     2520{
     2521    unsigned char header[54];
     2522    int pos = 0;
     2523    header[pos++] = 'B';
     2524    header[pos++] = 'M';
     2525
     2526    // BE CAREFUL:  BMP files must have an even multiple of 4 bytes
     2527    // on each scan line.  If need be, we add padding to each line.
     2528    int pad = 0;
     2529    if ((3*win_width) % 4 > 0) {
     2530        pad = 4 - ((3*win_width) % 4);
     2531    }
     2532
     2533    // file size in bytes
     2534    int fsize = (3*win_width+pad)*win_height + sizeof(header);
     2535    bmp_header_add_int(header, pos, fsize);
     2536
     2537    // reserved value (must be 0)
     2538    bmp_header_add_int(header, pos, 0);
     2539
     2540    // offset in bytes to start of bitmap data
     2541    bmp_header_add_int(header, pos, sizeof(header));
     2542
     2543    // size of the BITMAPINFOHEADER
     2544    bmp_header_add_int(header, pos, 40);
     2545
     2546    // width of the image in pixels
     2547    bmp_header_add_int(header, pos, win_width);
     2548
     2549    // height of the image in pixels
     2550    bmp_header_add_int(header, pos, win_height);
     2551
     2552    // 1 plane + (24 bits/pixel << 16)
     2553    bmp_header_add_int(header, pos, 1572865);
     2554
     2555    // no compression
     2556    // size of image for compression
     2557    bmp_header_add_int(header, pos, 0);
     2558    bmp_header_add_int(header, pos, 0);
     2559
     2560    // x pixels per meter
     2561    // y pixels per meter
     2562    bmp_header_add_int(header, pos, 0);
     2563    bmp_header_add_int(header, pos, 0);
     2564
     2565    // number of colors used (0 = compute from bits/pixel)
     2566    // number of important colors (0 = all colors important)
     2567    bmp_header_add_int(header, pos, 0);
     2568    bmp_header_add_int(header, pos, 0);
     2569
     2570    // BE CAREFUL: BMP format wants BGR ordering for screen data
     2571    unsigned char* scr = screen_buffer;
     2572    for (int row=0; row < win_height; row++) {
     2573        for (int col=0; col < win_width; col++) {
     2574            unsigned char tmp = scr[2];
     2575            scr[2] = scr[0];  // B
     2576            scr[0] = tmp;     // R
     2577            scr += 3;
     2578        }
     2579        scr += pad;  // skip over padding already in screen data
     2580    }
     2581
    23192582    std::ostringstream result;
    23202583    result << cmd << " " << fsize << "\n";
     
    23232586    write(0, header, sizeof(header));
    23242587    write(0, screen_buffer, (3*win_width+pad)*win_height);
     2588
    23252589}
    23262590
     
    23902654    //  Generate the latest frame and send it back to the client
    23912655    //
     2656    // INSOO
     2657    offscreen_buffer_capture();  //enable offscreen render
     2658
    23922659    display();
     2660
     2661    // INSOO
     2662#ifdef XINETD
     2663   read_screen();
     2664   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     2665#else
     2666   display_offscreen_buffer(); //display the final rendering on screen
     2667   read_screen();
     2668   glutSwapBuffers();
     2669#endif   
    23932670
    23942671#if DO_RLE
     
    24302707
    24312708/*----------------------------------------------------*/
    2432 void idle(){
     2709void idle()
     2710{
    24332711  glutSetWindow(render_window);
    24342712
     
    24502728
    24512729
    2452 void display_offscreen_buffer(){
     2730void display_offscreen_buffer()
     2731{
    24532732   glEnable(GL_TEXTURE_2D);
    24542733   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     
    24692748   glTexCoord2f(0, 1); glVertex2f(0, win_height);
    24702749   glEnd();
    2471 }
    2472 
    2473 void offscreen_buffer_capture(){
     2750
     2751}
     2752
     2753void offscreen_buffer_capture()
     2754{
    24742755   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
    24752756}
     
    27673048
    27683049
    2769 void draw_axis(){
     3050void draw_axis()
     3051{
    27703052
    27713053  glDisable(GL_TEXTURE_2D);
     
    28083090   //psys->advect(); //advect particles
    28093091
    2810    offscreen_buffer_capture();  //enable offscreen render
    2811    //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //enable onscreen render
     3092// INSOO
     3093   //offscreen_buffer_capture();  //enable offscreen render
    28123094
    28133095   //start final rendering
     
    28703152     glPopMatrix();
    28713153   }
    2872    else{
     3154   else {
    28733155     //2D rendering mode
    28743156     perf->enable();
     
    28773159   }
    28783160
    2879 
    28803161#ifdef XINETD
    28813162   float cost  = perf->get_pixel_count();
     
    28843165   perf->reset();
    28853166
    2886    display_offscreen_buffer(); //display the final rendering on screen
    2887 
     3167/*
    28883168#ifdef XINETD
    2889    read_screen();
     3169    read_screen();
     3170    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    28903171#else
    2891    //read_screen();
    2892 #endif   
    2893 
    2894    glutSwapBuffers();
     3172    display_offscreen_buffer(); //display the final rendering on screen
     3173    read_screen();
     3174    glutSwapBuffers();
     3175#endif
     3176*/
    28953177}
    28963178
     
    30893371void init_service(){
    30903372  //open log and map stderr to log file
    3091   xinetd_log = fopen("log.txt", "w");
     3373  xinetd_log = fopen("/tmp/log.txt", "w");
    30923374  close(2);
    30933375  dup2(fileno(xinetd_log), 2);
     
    31403422   
    31413423   glutInitWindowSize(win_width, win_height);
     3424
    31423425   glutInitWindowPosition(10, 10);
    31433426   render_window = glutCreateWindow(argv[0]);
     
    31453428
    31463429#ifndef XINETD
    3147    //MainTransferFunctionWindow * tf_window;
    3148    //tf_window = new MainTransferFunctionWindow();
    3149    //tf_window->mainInit();
    3150 
    31513430   glutMouseFunc(mouse);
    31523431   glutMotionFunc(motion);
    31533432   glutKeyboardFunc(keyboard);
    31543433#endif
     3434
    31553435   glutIdleFunc(idle);
    31563436   glutReshapeFunc(resize_offscreen_buffer);
    31573437
     3438   NvInit();
     3439
     3440
    31583441   initGL();
    31593442   initTcl();
     3443
     3444
    31603445
    31613446#ifdef EVENTLOG
     
    31693454
    31703455#ifdef XINETD
    3171    end_service();
     3456    end_service();
    31723457#endif
    31733458
    3174    return 0;
    3175 }
     3459    NvExit();
     3460
     3461    return 0;
     3462}
  • trunk/gui/vizservers/nanovis/shaders/zincblende_volume.cg

    r524 r580  
    2929  PixelOut OUT;
    3030
    31   float4 tex_coord = mul(modelViewInv, IN.TexCoord) + float4(0.5, 0.5, 0.5, 0.5);
     31  // INSOO
     32  //float4 tex_coord = mul(modelViewInv, IN.TexCoord) + float4(0.5, 0.5, 0.5, 0.5);
     33  float4 tex_coord = mul(modelViewInv, IN.TexCoord);
    3234  float4 twice_cell_size = cellSize * 2.0;
    3335       
  • trunk/gui/vizservers/nanovis/start_server

    r531 r580  
    1111export DISPLAY
    1212
    13 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/bin/X11:/opt/nanovis/bin
     13PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/bin/X11:/home/nanohub/vrinside/rappture/gui/vizservers
    1414export PATH
    1515
    16 LD_LIBRARY_PATH="/opt/render/lib:/lib:/usr/lib:/usr/local/lib"
    17 export LD_LIBRARY_PATH
     16#LD_LIBRARY_PATH="/opt/render/lib:/lib:/usr/lib:/usr/local/lib"
     17#export LD_LIBRARY_PATH
    1818
    19 exec /opt/nanovis/bin/nanoscale -l 4000 -b 4001 -s 172.18.3.255 -c /opt/nanovis/bin/nanovis > /dev/null 2>&1
     19exec /home/nanohub/vrinside/rappture/gui/vizservers/nanovis/nanoscale -l 2000 -b 2001 -s 128.210.189.255 -c "/home/nanohub/vrinside/rappture/gui/vizservers/nanovis/nanovis" > /dev/null 2>&1
Note: See TracChangeset for help on using the changeset viewer.