Ignore:
Timestamp:
Mar 7, 2012, 12:21:30 PM (13 years ago)
Author:
ldelgass
Message:

Const correctness fixes, pass vector/matrix objects by reference, various
formatting and style cleanups, don't spam syslog and uncomment openlog() call.
Still needs to be compiled with -DWANT_TRACE to get tracing, but now trace
output will be output to file in /tmp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r2804 r2822  
    1414 * ======================================================================
    1515 */
    16 
     16#include <stdlib.h>
    1717#include <assert.h>
    1818#include <time.h>
    1919#include <sys/time.h>
    2020
     21#include <GL/glew.h>
     22#include <GL/glut.h>
     23
     24#include <tcl.h>
     25
     26#include <vector>
     27
    2128#include <R2/R2string.h>
    2229#include <R2/R2FilePath.h>
    2330
    2431#include "nanovis.h"
    25 
    2632#include "VolumeRenderer.h"
    27 #include "VolumeInterpolator.h"
     33#include "ConvexPolygon.h"
     34
    2835#include "NvStdVertexShader.h"
    2936#include "Trace.h"
     
    4047    const char *path = R2FilePath::getInstance()->getPath("Font.bmp");
    4148    if (path == NULL) {
    42         ERROR("can't find Font.bmp\n");
    43         assert(path != NULL);
     49        ERROR("can't find Font.bmp\n");
     50        assert(path != NULL);
    4451    }
    4552    init_font(path);
     
    5764
    5865//initialize the volume shaders
    59 void VolumeRenderer::init_shaders(){
    60  
    61   //standard vertex program
    62   _stdVertexShader = new NvStdVertexShader();
    63 
    64   //volume rendering shader: one cubic volume
    65   _regularVolumeShader = new NvRegularVolumeShader();
    66 
    67   //volume rendering shader: one zincblende orbital volume.
    68   //This shader renders one orbital of the simulation.
    69   //A sim has S, P, D, SS orbitals. thus a full rendering requires 4 zincblende orbital volumes.
    70   //A zincblende orbital volume is decomposed into 2 "interlocking" cubic 4-component volumes and passed to the shader.
    71   //We render each orbital with a independent transfer functions then blend the result.
    72   //
    73   //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
    74   //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
    75   _zincBlendeShader = new NvZincBlendeVolumeShader();
     66void VolumeRenderer::init_shaders()
     67{
     68    //standard vertex program
     69    _stdVertexShader = new NvStdVertexShader();
     70
     71    //volume rendering shader: one cubic volume
     72    _regularVolumeShader = new NvRegularVolumeShader();
     73
     74    //volume rendering shader: one zincblende orbital volume.
     75    //This shader renders one orbital of the simulation.
     76    //A sim has S, P, D, SS orbitals. thus a full rendering requires 4 zincblende orbital volumes.
     77    //A zincblende orbital volume is decomposed into 2 "interlocking" cubic 4-component volumes and passed to the shader.
     78    //We render each orbital with a independent transfer functions then blend the result.
     79    //
     80    //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
     81    //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
     82    _zincBlendeShader = new NvZincBlendeVolumeShader();
    7683}
    7784
     
    8087    int volume_id;
    8188    int slice_id;
     89
    8290    SortElement(float _z, int _v, int _s) :
    83         z(_z), volume_id(_v), slice_id(_s)
     91        z(_z), volume_id(_v), slice_id(_s)
    8492    {}
    8593};
    8694
    87 int slice_sort(const void* a, const void* b){
    88     if((*((SortElement*)a)).z > (*((SortElement*)b)).z)
     95int slice_sort(const void* a, const void* b)
     96{
     97    if ((*((SortElement*)a)).z > (*((SortElement*)b)).z)
    8998        return 1;
    9099    else
     
    549558    }
    550559}
    551 
    552560void VolumeRenderer::deactivate_volume_shader()
    553561{
     
    557565}
    558566
    559 void VolumeRenderer::get_near_far_z(Mat4x4 mv, double &zNear, double &zFar)
    560 {
    561   double x0 = 0;
    562   double y0 = 0;
    563   double z0 = 0;
    564   double x1 = 1;
    565   double y1 = 1;
    566   double z1 = 1;
    567 
    568   double zMin, zMax;
    569   zMin =  10000;
    570   zMax = -10000;
    571 
    572   double vertex[8][4];
    573 
    574   vertex[0][0]=x0; vertex[0][1]=y0; vertex[0][2]=z0; vertex[0][3]=1.0;
    575   vertex[1][0]=x1; vertex[1][1]=y0; vertex[1][2]=z0; vertex[1][3]=1.0;
    576   vertex[2][0]=x0; vertex[2][1]=y1; vertex[2][2]=z0; vertex[2][3]=1.0;
    577   vertex[3][0]=x0; vertex[3][1]=y0; vertex[3][2]=z1; vertex[3][3]=1.0;
    578   vertex[4][0]=x1; vertex[4][1]=y1; vertex[4][2]=z0; vertex[4][3]=1.0;
    579   vertex[5][0]=x1; vertex[5][1]=y0; vertex[5][2]=z1; vertex[5][3]=1.0;
    580   vertex[6][0]=x0; vertex[6][1]=y1; vertex[6][2]=z1; vertex[6][3]=1.0;
    581   vertex[7][0]=x1; vertex[7][1]=y1; vertex[7][2]=z1; vertex[7][3]=1.0;
    582 
    583   for (int i = 0; i < 8; i++) {
    584     Vector4 tmp = mv.transform(Vector4(vertex[i][0], vertex[i][1], vertex[i][2], vertex[i][3]));
    585     tmp.perspective_devide();
    586     vertex[i][2] = tmp.z;
    587     if (vertex[i][2]<zMin) zMin = vertex[i][2];
    588     if (vertex[i][2]>zMax) zMax = vertex[i][2];
    589   }
    590 
    591   zNear = zMax;
    592   zFar = zMin;
    593 }
    594 
    595 void VolumeRenderer::set_slice_mode(bool val) { slice_mode = val; }
    596 void VolumeRenderer::set_volume_mode(bool val) { volume_mode = val; }
    597 void VolumeRenderer::switch_slice_mode() { slice_mode = (!slice_mode); }
    598 void VolumeRenderer::switch_volume_mode() { volume_mode = (!volume_mode); }
     567void VolumeRenderer::get_near_far_z(const Mat4x4& mv, double& zNear, double& zFar)
     568{
     569    double x0 = 0;
     570    double y0 = 0;
     571    double z0 = 0;
     572    double x1 = 1;
     573    double y1 = 1;
     574    double z1 = 1;
     575
     576    double zMin, zMax;
     577    zMin =  10000;
     578    zMax = -10000;
     579
     580    double vertex[8][4];
     581
     582    vertex[0][0]=x0; vertex[0][1]=y0; vertex[0][2]=z0; vertex[0][3]=1.0;
     583    vertex[1][0]=x1; vertex[1][1]=y0; vertex[1][2]=z0; vertex[1][3]=1.0;
     584    vertex[2][0]=x0; vertex[2][1]=y1; vertex[2][2]=z0; vertex[2][3]=1.0;
     585    vertex[3][0]=x0; vertex[3][1]=y0; vertex[3][2]=z1; vertex[3][3]=1.0;
     586    vertex[4][0]=x1; vertex[4][1]=y1; vertex[4][2]=z0; vertex[4][3]=1.0;
     587    vertex[5][0]=x1; vertex[5][1]=y0; vertex[5][2]=z1; vertex[5][3]=1.0;
     588    vertex[6][0]=x0; vertex[6][1]=y1; vertex[6][2]=z1; vertex[6][3]=1.0;
     589    vertex[7][0]=x1; vertex[7][1]=y1; vertex[7][2]=z1; vertex[7][3]=1.0;
     590
     591    for (int i = 0; i < 8; i++) {
     592        Vector4 tmp = mv.transform(Vector4(vertex[i][0], vertex[i][1], vertex[i][2], vertex[i][3]));
     593        tmp.perspective_divide();
     594        vertex[i][2] = tmp.z;
     595        if (vertex[i][2] < zMin) zMin = vertex[i][2];
     596        if (vertex[i][2] > zMax) zMax = vertex[i][2];
     597    }
     598
     599    zNear = zMax;
     600    zFar = zMin;
     601}
    599602
    600603bool
     
    759762    glPushMatrix();
    760763
    761     glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height, 
     764    glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height,
    762765                 -0.1*vol->aspect_ratio_depth);
    763766    glRotatef(180, 0, 0, 1);
     
    765768
    766769    glScalef(0.0008, 0.0008, 0.0008);
    767     for(int i=0; i<length; i++){
     770    for (int i = 0; i < length; i++) {
    768771        glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0].c_str()[i]);
    769772        glTranslatef(0.04, 0., 0.);
     
    777780    glRotatef(90, 0, 1, 0);
    778781    glRotatef(90, 0, 0, 1);
    779    
     782
    780783    glScalef(0.0008, 0.0008, 0.0008);
    781     for(int i=0; i<length; i++){
     784    for (int i = 0; i < length; i++) {
    782785        glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1].c_str()[i]);
    783786        glTranslatef(0.04, 0., 0.);
     
    792795
    793796    glScalef(0.0008, 0.0008, 0.0008);
    794     for(int i=0; i<length; i++){
     797    for (int i = 0; i < length; i++) {
    795798        glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2].c_str()[i]);
    796799        glTranslatef(0.04, 0., 0.);
     
    811814        cy = (float) (loop / 16) / 16.0f;
    812815        glNewList(font_base + loop, GL_COMPILE);
    813         glBegin(GL_QUADS);
    814         glTexCoord2f(cx, 1 - cy - 0.0625f);
    815         glVertex3f(0, 0, 0);
    816         glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f);
    817         glVertex3f(0.04, 0, 0);
    818         glTexCoord2f(cx + 0.0625f, 1 - cy);
    819         glVertex3f(0.04, 0.04, 0);
    820         glTexCoord2f(cx, 1 - cy);
    821         glVertex3f(0, 0.04, 0);
    822         glEnd();
    823         glTranslated(0.04, 0, 0);
     816        glBegin(GL_QUADS);
     817        glTexCoord2f(cx, 1 - cy - 0.0625f);
     818        glVertex3f(0, 0, 0);
     819        glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f);
     820        glVertex3f(0.04, 0, 0);
     821        glTexCoord2f(cx + 0.0625f, 1 - cy);
     822        glVertex3f(0.04, 0.04, 0);
     823        glTexCoord2f(cx, 1 - cy);
     824        glVertex3f(0, 0.04, 0);
     825        glEnd();
     826        glTranslated(0.04, 0, 0);
    824827        glEndList();
    825828    }
     
    830833{
    831834    if (set > 1) {
    832         set=1;
     835        set = 1;
    833836    }
    834837    glBindTexture(GL_TEXTURE_2D, font_texture);
Note: See TracChangeset for help on using the changeset viewer.