Ignore:
Timestamp:
Mar 14, 2012 1:14:22 AM (12 years ago)
Author:
ldelgass
Message:

Minor, mostly formatting changes

Location:
trunk/packages/vizservers/nanovis
Files:
8 edited

Legend:

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

    r2822 r2853  
    1818
    1919#include <memory.h>
     20#include <assert.h>
     21
     22#include "ScreenSnapper.h"
    2023#include "Trace.h"
    21 #include <assert.h>
    22 #include "ScreenSnapper.h"
    2324
    2425ScreenSnapper::ScreenSnapper(int w, int h, GLuint type,
    25                              int channel_per_pixel)
     26                             int channel_per_pixel)
    2627{
    2728    width = w;
     
    6061    case GL_FLOAT:
    6162        elemSize = sizeof(float);
    62         break;
     63        break;
    6364    case GL_UNSIGNED_BYTE:
    6465        elemSize = sizeof(unsigned char);
    65         break;
     66        break;
    6667    default:
    67         assert(0);
    68         break;
     68        assert(0);
     69        break;
    6970    }
    7071    unsigned int size;
     
    100101            } else if (n_channels_per_pixel==4) {
    101102                TRACE("(%f %f %f %f) ", ((float*)data)[4*i],
    102                       ((float*)data)[4*i+1],
    103                       ((float*)data)[4*i+2],
     103                      ((float*)data)[4*i+1],
     104                      ((float*)data)[4*i+2],
    104105                      ((float*)data)[4*i+3]);
    105106            }
  • trunk/packages/vizservers/nanovis/ScreenSnapper.h

    r2798 r2853  
    1616 * ======================================================================
    1717 */
     18#ifndef SCREEN_SNAPPER_H
     19#define SCREEN_SNAPPER_H
    1820
    19 #ifndef _SCREEN_SNAPPER_H_
    20 #define _SCREEN_SNAPPER_H_
     21#include <stdio.h>
     22
     23#include <GL/glew.h>
    2124
    2225#include "define.h"
    23 #include <GL/gl.h>
    24 #include <stdio.h>
    25 
    2626
    2727class ScreenSnapper
    2828{
    2929public:
    30         int width, height;      //size of the screen
    31         GLuint data_type;       //data type: GL_FLOAT or GL_UNSIGNED_BYTE
    32         int n_channels_per_pixel; //RGB(3) or RGBA(4)
    33        
    34         void* data;  //storage array for the captured image. This array is "flat".
    35                 //It stores pixels in the order from lower-left corner to upper-right corner.
    36                 //[rgb][rgb][rgb]... or [rgba][rgba][rgba]...
     30    ScreenSnapper(int width, int height, GLuint type, int channel_per_pixel);
     31    ~ScreenSnapper();
    3732
    38         ScreenSnapper(int width, int height, GLuint type, int channel_per_pixel);
    39         ~ScreenSnapper();
     33    /// set every byte in the data array to c
     34    void reset(char c);
    4035
    41         void reset(char c);     //set every byte in the data array to c
    42         void capture();
    43         void print();
     36    void capture();
     37
     38    void print();
     39
     40    int width;  ///< width of the screen
     41    int height; ///< height of the screen
     42    GLuint data_type;   ///< GL_FLOAT or GL_UNSIGNED_BYTE
     43    int n_channels_per_pixel; ///< RGB(3) or RGBA(4)
     44
     45    /**
     46     * storage array for the captured image. This array is "flat".
     47     * It stores pixels in the order from lower-left corner to
     48     * upper-right corner.
     49     * [rgb][rgb][rgb]... or [rgba][rgba][rgba]...
     50     */
     51    void *data;
    4452};
    4553
  • trunk/packages/vizservers/nanovis/VolumeInterpolator.cpp

    r2798 r2853  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #include "VolumeInterpolator.h"
    3 #include "Volume.h"
    42#include <string.h>
    53#include <memory.h>
    6 #include "Vector3.h"
    74#include <time.h>
    85#include <sys/time.h>
    96#include <math.h>
    107#include <stdlib.h>
     8
     9#include "VolumeInterpolator.h"
     10#include "Volume.h"
     11#include "Vector3.h"
    1112#include "Trace.h"
    1213
     
    2021    _referenceOfVolume(0)
    2122{
    22     /*empty*/
    2323}
    2424
     
    4343}
    4444
    45 Volume* VolumeInterpolator::update(float fraction)
     45Volume *VolumeInterpolator::update(float fraction)
    4646{
    4747    int key1, key2;
     
    5454        _volume->tex()->update(_volume->data());
    5555    } else {
    56         float* data1 = _volumes[key1]->data();
    57         float* data2 = _volumes[key2]->data();
    58         float* result = _volume->data();
     56        float *data1 = _volumes[key1]->data();
     57        float *data2 = _volumes[key2]->data();
     58        float *result = _volume->data();
    5959
    6060        Vector3 normal1, normal2, normal;
     
    7575        _volume->tex()->update(_volume->data());
    7676    }
    77    
     77
    7878    return _volume;
    7979}
    8080
    81 void 
    82 VolumeInterpolator::computeKeys(float fraction, int count, float* interp,
    83                                 int* key1, int* key2)
     81void
     82VolumeInterpolator::computeKeys(float fraction, int count, float *interp,
     83                                int *key1, int *key2)
    8484{
    8585    int limit = (int) count - 1;
     
    9292    } else {
    9393        int n;
    94         for (n = 0;n < limit; n++){
     94        for (n = 0; n < limit; n++){
    9595            if (fraction >= (n / (count - 1.0f)) &&
    9696                fraction < ((n+1)/(count-1.0f))) {
     
    9898            }
    9999        }
    100        
     100
    101101        TRACE("n = %d count = %d\n", n, count);
    102         if (n >= limit){
     102        if (n >= limit) {
    103103            *key1 = *key2 = limit;
    104104            *interp = 0.0f;
    105            
    106105        } else {
    107106            *key1 = n;
     
    113112}
    114113
    115 void 
     114void
    116115VolumeInterpolator::clearAll()
    117116{
     
    119118}
    120119
    121 void 
    122 VolumeInterpolator::addVolume(Volume* refPtr)
     120void
     121VolumeInterpolator::addVolume(Volume *refPtr)
    123122{
    124123    if (_volumes.size() != 0) {
     
    130129            return;
    131130        }
    132        
    133131    } else {
    134132        _dataCount = refPtr->width * refPtr->height * refPtr->depth;
     
    164162}
    165163
    166 Volume* VolumeInterpolator::getVolume()
     164Volume *VolumeInterpolator::getVolume()
    167165{
    168166    return _volume;
    169167    //return _volumes[0];
    170168}
    171 
  • trunk/packages/vizservers/nanovis/VolumeInterpolator.h

    r2798 r2853  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __VOLUME_INTERPOLATOR_H__
    3 #define __VOLUME_INTERPOLATOR_H__
     2#ifndef VOLUME_INTERPOLATOR_H
     3#define VOLUME_INTERPOLATOR_H
     4
     5#include <vector>
    46
    57#include "Volume.h"
    68
    7 #include <vector>
     9class VolumeInterpolator
     10{
     11public :
     12    VolumeInterpolator();
    813
    9 class VolumeInterpolator {
    10     Volume* _volume;
     14    void addVolume(Volume *vol);
     15
     16    void clearAll();
     17   
     18    void start();
     19
     20    Volume *update(float fraction);
     21
     22    void stop();
     23
     24    void computeKeys(float fraction, int count, float *interp, int *key1, int *key2);
     25
     26    bool is_started() const;
     27
     28    double getInterval() const;
     29
     30    double getStartTime() const;
     31
     32    unsigned int getReferenceVolumeID() const;
     33
     34    Volume *getVolume();
     35
     36private:
     37    Volume *_volume;
    1138
    1239    std::vector<Volume*> _volumes;
     
    1946    unsigned int _referenceOfVolume;
    2047    double _start_time;
    21 
    22 public :
    23     VolumeInterpolator();
    24     void addVolume(Volume* vol);
    25     void clearAll();
    26    
    27     void start();
    28     Volume* update(float fraction);
    29     void stop();
    30     void computeKeys(float fraction, int count, float* interp, int* key1, int* key2);
    31     bool is_started() const;
    32     double getInterval() const;
    33     double getStartTime() const;
    34     unsigned int getReferenceVolumeID() const;
    35     Volume* getVolume();
    3648};
    3749
     
    5668}
    5769
    58 //inline Volume* VolumeInterpolator::getVolume()
    59 //{
    60 //    return _volume;
    61 //    //return _volumes[0];
    62 //}
    6370#endif
    6471
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r2822 r2853  
    111111        ani_tf = ani_vol->transferFunction();
    112112#endif
    113         TRACE("VOLUME INTERPOLATOR IS STARTED ----------------------------");
     113        TRACE("VOLUME INTERPOLATOR IS STARTED ----------------------------");
    114114    }
    115115    // Determine the volumes that are to be rendered.
     
    118118    Tcl_HashSearch iter;
    119119    for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL;
    120         hPtr = Tcl_NextHashEntry(&iter)) {
    121         Volume* volPtr;
    122         volPtr = (Volume *)Tcl_GetHashValue(hPtr);
     120        hPtr = Tcl_NextHashEntry(&iter)) {
     121        Volume* volPtr;
     122        volPtr = (Volume *)Tcl_GetHashValue(hPtr);
    123123        if (!volPtr->visible()) {
    124             continue;                   // Skip this volume
    125         }
    126         // BE CAREFUL: Set the number of slices to something slightly
    127         // different for each volume.  If we have identical volumes at exactly
    128         // the same position with exactly the same number of slices, the
    129         // second volume will overwrite the first, so the first won't appear
    130         // at all.
    131         volumes.push_back(volPtr);
    132         volPtr->n_slices(256 - volumes.size());
     124            continue; // Skip this volume
     125        }
     126        // BE CAREFUL: Set the number of slices to something slightly
     127        // different for each volume.  If we have identical volumes at exactly
     128        // the same position with exactly the same number of slices, the
     129        // second volume will overwrite the first, so the first won't appear
     130        // at all.
     131        volumes.push_back(volPtr);
     132        volPtr->n_slices(256 - volumes.size());
    133133    }
    134134
    135135    //two dimension pointer array
    136     ConvexPolygon*** polys = new ConvexPolygon**[volumes.size()];       
     136    ConvexPolygon ***polys = new ConvexPolygon**[volumes.size()];
    137137    //number of actual slices for each volume
    138     size_t* actual_slices = new size_t[volumes.size()];
     138    size_t *actual_slices = new size_t[volumes.size()];
    139139
    140140    TRACE("start loop %d\n", volumes.size());
    141141    for (size_t i = 0; i < volumes.size(); i++) {
    142         Volume* volPtr;
    143 
     142        Volume *volPtr = volumes[i];
    144143        polys[i] = NULL;
    145144        actual_slices[i] = 0;
    146         volPtr = volumes[i];
    147145
    148146        int n_slices = volPtr->n_slices();
    149147        if (volPtr->isosurface()) {
    150             // double the number of slices
    151             n_slices <<= 1;
    152         }
     148            // double the number of slices
     149            n_slices <<= 1;
     150        }
    153151
    154152        //volume start location
     
    165163        double zNear, zFar;
    166164
    167         //initialize volume plane with world coordinates
     165        //initialize volume plane with world coordinates
    168166        Plane volume_planes[6];
    169167        volume_planes[0].set_coeffs( 1,  0,  0, -x0);
     
    174172        volume_planes[5].set_coeffs( 0,  0, -1,  z0+1);
    175173
    176         //get modelview matrix with no translation
     174        //get modelview matrix with no translation
    177175        glPushMatrix();
    178176        glScalef(volPtr->aspect_ratio_width,
    179                 volPtr->aspect_ratio_height,
    180                 volPtr->aspect_ratio_depth);
     177                volPtr->aspect_ratio_height,
     178                volPtr->aspect_ratio_depth);
    181179
    182180        glEnable(GL_DEPTH_TEST);
     
    190188        glPopMatrix();
    191189
    192         //get modelview matrix with translation
     190        //get modelview matrix with translation
    193191        glPushMatrix();
    194192        glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);
    195193        glScalef(volPtr->aspect_ratio_width,
    196                 volPtr->aspect_ratio_height,
    197                 volPtr->aspect_ratio_depth);
     194                volPtr->aspect_ratio_height,
     195                volPtr->aspect_ratio_depth);
    198196        GLfloat mv_trans[16];
    199197        glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans);
     
    202200        model_view_trans_inverse = model_view_trans.inverse();
    203201
    204         //draw volume bounding box with translation (the correct location in
    205         //space)
     202        //draw volume bounding box with translation (the correct location in
     203        //space)
    206204        if (volPtr->outline()) {
    207205            float olcolor[3];
    208206            volPtr->get_outline_color(olcolor);
    209207            draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1,
    210                 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],
    211                 1.5);
     208                (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],
     209                1.5);
    212210        }
    213211        glPopMatrix();
     
    217215        glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);
    218216        if(volPtr->outline()) {
    219             //draw_label(i);
     217            //draw_label(i);
    220218        }
    221219        glPopMatrix();
    222220
    223         //transform volume_planes to eye coordinates.
     221        //transform volume_planes to eye coordinates.
    224222        for (size_t j = 0; j < 6; j++) {
    225223            volume_planes[j].transform(model_view_no_trans);
    226         }
     224        }
    227225        get_near_far_z(mv_no_trans, zNear, zFar);
    228226
    229         //compute actual rendering slices
    230         float z_step = fabs(zNear-zFar)/n_slices;               
     227        //compute actual rendering slices
     228        float z_step = fabs(zNear-zFar)/n_slices;
    231229        size_t n_actual_slices;
    232230
     
    245243        Vector4 vert4 = (Vector4(+10, -10, -0.5, 1));
    246244
    247         // Render cutplanes first with depth test enabled.  They will mark the
    248         // image with their depth values.  Then we render other volume slices.
    249         // These volume slices will be occluded correctly by the cutplanes and
    250         // vice versa.
    251 
    252         ConvexPolygon static_poly;
    253         for (int j = 0; j < volPtr->get_cutplane_count(); j++) {
    254             if (!volPtr->cutplane_is_enabled(j)) {
    255                 continue;
    256             }
    257             float offset = volPtr->get_cutplane(j)->offset;
    258             int axis = volPtr->get_cutplane(j)->orient;
    259            
    260             if (axis == 3) {
    261                 vert1 = Vector4(-10, -10, offset, 1);
    262                 vert2 = Vector4(-10, +10, offset, 1);
    263                 vert3 = Vector4(+10, +10, offset, 1);
    264                 vert4 = Vector4(+10, -10, offset, 1);
    265                 //continue;
    266             } else if (axis == 1) {
    267                 vert1 = Vector4(offset, -10, -10, 1);
    268                 vert2 = Vector4(offset, +10, -10, 1);
    269                 vert3 = Vector4(offset, +10, +10, 1);
    270                 vert4 = Vector4(offset, -10, +10, 1);
    271                 //continue;
    272             } else if (axis == 2) {
    273                 vert1 = Vector4(-10, offset, -10, 1);
    274                 vert2 = Vector4(+10, offset, -10, 1);
    275                 vert3 = Vector4(+10, offset, +10, 1);
    276                 vert4 = Vector4(-10, offset, +10, 1);
    277                 //continue;
    278             }
    279 
    280             vert1 = model_view_no_trans.transform(vert1);
    281             vert2 = model_view_no_trans.transform(vert2);
    282             vert3 = model_view_no_trans.transform(vert3);
    283             vert4 = model_view_no_trans.transform(vert4);
    284 
    285             ConvexPolygon* p = &static_poly;
    286             p->vertices.clear();
    287 
    288             p->append_vertex(vert1);
    289             p->append_vertex(vert2);
    290             p->append_vertex(vert3);
    291             p->append_vertex(vert4);
    292 
    293             for (size_t k = 0; k < 6; k++) {
    294                 p->clip(volume_planes[k], true);
    295             }
    296 
    297             p->transform(model_view_no_trans_inverse);
    298             p->transform(model_view_trans);
    299 
    300             glPushMatrix();
    301             glScalef(volPtr->aspect_ratio_width, volPtr->aspect_ratio_height,
    302                      volPtr->aspect_ratio_depth);
    303 
    304             activate_volume_shader(volPtr, true);
    305             glPopMatrix();
    306 
    307             glEnable(GL_DEPTH_TEST);
    308             glDisable(GL_BLEND);
    309 
    310             glBegin(GL_POLYGON);
    311             p->Emit(true);
    312             glEnd();
    313             glDisable(GL_DEPTH_TEST);
    314 
    315             deactivate_volume_shader();
    316         } //done cutplanes
    317        
    318         //Now do volume rendering
     245        // Render cutplanes first with depth test enabled.  They will mark the
     246        // image with their depth values.  Then we render other volume slices.
     247        // These volume slices will be occluded correctly by the cutplanes and
     248        // vice versa.
     249
     250        ConvexPolygon static_poly;
     251        for (int j = 0; j < volPtr->get_cutplane_count(); j++) {
     252            if (!volPtr->cutplane_is_enabled(j)) {
     253                continue;
     254            }
     255            float offset = volPtr->get_cutplane(j)->offset;
     256            int axis = volPtr->get_cutplane(j)->orient;
     257           
     258            if (axis == 3) {
     259                vert1 = Vector4(-10, -10, offset, 1);
     260                vert2 = Vector4(-10, +10, offset, 1);
     261                vert3 = Vector4(+10, +10, offset, 1);
     262                vert4 = Vector4(+10, -10, offset, 1);
     263                //continue;
     264            } else if (axis == 1) {
     265                vert1 = Vector4(offset, -10, -10, 1);
     266                vert2 = Vector4(offset, +10, -10, 1);
     267                vert3 = Vector4(offset, +10, +10, 1);
     268                vert4 = Vector4(offset, -10, +10, 1);
     269                //continue;
     270            } else if (axis == 2) {
     271                vert1 = Vector4(-10, offset, -10, 1);
     272                vert2 = Vector4(+10, offset, -10, 1);
     273                vert3 = Vector4(+10, offset, +10, 1);
     274                vert4 = Vector4(-10, offset, +10, 1);
     275                //continue;
     276            }
     277
     278            vert1 = model_view_no_trans.transform(vert1);
     279            vert2 = model_view_no_trans.transform(vert2);
     280            vert3 = model_view_no_trans.transform(vert3);
     281            vert4 = model_view_no_trans.transform(vert4);
     282
     283            ConvexPolygon *p = &static_poly;
     284            p->vertices.clear();
     285
     286            p->append_vertex(vert1);
     287            p->append_vertex(vert2);
     288            p->append_vertex(vert3);
     289            p->append_vertex(vert4);
     290
     291            for (size_t k = 0; k < 6; k++) {
     292                p->clip(volume_planes[k], true);
     293            }
     294
     295            p->transform(model_view_no_trans_inverse);
     296            p->transform(model_view_trans);
     297
     298            glPushMatrix();
     299            glScalef(volPtr->aspect_ratio_width,
     300                     volPtr->aspect_ratio_height,
     301                     volPtr->aspect_ratio_depth);
     302
     303            activate_volume_shader(volPtr, true);
     304            glPopMatrix();
     305
     306            glEnable(GL_DEPTH_TEST);
     307            glDisable(GL_BLEND);
     308
     309            glBegin(GL_POLYGON);
     310            p->Emit(true);
     311            glEnd();
     312            glDisable(GL_DEPTH_TEST);
     313
     314            deactivate_volume_shader();
     315        } //done cutplanes
     316
     317        //Now do volume rendering
    319318
    320319        vert1 = (Vector4(-10, -10, -0.5, 1));
     
    325324        size_t counter = 0;
    326325
    327         //transform slices and store them
     326        //transform slices and store them
    328327        float slice_z;
    329328        for (size_t j = 0; j < n_actual_slices; j++) {
    330             slice_z = zFar + j * z_step;        //back to front
     329            slice_z = zFar + j * z_step; //back to front
    331330
    332331            ConvexPolygon *poly = new ConvexPolygon();
     
    349348
    350349            for (size_t k = 0; k < 6; k++) {
    351                 poly->clip(volume_planes[k], true);
    352             }
     350                poly->clip(volume_planes[k], true);
     351            }
    353352
    354353            poly->transform(model_view_no_trans_inverse);
     
    356355
    357356            if (poly->vertices.size() >= 3)
    358                 total_rendered_slices++;
     357                total_rendered_slices++;
    359358        }
    360359    } //iterate all volumes
     
    364363    // farthest to the closest.  This step is critical for correct blending
    365364
    366     SortElement* slices = (SortElement*)
    367         malloc(sizeof(SortElement) * total_rendered_slices);
     365    SortElement *slices = (SortElement *)
     366        malloc(sizeof(SortElement) * total_rendered_slices);
    368367
    369368    size_t counter = 0;
     
    385384
    386385    for (size_t i = 0; i < total_rendered_slices; i++) {
    387         Volume* volPtr;
     386        Volume *volPtr = NULL;
    388387
    389388        int volume_index = slices[i].volume_id;
    390389        int slice_index = slices[i].slice_id;
    391         ConvexPolygon* cur = polys[volume_index][slice_index];
    392 
    393         volPtr = volumes[volume_index];
     390        ConvexPolygon *cur = polys[volume_index][slice_index];
     391
     392        volPtr = volumes[volume_index];
     393
    394394        glPushMatrix();
    395395        glScalef(volPtr->aspect_ratio_width, volPtr->aspect_ratio_height,
    396                 volPtr->aspect_ratio_depth);
     396                volPtr->aspect_ratio_depth);
    397397
    398398#ifdef notdef
    399         TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d\n",
    400                volPtr->name(), volPtr, slice_index, volume_index);
     399        TRACE("shading slice: volume %s addr=%x slice=%d, volume=%d\n",
     400               volPtr->name(), volPtr, slice_index, volume_index);
    401401#endif
    402402        activate_volume_shader(volPtr, false);
     
    429429void
    430430VolumeRenderer::draw_bounding_box(float x0, float y0, float z0,
    431                                   float x1, float y1, float z1,
    432                                   float r, float g, float b,
    433                                   float line_width)
     431                                  float x1, float y1, float z1,
     432                                  float r, float g, float b,
     433                                  float line_width)
    434434{
    435435    glPushMatrix();
     
    443443    glBegin(GL_LINE_LOOP);
    444444    {
    445         glVertex3d(x0, y0, z0);
    446         glVertex3d(x1, y0, z0);
    447         glVertex3d(x1, y1, z0);
    448         glVertex3d(x0, y1, z0);
     445        glVertex3d(x0, y0, z0);
     446        glVertex3d(x1, y0, z0);
     447        glVertex3d(x1, y1, z0);
     448        glVertex3d(x0, y1, z0);
    449449    }
    450450    glEnd();
     
    452452    glBegin(GL_LINE_LOOP);
    453453    {
    454         glVertex3d(x0, y0, z1);
    455         glVertex3d(x1, y0, z1);
    456         glVertex3d(x1, y1, z1);
    457         glVertex3d(x0, y1, z1);
     454        glVertex3d(x0, y0, z1);
     455        glVertex3d(x1, y0, z1);
     456        glVertex3d(x1, y1, z1);
     457        glVertex3d(x0, y1, z1);
    458458    }
    459459    glEnd();
    460    
     460
    461461    glBegin(GL_LINE_LOOP);
    462462    {
    463         glVertex3d(x0, y0, z0);
    464         glVertex3d(x0, y0, z1);
    465         glVertex3d(x0, y1, z1);
    466         glVertex3d(x0, y1, z0);
     463        glVertex3d(x0, y0, z0);
     464        glVertex3d(x0, y0, z1);
     465        glVertex3d(x0, y1, z1);
     466        glVertex3d(x0, y1, z0);
    467467    }
    468468    glEnd();
     
    470470    glBegin(GL_LINE_LOOP);
    471471    {
    472         glVertex3d(x1, y0, z0);
    473         glVertex3d(x1, y0, z1);
    474         glVertex3d(x1, y1, z1);
    475         glVertex3d(x1, y1, z0);
     472        glVertex3d(x1, y0, z0);
     473        glVertex3d(x1, y0, z1);
     474        glVertex3d(x1, y1, z1);
     475        glVertex3d(x1, y1, z0);
    476476    }
    477477    glEnd();
     
    485485
    486486    if (NanoVis::fonts != NULL) {
    487         double mv[16], prjm[16];
    488         int viewport[4];
    489         double wx, wy, wz;
    490         double dx, dy, dz;
    491 
    492         glGetDoublev(GL_MODELVIEW_MATRIX, mv);
    493         glGetDoublev(GL_PROJECTION_MATRIX, prjm);
    494         glGetIntegerv(GL_VIEWPORT, viewport);
    495        
    496         NanoVis::fonts->begin();
    497         dx = x1 - x0;
    498         dy = y1 - y0;
    499         dz = z1 - z0;
    500         if (gluProject((x0 + x1) * 0.5, y0, z0, mv, prjm, viewport,
    501                        &wx, &wy, &wz)) {
    502             char buff[20];
    503             double min, max;
    504 
    505             NanoVis::grid->xAxis.GetDataLimits(min, max);
    506             glLoadIdentity();
    507             glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
    508             const char *units;
    509             units = NanoVis::grid->xAxis.GetUnits();
    510             sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
    511             NanoVis::fonts->draw(buff);
    512         }
    513         if (gluProject(x0, (y0 + y1) * 0.5, z0, mv, prjm, viewport, &
    514                        wx, &wy, &wz)) {
    515             char buff[20];
    516             double min, max;
    517 
    518             NanoVis::grid->yAxis.GetDataLimits(min, max);
    519             glLoadIdentity();
    520             glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
    521             const char *units;
    522             units = NanoVis::grid->yAxis.GetUnits();
    523             sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
    524             NanoVis::fonts->draw(buff);
    525         }
    526         if (gluProject(x0, y0, (z0 + z1) * 0.5, mv, prjm, viewport,
    527                        &wx, &wy, &wz)) {
    528             glLoadIdentity();
    529             glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
    530 
    531             double min, max;
    532             NanoVis::grid->zAxis.GetDataLimits(min, max);
    533             const char *units;
    534             units = NanoVis::grid->zAxis.GetUnits();
    535             char buff[20];
    536             sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
    537             NanoVis::fonts->draw(buff);
    538         }
    539         NanoVis::fonts->end();
     487        double mv[16], prjm[16];
     488        int viewport[4];
     489        double wx, wy, wz;
     490        double dx, dy, dz;
     491
     492        glGetDoublev(GL_MODELVIEW_MATRIX, mv);
     493        glGetDoublev(GL_PROJECTION_MATRIX, prjm);
     494        glGetIntegerv(GL_VIEWPORT, viewport);
     495
     496        NanoVis::fonts->begin();
     497        dx = x1 - x0;
     498        dy = y1 - y0;
     499        dz = z1 - z0;
     500        if (gluProject((x0 + x1) * 0.5, y0, z0, mv, prjm, viewport,
     501                       &wx, &wy, &wz)) {
     502            char buff[20];
     503            double min, max;
     504
     505            NanoVis::grid->xAxis.GetDataLimits(min, max);
     506            glLoadIdentity();
     507            glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
     508            const char *units;
     509            units = NanoVis::grid->xAxis.GetUnits();
     510            sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
     511            NanoVis::fonts->draw(buff);
     512        }
     513        if (gluProject(x0, (y0 + y1) * 0.5, z0, mv, prjm, viewport, &
     514                       wx, &wy, &wz)) {
     515            char buff[20];
     516            double min, max;
     517
     518            NanoVis::grid->yAxis.GetDataLimits(min, max);
     519            glLoadIdentity();
     520            glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
     521            const char *units;
     522            units = NanoVis::grid->yAxis.GetUnits();
     523            sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
     524            NanoVis::fonts->draw(buff);
     525        }
     526        if (gluProject(x0, y0, (z0 + z1) * 0.5, mv, prjm, viewport,
     527                       &wx, &wy, &wz)) {
     528            glLoadIdentity();
     529            glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
     530
     531            double min, max;
     532            NanoVis::grid->zAxis.GetDataLimits(min, max);
     533            const char *units;
     534            units = NanoVis::grid->zAxis.GetUnits();
     535            char buff[20];
     536            sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
     537            NanoVis::fonts->draw(buff);
     538        }
     539        NanoVis::fonts->end();
    540540    };
    541541#endif
     
    553553    TransferFunction *tfPtr  = volPtr->transferFunction();
    554554    if (volPtr->volume_type() == Volume::CUBIC) {
    555         _regularVolumeShader->bind(tfPtr->id(), volPtr, slice_mode);
     555        _regularVolumeShader->bind(tfPtr->id(), volPtr, slice_mode);
    556556    } else if (volPtr->volume_type() == Volume::ZINCBLENDE) {
    557         _zincBlendeShader->bind(tfPtr->id(), volPtr, slice_mode);
     557        _zincBlendeShader->bind(tfPtr->id(), volPtr, slice_mode);
    558558    }
    559559}
     
    602602
    603603bool
    604 VolumeRenderer::init_font(const char* filename)
     604VolumeRenderer::init_font(const char *filename)
    605605{
    606606    FILE *f;
     
    617617    f = fopen(filename, "rb");
    618618    if (f == NULL) {
    619         ERROR("can't open font file \"%s\"\n", filename);
    620         return false;
     619        ERROR("can't open font file \"%s\"\n", filename);
     620        return false;
    621621    }
    622622
    623623    if (fread(&bfType, sizeof(short int), 1, f) != 1) {
    624         ERROR("can't read %lu bytes from font file \"%s\"\n",
    625                (unsigned long)sizeof(short int), filename);
    626         goto error;
     624        ERROR("can't read %lu bytes from font file \"%s\"\n",
     625               (unsigned long)sizeof(short int), filename);
     626        goto error;
    627627    }
    628628
    629629    /* check if file is a bitmap */
    630630    if (bfType != 19778) {
    631         ERROR("not a bmp file.\n");
    632         goto error;
     631        ERROR("not a bmp file.\n");
     632        goto error;
    633633    }
    634634
     
    639639    /* get the position of the actual bitmap data */
    640640    if (fread(&bfOffBits, sizeof(int), 1, f) != 1) {
    641         ERROR("error reading file.\n");
    642         goto error;
     641        ERROR("error reading file.\n");
     642        goto error;
    643643    }
    644644    //TRACE("Data at Offset: %ld\n", bfOffBits);
     
    649649    /* get the width of the bitmap */
    650650    if (fread(&width, sizeof(int), 1, f) != 1) {
    651         ERROR("error reading file.\n");
    652         goto error;
     651        ERROR("error reading file.\n");
     652        goto error;
    653653    }
    654654    //TRACE("Width of Bitmap: %d\n", texture->width);
     
    656656    /* get the height of the bitmap */
    657657    if (fread(&height, sizeof(int), 1, f) != 1) {
    658         ERROR("error reading file.\n");
    659         goto error;
     658        ERROR("error reading file.\n");
     659        goto error;
    660660    }
    661661    //TRACE("Height of Bitmap: %d\n", texture->height);
     
    663663    /* get the number of planes (must be set to 1) */
    664664    if (fread(&biPlanes, sizeof(short int), 1, f) != 1) {
    665         ERROR("error reading file.\n");
    666         goto error;
     665        ERROR("error reading file.\n");
     666        goto error;
    667667    }
    668668    if (biPlanes != 1) {
    669         ERROR("number of Planes not 1!\n");
    670         goto error;
     669        ERROR("number of Planes not 1!\n");
     670        goto error;
    671671    }
    672672
    673673    /* get the number of bits per pixel */
    674674    if (fread(&biBitCount, sizeof(short int), 1, f) != 1) {
    675         ERROR("error reading file.\n");
    676         goto error;
     675        ERROR("error reading file.\n");
     676        goto error;
    677677    }
    678678
    679679    //TRACE("Bits per Pixel: %d\n", biBitCount);
    680680    if (biBitCount != 24) {
    681         ERROR("Bits per Pixel not 24\n");
    682         goto error;
     681        ERROR("Bits per Pixel not 24\n");
     682        goto error;
    683683    }
    684684
     
    687687    data = (unsigned char*) malloc(biSizeImage);
    688688    if (data == NULL) {
    689         ERROR("Can't allocate memory for image\n");
    690         goto error;
     689        ERROR("Can't allocate memory for image\n");
     690        goto error;
    691691    }
    692692
     
    694694    fseek(f, bfOffBits, SEEK_SET);
    695695    if (fread(data, biSizeImage, 1, f) != 1) {
    696         ERROR("Error loading file!\n");
    697         goto error;
     696        ERROR("Error loading file!\n");
     697        goto error;
    698698    }
    699699    fclose(f);
     
    709709    unsigned char* data_with_alpha;
    710710    data_with_alpha = (unsigned char*)
    711         malloc(width*height*4*sizeof(unsigned char));
     711        malloc(width*height*4*sizeof(unsigned char));
    712712    for (int i = 0; i < height; i++) {
    713         for (int j = 0; j < width; j++) {
    714             unsigned char r, g, b, a;
    715             r = data[3*(i*width+j)];
    716             g = data[3*(i*width+j)+1];
    717             b = data[3*(i*width+j)+2];
    718 
    719             if (r==0 && g==0 && b==0)
    720                 a = 0;
    721             else
    722                 a = 255;
    723 
    724             data_with_alpha[4*(i*width+j)] = r;
    725             data_with_alpha[4*(i*width+j) + 1] = g;
    726             data_with_alpha[4*(i*width+j) + 2] = b;
    727             data_with_alpha[4*(i*width+j) + 3] = a;
    728         }
     713        for (int j = 0; j < width; j++) {
     714            unsigned char r, g, b, a;
     715            r = data[3*(i*width+j)];
     716            g = data[3*(i*width+j)+1];
     717            b = data[3*(i*width+j)+2];
     718
     719            if (r==0 && g==0 && b==0)
     720                a = 0;
     721            else
     722                a = 255;
     723
     724            data_with_alpha[4*(i*width+j)] = r;
     725            data_with_alpha[4*(i*width+j) + 1] = g;
     726            data_with_alpha[4*(i*width+j) + 2] = b;
     727            data_with_alpha[4*(i*width+j) + 3] = a;
     728        }
    729729    }
    730730    free(data);
     
    763763
    764764    glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height,
    765                 -0.1*vol->aspect_ratio_depth);
     765                -0.1*vol->aspect_ratio_depth);
    766766    glRotatef(180, 0, 0, 1);
    767767    glRotatef(90, 1, 0, 0);
     
    769769    glScalef(0.0008, 0.0008, 0.0008);
    770770    for (int i = 0; i < length; i++) {
    771         glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0].c_str()[i]);
    772         glTranslatef(0.04, 0., 0.);
     771        glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0].c_str()[i]);
     772        glTranslatef(0.04, 0., 0.);
    773773    }
    774774    glPopMatrix();
     
    783783    glScalef(0.0008, 0.0008, 0.0008);
    784784    for (int i = 0; i < length; i++) {
    785         glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1].c_str()[i]);
    786         glTranslatef(0.04, 0., 0.);
     785        glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1].c_str()[i]);
     786        glTranslatef(0.04, 0., 0.);
    787787    }
    788788    glPopMatrix();
     
    796796    glScalef(0.0008, 0.0008, 0.0008);
    797797    for (int i = 0; i < length; i++) {
    798         glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2].c_str()[i]);
    799         glTranslatef(0.04, 0., 0.);
     798        glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2].c_str()[i]);
     799        glTranslatef(0.04, 0., 0.);
    800800    }
    801801    glPopMatrix();
  • trunk/packages/vizservers/nanovis/VolumeRenderer.h

    r2822 r2853  
    1414 * ======================================================================
    1515 */
    16 
    1716#ifndef _VOLUME_RENDERER_H_
    1817#define _VOLUME_RENDERER_H_
     
    3029class VolumeRenderer
    3130{
    32     friend class NanoVis;
    33 
    34 private:
    35     VolumeInterpolator* _volumeInterpolator;
    36 
    37     bool slice_mode;                    //!<- enable cut planes
    38     bool volume_mode;                   //!<- enable full volume rendering
    39 
    40     /**
    41      * shader parameters for rendering a single cubic volume
    42      */
    43     NvRegularVolumeShader* _regularVolumeShader;
    44 
    45     /**
    46      * Shader parameters for rendering a single zincblende orbital.  A
    47      * simulation contains S, P, D and SS, total of 4 orbitals. A full
    48      * rendering requires 4 zincblende orbital volumes.  A zincblende orbital
    49      * volume is decomposed into two "interlocking" cubic volumes and passed
    50      * to the shader.  We render each orbital with its own independent
    51      * transfer functions then blend the result.
    52      *
    53      * The engine is already capable of rendering multiple volumes and combine
    54      * them. Thus, we just invoke this shader on S, P, D and SS orbitals with
    55      * different transfor functions. The result is a multi-orbital rendering.
    56      * This is equivalent to rendering 4 unrelated data sets occupying the
    57      * same space.
    58      */
    59     NvZincBlendeVolumeShader* _zincBlendeShader;
    60 
    61     /**
    62      * standard vertex shader
    63      */
    64     NvStdVertexShader* _stdVertexShader;
    65 
    66     //standard vertex shader parameters
    67     CGprogram m_vert_std_vprog;
    68     CGparameter m_mvp_vert_std_param;
    69     CGparameter m_mvi_vert_std_param;
    70     GLuint font_base;           // The base of the font display list.
    71     GLuint font_texture;        //the id of the font texture
    72 
    73     void init_shaders();
    74 
    75     void activate_volume_shader(Volume* vol, bool slice_mode);
    76 
    77     void deactivate_volume_shader();
    78 
    79     //draw bounding box
    80     void draw_bounding_box(float x0, float y0, float z0,
    81                            float x1, float y1, float z1,
    82                            float r, float g, float b, float line_width);
    83 
    84     void get_near_far_z(const Mat4x4& mv, double& zNear, double& zFar);
    85 
    86     bool init_font(const char* filename);
    87 
    88     void glPrint(char* string, int set); //there are two sets of font in the
    89                                          //texture. 0, 1
    90 
    91     void draw_label(Volume* vol); //draw label using bitmap texture
    92                                 // the texture.
    93 
    94     void build_font();          // Register the location of each alphabet in
    95 
    9631public:
    9732    VolumeRenderer();
     
    9934    ~VolumeRenderer();
    10035
    101     void render_all();                  //render all enabled volumes;
     36    /// render all enabled volumes
     37    void render_all();
    10238
    10339    void specular(float val);
     
    10541    void diffuse(float val);
    10642
    107     void set_slice_mode(bool val)       //control independently.
     43    /// control independently
     44    void set_slice_mode(bool val)
    10845    {
    10946        slice_mode = val;
     
    11552    }
    11653
    117     void switch_slice_mode()            //switch_cutplane_mode
     54    /// switch_cutplane_mode
     55    void switch_slice_mode()
    11856    {
    11957        slice_mode = (!slice_mode);
     
    14280    void stopVolumeAnimation()
    14381    {
    144         _volumeInterpolator->stop();
     82        _volumeInterpolator->stop();
    14583    }
    14684
    14785    VolumeInterpolator* getVolumeInterpolator()
    14886    {
    149         return _volumeInterpolator;
     87        return _volumeInterpolator;
    15088    }
     89
     90    friend class NanoVis;
     91
     92private:
     93    void init_shaders();
     94
     95    void activate_volume_shader(Volume *vol, bool slice_mode);
     96
     97    void deactivate_volume_shader();
     98
     99     void draw_bounding_box(float x0, float y0, float z0,
     100                            float x1, float y1, float z1,
     101                            float r, float g, float b, float line_width);
     102
     103    void get_near_far_z(const Mat4x4& mv, double& zNear, double& zFar);
     104
     105    bool init_font(const char *filename);
     106
     107    /// there are two sets of font in the texture. 0, 1
     108    void glPrint(char *string, int set);
     109
     110    /// draw label using bitmap texture
     111    void draw_label(Volume *vol);
     112
     113    /// Register the location of each alphabet in
     114    void build_font();
     115
     116    VolumeInterpolator *_volumeInterpolator;
     117
     118    bool slice_mode;  ///< enable cut planes
     119    bool volume_mode; ///< enable full volume rendering
     120
     121    /**
     122     * shader parameters for rendering a single cubic volume
     123     */
     124    NvRegularVolumeShader *_regularVolumeShader;
     125
     126    /**
     127     * Shader parameters for rendering a single zincblende orbital.  A
     128     * simulation contains S, P, D and SS, total of 4 orbitals. A full
     129     * rendering requires 4 zincblende orbital volumes.  A zincblende orbital
     130     * volume is decomposed into two "interlocking" cubic volumes and passed
     131     * to the shader.  We render each orbital with its own independent
     132     * transfer functions then blend the result.
     133     *
     134     * The engine is already capable of rendering multiple volumes and combine
     135     * them. Thus, we just invoke this shader on S, P, D and SS orbitals with
     136     * different transfor functions. The result is a multi-orbital rendering.
     137     * This is equivalent to rendering 4 unrelated data sets occupying the
     138     * same space.
     139     */
     140    NvZincBlendeVolumeShader *_zincBlendeShader;
     141
     142    /**
     143     * standard vertex shader
     144     */
     145    NvStdVertexShader *_stdVertexShader;
     146
     147    //standard vertex shader parameters
     148    CGprogram m_vert_std_vprog;
     149    CGparameter m_mvp_vert_std_param;
     150    CGparameter m_mvi_vert_std_param;
     151    GLuint font_base;           // The base of the font display list.
     152    GLuint font_texture;        //the id of the font texture
    151153};
    152154
    153 #endif  /*_VOLUME_RENDERER_H_*/
     155#endif
  • trunk/packages/vizservers/nanovis/dxReader.h

    r2846 r2853  
    22#ifndef DXREADER_H
    33#define DXREADER_H
     4
     5#include <iostream>
    46
    57namespace Rappture {
  • trunk/packages/vizservers/nanovis/vrmath/vrQuaternion.cpp

    r2840 r2853  
    88#include <cstdlib>
    99#include <cmath>
     10#include <float.h>
     11
    1012#include <vrmath/vrQuaternion.h>
    1113#include <vrmath/vrRotation.h>
    1214#include <vrmath/vrLinmath.h>
    1315#include <vrmath/vrVector3f.h>
    14 #include <float.h>
    1516
    1617#ifndef PI
Note: See TracChangeset for help on using the changeset viewer.