Ignore:
Timestamp:
Apr 19, 2012 11:09:40 AM (12 years ago)
Author:
ldelgass
Message:

Remove unused volume axis/bbox labeling from VolumeRenderer?. This feature is
now provided by the Grid. Also remove unused volume/slice mode flags in
VolumeRenderer? since it now uses cutplane information from each Volume object
instead.

Location:
trunk/packages/vizservers/nanovis
Files:
1 deleted
5 edited

Legend:

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

    r2953 r2974  
    14901490
    14911491static int
    1492 VolumeAxisOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1493              Tcl_Obj *const *objv)
    1494 {
    1495     const char *string = Tcl_GetString(objv[2]);
    1496     char c;
    1497     c = string[0];
    1498     if ((c == 'l') && (strcmp(string, "label") == 0)) {
    1499         int axis;
    1500         if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) {
    1501             return TCL_ERROR;
    1502         }
    1503         std::vector<Volume *> ivol;
    1504         if (GetVolumes(interp, objc - 5, objv + 5, &ivol) != TCL_OK) {
    1505             return TCL_ERROR;
    1506         }
    1507         std::vector<Volume *>::iterator iter;
    1508         const char *label;
    1509         label = Tcl_GetString(objv[4]);
    1510         for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1511             (*iter)->setLabel(axis, label);
    1512         }
    1513     } else {
    1514         Tcl_AppendResult(interp, "bad option \"", string,
    1515                          "\": should be label", (char*)NULL);
    1516         return TCL_ERROR;
    1517     }
    1518     return TCL_OK;
    1519 }
    1520 
    1521 static int
    15221492VolumeStateOp(ClientData clientData, Tcl_Interp *interp, int objc,
    15231493              Tcl_Obj *const *objv)
     
    15571527static Rappture::CmdSpec volumeOps[] = {
    15581528    {"animation", 2, VolumeAnimationOp,   3, 0, "oper ?args?",},
    1559     {"axis",      2, VolumeAxisOp,        4, 0, "label axis value ?indices?",},
    15601529    {"data",      2, VolumeDataOp,        3, 0, "oper ?args?",},
    15611530    {"delete",    2, VolumeDeleteOp,      3, 0, "?name...?",},
     
    15721541 * ----------------------------------------------------------------------
    15731542 * CLIENT COMMAND:
    1574  *   volume axis label x|y|z <value> ?<volumeId> ...?
    15751543 *   volume data state on|off ?<volumeId> ...?
    15761544 *   volume outline state on|off ?<volumeId> ...?
  • trunk/packages/vizservers/nanovis/Makefile.in

    r2972 r2974  
    148148
    149149resources       = \
    150                 $(srcdir)/resources/Font.bmp \
    151150                $(srcdir)/resources/arrows.bmp \
    152151                $(srcdir)/resources/particle2.bmp \
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r2973 r2974  
    1515 */
    1616#include <stdlib.h>
    17 #include <assert.h>
    18 #include <time.h>
    19 #include <sys/time.h>
    2017#include <float.h>
    2118
     
    2320
    2421#include <GL/glew.h>
    25 #include <GL/glut.h>
    2622
    2723#include <tcl.h>
    28 
    29 #include <R2/R2FilePath.h>
    3024
    3125#include "nanovis.h"
    3226#include "VolumeRenderer.h"
    3327#include "ConvexPolygon.h"
    34 
    3528#include "NvStdVertexShader.h"
    3629#include "Trace.h"
    37 #include "Grid.h"
    38 
    39 #define NUMDIGITS       6
    40 
    41 VolumeRenderer::VolumeRenderer() :
    42     _sliceMode(false),
    43     _volumeMode(true)
     30
     31VolumeRenderer::VolumeRenderer()
    4432{
    4533    initShaders();
    4634
    47     std::string path = R2FilePath::getInstance()->getPath("Font.bmp");
    48     if (path.empty()) {
    49         ERROR("can't find Font.bmp\n");
    50         assert(!path.empty());
    51     }
    52     initFont(path.c_str());
    5335    _volumeInterpolator = new VolumeInterpolator();
    5436}
     
    209191                (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],
    210192                1.5);
    211         }
    212         glPopMatrix();
    213 
    214         //draw labels
    215         glPushMatrix();
    216         glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);
    217         if (volPtr->outline()) {
    218             //drawLabel(i);
    219193        }
    220194        glPopMatrix();
     
    491465    glEnd();
    492466
    493 #ifdef notdef
    494     /* Rappture doesn't supply axis units yet. So turn labeling off until we
    495      * can display the proper units with the distance of each bounding box
    496      * dimension.
    497      */
    498     glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
    499 
    500     if (NanoVis::fonts != NULL) {
    501         double mv[16], prjm[16];
    502         int viewport[4];
    503         double wx, wy, wz;
    504         double dx, dy, dz;
    505 
    506         glGetDoublev(GL_MODELVIEW_MATRIX, mv);
    507         glGetDoublev(GL_PROJECTION_MATRIX, prjm);
    508         glGetIntegerv(GL_VIEWPORT, viewport);
    509 
    510         NanoVis::fonts->begin();
    511         dx = x1 - x0;
    512         dy = y1 - y0;
    513         dz = z1 - z0;
    514         if (gluProject((x0 + x1) * 0.5, y0, z0, mv, prjm, viewport,
    515                        &wx, &wy, &wz)) {
    516             char buff[20];
    517             double min, max;
    518 
    519             NanoVis::grid->xAxis.GetDataLimits(min, max);
    520             glLoadIdentity();
    521             glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
    522             const char *units;
    523             units = NanoVis::grid->xAxis.GetUnits();
    524             sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
    525             NanoVis::fonts->draw(buff);
    526         }
    527         if (gluProject(x0, (y0 + y1) * 0.5, z0, mv, prjm, viewport, &
    528                        wx, &wy, &wz)) {
    529             char buff[20];
    530             double min, max;
    531 
    532             NanoVis::grid->yAxis.GetDataLimits(min, max);
    533             glLoadIdentity();
    534             glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
    535             const char *units;
    536             units = NanoVis::grid->yAxis.GetUnits();
    537             sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
    538             NanoVis::fonts->draw(buff);
    539         }
    540         if (gluProject(x0, y0, (z0 + z1) * 0.5, mv, prjm, viewport,
    541                        &wx, &wy, &wz)) {
    542             glLoadIdentity();
    543             glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
    544 
    545             double min, max;
    546             NanoVis::grid->zAxis.GetDataLimits(min, max);
    547             const char *units;
    548             units = NanoVis::grid->zAxis.GetUnits();
    549             char buff[20];
    550             sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
    551             NanoVis::fonts->draw(buff);
    552         }
    553         NanoVis::fonts->end();
    554     };
    555 #endif
    556467    glPopMatrix();
    557468    glPopAttrib();
     
    625536    zFar = zMin;
    626537}
    627 
    628 bool
    629 VolumeRenderer::initFont(const char *filename)
    630 {
    631     FILE *f;
    632     unsigned short int bfType;
    633     int bfOffBits;
    634     short int biPlanes;
    635     short int biBitCount;
    636     int biSizeImage;
    637     int width, height;
    638     int i;
    639     unsigned char temp;
    640     unsigned char* data;
    641     /* make sure the file is there and open it read-only (binary) */
    642     f = fopen(filename, "rb");
    643     if (f == NULL) {
    644         ERROR("can't open font file \"%s\"\n", filename);
    645         return false;
    646     }
    647 
    648     if (fread(&bfType, sizeof(short int), 1, f) != 1) {
    649         ERROR("can't read %lu bytes from font file \"%s\"\n",
    650                (unsigned long)sizeof(short int), filename);
    651         goto error;
    652     }
    653 
    654     /* check if file is a bitmap */
    655     if (bfType != 19778) {
    656         ERROR("not a bmp file.\n");
    657         goto error;
    658     }
    659 
    660     /* get the file size */
    661     /* skip file size and reserved fields of bitmap file header */
    662     fseek(f, 8, SEEK_CUR);
    663 
    664     /* get the position of the actual bitmap data */
    665     if (fread(&bfOffBits, sizeof(int), 1, f) != 1) {
    666         ERROR("error reading file.\n");
    667         goto error;
    668     }
    669     //TRACE("Data at Offset: %ld\n", bfOffBits);
    670 
    671     /* skip size of bitmap info header */
    672     fseek(f, 4, SEEK_CUR);
    673 
    674     /* get the width of the bitmap */
    675     if (fread(&width, sizeof(int), 1, f) != 1) {
    676         ERROR("error reading file.\n");
    677         goto error;
    678     }
    679     //TRACE("Width of Bitmap: %d\n", texture->width);
    680 
    681     /* get the height of the bitmap */
    682     if (fread(&height, sizeof(int), 1, f) != 1) {
    683         ERROR("error reading file.\n");
    684         goto error;
    685     }
    686     //TRACE("Height of Bitmap: %d\n", texture->height);
    687 
    688     /* get the number of planes (must be set to 1) */
    689     if (fread(&biPlanes, sizeof(short int), 1, f) != 1) {
    690         ERROR("error reading file.\n");
    691         goto error;
    692     }
    693     if (biPlanes != 1) {
    694         ERROR("number of Planes not 1!\n");
    695         goto error;
    696     }
    697 
    698     /* get the number of bits per pixel */
    699     if (fread(&biBitCount, sizeof(short int), 1, f) != 1) {
    700         ERROR("error reading file.\n");
    701         goto error;
    702     }
    703 
    704     //TRACE("Bits per Pixel: %d\n", biBitCount);
    705     if (biBitCount != 24) {
    706         ERROR("Bits per Pixel not 24\n");
    707         goto error;
    708     }
    709 
    710     /* calculate the size of the image in bytes */
    711     biSizeImage = width * height * 3 * sizeof(unsigned char);
    712     data = (unsigned char*) malloc(biSizeImage);
    713     if (data == NULL) {
    714         ERROR("Can't allocate memory for image\n");
    715         goto error;
    716     }
    717 
    718     /* seek to the actual data */
    719     fseek(f, bfOffBits, SEEK_SET);
    720     if (fread(data, biSizeImage, 1, f) != 1) {
    721         ERROR("Error loading file!\n");
    722         goto error;
    723     }
    724     fclose(f);
    725 
    726     /* swap red and blue (bgr -> rgb) */
    727     for (i = 0; i < biSizeImage; i += 3) {
    728        temp = data[i];
    729        data[i] = data[i + 2];
    730        data[i + 2] = temp;
    731     }
    732 
    733     //insert alpha channel
    734     unsigned char* data_with_alpha;
    735     data_with_alpha = (unsigned char*)
    736         malloc(width*height*4*sizeof(unsigned char));
    737     for (int i = 0; i < height; i++) {
    738         for (int j = 0; j < width; j++) {
    739             unsigned char r, g, b, a;
    740             r = data[3*(i*width+j)];
    741             g = data[3*(i*width+j)+1];
    742             b = data[3*(i*width+j)+2];
    743 
    744             if (r==0 && g==0 && b==0)
    745                 a = 0;
    746             else
    747                 a = 255;
    748 
    749             data_with_alpha[4*(i*width+j)] = r;
    750             data_with_alpha[4*(i*width+j) + 1] = g;
    751             data_with_alpha[4*(i*width+j) + 2] = b;
    752             data_with_alpha[4*(i*width+j) + 3] = a;
    753         }
    754     }
    755     free(data);
    756 
    757     //create opengl texture
    758     glGenTextures(1, &_fontTexture);
    759     glBindTexture(GL_TEXTURE_2D, _fontTexture);
    760     //glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
    761     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data_with_alpha);
    762     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    763     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    764     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    765 
    766     free(data_with_alpha);
    767 
    768     buildFont();
    769     return (glGetError()==0);
    770 
    771  error:
    772     fclose(f);
    773     return false;
    774 }
    775 
    776 void
    777 VolumeRenderer::drawLabel(Volume* vol)
    778 {
    779     //glEnable(GL_TEXTURE_2D);
    780     glDisable(GL_TEXTURE_2D);
    781     glEnable(GL_DEPTH_TEST);
    782 
    783     //x
    784     glColor3f(0.5, 0.5, 0.5);
    785 
    786     int length = vol->label[0].size();
    787     glPushMatrix();
    788 
    789     glTranslatef(.5 * vol->aspectRatioWidth,
    790                  vol->aspectRatioHeight,
    791                  -0.1 * vol->aspectRatioDepth);
    792     glRotatef(180, 0, 0, 1);
    793     glRotatef(90, 1, 0, 0);
    794 
    795     glScalef(0.0008, 0.0008, 0.0008);
    796     for (int i = 0; i < length; i++) {
    797         glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0].c_str()[i]);
    798         glTranslatef(0.04, 0., 0.);
    799     }
    800     glPopMatrix();
    801 
    802     //y
    803     length = vol->label[1].size();
    804     glPushMatrix();
    805     glTranslatef(vol->aspectRatioWidth,
    806                  0.5*vol->aspectRatioHeight,
    807                  -0.1*vol->aspectRatioDepth);
    808     glRotatef(90, 0, 1, 0);
    809     glRotatef(90, 0, 0, 1);
    810 
    811     glScalef(0.0008, 0.0008, 0.0008);
    812     for (int i = 0; i < length; i++) {
    813         glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1].c_str()[i]);
    814         glTranslatef(0.04, 0., 0.);
    815     }
    816     glPopMatrix();
    817 
    818     //z
    819     length = vol->label[2].size();
    820     glPushMatrix();
    821     glTranslatef(0.,
    822                  1. * vol->aspectRatioHeight,
    823                  0.5 * vol->aspectRatioDepth);
    824     glRotatef(90, 0, 1, 0);
    825 
    826     glScalef(0.0008, 0.0008, 0.0008);
    827     for (int i = 0; i < length; i++) {
    828         glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2].c_str()[i]);
    829         glTranslatef(0.04, 0., 0.);
    830     }
    831     glPopMatrix();
    832 
    833     glDisable(GL_TEXTURE_2D);
    834 }
    835 
    836 void
    837 VolumeRenderer::buildFont()
    838 {
    839     GLfloat cx, cy;         /* the character coordinates in our texture */
    840     _fontBase = glGenLists(256);
    841     glBindTexture(GL_TEXTURE_2D, _fontTexture);
    842     for (int loop = 0; loop < 256; loop++) {
    843         cx = (float) (loop % 16) / 16.0f;
    844         cy = (float) (loop / 16) / 16.0f;
    845         glNewList(_fontBase + loop, GL_COMPILE);
    846         glBegin(GL_QUADS);
    847         glTexCoord2f(cx, 1 - cy - 0.0625f);
    848         glVertex3f(0, 0, 0);
    849         glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f);
    850         glVertex3f(0.04, 0, 0);
    851         glTexCoord2f(cx + 0.0625f, 1 - cy);
    852         glVertex3f(0.04, 0.04, 0);
    853         glTexCoord2f(cx, 1 - cy);
    854         glVertex3f(0, 0.04, 0);
    855         glEnd();
    856         glTranslated(0.04, 0, 0);
    857         glEndList();
    858     }
    859 }
    860 
    861 void
    862 VolumeRenderer::glPrint(char* string, int set)
    863 {
    864     if (set > 1) {
    865         set = 1;
    866     }
    867     glBindTexture(GL_TEXTURE_2D, _fontTexture);
    868     glListBase(_fontBase - 32 + (128 * set));
    869     glCallLists(strlen(string), GL_BYTE, string);
    870 }
  • trunk/packages/vizservers/nanovis/VolumeRenderer.h

    r2973 r2974  
    1616#ifndef _VOLUME_RENDERER_H_
    1717#define _VOLUME_RENDERER_H_
    18 
    19 #include <GL/glew.h>
    2018
    2119#include "Mat4x4.h"
     
    3937
    4038    void diffuse(float val);
    41 
    42     /// control independently
    43     void setSliceMode(bool val)
    44     {
    45         _sliceMode = val;
    46     }
    47 
    48     void setVolumeMode(bool val)
    49     {
    50         _volumeMode = val;
    51     }
    52 
    53     /// switch_cutplane_mode
    54     void switchSliceMode()
    55     {
    56         _sliceMode = (!_sliceMode);
    57     }
    58 
    59     void switchVolumeMode()
    60     {
    61         _volumeMode = (!_volumeMode);
    62     }
    6339
    6440    void clearAnimatedVolumeInfo()
     
    10581                           double& zNear, double& zFar);
    10682
    107     bool initFont(const char *filename);
    108 
    109     /// there are two sets of font in the texture. 0, 1
    110     void glPrint(char *string, int set);
    111 
    112     /// draw label using bitmap texture
    113     void drawLabel(Volume *vol);
    114 
    115     /// Register the location of each alphabet in
    116     void buildFont();
    117 
    11883    VolumeInterpolator *_volumeInterpolator;
    119 
    120     bool _sliceMode;  ///< enable cut planes
    121     bool _volumeMode; ///< enable full volume rendering
    12284
    12385    /**
     
    146108     */
    147109    NvStdVertexShader *_stdVertexShader;
    148 
    149     GLuint _fontBase;      ///< The base of the font display list.
    150     GLuint _fontTexture;   ///< The id of the font texture
    151110};
    152111
  • trunk/packages/vizservers/nanovis/protocol-nanovis.txt

    r2953 r2974  
    126126          -size <val>
    127127
    128 volume axis label <x|y|z> <value> <?names?>
    129128volume data state <on|off> <?names?>
    130129volume data follows <size> <tag>
Note: See TracChangeset for help on using the changeset viewer.