Ignore:
Timestamp:
Mar 8, 2007 5:56:29 PM (17 years ago)
Author:
vrinside
Message:

Added new zinc blende renderer - It is still needed to compare with unicell based simulation data.
Removed tentatively used class, NvVolQDVolumeShader,NvVolQDVolume
Moved Font.bmp into resources directory

Location:
trunk/gui/vizservers/nanovis
Files:
3 added
5 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/vizservers/nanovis/Makefile

    r604 r617  
    44                ColorGradientGLUTWindow.o TransferFunctionGLUTWindow.o MainWindow.o Event.o \
    55                Lic.o Renderable.o Camera.o ScreenSnapper.o VolumeRenderer.o PlaneRenderer.o Nv.o \
    6                 NvZincBlendeVolumeShader.o NvShader.o NvVolumeShader.o NvRegularVolumeShader.o NvVolQDVolumeShader.o \
    7                 NvLoadFile.o NvVolQDVolume.o NvDefaultTFData.o NvColorTableShader.o NvColorTableRenderer.o NvParticleAdvectionShader.o \
    8                 NvEventLog.o NvParticleRenderer.o NvLIC.o NvZincBlendeReconstructor.o \
     6                NvZincBlendeVolumeShader.o NvShader.o NvVolumeShader.o NvRegularVolumeShader.o \
     7                NvLoadFile.o NvDefaultTFData.o NvColorTableShader.o NvColorTableRenderer.o NvParticleAdvectionShader.o \
     8                NvEventLog.o NvParticleRenderer.o NvLIC.o NvZincBlendeReconstructor.o NvStdVertexShader.o \
    99                R2string.o R2FilePath.o R2Fonts.o R2Object.o
    1010
     
    4646        gcc $(CFLAG) Nv.cpp
    4747
     48NvStdVertexShader.o: NvStdVertexShader.cpp NvStdVertexShader.h
     49        gcc $(CFLAG) NvStdVertexShader.cpp
     50
    4851NvLoadFile.o: NvLoadFile.cpp NvLoadFile.cpp
    4952        gcc $(CFLAG) NvLoadFile.cpp
     
    7578NvDefaultTFData.o: NvDefaultTFData.cpp
    7679        gcc $(CFLAG) NvDefaultTFData.cpp
    77 
    78 NvVolQDVolume.o: NvVolQDVolume.cpp NvVolQDVolume.h
    79         gcc $(CFLAG) NvVolQDVolume.cpp
    80 
    81 NvVolQDVolumeShader.o: NvVolQDVolumeShader.cpp NvVolQDVolumeShader.h
    82         gcc $(CFLAG) NvVolQDVolumeShader.cpp
    8380
    8481NvRegularVolumeShader.o: NvRegularVolumeShader.cpp NvRegularVolumeShader.h
  • trunk/gui/vizservers/nanovis/NvLoadFile.cpp

    r580 r617  
    55#include <assert.h>
    66
    7 extern void load_volqd_volume(int index, int width, int height, int depth,
    8     int n_component, float* data, double vmin, double vmax, Vector3& cellSize);
    9 
    10 extern void load_zinc_volume(int index, int width, int height, int depth,
    11     int n_component, float* data, double vmin, double vmax, Vector3& cellSize);
    12 
    13 void NvLoadVolumeBinFile(int index, char* filename)
    14 {
    15         //read file
    16         FILE* file = fopen(filename, "rb");
    17         assert(file!=NULL);
    18 
    19         int width, height, depth, n_components;
    20         unsigned int type;
    21         unsigned int interp;
    22 
    23         fread(&width, sizeof(int), 1, file);
    24         fread(&height, sizeof(int), 1, file);
    25         fread(&depth, sizeof(int), 1, file);
    26         fread(&n_components, sizeof(int), 1, file);
    27         fread(&type, sizeof(unsigned int), 1, file);
    28         fread(&interp, sizeof(unsigned int), 1, file);
    29 
    30     int size = n_components*width*depth*height;
    31 
    32         float* data;
    33         data = new float[size];
    34 
    35     fread(data, sizeof(float) * size, 1, file);
    36     fclose(file);
    37 
    38     float min = data[0], max = data[0];
    39     float non_zero_min = -1e27f;
    40         for (int i=0; i<n_components*width*depth*height; i++)
    41     {
    42                 if(data[i]>max)
    43                         max = data[i];
    44                 if(data[i]<min)
    45                         min = data[i];
    46 
    47                 if(data[i]<non_zero_min && data[i] != 0)
    48         {
    49                         non_zero_min = data[i];
    50                 }
    51         }
    52        
    53  
    54     int i = 0;
    55     if (max != 0.0f)
    56     {
    57         for (i=0; i < size; ++i) {
    58             data[i] = data[i] / max;
    59         }
    60     }
    61 
    62     Vector3 cellsize;
    63     cellsize.x = width * 0.25;
    64     cellsize.y = height * 0.25;
    65     cellsize.z = depth * 0.25;
    66 
    67     load_volqd_volume(index, width, height, depth, 4, data, min, max, cellsize);
    68 
    69     delete [] data;
    70 }
    71 
    72 void NvLoadVolumeBinFile2(int index, char* filename)
    73 {
    74         //read file
    75         FILE* file = fopen(filename, "rb");
    76         assert(file!=NULL);
    77 
    78         int width, height, depth, n_components;
    79         unsigned int type;
    80         unsigned int interp;
    81 
    82         fread(&width, sizeof(int), 1, file);
    83         fread(&height, sizeof(int), 1, file);
    84         fread(&depth, sizeof(int), 1, file);
    85         fread(&n_components, sizeof(int), 1, file);
    86         fread(&type, sizeof(unsigned int), 1, file);
    87         fread(&interp, sizeof(unsigned int), 1, file);
    88 
    89     int size = n_components*width*depth*height;
    90 
    91         float* data;
    92         data = new float[size];
    93 
    94     fread(data, sizeof(float) * size, 1, file);
    95     fclose(file);
    96 
    97     float min = data[0], max = data[0];
    98     float non_zero_min = -1e27f;
    99         for (int i=0; i<n_components*width*depth*height; i++)
    100     {
    101                 if(data[i]>max)
    102                         max = data[i];
    103                 if(data[i]<min)
    104                         min = data[i];
    105 
    106                 if(data[i]<non_zero_min && data[i] != 0)
    107         {
    108                         non_zero_min = data[i];
    109                 }
    110         }
    111        
    112  
    113     int i = 0;
    114     if (max != 0.0f)
    115     {
    116         for (i=0; i < size; ++i) {
    117             data[i] = data[i] / max;
    118         }
    119     }
    120 
    121     Vector3 cellsize;
    122     cellsize.x = width * 0.25;
    123     cellsize.y = height * 0.25;
    124     cellsize.z = depth * 0.25;
    125 
    126     load_zinc_volume(index, width, height, depth, 4, data, min, max, cellsize);
    127 
    128     delete [] data;
    129 }
  • trunk/gui/vizservers/nanovis/NvZincBlendeReconstructor.cpp

    r601 r617  
    2222}
    2323
    24 ZincBlendeVolume* NvZincBlendeReconstructor::load(const char* fileName)
     24ZincBlendeVolume* NvZincBlendeReconstructor::loadFromFile(const char* fileName)
    2525{
    2626    Vector3 origin, delta;
     27    double temp;
    2728    int width = 0, height = 0, depth = 0;
    2829    void* data = NULL;
    2930
    30     // TBD
    31     // INSOO
    32     // I have to handle the header of the file
     31    ifstream stream;
     32    stream.open(fileName, ios::binary);
     33
     34    ZincBlendeVolume* volume = loadFromStream(stream);
     35
     36    stream.close();
     37
     38    return volume;
     39}
     40
     41ZincBlendeVolume* NvZincBlendeReconstructor::loadFromStream(std::istream& stream)
     42{
     43    Vector3 origin, delta;
     44    double temp;
     45    int width = 0, height = 0, depth = 0;
     46    void* data = NULL;
     47
     48    char str[5][20];
     49    do {
     50        getLine(stream);
     51    } while(strstr(buff, "object") == 0);
     52
     53
     54     sscanf(buff, "%s%s%s%s%s%d%d%d", str[0], str[1], str[2], str[3], str[4],&width, &height, &depth);
     55     getLine(stream);
     56     sscanf(buff, "%s%f%f%f", str[0], &(origin.x), &(origin.y), &(origin.z));
     57     getLine(stream);
     58     sscanf(buff, "%s%f%f%f", str[0], &(delta.x), &temp, &temp);
     59     getLine(stream);
     60     sscanf(buff, "%s%f%f%f", str[0], &temp, &(delta.y), &temp);
     61     getLine(stream);
     62     sscanf(buff, "%s%f%f%f", str[0], &temp, &temp, &(delta.z));
     63
     64    do {
     65        getLine(stream);
     66    } while(strcmp(buff, "<\\HDR>") != 0);
     67
    3368   
     69    width = width / 4;
     70    height = height / 4;
     71    depth = depth / 4;
     72    data = new double[width * height * depth * 8 * 4]; // 8 atom per cell, 4 double (x, y, z, and probability) per atom
     73
     74    try {
     75        stream.read((char*) data, width * height * depth * 8 * 4 * sizeof(double));
     76    }
     77    catch (...)
     78    {
     79        printf("ERROR\n");
     80    }
     81
    3482    return buildUp(origin, delta, width, height, depth, data);
    3583}
    3684
    37 struct _NvUnitCellInfo {
    38     float indexX, indexY, indexZ;
    39     float atoms[8];
     85struct _NvAtomInfo {
     86    double indexX, indexY, indexZ;
     87    double atom;
    4088
    4189    int getIndex(int width, int height) const
     
    4896        // The reasone why index is multiplied by 4 is that one unit cell has half of eight atoms
    4997        // ,i.e. four atoms are mapped into RGBA component of one texel
    50         return (indexZ + indexX * width + indexY * width * height) * 4;
     98        return ((int) (indexZ - 1)+ (int) (indexX - 1) * width + (int) (indexY - 1) * width * height) * 4;
    5199    }
    52100};
    53101
    54 template<class T>
    55 inline int _NvMax2(T a, T b) { return ((a >= b)? a : b); }
    56 
    57 template<class T>
    58 inline int _NvMin2(T a, T b) { return ((a >= b)? a : b); }
    59 
    60 template<class T>
    61 inline int _NvMax3(T a, T b, T c) { return ((a >= b)? ((a >= c) ? a : c) : ((b >= c)? b : c)); }
    62 
    63 template<class T>
    64 inline int _NvMin3(T a, T b, T c) { return ((a <= b)? ((a <= c) ? a : c) : ((b <= c)? b : c)); }
    65 
    66 template<class T>
    67 inline int _NvMax9(T* a, T curMax) { return _NvMax3(_NvMax3(a[0], a[1], a[2]), _NvMax3(a[3], a[4], a[5]), _NvMax3(a[6], a[7], curMax)); }
    68 
    69 template<class T>
    70 inline int _NvMin9(T* a, T curMax) { return _NvMin3(_NvMax3(a[0], a[1], a[2]), _NvMin3(a[3], a[4], a[5]), _NvMin3(a[6], a[7], curMax)); }
     102
     103template<class T>
     104inline T _NvMax2(T a, T b) { return ((a >= b)? a : b); }
     105
     106template<class T>
     107inline T _NvMin2(T a, T b) { return ((a >= b)? a : b); }
     108
     109template<class T>
     110inline T _NvMax3(T a, T b, T c) { return ((a >= b)? ((a >= c) ? a : c) : ((b >= c)? b : c)); }
     111
     112template<class T>
     113inline T _NvMin3(T a, T b, T c) { return ((a <= b)? ((a <= c) ? a : c) : ((b <= c)? b : c)); }
     114
     115template<class T>
     116inline T _NvMax9(T* a, T curMax) { return _NvMax3(_NvMax3(a[0], a[1], a[2]), _NvMax3(a[3], a[4], a[5]), _NvMax3(a[6], a[7], curMax)); }
     117
     118template<class T>
     119inline T _NvMin9(T* a, T curMax) { return _NvMin3(_NvMax3(a[0], a[1], a[2]), _NvMin3(a[3], a[4], a[5]), _NvMin3(a[6], a[7], curMax)); }
     120
     121template<class T>
     122inline T _NvMax4(T* a) { return _NvMax2(_NvMax2(a[0], a[1]), _NvMax2(a[2], a[3])); }
     123
     124template<class T>
     125inline T _NvMin4(T* a) { return _NvMin2(_NvMin2(a[0], a[1]), _NvMin2(a[2], a[3])); }
     126
    71127
    72128ZincBlendeVolume* NvZincBlendeReconstructor::buildUp(const Vector3& origin, const Vector3& delta, int width, int height, int depth, void* data)
     
    74130    ZincBlendeVolume* zincBlendeVolume = NULL;
    75131
    76     float *dataVolumeA, *dataVolumeB;
     132    float *fourAnionVolume, *fourCationVolume;
    77133    int cellCount = width * height * depth;
    78     dataVolumeA = new float[cellCount * sizeof(float) * 4];
    79     dataVolumeB = new float[cellCount * sizeof(float) * 4];
    80 
    81     _NvUnitCellInfo* srcPtr = (_NvUnitCellInfo*) data;
     134    fourAnionVolume = new float[cellCount * sizeof(float) * 4];
     135    fourCationVolume = new float[cellCount * sizeof(float) * 4];
     136
     137    _NvAtomInfo* srcPtr = (_NvAtomInfo*) data;
    82138
    83139    float vmin, vmax;
     
    85141    int index;
    86142
    87     vmin = vmax = srcPtr->atoms[0];
    88     for (int i = 0; i < cellCount; ++i)
     143    vmin = vmax = srcPtr->atom;
     144
     145    int i;
     146    for (i = 0; i < cellCount; ++i)
    89147    {
    90148        index = srcPtr->getIndex(width, height);
    91         component4A = dataVolumeA + index;
    92         component4B = dataVolumeB + index;
    93 
    94 
    95         component4A[0] = srcPtr->atoms[0];
    96         component4A[1] = srcPtr->atoms[1];
    97         component4A[2] = srcPtr->atoms[2];
    98         component4A[3] = srcPtr->atoms[3];
    99 
    100         component4B[0] = srcPtr->atoms[4];
    101         component4B[1] = srcPtr->atoms[5];
    102         component4B[2] = srcPtr->atoms[6];
    103         component4B[3] = srcPtr->atoms[7];
    104 
    105         vmin = _NvMax9((float*) srcPtr->atoms, vmin);
    106         vmax = _NvMax9((float*)  srcPtr->atoms, vmax);
    107 
    108         ++srcPtr;
    109     }
    110 
    111 /*
    112     zincBlendeVolume = new ZincBlendeVolume(origin.x, origin.y, origin.z,
    113                 width, height, depth, size, 4,
    114                 dataVolumeA, dataVolumeB,
    115         vmin, vmax, cellSize);
    116 */
     149        component4A = fourAnionVolume + index;
     150        component4B = fourCationVolume + index;
     151
     152        component4A[0] = (float) srcPtr->atom; srcPtr++;
     153        component4A[1] = (float) srcPtr->atom; srcPtr++;
     154        component4A[2] = (float) srcPtr->atom; srcPtr++;
     155        component4A[3] = (float) srcPtr->atom; srcPtr++;
     156     
     157        component4B[0] = (float) srcPtr->atom; srcPtr++;
     158        component4B[1] = (float) srcPtr->atom; srcPtr++;
     159        component4B[2] = (float) srcPtr->atom; srcPtr++;
     160        component4B[3] = (float) srcPtr->atom; srcPtr++;
     161
     162        vmax = _NvMax3(_NvMax4(component4A), _NvMax4(component4B), vmax);
     163        vmin = _NvMin3(_NvMin4(component4A), _NvMin4(component4B), vmin);
     164    }
     165
     166    double dv = vmax - vmin;
     167    if (vmax != 0.0f)
     168    {
     169        for (i=0; i < cellCount; ++i)
     170        {
     171            fourAnionVolume[i] = (fourAnionVolume[i] - vmin)/ dv;
     172            fourCationVolume[i] = (fourCationVolume[i] - vmin) / dv;
     173        }
     174    }
     175
     176    Vector3 cellSize;
     177    cellSize.x = 0.25 / width;
     178    cellSize.y = 0.25 / height;
     179    cellSize.z = 0.25 / depth;
     180
     181    zincBlendeVolume = new ZincBlendeVolume(origin.x, origin.y, origin.z,
     182                                            width, height, depth, 1, 4,
     183                                            fourAnionVolume, fourCationVolume,
     184                                            vmin, vmax, cellSize);
    117185
    118186    return zincBlendeVolume;
    119187}
    120188
     189void NvZincBlendeReconstructor::getLine(std::istream& sin)
     190{
     191    char ch;
     192    int index = 0;
     193    do {
     194        sin.get(ch);
     195        if (ch == '\n') break;
     196        buff[index++] = ch;
     197        if (ch == '>')
     198        {
     199            if (buff[1] == '\\')
     200                break;
     201        }
     202    } while (!sin.eof());
     203
     204    buff[index] = '\0';
     205}
     206
  • trunk/gui/vizservers/nanovis/NvZincBlendeReconstructor.h

    r601 r617  
    1717#define __NV_ZINC_BLENDE_RECONSTRUCTOR_H__
    1818
     19#include <stdio.h>
     20#include <ostream>
     21#include <sstream>
     22#include <fstream>
    1923
    2024#include "Vector3.h"
     
    2327
    2428class NvZincBlendeReconstructor {
     29    char buff[255];
    2530
    2631    /**
     
    4449     */
    4550    static NvZincBlendeReconstructor* getInstance();
     51
     52private :
     53    /**
     54     * @brief Get a line from file. It is used for reading header because header is written in ascii.
     55     * @param fp A file pointer of data file
     56     */
     57    void getLine(std::istream& stream);
    4658   
    4759public :
     
    5062     * @param fileName Zinc blende file name, which data is generated by NEMO-3D
    5163     */
    52     ZincBlendeVolume* load(const char* fileName);
     64    ZincBlendeVolume* loadFromFile(const char* fileName);
     65
     66    /**
     67     * @brief Load Zinc blende binary volume data and create ZincBlendeVolume with the file
     68     * @param data Zinc blende binary volume data, which data is generated by NEMO-3D and transferred from nanoscale
     69     */
     70    ZincBlendeVolume* loadFromStream(std::istream& stream);
    5371
    5472    /**
  • trunk/gui/vizservers/nanovis/NvZincBlendeVolumeShader.h

    r580 r617  
    2626inline void NvZincBlendeVolumeShader::bind(unsigned int tfID, Volume* volume, int sliceMode)
    2727{
    28     //ZincBlendeVolume* vol = reinterpret_cast<ZincBlendeVolume*)>(volume);
    2928    ZincBlendeVolume* vol = (ZincBlendeVolume*)volume;
    3029    cgGLSetStateMatrixParameter(_mviParam, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE);
  • trunk/gui/vizservers/nanovis/VolumeRenderer.cpp

    r580 r617  
    1414 */
    1515
     16#include <R2/R2string.h>
     17#include <R2/R2FilePath.h>
    1618#include "VolumeRenderer.h"
    17 
    18 
    19 VolumeRenderer::VolumeRenderer(CGcontext _context):
     19#include "NvStdVertexShader.h"
     20
     21
     22VolumeRenderer::VolumeRenderer():
    2023  n_volumes(0),
    21   g_context(_context),
    2224  slice_mode(false),
    2325  volume_mode(true)
    2426{
    25   volume.clear();
    26   tf.clear();
    27 
    28   init_shaders();
    29   init_font("/opt/nanovis/lib/font/Font.bmp");
     27    volume.clear();
     28    tf.clear();
     29
     30    init_shaders();
     31
     32    R2string path = R2FilePath::getInstance()->getPath("Font.bmp");
     33    init_font((const char*) path);
    3034}
    3135
    3236VolumeRenderer::~VolumeRenderer()
    3337{
    34     delete m_zincBlendeShader;
    35     delete m_regularVolumeShader;
    36     delete m_volQDVolumeShader;
     38    delete _zincBlendeShader;
     39    delete _regularVolumeShader;
     40    delete _stdVertexShader;
    3741}
    3842
     
    4145 
    4246  //standard vertex program
    43   m_vert_std_vprog = loadProgram(g_context, CG_PROFILE_VP30, CG_SOURCE, "/opt/nanovis/lib/shaders/vertex_std.cg");
    44   m_mvp_vert_std_param = cgGetNamedParameter(m_vert_std_vprog, "modelViewProjMatrix");
    45   m_mvi_vert_std_param = cgGetNamedParameter(m_vert_std_vprog, "modelViewInv");
    46 
     47  _stdVertexShader = new NvStdVertexShader();
    4748
    4849  //volume rendering shader: one cubic volume
    49   m_regularVolumeShader = new NvRegularVolumeShader();
     50  _regularVolumeShader = new NvRegularVolumeShader();
    5051
    5152  //volume rendering shader: one zincblende orbital volume.
     
    5758  //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
    5859  //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
    59   m_zincBlendeShader = new NvZincBlendeVolumeShader();
    60 
    61   m_volQDVolumeShader = new NvVolQDVolumeShader();
     60  _zincBlendeShader = new NvZincBlendeVolumeShader();
    6261}
    6362
     
    669668
    670669
    671 void VolumeRenderer::activate_volume_shader(int volume_index, bool slice_mode){
    672 
     670void VolumeRenderer::activate_volume_shader(int volume_index, bool slice_mode)
     671{
    673672  //vertex shader
    674   cgGLSetStateMatrixParameter(m_mvp_vert_std_param, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
    675   cgGLSetStateMatrixParameter(m_mvi_vert_std_param, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE);
    676   cgGLBindProgram(m_vert_std_vprog);
    677   cgGLEnableProfile(CG_PROFILE_VP30);
    678 
     673  _stdVertexShader->bind();
    679674
    680675  if (volume[volume_index]->volume_type == CUBIC)
    681676  {
    682677    //regular cubic volume
    683     m_regularVolumeShader->bind(tf[volume_index]->id, volume[volume_index], slice_mode);
    684   }
    685 
     678    _regularVolumeShader->bind(tf[volume_index]->id, volume[volume_index], slice_mode);
     679  }
    686680  else if (volume[volume_index]->volume_type == ZINCBLENDE)
    687681  {
    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);
     682    _zincBlendeShader->bind(tf[volume_index]->id, volume[volume_index], slice_mode);
    693683  }
    694684}
     
    697687void VolumeRenderer::deactivate_volume_shader()
    698688{
    699   cgGLDisableProfile(CG_PROFILE_VP30);
    700 
    701   m_regularVolumeShader->unbind();
    702   m_zincBlendeShader->unbind();
     689    _stdVertexShader->unbind();
     690    _regularVolumeShader->unbind();
     691    _zincBlendeShader->unbind();
    703692}
    704693
     
    756745
    757746
    758 void VolumeRenderer::init_font(char* filename) {
     747void VolumeRenderer::init_font(const char* filename) {
    759748
    760749    FILE *file;
  • trunk/gui/vizservers/nanovis/VolumeRenderer.h

    r580 r617  
    3535#include "PerfQuery.h"
    3636#include "NvRegularVolumeShader.h"
    37 #include "NvVolQDVolumeShader.h"
    3837#include "NvZincBlendeVolumeShader.h"
     38#include "NvStdVertexShader.h"
    3939
    4040using namespace std;
     
    4343
    4444private:
    45   vector <Volume*> volume;      //array of volumes
    46   vector <TransferFunction*> tf;//array of corresponding transfer functions
    47   int n_volumes;
     45    vector <Volume*> volume;        //!<- array of volumes
     46    vector <TransferFunction*> tf;    //!<- array of corresponding transfer functions
     47    int n_volumes;
    4848
    49   bool slice_mode;      //enable cut planes
    50   bool volume_mode;     //enable full volume rendering
     49    bool slice_mode;    //!<- enable cut planes
     50    bool volume_mode;   //!<- enable full volume rendering
     51
     52    /**
     53     * shader parameters for rendering a single cubic volume
     54     */
     55    NvRegularVolumeShader* _regularVolumeShader;
    5156
    5257
    53   //cg related
    54   CGcontext g_context;  //the Nvidia cg context
    55 
    56   //shader parameters for rendering a single cubic volume
    57   NvRegularVolumeShader* m_regularVolumeShader;
    58   NvVolQDVolumeShader* m_volQDVolumeShader;
    59 
    60 
    61   //Shader parameters for rendering a single zincblende orbital.
    62   //A simulation contains S, P, D and SS, total of 4 orbitals. A full rendering requires 4 zincblende orbital volumes.
    63   //A zincblende orbital volume is decomposed into two "interlocking" cubic volumes and passed to the shader.
    64   //We render each orbital with its own independent transfer functions then blend the result.
    65   //
    66   //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
    67   //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
    68   //This is equivalent to rendering 4 unrelated data sets occupying the same space.
    69   NvZincBlendeVolumeShader* m_zincBlendeShader;
     58    /**
     59     * Shader parameters for rendering a single zincblende orbital.
     60     * A simulation contains S, P, D and SS, total of 4 orbitals. A full rendering requires 4 zincblende orbital volumes.
     61     * A zincblende orbital volume is decomposed into two "interlocking" cubic volumes and passed to the shader.
     62     * We render each orbital with its own independent transfer functions then blend the result.
     63     *
     64     * The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
     65     * S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
     66     * This is equivalent to rendering 4 unrelated data sets occupying the same space.
     67     */
     68    NvZincBlendeVolumeShader* _zincBlendeShader;
    7069 
    7170 
     71    /**
     72     * standard vertex shader
     73     */
     74    NvStdVertexShader* _stdVertexShader;
    7275 
    7376  //standard vertex shader parameters
     
    8790  void get_near_far_z(Mat4x4 mv, double &zNear, double &zFar);
    8891
    89   void init_font(char* filename);
     92  void init_font(const char* filename);
    9093  GLuint font_texture;                          //the id of the font texture
    9194  void glPrint(char* string, int set);          //there are two sets of font in the texture. 0, 1
     
    9598
    9699public:
    97   VolumeRenderer(CGcontext _context);
     100  VolumeRenderer();
    98101  ~VolumeRenderer();
    99102
  • trunk/gui/vizservers/nanovis/ZincBlendeVolume.cpp

    r580 r617  
    2525                : Volume(x, y, z, w, h, d, s, n, dataVolumeA, v0, v1), cell_size(cellSize)
    2626{
    27  
    2827  //label it as zincblende
    2928  volume_type = ZINCBLENDE;
    30 
    31   //compute cellsize
    32   cell_size = Vector3(0.25/w, 0.25/h, 0.25/d);
    33 
    3429
    3530  //store member tex initialize in Volume() as zincblende_tex[0]
     
    4439
    4540  zincblende_tex[1] = secondTex;
    46 
    4741}
    4842
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r611 r617  
    4343#include "ZincBlendeVolume.h"
    4444#include "NvLoadFile.h"
    45 #include "NvVolQDVolume.h"
    4645#include "NvColorTableRenderer.h"
    4746#include "NvEventLog.h"
     47#include "NvZincBlendeReconstructor.h"
    4848
    4949// R2 headers
     
    286286}
    287287
    288 /*
    289 {
    290   glEnable(GL_TEXTURE_2D);
    291   glEnable(GL_BLEND);
    292 
    293   glViewport(0, 0, 1024, 1024);
    294   glMatrixMode(GL_PROJECTION);
    295   glLoadIdentity();
    296   gluOrtho2D(0, render_width, 0, render_height);
    297   glMatrixMode(GL_MODELVIEW);
    298   glLoadIdentity();
    299 
    300   glBegin(GL_QUADS);
    301   glTexCoord2f(0, 0); glVertex2f(30, 30);
    302   glTexCoord2f(1, 0); glVertex2f(1024 - 60, 30);
    303   glTexCoord2f(1, 1); glVertex2f(1024 - 60, 1024 - 60);
    304   glTexCoord2f(0, 1); glVertex2f(30, 1024 - 60);
    305   glEnd();
    306 }
    307 */
    308 
    309288static int
    310289ScreenShotCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
    311290{
    312 // INSOO
    313 /*
    314291    int old_win_width = win_width;
    315292    int old_win_height = win_height;
     293
    316294#ifdef XINETD
    317295    resize_offscreen_buffer(1024, 1024);
     
    320298    display();
    321299
     300    // INSOO
    322301    // TBD
    323302    Volume* vol = volume[0];
     
    336315    read_screen();
    337316    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     317
    338318    // INSOO
    339319    // TBD
     320    //bmp_write("nv>screenshot -bytes");
    340321    bmp_write_to_file();
    341     //bmp_write("nv>screenshot -bytes");
     322   
    342323    resize_offscreen_buffer(old_win_width, old_win_height);
    343324#endif
    344 */
    345 
    346325
    347326        return TCL_OK;
     
    824803
    825804            char buffer[8096];
    826             while (nbytes > 0) {
     805            while (nbytes > 0)
     806            {
    827807                int chunk = (sizeof(buffer) < nbytes) ? sizeof(buffer) : nbytes;
    828808                int status = fread(buffer, 1, chunk, stdin);
     
    842822                return TCL_ERROR;
    843823            }
    844             std::stringstream fdata;
    845             fdata.write(buf.bytes(),buf.size());
     824
    846825
    847826            int n = n_volumes;
    848             err = load_volume_stream(n, fdata);
    849 
    850             if (err) {
    851                 Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
    852                 return TCL_ERROR;
    853             }
     827            char header[6];
     828            memcpy(header, buf.bytes(), sizeof(char) * 5);
     829            header[5] = '\0';
     830
     831            if (!strcmp(header, "<HDR>"))
     832            {
     833                std::stringstream fdata(std::ios_base::out|std::ios_base::in|std::ios_base::binary);
     834                fdata.write(buf.bytes(),buf.size());
     835
     836                Volume* vol = NULL;
     837                vol = NvZincBlendeReconstructor::getInstance()->loadFromStream(fdata);
     838                if (vol)
     839                {
     840                    while (n_volumes <= n)
     841                    {
     842                        volume.push_back((Volume*) NULL);
     843                        n_volumes++;
     844                    }
     845
     846                    if (volume[n] != NULL)
     847                    {
     848                        delete volume[n];
     849                        volume[n] = NULL;
     850                    }
     851
     852                    float dx0 = -0.5;
     853                    float dy0 = -0.5*vol->height/vol->width;
     854                    float dz0 = -0.5*vol->depth/vol->width;
     855                    vol->move(Vector3(dx0, dy0, dz0));
     856
     857                    volume[n] = vol;
     858                }
     859            }
     860            else
     861            {
     862                std::stringstream fdata;
     863                fdata.write(buf.bytes(),buf.size());
     864                err = load_volume_stream(n, fdata);
     865                if (err) {
     866                    Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
     867                    return TCL_ERROR;
     868                }
     869            }
     870           
    854871
    855872            //
     
    861878            //   appear at all.
    862879            //
    863             volume[n]->set_n_slice(256-n);
    864             volume[n]->disable_cutplane(0);
    865             volume[n]->disable_cutplane(1);
    866             volume[n]->disable_cutplane(2);
    867             g_vol_render->add_volume(volume[n], get_transfunc("default"));
     880            if (volume[n])
     881            {
     882                volume[n]->set_n_slice(256-n);
     883                volume[n]->disable_cutplane(0);
     884                volume[n]->disable_cutplane(1);
     885                volume[n]->disable_cutplane(2);
     886
     887                g_vol_render->add_volume(volume[n], get_transfunc("default"));
     888            }
    868889
    869890            return TCL_OK;
     
    10721093            ++iter;
    10731094        }
    1074         return TCL_OK;
    1075     }
    1076     else if (c == 'v' && strcmp(argv[1],"volqd") == 0) {
    1077         int n = n_volumes;
    1078 
    1079         NvLoadVolumeBinFile(n, "/home/nanohub/vrinside/grid_1_0");
    1080 
    1081         volume[n]->set_n_slice(256-n);
    1082         volume[n]->disable_cutplane(0);
    1083         volume[n]->disable_cutplane(1);
    1084         volume[n]->disable_cutplane(2);
    1085         g_vol_render->add_volume(volume[n], get_transfunc("default"));
    1086 
    1087         return TCL_OK;
    1088     }
    1089     else if (c == 'z' && strcmp(argv[1],"zinc") == 0) {
    1090         int n = n_volumes;
    1091 
    1092         NvLoadVolumeBinFile2(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         g_vol_render->add_volume(volume[n], get_transfunc("default"));
    1099 
    11001095        return TCL_OK;
    11011096    }
     
    19061901                                 n_component, data, vmin, vmax);
    19071902    assert(volume[index]!=0);
    1908 }
    1909 
    1910 //INSOO
    1911 extern float tfdefaultdata[];
    1912 void load_volqd_volume(int index, int width, int height, int depth,
    1913     int n_component, float* data, double vmin, double vmax, Vector3& cellSize)
    1914 {
    1915     while (n_volumes <= index) {
    1916         volume.push_back(NULL);
    1917         n_volumes++;
    1918     }
    1919 
    1920     if (volume[index] != NULL) {
    1921         delete volume[index];
    1922         volume[index] = NULL;
    1923     }
    1924 
    1925     volume[index] = new NvVolQDVolume(0.f, 0.f, 0.f, width, height, depth, 1.,
    1926                                  n_component, data, vmin, vmax, cellSize);
    1927 
    1928     float dx0 = -0.5;
    1929     float dy0 = -0.5*height/width;
    1930     float dz0 = -0.5*depth/width;
    1931     volume[index]->move(Vector3(dx0, dy0, dz0));
    1932 
    1933     // INSOO
    1934     // Tentatively
    1935     TransferFunction* tf = new TransferFunction(256, tfdefaultdata);
    1936     g_vol_render->shade_volume(volume[index], tf);
    1937 }
    1938 
    1939 // INSOO
    1940 void load_zinc_volume(int index, int width, int height, int depth,
    1941     int n_component, float* data, double vmin, double vmax, Vector3& cellSize)
    1942 {
    1943     while (n_volumes <= index) {
    1944         volume.push_back(NULL);
    1945         n_volumes++;
    1946     }
    1947 
    1948     if (volume[index] != NULL) {
    1949         delete volume[index];
    1950         volume[index] = NULL;
    1951     }
    1952 
    1953     volume[index] = new ZincBlendeVolume(0.f, 0.f, 0.f, width, height, depth, 1.,
    1954                                  n_component, data, data, vmin, vmax, cellSize);
    1955 
    1956     float dx0 = -0.5;
    1957     float dy0 = -0.5*height/width;
    1958     float dz0 = -0.5*depth/width;
    1959     volume[index]->move(Vector3(dx0, dy0, dz0));
    19601903}
    19611904
     
    22012144
    22022145   //create volume renderer and add volumes to it
    2203    g_vol_render = new VolumeRenderer(g_context);
     2146   g_vol_render = new VolumeRenderer();
    22042147
    22052148   
  • trunk/gui/vizservers/nanovis/shaders/zincblende_volume.cg

    r580 r617  
    2929  PixelOut OUT;
    3030
    31   // INSOO
    32   //float4 tex_coord = mul(modelViewInv, IN.TexCoord) + float4(0.5, 0.5, 0.5, 0.5);
    3331  float4 tex_coord = mul(modelViewInv, IN.TexCoord);
    3432  float4 twice_cell_size = cellSize * 2.0;
     
    4341  float4 voxel_face_center_c = f4tex3D(volumeA, tex_coord_c) + f4tex3D(volumeB, tex_coord_c - cellSize);
    4442       
    45 
    4643  //combine 8 sampling results
    4744  float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125;
Note: See TracChangeset for help on using the changeset viewer.