Changeset 1028 for trunk/packages


Ignore:
Timestamp:
Jun 9, 2008 9:08:02 AM (16 years ago)
Author:
gah
Message:

various cleanups

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

Legend:

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

    r955 r1028  
    122122    _name = NULL;
    123123    SetName(name);
     124    _units = NULL;
    124125    _title = NULL;
    125126    _valueMin = DBL_MAX, _valueMax = -DBL_MAX;
  • trunk/packages/vizservers/nanovis/Axis.h

    r939 r1028  
    187187    };
    188188
    189     char *_name;                /* Name of the axis. Malloc-ed */
     189    const char *_name;          /* Name of the axis. Malloc-ed */
    190190
    191191    unsigned int _flags;
    192192
    193     char *_title;               /* Title of the axis. */
     193    const char *_title;         /* Title of the axis. */
     194
     195    const char *_units;         /* Units of the axis. */
    194196
    195197    double _valueMin, _valueMax; /* The limits of the data. */
     
    227229public:
    228230    Axis(const char *name);
     231    ~Axis(void) {
     232        if (_name != NULL) {
     233            free((void *)_name);
     234        }
     235        if (_units != NULL) {
     236            free((void *)_units);
     237        }
     238        if (_title != NULL) {
     239            free((void *)_title);
     240        }
     241    }
    229242
    230243    void ResetRange(void);
     
    243256        return _minor.FirstTick(iter);
    244257    }
    245     void GetDataLimits(double min, double max);
     258    void GetDataLimits(double &min, double &max) {
     259        min = _valueMin, max = _valueMax;
     260    }
    246261    double Map(double x);
    247262    double InvMap(double x);
    248     char *GetName(void) {
    249         return _name;
     263    const char *GetName(void) {
     264        return (_name == NULL) ? "???" : _name;
    250265    }
    251266    void SetName(const char *name) {
    252         _name = new char[strlen(name) + 1];
    253         strcpy(_name, name);
     267        if (_name != NULL) {
     268            free((void *)_name);
     269        }
     270        _name = strdup(name);
     271    }
     272    const char *GetUnits(void) {
     273        return (_units == NULL) ? "???" : _units;
     274    }
     275    void SetUnits(const char *units) {
     276        if (_units != NULL) {
     277            free((void *)_units);
     278        }
     279        _units = strdup(units);
     280    }
     281    const char *GetTitle(void) {
     282        return (_title == NULL) ? "???" : _title;
     283    }
     284    void SetTitle(const char *title) {
     285        if (_title != NULL) {
     286            free((void *)_title);
     287        }
     288        _title = strdup(title);
    254289    }
    255290    void SetMin(double min) {
  • trunk/packages/vizservers/nanovis/Command.cpp

    r1000 r1028  
    7373#include <NvLIC.h>
    7474
    75 //#define ISO_TEST                1
     75#define ISO_TEST                1
    7676#define PLANE_CMD               0
    7777#define __TEST_CODE__           0
     
    143143#endif
    144144static Tcl_ObjCmdProc ScreenCmd;
    145 static Tcl_ObjCmdProc ScreenShotCmd;
     145static Tcl_ObjCmdProc SnapshotCmd;
    146146static Tcl_ObjCmdProc TransfuncCmd;
    147147static Tcl_ObjCmdProc UniRect2dCmd;
     
    175175static int
    176176GetCullMode(Tcl_Interp *interp, Tcl_Obj *objPtr,
    177             graphics::RenderContext::CullMode *modePtr)
    178 {
    179     char *string = Tcl_GetString(objPtr);
     177            graphics::RenderContext::CullMode *modePtr)
     178{
     179    const char *string = Tcl_GetString(objPtr);
    180180    if (strcmp(string, "none") == 0) {
    181181        *modePtr = graphics::RenderContext::NO_CULL;
     
    186186    } else {
    187187        Tcl_AppendResult(interp, "invalid cull mode \"", string,
    188                         "\": should be front, back, or none\"", (char *)NULL);
     188                        "\": should be front, back, or none\"", (char *)NULL);
    189189        return TCL_ERROR;
    190190    }
     
    196196                graphics::RenderContext::ShadingModel *modelPtr)
    197197{
    198     char *string = Tcl_GetString(objPtr);
     198    const char *string = Tcl_GetString(objPtr);
     199
    199200    if (strcmp(string,"flat") == 0) {
    200201        *modelPtr = graphics::RenderContext::FLAT;
     
    213214               graphics::RenderContext::PolygonMode *modePtr)
    214215{
    215     char *string = Tcl_GetString(objPtr);
     216    const char *string = Tcl_GetString(objPtr);
     217
    216218    if (strcmp(string,"wireframe") == 0) {
    217219        *modePtr = graphics::RenderContext::LINE;
     
    220222    } else {
    221223        Tcl_AppendResult(interp, "invalid polygon mode \"", string,
    222                         "\": should be wireframe or fill\"", (char *)NULL);
     224                        "\": should be wireframe or fill\"", (char *)NULL);
    223225        return TCL_ERROR;
    224226    }
     
    243245static HeightMap *
    244246CreateHeightMap(ClientData clientData, Tcl_Interp *interp, int objc,
    245                 Tcl_Obj *CONST *objv)
     247                Tcl_Obj *const *objv)
    246248{
    247249    float xMin, yMin, xMax, yMax;
     
    250252    if (objc != 7) {
    251253        Tcl_AppendResult(interp,
    252                         "wrong # of values: should be xMin yMin xMax yMax xNum yNum heights",
    253                         (char *)NULL);
     254        "wrong # of values: should be xMin yMin xMax yMax xNum yNum heights",
     255        (char *)NULL);
    254256        return NULL;
    255257    }
     
    280282    if (heights == NULL) {
    281283        Tcl_AppendResult(interp, "can't allocate array of heights",
    282                         (char *)NULL);
     284                        (char *)NULL);
    283285        return NULL;
    284286    }
     
    317319    if (index < 0) {
    318320        Tcl_AppendResult(interp, "can't have negative index \"",
    319                         Tcl_GetString(objPtr), "\"", (char*)NULL);
     321                        Tcl_GetString(objPtr), "\"", (char*)NULL);
    320322        return TCL_ERROR;
    321323    }
     
    347349    if (hmPtr == NULL) {
    348350        Tcl_AppendResult(interp, "no heightmap defined for index \"",
    349                         Tcl_GetString(objPtr), "\"", (char*)NULL);
     351                        Tcl_GetString(objPtr), "\"", (char*)NULL);
    350352        return TCL_ERROR;
    351353    }
     
    376378    if (index < 0) {
    377379        Tcl_AppendResult(interp, "can't have negative index \"",
    378                         Tcl_GetString(objPtr), "\"", (char*)NULL);
     380                        Tcl_GetString(objPtr), "\"", (char*)NULL);
    379381        return TCL_ERROR;
    380382    }
     
    412414    if (vol == NULL) {
    413415        Tcl_AppendResult(interp, "no volume defined for index \"",
    414                         Tcl_GetString(objPtr), "\"", (char*)NULL);
     416                        Tcl_GetString(objPtr), "\"", (char*)NULL);
    415417        return TCL_ERROR;
    416418    }
     
    433435 */
    434436static int
    435 GetVolumeIndices(Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv,
    436                 vector<unsigned int>* vectorPtr)
     437GetVolumeIndices(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,
     438                vector<unsigned int>* vectorPtr)
    437439{
    438440    if (objc == 0) {
     
    471473 */
    472474static int
    473 GetVolumes(Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv,
    474            vector<Volume *>* vectorPtr)
     475GetVolumes(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,
     476           vector<Volume *>* vectorPtr)
    475477{
    476478    if (objc == 0) {
     
    487489                return TCL_ERROR;
    488490            }
    489             vectorPtr->push_back(volPtr);
     491            vectorPtr->push_back(volPtr);
    490492        }
    491493    }
     
    507509 */
    508510static int
    509 GetHeightMaps(Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv,
    510            vector<HeightMap *>* vectorPtr)
     511GetHeightMaps(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,
     512           vector<HeightMap *>* vectorPtr)
    511513{
    512514    if (objc == 0) {
     
    523525                return TCL_ERROR;
    524526            }
    525             vectorPtr->push_back(hmPtr);
     527            vectorPtr->push_back(hmPtr);
    526528        }
    527529    }
     
    560562    }
    561563    Tcl_AppendResult(interp, "bad axis \"", string,
    562                      "\": should be x, y, or z", (char*)NULL);
     564                     "\": should be x, y, or z", (char*)NULL);
    563565    return TCL_ERROR;
    564566}
     
    593595GetAxisDirFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *indexPtr, int *dirPtr)
    594596{
    595     char *string = Tcl_GetString(objPtr);
     597    const char *string = Tcl_GetString(objPtr);
    596598
    597599    int sign = 1;
     
    620622 */
    621623static int
    622 GetColor(Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv, float *rgbPtr)
     624GetColor(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, float *rgbPtr)
    623625{
    624626    if (objc < 3) {
    625627        Tcl_AppendResult(interp, "missing color values\": ",
    626                         "should list of R G B values 0.0 - 1.0", (char*)NULL);
     628                        "should list of R G B values 0.0 - 1.0", (char*)NULL);
    627629        return TCL_ERROR;
    628630    }
     
    661663        if (ferror(stdin)) {
    662664            Tcl_AppendResult(interp, "while reading data stream: ",
    663                              Tcl_PosixError(interp), (char*)NULL);
     665                             Tcl_PosixError(interp), (char*)NULL);
    664666            return TCL_ERROR;
    665667        }
    666668        if (feof(stdin)) {
    667669            Tcl_AppendResult(interp, "premature EOF while reading data stream",
    668                              (char*)NULL);
     670                             (char*)NULL);
    669671            return TCL_ERROR;
    670672        }
     
    687689
    688690static int
    689 CameraAimOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     691CameraAimOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    690692{
    691693    double x0, y0, z0;
     
    700702
    701703static int
    702 CameraAngleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     704CameraAngleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    703705{
    704706    double xangle, yangle, zangle;
     
    713715
    714716static int
    715 CameraZoomOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     717CameraZoomOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    716718{
    717719    double zoom;
     
    744746 */
    745747static int
    746 CameraCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     748CameraCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    747749{
    748750    Tcl_ObjCmdProc *proc;
    749751
    750752    proc = Rappture::GetOpFromObj(interp, nCameraOps, cameraOps,
    751                                   Rappture::CMDSPEC_ARG1, objc, objv, 0);
     753                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
    752754    if (proc == NULL) {
    753755        return TCL_ERROR;
     
    756758}
    757759
    758 static int
    759 ScreenShotCmd(ClientData cdata, Tcl_Interp *interp, int objc,
    760               Tcl_Obj *CONST *objv)
    761 {
    762 #ifdef XINETD
    763     NanoVis::resize_offscreen_buffer(1024, 1024);
    764     NanoVis::cam->set_screen_size(30, 90, 1024 - 60, 1024 - 120);
     760/*ARGSUSED*/
     761static int
     762SnapshotCmd(ClientData cdata, Tcl_Interp *interp, int objc,
     763              Tcl_Obj *const *objv)
     764{
     765    int w, h;
     766
     767    w = NanoVis::win_width, h = NanoVis::win_height;
     768    NanoVis::resize_offscreen_buffer(2048, 2048);
     769#ifdef notdef
     770    NanoVis::cam->set_screen_size(0, 0, NanoVis::win_width,NanoVis::win_height);
     771    NanoVis::cam->set_screen_size(30, 90, 2048 - 60, 2048 - 120);
     772#endif
    765773    NanoVis::offscreen_buffer_capture();  //enable offscreen render
    766774    NanoVis::display();
    767 
    768     // INSOO
    769     // TBD
    770     /*
    771       Volume* vol = NanoVis::volume[0];
    772       TransferFunction* tf;
    773       tf = NanoVis::vol_renderer->get_volume_shading(vol);
    774       if (tf != NULL)
    775       {
    776       float data[512];
    777 
    778       for (int i=0; i < 256; i++) {
    779       data[i] = data[i+256] = (float)(i/255.0);
    780       }
    781       Texture2D* plane = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data);
    782       NanoVis::color_table_renderer->render(1024, 1024, plane, tf, vol->wAxis.Min(),
    783                 vol->wAxis.Max());
    784       delete plane;
    785    
    786       }
    787     */
     775    NanoVis::read_screen();
     776#ifdef notdef
     777    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    788778#endif
    789 
     779    NanoVis::ppm_write("nv>print -bytes");
     780    NanoVis::resize_offscreen_buffer(w, h);
    790781    return TCL_OK;
    791782}
     
    793784static int
    794785CutplanePositionOp(ClientData cdata, Tcl_Interp *interp, int objc,
    795                    Tcl_Obj *CONST *objv)
     786                   Tcl_Obj *const *objv)
    796787{
    797788    float relval;
     
    825816static int
    826817CutplaneStateOp(ClientData cdata, Tcl_Interp *interp, int objc,
    827                 Tcl_Obj *CONST *objv)
     818                Tcl_Obj *const *objv)
    828819{
    829820    bool state;
     
    877868 */
    878869static int
    879 CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     870CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int objc,
     871            Tcl_Obj *const *objv)
    880872{
    881873    Tcl_ObjCmdProc *proc;
    882874
    883875    proc = Rappture::GetOpFromObj(interp, nCutplaneOps, cutplaneOps,
    884                                   Rappture::CMDSPEC_ARG1, objc, objv, 0);
     876                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
    885877    if (proc == NULL) {
    886878        return TCL_ERROR;
     
    901893 */
    902894static int
    903 LegendCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     895LegendCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    904896{
    905897    if (objc != 4) {
    906898        Tcl_AppendResult(interp, "wrong # args: should be \"",
    907                         Tcl_GetString(objv[0]), " volIndex width height\"", (char*)NULL);
     899            Tcl_GetString(objv[0]), " volIndex width height\"", (char*)NULL);
    908900        return TCL_ERROR;
    909901    }
     
    917909    if (tf == NULL) {
    918910        Tcl_AppendResult(interp, "no transfer function defined for volume \"",
    919                         Tcl_GetString(objv[1]), "\"", (char*)NULL);
    920         return TCL_ERROR;
    921     }
    922     char *label;
     911                        Tcl_GetString(objv[1]), "\"", (char*)NULL);
     912        return TCL_ERROR;
     913    }
     914    const char *label;
    923915    label = Tcl_GetString(objv[1]);
    924916
     
    929921    }
    930922    if (volPtr->update_pending) {
    931         NanoVis::SetVolumeRanges();
     923        NanoVis::SetVolumeRanges();
    932924    }
    933925    NanoVis::render_legend(tf, Volume::valueMin, Volume::valueMax, w, h, label);
     
    945937 */
    946938static int
    947 ScreenCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     939ScreenCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    948940{
    949941    if (objc != 3) {
    950942        Tcl_AppendResult(interp, "wrong # args: should be \"",
    951                         Tcl_GetString(objv[0]), " width height\"", (char*)NULL);
     943                        Tcl_GetString(objv[0]), " width height\"", (char*)NULL);
    952944        return TCL_ERROR;
    953945    }
     
    974966static int
    975967TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc,
    976              Tcl_Obj *CONST *objv)
     968             Tcl_Obj *const *objv)
    977969{
    978970    if (objc < 2) {
    979971        Tcl_AppendResult(interp, "wrong # args: should be \"",
    980                 Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL);
    981         return TCL_ERROR;
    982     }
    983 
    984     char *string = Tcl_GetString(objv[1]);
     972                Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL);
     973        return TCL_ERROR;
     974    }
     975
     976    const char *string = Tcl_GetString(objv[1]);
    985977    char c = string[0];
    986     if ((c == 'd') && (strcmp(string, "define") == 0))
    987     {
     978    if ((c == 'd') && (strcmp(string, "define") == 0)) {
    988979        if (objc != 5) {
    989980            Tcl_AppendResult(interp, "wrong # args: should be \"",
    990                     Tcl_GetString(objv[0]), " define name colorMap alphaMap\"",
    991                 (char*)NULL);
     981                Tcl_GetString(objv[0]), " define name colorMap alphaMap\"",
     982                (char*)NULL);
    992983            return TCL_ERROR;
    993984        }
     
    1005996        if ((cmapc % 4) != 0) {
    1006997            Tcl_AppendResult(interp, "wrong # elements is colormap: should be ",
    1007                 "{ v r g b ... }", (char*)NULL);
     998                "{ v r g b ... }", (char*)NULL);
    1008999            return TCL_ERROR;
    10091000        }
     
    10131004        if ((wmapc % 2) != 0) {
    10141005            Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ",
    1015                 " { v w ... }", (char*)NULL);
     1006                " { v w ... }", (char*)NULL);
    10161007            return TCL_ERROR;
    10171008        }
     
    10261017                if ((q[j] < 0.0) || (q[j] > 1.0)) {
    10271018                    Tcl_AppendResult(interp, "bad colormap value \"",
    1028                         Tcl_GetString(cmapv[i+j]),
    1029                         "\": should be in the range 0-1", (char*)NULL);
     1019                        Tcl_GetString(cmapv[i+j]),
     1020                        "\": should be in the range 0-1", (char*)NULL);
    10301021                    return TCL_ERROR;
    10311022                }
     
    10451036                if ((q[j] < 0.0) || (q[j] > 1.0)) {
    10461037                    Tcl_AppendResult(interp, "bad alphamap value \"",
    1047                         Tcl_GetString(wmapv[i+j]),
    1048                         "\": should be in the range 0-1", (char*)NULL);
     1038                        Tcl_GetString(wmapv[i+j]),
     1039                        "\": should be in the range 0-1", (char*)NULL);
    10491040                    return TCL_ERROR;
    10501041                }
     
    10661057    } else {
    10671058        Tcl_AppendResult(interp, "bad option \"", string,
    1068                 "\": should be define", (char*)NULL);
     1059                "\": should be define", (char*)NULL);
    10691060        return TCL_ERROR;
    10701061    }
     
    10821073 */
    10831074static int
    1084 UpCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     1075UpCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    10851076{
    10861077    if (objc != 2) {
    10871078        Tcl_AppendResult(interp, "wrong # args: should be \"",
    1088                         Tcl_GetString(objv[0]), " x|y|z|-x|-y|-z\"", (char*)NULL);
     1079                        Tcl_GetString(objv[0]), " x|y|z|-x|-y|-z\"", (char*)NULL);
    10891080        return TCL_ERROR;
    10901081    }
     
    11021093static int
    11031094VolumeAnimationCaptureOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1104                          Tcl_Obj *CONST *objv)
     1095                         Tcl_Obj *const *objv)
    11051096{
    11061097    int total;
    11071098    if (Tcl_GetIntFromObj(interp, objv[3], &total) != TCL_OK) {
    1108         return TCL_ERROR;
     1099        return TCL_ERROR;
    11091100    }
    11101101    VolumeInterpolator* interpolator;
     
    11121103    interpolator->start();
    11131104    if (interpolator->is_started()) {
    1114         char *fileName = (objc < 5) ? NULL : Tcl_GetString(objv[4]);
    1115         for (int frame_num = 0; frame_num < total; ++frame_num) {
    1116             float fraction;
    1117            
    1118             fraction = ((float)frame_num) / (total - 1);
    1119             Trace("fraction : %f\n", fraction);
    1120             //interpolator->update(((float)frame_num) / (total - 1));
    1121             interpolator->update(fraction);
    1122            
    1123             NanoVis::offscreen_buffer_capture();  //enable offscreen render
    1124            
    1125             NanoVis::display();
    1126             NanoVis::read_screen();
    1127            
    1128             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     1105        const char *fileName = (objc < 5) ? NULL : Tcl_GetString(objv[4]);
     1106        for (int frame_num = 0; frame_num < total; ++frame_num) {
     1107            float fraction;
    11291108           
    1130             NanoVis::bmp_write_to_file(frame_num, fileName);
    1131         }
     1109            fraction = ((float)frame_num) / (total - 1);
     1110            Trace("fraction : %f\n", fraction);
     1111            //interpolator->update(((float)frame_num) / (total - 1));
     1112            interpolator->update(fraction);
     1113           
     1114            NanoVis::offscreen_buffer_capture();  //enable offscreen render
     1115           
     1116            NanoVis::display();
     1117            NanoVis::read_screen();
     1118           
     1119            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     1120           
     1121            NanoVis::bmp_write_to_file(frame_num, fileName);
     1122        }
    11321123    }
    11331124    return TCL_OK;
     
    11361127static int
    11371128VolumeAnimationClearOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1138                        Tcl_Obj *CONST *objv)
     1129                       Tcl_Obj *const *objv)
    11391130{
    11401131    NanoVis::vol_renderer->clearAnimatedVolumeInfo();
     
    11441135static int
    11451136VolumeAnimationStartOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1146                        Tcl_Obj *CONST *objv)
     1137                       Tcl_Obj *const *objv)
    11471138{
    11481139    NanoVis::vol_renderer->startVolumeAnimation();
     
    11521143static int
    11531144VolumeAnimationStopOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1154                       Tcl_Obj *CONST *objv)
     1145                      Tcl_Obj *const *objv)
    11551146{
    11561147    NanoVis::vol_renderer->stopVolumeAnimation();
     
    11601151static int
    11611152VolumeAnimationVolumesOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1162                          Tcl_Obj *CONST *objv)
     1153                         Tcl_Obj *const *objv)
    11631154{
    11641155    vector<unsigned int> ivol;
    11651156    if (GetVolumeIndices(interp, objc - 3, objv + 3, &ivol) != TCL_OK) {
    1166         return TCL_ERROR;
     1157        return TCL_ERROR;
    11671158    }
    11681159    Trace("parsing volume index\n");
    11691160    vector<unsigned int>::iterator iter;
    11701161    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1171         Trace("index: %d\n", *iter);
    1172         NanoVis::vol_renderer->addAnimatedVolume(NanoVis::volume[*iter], *iter);
     1162        Trace("index: %d\n", *iter);
     1163        NanoVis::vol_renderer->addAnimatedVolume(NanoVis::volume[*iter], *iter);
    11731164    }
    11741165    return TCL_OK;
     
    11871178static int
    11881179VolumeAnimationOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1189                   Tcl_Obj *CONST *objv)
     1180                  Tcl_Obj *const *objv)
    11901181{
    11911182    Tcl_ObjCmdProc *proc;
    11921183
    11931184    proc = Rappture::GetOpFromObj(interp, nVolumeAnimationOps, volumeAnimationOps,
    1194                                   Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1185                                  Rappture::CMDSPEC_ARG2, objc, objv, 0);
    11951186    if (proc == NULL) {
    11961187        return TCL_ERROR;
     
    12021193static int
    12031194VolumeDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1204                     Tcl_Obj *CONST *objv)
     1195                    Tcl_Obj *const *objv)
    12051196{
    12061197    printf("Data Loading\n");
     
    13351326       
    13361327        if (Volume::update_pending) {
    1337             NanoVis::SetVolumeRanges();
     1328            NanoVis::SetVolumeRanges();
    13381329        }
    13391330        volPtr = NanoVis::volume[n];
    13401331        sprintf(info, "nv>data id %d min %g max %g vmin %g vmax %g\n",
    13411332                n, volPtr->wAxis.Min(), volPtr->wAxis.Max(),
    1342                 Volume::valueMin, Volume::valueMax);
     1333                Volume::valueMin, Volume::valueMax);
    13431334        write(0, info, strlen(info));
    13441335    }
     
    13481339static int
    13491340VolumeDataStateOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1350                   Tcl_Obj *CONST *objv)
     1341                  Tcl_Obj *const *objv)
    13511342{
    13521343    bool state;
     
    13801371static int
    13811372VolumeDataOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1382              Tcl_Obj *CONST *objv)
     1373             Tcl_Obj *const *objv)
    13831374{
    13841375    Tcl_ObjCmdProc *proc;
    13851376
    13861377    proc = Rappture::GetOpFromObj(interp, nVolumeDataOps, volumeDataOps,
    1387                                   Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1378                                  Rappture::CMDSPEC_ARG2, objc, objv, 0);
    13881379    if (proc == NULL) {
    13891380        return TCL_ERROR;
     
    13941385static int
    13951386VolumeOutlineColorOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1396                      Tcl_Obj *CONST *objv)
     1387                     Tcl_Obj *const *objv)
    13971388{
    13981389    float rgb[3];
    13991390    if (GetColor(interp, objc - 3, objv + 3, rgb) != TCL_OK) {
    1400         return TCL_ERROR;
     1391        return TCL_ERROR;
    14011392    }
    14021393    vector<Volume *> ivol;
    14031394    if (GetVolumes(interp, objc - 6, objv + 6, &ivol) != TCL_OK) {
    1404         return TCL_ERROR;
     1395        return TCL_ERROR;
    14051396    }
    14061397    vector<Volume *>::iterator iter;
    14071398    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1408         (*iter)->set_outline_color(rgb);
     1399        (*iter)->set_outline_color(rgb);
    14091400    }
    14101401    return TCL_OK;
     
    14131404static int
    14141405VolumeOutlineStateOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1415                      Tcl_Obj *CONST *objv)
     1406                     Tcl_Obj *const *objv)
    14161407{
    14171408    bool state;
    14181409    if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) {
    1419         return TCL_ERROR;
     1410        return TCL_ERROR;
    14201411    }
    14211412    vector<Volume *> ivol;
    14221413    if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) {
    1423         return TCL_ERROR;
     1414        return TCL_ERROR;
    14241415    }
    14251416    if (state) {
    1426         vector<Volume *>::iterator iter;
    1427         for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1428             (*iter)->enable_outline();
    1429         }
     1417        vector<Volume *>::iterator iter;
     1418        for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1419            (*iter)->enable_outline();
     1420        }
    14301421    } else {
    1431         vector<Volume *>::iterator iter;
    1432         for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1433             (*iter)->disable_outline();
    1434         }
     1422        vector<Volume *>::iterator iter;
     1423        for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1424            (*iter)->disable_outline();
     1425        }
    14351426    }
    14361427    return TCL_OK;
     
    14471438static int
    14481439VolumeOutlineOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1449                 Tcl_Obj *CONST *objv)
     1440                Tcl_Obj *const *objv)
    14501441{
    14511442    Tcl_ObjCmdProc *proc;
    14521443
    14531444    proc = Rappture::GetOpFromObj(interp, nVolumeOutlineOps, volumeOutlineOps,
    1454                                   Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1445        Rappture::CMDSPEC_ARG2, objc, objv, 0);
    14551446    if (proc == NULL) {
    14561447        return TCL_ERROR;
     
    14611452static int
    14621453VolumeShadingDiffuseOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1463                        Tcl_Obj *CONST *objv)
     1454                       Tcl_Obj *const *objv)
    14641455{
    14651456    float diffuse;
    14661457    if (GetFloatFromObj(interp, objv[3], &diffuse) != TCL_OK) {
    1467         return TCL_ERROR;
     1458        return TCL_ERROR;
    14681459    }
    14691460
    14701461    vector<Volume *> ivol;
    14711462    if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) {
    1472         return TCL_ERROR;
     1463        return TCL_ERROR;
    14731464    }
    14741465    vector<Volume *>::iterator iter;
    14751466    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1476             (*iter)->set_diffuse(diffuse);
     1467        (*iter)->set_diffuse(diffuse);
    14771468    }
    14781469    return TCL_OK;
     
    14811472static int
    14821473VolumeShadingIsosurfaceOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1483                           Tcl_Obj *CONST *objv)
     1474                          Tcl_Obj *const *objv)
    14841475{
    14851476    bool iso_surface;
    14861477    if (GetBooleanFromObj(interp, objv[3], &iso_surface) != TCL_OK) {
    1487         return TCL_ERROR;
     1478        return TCL_ERROR;
    14881479    }
    14891480    vector<Volume *> ivol;
    14901481    if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) {
    1491         return TCL_ERROR;
     1482        return TCL_ERROR;
    14921483    }
    14931484    vector<Volume *>::iterator iter;
    14941485    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1495         (*iter)->set_isosurface(iso_surface);
     1486        (*iter)->set_isosurface(iso_surface);
    14961487    }
    14971488    return TCL_OK;
     
    15001491static int
    15011492VolumeShadingOpacityOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1502                        Tcl_Obj *CONST *objv)
     1493                       Tcl_Obj *const *objv)
    15031494{
    15041495
    15051496    float opacity;
    15061497    if (GetFloatFromObj(interp, objv[3], &opacity) != TCL_OK) {
    1507         return TCL_ERROR;
     1498        return TCL_ERROR;
    15081499    }
    15091500    printf("set opacity %f\n", opacity);
    15101501    vector<Volume *> ivol;
    15111502    if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) {
    1512         return TCL_ERROR;
     1503        return TCL_ERROR;
    15131504    }
    15141505    vector<Volume *>::iterator iter;
    15151506    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1516         (*iter)->set_opacity_scale(opacity);
     1507        (*iter)->set_opacity_scale(opacity);
    15171508    }
    15181509    return TCL_OK;
     
    15211512static int
    15221513VolumeShadingSpecularOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1523                         Tcl_Obj *CONST *objv)
     1514                        Tcl_Obj *const *objv)
    15241515{
    15251516    float specular;
    15261517    if (GetFloatFromObj(interp, objv[3], &specular) != TCL_OK) {
    1527         return TCL_ERROR;
     1518        return TCL_ERROR;
    15281519    }
    15291520    vector<Volume *> ivol;
    15301521    if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) {
    1531         return TCL_ERROR;
     1522        return TCL_ERROR;
    15321523    }
    15331524    vector<Volume *>::iterator iter;
    15341525    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1535         (*iter)->set_specular(specular);
     1526        (*iter)->set_specular(specular);
    15361527    }
    15371528    return TCL_OK;
     
    15401531static int
    15411532VolumeShadingTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1542                          Tcl_Obj *CONST *objv)
     1533                         Tcl_Obj *const *objv)
    15431534{
    15441535    TransferFunction *tf;
    1545     char *name = Tcl_GetString(objv[3]);
     1536    const char *name = Tcl_GetString(objv[3]);
    15461537    tf = NanoVis::get_transfunc(name);
    15471538    if (tf == NULL) {
    1548         Tcl_AppendResult(interp, "transfer function \"", name,
    1549                         "\" is not defined", (char*)NULL);
    1550         return TCL_ERROR;
     1539        Tcl_AppendResult(interp, "transfer function \"", name,
     1540                        "\" is not defined", (char*)NULL);
     1541        return TCL_ERROR;
    15511542    }
    15521543    vector<Volume *> ivol;
    15531544    if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) {
    1554         return TCL_ERROR;
     1545        return TCL_ERROR;
    15551546    }
    15561547    vector<Volume *>::iterator iter;
    15571548    for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1558         NanoVis::vol_renderer->shade_volume(*iter, tf);
     1549        NanoVis::vol_renderer->shade_volume(*iter, tf);
    15591550#ifdef POINTSET
    1560         // TBD..
    1561         // POINTSET
    1562         if ((*iter)->pointsetIndex != -1) {
    1563             g_pointSet[(*iter)->pointsetIndex]->updateColor(tf->getData(), 256);
    1564         }
     1551        // TBD..
     1552        // POINTSET
     1553        if ((*iter)->pointsetIndex != -1) {
     1554            g_pointSet[(*iter)->pointsetIndex]->updateColor(tf->getData(), 256);
     1555        }
    15651556#endif /*POINTSET*/
    15661557    }
     
    15791570static int
    15801571VolumeShadingOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1581                 Tcl_Obj *CONST *objv)
     1572                Tcl_Obj *const *objv)
    15821573{
    15831574    Tcl_ObjCmdProc *proc;
    15841575
    15851576    proc = Rappture::GetOpFromObj(interp, nVolumeShadingOps, volumeShadingOps,
    1586         Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1577        Rappture::CMDSPEC_ARG2, objc, objv, 0);
    15871578    if (proc == NULL) {
    15881579        return TCL_ERROR;
     
    15931584static int
    15941585VolumeAxisOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1595              Tcl_Obj *CONST *objv)
    1596 {
    1597     char *string = Tcl_GetString(objv[2]);
     1586             Tcl_Obj *const *objv)
     1587{
     1588    const char *string = Tcl_GetString(objv[2]);
    15981589    char c;
    15991590    c = string[0];
    16001591    if ((c == 'l') && (strcmp(string, "label") == 0)) {
    1601         int axis;
    1602         if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) {
    1603             return TCL_ERROR;
    1604         }
    1605         vector<Volume *> ivol;
    1606         if (GetVolumes(interp, objc - 5, objv + 5, &ivol) != TCL_OK) {
    1607             return TCL_ERROR;
    1608         }
    1609         vector<Volume *>::iterator iter;
    1610         char *label;
    1611         label = Tcl_GetString(objv[4]);
    1612         for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1613             (*iter)->set_label(axis, label);
    1614         }
     1592        int axis;
     1593        if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) {
     1594            return TCL_ERROR;
     1595        }
     1596        vector<Volume *> ivol;
     1597        if (GetVolumes(interp, objc - 5, objv + 5, &ivol) != TCL_OK) {
     1598            return TCL_ERROR;
     1599        }
     1600        vector<Volume *>::iterator iter;
     1601        const char *label;
     1602        label = Tcl_GetString(objv[4]);
     1603        for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1604            (*iter)->set_label(axis, label);
     1605        }
    16151606    } else {
    1616         Tcl_AppendResult(interp, "bad option \"", string,
    1617                         "\": should be label", (char*)NULL);
    1618         return TCL_ERROR;
     1607        Tcl_AppendResult(interp, "bad option \"", string,
     1608                        "\": should be label", (char*)NULL);
     1609        return TCL_ERROR;
    16191610    }
    16201611    return TCL_OK;
     
    16231614static int
    16241615VolumeStateOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1625               Tcl_Obj *CONST *objv)
     1616              Tcl_Obj *const *objv)
    16261617{
    16271618    bool state;
    16281619    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
    1629         return TCL_ERROR;
     1620        return TCL_ERROR;
    16301621    }
    16311622    vector<Volume *> ivol;
    16321623    if (GetVolumes(interp, objc - 3, objv + 3, &ivol) != TCL_OK) {
    1633         return TCL_ERROR;
     1624        return TCL_ERROR;
    16341625    }
    16351626    if (state) {
    1636         vector<Volume *>::iterator iter;
    1637         for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1638             (*iter)->enable();
    1639         }
     1627        vector<Volume *>::iterator iter;
     1628        for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1629            (*iter)->enable();
     1630        }
    16401631    } else {
    1641         vector<Volume *>::iterator iter;
    1642         for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    1643             (*iter)->disable();
    1644         }
     1632        vector<Volume *>::iterator iter;
     1633        for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1634            (*iter)->disable();
     1635        }
    16451636    }
    16461637    return TCL_OK;
     
    16491640static int
    16501641VolumeTestOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1651              Tcl_Obj *CONST *objv)
     1642             Tcl_Obj *const *objv)
    16521643{
    16531644    NanoVis::volume[1]->disable_data();
     
    16841675 */
    16851676static int
    1686 VolumeCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     1677VolumeCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    16871678{
    16881679    Tcl_ObjCmdProc *proc;
    16891680
    16901681    proc = Rappture::GetOpFromObj(interp, nVolumeOps, volumeOps,
    1691         Rappture::CMDSPEC_ARG1, objc, objv, 0);
     1682        Rappture::CMDSPEC_ARG1, objc, objv, 0);
    16921683    if (proc == NULL) {
    16931684        return TCL_ERROR;
     
    16971688
    16981689static int
    1699 FlowCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     1690FlowCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    17001691{
    17011692    Rappture::Outcome err;
     
    17031694    if (objc < 2) {
    17041695        Tcl_AppendResult(interp, "wrong # args: should be \"",
    1705                 Tcl_GetString(objv[0]), " option ?arg arg?", (char *)NULL);
    1706         return TCL_ERROR;
    1707     }
    1708     char *string = Tcl_GetString(objv[1]);
     1696                Tcl_GetString(objv[0]), " option ?arg arg?", (char *)NULL);
     1697        return TCL_ERROR;
     1698    }
     1699    const char *string = Tcl_GetString(objv[1]);
    17091700    char c = string[0];
    17101701    if ((c == 'v') && (strcmp(string, "vectorid") == 0)) {
    17111702        if (objc != 3) {
    17121703            Tcl_AppendResult(interp, "wrong # args: should be \"",
    1713                 Tcl_GetString(objv[0]), " vectorid volume", (char *)NULL);
     1704                Tcl_GetString(objv[0]), " vectorid volume", (char *)NULL);
    17141705            return TCL_ERROR;
    17151706        }
     
    17201711        if (NanoVis::particleRenderer != NULL) {
    17211712            NanoVis::particleRenderer->setVectorField(volPtr->id, 1.0f,
    1722                 volPtr->height / (float)volPtr->width,
    1723                 volPtr->depth  / (float)volPtr->width,
    1724                 volPtr->wAxis.Max());
     1713                volPtr->height / (float)volPtr->width,
     1714                volPtr->depth  / (float)volPtr->width,
     1715                volPtr->wAxis.Max());
    17251716            NanoVis::initParticle();
    17261717        }
    17271718        if (NanoVis::licRenderer != NULL) {
    17281719            NanoVis::licRenderer->setVectorField(volPtr->id,
    1729                 1.0f / volPtr->aspect_ratio_width,
    1730                 1.0f / volPtr->aspect_ratio_height,
    1731                 1.0f / volPtr->aspect_ratio_depth,
    1732                 volPtr->wAxis.Max());
     1720                1.0f / volPtr->aspect_ratio_width,
     1721                1.0f / volPtr->aspect_ratio_height,
     1722                1.0f / volPtr->aspect_ratio_depth,
     1723                volPtr->wAxis.Max());
    17331724            NanoVis::licRenderer->set_offset(NanoVis::lic_slice_z);
    17341725        }
     
    17361727        if (objc != 3) {
    17371728            Tcl_AppendResult(interp, "wrong # args: should be \"",
    1738                              Tcl_GetString(objv[0]), " lic on|off\"", (char*)NULL);
     1729                             Tcl_GetString(objv[0]), " lic on|off\"", (char*)NULL);
    17391730            return TCL_ERROR;
    17401731        }
     
    17471738        if (objc < 3) {
    17481739            Tcl_AppendResult(interp, "wrong # args: should be \"",
    1749                 Tcl_GetString(objv[0]), " particle visible|slice|slicepos arg \"",
    1750                 (char*)NULL);
     1740                Tcl_GetString(objv[0]), " particle visible|slice|slicepos arg \"",
     1741                (char*)NULL);
    17511742            return TCL_ERROR;
    17521743        }
    1753         char *string = Tcl_GetString(objv[2]);
     1744        const char *string = Tcl_GetString(objv[2]);
    17541745        c = string[0];
    17551746        if ((c == 'v') && (strcmp(string, "visible") == 0)) {
    17561747            if (objc != 4) {
    17571748                Tcl_AppendResult(interp, "wrong # args: should be \"",
    1758                                 Tcl_GetString(objv[0]), " particle visible on|off\"",
    1759                                 (char*)NULL);
     1749                                Tcl_GetString(objv[0]), " particle visible on|off\"",
     1750                                (char*)NULL);
    17601751                return TCL_ERROR;
    17611752            }
     
    17681759            if (objc != 4) {
    17691760                Tcl_AppendResult(interp, "wrong # args: should be \"",
    1770                                 Tcl_GetString(objv[0]),
    1771                                 " particle slice volume\"", (char*)NULL);
     1761                                Tcl_GetString(objv[0]),
     1762                                " particle slice volume\"", (char*)NULL);
    17721763                return TCL_ERROR;
    17731764            }
     
    17801771            if (objc != 4) {
    17811772                Tcl_AppendResult(interp, "wrong # args: should be \"",
    1782                                 Tcl_GetString(objv[0]), " particle slicepos value\"",
    1783                                 (char*)NULL);
     1773                                Tcl_GetString(objv[0]), " particle slicepos value\"",
     1774                                (char*)NULL);
    17841775                return TCL_ERROR;
    17851776            }
     
    18051796            }
    18061797        } else {
    1807             Tcl_AppendResult(interp, "unknown option \"",string,"\": should be \"",
    1808                              Tcl_GetString(objv[0]), " visible, slice, or slicepos\"",
    1809                             (char *)NULL);
     1798            Tcl_AppendResult(interp, "unknown option \"", string,
     1799                "\": should be \"", Tcl_GetString(objv[0]),
     1800                " visible, slice, or slicepos\"", (char *)NULL);
    18101801            return TCL_ERROR;
    18111802        }
     
    18151806        if (objc > 4 || objc < 3) {
    18161807            Tcl_AppendResult(interp, "wrong # args: should be \"",
    1817                              Tcl_GetString(objv[0]), " capture numframes [directory]\"",
    1818                              (char*)NULL);
     1808                             Tcl_GetString(objv[0]), " capture numframes [directory]\"",
     1809                             (char*)NULL);
    18191810            return TCL_ERROR;
    18201811        }
     
    18331824        //
    18341825        Trace("FLOW started\n");
    1835         char *fileName;
     1826        const char *fileName;
    18361827        fileName = (objc < 4) ? NULL : Tcl_GetString(objv[3]);
    18371828        for (int frame_count = 0; frame_count < total_frame_count;
     
    18691860        if (objc < 3) {
    18701861            Tcl_AppendResult(interp, "wrong # args: should be \"",
    1871                              Tcl_GetString(objv[0]), " data follows ?args?", (char *)NULL);
     1862                Tcl_GetString(objv[0]), " data follows ?args?", (char *)NULL);
    18721863            return TCL_ERROR;
    18731864        }
    1874         char *string = Tcl_GetString(objv[2]);;
     1865        const char *string = Tcl_GetString(objv[2]);;
    18751866        c = string[0];
    18761867        if ((c == 'f') && (strcmp(string,"follows") == 0)) {
    18771868            if (objc != 4) {
    18781869                Tcl_AppendResult(interp, "wrong # args: should be \"",
    1879                                 Tcl_GetString(objv[0]), " data follows length",
    1880                                 (char *)NULL);
     1870                    Tcl_GetString(objv[0]), " data follows length",
     1871                    (char *)NULL);
    18811872                return TCL_ERROR;
    18821873            }
     
    19101901
    19111902                NanoVis::vol_renderer->add_volume(volPtr,
    1912                         NanoVis::get_transfunc("default"));
     1903                        NanoVis::get_transfunc("default"));
    19131904            }
    19141905        }
     
    19221913static int
    19231914HeightMapDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1924                        Tcl_Obj *CONST *objv)
     1915                       Tcl_Obj *const *objv)
    19251916{
    19261917    Rappture::Buffer buf;
     
    19451936static int
    19461937HeightMapDataVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1947                        Tcl_Obj *CONST *objv)
     1938                       Tcl_Obj *const *objv)
    19481939{
    19491940    bool visible;
     
    19571948    vector<HeightMap *>::iterator iter;
    19581949    for (iter = imap.begin(); iter != imap.end(); iter++) {
    1959         (*iter)->setVisible(visible);
     1950        (*iter)->setVisible(visible);
    19601951    }
    19611952    return TCL_OK;
     
    19701961static int
    19711962HeightMapDataOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1972                 Tcl_Obj *CONST *objv)
     1963                Tcl_Obj *const *objv)
    19731964{
    19741965    Tcl_ObjCmdProc *proc;
    19751966
    19761967    proc = Rappture::GetOpFromObj(interp, nHeightMapDataOps, heightMapDataOps,
    1977                                   Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1968                                  Rappture::CMDSPEC_ARG2, objc, objv, 0);
    19781969    if (proc == NULL) {
    19791970        return TCL_ERROR;
     
    19851976static int
    19861977HeightMapLineContourColorOp(ClientData cdata, Tcl_Interp *interp, int objc,
    1987                             Tcl_Obj *CONST *objv)
     1978                            Tcl_Obj *const *objv)
    19881979{
    19891980    float rgb[3];
     
    19971988    vector<HeightMap *>::iterator iter;
    19981989    for (iter = imap.begin(); iter != imap.end(); iter++) {
    1999         (*iter)->setLineContourColor(rgb);
     1990        (*iter)->setLineContourColor(rgb);
    20001991    }
    20011992    return TCL_OK;
     
    20041995static int
    20051996HeightMapLineContourVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2006                               Tcl_Obj *CONST *objv)
     1997                              Tcl_Obj *const *objv)
    20071998{
    20081999    bool visible;
     
    20162007    vector<HeightMap *>::iterator iter;
    20172008    for (iter = imap.begin(); iter != imap.end(); iter++) {
    2018         (*iter)->setLineContourVisible(visible);
     2009        (*iter)->setLineContourVisible(visible);
    20192010    }
    20202011    return TCL_OK;
     
    20292020static int
    20302021HeightMapLineContourOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2031                        Tcl_Obj *CONST *objv)
     2022                       Tcl_Obj *const *objv)
    20322023{
    20332024    Tcl_ObjCmdProc *proc;
    20342025
    20352026    proc = Rappture::GetOpFromObj(interp, nHeightMapLineContourOps,
    2036         heightMapLineContourOps, Rappture::CMDSPEC_ARG2, objc, objv, 0);
     2027        heightMapLineContourOps, Rappture::CMDSPEC_ARG2, objc, objv, 0);
    20372028    if (proc == NULL) {
    20382029        return TCL_ERROR;
     
    20432034static int
    20442035HeightMapCullOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2045                 Tcl_Obj *CONST *objv)
     2036                Tcl_Obj *const *objv)
    20462037{
    20472038    graphics::RenderContext::CullMode mode;
     
    20552046static int
    20562047HeightMapCreateOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2057                   Tcl_Obj *CONST *objv)
     2048                  Tcl_Obj *const *objv)
    20582049{
    20592050    HeightMap *hmPtr;
     
    20712062static int
    20722063HeightMapLegendOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2073                   Tcl_Obj *CONST *objv)
     2064                  Tcl_Obj *const *objv)
    20742065{
    20752066    HeightMap *hmPtr;
     
    20812072    if (tf == NULL) {
    20822073        Tcl_AppendResult(interp, "no transfer function defined for heightmap \"",
    2083                         Tcl_GetString(objv[2]), "\"", (char*)NULL);
     2074                        Tcl_GetString(objv[2]), "\"", (char*)NULL);
    20842075        return TCL_ERROR;
    20852076    }
     
    20902081    }
    20912082    if (HeightMap::update_pending) {
    2092         NanoVis::SetHeightmapRanges();
     2083        NanoVis::SetHeightmapRanges();
    20932084    }
    20942085    NanoVis::render_legend(tf, HeightMap::valueMin, HeightMap::valueMax, w, h,
    2095         "label");
     2086        "label");
    20962087    return TCL_OK;
    20972088}
     
    20992090static int
    21002091HeightMapPolygonOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2101                    Tcl_Obj *CONST *objv)
     2092                   Tcl_Obj *const *objv)
    21022093{
    21032094    graphics::RenderContext::PolygonMode mode;
     
    21112102static int
    21122103HeightMapShadingOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2113                  Tcl_Obj *CONST *objv)
     2104                 Tcl_Obj *const *objv)
    21142105{
    21152106    graphics::RenderContext::ShadingModel model;
     
    21232114static int
    21242115HeightMapTestOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2125                 Tcl_Obj *CONST *objv)
     2116                Tcl_Obj *const *objv)
    21262117{
    21272118    srand((unsigned)time(NULL));
     
    21552146static int
    21562147HeightMapTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2157                      Tcl_Obj *CONST *objv)
    2158 {
    2159     char *name;
     2148                     Tcl_Obj *const *objv)
     2149{
     2150    const char *name;
    21602151    name = Tcl_GetString(objv[2]);
    21612152    TransferFunction *tf;
     
    21722163    vector<HeightMap *>::iterator iter;
    21732164    for (iter = imap.begin(); iter != imap.end(); iter++) {
    2174         (*iter)->setColorMap(tf);
     2165        (*iter)->setColorMap(tf);
    21752166    }
    21762167    return TCL_OK;
     
    21922183
    21932184static int
    2194 HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     2185HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    21952186{
    21962187    Tcl_ObjCmdProc *proc;
    21972188
    21982189    proc = Rappture::GetOpFromObj(interp, nHeightMapOps, heightMapOps,
    2199                                   Rappture::CMDSPEC_ARG1, objc, objv, 0);
     2190                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
    22002191    if (proc == NULL) {
    22012192        return TCL_ERROR;
     
    22062197static int
    22072198GridAxisColorOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2208                 Tcl_Obj *CONST *objv)
     2199                Tcl_Obj *const *objv)
    22092200{
    22102201    float r, g, b, a;
     
    22262217static int
    22272218GridAxisNameOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2228                Tcl_Obj *CONST *objv)
    2229 {
    2230     int axisId;
    2231     if (GetAxisFromObj(interp, objv[2], &axisId) != TCL_OK) {
    2232         return TCL_ERROR;
    2233     }
    2234     if (NanoVis::grid) {
    2235 #ifdef notdef
    2236         NanoVis::grid->setAxisName(axisId, Tcl_GetString(objv[3]));
    2237 #endif
     2219               Tcl_Obj *const *objv)
     2220{
     2221    int axis;
     2222    if (GetAxisFromObj(interp, objv[2], &axis) != TCL_OK) {
     2223        return TCL_ERROR;
     2224    }
     2225    if (NanoVis::grid != NULL) {
     2226        Axis *axisPtr;
     2227
     2228        switch (axis) {
     2229        case 0: axisPtr = &NanoVis::grid->xAxis; break;
     2230        case 1: axisPtr = &NanoVis::grid->yAxis; break;
     2231        case 2: axisPtr = &NanoVis::grid->zAxis; break;
     2232        }
     2233        axisPtr->SetName(Tcl_GetString(objv[3]));
     2234        axisPtr->SetUnits(Tcl_GetString(objv[4]));
    22382235    }
    22392236    return TCL_OK;
     
    22422239static int
    22432240GridLineColorOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2244                 Tcl_Obj *CONST *objv)
     2241                Tcl_Obj *const *objv)
    22452242{
    22462243    float r, g, b, a;
     
    22612258
    22622259static int
    2263 GridVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     2260GridVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    22642261{
    22652262    bool visible;
     
    22732270static Rappture::CmdSpec gridOps[] = {
    22742271    {"axiscolor",  5, GridAxisColorOp,  5, 6, "r g b ?a?",},
    2275     {"axisname",   5, GridAxisNameOp,   5, 5, "index width height",},
     2272    {"axisname",   5, GridAxisNameOp,   5, 5, "index title units",},
    22762273    {"linecolor",  7, GridLineColorOp,  5, 6, "r g b ?a?",},
    22772274    {"visible",    1, GridVisibleOp,    3, 3, "bool",},
     
    22802277
    22812278static int
    2282 GridCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     2279GridCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    22832280{
    22842281    Tcl_ObjCmdProc *proc;
    22852282
    22862283    proc = Rappture::GetOpFromObj(interp, nGridOps, gridOps,
    2287                                   Rappture::CMDSPEC_ARG1, objc, objv, 0);
     2284        Rappture::CMDSPEC_ARG1, objc, objv, 0);
    22882285    if (proc == NULL) {
    22892286        return TCL_ERROR;
     
    22932290
    22942291static int
    2295 AxisCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     2292AxisCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    22962293{
    22972294    if (objc < 2) {
    22982295        Tcl_AppendResult(interp, "wrong # args: should be \"",
    2299                         Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL);
    2300         return TCL_ERROR;
    2301     }
    2302     char *string = Tcl_GetString(objv[1]);
     2296                Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL);
     2297        return TCL_ERROR;
     2298    }
     2299    const char *string = Tcl_GetString(objv[1]);
    23032300    char c = string[0];
    23042301    if ((c == 'v') && (strcmp(string, "visible") == 0)) {
     
    23192316#if PLANE_CMD
    23202317static int
    2321 PlaneNewOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     2318PlaneNewOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    23222319{
    23232320    fprintf(stderr, "load plane for 2D visualization command\n");
     
    23252322    if (objc != 4) {
    23262323        Tcl_AppendResult(interp, "wrong # args: should be \"",
    2327                         Tcl_GetString(objv[0]), " plane_index w h \"", (char*)NULL);
     2324            Tcl_GetString(objv[0]), " plane_index w h \"", (char*)NULL);
    23282325        return TCL_ERROR;
    23292326    }
     
    23382335    }
    23392336   
    2340     //Now read w*h*4 bytes. The server expects the plane to be a stream of floats
     2337    //Now read w*h*4 bytes. The server expects the plane to be a stream of
     2338    //floats
    23412339    char* tmp = new char[int(w*h*sizeof(float))];
    23422340    if (tmp == NULL) {
     
    23582356static int
    23592357PlaneLinkOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2360             Tcl_Obj *CONST *objv)
     2358            Tcl_Obj *const *objv)
    23612359{
    23622360    fprintf(stderr, "link the plane to the 2D renderer command\n");
     
    23662364    if (objc != 3) {
    23672365        Tcl_AppendResult(interp, "wrong # args: should be \"",
    2368                         Tcl_GetString(objv[0]), " plane_index tf_index \"", (char*)NULL);
     2366            Tcl_GetString(objv[0]), " plane_index tf_index \"", (char*)NULL);
    23692367        return TCL_ERROR;
    23702368    }
     
    23832381static int
    23842382PlaneEnableOp(ClientData cdata, Tcl_Interp *interp, int objc,
    2385               Tcl_Obj *CONST *objv)
     2383              Tcl_Obj *const *objv)
    23862384{
    23872385    fprintf(stderr,"enable a plane so the 2D renderer can render it command\n");
     
    23892387    if (objc != 3) {
    23902388        Tcl_AppendResult(interp, "wrong # args: should be \"",
    2391                         Tcl_GetString(objv[0]), " plane_index mode \"", (char*)NULL);
     2389            Tcl_GetString(objv[0]), " plane_index mode \"", (char*)NULL);
    23922390        return TCL_ERROR;
    23932391    }
     
    24152413
    24162414static int
    2417 PlaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     2415PlaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    24182416{
    24192417    Tcl_ObjCmdProc *proc;
    24202418
    24212419    proc = Rappture::GetOpFromObj(interp, nPlaneOps, planeOps,
    2422                                   Rappture::CMDSPEC_ARG1, objc, objv, 0);
     2420                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
    24232421    if (proc == NULL) {
    24242422        return TCL_ERROR;
     
    24412439 */
    24422440static int
    2443 UniRect2dCmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     2441UniRect2dCmd(ClientData clientData, Tcl_Interp *interp, int objc,
     2442             Tcl_Obj *const *objv)
    24442443{   
    24452444    int xNum, yNum, zNum;
     
    24492448    if ((objc & 0x01) == 0) {
    24502449        Tcl_AppendResult(interp, Tcl_GetString(objv[0]), ": ",
    2451                         "wrong number of arguments: should be key-value pairs",
    2452                         (char *)NULL);
     2450                "wrong number of arguments: should be key-value pairs",
     2451                (char *)NULL);
    24532452        return TCL_ERROR;
    24542453    }
     
    24582457    int i;
    24592458    for (i = 1; i < objc; i += 2) {
    2460         char *string;
     2459        const char *string;
    24612460
    24622461        string = Tcl_GetString(objv[i]);
     
    25102509        } else {
    25112510            Tcl_AppendResult(interp, "unknown key \"", string,
    2512                              "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues",
    2513                              (char *)NULL);
     2511                "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues",
     2512                (char *)NULL);
    25142513            return TCL_ERROR;
    25152514        }
     
    25212520    if (zNum != (xNum * yNum)) {
    25222521        Tcl_AppendResult(interp, "wrong number of z values must be xnum*ynum",
    2523                         (char *)NULL);
     2522                (char *)NULL);
    25242523        return TCL_ERROR;
    25252524    }
     
    25592558    Tcl_CreateObjCommand(interp, "legend",      LegendCmd,      NULL, NULL);
    25602559    Tcl_CreateObjCommand(interp, "screen",      ScreenCmd,      NULL, NULL);
    2561     Tcl_CreateObjCommand(interp, "screenshot",  ScreenShotCmd,  NULL, NULL);
     2560    Tcl_CreateObjCommand(interp, "snapshot",    SnapshotCmd,    NULL, NULL);
    25622561    Tcl_CreateObjCommand(interp, "transfunc",   TransfuncCmd,   NULL, NULL);
    25632562    Tcl_CreateObjCommand(interp, "unirect2d",   UniRect2dCmd,   NULL, NULL);
     
    26322631    if (status != TCL_OK) {
    26332632        std::ostringstream errmsg;
    2634         errmsg << "ERROR: " << Tcl_GetStringResult(interp) << std::endl;
     2633        errmsg << "NanoVis Server Error: " << Tcl_GetStringResult(interp) << std::endl;
    26352634        write(0, errmsg.str().c_str(), errmsg.str().size());
    26362635        return;
     
    26772676    write(0, rle, rle_size);    //unsigned byte
    26782677#else
    2679     NanoVis::bmp_write("nv>image -bytes");
     2678    NanoVis::ppm_write("nv>image -bytes");
    26802679#endif
    26812680}
  • trunk/packages/vizservers/nanovis/HeightMap.cpp

    r1000 r1028  
    2020double HeightMap::valueMax = 1.0;
    2121
    22 #define TOPCONTOUR
     22#define TOPCONTOUR      0
    2323HeightMap::HeightMap() :
    2424    _vertexBufferObjectID(0),
     
    150150        }
    151151
    152 #ifdef TOPCONTOUR
     152#if TOPCONTOUR
    153153        if (_topContourVisible) {
    154154            glDisable(GL_BLEND);
     
    303303    _contour = lineFilter.create(0.0f, 1.0f, 10, heights, xCount, yCount);
    304304
    305 #ifdef TOPCONTOUR
     305#if TOPCONTOUR
    306306    ContourLineFilter topLineFilter;
    307307    topLineFilter.setHeightTop(true);
     
    379379    _contour = lineFilter.create(0.0f, 1.0f, 10, heightMap, xCount, yCount);
    380380   
    381 #ifdef TOPCONTOUR
     381#if TOPCONTOUR
    382382    ContourLineFilter topLineFilter;
    383383    topLineFilter.setHeightTop(true);
  • trunk/packages/vizservers/nanovis/Makefile.in

    r951 r1028  
    128128                TransferFunction.o \
    129129                Util.o \
    130                 Vector3.o \
    131                 Vector4.o \
    132130                Volume.o \
    133131                VolumeInterpolator.o \
     
    267265PlaneRenderer.o: PlaneRenderer.cpp PlaneRenderer.h
    268266Mat4x4.o: Mat4x4.cpp Mat4x4.h
    269 Vector4.o: Vector4.cpp Vector4.h
    270 Vector3.o: Vector3.cpp Vector3.h
    271267Plane.o: Plane.cpp Plane.h
    272268ConvexPolygon.o: ConvexPolygon.cpp ConvexPolygon.h
  • trunk/packages/vizservers/nanovis/Mat4x4.cpp

    r226 r1028  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    1819#include <assert.h>
    1920
    20 Mat4x4::Mat4x4(){}
    21 
    22 Mat4x4::Mat4x4(float *vals){
    23         int i;
    24         for (i=0;i<16;i++)
    25                 m[i] = vals[i];
     21Mat4x4::Mat4x4(float *vals) {
     22    int i;
     23    for (i=0;i<16;i++)
     24        m[i] = vals[i];
    2625}
    2726
    28 Mat4x4::~Mat4x4(){}
    29 
    30 void Mat4x4::print(){
    31         fprintf(stderr, "\n%f %f %f %f\n", m[0], m[1], m[2], m[3]);
    32         fprintf(stderr, "%f %f %f %f\n", m[4], m[5], m[6], m[7]);
    33         fprintf(stderr, "%f %f %f %f\n", m[8], m[9], m[10], m[11]);
    34         fprintf(stderr, "%f %f %f %f\n\n", m[12], m[13], m[14], m[15]);
     27void
     28Mat4x4::print(){
     29    fprintf(stderr, "\n%f %f %f %f\n", m[0], m[1], m[2], m[3]);
     30    fprintf(stderr, "%f %f %f %f\n", m[4], m[5], m[6], m[7]);
     31    fprintf(stderr, "%f %f %f %f\n", m[8], m[9], m[10], m[11]);
     32    fprintf(stderr, "%f %f %f %f\n\n", m[12], m[13], m[14], m[15]);
    3533}
    3634
    37 Mat4x4 Mat4x4::inverse(){
    38         Mat4x4 p;
    39 
     35Mat4x4
     36Mat4x4::inverse(){
     37    Mat4x4 p;
     38       
    4039    float m00 = m[0], m01 = m[4], m02 = m[8], m03 = m[12];
    4140    float m10 = m[1], m11 = m[5], m12 = m[9], m13 = m[13];
     
    105104    p.m[15]= cof33 * inv0;     
    106105       
    107         return p;
    108         /*
    109         Mat4x4 ret;
    110         int i, j;
    111         double dst[4][4];
    112         double tmp[12];
    113 
    114         // calculate pairs for first 8 mements (cofactors)
    115         tmp[0] = m[10] * m[15];
    116         tmp[1] = m[11] * m[14];
    117         tmp[2] = m[9] * m[15];
    118         tmp[3] = m[11] * m[13];
    119         tmp[4] = m[9] * m[14];
    120         tmp[5] = m[10] * m[13];
    121         tmp[6] = m[8] * m[15];
    122         tmp[7] = m[11] * m[12];
    123         tmp[8] = m[8] * m[14];
    124         tmp[9] = m[10] * m[12];
    125         tmp[10] = m[8] * m[13];
    126         tmp[11] = m[9] * m[12];
    127 
    128         // calculate first 8 mements (cofactors)
    129         dst[0][0] = tmp[0]*m[5] + tmp[3]*m[6] + tmp[4]*m[7];
    130         dst[0][0] -= tmp[1]*m[5] + tmp[2]*m[6] + tmp[5]*m[7];
    131         dst[0][1] = tmp[1]*m[4] + tmp[6]*m[6] + tmp[9]*m[7];
    132         dst[0][1]-= tmp[0]*m[4] + tmp[7]*m[6] + tmp[8]*m[7];
    133         dst[0][2] = tmp[2]*m[4] + tmp[7]*m[5] + tmp[10]*m[7];
    134         dst[0][2] -= tmp[3]*m[4] + tmp[6]*m[5] + tmp[11]*m[7];
    135         dst[0][3] = tmp[5]*m[4] + tmp[8]*m[5] + tmp[11]*m[6];
    136         dst[0][3] -= tmp[4]*m[4] + tmp[9]*m[5] + tmp[10]*m[6];
    137         dst[1][0] = tmp[1]*m[1] + tmp[2]*m[2] + tmp[5]*m[3];
    138         dst[1][0] -= tmp[0]*m[1] + tmp[3]*m[2] + tmp[4]*m[3];
    139         dst[1][1] = tmp[0]*m[0] + tmp[7]*m[2] + tmp[8]*m[3];
    140         dst[1][1] -= tmp[1]*m[0] + tmp[6]*m[2] + tmp[9]*m[3];
    141         dst[1][2] = tmp[3]*m[0] + tmp[6]*m[1] + tmp[11]*m[3];
    142         dst[1][2] -= tmp[2]*m[0] + tmp[7]*m[1] + tmp[10]*m[3];
    143         dst[1][3] = tmp[4]*m[0] + tmp[9]*m[1] + tmp[10]*m[2];
    144         dst[1][3] -= tmp[5]*m[0] + tmp[8]*m[1] + tmp[11]*m[2];
    145 
    146         // calculate pairs for second 8 mements (cofactors)
    147         tmp[0] = m[2]*m[7];
    148         tmp[1] = m[3]*m[6];
    149         tmp[2] = m[1]*m[7];
    150         tmp[3] = m[3]*m[5];
    151         tmp[4] = m[1]*m[6];
    152         tmp[5] = m[2]*m[5];
    153         tmp[6] = m[0]*m[7];
    154         tmp[7] = m[3]*m[4];
    155         tmp[8] = m[0]*m[6];
    156         tmp[9] = m[2]*m[4];
    157         tmp[10] = m[0]*m[5];
    158         tmp[11] = m[1]*m[4];
    159 
    160         // calculate second 8 mements (cofactors)
    161         dst[2][0] = tmp[0]*m[13] + tmp[3]*m[14] + tmp[4]*m[15];
    162         dst[2][0] -= tmp[1]*m[13] + tmp[2]*m[14] + tmp[5]*m[15];
    163         dst[2][1] = tmp[1]*m[12] + tmp[6]*m[14] + tmp[9]*m[15];
    164         dst[2][1] -= tmp[0]*m[12] + tmp[7]*m[14] + tmp[8]*m[15];
    165         dst[2][2] = tmp[2]*m[12] + tmp[7]*m[13] + tmp[10]*m[15];
    166         dst[2][2]-= tmp[3]*m[12] + tmp[6]*m[13] + tmp[11]*m[15];
    167         dst[2][3] = tmp[5]*m[12] + tmp[8]*m[13] + tmp[11]*m[14];
    168         dst[2][3]-= tmp[4]*m[12] + tmp[9]*m[13] + tmp[10]*m[14];
    169         dst[3][0] = tmp[2]*m[10] + tmp[5]*m[11] + tmp[1]*m[9];
    170         dst[3][0]-= tmp[4]*m[11] + tmp[0]*m[9] + tmp[3]*m[10];
    171         dst[3][1] = tmp[8]*m[11] + tmp[0]*m[8] + tmp[7]*m[10];
    172         dst[3][1]-= tmp[6]*m[10] + tmp[9]*m[11] + tmp[1]*m[8];
    173         dst[3][2] = tmp[6]*m[9] + tmp[11]*m[11] + tmp[3]*m[8];
    174         dst[3][2]-= tmp[10]*m[11] + tmp[2]*m[8] + tmp[7]*m[9];
    175         dst[3][3] = tmp[10]*m[10] + tmp[4]*m[8] + tmp[9]*m[9];
    176         dst[3][3]-= tmp[8]*m[9] + tmp[11]*m[10] + tmp[5]*m[8];
    177 
    178         // calculate determinant
    179         double determinant=m[0]*dst[0][0]+m[1]*dst[0][1]+m[2]*dst[0][2]+m[3]*dst[0][3];
    180 
    181         assert(fabs(determinant) != 0.0);
    182 
    183         // calculate matrix inverse
    184         determinant = 1/determinant;
    185         for(i = 0; i < 4; i++){
    186                 for (j = 0; j < 4; j++){
    187                         dst[i][j] *= determinant;
    188                         ret.m[i*4+j] = dst[i][j];
    189                 }
    190         }
    191 
    192         return ret;
    193         */
     106    return p;
    194107}
    195108
    196 Vector4 Mat4x4::multiply_row_vector(Vector4 v){
    197         Vector4 ret;
    198     ret.x = m[0]*v.x + m[1]*v.y + m[2]*v.z + m[3]*v.w;
    199     ret.y = m[4]*v.x + m[5]*v.y + m[6]*v.z + m[7]*v.w;
    200     ret.z = m[8]*v.x + m[9]*v.y + m[10]*v.z + m[11]*v.w;
    201         ret.w = m[12]*v.x + m[13]*v.y + m[14]*v.z + m[15]*v.w;
    202         return ret;
     109Vector4
     110Mat4x4::multiply_row_vector(Vector4 v){
     111    Vector4 ret;
     112    ret.x = (m[0]  * v.x) + (m[1]  * v.y) + (m[2]  * v.z) + (m[3]  * v.w);
     113    ret.y = (m[4]  * v.x) + (m[5]  * v.y) + (m[6]  * v.z) + (m[7]  * v.w);
     114    ret.z = (m[8]  * v.x) + (m[9]  * v.y) + (m[10] * v.z) + (m[11] * v.w);
     115    ret.w = (m[12] * v.x) + (m[13] * v.y) + (m[14] * v.z) + (m[15] * v.w);
     116    return ret;
    203117}
    204118
    205 Vector4 Mat4x4::transform(Vector4 vector){
    206         Vector4 ret;
    207         ret.x = vector.x*m[0]+vector.y*m[4]+vector.z*m[8]+vector.w*m[12];
    208         ret.y = vector.x*m[1]+vector.y*m[5]+vector.z*m[9]+vector.w*m[13];
    209         ret.z = vector.x*m[2]+vector.y*m[6]+vector.z*m[10]+vector.w*m[14];
    210         ret.w = vector.x*m[3]+vector.y*m[7]+vector.z*m[11]+vector.w*m[15];
    211 
    212         return ret;
     119Vector4
     120Mat4x4::transform(Vector4 v){
     121    Vector4 ret;
     122    ret.x = v.x*m[0]+v.y*m[4]+v.z*m[8]+v.w*m[12];
     123    ret.y = v.x*m[1]+v.y*m[5]+v.z*m[9]+v.w*m[13];
     124    ret.z = v.x*m[2]+v.y*m[6]+v.z*m[10]+v.w*m[14];
     125    ret.w = v.x*m[3]+v.y*m[7]+v.z*m[11]+v.w*m[15];
     126    return ret;
    213127}
    214128
    215 Mat4x4 Mat4x4::operator *(Mat4x4 mat){
    216         Mat4x4 ret;
    217        
    218         ret.m[0] = m[0]*mat.m[0]+m[1]*mat.m[4]+m[2]*mat.m[8]+m[3]*mat.m[12];
    219         ret.m[1] = m[0]*mat.m[1]+m[1]*mat.m[5]+m[2]*mat.m[9]+m[3]*mat.m[13];
    220         ret.m[2] = m[0]*mat.m[2]+m[1]*mat.m[6]+m[2]*mat.m[10]+m[3]*mat.m[14];
    221         ret.m[3] = m[0]*mat.m[3]+m[1]*mat.m[7]+m[2]*mat.m[11]+m[3]*mat.m[15];
    222 
    223         ret.m[4] = m[4]*mat.m[0]+m[5]*mat.m[4]+m[6]*mat.m[8]+m[7]*mat.m[12];
    224         ret.m[5] = m[4]*mat.m[1]+m[5]*mat.m[5]+m[6]*mat.m[9]+m[7]*mat.m[13];
    225         ret.m[6] = m[4]*mat.m[2]+m[5]*mat.m[6]+m[6]*mat.m[10]+m[7]*mat.m[14];
    226         ret.m[7] = m[4]*mat.m[3]+m[5]*mat.m[7]+m[6]*mat.m[11]+m[7]*mat.m[15];
    227 
    228         ret.m[8] = m[8]*mat.m[0]+m[9]*mat.m[4]+m[10]*mat.m[8]+m[11]*mat.m[12];
    229         ret.m[9] = m[8]*mat.m[1]+m[9]*mat.m[5]+m[10]*mat.m[9]+m[11]*mat.m[13];
    230         ret.m[10] = m[8]*mat.m[2]+m[9]*mat.m[6]+m[10]*mat.m[10]+m[11]*mat.m[14];
    231         ret.m[11] = m[8]*mat.m[3]+m[9]*mat.m[7]+m[10]*mat.m[11]+m[11]*mat.m[15];
    232 
    233         ret.m[12] = m[12]*mat.m[0]+m[13]*mat.m[4]+m[14]*mat.m[8]+m[15]*mat.m[12];
    234         ret.m[13] = m[12]*mat.m[1]+m[13]*mat.m[5]+m[14]*mat.m[9]+m[15]*mat.m[13];
    235         ret.m[14] = m[12]*mat.m[2]+m[13]*mat.m[6]+m[14]*mat.m[10]+m[15]*mat.m[14];
    236         ret.m[15] = m[12]*mat.m[3]+m[13]*mat.m[7]+m[14]*mat.m[11]+m[15]*mat.m[15];
    237 
    238         return ret;
     129Mat4x4
     130Mat4x4::operator *(Mat4x4 mat){
     131    Mat4x4 ret;
     132   
     133    ret.m[0] = m[0]*mat.m[0]+m[1]*mat.m[4]+m[2]*mat.m[8]+m[3]*mat.m[12];
     134    ret.m[1] = m[0]*mat.m[1]+m[1]*mat.m[5]+m[2]*mat.m[9]+m[3]*mat.m[13];
     135    ret.m[2] = m[0]*mat.m[2]+m[1]*mat.m[6]+m[2]*mat.m[10]+m[3]*mat.m[14];
     136    ret.m[3] = m[0]*mat.m[3]+m[1]*mat.m[7]+m[2]*mat.m[11]+m[3]*mat.m[15];
     137   
     138    ret.m[4] = m[4]*mat.m[0]+m[5]*mat.m[4]+m[6]*mat.m[8]+m[7]*mat.m[12];
     139    ret.m[5] = m[4]*mat.m[1]+m[5]*mat.m[5]+m[6]*mat.m[9]+m[7]*mat.m[13];
     140    ret.m[6] = m[4]*mat.m[2]+m[5]*mat.m[6]+m[6]*mat.m[10]+m[7]*mat.m[14];
     141    ret.m[7] = m[4]*mat.m[3]+m[5]*mat.m[7]+m[6]*mat.m[11]+m[7]*mat.m[15];
     142   
     143    ret.m[8] = m[8]*mat.m[0]+m[9]*mat.m[4]+m[10]*mat.m[8]+m[11]*mat.m[12];
     144    ret.m[9] = m[8]*mat.m[1]+m[9]*mat.m[5]+m[10]*mat.m[9]+m[11]*mat.m[13];
     145    ret.m[10] = m[8]*mat.m[2]+m[9]*mat.m[6]+m[10]*mat.m[10]+m[11]*mat.m[14];
     146    ret.m[11] = m[8]*mat.m[3]+m[9]*mat.m[7]+m[10]*mat.m[11]+m[11]*mat.m[15];
     147   
     148    ret.m[12] = m[12]*mat.m[0]+m[13]*mat.m[4]+m[14]*mat.m[8]+m[15]*mat.m[12];
     149    ret.m[13] = m[12]*mat.m[1]+m[13]*mat.m[5]+m[14]*mat.m[9]+m[15]*mat.m[13];
     150    ret.m[14] = m[12]*mat.m[2]+m[13]*mat.m[6]+m[14]*mat.m[10]+m[15]*mat.m[14];
     151    ret.m[15] = m[12]*mat.m[3]+m[13]*mat.m[7]+m[14]*mat.m[11]+m[15]*mat.m[15];
     152   
     153    return ret;
    239154}
    240155
    241 Mat4x4 Mat4x4::transpose(){
    242         Mat4x4 ret;
    243         for(int i=0; i<4; i++){
    244                 for(int j=0; j<4; j++){
    245                         ret.m[j+4*i] = this->m[i+4*j];
    246                 }
     156Mat4x4
     157Mat4x4::transpose(){
     158    Mat4x4 ret;
     159    for(int i=0; i<4; i++){
     160        for(int j=0; j<4; j++){
     161            ret.m[j+4*i] = this->m[i+4*j];
    247162        }
    248         return ret;
     163    }
     164    return ret;
    249165}
    250166
  • trunk/packages/vizservers/nanovis/Mat4x4.h

    r226 r1028  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    2021class Mat4x4 
    2122{
    22        
     23       
    2324public:
    24         float m[16];    //row by row
    25         Mat4x4();
    26         Mat4x4(float *vals);
    27         ~Mat4x4();
     25    float m[16];        //row by row
     26    Mat4x4() {
     27        /*empty*/
     28    };
     29    Mat4x4(float *vals);
    2830
    29         void print();
    30         Mat4x4 inverse();
    31         Mat4x4 transpose();
    32         Vector4 multiply_row_vector(Vector4 v);
    33         Vector4 transform(Vector4 v);
    34         Mat4x4 operator*(Mat4x4 op);
     31    void print(void);
     32    Mat4x4 inverse(void);
     33    Mat4x4 transpose(void);
     34    Vector4 multiply_row_vector(Vector4 v);
     35    Vector4 transform(Vector4 v);
     36    Mat4x4 operator*(Mat4x4 op);
    3537};
    3638
  • trunk/packages/vizservers/nanovis/NvLIC.cpp

    r984 r1028  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    2324#include <Trace.h>
    2425
    25 NvLIC::NvLIC(int _size, int _width, int _height, float _offset, CGcontext _context)
    26     : Renderable(Vector3(0.0f,0.0f,0.0f)),
     26NvLIC::NvLIC(int _size, int _width, int _height, float _offset,
     27             CGcontext _context) :
     28    Renderable(Vector3(0.0f,0.0f,0.0f)),
    2729    disListID(0),
    28         width(_width),
    29         height(_height),
    30         size(_size),
     30    width(_width),
     31    height(_height),
     32    size(_size),
    3133    scale(1.0f, 1.0f, 1.0f),
    32         offset(_offset),
     34    offset(_offset),
    3335    iframe(0),
    34         Npat(64),
    35         alpha((int) 0.12*255),
    36         tmax(NPIX/(SCALE*NPN)),
    37         dmax(SCALE/NPIX),
     36    Npat(64),
     37    alpha((int) 0.12*255),
     38    tmax(NPIX/(SCALE*NPN)),
     39    dmax(SCALE/NPIX),
    3840    max(1.0f),
    39         m_g_context(_context),
     41    m_g_context(_context),
    4042    vectorFieldID((NVISid) 0),
    4143    _activate(false)
     
    7880
    7981    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    80                   GL_TEXTURE_RECTANGLE_NV, slice_vector_tex, 0);
     82                  GL_TEXTURE_RECTANGLE_NV, slice_vector_tex, 0);
    8183
    8284
     
    149151   
    150152    for (i = 0; i < 256; i++) {
    151         lut[i] = i < 127 ? 0 : 255;
     153        lut[i] = i < 127 ? 0 : 255;
    152154    }
    153155    for (i = 0; i < NPN; i++) {
    154         for (j = 0; j < NPN; j++) {
    155             phase[i][j] = rand() % 256;
     156        for (j = 0; j < NPN; j++) {
     157            phase[i][j] = rand() >> 8;
    156158        }
    157159    }
    158160    for (k = 0; k < Npat; k++) {
    159         t = k*256/Npat;
    160         for (i = 0; i < NPN; i++) {
    161             for (j = 0; j < NPN; j++) {
    162                 pat[i][j][0] =
    163                     pat[i][j][1] =
    164                     pat[i][j][2] = lut[(t + phase[i][j]) % 255];
    165                 pat[i][j][3] = alpha;
    166             }
    167         }
    168         glNewList(disListID + k, GL_COMPILE);
    169         glBindTexture(GL_TEXTURE_2D, pattern_tex);
    170         glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0,
    171                      GL_RGBA, GL_UNSIGNED_BYTE, pat);
    172         glEndList();
     161        t = (k << 8) / Npat;
     162        for (i = 0; i < NPN; i++) {
     163            for (j = 0; j < NPN; j++) {
     164                pat[i][j][0] = pat[i][j][1] = pat[i][j][2] =
     165                    lut[(t + phase[i][j]) % 255];
     166                pat[i][j][3] = alpha;
     167            }
     168        }
     169        glNewList(disListID + k, GL_COMPILE);
     170        glBindTexture(GL_TEXTURE_2D, pattern_tex);
     171        glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, GL_RGBA,
     172                     GL_UNSIGNED_BYTE, pat);
     173        glEndList();
    173174    }
    174175   
    175176    glBindTexture(GL_TEXTURE_2D, pattern_tex);
    176177    glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0,
    177                 GL_RGBA, GL_UNSIGNED_BYTE, pat);
     178                GL_RGBA, GL_UNSIGNED_BYTE, pat);
    178179    Trace("finish make_patterns\n");
    179180}
     
    187188    for(int i=0; i<NMESH; i++){
    188189        for(int j=0; j<NMESH; j++){
    189 
    190       float x=DM*i;
    191       float y=DM*j;
    192 
    193       float magnitude = sqrt(x*x+y*y)/1.414;
    194      
    195       //from green to red
    196       GLubyte r = (GLubyte) floor(magnitude*255);
    197       GLubyte g = 0;
    198       GLubyte b = 255 - r;
    199       GLubyte a = 122;
    200 
    201       mag[i][j][0] = r;
    202       mag[i][j][1] = g;
    203       mag[i][j][2] = b;
    204       mag[i][j][3] = a;
     190            float x=DM*i;
     191            float y=DM*j;
     192           
     193            float magnitude = sqrt(x*x+y*y)/1.414;
     194           
     195            //from green to red
     196            GLubyte r = (GLubyte) floor(magnitude*255);
     197            GLubyte g = 0;
     198            GLubyte b = 255 - r;
     199            GLubyte a = 122;
     200           
     201            mag[i][j][0] = r;
     202            mag[i][j][1] = g;
     203            mag[i][j][2] = b;
     204            mag[i][j][3] = a;
    205205        }
    206206    }
     
    213213    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    214214    //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
    215     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NMESH, NMESH, 0, GL_RGBA, GL_UNSIGNED_BYTE, mag);
     215    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NMESH, NMESH, 0, GL_RGBA,
     216                 GL_UNSIGNED_BYTE, mag);
    216217    glBindTexture(GL_TEXTURE_2D, 0);
    217218}
    218219
    219 void NvLIC::get_slice()
     220void
     221NvLIC::get_slice()
    220222{
    221223    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);
     
    242244
    243245    glBegin(GL_QUADS);
     246    {
    244247        glTexCoord3f(0., 0., offset); glVertex2f(0.,   0.);
    245248        glTexCoord3f(1., 0., offset); glVertex2f(size, 0.);
    246249        glTexCoord3f(1., 1., offset); glVertex2f(size, size);
    247250        glTexCoord3f(0., 1., offset); glVertex2f(0.,   size);
     251    }
    248252    glEnd();
    249253   
     
    261265    int lim = size * size * 4;
    262266    float* v= slice_vector;
    263     for (int i = 0; i < lim; ++i)
    264     {
    265         if (isnan(*v)) *v = 0.0f;   
     267    for (int i = 0; i < lim; ++i) {
     268        if (isnan(*v)) {
     269            *v = 0.0f;   
     270        }
    266271        ++v;
    267272    }
     
    269274
    270275//line integral convolution
    271 void NvLIC::convolve()
     276void
     277NvLIC::convolve()
    272278{
    273279    int   i, j;
    274280    float x1, x2, y, px, py;
    275 
     281   
    276282    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    277 
     283   
    278284    glMatrixMode(GL_PROJECTION);
    279285    glLoadIdentity();
     
    283289    //glScalef(2.0, 2.0, 1.0);
    284290    glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -10.0f, 10.0f);
    285 
     291   
    286292    glMatrixMode(GL_MODELVIEW);
    287293    glLoadIdentity();
    288 
     294   
    289295    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    290 
     296   
    291297    //sa = 0.010*cos(iframe*2.0*M_PI/200.0);
    292298    glEnable(GL_TEXTURE_2D);
    293299    glBindTexture(GL_TEXTURE_2D, pattern_tex);
    294300    sa = 0.01;
    295 
    296     for (i = 0; i < NMESH-1; i++)
    297     {
     301   
     302    for (i = 0; i < NMESH-1; i++) {
    298303        x1 = DM*i; x2 = x1 + DM;
    299304        glBegin(GL_QUAD_STRIP);
    300305        for (j = 0; j < NMESH-1; j++) {
    301           y = DM*j;
    302           glTexCoord2f(x1, y);
    303           get_velocity(x1, y, &px, &py);
    304           glVertex2f(px, py);
    305 
    306           glTexCoord2f(x2, y);
    307           get_velocity(x2, y, &px, &py);
    308           glVertex2f(px, py);
     306            y = DM*j;
     307            glTexCoord2f(x1, y);
     308            get_velocity(x1, y, &px, &py);
     309            glVertex2f(px, py);
     310           
     311            glTexCoord2f(x2, y);
     312            get_velocity(x2, y, &px, &py);
     313            glVertex2f(px, py);
    309314        }
    310315        glEnd();
    311    }
    312    iframe = iframe + 1;
    313 
    314    glEnable(GL_BLEND);
    315 
     316    }
     317    iframe = iframe + 1;
     318   
     319    glEnable(GL_BLEND);
     320   
    316321    // INSOO ADD
    317322    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    318 
     323   
    319324    glEnable(GL_TEXTURE_2D);
    320    glCallList(iframe % Npat + disListID);
    321    glBegin(GL_QUAD_STRIP);
    322       glTexCoord2f(0.0,  0.0);  glVertex2f(0.0, 0.0);
    323       glTexCoord2f(0.0,  tmax); glVertex2f(0.0, 1.0);
    324       glTexCoord2f(tmax, 0.0);  glVertex2f(1.0, 0.0);
    325       glTexCoord2f(tmax, tmax); glVertex2f(1.0, 1.0);
    326    glEnd();
     325    glCallList(iframe % Npat + disListID);
     326    glBegin(GL_QUAD_STRIP);
     327    {
     328        glTexCoord2f(0.0,  0.0);  glVertex2f(0.0, 0.0);
     329        glTexCoord2f(0.0,  tmax); glVertex2f(0.0, 1.0);
     330        glTexCoord2f(tmax, 0.0);  glVertex2f(1.0, 0.0);
     331        glTexCoord2f(tmax, tmax); glVertex2f(1.0, 1.0);
     332        glEnd();
     333    }
    327334    glDisable(GL_TEXTURE_2D);
    328 
    329    /*
    330    //inject dye
    331    glDisable(GL_TEXTURE_2D);
    332    glColor4f(1.,0.8,0.,1.);
    333    glBegin(GL_QUADS);
    334      glVertex2d(0.6, 0.6);
    335      glVertex2d(0.6, 0.62);
    336      glVertex2d(0.62, 0.62);
    337      glVertex2d(0.62, 0.6);
    338    glEnd();
    339    */
    340 
     335   
     336    /*
     337    //inject dye
     338    glDisable(GL_TEXTURE_2D);
     339    glColor4f(1.,0.8,0.,1.);
     340    glBegin(GL_QUADS);
     341    glVertex2d(0.6, 0.6);
     342    glVertex2d(0.6, 0.62);
     343    glVertex2d(0.62, 0.62);
     344    glVertex2d(0.62, 0.6);
     345    glEnd();
     346    */
     347   
    341348    /// INSOO ADDED
    342349    glDisable(GL_ALPHA_TEST);
    343 
    344    glDisable(GL_BLEND);
    345    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, NPIX, NPIX, 0);
    346    
    347    /*
    348    //blend magnitude texture
    349    glBindTexture(GL_TEXTURE_2D, mag_tex);
    350    glEnable(GL_TEXTURE_2D);
    351    glEnable(GL_BLEND);
    352    glBegin(GL_QUADS);
    353       glTexCoord2f(0.0,  0.0);  glVertex2f(0.0, 0.0);
    354       glTexCoord2f(0.0,  1.0); glVertex2f(0.0, 1.);
    355       glTexCoord2f(1.0, 1.0);  glVertex2f(1., 1.);
    356       glTexCoord2f(1.0, 0.0); glVertex2f(1., 0.0);
    357    glEnd();
    358    */
    359 
    360    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    361 
     350   
     351    glDisable(GL_BLEND);
     352    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, NPIX, NPIX, 0);
     353   
     354    /*
     355    //blend magnitude texture
     356    glBindTexture(GL_TEXTURE_2D, mag_tex);
     357    glEnable(GL_TEXTURE_2D);
     358    glEnable(GL_BLEND);
     359    glBegin(GL_QUADS);
     360    glTexCoord2f(0.0,  0.0);  glVertex2f(0.0, 0.0);
     361    glTexCoord2f(0.0,  1.0); glVertex2f(0.0, 1.);
     362    glTexCoord2f(1.0, 1.0);  glVertex2f(1., 1.);
     363    glTexCoord2f(1.0, 0.0); glVertex2f(1., 0.0);
     364    glEnd();
     365    */
     366
     367    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    362368    glPopAttrib();
    363 
    364369    glPopMatrix();
    365370    glMatrixMode(GL_PROJECTION);
     
    371376
    372377
    373 void NvLIC::display()
    374 {
    375   glBindTexture(GL_TEXTURE_2D, color_tex);
    376   glEnable(GL_TEXTURE_2D);
    377 
    378   //draw line integral convolution quad
    379   glEnable(GL_DEPTH_TEST);
    380 
    381   glPushMatrix();
    382 
     378void
     379NvLIC::display()
     380{
     381    glBindTexture(GL_TEXTURE_2D, color_tex);
     382    glEnable(GL_TEXTURE_2D);
     383   
     384    //draw line integral convolution quad
     385    glEnable(GL_DEPTH_TEST);
     386   
     387    glPushMatrix();
     388   
    383389    //glScalef(scale.x, scale.y, scale.z);
    384390    float w = 1.0f / scale.x;
    385391    glScalef(1.0f, 1.0f / scale.y / w, 1.0f / scale.z / w);
    386 
    387   glBegin(GL_QUADS);
    388     glTexCoord2f(0, 0); glVertex3f(0, 0, offset);
    389     glTexCoord2f(1, 0); glVertex3f(1, 0, offset);
    390     glTexCoord2f(1, 1); glVertex3f(1, 1, offset);
    391     glTexCoord2f(0, 1); glVertex3f(0, 1, offset);
    392   glEnd();
    393 
    394   glPopMatrix();
    395 
    396   glBindTexture(GL_TEXTURE_2D,0);
    397 
    398   glDisable(GL_DEPTH_TEST);
    399   glDisable(GL_TEXTURE_2D);
    400 
    401 }
     392   
     393    glBegin(GL_QUADS);
     394    {
     395        glTexCoord2f(0, 0); glVertex3f(0, 0, offset);
     396        glTexCoord2f(1, 0); glVertex3f(1, 0, offset);
     397        glTexCoord2f(1, 1); glVertex3f(1, 1, offset);
     398        glTexCoord2f(0, 1); glVertex3f(0, 1, offset);
     399    }
     400    glEnd();
     401   
     402    glPopMatrix();
     403   
     404    glBindTexture(GL_TEXTURE_2D,0);
     405   
     406    glDisable(GL_DEPTH_TEST);
     407    glDisable(GL_TEXTURE_2D);
     408}
     409
    402410/*
    403411{
     
    433441
    434442
    435 void NvLIC::setVectorField(unsigned int texID, float scaleX, float scaleY, float scaleZ, float max)
     443void
     444NvLIC::setVectorField(unsigned int texID, float scaleX, float scaleY,
     445                      float scaleZ, float max)
    436446{
    437447    Trace("NvLIC: vector field is assigned [%d]\n", texID);
     
    443453}
    444454
    445 void NvLIC::get_velocity(float x, float y, float *px, float *py)
     455void
     456NvLIC::get_velocity(float x, float y, float *px, float *py)
    446457{
    447458   float vx, vy, r;
     
    456467
    457468    //Trace("(vx vx) = (%f %f), r=%f, ", vx, vy, r);
    458    if (r > dmax*dmax) {
     469   if (r > (dmax*dmax)) {
    459470      r  = sqrt(r);
    460471      vx *= dmax/r;
     
    468479}
    469480
    470 void NvLIC::set_offset(float v)
    471 {
    472   offset = v;
    473   get_slice();
    474 }
     481void
     482NvLIC::set_offset(float v)
     483{
     484    offset = v;
     485    get_slice();
     486}
  • trunk/packages/vizservers/nanovis/NvParticleRenderer.cpp

    r851 r1028  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    2728
    2829NvParticleRenderer::NvParticleRenderer(int w, int h, CGcontext context)
    29 : scale(1, 1, 1), _activate(false)
    30 {
    31   psys_width = w;
    32   psys_height = h;
    33 
    34   psys_frame = 0;
    35   reborn = true;
    36   flip = true;
    37   max_life = 500;
    38 
    39   data = (Particle*) malloc(w*h*sizeof(Particle));
    40 
    41   m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT);
    42 
    43   assert(glGetError()==0);
    44 
    45   glGenFramebuffersEXT(2, psys_fbo);
    46   glGenTextures(2, psys_tex);
    47 
    48   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);
    49 
    50   glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);
    51   glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    52   glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    53 
    54 #ifdef NV_32
    55   glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
    56 #else
    57   glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
    58 #endif
    59   glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[0], 0);
    60 
    61   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);
    62 
    63   glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);
    64   glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    65   glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    66 #ifdef NV_32
    67   glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
    68 #else
    69   glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
    70 #endif
    71   glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[1], 0);
    72 
    73   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    74 
    75   CHECK_FRAMEBUFFER_STATUS();
    76 
    77   //load related shaders
    78   /*
    79   m_g_context = context;
    80 
    81   R2string path = R2FilePath::getInstance()->getPath("update_pos.cg");
    82   m_pos_fprog = loadProgram(m_g_context, CG_PROFILE_FP30, CG_SOURCE, path);
    83   m_pos_timestep_param  = cgGetNamedParameter(m_pos_fprog, "timestep");
    84   m_vel_tex_param = cgGetNamedParameter(m_pos_fprog, "vel_tex");
    85   m_pos_tex_param = cgGetNamedParameter(m_pos_fprog, "pos_tex");
    86   m_scale_param = cgGetNamedParameter(m_pos_fprog, "scale");
    87   cgGLSetTextureParameter(m_vel_tex_param, volume);
    88   cgGLSetParameter3f(m_scale_param, scale_x, scale_y, scale_z);
    89   */
    90 
    91   _advectionShader = new NvParticleAdvectionShader();
     30    : scale(1, 1, 1), _activate(false)
     31{
     32    psys_width = w;
     33    psys_height = h;
     34
     35    psys_frame = 0;
     36    reborn = true;
     37    flip = true;
     38    max_life = 500;
     39
     40    data = (Particle*) malloc(w*h*sizeof(Particle));
     41
     42    m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT);
     43
     44    assert(glGetError()==0);
     45
     46    glGenFramebuffersEXT(2, psys_fbo);
     47    glGenTextures(2, psys_tex);
     48
     49    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);
     50
     51    glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);
     52    glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     53    glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     54
     55#ifdef NV_32
     56    glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
     57#else
     58    glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
     59#endif
     60    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[0], 0);
     61
     62    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);
     63
     64    glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);
     65    glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     66    glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     67#ifdef NV_32
     68    glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
     69#else
     70    glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);
     71#endif
     72    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[1], 0);
     73
     74    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     75
     76    CHECK_FRAMEBUFFER_STATUS();
     77
     78    //load related shaders
     79    /*
     80      m_g_context = context;
     81
     82      R2string path = R2FilePath::getInstance()->getPath("update_pos.cg");
     83      m_pos_fprog = loadProgram(m_g_context, CG_PROFILE_FP30, CG_SOURCE, path);
     84      m_pos_timestep_param  = cgGetNamedParameter(m_pos_fprog, "timestep");
     85      m_vel_tex_param = cgGetNamedParameter(m_pos_fprog, "vel_tex");
     86      m_pos_tex_param = cgGetNamedParameter(m_pos_fprog, "pos_tex");
     87      m_scale_param = cgGetNamedParameter(m_pos_fprog, "scale");
     88      cgGLSetTextureParameter(m_vel_tex_param, volume);
     89      cgGLSetParameter3f(m_scale_param, scale_x, scale_y, scale_z);
     90    */
     91
     92    _advectionShader = new NvParticleAdvectionShader();
    9293
    9394}
     
    135136    glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)data);#
    136137#endif
    137     glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
     138                                                                                                                       glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
    138139 
    139140    flip = true;
     
    151152   
    152153    if (flip)
    153     {
    154         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);
    155         glEnable(GL_TEXTURE_RECTANGLE_NV);
    156         glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);
    157 
    158         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    159         //glClear(GL_COLOR_BUFFER_BIT);
    160 
    161         glViewport(0, 0, psys_width, psys_height);
    162         glMatrixMode(GL_PROJECTION);
    163         glLoadIdentity();
    164         //gluOrtho2D(0, psys_width, 0, psys_height);
    165         glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f);
    166         glMatrixMode(GL_MODELVIEW);
    167         glLoadIdentity();
    168 
    169         _advectionShader->bind(psys_tex[0]);
     154        {
     155            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);
     156            glEnable(GL_TEXTURE_RECTANGLE_NV);
     157            glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);
     158
     159            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     160            //glClear(GL_COLOR_BUFFER_BIT);
     161
     162            glViewport(0, 0, psys_width, psys_height);
     163            glMatrixMode(GL_PROJECTION);
     164            glLoadIdentity();
     165            //gluOrtho2D(0, psys_width, 0, psys_height);
     166            glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f);
     167            glMatrixMode(GL_MODELVIEW);
     168            glLoadIdentity();
     169
     170            _advectionShader->bind(psys_tex[0]);
    170171     
    171      //cgGLBindProgram(m_pos_fprog);
    172      //cgGLSetParameter1f(m_pos_timestep_param, 0.05);
    173      //cgGLEnableTextureParameter(m_vel_tex_param);
    174      //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[0]);
    175      //cgGLEnableTextureParameter(m_pos_tex_param);
    176      //cgGLEnableProfile(CG_PROFILE_FP30);
     172            //cgGLBindProgram(m_pos_fprog);
     173            //cgGLSetParameter1f(m_pos_timestep_param, 0.05);
     174            //cgGLEnableTextureParameter(m_vel_tex_param);
     175            //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[0]);
     176            //cgGLEnableTextureParameter(m_pos_tex_param);
     177            //cgGLEnableProfile(CG_PROFILE_FP30);
    177178     
    178      draw_quad(psys_width, psys_height, psys_width, psys_height);
    179 
    180      //cgGLDisableProfile(CG_PROFILE_FP30);
    181      //cgGLDisableTextureParameter(m_vel_tex_param);
    182      //cgGLDisableTextureParameter(m_pos_tex_param);
    183         glDisable(GL_TEXTURE_RECTANGLE_NV);
    184    }
    185    else
    186    {
    187         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);
    188         glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);
    189 
    190         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    191         //glClear(GL_COLOR_BUFFER_BIT);
    192 
    193         glViewport(0, 0, psys_width, psys_height);
    194         glMatrixMode(GL_PROJECTION);
    195         glLoadIdentity();
    196         //gluOrtho2D(0, psys_width, 0, psys_height);
    197         glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f);
    198         glMatrixMode(GL_MODELVIEW);
    199         glLoadIdentity();
    200 
    201         _advectionShader->bind(psys_tex[1]);
    202 
    203      //cgGLBindProgram(m_pos_fprog);
    204      //cgGLSetParameter1f(m_pos_timestep_param, 0.05);
    205      //cgGLEnableTextureParameter(m_vel_tex_param);
    206      //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[1]);
    207      //cgGLEnableTextureParameter(m_pos_tex_param);
    208      //cgGLEnableProfile(CG_PROFILE_FP30);
    209 
    210         draw_quad(psys_width, psys_height, psys_width, psys_height);
    211         //draw_quad(psys_width, psys_height, 1.0f, 1.0f);
    212 
    213      //cgGLDisableProfile(CG_PROFILE_FP30);
    214      //cgGLDisableTextureParameter(m_vel_tex_param);
    215      //cgGLDisableTextureParameter(m_pos_tex_param);
    216     }
     179            draw_quad(psys_width, psys_height, psys_width, psys_height);
     180
     181            //cgGLDisableProfile(CG_PROFILE_FP30);
     182            //cgGLDisableTextureParameter(m_vel_tex_param);
     183            //cgGLDisableTextureParameter(m_pos_tex_param);
     184            glDisable(GL_TEXTURE_RECTANGLE_NV);
     185        }
     186    else
     187        {
     188            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);
     189            glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);
     190
     191            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     192            //glClear(GL_COLOR_BUFFER_BIT);
     193
     194            glViewport(0, 0, psys_width, psys_height);
     195            glMatrixMode(GL_PROJECTION);
     196            glLoadIdentity();
     197            //gluOrtho2D(0, psys_width, 0, psys_height);
     198            glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f);
     199            glMatrixMode(GL_MODELVIEW);
     200            glLoadIdentity();
     201
     202            _advectionShader->bind(psys_tex[1]);
     203
     204            //cgGLBindProgram(m_pos_fprog);
     205            //cgGLSetParameter1f(m_pos_timestep_param, 0.05);
     206            //cgGLEnableTextureParameter(m_vel_tex_param);
     207            //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[1]);
     208            //cgGLEnableTextureParameter(m_pos_tex_param);
     209            //cgGLEnableProfile(CG_PROFILE_FP30);
     210
     211            draw_quad(psys_width, psys_height, psys_width, psys_height);
     212            //draw_quad(psys_width, psys_height, 1.0f, 1.0f);
     213
     214            //cgGLDisableProfile(CG_PROFILE_FP30);
     215            //cgGLDisableTextureParameter(m_vel_tex_param);
     216            //cgGLDisableTextureParameter(m_pos_tex_param);
     217        }
    217218
    218219    _advectionShader->unbind();
    219220
    220    //soft_read_verts();
     221    //soft_read_verts();
    221222   
    222    update_vertex_buffer();
     223    update_vertex_buffer();
    223224
    224225    flip = (!flip);
     
    226227    psys_frame++;
    227228    if(psys_frame==max_life)
    228     {
    229         psys_frame=0;
    230         reborn = true;
    231     }
     229        {
     230            psys_frame=0;
     231            reborn = true;
     232        }
    232233
    233234    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     
    277278{
    278279    scale.set(scaleX, scaleY, scaleZ);
    279   _advectionShader->setScale(scale);
    280   _advectionShader->setVelocityVolume(texID, max);
    281 }
     280    _advectionShader->setScale(scale);
     281    _advectionShader->setVelocityVolume(texID, max);
     282}
  • trunk/packages/vizservers/nanovis/PCASplit.cpp

    r846 r1028  
     1
    12#include <stdio.h>
    23#include "PCASplit.h"
     
    1516namespace PCA {
    1617
    17 PCASplit::PCASplit()
    18 : _maxLevel(4), _minDistance(0.5f), _distanceScale(0.2f), _indexCount(0), _finalMaxLevel(0)
    19 {
    20         _indices = new unsigned int[MAX_INDEX];
    21         _memClusterChunk1 = new ClusterListNode[MAX_INDEX];
    22         _memClusterChunk2 = new ClusterListNode[MAX_INDEX];
    23         _curMemClusterChunk = _memClusterChunk1;
    24         _memClusterChunkIndex = 0;
     18PCASplit::PCASplit() :
     19    _maxLevel(4),
     20    _minDistance(0.5f),
     21    _distanceScale(0.2f),
     22    _indexCount(0),
     23    _finalMaxLevel(0)
     24{
     25    _indices = new unsigned int[MAX_INDEX];
     26    _memClusterChunk1 = new ClusterListNode[MAX_INDEX];
     27    _memClusterChunk2 = new ClusterListNode[MAX_INDEX];
     28    _curMemClusterChunk = _memClusterChunk1;
     29    _memClusterChunkIndex = 0;
    2530}
    2631
    2732PCASplit::~PCASplit()
    2833{
    29         delete [] _indices;
    30         delete [] _memClusterChunk1;
    31         delete [] _memClusterChunk2;
    32 }
    33 
    34 void PCASplit::computeCentroid(Point* data, int count, Vector3& mean/*, float& minValue, float& maxValue*/)
    35 {
    36         float sumx= 0, sumy = 0, sumz = 0;
    37         float size = 0;
    38         float sumsize = 0;
    39         for (int i = 0; i < count; ++i)
    40         {
    41                 size = data[i].size;
    42                 sumx += data[i].position.x * size;
    43                 sumy += data[i].position.y * size;
    44                 sumz += data[i].position.z * size;
    45                 sumsize += size;
    46         }
    47 
    48         sumsize = 1.0f / sumsize;
    49         mean.set(sumx * sumsize, sumy * sumsize, sumz * sumsize);
    50 }
    51 
    52 void PCASplit::computeCovariant(Point* data, int count, const Vector3& mean, float* m)
    53 {
    54         memset(m, 0, sizeof(float) * 9);
    55 
    56         for (int i = 0; i < count; ++i)
    57         {
    58                 m[0] += (data[i].position.x - mean.x) * (data[i].position.x - mean.x);
    59                 m[1] += (data[i].position.x - mean.x) * (data[i].position.y - mean.y);
    60                 m[2] += (data[i].position.x - mean.x) * (data[i].position.z - mean.z);
    61                 m[4] += (data[i].position.y - mean.y) * (data[i].position.y - mean.y);
    62                 m[5] += (data[i].position.y - mean.y) * (data[i].position.z - mean.z);
    63                 m[8] += (data[i].position.z - mean.z) * (data[i].position.z - mean.z);
    64         }
    65 
    66         float invCount = 1.0f / (count - 1);
    67         m[0] *= invCount;
    68         m[1] *= invCount;
    69         m[2] *= invCount;
    70         m[4] *= invCount;
    71         m[5] *= invCount;
    72         m[8] *= invCount;
    73         m[3] = m[1];
    74         m[6] = m[2];
    75         m[7] = m[5];
    76 }
    77 
    78 void PCASplit::computeDistortion(Point* data, int count, const Vector3& mean, float& distortion, float& finalSize)
    79 {
    80         distortion = 0.0f;
    81         finalSize = 0.0f;
    82        
    83         float maxSize = 0.0f;
    84         float distance;
    85         for (int i = 0; i < count; ++i)
    86         {
    87                 // sum
    88                 distance = mean.distanceSquare(data[i].position.x, data[i].position.y, data[i].position.z);
    89                 distortion += distance;
    90 
    91                 if (data[i].size > maxSize)
    92                 {
    93                         maxSize = data[i].size;
    94                 }
    95 
    96                 /*
    97                 finalSize += data[i].size * sqrt(distance);
    98                 */
    99                 if (distance > finalSize) finalSize = distance;
    100         }
    101 
    102         // equation 2
    103         //finalSize = 0.5f * sqrt (finalSize) / (float) (count - 1) + maxSize;
    104         finalSize = sqrt (finalSize) + maxSize;
    105 }
    106        
    107 void PCASplit::init()
    108 {
    109         _curClusterNode = 0;
    110         _curClusterCount = 0;
    111 }
    112 
    113 Cluster* PCASplit::createClusterBlock(ClusterListNode* clusterList, int count, int level)
    114 {
    115         static int cc = 0;
    116         cc += count;
    117         Cluster* clusterBlock = new Cluster[count];
    118 
    119         _clusterHeader->numOfClusters[level - 1] = count;
    120         _clusterHeader->startPointerCluster[level - 1] = clusterBlock;
    121 
    122         printf("Cluster created %d [in level %d]:total %d\n", count, level, cc);
     34    delete [] _indices;
     35    delete [] _memClusterChunk1;
     36    delete [] _memClusterChunk2;
     37}
     38
     39void
     40PCASplit::computeCentroid(Point* data, int count, Vector3& mean)
     41{
     42    float sumx= 0, sumy = 0, sumz = 0;
     43    float size = 0;
     44    float sumsize = 0;
     45    for (int i = 0; i < count; ++i) {
     46        size = data[i].size;
     47        sumx += data[i].position.x * size;
     48        sumy += data[i].position.y * size;
     49        sumz += data[i].position.z * size;
     50        sumsize += size;
     51    }
     52    sumsize = 1.0f / sumsize;
     53    mean.set(sumx * sumsize, sumy * sumsize, sumz * sumsize);
     54}
     55
     56void
     57PCASplit::computeCovariant(Point* data, int count, const Vector3& mean,
     58                           float* m)
     59{
     60    memset(m, 0, sizeof(float) * 9);
     61
     62    for (int i = 0; i < count; ++i) {
     63        m[0] += (data[i].position.x - mean.x) * (data[i].position.x - mean.x);
     64        m[1] += (data[i].position.x - mean.x) * (data[i].position.y - mean.y);
     65        m[2] += (data[i].position.x - mean.x) * (data[i].position.z - mean.z);
     66        m[4] += (data[i].position.y - mean.y) * (data[i].position.y - mean.y);
     67        m[5] += (data[i].position.y - mean.y) * (data[i].position.z - mean.z);
     68        m[8] += (data[i].position.z - mean.z) * (data[i].position.z - mean.z);
     69    }
     70   
     71    float invCount = 1.0f / (count - 1);
     72    m[0] *= invCount;
     73    m[1] *= invCount;
     74    m[2] *= invCount;
     75    m[4] *= invCount;
     76    m[5] *= invCount;
     77    m[8] *= invCount;
     78    m[3] = m[1];
     79    m[6] = m[2];
     80    m[7] = m[5];
     81}
     82
     83void
     84PCASplit::computeDistortion(Point* data, int count, const Vector3& mean,
     85                            float& distortion, float& finalSize)
     86{
     87    distortion = 0.0f;
     88    finalSize = 0.0f;
     89       
     90    float maxSize = 0.0f;
     91    float distance;
     92    for (int i = 0; i < count; ++i) {
     93        // sum
     94        distance = mean.distanceSquare(data[i].position.x, data[i].position.y, data[i].position.z);
     95        distortion += distance;
     96       
     97        if (data[i].size > maxSize) {
     98            maxSize = data[i].size;
     99        }
     100       
     101        /*
     102          finalSize += data[i].size * sqrt(distance);
     103        */
     104        if (distance > finalSize) {
     105            finalSize = distance;
     106        }
     107    }
     108    // equation 2
     109    //finalSize = 0.5f * sqrt (finalSize) / (float) (count - 1) + maxSize;
     110    finalSize = sqrt (finalSize) + maxSize;
     111}
     112       
     113void
     114PCASplit::init()
     115{
     116    _curClusterNode = 0;
     117    _curClusterCount = 0;
     118}
     119
     120Cluster*
     121PCASplit::createClusterBlock(ClusterListNode* clusterList, int count, int level)
     122{
     123    static int cc = 0;
     124    cc += count;
     125    Cluster* clusterBlock = new Cluster[count];
     126
     127    _clusterHeader->numOfClusters[level - 1] = count;
     128    _clusterHeader->startPointerCluster[level - 1] = clusterBlock;
     129
     130    printf("Cluster created %d [in level %d]:total %d\n", count, level, cc);
    123131    fflush(stdout);
    124        
    125         int i = 0;
    126         ClusterListNode* clusterNode = clusterList;
    127         while (clusterNode)
    128         {
    129                 clusterBlock[i].centroid = clusterList->data->centroid_t;
    130                 clusterBlock[i].level = level;
    131                 clusterBlock[i].scale = clusterList->data->scale_t;
    132 
    133                 clusterNode = clusterNode->next;
    134                 ++i;
    135         }
    136         if (count != i)
    137         {
    138                 printf("ERROR\n");
    139         }
    140         return clusterBlock;
     132       
     133    int i = 0;
     134    ClusterListNode* clusterNode = clusterList;
     135    while (clusterNode) {
     136        clusterBlock[i].centroid = clusterList->data->centroid_t;
     137        clusterBlock[i].level = level;
     138        clusterBlock[i].scale = clusterList->data->scale_t;
     139       
     140        clusterNode = clusterNode->next;
     141        ++i;
     142    }
     143    if (count != i) {
     144        printf("ERROR\n");
     145    }
     146    return clusterBlock;
    141147}
    142148
    143149ClusterAccel* PCASplit::doIt(Point* data, int count)
    144150{
    145         init();
    146 
    147         _clusterHeader = new ClusterAccel(_maxLevel);
    148        
    149         Cluster* root = new Cluster;
     151    init();
     152
     153    _clusterHeader = new ClusterAccel(_maxLevel);
     154       
     155    Cluster* root = new Cluster;
     156    Cluster_t* cluster_t = new Cluster_t();
     157    cluster_t->points_t = data;
     158    cluster_t->numOfPoints_t = count;
     159    root->level = 1;
     160       
     161    _clusterHeader->root = root;
     162    _clusterHeader->numOfClusters[0] = 1;
     163    _clusterHeader->startPointerCluster[0] = root;
     164       
     165    Vector3 mean;
     166    float distortion, scale;
     167       
     168    computeCentroid(cluster_t->points_t, cluster_t->numOfPoints_t, mean);
     169    computeDistortion(cluster_t->points_t, cluster_t->numOfPoints_t, mean,
     170                      distortion, scale);
     171       
     172    cluster_t->centroid_t = mean;
     173    cluster_t->scale_t = scale;
     174       
     175    float mindistance = _minDistance;
     176    int level = 2;
     177
     178    ClusterListNode* clustNodeList = &(_memClusterChunk2[0]);
     179    clustNodeList->data = cluster_t;
     180    clustNodeList->next = 0;
     181       
     182    _curRoot = root;
     183    do {
     184        analyze(clustNodeList, _curRoot, level, mindistance);
     185
     186        mindistance *= _distanceScale;
     187        ++level;
     188
     189        // swap memory buffer & init
     190        _curMemClusterChunk = (_curMemClusterChunk == _memClusterChunk1)?
     191            _memClusterChunk2 : _memClusterChunk1;
     192        _memClusterChunkIndex = 0;
     193
     194        clustNodeList = _curClusterNode;
     195
     196    } while (level <= _maxLevel);
     197
     198    return _clusterHeader;
     199}
     200
     201void
     202PCASplit::addLeafCluster(Cluster_t* cluster)
     203{
     204    ClusterListNode* clusterNode =
     205        &_curMemClusterChunk[_memClusterChunkIndex++];
     206    clusterNode->data = cluster;
     207    clusterNode->next = _curClusterNode;
     208    _curClusterNode = clusterNode;
     209    ++_curClusterCount;
     210}
     211
     212void
     213PCASplit::split(Point* data, int count, float limit)
     214{
     215    Vector3 mean;
     216    float m[9];
     217
     218    computeCentroid(data, count, mean);
     219    float scale, distortion;
     220    computeDistortion(data, count, mean, distortion, scale);
     221       
     222    //if (distortion < limit)
     223    if (scale < limit) {
    150224        Cluster_t* cluster_t = new Cluster_t();
     225        cluster_t->centroid_t = mean;
    151226        cluster_t->points_t = data;
    152227        cluster_t->numOfPoints_t = count;
    153         root->level = 1;
    154        
    155         _clusterHeader->root = root;
    156         _clusterHeader->numOfClusters[0] = 1;
    157         _clusterHeader->startPointerCluster[0] = root;
    158        
    159         Vector3 mean;
    160         float distortion, scale;
    161        
    162         computeCentroid(cluster_t->points_t, cluster_t->numOfPoints_t, mean);
    163         computeDistortion(cluster_t->points_t, cluster_t->numOfPoints_t, mean, distortion, scale);
    164        
    165         cluster_t->centroid_t = mean;
    166228        cluster_t->scale_t = scale;
    167        
    168         float mindistance = _minDistance;
    169         int level = 2;
    170 
    171         ClusterListNode* clustNodeList = &(_memClusterChunk2[0]);
    172         clustNodeList->data = cluster_t;
    173         clustNodeList->next = 0;
    174        
    175         _curRoot = root;
    176         do {
    177                 analyze(clustNodeList, _curRoot, level, mindistance);
    178 
    179                 mindistance *= _distanceScale;
    180                 ++level;
    181 
    182                 // swap memory buffer & init
    183                 _curMemClusterChunk = (_curMemClusterChunk == _memClusterChunk1)?
    184                                                                 _memClusterChunk2 : _memClusterChunk1;
    185                 _memClusterChunkIndex = 0;
    186 
    187                 clustNodeList = _curClusterNode;
    188 
    189         } while (level <= _maxLevel);
    190 
    191         return _clusterHeader;
    192 }
    193 
    194 void PCASplit::addLeafCluster(Cluster_t* cluster)
    195 {
    196         ClusterListNode* clusterNode = &_curMemClusterChunk[_memClusterChunkIndex++];
    197         clusterNode->data = cluster;
    198         clusterNode->next = _curClusterNode;
    199         _curClusterNode = clusterNode;
    200         ++_curClusterCount;
    201 }
    202 
    203 void PCASplit::split(Point* data, int count, float limit)
    204 {
    205         Vector3 mean;
    206         float m[9];
    207 
    208         computeCentroid(data, count, mean);
    209         float scale, distortion;
    210         computeDistortion(data, count, mean, distortion, scale);
    211        
    212         //if (distortion < limit)
    213         if (scale < limit)
    214         {
    215                 Cluster_t* cluster_t = new Cluster_t();
    216                 cluster_t->centroid_t = mean;
    217                 cluster_t->points_t = data;
    218                 cluster_t->numOfPoints_t = count;
    219                 cluster_t->scale_t = scale;
    220                 addLeafCluster(cluster_t);
    221                 return;
    222         }
    223 
    224         computeCovariant(data, count, mean, m);
    225 
    226         SymmetricMatrix A(3);
    227         for (int i = 1; i <= 3; ++i)
    228                 for (int j = 1; j <= i; ++j)
    229                 {
    230                         A(i, j) = m[(i - 1) * 3 + j - 1];
     229        addLeafCluster(cluster_t);
     230        return;
     231    }
     232   
     233    computeCovariant(data, count, mean, m);
     234   
     235    SymmetricMatrix A(3);
     236    for (int i = 1; i <= 3; ++i) {
     237        for (int j = 1; j <= i; ++j) {
     238            A(i, j) = m[(i - 1) * 3 + j - 1];
     239        }
     240    }
     241       
     242    Matrix U; DiagonalMatrix D;
     243    eigenvalues(A,D,U);
     244    Vector3 emax(U(1, 3), U(2, 3), U(3, 3));
     245   
     246    int left = 0, right = count - 1;
     247   
     248    Point p;
     249    for (;left < right;) {
     250        while (left < count && emax.dot(data[left].position - mean) >= 0.0f) {
     251            ++left;
     252        }
     253        while (right >= 0 && emax.dot(data[right].position - mean) < 0.0f) {
     254            --right;
     255        }
     256        if (left > right) {
     257            break;
     258        }
     259       
     260        p = data[left];
     261        data[left] = data[right];
     262        data[right] = p;
     263        ++left, --right;
     264       
     265    }
     266   
     267    if (left == 0 || right == count - 1) {
     268        printf("error\n");
     269        exit(1);
     270    } else {
     271        split(data, left, limit);
     272        split(data + left, count - left, limit);
     273    }
     274}
     275
     276void
     277PCASplit::analyze(ClusterListNode* clusterNode, Cluster* parent, int level,
     278                  float limit)
     279{
     280    if (level > _maxLevel) {
     281        return;
     282    }
     283    if (level > _finalMaxLevel) {
     284        _finalMaxLevel = level;
     285    }
     286       
     287    init();
     288
     289    ClusterListNode* clNode = clusterNode;
     290       
     291    // initialize the indexCount of indices
     292    _indexCount = 0;
     293    while (clNode) {
     294        if (clNode->data) {
     295            split(clNode->data->points_t, clNode->data->numOfPoints_t, limit);
     296            _indices[_indexCount++] = _curClusterCount;
     297        }
     298        clNode = clNode->next;
     299    }
     300       
     301    //Vector3 mean;
     302    //computeCentroid(cluster->points, cluster->numOfPoints, mean);
     303
     304    // the process values of split are in _curClusterNode and _curClusterCount
     305    ClusterListNode* curClusterNode = _curClusterNode;
     306    unsigned int curClusterNodeCount = _curClusterCount;
     307
     308    if (curClusterNodeCount) {
     309       
     310        // create and init centroid
     311        Cluster* retClusterBlock =
     312            createClusterBlock(curClusterNode, curClusterNodeCount, level);
     313       
     314        _curRoot = retClusterBlock;
     315       
     316        if (level == _maxLevel) {
     317            ClusterListNode* node = curClusterNode;
     318            if (_indexCount > 0) {
     319                // for parent
     320                Point* points = new Point[curClusterNodeCount];
     321               
     322                parent[0].setChildren(retClusterBlock, _indices[0]);
     323                parent[0].setPoints(points, _indices[0]);
     324               
     325                for (unsigned int i = 0, in = 0; i < curClusterNodeCount; ++i) {
     326                    if (i >= _indices[in]) {
     327                        in++;
     328                        parent[in].setChildren(retClusterBlock + _indices[in - 1], _indices[in] - _indices[in - 1]);
     329                        parent[in].setPoints(points + _indices[in - 1], _indices[in] - _indices[in - 1]);
     330                    }
     331                                       
     332                    retClusterBlock[i].scale = node->data->scale_t;
     333                    retClusterBlock[i].centroid = node->data->centroid_t;
     334                    retClusterBlock[i].points = node->data->points_t;
     335                    retClusterBlock[i].numOfPoints = node->data->numOfPoints_t;
     336                    retClusterBlock[i].color.set(float(rand()) / RAND_MAX,
     337                                                 float(rand()) / RAND_MAX,
     338                                                 float(rand()) / RAND_MAX,
     339                                                 0.2);
     340                   
     341                    points[i].position = node->data->centroid_t;
     342                    points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
     343                    points[i].size = node->data->scale_t;
     344                   
     345                    node = node->next;
    231346                }
    232 
    233        
    234         Matrix U; DiagonalMatrix D;
    235         eigenvalues(A,D,U);
    236         Vector3 emax(U(1, 3), U(2, 3), U(3, 3));
    237        
    238         int left = 0, right = count - 1;
    239 
    240         Point p;
    241         for (;left < right;)
    242         {
    243                 while (left < count && emax.dot(data[left].position - mean) >= 0.0f) ++left;
    244                 while (right >= 0 && emax.dot(data[right].position - mean) < 0.0f) --right;
     347            }
     348        } else {
     349            Point* points = new Point[curClusterNodeCount];
     350            ClusterListNode* node = curClusterNode;
     351           
     352            if (_indexCount > 0) {
     353                parent[0].setPoints(points, _indices[0]);
     354                parent[0].setChildren(retClusterBlock, _indices[0]);
     355                for (int k = 1; k < _indexCount; ++k) {
     356                    parent[k].setPoints(points + _indices[k - 1],
     357                                        _indices[k] - _indices[k - 1]);
     358                    parent[k].setChildren(retClusterBlock + _indices[k - 1],
     359                                          _indices[k] - _indices[k - 1]);
     360                }
     361                               
     362                // set points of sub-clusters
     363                for (unsigned int i = 0; i < curClusterNodeCount; ++i) {
     364                    points[i].position = node->data->centroid_t;
     365                    points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
     366                    points[i].size = node->data->scale_t;
     367                    node = node->next;
     368                }
    245369               
    246                 if (left > right) break;
    247 
    248                 p = data[left];
    249                 data[left] = data[right];
    250                 data[right] = p;
    251                 ++left, --right;
    252                
    253         }
    254 
    255         if (left == 0 || right == count - 1)
    256         {
    257                 printf("error\n");
    258                 exit(1);
    259         }
    260         else
    261         {
    262                 split(data, left, limit);
    263                 split(data + left, count - left, limit);
    264         }
    265 }
    266 
    267 void PCASplit::analyze(ClusterListNode* clusterNode, Cluster* parent, int level, float limit)
    268 {
    269     fflush(stdout);
    270         if (level > _maxLevel) return;
    271         else if (level > _finalMaxLevel) _finalMaxLevel = level;
    272        
    273         init();
    274 
    275         ClusterListNode* clNode = clusterNode;
    276        
    277         // initialize the indexCount of indices
    278         _indexCount = 0;
    279 
    280         while (clNode)
    281         {
    282                 if (clNode->data)
    283                 {
    284                         split(clNode->data->points_t, clNode->data->numOfPoints_t, limit);
    285                         _indices[_indexCount++] = _curClusterCount;
    286                 }
    287                        
    288                 clNode = clNode->next;
    289         }
    290        
    291         //Vector3 mean;
    292         //computeCentroid(cluster->points, cluster->numOfPoints, mean);
    293 
    294         // the process values of split are in _curClusterNode and _curClusterCount
    295         ClusterListNode* curClusterNode = _curClusterNode;
    296         unsigned int curClusterNodeCount = _curClusterCount;
    297 
    298         if (curClusterNodeCount)
    299         {
    300 
    301                 // create and init centroid
    302                 Cluster* retClusterBlock = createClusterBlock(curClusterNode, curClusterNodeCount, level);
    303                
    304                 _curRoot = retClusterBlock;
    305 
    306                 if (level == _maxLevel)
    307                 {
    308                         ClusterListNode* node = curClusterNode;
    309                         if (_indexCount > 0)
    310                         {
    311                                 // for parent
    312                                 Point* points = new Point[curClusterNodeCount];
    313                                
    314                                 parent[0].setChildren(retClusterBlock, _indices[0]);
    315                                 parent[0].setPoints(points, _indices[0]);
    316 
    317                                 for (unsigned int i = 0, in = 0; i < curClusterNodeCount; ++i)
    318                                 {
    319                                         if (i >= _indices[in])
    320                                         {
    321                                                 in++;
    322                                                 parent[in].setChildren(retClusterBlock + _indices[in - 1], _indices[in] - _indices[in - 1]);
    323                                                 parent[in].setPoints(points + _indices[in - 1], _indices[in] - _indices[in - 1]);
    324                                         }
    325                                        
    326                                         retClusterBlock[i].scale = node->data->scale_t;
    327                                         retClusterBlock[i].centroid = node->data->centroid_t;
    328                                         retClusterBlock[i].points = node->data->points_t;
    329                                         retClusterBlock[i].numOfPoints = node->data->numOfPoints_t;
    330                                         retClusterBlock[i].color.set(
    331                                                 float(rand()) / RAND_MAX, float(rand()) / RAND_MAX, float(rand()) / RAND_MAX,
    332                                                 0.2);
    333 
    334                                         points[i].position = node->data->centroid_t;
    335                                         points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
    336                                         points[i].size = node->data->scale_t;
    337 
    338                                         node = node->next;
    339                                        
    340                                         //::glGenBuffers(1, &(cluster[i].vbo));
    341                                         //glBindBuffer(GL_ARRAY_BUFFER, cluster[i].vbo);
    342                                         //      glBufferData(GL_ARRAY_BUFFER,
    343                                         //      sizeof(Point) * cluster[i].numOfPoints,
    344                                         //      cluster[i].points,
    345                                         //      GL_STATIC_DRAW);
    346                                         //glBindBuffer(GL_ARRAY_BUFFER, 0);
    347                                
    348                                 }
    349 
    350                                 /*
    351                                 ::glGenBuffers(1, &(_clusterHeader->_vbo[level - 1]));
    352                                 ::glBindBuffer(GL_ARRAY_BUFFER, _clusterHeader->_vbo[level - 1]);
    353                                 ::glBufferData(GL_ARRAY_BUFFER,
    354                                                 sizeof(Point) * curClusterNodeCount,
    355                                                 points,
    356                                                 GL_STATIC_DRAW);
    357                                 ::glBindBuffer(GL_ARRAY_BUFFER, 0);
    358                                 */
    359                         }
    360                        
    361                        
    362                        
    363                 }
    364                 else
    365                 {
    366                         Point* points = new Point[curClusterNodeCount];
    367                         ClusterListNode* node = curClusterNode;
    368                        
    369                         if (_indexCount > 0)
    370                         {
    371                                 parent[0].setPoints(points, _indices[0]);
    372                                 parent[0].setChildren(retClusterBlock, _indices[0]);
    373                                 for (int k = 1; k < _indexCount; ++k)
    374                                 {
    375                                         parent[k].setPoints(points + _indices[k - 1], _indices[k] - _indices[k - 1]);
    376                                         parent[k].setChildren(retClusterBlock + _indices[k - 1], _indices[k] - _indices[k - 1]);
    377                                 }
    378                                
    379                                 // set points of sub-clusters
    380                                 for (unsigned int i = 0; i < curClusterNodeCount; ++i)
    381                                 {
    382                                         points[i].position = node->data->centroid_t;
    383                                         points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
    384                                         points[i].size = node->data->scale_t;
    385                                         node = node->next;
    386                                 }
    387 
    388                         }
    389                 }
    390         }
    391 }
    392 
    393 }
    394 
     370            }
     371        }
     372    }
     373}
     374
     375} /*namespace PCA */
     376
  • trunk/packages/vizservers/nanovis/PCASplit.h

    r934 r1028  
    3737public :
    3838
    39         Cluster() : color(1.0f, 1.0f, 1.0f, 1.0f), scale(0.0f), numOfChildren(0), numOfPoints(0),
    40                         points(0), children(0), vbo(0)/*, minValue(0.0f), maxValue(0.0f)*/
    41                         , level(0)
     39        Cluster() :
     40            color(1.0f, 1.0f, 1.0f, 1.0f),
     41            scale(0.0f),
     42            numOfChildren(0),
     43            numOfPoints(0),
     44            points(0),
     45            children(0),
     46            vbo(0)/*, minValue(0.0f), maxValue(0.0f)*/
     47            , level(0)
    4248        {
    4349        }
  • trunk/packages/vizservers/nanovis/Plane.cpp

    r226 r1028  
    1515#include <assert.h>
    1616#include "Plane.h"
    17 
    18 Plane::Plane(){}
    1917
    2018Plane::Plane(float _a, float _b, float _c, float _d) {
     
    3634}
    3735
    38 void Plane::get_normal(Vector3 &normal){
    39     normal.x = a;
    40     normal.y = b;
    41     normal.z = c;
    42 }
    4336
    44 void Plane::get_point(Vector3 &point){
    45     if(a != 0){
    46                 point.x = -d/a;
    47                 point.y = 0;
    48                 point.z = 0;
    49     }
    50         else if(b != 0){
    51                 point.y = -d/b;
    52                 point.x = 0;
    53                 point.z = 0;
    54     }
    55         else if(c != 0){
    56                 point.z = -d /c;
    57                 point.y = 0;
    58                 point.x = 0;
    59     }
    60         else{
    61                 assert(false);
    62     }
    63 }
     37void
     38Plane::transform(Mat4x4 mat) {
     39    Vector4 coeffs(a, b, c, d);
    6440
    65 Vector4 Plane::get_coeffs(){
    66     Vector4 ret(a, b, c, d);
    67         return ret;
    68 }
    69 
    70 void Plane::set_coeffs(float _a, float _b, float _c, float _d){
    71     a = _a;
    72     b = _b;
    73     c = _c;
    74     d = _d;
    75 }
    76 
    77 void Plane::transform(Mat4x4 mat) {
    78     Vector4 coeffs(a, b, c, d);
    79         Mat4x4 inv = mat.inverse();
    80         Vector4 new_coeffs = inv.multiply_row_vector(coeffs);
    81 
     41    Mat4x4 inv = mat.inverse();
     42    Vector4 new_coeffs = inv.multiply_row_vector(coeffs);
    8243    a = new_coeffs.x;
    8344    b = new_coeffs.y;
     
    8647}
    8748
    88 void Plane::transform(float *m){
    89         Mat4x4 mat(m);
    90         transform(mat);
     49void
     50Plane::get_point(Vector3 &point){
     51    if (a != 0) {
     52        point.x = -d/a;
     53        point.y = 0;
     54        point.z = 0;
     55    } else if (b != 0) {
     56        point.y = -d/b;
     57        point.x = 0;
     58        point.z = 0;
     59    } else if (c != 0) {
     60        point.z = -d /c;
     61        point.y = 0;
     62        point.x = 0;
     63    } else{
     64        assert(false);
     65    }
    9166}
    92 
    93 bool Plane::retains(Vector3 point){
    94     return (a * point.x + b * point.y + c * point.z + d >= 0);
    95 }
  • trunk/packages/vizservers/nanovis/Plane.h

    r415 r1028  
    2020
    2121class Plane {
     22    float a, b, c, d;
    2223public:
    23     float a, b, c, d;
    2424       
    2525    Plane(float a, float b, float c, float d);
    2626    Plane(float coeffs[4]);
    27     Plane();
     27    Plane(void) {
     28        /*empty*/
     29    };
    2830   
    29     void get_normal(Vector3 &normal);
    3031    void get_point(Vector3 &point);
    31     Vector4 get_coeffs();
    32     void set_coeffs(float _a, float _b, float _c, float _d);
    33     void transform(Mat4x4 mat);
    34     void transform(float *m);
    35     bool retains(Vector3 point);
    3632    //bool clips(float point[3]) const { return !retains(point); }
    3733
     34    void transform(Mat4x4 mat);
     35    void transform(float *m) {
     36        Mat4x4 mat(m);
     37        transform(mat);
     38    }
     39    bool retains(Vector3 point) {
     40        return ((a*point.x + b*point.y + c*point.z + d) >= 0);
     41    }
     42    Vector4 get_coeffs(void) {
     43        return Vector4(a, b, c, d);
     44    }
     45    void set_coeffs(float a_val, float b_val, float c_val, float d_val) {
     46        a = a_val, b = b_val, c = c_val, d = d_val;
     47    }
     48    void get_normal(Vector3 &normal) {
     49        normal.x = a;
     50        normal.y = b;
     51        normal.z = c;
     52    }
    3853};
    3954
  • trunk/packages/vizservers/nanovis/PointSet.cpp

    r953 r1028  
    44#include <stdio.h>
    55
    6 PointSet::PointSet() :
    7     _sortLevel(4),
    8     _cluster(0),
    9     _max(1.0f),
    10     _min(0.0f),
    11     _visible(false)
    12 {
    13     /*empty*/
    14 }
    15 
    16 PointSet::~PointSet()
    17 {
    18     if (_cluster)
    19     {
    20         delete _cluster;
    21     }
    22 }
    23 
    24 void PointSet::initialize(Vector4* values, const unsigned int count, const Vector3& scale, const Vector3& origin, float min, float max)
     6void
     7PointSet::initialize(Vector4* values, const unsigned int count,
     8                     const Vector3& scale, const Vector3& origin,
     9                     float min, float max)
    2510{
    2611    PCA::PCASplit pcaSplit;
     
    3217
    3318    PCA::Point* points = (PCA::Point*) malloc(sizeof(PCA::Point) * count);
    34     for (unsigned int i = 0; i < count; ++i)
    35     {
     19    for (unsigned int i = 0; i < count; ++i) {
    3620        points[i].position.set(values[i].x, values[i].y, values[i].z);
    3721        points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
     
    4024    }
    4125
    42     if (_cluster != 0)
    43     {
     26    if (_cluster != 0) {
    4427        delete _cluster;
    4528    }
     
    4932}
    5033
    51 void PointSet::updateColor(float* color,  int colorCount)
     34void
     35PointSet::updateColor(float* color,  int colorCount)
    5236{
    53         if (_cluster == 0) return;
    54 
     37    if (_cluster == 0) {
     38        return;
     39    }
    5540    int level = 4;
    5641
    57         PCA::Cluster* cluster = _cluster->startPointerCluster[level - 1];
    58         PCA::Cluster* c = &(cluster[0]);
    59         PCA::Cluster* end = &(cluster[_cluster->numOfClusters[level - 1] - 1]);
    60 
    61         Vector3 pos;
    62        
     42    PCA::Cluster* cluster = _cluster->startPointerCluster[level - 1];
     43    PCA::Cluster* c = &(cluster[0]);
     44    PCA::Cluster* end = &(cluster[_cluster->numOfClusters[level - 1] - 1]);
     45   
     46    Vector3 pos;
     47   
    6348    PCA::Point* points;
    6449    Vector4* colors = (Vector4*) color;
    65         int numOfPoints;
     50    int numOfPoints;
    6651    int index;
    6752    float d = _max - _min;
    68         for (; c <= end; c = (PCA::Cluster*) ((int) c + sizeof(PCA::Cluster)))
    69         {
     53    for (/*empty*/; c <= end; c = (PCA::Cluster*)((int)c+sizeof(PCA::Cluster))){
    7054        points = c->points;
    7155        numOfPoints = c->numOfPoints;
    72 
    73         for (int i = 0; i < numOfPoints; ++i)
    74         {
     56       
     57        for (int i = 0; i < numOfPoints; ++i) {
    7558            index = (points[i].value - _min) / d  * (colorCount - 1);
    76             if (index >= colorCount) index = colorCount - 1;
    77             //printf("TEST %f %d/%d -> %d (%f %f %f)\n", points[i].value, i, numOfPoints, index,
    78             //                                    colors[index].x, colors[index].y, colors[index].z);
    79             //fflush(stdout);
     59            if (index >= colorCount) {
     60                index = colorCount - 1;
     61            }
    8062            points[i].color = colors[index];
    8163        }
    82 
    83         }
     64    }
    8465}
    8566
  • trunk/packages/vizservers/nanovis/PointSet.h

    r953 r1028  
    1717    bool _visible;
    1818public :
    19     PointSet();
    20     ~PointSet();
     19    void initialize(Vector4* values, const unsigned int count,
     20                    const Vector3& scale, const Vector3& origin,
     21                    float min, float max);
     22    void updateColor(float* color, int  count);
    2123
    22 public :
    23     void initialize(Vector4* values, const unsigned int count, const Vector3& scale, const Vector3& origin, float min, float max);
    24     bool isVisible() const;
    25     void setVisible(bool visible);
    26     unsigned int getSortLevel()const;
    27     PCA::ClusterAccel* getCluster();
    28     void updateColor(float* color, int  count);
    29     const Vector3& getScale() const;
    30     Vector3& getScale();
    31     const Vector3& getOrigin() const;
    32     Vector3& getOrigin();
     24    PointSet() :
     25        _sortLevel(4),
     26        _cluster(0),
     27        _max(1.0f),
     28        _min(0.0f),
     29        _visible(false)
     30    {
     31        /*empty*/
     32    }
     33    ~PointSet() {
     34        if (_cluster) {
     35            delete _cluster;
     36        }
     37    }
     38
     39    bool isVisible() const {
     40        return _visible;
     41    }
     42    void setVisible(bool visible) {
     43        _visible = visible;
     44    }
     45    unsigned int getSortLevel(void) const {
     46        return _sortLevel;
     47    }
     48    PCA::ClusterAccel* getCluster(void) {
     49        return _cluster;
     50    }
     51    Vector3& getScale(void) {
     52        return _scale;
     53    }
     54    const Vector3& getScale(void) const {
     55        return _scale;
     56    }
     57    Vector3& getOrigin(void) {
     58        return _origin;
     59    }
     60    const Vector3& getOrigin(void) const {
     61        return _origin;
     62    }
    3363};
    3464
    35 inline bool PointSet::isVisible() const
    36 {
    37     return _visible;
    38 }
    39 
    40 inline void PointSet::setVisible(bool visible)
    41 {
    42     _visible = visible;
    43 }
    44 
    45 inline unsigned int PointSet::getSortLevel()const
    46 {
    47     return _sortLevel;
    48 }
    49 
    50 inline PCA::ClusterAccel* PointSet::getCluster()
    51 {
    52     return _cluster;
    53 }
    54 
    55 inline Vector3& PointSet::getScale()
    56 {
    57     return _scale;
    58 }
    59 
    60 inline const Vector3& PointSet::getScale() const
    61 {
    62     return _scale;
    63 }
    64 
    65 inline Vector3& PointSet::getOrigin()
    66 {
    67     return _origin;
    68 }
    69 
    70 inline const Vector3& PointSet::getOrigin() const
    71 {
    72     return _origin;
    73 }
    74 
    75 #endif //
     65#endif /*__POINT_SET_H__*/
  • trunk/packages/vizservers/nanovis/RpDX.cpp

    r973 r1028  
    2222using namespace Rappture;
    2323
    24 DX::DX(const char* filename) :
     24DX::DX(const char* filename, Outcome *resultPtr) :
    2525    _dataMin(FLT_MAX),
    2626    _dataMax(-FLT_MAX),
     
    4747
    4848    if (filename == NULL) {
    49         // error
     49        resultPtr->AddError("filename is NULL");
     50        return;
    5051    }
    5152    // open the file with libdx
     
    5455    DXenable_locks(0);
    5556    _dxobj = DXImportDX((char*)filename,NULL,NULL,NULL,NULL);
     57    if (_dxobj == NULL) {
     58        resultPtr->AddError("can't import DX file \"%s\"", filename);
     59        return;
     60    }
    5661
    5762    fprintf(stdout, "dxobj=%x\n", (unsigned int)_dxobj);
    5863    fflush(stdout);
    5964
    60     // parse out the positions array
    61     // FIXME: nanowire will need a different way to parse out the positions array
    62     // since it uses a productarray to store its positions.
    63     // possibly use DXGetProductArray()
     65    // parse out the positions array
     66
     67    // FIXME: nanowire will need a different way to parse out the positions
     68    //        array since it uses a productarray to store its positions. 
     69    //        Possibly use DXGetProductArray().
    6470    dxpos = (Array) DXGetComponentValue((Field) _dxobj, (char *)"positions");
     71    if (dxpos == NULL) {
     72        resultPtr->AddError("can't get component value of \"positions\"");
     73        return;
     74    }
    6575    DXGetArrayInfo(dxpos, &_n, &type, &category, &_rank, &_shape);
    6676
    6777    fprintf(stdout, "_n = %d\n",_n);
    6878    if (type != TYPE_FLOAT) {
    69         fprintf(stderr, "WARNING: positions is not type float (type=%d)\n",
    70             type);
    71         fflush(stderr);
     79        resultPtr->AddError("\"positions\" is not type float (type=%d)\n", type);
     80        return;
    7281    }
    7382    fprintf(stdout, "_rank = %d\n",_rank);
     
    7786    pos = (float*) DXGetArrayData(dxpos);
    7887    if (pos == NULL) {
    79         fprintf(stdout, "DXGetArrayData failed to return positions array\n");
    80         fflush(stdout);
     88        resultPtr->AddError("DXGetArrayData failed to return positions array");
     89        return;
    8190    }
    8291
     
    8594    if (DXQueryGridConnections(dxgrid, &_numAxis, NULL) == NULL) {
    8695        // raise error, data is not a regular grid and we cannot handle it
    87         fprintf(stdout,"DX says our grid is not regular, we cannot handle this data\n");
    88         fflush(stdout);
     96        resultPtr->AddError("DX says our grid is not regular, we cannot handle this data");
     97        return;
    8998    }
    9099
     
    92101    if (_positions == NULL) {
    93102        // malloc failed, raise error
    94         fprintf(stdout, "malloc of _positions array failed");
    95         fflush(stdout);
     103        resultPtr->AddError("malloc of _positions array failed");
     104        return;
    96105    }
    97106    memcpy(_positions,pos,sizeof(float)*_n*_numAxis);
     
    100109    if (_axisLen == NULL) {
    101110        // malloc failed, raise error
    102         fprintf(stdout, "malloc of _axisLen array failed");
    103         fflush(stdout);
     111        resultPtr->AddError("malloc of _axisLen array failed");
     112        return;
    104113    }
    105114    memset(_axisLen, 0, _numAxis);
     
    107116    _delta = new float[_numAxis*_numAxis];
    108117    if (_delta == NULL) {
    109         // malloc failed, raise error
    110         fprintf(stdout, "malloc of _delta array failed");
    111         fflush(stdout);
     118        resultPtr->AddError("malloc of _delta array failed");
     119        return;
    112120    }
    113121    memset(_delta, 0, _numAxis*_numAxis);
     
    115123    _origin = new float[_numAxis];
    116124    if (_origin == NULL) {
    117         // malloc failed, raise error
    118         fprintf(stdout, "malloc of _origin array failed");
    119         fflush(stdout);
     125        resultPtr->AddError("malloc of _origin array failed");
     126        return;
    120127    }
    121128    memset(_origin, 0, _numAxis);
     
    123130    _max = new float[_numAxis];
    124131    if (_max == NULL) {
    125         // malloc failed, raise error
    126         fprintf(stdout, "malloc of _max array failed");
    127         fflush(stdout);
     132        resultPtr->AddError("malloc of _max array failed");
     133        return;
    128134    }
    129135    memset(_max, 0, _numAxis);
     
    148154    _data = new float[_n];
    149155    if (_data == NULL) {
    150         // malloc failed, raise error
    151         fprintf(stdout, "malloc of _data array failed");
    152         fflush(stdout);
     156        resultPtr->AddError("malloc of _data array failed");
     157        return;
    153158    }
    154159
     
    167172        }
    168173    default:
    169         fprintf(stdout, "don't know how to handle data of type %d\n", type);
    170         fflush(stdout);
     174        resultPtr->AddError("don't know how to handle data of type %d\n", type);
     175        return;
    171176    }
    172177
  • trunk/packages/vizservers/nanovis/RpDX.h

    r956 r1028  
    1919// #include "rappture2.h"
    2020#include <dx/dx.h>
     21#include <RpOutcome.h>
    2122
    2223namespace Rappture {
     
    2526public:
    2627    DX();
    27     DX(const char* filename);
     28    DX(const char* filename, RpOutcome *resultPtr);
    2829    DX(const DX& rpdx);
    2930    DX& operator=(const DX& rpdx);
  • trunk/packages/vizservers/nanovis/Texture3D.cpp

    r884 r1028  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    2526Texture3D::Texture3D(int width, int height, int depth, GLuint type=GL_FLOAT, GLuint interp=GL_LINEAR, int components=4)
    2627{
    27         assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT);
    28         assert(interp == GL_LINEAR || interp == GL_NEAREST);
    29        
    30         this->width = width;
    31         this->height = height;
    32         this->depth = depth;
    33 
    34         //int m = (width > height) ? width : height;
    35         //m = (m > depth) ? m : depth;
    36 
    37         //int m = max(max(width, height), depth);
    38         this->aspect_ratio_width = 1.;
    39         this->aspect_ratio_height = (double)height/(double)width;
    40         this->aspect_ratio_depth = (double)depth/(double)width;
    41 
    42         //this->aspect_ratio_width = (double)width/(double)m;
    43         //this->aspect_ratio_height = (double)height/(double)m;
    44         //this->aspect_ratio_depth = (double)depth/(double)m;
    45 
    46         this->type = type;
    47         this->interp_type = interp;
    48         this->n_components = components;
    49 
    50         this->id = 0;
    51         gl_resource_allocated = false;
     28    assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT);
     29    assert(interp == GL_LINEAR || interp == GL_NEAREST);
     30       
     31    this->width = width;
     32    this->height = height;
     33    this->depth = depth;
     34
     35    //int m = (width > height) ? width : height;
     36    //m = (m > depth) ? m : depth;
     37
     38    //int m = max(max(width, height), depth);
     39    this->aspect_ratio_width = 1.;
     40    this->aspect_ratio_height = (double)height/(double)width;
     41    this->aspect_ratio_depth = (double)depth/(double)width;
     42
     43    //this->aspect_ratio_width = (double)width/(double)m;
     44    //this->aspect_ratio_height = (double)height/(double)m;
     45    //this->aspect_ratio_depth = (double)depth/(double)m;
     46
     47    this->type = type;
     48    this->interp_type = interp;
     49    this->n_components = components;
     50
     51    this->id = 0;
     52    gl_resource_allocated = false;
    5253}
    5354
    5455void Texture3D::update(float* data)
    5556{
    56         //load texture with 16 bit half floating point precision if card is 6 series NV40
    57         //half float with linear interpolation is only supported by 6 series and up cards
    58         //If NV40 not defined, data is quantized to 8-bit from 32-bit.
    59         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    60 
    61         glBindTexture(GL_TEXTURE_3D, id);
    62         assert(id!=-1);
    63 
    64         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    65         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    66         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    67 
    68         if(interp_type==GL_LINEAR){
    69                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    70                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    71         }
    72         else{
    73                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    74                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    75         }
    76 
    77         //to do: add handling to more formats
    78         if(type==GL_FLOAT){
    79           switch(n_components){
    80             #ifdef NV40
    81                 case 1:
    82                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    83                         break;
    84                 case 2:
    85                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    86                         break;
    87                 case 3:
    88                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    89                         break;
    90                 case 4:
    91                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    92                         break;
    93             #else
    94                 case 1:
    95                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    96                         break;
    97                 case 2:
    98                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    99                         break;
    100                 case 3:
    101                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    102                         break;
    103                 case 4:
    104                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    105                         break;
    106             #endif
    107                 default:
    108                         break;
    109           }
    110         }
    111 
    112 
    113         assert(glGetError()==0);
    114        
    115         gl_resource_allocated = true;
     57    //load texture with 16 bit half floating point precision if card is 6 series NV40
     58    //half float with linear interpolation is only supported by 6 series and up cards
     59    //If NV40 not defined, data is quantized to 8-bit from 32-bit.
     60    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     61
     62    glBindTexture(GL_TEXTURE_3D, id);
     63    assert(id!=-1);
     64
     65    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     66    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     67    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
     68
     69    if(interp_type==GL_LINEAR){
     70        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     71        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     72    }
     73    else{
     74        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     75        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     76    }
     77
     78    //to do: add handling to more formats
     79    if(type==GL_FLOAT){
     80        switch(n_components){
     81#ifdef NV40
     82        case 1:
     83            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
     84            break;
     85        case 2:
     86            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
     87            break;
     88        case 3:
     89            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
     90            break;
     91        case 4:
     92            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
     93            break;
     94#else
     95        case 1:
     96            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
     97            break;
     98        case 2:
     99            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
     100            break;
     101        case 3:
     102            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
     103            break;
     104        case 4:
     105            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
     106            break;
     107#endif
     108        default:
     109            break;
     110        }
     111    }
     112
     113
     114    assert(glGetError()==0);
     115       
     116    gl_resource_allocated = true;
    116117
    117118}
     
    119120GLuint Texture3D::initialize(float *data)
    120121{
    121         if (id != 0) glDeleteTextures(1, &id);
    122 
    123         //load texture with 16 bit half floating point precision if card is 6 series NV40
    124         //half float with linear interpolation is only supported by 6 series and up cards
    125         //If NV40 not defined, data is quantized to 8-bit from 32-bit.
    126         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    127 
    128         glGenTextures(1, &id);
    129         glBindTexture(GL_TEXTURE_3D, id);
    130         assert(id!=-1);
    131 
    132         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    133         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    134         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    135 
    136         if(interp_type==GL_LINEAR){
    137                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    138                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    139         }
    140         else{
    141                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    142                 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    143         }
    144 
    145         //to do: add handling to more formats
    146         if(type==GL_FLOAT){
    147           switch(n_components){
    148             #ifdef NV40
    149                 case 1:
    150                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    151                         break;
    152                 case 2:
    153                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    154                         break;
    155                 case 3:
    156                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    157                         break;
    158                 case 4:
    159                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    160                         break;
    161             #else
    162                 case 1:
    163                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    164                         break;
    165                 case 2:
    166                         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    167                         break;
    168                 case 3:
    169                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    170                         break;
    171                 case 4:
    172                         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    173                         break;
    174             #endif
    175                 default:
    176                         break;
    177           }
    178         }
    179 
    180 
    181         assert(glGetError()==0);
    182        
    183         gl_resource_allocated = true;
    184         return id;
     122    if (id != 0) glDeleteTextures(1, &id);
     123
     124    //load texture with 16 bit half floating point precision if card is 6 series NV40
     125    //half float with linear interpolation is only supported by 6 series and up cards
     126    //If NV40 not defined, data is quantized to 8-bit from 32-bit.
     127    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     128
     129    glGenTextures(1, &id);
     130    glBindTexture(GL_TEXTURE_3D, id);
     131    assert(id!=-1);
     132
     133    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     134    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     135    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
     136
     137    if(interp_type==GL_LINEAR){
     138        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     139        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     140    }
     141    else{
     142        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     143        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     144    }
     145
     146    //to do: add handling to more formats
     147    if(type==GL_FLOAT){
     148        switch(n_components){
     149#ifdef NV40
     150        case 1:
     151            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
     152            break;
     153        case 2:
     154            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
     155            break;
     156        case 3:
     157            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
     158            break;
     159        case 4:
     160            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
     161            break;
     162#else
     163        case 1:
     164            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
     165            break;
     166        case 2:
     167            glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
     168            break;
     169        case 3:
     170            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
     171            break;
     172        case 4:
     173            glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
     174            break;
     175#endif
     176        default:
     177            break;
     178        }
     179    }
     180
     181
     182    assert(glGetError()==0);
     183       
     184    gl_resource_allocated = true;
     185    return id;
    185186}
    186187
    187188void Texture3D::activate()
    188189{
    189         glEnable(GL_TEXTURE_3D);
    190         glBindTexture(GL_TEXTURE_3D, id);
     190    glEnable(GL_TEXTURE_3D);
     191    glBindTexture(GL_TEXTURE_3D, id);
    191192}
    192193
    193194void Texture3D::deactivate()
    194195{
    195         glDisable(GL_TEXTURE_3D);               
     196    glDisable(GL_TEXTURE_3D);           
    196197}
    197198
    198199Texture3D::~Texture3D()
    199200{
    200         glDeleteTextures(1, &id);
     201    glDeleteTextures(1, &id);
    201202}
    202203
    203204void Texture3D::check_max_size(){
    204         GLint max = 0;
    205         glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &max);
    206        
    207         //printf("%d", glGetError());
    208         fprintf(stderr, "max 3d texture size: %d\n", max);
     205    GLint max = 0;
     206    glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &max);
     207       
     208    //printf("%d", glGetError());
     209    fprintf(stderr, "max 3d texture size: %d\n", max);
    209210}
    210211
    211212void Texture3D::check_max_unit(){
    212         int max;
    213         glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
    214 
    215         fprintf(stderr, "max texture units: %d.\n", max);
    216 }
     213    int max;
     214    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
     215
     216    fprintf(stderr, "max texture units: %d.\n", max);
     217}
  • trunk/packages/vizservers/nanovis/Vector3.h

    r911 r1028  
    1616#define _VECTOR3_H_
    1717
    18 class Mat4x4;
     18/*
     19 * FIXME: The files that explicitly use the "rot*", "length", "distance", or
     20 * "normalize" methods, should include the following headers.  Don't do it
     21 * here.
     22 */
     23#include <math.h>
     24#include "Mat4x4.h"
    1925
    2026class Vector3{
    21 
     27private:
     28    float radians(float degree) const {
     29        return (M_PI * degree) / 180.0;
     30    }
    2231public:
    23         float x, y, z;
    24         Vector3(float _x, float _y, float _z);
    25         Vector3();
    26 
    27         Vector3 operator +(Vector3 &op2);       
    28         Vector3 operator -(Vector3 &op2);
    29         Vector3 operator -(float scalar);
    30         Vector3 operator +(float scalar);
    31         bool equal(Vector3 &op2);
    32         //float operator *(Vector3 &op2);       //dot product
    33         float operator *(Vector3 &op2);         //dot product
    34         Vector3 operator *(float op2);    //mul per component
    35         Vector3 operator /(float op2);    //mul per component
    36         void operator <(Vector3 &op2);    //assign     
    37         Vector3 operator ^(Vector3 &op2); //cross product
    38         Vector3 normalize();
    39         Vector3 rot_x(float degree);      //rotation about x
    40         Vector3 rot_y(float degree);      //rotation about y
    41         Vector3 rot_z(float degree);      //rotation about z
    42         void set(float newx, float newy, float newz);
    43         void print();
    44         float distance(Vector3 &another) const; //compute distance
    45         float distanceSquare(Vector3 &another) const;   //compute distance
    46         float distanceSquare(float vx, float vy, float vz) const;       //compute distance
    47 
    48         //fast version
    49         Vector3 cross(Vector3 op2);
    50 
    51     float dot(const Vector3& vec) const;
    52 
    53     void transform(const Vector3& vec, const Mat4x4& mat);
    54     float length() const;
     32    float x, y, z;
     33    Vector3(void) {
     34        /*empty*/
     35    }
     36    Vector3(float x_val, float y_val, float z_val) {
     37        set(x_val, y_val, z_val);
     38    }
     39    Vector3 operator +(float scalar) {
     40        return Vector3(x + scalar, y + scalar, z + scalar);
     41    }
     42    Vector3 operator -(float scalar) {
     43        return Vector3(x - scalar, y - scalar, z - scalar);
     44    }
     45    Vector3 operator *(float scalar) {
     46        return Vector3(x * scalar, y * scalar, z * scalar);
     47    }
     48    Vector3 operator /(float scalar) {
     49        return Vector3(x / scalar, y / scalar, z / scalar);
     50    }
     51    Vector3 operator +(Vector3 &op2) {
     52        return Vector3(x + op2.x, y + op2.y, z + op2.z);
     53    }
     54    Vector3 operator -(Vector3 &op2) {
     55        return Vector3(x - op2.x, y - op2.y, z - op2.z);
     56    }
     57    float operator *(Vector3 &op2){
     58        return x*op2.x + y*op2.y + z*op2.z;
     59    }
     60    float dot(const Vector3& vec) const {
     61        return x*vec.x + y*vec.y + z*vec.z;
     62    }
     63    bool equal(Vector3 &op2) {
     64        return (x==op2.x) && (y==op2.y) && (z==op2.z);
     65    }
     66    Vector3 cross(Vector3 op2) {
     67        return Vector3(y*op2.z - z*op2.y, z*op2.x - x*op2.z, x*op2.y - y*op2.x);
     68    }
     69    void operator<(Vector3 &op2) {
     70        set(op2.x, op2.y, op2.z);
     71    }
     72    Vector3 operator ^(Vector3 &op2) {
     73        return cross(op2);
     74    }
     75    Vector3 normalize(void) {
     76        float len = length();
     77        return Vector3(x / len, y / len, z / len);
     78    }
     79    Vector3 rot_x(float degree) {
     80        float rad = radians(degree);
     81        return Vector3(x,
     82                       y*cos(rad) - z*sin(rad),
     83                       y*sin(rad) + z*cos(rad));
     84    }
     85    Vector3 rot_y(float degree) {
     86        float rad = radians(degree);
     87        return Vector3(x*cos(rad) + z*sin(rad),
     88                       y,
     89                       -x*sin(rad) + z*cos(rad));
     90    }
     91    Vector3 rot_z(float degree) {
     92        float rad = radians(degree);
     93        return Vector3(x*cos(rad) - y*sin(rad),
     94                       x*sin(rad) + y*cos(rad),
     95                       z);
     96    }
     97    void set(float x_val, float y_val, float z_val) {
     98        x = x_val, y = y_val, z = z_val;
     99    }
     100    void print(void){
     101        fprintf(stderr, "x:%f, y:%f, z:%f\n", x, y, z);
     102    }
     103    float distance(Vector3 &v) const {
     104        return sqrtf(distanceSquare(v));
     105    }
     106    float distanceSquare(Vector3 &v) const {
     107        return (x-v.x)*(x-v.x) + (y-v.y)*(y-v.y) + (z-v.z)*(z-v.z);
     108    }
     109    float distanceSquare(float vx, float vy, float vz) const {
     110        return (x-vx)*(x-vx) + (y-vy)*(y-vy) + (z-vz)*(z-vz);
     111    }
     112    void transform(const Vector3& v, const Mat4x4& mat) {
     113        const float* m = mat.m;
     114        x = m[0] * v.x + m[4] * v.y + m[8]  * v.z + m[12];
     115        y = m[1] * v.x + m[5] * v.y + m[9]  * v.z + m[13];
     116        z = m[2] * v.x + m[6] * v.y + m[10] * v.z + m[14];
     117    }
     118    float length(void) const {
     119        return sqrt(x*x + y*y + z*z);
     120    }
    55121};
    56122
    57 inline Vector3 Vector3::operator +(float scalar)
    58 {
    59     Vector3 v;
    60     v.x = x + scalar;
    61     v.y = y + scalar;
    62     v.z = z + scalar;
    63     return v;
    64 }
    65123
    66 inline Vector3 Vector3::operator -(float scalar)
    67 {
    68     Vector3 v;
    69     v.x = x - scalar;
    70     v.y = y - scalar;
    71     v.z = z - scalar;
    72     return v;
    73 }
    74124#endif
  • trunk/packages/vizservers/nanovis/Vector4.h

    r819 r1028  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    1617#define _VECTOR4_H_
    1718
     19#include <stdio.h>
     20
    1821class Vector4 
    1922{
    2023public:
    21         float x, y, z, w;
     24    float x, y, z, w;
    2225
    23         Vector4();
    24         Vector4(float _x, float _y, float _z, float _w);
    25         ~Vector4();
     26    Vector4(void) {
     27        /*empty*/
     28    }
     29    Vector4(float x_val, float y_val, float z_val, float w_val) {
     30        set(x_val, y_val, z_val, w_val);
     31    }
     32    void perspective_devide(void) {
     33        /* Divide vector by w */
     34        x /= w, y /= w, z /= w, w = 1.;
     35    }
    2636
    27         void perspective_devide();
    28         void print();
    29         Vector4 operator +(Vector4 &op2); //plus       
    30         Vector4 operator -(Vector4 &op2); //minus
    31         float operator *(Vector4 &op2);   //dot product
    32         Vector4 operator*(float op2);     //mul per component
    33         Vector4 operator/(float op2);     //mul per component
    34         void operator <(Vector4 &op2);    //assign     
     37    void print(void) {
     38        fprintf(stderr, "Vector4: (%.3f, %.3f, %.3f, %.3f)\n", x, y, z, w);
     39    }
    3540
    36     void set(float x1, float y1, float z1, float w1);
     41    Vector4 operator +(Vector4 &op2){
     42        return Vector4(x + op2.x, y + op2.y, z + op2.z, w + op2.w);
     43    }
     44
     45    Vector4 operator -(Vector4 &op2){
     46        return Vector4(x - op2.x, y - op2.y, z - op2.z, w - op2.w);
     47    }
     48
     49    float operator *(Vector4 &op2) {
     50        return (x * op2.x) + (y * op2.y) + (z * op2.z) + (w * op2.w);
     51    }
     52
     53    Vector4 operator *(float op2){
     54        return Vector4(x * op2, y * op2, z * op2, w * op2);
     55    }
     56
     57    Vector4 operator /(float op2) {
     58        return Vector4(x / op2, y / op2, z / op2, w / op2);
     59    }
     60
     61    void operator <(Vector4 &op2) {
     62        set(op2.x, op2.y, op2.z, op2.w);
     63    }
     64    void set(float x_val, float y_val, float z_val, float w_val) {
     65        x = x_val, y = y_val, z = z_val, w = w_val;
     66    }
    3767};
    3868
  • trunk/packages/vizservers/nanovis/VolumeRenderer.cpp

    r927 r1028  
    2222#include <sys/time.h>
    2323#include "Trace.h"
    24 
     24#include "nanovis.h"
     25#include "Grid.h"
     26
     27#define NUMDIGITS       6
    2528
    2629VolumeRenderer::VolumeRenderer():
     
    242245        model_view_trans_inverse = model_view_trans.inverse();
    243246
    244     //draw volume bounding box with translation (the correct location in space)
     247        //draw volume bounding box with translation (the correct location in
     248        //space)
    245249        if (cur_vol->outline_is_enabled()) {
    246250            float olcolor[3];
     
    484488
    485489  //volume start location
    486   Vector4 shift_4d(volume[volume_index]->location.x, volume[volume_index]->location.y, volume[volume_index]->location.z, 0);
     490  Vector4 shift_4d(volume[volume_index]->location.x,
     491                   volume[volume_index]->location.y,
     492                   volume[volume_index]->location.z, 0);
    487493
    488494  double x0 = 0;
     
    570576    int axis = volume[volume_index]->get_cutplane(i)->orient;
    571577
    572     if(axis==1){
     578    if (axis==1) {
    573579      vert1 = Vector4(-10, -10, offset, 1);
    574580      vert2 = Vector4(-10, +10, offset, 1);
    575581      vert3 = Vector4(+10, +10, offset, 1);
    576582      vert4 = Vector4(+10, -10, offset, 1);
    577     }
    578     else if(axis==2){
     583    } else if(axis==2){
    579584      vert1 = Vector4(offset, -10, -10, 1);
    580585      vert2 = Vector4(offset, +10, -10, 1);
    581586      vert3 = Vector4(offset, +10, +10, 1);
    582587      vert4 = Vector4(offset, -10, +10, 1);
    583     }
    584     else if(axis==3){
     588    } else if(axis==3) {
    585589      vert1 = Vector4(-10, offset, -10, 1);
    586590      vert2 = Vector4(+10, offset, -10, 1);
     
    692696}
    693697
    694 void VolumeRenderer::draw_bounding_box(float x0, float y0, float z0,
    695                 float x1, float y1, float z1,
    696                 float r, float g, float b, float line_width)
     698void
     699VolumeRenderer::draw_bounding_box(
     700    float x0, float y0, float z0,
     701    float x1, float y1, float z1,
     702    float r, float g, float b,
     703    float line_width)
    697704{
    698         glDisable(GL_TEXTURE_2D);
    699 
    700         glColor4d(r, g, b, 1.0);
    701         glLineWidth(line_width);
     705    glPushMatrix();
     706    glEnable(GL_DEPTH_TEST);
     707    glDisable(GL_TEXTURE_2D);
     708    glEnable(GL_BLEND);
     709
     710    glColor4d(r, g, b, 1.0);
     711    glLineWidth(line_width);
     712   
     713    glBegin(GL_LINE_LOOP);
     714    {
     715        glVertex3d(x0, y0, z0);
     716        glVertex3d(x1, y0, z0);
     717        glVertex3d(x1, y1, z0);
     718        glVertex3d(x0, y1, z0);
     719    }
     720    glEnd();
     721   
     722    glBegin(GL_LINE_LOOP);
     723    {
     724        glVertex3d(x0, y0, z1);
     725        glVertex3d(x1, y0, z1);
     726        glVertex3d(x1, y1, z1);
     727        glVertex3d(x0, y1, z1);
     728    }
     729    glEnd();
     730   
     731   
     732    glBegin(GL_LINE_LOOP);
     733    {
     734        glVertex3d(x0, y0, z0);
     735        glVertex3d(x0, y0, z1);
     736        glVertex3d(x0, y1, z1);
     737        glVertex3d(x0, y1, z0);
     738    }
     739    glEnd();
     740   
     741    glBegin(GL_LINE_LOOP);
     742    {
     743        glVertex3d(x1, y0, z0);
     744        glVertex3d(x1, y0, z1);
     745        glVertex3d(x1, y1, z1);
     746        glVertex3d(x1, y1, z0);
     747    }
     748    glEnd();
     749
     750#ifdef notdef
     751    /* Rappture doesn't supply axis units yet. So turn labeling off until we
     752     * can display the proper units with the distance of each bounding box
     753     * dimension.
     754     */
     755    glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
     756
     757    if (NanoVis::fonts != NULL) {
     758        double mv[16], prjm[16];
     759        int viewport[4];
     760        double wx, wy, wz;
     761        double dx, dy, dz;
     762
     763        glGetDoublev(GL_MODELVIEW_MATRIX, mv);
     764        glGetDoublev(GL_PROJECTION_MATRIX, prjm);
     765        glGetIntegerv(GL_VIEWPORT, viewport);
    702766       
    703         glBegin(GL_LINE_LOOP);
    704 
    705                 glVertex3d(x0, y0, z0);
    706                 glVertex3d(x1, y0, z0);
    707                 glVertex3d(x1, y1, z0);
    708                 glVertex3d(x0, y1, z0);
    709                
    710         glEnd();
    711 
    712         glBegin(GL_LINE_LOOP);
    713 
    714                 glVertex3d(x0, y0, z1);
    715                 glVertex3d(x1, y0, z1);
    716                 glVertex3d(x1, y1, z1);
    717                 glVertex3d(x0, y1, z1);
    718                
    719         glEnd();
    720 
    721 
    722         glBegin(GL_LINE_LOOP);
    723 
    724                 glVertex3d(x0, y0, z0);
    725                 glVertex3d(x0, y0, z1);
    726                 glVertex3d(x0, y1, z1);
    727                 glVertex3d(x0, y1, z0);
    728                
    729         glEnd();
    730 
    731         glBegin(GL_LINE_LOOP);
    732 
    733                 glVertex3d(x1, y0, z0);
    734                 glVertex3d(x1, y0, z1);
    735                 glVertex3d(x1, y1, z1);
    736                 glVertex3d(x1, y1, z0);
    737                
    738         glEnd();
    739 
    740         glEnable(GL_TEXTURE_2D);
     767        NanoVis::fonts->begin();
     768        dx = x1 - x0;
     769        dy = y1 - y0;
     770        dz = z1 - z0;
     771        if (gluProject((x0 + x1) * 0.5, y0, z0, mv, prjm, viewport,
     772                       &wx, &wy, &wz)) {
     773            char buff[20];
     774            double min, max;
     775
     776            NanoVis::grid->xAxis.GetDataLimits(min, max);
     777            glLoadIdentity();
     778            glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
     779            const char *units;
     780            units = NanoVis::grid->xAxis.GetUnits();
     781            sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
     782            NanoVis::fonts->draw(buff);
     783        }
     784        if (gluProject(x0, (y0 + y1) * 0.5, z0, mv, prjm, viewport, &
     785                       wx, &wy, &wz)) {
     786            char buff[20];
     787            double min, max;
     788
     789            NanoVis::grid->yAxis.GetDataLimits(min, max);
     790            glLoadIdentity();
     791            glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
     792            const char *units;
     793            units = NanoVis::grid->yAxis.GetUnits();
     794            sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
     795            NanoVis::fonts->draw(buff);
     796        }
     797        if (gluProject(x0, y0, (z0 + z1) * 0.5, mv, prjm, viewport,
     798                       &wx, &wy, &wz)) {
     799            glLoadIdentity();
     800            glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f);
     801
     802            double min, max;
     803            NanoVis::grid->zAxis.GetDataLimits(min, max);
     804            const char *units;
     805            units = NanoVis::grid->zAxis.GetUnits();
     806            char buff[20];
     807            sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units);
     808            NanoVis::fonts->draw(buff);
     809        }
     810        NanoVis::fonts->end();
     811    };
     812#endif
     813    glPopMatrix();
     814    glDisable(GL_DEPTH_TEST);
     815    glDisable(GL_BLEND);
     816    glEnable(GL_TEXTURE_2D);
    741817}
    742818
     
    793869  vertex[7][0]=x1; vertex[7][1]=y1; vertex[7][2]=z1; vertex[7][3]=1.0;
    794870
    795   for(int i=0;i<8;i++)
    796   {
     871  for(int i=0;i<8;i++) {
    797872    Vector4 tmp = mv.transform(Vector4(vertex[i][0], vertex[i][1], vertex[i][2], vertex[i][3]));
    798873    tmp.perspective_devide();
     
    834909
    835910    /* make sure the file is there and open it read-only (binary) */
    836     if ((file = fopen(filename, "rb")) == NULL)
    837     {
    838       assert(false);
    839     }
    840    
    841     if(!fread(&bfType, sizeof(short int), 1, file))
    842     {
    843       assert(false);
    844       //printf("Error reading file!\n");
     911    if ((file = fopen(filename, "rb")) == NULL) {
     912        fprintf(stderr, "can't open font file \"%s\"\n", filename);
     913        abort();
     914    }
     915   
     916    if(!fread(&bfType, sizeof(short int), 1, file)) {
     917        fprintf(stderr, "can't read 2 bytes from font file \"%s\"\n", filename);
     918        abort();
    845919    }
    846920   
    847921    /* check if file is a bitmap */
    848     if (bfType != 19778)
    849     {
    850       assert(false);
    851       //printf("Not a Bitmap-File!\n");
     922    if (bfType != 19778) {
     923        assert(false);
     924        //printf("Not a Bitmap-File!\n");
    852925    }
    853926   
     
    857930   
    858931    /* get the position of the actual bitmap data */
    859     if (!fread(&bfOffBits, sizeof(long int), 1, file))
    860     {
    861       assert(false);
    862       //printf("Error reading file!\n");
     932    if (!fread(&bfOffBits, sizeof(long int), 1, file)) {
     933        assert(false);
     934        //printf("Error reading file!\n");
    863935    }
    864936    //printf("Data at Offset: %ld\n", bfOffBits);
     
    884956   
    885957    /* get the number of bits per pixel */
    886     if (!fread(&biBitCount, sizeof(short int), 1, file))
    887     {
    888       assert(false);
    889       //printf("Error reading file!\n");
    890       //return 0;
     958    if (!fread(&biBitCount, sizeof(short int), 1, file)) {
     959        assert(false);
     960        //printf("Error reading file!\n");
     961        //return 0;
    891962    }
    892963   
    893964    //printf("Bits per Pixel: %d\n", biBitCount);
    894     if (biBitCount != 24)
    895     {
    896       assert(false);
    897       //printf("Bits per Pixel not 24\n");
    898       //return 0;
     965    if (biBitCount != 24) {
     966        assert(false);
     967        //printf("Bits per Pixel not 24\n");
     968        //return 0;
    899969    }
    900970
     
    907977    /* seek to the actual data */
    908978    fseek(file, bfOffBits, SEEK_SET);
    909     if (!fread(data, biSizeImage, 1, file))
    910     {
    911        assert(false);
    912        //printf("Error loading file!\n");
    913     }
    914 
     979    if (!fread(data, biSizeImage, 1, file)) {
     980        assert(false);
     981        //printf("Error loading file!\n");
     982    }
     983   
    915984    /* swap red and blue (bgr -> rgb) */
    916     for (i = 0; i < biSizeImage; i += 3)
    917     {
     985    for (i = 0; i < biSizeImage; i += 3) {
    918986       temp = data[i];
    919987       data[i] = data[i + 2];
  • trunk/packages/vizservers/nanovis/config.h

    r829 r1028  
    2222//#define DO_RLE  //do run length compression
    2323
     24/*
     25 * The following define controls whether new prototype features are to be
     26 * compiled.  Right now by default it's off (0). That's because nanovis
     27 * releases are built directly from the subversion repository.  So for now,
     28 * we'll rely on developers to set this in their respective sandboxes.
     29 */
     30#define PROTOTYPE               0
     31
     32/*
     33 * The following define controls whether new load_volume_stream or
     34 * load_volume_stream2 are used to load DX data.  The difference is that
     35 * load_volume_stream2 doesn't do any interpolation of the points to a coarser
     36 * mesh.  Right now, we're using load_volume_stream2 to make isosurfaces
     37 * work correctly. 
     38
     39 * [In the future, we'll use the OpenDX library reader and determine at
     40 * runtime if mesh decimation is required]
     41 */
     42#define ISO_TEST                1
     43
     44/*
     45 * The following define controls whether the plane* commands are
     46 * registered in the interpreter.  Right now it's off.  [Are these
     47 * commands still required?]
     48 */
     49#define PLANE_CMD               0
     50
    2451#endif
  • trunk/packages/vizservers/nanovis/dxReader2.cpp

    r961 r1028  
    2929    // write the dx file to disk, because DXImportDX takes a file name
    3030    // george suggested using a pipe here
     31
     32    // You can do it like this.  Give
    3133    sprintf(dxfilename, "/tmp/dx%d.dx", getpid());
    3234
     
    3739    fclose(f);
    3840
    39     Rappture::DX dxObj(dxfilename);
     41    Rappture::DX dxObj(dxfilename, &outcome);
    4042
    4143    if (remove(dxfilename) != 0) {
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r973 r1028  
    6969#include <R2/R2FilePath.h>
    7070#include <R2/R2Fonts.h>
     71
     72#define SIZEOF_BMP_HEADER       54
    7173
    7274extern void NvInitCG(); // in Shader.cpp
     
    104106
    105107
     108//frame buffer for final rendering
     109NVISid NanoVis::final_fbo;
     110NVISid NanoVis::final_color_tex;
     111NVISid NanoVis::final_depth_rb;
     112
    106113// pointers to volumes, currently handle up to 10 volumes
    107114/*FIXME: Is the above comment true? Is there a 10 volume limit */
     
    139146//static Lic* lic;
    140147
    141 //frame buffer for final rendering
    142 static NVISid final_fbo, final_color_tex, final_depth_rb;
    143148
    144149//bool advect=false;
     
    253258
    254259//report errors related to CG shaders
    255 void cgErrorCallback(void)
     260void
     261cgErrorCallback(void)
    256262{
    257263    CGerror lastError = cgGetError();
     
    408414    //glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, screen_buffer); // INSOO's
    409415
    410     std::ostringstream result;
    411     result << "nv>legend " << volArg;
    412     result << " " << min;
    413     result << " " << max;
    414     bmp_write(result.str().c_str());
     416    char prefix[200];
     417    sprintf(prefix, "nv>legend %s %g %g", volArg, min, max);
     418    ppm_write(prefix);
    415419    write(0, "\n", 1);
    416420
     
    529533    CHECK_FRAMEBUFFER_STATUS();
    530534    //assert(glGetError()==0);
    531     fprintf(stdin,"  after assert\n");
    532 }
    533 
     535}
     536
     537/*
     538 * FIXME: This routine is fairly expensive (60000 floating pt divides). 
     539 *        I've put an ifdef around the call to it so that the released
     540 *        builds don't include it.  Define PROTOTYPE to 1 in config.h
     541 *        to turn it back on.
     542 */
    534543void
    535544make_test_2D_data()
    536545{
    537 
    538546    int w = 300;
    539547    int h = 200;
     
    640648   
    641649    particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context);
     650
     651#if PROTOTYPE
    642652    licRenderer = new NvLIC(NMESH, NPIX, NPIX, 0.5, g_context);
     653#endif
    643654
    644655    ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl());
    645 
    646656    grid = new Grid();
    647657    grid->setFont(fonts);
     
    722732   //create an 2D plane renderer
    723733   plane_render = new PlaneRenderer(g_context, win_width, win_height);
     734#if PROTOTYPE
    724735   make_test_2D_data();
    725 
     736#endif  /* PROTOTYPE */
    726737   plane_render->add_plane(plane[0], get_transfunc("default"));
    727738
     
    732743   NanoVis::init_lic();
    733744#endif
    734 }
    735 
    736 void
    737 NanoVis::read_screen()
    738 {
    739     glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE,
    740                  screen_buffer);
    741745}
    742746
     
    780784
    781785// used internally to build up the BMP file header
    782 // writes an integer value into the header data structure at pos
    783 static void
     786// Writes an integer value into the header data structure at pos
     787static inline void
    784788bmp_header_add_int(unsigned char* header, int& pos, int data)
    785789{
     790#ifdef WORDS_BIGENDIAN
     791    header[pos++] = (data >> 24) & 0xFF;
     792    header[pos++] = (data >> 16) & 0xFF;
     793    header[pos++] = (data >> 8)  & 0xFF;
     794    header[pos++] = (data)       & 0xFF;
     795#else
    786796    header[pos++] = data & 0xff;
    787797    header[pos++] = (data >> 8) & 0xff;
    788798    header[pos++] = (data >> 16) & 0xff;
    789799    header[pos++] = (data >> 24) & 0xff;
     800#endif
    790801}
    791802
     
    793804// FOR DEBUGGING
    794805void
    795 NanoVis::bmp_write_to_file(int frame_number, char* directory_name)
    796 {
    797     unsigned char header[54];
     806NanoVis::bmp_write_to_file(int frame_number, const char *directory_name)
     807{
     808    unsigned char header[SIZEOF_BMP_HEADER];
    798809    int pos = 0;
    799810    header[pos++] = 'B';
     
    808819
    809820    // file size in bytes
    810     int fsize = (3*win_width+pad)*win_height + sizeof(header);
     821    int fsize = (3*win_width+pad)*win_height + SIZEOF_BMP_HEADER;
    811822    bmp_header_add_int(header, pos, fsize);
    812823
     
    815826
    816827    // offset in bytes to start of bitmap data
    817     bmp_header_add_int(header, pos, sizeof(header));
     828    bmp_header_add_int(header, pos, SIZEOF_BMP_HEADER);
    818829
    819830    // size of the BITMAPINFOHEADER
     
    875886        }
    876887    }
    877     fwrite((void*) header, sizeof(header), 1, f);
     888    fwrite((void*) header, SIZEOF_BMP_HEADER, 1, f);
    878889    fwrite((void*) screen_buffer, (3*win_width+pad)*win_height, 1, f);
    879890    fclose(f);
     
    881892
    882893void
    883 NanoVis::bmp_write(const char* cmd)
    884 {
    885     unsigned char header[54];
     894NanoVis::bmp_write(const char *prefix)
     895{
     896    unsigned char header[SIZEOF_BMP_HEADER];
    886897    int pos = 0;
    887     header[pos++] = 'B';
    888     header[pos++] = 'M';
    889898
    890899    // BE CAREFUL:  BMP files must have an even multiple of 4 bytes
     
    894903        pad = 4 - ((3*win_width) % 4);
    895904    }
     905    pad = 0;
     906    int fsize = (3*win_width+pad)*win_height + sizeof(header);
     907
     908    char string[200];
     909    sprintf(string, "%s %d\n", prefix, fsize);
     910    write(0, string, strlen(string));
     911
     912    header[pos++] = 'B';
     913    header[pos++] = 'M';
    896914
    897915    // file size in bytes
    898     int fsize = (3*win_width+pad)*win_height + sizeof(header);
    899916    bmp_header_add_int(header, pos, fsize);
    900917
     
    903920
    904921    // offset in bytes to start of bitmap data
    905     bmp_header_add_int(header, pos, sizeof(header));
     922    bmp_header_add_int(header, pos, SIZEOF_BMP_HEADER);
    906923
    907924    // size of the BITMAPINFOHEADER
     
    944961    }
    945962
    946     std::ostringstream result;
    947     result << cmd << " " << fsize << "\n";
    948     write(0, result.str().c_str(), result.str().size());
    949 
    950     write(0, header, sizeof(header));
     963    write(0, header, SIZEOF_BMP_HEADER);
    951964    write(0, screen_buffer, (3*win_width+pad)*win_height);
    952 
     965}
     966
     967/*
     968 * ppm_write --
     969 *
     970 *      Writes the screen image as PPM binary data to the nanovisviewer
     971 *      client.  The PPM binary format is very simple. 
     972 *
     973 *              P6 w h 255\n
     974 *              3-byte RGB pixel data.
     975 *
     976 *      The nanovisviewer client (using the TkImg library) will do less work
     977 *      to unpack this format, as opposed to BMP or PNG.  (This doesn't
     978 *      eliminate the need to look into DXT compression performed on the GPU).
     979 *
     980 *      Note that currently the image data from the screen is both row-padded
     981 *      and the scan lines are reversed.  This routine could be made even
     982 *      simpler (faster) if the screen buffer is an array of packed 3-bytes
     983 *      per pixels (no padding) and where the origin is the top-left corner.
     984 */
     985void
     986NanoVis::ppm_write(const char *prefix)
     987{
     988#define PPM_MAXVAL 255
     989    char header[200];
     990
     991    // Generate the PPM binary file header
     992    sprintf(header, "P6 %d %d %d\n", win_width, win_height, PPM_MAXVAL);
     993
     994    size_t header_length = strlen(header);
     995    size_t data_length = win_width * win_height * 3;
     996
     997    char command[200];
     998    sprintf(command, "%s %d\n", prefix, header_length + data_length);
     999
     1000    size_t wordsPerRow = (win_width * 24 + 31) / 32;
     1001    size_t bytesPerRow = wordsPerRow * 4;
     1002    size_t rowLength = win_width * 3;
     1003    size_t nRecs = win_height + 2;
     1004
     1005    struct iovec *iov;
     1006    iov = (struct iovec *)malloc(sizeof(struct iovec) * nRecs);
     1007
     1008    // Write the nanovisviewer command, then the image header and data.
     1009    // Command
     1010    iov[0].iov_base = command;
     1011    iov[0].iov_len = strlen(command);
     1012    // Header of image data
     1013    iov[1].iov_base = header;
     1014    iov[1].iov_len = header_length;
     1015    // Image data.
     1016    int y;
     1017    unsigned char *srcRowPtr = screen_buffer;
     1018    for (y = win_height + 1; y >= 2; y--) {
     1019        iov[y].iov_base = srcRowPtr;
     1020        iov[y].iov_len = rowLength;
     1021        srcRowPtr += bytesPerRow;
     1022    }
     1023    writev(0, iov, nRecs);
     1024    free(iov);
    9531025}
    9541026
     
    10221094}
    10231095
    1024 void
    1025 NanoVis::offscreen_buffer_capture()
    1026 {
    1027     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
    1028 }
    1029 
    1030 #ifdef notdef
    1031 /*
    1032  * Is this routine being used? --gah
    1033  */
    1034 void
    1035 draw_bounding_box(float x0, float y0, float z0,
    1036                   float x1, float y1, float z1,
    1037                   float r, float g, float b, float line_width)
    1038 {
    1039     glDisable(GL_TEXTURE_2D);
    1040     glColor4d(r, g, b, 1.0);
    1041     glLineWidth(line_width);
    1042     glBegin(GL_LINE_LOOP);
    1043     {
    1044         glVertex3d(x0, y0, z0);
    1045         glVertex3d(x1, y0, z0);
    1046         glVertex3d(x1, y1, z0);
    1047         glVertex3d(x0, y1, z0);
    1048     }
    1049     glEnd();
    1050     glBegin(GL_LINE_LOOP);
    1051     {
    1052         glVertex3d(x0, y0, z1);
    1053         glVertex3d(x1, y0, z1);
    1054         glVertex3d(x1, y1, z1);
    1055         glVertex3d(x0, y1, z1);
    1056     }
    1057     glEnd();
    1058     glBegin(GL_LINE_LOOP);
    1059     {
    1060         glVertex3d(x0, y0, z0);
    1061         glVertex3d(x0, y0, z1);
    1062         glVertex3d(x0, y1, z1);
    1063         glVertex3d(x0, y1, z0);
    1064     }
    1065     glEnd();
    1066     glBegin(GL_LINE_LOOP);
    1067     {
    1068         glVertex3d(x1, y0, z0);
    1069         glVertex3d(x1, y0, z1);
    1070         glVertex3d(x1, y1, z1);
    1071         glVertex3d(x1, y1, z0);
    1072     }
    1073     glEnd();
    1074     glEnable(GL_TEXTURE_2D);
    1075 }
    1076 #endif
    1077 
    10781096
    10791097#ifdef notdef
     
    10911109void soft_read_verts()
    10921110{
    1093     glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, vert);
     1111    glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT,
     1112                 vert);
    10941113    //fprintf(stderr, "soft_read_vert");
    10951114   
     
    15421561        glEnable(GL_TEXTURE_2D);
    15431562        glEnable(GL_DEPTH_TEST);
    1544        
     1563
    15451564        //camera setting activated
    15461565        cam->activate();
     
    18741893main(int argc, char** argv)
    18751894{
    1876 
    18771895    char *path;
    18781896    path = NULL;
  • trunk/packages/vizservers/nanovis/nanovis.h

    r973 r1028  
    101101
    102102class NanoVis {
     103    //frame buffer for final rendering
     104    static NVISid final_fbo, final_color_tex, final_depth_rb;
    103105public:
    104106    static VolumeRenderer* vol_renderer;
     
    139141    static bool vector_on;
    140142
     143
    141144    static TransferFunction* get_transfunc(const char *name);
    142145    static TransferFunction* DefineTransferFunction(const char *name,
     
    150153    static void initParticle();
    151154    static void resize_offscreen_buffer(int w, int h);
    152     static void offscreen_buffer_capture(void);
    153     static void bmp_write(const char* cmd);
    154     static void bmp_write_to_file(int frame_number, char* directory_name);
     155    static void ppm_write(const char *prefix);
     156    static void bmp_write(const char *prefix);
     157    static void bmp_write_to_file(int frame_number, const char* directory_name);
    155158    static void display(void);
    156159    static void update(void);
    157160    static void display_offscreen_buffer();
    158     static void read_screen();
    159161    static void zoom(double zoom);
    160162    static int render_legend(TransferFunction *tf, double min, double max,
     
    169171    static void update_trans(int delta_x, int delta_y, int delta_z);
    170172#endif
     173
     174    static void read_screen(void) {
     175        glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE,
     176                     screen_buffer);
     177    }
     178    static void offscreen_buffer_capture(void) {
     179        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
     180    }
    171181};
    172182
Note: See TracChangeset for help on using the changeset viewer.