Changeset 2831


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

Refactor texture classes, misc. cleanups, cut down on header pollution -- still
need to fix header deps in Makefile.in

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

Legend:

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

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2#include <string.h>
     3
    24#include <tcl.h>
     5
    36#include "CmdProc.h"
    4 #include <string.h>
    57
    68/*
  • trunk/packages/vizservers/nanovis/CmdProc.h

    r2798 r2831  
    4646#define CMDSPEC_BINARY_SEARCH   0
    4747
    48 extern Tcl_ObjCmdProc *GetOpFromObj(Tcl_Interp *interp, int nSpecs,
    49         CmdSpec *specs, int operPos, int objc, Tcl_Obj *const *objv, int flags);
     48extern Tcl_ObjCmdProc *
     49GetOpFromObj(Tcl_Interp *interp, int nSpecs,
     50             CmdSpec *specs, int operPos, int objc, Tcl_Obj *const *objv, int flags);
    5051
    5152#define NumCmdSpecs(s) (sizeof(s) / sizeof(Rappture::CmdSpec))
     
    5354}
    5455
    55 
    5656#endif /* CMDSPEC_H */
  • trunk/packages/vizservers/nanovis/Command.cpp

    r2828 r2831  
    2424/*
    2525 * TODO:  In no particular order...
    26  *        x Convert to Tcl_CmdObj interface. (done)
    2726 *        o Use Tcl command option parser to reduce size of procedures, remove
    2827 *          lots of extra error checking code. (almost there)
     
    3332 *          the vector. 1) Use a list instead of a vector. 2) carry
    3433 *          an id field that's a number that gets incremented each new volume.
    35  *        x Create R2, matrix, etc. libraries. (done)
    3634 *        o Add bookkeeping for volumes, heightmaps, flows, etc. to track
    3735 *          1) id #  2) simulation # 3) include/exclude.  The include/exclude
     
    4038 */
    4139
    42 
    43 
    4440#include <assert.h>
    4541#include <stdlib.h>
     42
    4643#include <tcl.h>
    4744
     
    5350#include <RpBuffer.h>
    5451
    55 #include "Trace.h"
    5652#include "nanovis.h"
    5753#include "CmdProc.h"
    58 #include "PointSetRenderer.h"
    59 #include "PointSet.h"
    60 #include "ZincBlendeVolume.h"
    61 #include "NvColorTableRenderer.h"
    62 #include "NvEventLog.h"
     54#include "Trace.h"
     55
     56#if PLANE_CMD
     57#include "PlaneRenderer.h"
     58#endif
     59#include "Grid.h"
     60#include "HeightMap.h"
     61#include "NvCamera.h"
    6362#include "NvZincBlendeReconstructor.h"
    64 #include "VolumeInterpolator.h"
    65 #include "HeightMap.h"
    66 #include "Grid.h"
    67 #include "NvCamera.h"
    68 #include "RenderContext.h"
    69 #include "NvLIC.h"
    7063#include "Unirect.h"
    71 
    72 #define PLANE_CMD               0
    73 
    74 // EXTERN DECLARATIONS
    75 // in Nv.cpp
    76 
    77 // in nanovis.cpp
    78 extern std::vector<PointSet*> g_pointSet;
    79 
    80 extern PlaneRenderer* plane_render;
    81 extern Texture2D* plane[10];
    82 
    83 // Tcl interpreter for incoming messages
     64#include "VelocityArrowsSlice.h"
     65#include "VolumeRenderer.h"
    8466
    8567// default transfer function
     
    15061488               tfPtr->name());
    15071489        (*iter)->transferFunction(tfPtr);
    1508 #ifdef POINTSET
     1490#ifdef USE_POINTSET_RENDERER
    15091491        // TBD..
    1510         // POINTSET
    1511         if ((*iter)->pointsetIndex != -1) {
    1512             g_pointSet[(*iter)->pointsetIndex]->updateColor(tf->getData(), 256);
    1513         }
    1514 #endif /*POINTSET*/
     1492 //        if ((*iter)->pointsetIndex != -1) {
     1493//             NanoVis::pointSet[(*iter)->pointsetIndex]->updateColor(tf->getData(), 256);
     1494//         }
     1495#endif
    15151496    }
    15161497    return TCL_OK;
     
    20131994
    20141995static Rappture::CmdSpec heightMapOps[] = {
    2015     {"create",       2, HeightMapCreateOp,      10, 10,
    2016      "tag xmin ymin xmax ymax xnum ynum values",},
     1996    {"create",       2, HeightMapCreateOp,      10, 10, "tag xmin ymin xmax ymax xnum ynum values",},
    20171997    {"cull",         2, HeightMapCullOp,        3, 3, "mode",},
    20181998    {"data",         1, HeightMapDataOp,        3, 0, "oper ?args?",},
     
    21932173    //Now read w*h*4 bytes. The server expects the plane to be a stream of
    21942174    //floats
    2195     char* tmp = new char[int(w*h*sizeof(float))];
     2175    char *tmp = new char[int(w*h*sizeof(float))];
    21962176    if (tmp == NULL) {
    21972177        Tcl_AppendResult(interp, "can't allocate stream data", (char *)NULL);
     
    22042184                                // error and return a non-zero exit status.
    22052185    }
    2206     plane[index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp);
     2186    NanoVis::plane[index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp);
    22072187    delete[] tmp;
    22082188    return TCL_OK;
    22092189}
    2210 
    22112190
    22122191static int
     
    22292208        return TCL_ERROR;
    22302209    }
    2231     //plane_render->add_plane(plane[plane_index], tf[tf_index]);
     2210    //NanoVis::plane_renderer->add_plane(NanoVis::plane[plane_index], tf[tf_index]);
    22322211    return TCL_OK;
    22332212}
     
    22572236        plane_index = -1;
    22582237    }
    2259     plane_render->set_active_plane(plane_index);
     2238    NanoVis::plane_renderer->set_active_plane(plane_index);
    22602239    return TCL_OK;
    22612240}
     
    23282307initTcl()
    23292308{
    2330 
    23312309    /*
    23322310     * Ideally the connection is authenticated by nanoscale.  I still like the
     
    23502328    Tcl_CreateObjCommand(interp, "heightmap",   HeightMapCmd,   NULL, NULL);
    23512329    Tcl_CreateObjCommand(interp, "legend",      LegendCmd,      NULL, NULL);
     2330#if PLANE_CMD
     2331    Tcl_CreateObjCommand(interp, "plane",       PlaneCmd,       NULL, NULL);
     2332#endif
    23522333    Tcl_CreateObjCommand(interp, "screen",      ScreenCmd,      NULL, NULL);
    23532334    Tcl_CreateObjCommand(interp, "snapshot",    SnapshotCmd,    NULL, NULL);
  • trunk/packages/vizservers/nanovis/FlowCmd.cpp

    r2822 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #include <nvconf.h>
    3 #if defined(HAVE_LIBAVCODEC) || defined(HAVE_LIBAVFORMAT)
    4 #define HAVE_FFMPEG 1
    5 #endif
    62
    73#include <assert.h>
     
    117#include <stdint.h>
    128#include <poll.h>
     9
    1310#include <tcl.h>
    14 #include "Switch.h"
     11
    1512#include <RpField1D.h>
    1613#include <RpFieldRect3D.h>
    1714#include <RpFieldPrism3D.h>
    1815#include <RpOutcome.h>
     16
     17#include "nvconf.h"
     18
     19#if defined(HAVE_LIBAVCODEC) || defined(HAVE_LIBAVFORMAT)
     20#define HAVE_FFMPEG 1
     21#endif
     22
    1923#ifdef HAVE_FFMPEG
    20 #include <RpAVTranslate.h>
     24#include "RpAVTranslate.h"
    2125#endif
     26
     27#include "nanovis.h"
     28#include "FlowCmd.h"
     29#include "CmdProc.h"
     30#include "Switch.h"
     31#include "TransferFunction.h"
     32#include "NvLIC.h"
    2233#include "Trace.h"
    23 #include "TransferFunction.h"
    24 
    25 #include "nanovis.h"
    26 #include "CmdProc.h"
    27 
    28 #include "NvLIC.h"
    29 
    3034#include "Unirect.h"
    31 #include "FlowCmd.h"
     35#include "VelocityArrowsSlice.h"
    3236
    3337#define RELPOS 0
  • trunk/packages/vizservers/nanovis/FlowCmd.h

    r2798 r2831  
    2222 * ======================================================================
    2323 */
     24#ifndef FLOWCMD_H
     25#define FLOWCMD_H
     26
     27#include <tcl.h>
     28
     29#include "Switch.h"
     30#include "NvLIC.h"
     31#include "NvParticleRenderer.h"
     32#include "NvVectorField.h"
     33#include "Unirect.h"
     34#include "Volume.h"
    2435
    2536struct FlowColor {
     
    5162};
    5263
    53 class FlowParticles {
     64class FlowParticles
     65{
     66public:
     67    FlowParticles(const char *name, Tcl_HashEntry *hPtr);
     68
     69    ~FlowParticles();
     70
     71    const char *name()
     72    {
     73        return _name;
     74    }
     75
     76    void disconnect()
     77    {
     78        _hashPtr = NULL;
     79    }
     80
     81    bool visible()
     82    {
     83        return !_sv.isHidden;
     84    }
     85
     86    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
     87    {
     88        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
     89                                    SWITCH_DEFAULTS) < 0) {
     90            return TCL_ERROR;
     91        }
     92        return TCL_OK;
     93    }
     94
     95    void Advect()
     96    {
     97        assert(_rendererPtr->active());
     98        _rendererPtr->advect();
     99    }
     100
     101    void Render();
     102
     103    void Reset()
     104    {
     105        _rendererPtr->reset();
     106    }
     107
     108    void Initialize()
     109    {
     110        _rendererPtr->initialize();
     111    }
     112
     113    void SetVectorField(Volume *volPtr)
     114    {
     115        _rendererPtr->
     116            setVectorField(volPtr->id,
     117                           volPtr->location(),
     118                           1.0f,
     119                           volPtr->height / (float)volPtr->width,
     120                           volPtr->depth  / (float)volPtr->width,
     121                           volPtr->wAxis.max());
     122    }
     123
     124    void Configure();
     125
     126private:
    54127    const char *_name;                  /* Name of particle injection
    55128                                         * plane. Actual character string is
     
    60133
    61134    static Rappture::SwitchSpec _switches[];
    62 public:
    63 
    64     FlowParticles(const char *name, Tcl_HashEntry *hPtr);
    65     ~FlowParticles(void);
    66     const char *name(void) {
    67         return _name;
    68     }
    69     void disconnect(void) {
    70         _hashPtr = NULL;
    71     }
    72     bool visible(void) {
    73         return !_sv.isHidden;
    74     }
    75     int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) {
    76         if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
    77                 SWITCH_DEFAULTS) < 0) {
    78             return TCL_ERROR;
    79         }
    80         return TCL_OK;
    81     }
    82     void Advect(void) {
    83         assert(_rendererPtr->active());
    84         _rendererPtr->advect();
    85     }
    86     void Render(void);
    87     void Reset(void) {
    88         _rendererPtr->reset();
    89     }
    90     void Initialize(void) {
    91         _rendererPtr->initialize();
    92     }
    93     void SetVectorField(Volume *volPtr) {
    94         _rendererPtr->setVectorField(volPtr->id,
    95             volPtr->location(),
    96             1.0f,
    97             volPtr->height / (float)volPtr->width,
    98             volPtr->depth  / (float)volPtr->width,
    99             volPtr->wAxis.max());
    100     }
    101     void Configure(void);
    102135};
    103136
     
    118151};
    119152
    120 class FlowBox {
     153class FlowBox
     154{
     155public:
     156    FlowBox(const char *name, Tcl_HashEntry *hPtr);
     157
     158    ~FlowBox()
     159    {
     160        Rappture::FreeSwitches(_switches, &_sv, 0);
     161        if (_hashPtr != NULL) {
     162            Tcl_DeleteHashEntry(_hashPtr);
     163        }
     164    }
     165
     166    const char *name()
     167    {
     168        return _name;
     169    }
     170
     171    bool visible()
     172    {
     173        return !_sv.isHidden;
     174    }
     175
     176    void disconnect()
     177    {
     178        _hashPtr = NULL;
     179    }
     180
     181    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
     182    {
     183        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
     184                                    SWITCH_DEFAULTS) < 0) {
     185            return TCL_ERROR;
     186        }
     187        return TCL_OK;
     188    }
     189
     190    void Render(Volume *volPtr);
     191
     192private:
    121193    const char *_name;                  /* Name of this box in the hash
    122194                                         * table. */
     
    125197    FlowBoxValues _sv;
    126198    static Rappture::SwitchSpec _switches[];
    127 public:
    128 
    129     FlowBox(const char *name, Tcl_HashEntry *hPtr);
    130     ~FlowBox(void) {
    131         Rappture::FreeSwitches(_switches, &_sv, 0);
    132         if (_hashPtr != NULL) {
    133             Tcl_DeleteHashEntry(_hashPtr);
    134         }
    135     }
    136     const char *name(void) {
    137         return _name;
    138     }
    139     bool visible(void) {
    140         return !_sv.isHidden;
    141     }
    142     void disconnect(void) {
    143         _hashPtr = NULL;
    144     }
    145     int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) {
    146         if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
    147                 SWITCH_DEFAULTS) < 0) {
    148             return TCL_ERROR;
    149         }
    150         return TCL_OK;
    151     }
    152     void Render(Volume *volPtr);
     199
    153200};
    154201
     
    172219};
    173220
    174 class FlowCmd {
     221class FlowCmd
     222{
     223public:
     224    enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z };
     225
     226    FlowCmd(Tcl_Interp *interp, const char *name, Tcl_HashEntry *hPtr);
     227
     228    ~FlowCmd();
     229
     230    int CreateParticles(Tcl_Interp *interp, Tcl_Obj *objPtr);
     231
     232    int GetParticles(Tcl_Interp *interp, Tcl_Obj *objPtr,
     233                     FlowParticles **particlePtrPtr);
     234
     235    void Render();
     236
     237    void Advect();
     238
     239    void ResetParticles();
     240
     241    void InitializeParticles();
     242
     243    FlowParticles *FirstParticles(FlowParticlesIterator *iterPtr);
     244
     245    FlowParticles *NextParticles(FlowParticlesIterator *iterPtr);
     246
     247    int CreateBox(Tcl_Interp *interp, Tcl_Obj *objPtr);
     248
     249    int GetBox(Tcl_Interp *interp, Tcl_Obj *objPtr, FlowBox **boxPtrPtr);
     250
     251    FlowBox *FirstBox(FlowBoxIterator *iterPtr);
     252
     253    FlowBox *NextBox(FlowBoxIterator *iterPtr);
     254
     255    float *GetScaledVector();
     256
     257    Volume *MakeVolume(float *data);
     258   
     259    void InitVectorField();
     260
     261    NvVectorField *VectorField()
     262    {
     263        return _fieldPtr;
     264    }
     265
     266    bool ScaleVectorField();
     267
     268    bool visible()
     269    {
     270        return !_sv.isHidden;
     271    }
     272
     273    const char *name()
     274    {
     275        return _name;
     276    }
     277
     278    void disconnect()
     279    {
     280        _hashPtr = NULL;
     281    }
     282
     283    bool isDataLoaded()
     284    {
     285        return (_dataPtr != NULL);
     286    }
     287
     288    Rappture::Unirect3d *data()
     289    {
     290        return _dataPtr;
     291    }
     292
     293    void data(Rappture::Unirect3d *dataPtr)
     294    {
     295        if (_dataPtr != NULL) {
     296            delete _dataPtr;
     297        }
     298        _dataPtr = dataPtr;
     299    }
     300
     301    void ActivateSlice()
     302    {
     303        /* Must set axis before offset or position goes to wrong axis. */
     304        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
     305        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
     306        NanoVis::licRenderer->active(true);
     307    }
     308
     309    void DeactivateSlice()
     310    {
     311        NanoVis::licRenderer->active(false);
     312    }
     313
     314    SliceAxis GetAxis()
     315    {
     316        return (SliceAxis)_sv.slicePos.axis;
     317    }
     318
     319    TransferFunction *GetTransferFunction()
     320    {
     321        return _sv.tfPtr;
     322    }
     323
     324    float GetRelativePosition();
     325
     326    void SetAxis()
     327    {
     328        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
     329    }
     330
     331    void SetAxis(FlowCmd::SliceAxis axis)
     332    {
     333        _sv.slicePos.axis = axis;
     334        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
     335    }
     336
     337    void SetCurrentPosition(float position)
     338    {
     339        _sv.slicePos.value = position;
     340        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
     341    }
     342
     343    void SetCurrentPosition()
     344    {
     345        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
     346    }
     347
     348    void SetActive(bool state)
     349    {
     350        _sv.sliceVisible = state;
     351        NanoVis::licRenderer->active(state);
     352    }
     353
     354    void SetActive()
     355    {
     356        NanoVis::licRenderer->active(_sv.sliceVisible);
     357    }
     358
     359    void SetVectorField(NvVectorField *fieldPtr)
     360    {
     361        DeleteVectorField();
     362        _fieldPtr = fieldPtr;
     363    }
     364
     365    void DeleteVectorField()
     366    {
     367        if (_fieldPtr != NULL) {
     368            delete _fieldPtr;
     369            _fieldPtr = NULL;
     370        }
     371    }
     372
     373    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
     374    {
     375        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
     376                                    SWITCH_DEFAULTS) < 0) {
     377            return TCL_ERROR;
     378        }
     379        return TCL_OK;
     380    }
     381
     382    static float GetRelativePosition(FlowPosition *posPtr);
     383
     384    static Rappture::SwitchSpec videoSwitches[];
     385
     386private:
     387    void Configure();
     388
     389    void RenderBoxes();
     390
    175391    Tcl_Interp *_interp;
    176392    Tcl_HashEntry *_hashPtr;
     
    203419                                         * with each field. */
    204420
    205     void Configure(void);
    206 
    207421    static Rappture::SwitchSpec _switches[];
    208422    FlowValues _sv;
    209 
    210     void RenderBoxes(void);
    211 public:
    212     static Rappture::SwitchSpec videoSwitches[];
    213     enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z };
    214     FlowCmd(Tcl_Interp *interp, const char *name, Tcl_HashEntry *hPtr);
    215     ~FlowCmd(void);
    216 
    217     int CreateParticles(Tcl_Interp *interp, Tcl_Obj *objPtr);
    218     int GetParticles(Tcl_Interp *interp, Tcl_Obj *objPtr,
    219                      FlowParticles **particlePtrPtr);
    220     void Render(void);
    221     void Advect(void);
    222     void ResetParticles(void);
    223     void InitializeParticles(void);
    224 
    225     FlowParticles *FirstParticles(FlowParticlesIterator *iterPtr);
    226     FlowParticles *NextParticles(FlowParticlesIterator *iterPtr);
    227 
    228     int CreateBox(Tcl_Interp *interp, Tcl_Obj *objPtr);
    229     int GetBox(Tcl_Interp *interp, Tcl_Obj *objPtr, FlowBox **boxPtrPtr);
    230     FlowBox *FirstBox(FlowBoxIterator *iterPtr);
    231     FlowBox *NextBox(FlowBoxIterator *iterPtr);
    232 
    233     float *GetScaledVector(void);
    234     Volume *MakeVolume(float *data);
    235    
    236     void InitVectorField(void);
    237 
    238     NvVectorField *VectorField(void) {
    239         return _fieldPtr;
    240     }
    241 
    242     bool ScaleVectorField(void);
    243 
    244     bool visible(void) {
    245         return !_sv.isHidden;
    246     }
    247     const char *name(void) {
    248         return _name;
    249     }
    250     void disconnect(void) {
    251         _hashPtr = NULL;
    252     }
    253     bool isDataLoaded(void) {
    254         return (_dataPtr != NULL);
    255     }
    256     Rappture::Unirect3d *data(void) {
    257         return _dataPtr;
    258     }
    259     void data(Rappture::Unirect3d *dataPtr) {
    260         if (_dataPtr != NULL) {
    261             delete _dataPtr;
    262         }
    263         _dataPtr = dataPtr;
    264     }
    265     void ActivateSlice(void) {
    266         /* Must set axis before offset or position goes to wrong axis. */
    267         NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
    268         NanoVis::licRenderer->set_offset(_sv.slicePos.value);
    269         NanoVis::licRenderer->active(true);
    270     }
    271     void DeactivateSlice(void) {
    272         NanoVis::licRenderer->active(false);
    273     }
    274     SliceAxis GetAxis(void) {
    275         return (SliceAxis)_sv.slicePos.axis;
    276     }
    277     TransferFunction *GetTransferFunction(void) {
    278         return _sv.tfPtr;
    279     }
    280     float GetRelativePosition(void);
    281     void SetAxis(void) {
    282         NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
    283     }
    284     void SetAxis(FlowCmd::SliceAxis axis) {
    285         _sv.slicePos.axis = axis;
    286         NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
    287     }
    288     void SetCurrentPosition(float position) {
    289         _sv.slicePos.value = position;
    290         NanoVis::licRenderer->set_offset(_sv.slicePos.value);
    291     }
    292     void SetCurrentPosition(void) {
    293         NanoVis::licRenderer->set_offset(_sv.slicePos.value);
    294     }
    295     void SetActive(bool state) {
    296         _sv.sliceVisible = state;
    297         NanoVis::licRenderer->active(state);
    298     }
    299     void SetActive(void) {
    300         NanoVis::licRenderer->active(_sv.sliceVisible);
    301     }
    302     void SetVectorField(NvVectorField *fieldPtr) {
    303         DeleteVectorField();
    304         _fieldPtr = fieldPtr;
    305     }
    306     void DeleteVectorField(void) {
    307         if (_fieldPtr != NULL) {
    308             delete _fieldPtr;
    309             _fieldPtr = NULL;
    310         }
    311     }
    312     int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) {
    313         if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
    314                 SWITCH_DEFAULTS) < 0) {
    315             return TCL_ERROR;
    316         }
    317         return TCL_OK;
    318     }
    319     static float GetRelativePosition(FlowPosition *posPtr);
    320423};
    321424
    322425extern int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes);
    323426
    324 extern int GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    325         bool *boolPtr);
    326 extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    327         float *floatPtr);
    328 extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    329         int *axisPtr);
    330 extern int GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    331         Volume **volumePtrPtr);
    332 
    333 
     427extern int GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
     428                             bool *boolPtr);
     429
     430extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
     431                           float *floatPtr);
     432
     433extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
     434                          int *axisPtr);
     435
     436extern int GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
     437                            Volume **volumePtrPtr);
     438
     439#endif
  • trunk/packages/vizservers/nanovis/HeightMap.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef _HEIGHT_MAP_H_
    3 #define _HEIGHT_MAP_H_
     2#ifndef HEIGHTMAP_H
     3#define HEIGHTMAP_H
    44
    55#include <Cg/cgGL.h>
    66#include <Cg/cg.h>
     7
    78#include <R2/graphics/R2Geometry.h>
     9
    810#include "TransferFunction.h"
    911#include "NvShader.h"
    1012#include "Vector3.h"
    11 #include <RenderContext.h>
     13#include "RenderContext.h"
    1214#include "AxisRange.h"
    1315
     
    2224 *@brief Create a surface from height map and line contour of the generated surface
    2325 */
     26class HeightMap
     27{
     28public:
     29    HeightMap();
    2430
    25 class HeightMap {
     31    ~HeightMap();
     32
     33    void render(graphics::RenderContext *renderContext);
     34
     35    void render_topview(graphics::RenderContext *renderContext,
     36                        int render_width, int render_height);
     37
     38    /**
     39     *@brief Create a height map with heigh values
     40     *@param startX a x position of the first height value
     41     *@param startY a y position of the first height value
     42     *@param endX a x position of the last height value
     43     *@param endY a y position of the last height value
     44     *@param xCount the number of columns of height values
     45     *@param yCount the number of rows of height values
     46     *@param height a pointer value adrressing xCount * yCount values of heights
     47     */
     48    void setHeight(float startX, float startY, float endX, float endY,
     49                   int xCount, int yCount, float *height);
     50
     51    /**
     52     *@brief Create a height map with a set of points
     53     *@param xCount the number of columns of height values
     54     *@param yCount the number of rows of height values
     55     */
     56    void setHeight(int xCount, int yCount, Vector3 *heights);
     57
     58    void MapToGrid(Grid *gridPtr);
     59
     60    /**
     61     *@brief Define a color map for color shading of heightmap
     62     */
     63    void transferFunction(TransferFunction *tfPtr)
     64    {
     65        _tfPtr = tfPtr;
     66    }
     67
     68    /**
     69     *@brief Get the color map defined for shading of this heightmap
     70     */
     71    TransferFunction *transferFunction()
     72    {
     73        return _tfPtr;
     74    }
     75
     76    /**
     77     *@brief Set the visibility of the height map
     78     */
     79    void setVisible(bool visible)
     80    {
     81        _visible = visible;
     82    }
     83
     84    /**
     85     *@brief Return the status of the visibility
     86     */
     87    bool isVisible() const
     88    {
     89        return _visible;
     90    }
     91
     92    /**
     93     *@brief Set the visibility of the line contour
     94     */
     95    void setLineContourVisible(bool visible)
     96    {
     97        _contourVisible = visible;
     98    }
     99
     100    void setTopLineContourVisible(bool visible)
     101    {
     102        _topContourVisible = visible;
     103    }
     104
     105    void opacity(float opacity)
     106    {
     107        _opacity = opacity;
     108    }
     109
     110    float opacity()
     111    {
     112        return _opacity;
     113    }
     114
     115    /**
     116     *@brief Defind the color of the line contour
     117     */
     118    void setLineContourColor(float *rgb)
     119    {
     120        _contourColor.x = rgb[0];
     121        _contourColor.y = rgb[1];
     122        _contourColor.z = rgb[2];
     123    }
     124
     125    AxisRange xAxis, yAxis, zAxis, wAxis;
     126    static bool update_pending;
     127    static double valueMin, valueMax;
     128
     129private:
     130    void createIndexBuffer(int xCount, int zCount, float* heights);
     131    Vector3 *createHeightVertices(float startX, float startY,
     132                                  float endX, float endY,
     133                                  int xCount, int yCount, float  *height);
     134    void reset();
     135
    26136    unsigned int _vertexBufferObjectID;
    27137    unsigned int _textureBufferObjectID;
     
    29139    CGparameter _tfParam;
    30140    CGparameter _opacityParam;
    31     R2Geometry* _contour;
    32     R2Geometry* _topContour;
    33     TransferFunction* _tfPtr;
     141    R2Geometry *_contour;
     142    R2Geometry *_topContour;
     143    TransferFunction *_tfPtr;
    34144    float _opacity;
    35     NvShader* _shader;
     145    NvShader *_shader;
    36146    int *_indexBuffer;
    37147    int _indexCount;
     
    47157    float *_heights;            // Array of original (unscaled) heights
    48158                                // (y-values)
    49 public :
    50     AxisRange xAxis, yAxis, zAxis, wAxis;
    51     static bool update_pending;
    52     static double valueMin, valueMax;
    53 
    54     /**
    55      *@brief Constructor
    56      */
    57     HeightMap();
    58     /**
    59      *@brief Destructor
    60      */
    61     ~HeightMap();
    62 
    63 private :
    64     void createIndexBuffer(int xCount, int zCount, float* heights);
    65         Vector3* createHeightVertices(float startX, float startY, float endX, float endY, int xCount, int yCount, float* height);
    66         void reset();
    67 public :
    68     void render(graphics::RenderContext* renderContext);
    69     void render_topview(graphics::RenderContext* renderContext, int render_width, int render_height);
    70     /**
    71      *@brief Create a height map with heigh values
    72      *@param startX a x position of the first height value
    73      *@param startY a y position of the first height value
    74      *@param endX a x position of the last height value
    75      *@param endY a y position of the last height value
    76      *@param xCount the number of columns of height values
    77      *@param yCount the number of rows of height values
    78      *@param height a pointer value adrressing xCount * yCount values of heights
    79      */
    80     void setHeight(float startX, float startY, float endX, float endY,
    81                    int xCount, int yCount, float* height);
    82 
    83     /**
    84      *@brief Create a height map with a set of points
    85      *@param xCount the number of columns of height values
    86      *@param yCount the number of rows of height values
    87      */
    88     void setHeight(int xCount, int yCount, Vector3* heights);
    89 
    90     void MapToGrid(Grid *gridPtr);
    91     /**
    92      *@brief Define a color map for color shading of heightmap
    93      */
    94     void transferFunction(TransferFunction* tfPtr) {
    95         _tfPtr = tfPtr;
    96     }
    97     /**
    98      *@brief Get the color map defined for shading of this heightmap
    99      */
    100     TransferFunction *transferFunction(void) {
    101         return _tfPtr;
    102     }
    103     /**
    104      *@brief Set the visibility of the height map
    105      */
    106     void setVisible(bool visible) {
    107         _visible = visible;
    108     }
    109 
    110     /**
    111      *@brief Return the status of the visibility
    112      */
    113     bool isVisible() const {
    114         return _visible;
    115     }
    116     /**
    117      *@brief Set the visibility of the line contour
    118      */
    119     void setLineContourVisible(bool visible) {
    120         _contourVisible = visible;
    121     }
    122 
    123     void setTopLineContourVisible(bool visible) {
    124             _topContourVisible = visible;
    125     }
    126 
    127     void opacity(float opacity) {
    128         _opacity = opacity;
    129     }
    130     float opacity(void) {
    131         return _opacity;
    132     }
    133     /**
    134      *@brief Defind the color of the line contour
    135      */
    136     void setLineContourColor(float *rgb) {
    137         _contourColor.x = rgb[0];
    138         _contourColor.y = rgb[1];
    139         _contourColor.z = rgb[2];
    140     }
    141159};
    142160
  • trunk/packages/vizservers/nanovis/NvColorTableShader.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    22#include <R2/R2FilePath.h>
     3
    34#include "NvColorTableShader.h"
    4 #include <Trace.h>
    5 #include <global.h>
     5#include "Trace.h"
     6#include "global.h"
    67
    78NvColorTableShader::NvColorTableShader()
  • trunk/packages/vizservers/nanovis/NvFlowVisRenderer.cpp

    r2798 r2831  
    2121
    2222#include <R2/R2FilePath.h>
     23
    2324#include "NvFlowVisRenderer.h"
    2425#include "NvVectorField.h"
    25 #include <Trace.h>
    26 
     26#include "Trace.h"
    2727
    2828#define NV_32
  • trunk/packages/vizservers/nanovis/NvLIC.cpp

    r2798 r2831  
    1414 * ======================================================================
    1515 */
    16 
    17 
    1816#include <stdlib.h>
    1917#include <math.h>
     
    2119
    2220#include <R2/R2FilePath.h>
     21
    2322#include "NvLIC.h"
    24 #include <Trace.h>
     23#include "Trace.h"
    2524#include "global.h"
    2625
  • trunk/packages/vizservers/nanovis/NvParticleAdvectionShader.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    22#include <R2/R2FilePath.h>
    3 #include <Trace.h>
     3
    44#include "NvParticleAdvectionShader.h"
    5 #include <global.h>
     5#include "Trace.h"
     6#include "global.h"
    67
    78NvParticleAdvectionShader::NvParticleAdvectionShader() :
  • trunk/packages/vizservers/nanovis/NvParticleRenderer.cpp

    r2798 r2831  
    1919#include <malloc.h>
    2020#include <string.h>
     21#include <stdlib.h>
    2122
    2223#include <R2/R2FilePath.h>
     24
    2325#include "NvParticleRenderer.h"
    24 #include <Trace.h>
    25 #include <stdlib.h>
     26#include "Trace.h"
    2627
    2728#define NV_32
  • trunk/packages/vizservers/nanovis/NvRegularVolumeShader.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    22#include "NvRegularVolumeShader.h"
    3 #include <global.h>
     3#include "global.h"
    44
    55NvRegularVolumeShader::NvRegularVolumeShader()
  • trunk/packages/vizservers/nanovis/ParticleSystem.cpp

    r2818 r2831  
    77#include <pthread.h>
    88
    9 #ifdef _WIN32
    10 #include <GL/glaux.h>
    11 #else
    129#ifdef HAVE_OPENCV_H
    1310#include <opencv/cv.h>
     
    1512#ifdef HAVE_OPENCV_HIGHGUI_H
    1613#include <opencv/highgui.h>
    17 #endif
    1814#endif
    1915
     
    318314    _arrows->setWrapT(TW_MIRROR);
    319315
    320 #ifdef _WIN32
    321 #ifndef USE_RGBA_ARROW
    322     std::string path = vrFilePath::getInstance()->getPath("arrows.bmp");
    323     AUX_RGBImageRec *pTextureImage = auxDIBImageLoad(path.c_str());
    324     _arrows->setPixels(CF_RGB, DT_UBYTE, pTextureImage->sizeX, pTextureImage->sizeY, (void*) pTextureImage->data);
    325 #else
    326     std::string path = vrFilePath::getInstance()->getPath("arrows_red_bg.bmp");
    327     AUX_RGBImageRec *pTextureImage = auxDIBImageLoad(path.c_str());
    328     unsigned char* pixels = new unsigned char [pTextureImage->sizeX * pTextureImage->sizeY * sizeof(unsigned char) * 4];
    329     unsigned char* srcPixels = pTextureImage->data;
    330     unsigned char* dstPixels = pixels;
    331     for (int i = 0; i < pTextureImage->sizeX * pTextureImage->sizeY; ++i) {
    332         *dstPixels = *srcPixels; ++srcPixels;
    333         *(dstPixels + 1) = *srcPixels; ++srcPixels;
    334         *(dstPixels + 2) = *srcPixels; ++srcPixels;
    335 
    336         if ((*dstPixels > 127) && (*(dstPixels + 1) < 127) && (*(dstPixels + 2) < 127)) {
    337             *(dstPixels + 3) = 0;
    338         } else {
    339             *(dstPixels + 3) = 255;
    340         }
    341 
    342         dstPixels += 4;
    343     }
    344     _arrows->setPixels(CF_RGBA, DT_UBYTE, pTextureImage->sizeX, pTextureImage->sizeY, (void*) pixels);
    345 #endif
    346 
    347 #else
    348316#ifndef USE_RGBA_ARROW
    349317    IplImage* pTextureImage = cvLoadImage("arrows_flip2.png");
    350     _arrows->setPixels(CF_RGB, DT_UBYTE, pTextureImage->width, pTextureImage->height, (void*) pTextureImage->imageData);
     318    _arrows->setPixels(CF_RGB, DT_UBYTE, pTextureImage->width, pTextureImage->height, pTextureImage->imageData);
    351319#else
    352320#ifdef notdef
     
    375343
    376344#endif // USE_RGBA_ARROW
    377 #endif // _WIN32
    378345
    379346#ifdef TEST
  • trunk/packages/vizservers/nanovis/PointSet.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __POINT_SET_H__
    3 #define __POINT_SET_H__
     2#ifndef POINT_SET_H
     3#define POINT_SET_H
    44
    5 #include <PCASplit.h>
    6 #include <Vector4.h>
    7 #include <Vector3.h>
     5#include "PCASplit.h"
     6#include "Vector4.h"
     7#include "Vector3.h"
    88
    9 class PointSet {
     9class PointSet
     10{
     11public :
     12    PointSet() :
     13        _sortLevel(4),
     14        _cluster(0),
     15        _max(1.0f),
     16        _min(0.0f),
     17        _visible(false)
     18    {
     19    }
     20
     21    ~PointSet() {
     22        if (_cluster) {
     23            delete _cluster;
     24        }
     25    }
     26
     27    void initialize(Vector4 *values, const unsigned int count,
     28                    const Vector3& scale, const Vector3& origin,
     29                    float min, float max);
     30
     31    void updateColor(float *color, int  count);
     32
     33    bool isVisible() const
     34    {
     35        return _visible;
     36    }
     37
     38    void setVisible(bool visible)
     39    {
     40        _visible = visible;
     41    }
     42
     43    unsigned int getSortLevel() const
     44    {
     45        return _sortLevel;
     46    }
     47
     48    PCA::ClusterAccel* getCluster()
     49    {
     50        return _cluster;
     51    }
     52
     53    Vector3& getScale()
     54    {
     55        return _scale;
     56    }
     57
     58    const Vector3& getScale() const
     59    {
     60        return _scale;
     61    }
     62
     63    Vector3& getOrigin()
     64    {
     65        return _origin;
     66    }
     67
     68    const Vector3& getOrigin() const
     69    {
     70        return _origin;
     71    }
     72
     73private:
    1074    unsigned int _sortLevel;
    1175    PCA::ClusterAccel* _cluster;
     
    1680    float _min;
    1781    bool _visible;
    18 public :
    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);
    23 
    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     }
    6382};
    6483
    65 #endif /*__POINT_SET_H__*/
     84#endif
  • trunk/packages/vizservers/nanovis/PointSetRenderer.cpp

    r2822 r2831  
    2222        return;
    2323    }
    24    
    25     ImageLoader* loader = ImageLoaderFactory::getInstance()->createLoader("bmp");
    26     Image* image = loader->load(path, Image::IMG_RGBA);
     24
     25    ImageLoader *loader = ImageLoaderFactory::getInstance()->createLoader("bmp");
     26    Image *image = loader->load(path, Image::IMG_RGBA);
    2727    delete [] path;
    28     unsigned char* bytes = (unsigned char*) image->getImageBuffer();
     28    unsigned char *bytes = (unsigned char *)image->getImageBuffer();
    2929    if (bytes) {
    3030        for (unsigned int y = 0; y < image->getHeight(); ++y) {
    31             for (unsigned int x = 0; x < image->getWidth(); ++x, bytes +=4) {
    32                 bytes[3] =  (bytes[0] == 0)? 0 : 255;
     31            for (unsigned int x = 0; x < image->getWidth(); ++x, bytes += 4) {
     32                bytes[3] =  (bytes[0] == 0) ? 0 : 255;
    3333            }
    3434        }
     
    3838        _pointTexture = new Texture2D(image->getWidth(), image->getHeight(),
    3939                                      GL_UNSIGNED_BYTE, GL_LINEAR,   
    40                                       4, (float*) image->getImageBuffer());
     40                                      4, image->getImageBuffer());
    4141    } else {
    4242        ERROR("fail to load image [%s]\n", "particles2.bmp");
     
    4747}
    4848
    49 void PointSetRenderer::renderPoints(PCA::Point* points, int length)
     49void PointSetRenderer::renderPoints(PCA::Point *points, int length)
    5050{
    51     PCA::Point* p = points;
    52     for (int i = 0; i < length; ++i)
    53     {
     51    PCA::Point *p = points;
     52    for (int i = 0; i < length; ++i, ++p) {
    5453        glColor4f(p->color.x, p->color.y, p->color.z, p->color.w);
    5554        glVertex3f(p->position.x, p->position.y, p->position.z);
    56    
    57         ++p;
    5855    }
    5956}
     
    7875
    7976    PCA::ClusterList* p;
    80     for (int i = size - 1; i >= 0; --i)
    81     {
     77    for (int i = size - 1; i >= 0; --i) {
    8278        p = bucket[i];
    83         if (p)
    84         {
    85             if (!setSize)
    86             {
     79        if (p) {
     80            if (!setSize) {
    8781#ifdef USE_SHADER
    8882                _shader->setScale(p->data->points[0].size);
     
    9286        }
    9387
    94         while (p)
    95         {
     88        while (p) {
    9689            renderPoints(p->data->points, p->data->numOfPoints);
    9790
    9891            p = p->next;
    9992        }
    100        
    10193    }
    10294
     
    10597    glDisable(GL_POINT_SPRITE_ARB);
    10698    glPointSize(1);
    107 
    10899}
    109100
    110 void PointSetRenderer::render(PCA::ClusterAccel* cluster, const Mat4x4& mat, int sortLevel, const Vector3& scale, const Vector3& origin)
     101void PointSetRenderer::render(PCA::ClusterAccel *cluster, const Mat4x4& mat,
     102                              int sortLevel, const Vector3& scale, const Vector3& origin)
    111103{
    112104    _bucketSort->init();
     
    134126
    135127    //glTranslatef(-shift.x, -shift.y, -shift.z);
    136    
     128
    137129#ifdef USE_SHADER
    138130    _shader->bind();
     
    140132    glPointSize(POINT_SIZE);
    141133#endif
    142         renderCluster(_bucketSort->getBucket(), _bucketSort->getSize(), 4);
     134    renderCluster(_bucketSort->getBucket(), _bucketSort->getSize(), 4);
    143135#ifdef USE_SHADER
    144136    _shader->unbind();
     
    146138    glPointSize(1.0f);
    147139#endif
    148    
     140
    149141    glPopMatrix();
    150142
     
    159151#endif
    160152}
    161 
  • trunk/packages/vizservers/nanovis/PointSetRenderer.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __POINT_SET_RENDERER_H__
    3 #define __POINT_SET_RENDERER_H__
     2#ifndef POINT_SET_RENDERER_H
     3#define POINT_SET_RENDERER_H
    44
    55#include "PCASplit.h"
     
    77#include "PointShader.h"
    88#include "Texture2D.h"
    9 #include <Mat4x4.h>
     9#include "Mat4x4.h"
    1010
    11 class PointSetRenderer {
    12     PCA::BucketSort* _bucketSort;
    13     PointShader* _shader;
    14     Texture2D* _pointTexture;
    15 public :
     11class PointSetRenderer
     12{
     13 public:
    1614    PointSetRenderer();
    1715    ~PointSetRenderer();
    1816
    19 private :
    20     void renderPoints(PCA::Point* points, int length);
    21     void renderCluster(PCA::ClusterList** bucket, int size, int level);
     17    void render(PCA::ClusterAccel *cluster, const Mat4x4& mat,
     18                int sortLevel, const Vector3& scale, const Vector3& origin);
    2219
    23 public :
    24     void render(PCA::ClusterAccel* cluster, const Mat4x4& mat, int sortLevel, const Vector3& scale, const Vector3& origin);
     20private:
     21    void renderPoints(PCA::Point *points, int length);
     22
     23    void renderCluster(PCA::ClusterList **bucket, int size, int level);
     24
     25    PCA::BucketSort *_bucketSort;
     26    PointShader *_shader;
     27    Texture2D *_pointTexture;
    2528};
    2629
  • trunk/packages/vizservers/nanovis/RenderContext.cpp

    r2798 r2831  
    44namespace graphics {
    55
    6 RenderContext::RenderContext()
    7 : _cullMode(NO_CULL), _fillMode(FILL), _shadingModel(SMOOTH)
     6RenderContext::RenderContext() :
     7    _cullMode(NO_CULL),
     8    _fillMode(FILL),
     9    _shadingModel(SMOOTH)
    810{
    911}
     
    1315}
    1416
    15 };
    16 
     17}
  • trunk/packages/vizservers/nanovis/RenderContext.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __RENDER_CONTEXT_H__
    3 #define __RENDER_CONTEXT_H__
     2#ifndef RENDER_CONTEXT_H
     3#define RENDER_CONTEXT_H
    44
    55#include <GL/gl.h>
     
    77namespace graphics {
    88
    9 class RenderContext {
    10 public :
     9class RenderContext
     10{
     11public:
    1112    enum ShadingModel {
    1213        FLAT = GL_FLAT ,        //!< Flat Shading
    13         SMOOTH = GL_SMOOTH      //!< Smooth shading (Goraud shading model)
     14        SMOOTH = GL_SMOOTH      //!< Smooth shading (Gouraud shading model)
    1415    };
    1516
     
    2526    };
    2627
     28    RenderContext();
     29
     30    ~RenderContext();
     31
     32    /**
     33     *@brief Set the shading model such as flat, smooth
     34     */
     35    void setShadingModel(const ShadingModel shadeModel)
     36    {
     37        _shadingModel = shadeModel;
     38    }
     39
     40    ShadingModel getShadingModel() const
     41    {
     42        return _shadingModel;
     43    }
     44
     45    void setCullMode(const CullMode cullMode)
     46    {
     47        _cullMode = cullMode;
     48    }
     49
     50    CullMode getCullMode() const
     51    {
     52        return _cullMode;
     53    }
     54
     55    void setPolygonMode(const PolygonMode fillMode)
     56    {
     57        _fillMode = fillMode;
     58    }
     59
     60    PolygonMode getPolygonMode() const
     61    {
     62        return _fillMode;
     63    }
     64
    2765private :
    2866    CullMode _cullMode;
    2967    PolygonMode _fillMode;
    3068    ShadingModel _shadingModel;
    31    
    32 public :
    33     /**
    34      *@brief constructor
    35      */
    36     RenderContext();
    37 
    38     /**
    39      *@brief Destructor
    40      */
    41     ~RenderContext();
    42 
    43 public :
    44     /**
    45      *@brief Set the shading model such as flat, smooth
    46      */
    47     void setShadingModel(const ShadingModel shadeModel);
    48     ShadingModel getShadingModel() const;
    49 
    50     void setCullMode(const CullMode cullMode);
    51     CullMode getCullMode() const;
    52 
    53     void setPolygonMode(const PolygonMode fillMode);
    54     PolygonMode getPolygonMode() const;
    55 
    5669};
    57 
    58 inline void RenderContext::setShadingModel(const RenderContext::ShadingModel shadeModel)
    59 {
    60     _shadingModel = shadeModel;
    61 }
    62 
    63 inline RenderContext::ShadingModel RenderContext::getShadingModel() const
    64 {
    65     return _shadingModel;
    66 }
    67 
    68 inline void RenderContext::setCullMode(const RenderContext::CullMode cullMode)
    69 {
    70     _cullMode = cullMode;
    71 }
    72 
    73 inline RenderContext::CullMode RenderContext::getCullMode() const
    74 {
    75     return _cullMode;
    76 }
    77 
    78 inline void RenderContext::setPolygonMode(const RenderContext::PolygonMode fillMode)
    79 {
    80     _fillMode = fillMode;
    81 }
    82 
    83 inline RenderContext::PolygonMode RenderContext::getPolygonMode() const
    84 {
    85     return _fillMode;
    86 }
    8770
    8871}
    8972
    90 #endif //
     73#endif
  • trunk/packages/vizservers/nanovis/Texture1D.cpp

    r2798 r2831  
    1515 */
    1616
    17 #include "Texture1D.h"
    18 #include "Trace.h"
    1917#include <stdio.h>
    2018#include <assert.h>
    2119#include <math.h>
    2220
     21#include "Texture1D.h"
     22#include "Trace.h"
    2323
    24 Texture1D::Texture1D(){
    25     id = -1;                   
    26     gl_resource_allocated = false;
     24Texture1D::Texture1D() :
     25    gl_resource_allocated(false),
     26    id(0)
     27{
    2728}
    2829
    29 Texture1D::Texture1D(int width, int type)
     30Texture1D::Texture1D(int width,
     31                     GLuint type, GLuint interp,
     32                     int numComponents, void *data) :
     33    gl_resource_allocated(false),
     34    id(0)
    3035{
    31     assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT ||
    32            type == GL_UNSIGNED_INT);
    33        
    3436    this->width = width;
    3537    this->type = type;
     38    this->interp_type = interp;
     39    this->n_components = numComponents;
    3640
    37     id = -1;
    38     gl_resource_allocated = false;
     41    if (data != NULL)
     42        initialize(data);
    3943}
    4044
    41 GLuint Texture1D::initialize_float_rgba(float *data)
     45Texture1D::~Texture1D()
    4246{
    43     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     47    glDeleteTextures(1, &id);
     48}
     49
     50GLuint Texture1D::initialize(void *data)
     51{
     52    if (gl_resource_allocated)
     53        glDeleteTextures(1, &id);
    4454
    4555    glGenTextures(1, &id);
    46     glBindTexture(GL_TEXTURE_1D, id);
    47     assert(id != (GLuint)-1);
    4856
    49     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    50 
    51     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    52     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    53 
    54     glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, width, 0, GL_RGBA, GL_FLOAT, data);
    55     assert(glGetError()==0);
     57    update(data);
    5658       
    5759    gl_resource_allocated = true;
     
    5961}
    6062
    61 void Texture1D::update_float_rgba(float* data){
     63void Texture1D::update(void *data)
     64{
    6265    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     66
    6367    glBindTexture(GL_TEXTURE_1D, id);
    6468       
    6569    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     70    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, interp_type);
     71    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, interp_type);
    6672
    67     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    68     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     73    GLuint format[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
    6974
    70     glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, width, 0, GL_RGBA, GL_FLOAT, data);
     75    glTexImage1D(GL_TEXTURE_1D, 0, format[n_components], width, 0,
     76                 format[n_components], type, data);
     77
    7178    assert(glGetError()==0);   
    7279}
     
    8390}
    8491
    85 Texture1D::~Texture1D()
     92void Texture1D::check_max_size()
    8693{
    87     glDeleteTextures(1, &id);
    88 }
    89 
    90 void Texture1D::check_max_size(){
    9194    GLint max = 0;
    9295    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
    93        
    94     //TRACE("%d", glGetError());
     96
    9597    TRACE("max texture size: %d\n", max);
    9698}
    9799
    98 void Texture1D::check_max_unit(){
     100void Texture1D::check_max_unit()
     101{
    99102    int max;
    100103    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
  • trunk/packages/vizservers/nanovis/Texture1D.h

    r2798 r2831  
    1414 * ======================================================================
    1515 */
    16 #ifndef _TEXTURE_1D_H_
    17 #define _TEXTURE_1D_H_
     16#ifndef TEXTURE1D_H
     17#define TEXTURE1D_H
    1818
    1919#include <GL/glew.h>
    2020
    21 class Texture1D {
     21class Texture1D
     22{
    2223public:
     24    Texture1D();
     25
     26    Texture1D(int width,
     27              GLuint type = GL_FLOAT,
     28              GLuint interp = GL_LINEAR,
     29              int numComponents = 4,
     30              void *data = NULL);
     31
     32    ~Texture1D();
     33
     34    GLuint initialize(void *data);
     35
     36    void update(void *data);
     37
     38    void activate();
     39
     40    void deactivate();
     41
     42    static void check_max_size();
     43
     44    static void check_max_unit();
     45
    2346    int width;
     47
     48    int n_components;
     49
    2450    bool gl_resource_allocated;
    25    
     51    GLuint id;
    2652    GLuint type;
    27     GLuint id;
    28     GLuint tex_unit;
     53    GLuint interp_type;
    2954
    30     Texture1D();
    31     Texture1D(int length, int type = GL_UNSIGNED_BYTE);
    32     ~Texture1D();
    33        
    34     void activate();
    35     void deactivate();
    36     GLuint initialize_float_rgba(float* data);
    37     void update_float_rgba(float* data);
    38     static void check_max_size();
    39     static void check_max_unit();
     55    //GLuint tex_unit;
    4056};
    4157
  • trunk/packages/vizservers/nanovis/Texture2D.cpp

    r2798 r2831  
    2323#include "config.h"
    2424
    25 Texture2D::Texture2D(){}
     25Texture2D::Texture2D() :
     26    gl_resource_allocated(false),
     27    id(0)
     28{}
    2629
    27 Texture2D::Texture2D(int width, int height, GLuint type=GL_FLOAT,
    28         GLuint interp=GL_LINEAR, int n=4, float* data = 0)
     30Texture2D::Texture2D(int width, int height,
     31                     GLuint type, GLuint interp,
     32                     int numComponents, void *data) :
     33    gl_resource_allocated(false),
     34    id(0)
    2935{
    30     assert(type == GL_UNSIGNED_BYTE ||
    31            type == GL_FLOAT ||
    32            type ==GL_UNSIGNED_INT);
    33     assert(interp == GL_LINEAR || interp == GL_NEAREST);
    34        
    3536    this->width = width;
    3637    this->height = height;
    3738    this->type = type;
    3839    this->interp_type = interp;
    39     this->n_components = n;
     40    this->n_components = numComponents;
    4041
    41     this->id = 0;
    42 
    43     if(data != 0)
     42    if (data != NULL)
    4443        initialize(data);
    4544}
    4645
    47 GLuint
    48 Texture2D::initialize(float *data)
     46Texture2D::~Texture2D()
    4947{
    50     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     48    glDeleteTextures(1, &id);
     49}
     50
     51GLuint Texture2D::initialize(void *data)
     52{
     53    if (gl_resource_allocated)
     54        glDeleteTextures(1, &id);
    5155
    5256    glGenTextures(1, &id);
     57
     58    update(data);
     59
     60    gl_resource_allocated = true;
     61    return id;
     62}
     63
     64void Texture2D::update(void *data)
     65{
    5366    glBindTexture(GL_TEXTURE_2D, id);
    54     assert(id != (GLuint)-1);
     67
     68    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    5569
    5670    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    5771    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    58        
    59     if(interp_type == GL_LINEAR){
    60         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    61         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    62     } else {
    63         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    64         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    65     }
     72
     73    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, interp_type);
     74    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, interp_type);
    6675
    6776    //to do: add handling to more formats
    68     if (type==GL_FLOAT) {
    69         switch(n_components){
    7077#ifdef NV40
    71         case 1:
    72             glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, width, height,
    73                          0, GL_LUMINANCE, GL_FLOAT, data);
    74             break;
    75         case 2:
    76             glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA16F_ARB, width,
    77                          height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    78             break;
    79         case 3:
    80             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, width, height, 0,
    81                          GL_RGB, GL_FLOAT, data);
    82             break;
    83         case 4:
    84             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0,
    85                          GL_RGBA, GL_FLOAT, data);
    86             break;
    87 #else
    88         case 1:
    89             glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
    90                          GL_LUMINANCE, GL_FLOAT, data);
    91             break;
    92         case 2:
    93             glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width, height,
    94                          0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    95             break;
    96         case 3:
    97             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
    98                          GL_FLOAT, data);
    99             break;
    100         case 4:
    101             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
    102                          GL_FLOAT, data);
    103             break;
     78    if (type == GL_FLOAT) {
     79        GLuint targetFormat[5] = { -1, GL_LUMINANCE16F_ARB, GL_LUMINANCE_ALPHA16F_ARB, GL_RGB16F_ARB, GL_RGBA16F_ARB };
     80        GLuint format[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
     81        glTexImage2D(GL_TEXTURE_2D, 0, targetFormat[n_components], width, height, 0,
     82                     format[n_components], type, data);
     83    } else {
    10484#endif
    105         default:
    106             break;
    107         }
    108     } else {
    109         int comp[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
    110         glTexImage2D(GL_TEXTURE_2D, 0, comp[n_components], width, height, 0,
    111                      GL_RGBA, type, data);
     85        GLuint format[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
     86        glTexImage2D(GL_TEXTURE_2D, 0, format[n_components], width, height, 0,
     87                     format[n_components], type, data);
     88#ifdef NV40
    11289    }
    113     assert(glGetError()==0);
    114     return id;
     90#endif
     91    assert(glGetError() == 0);
     92
     93    gl_resource_allocated = true;
    11594}
    116 
    11795
    11896void
     
    123101}
    124102
    125 
    126103void
    127104Texture2D::deactivate()
     
    130107}
    131108
    132 
    133 Texture2D::~Texture2D()
     109void
     110Texture2D::check_max_size()
    134111{
    135     glDeleteTextures(1, &id);
    136 }
    137 
    138 
    139 void
    140 Texture2D::check_max_size(){
    141112    GLint max = 0;
    142113    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
     
    146117
    147118void
    148 Texture2D::check_max_unit(){
    149     int max;
     119Texture2D::check_max_unit()
     120{
     121    int max = 0;
    150122    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
    151123
    152124    TRACE("max texture units: %d.\n", max);
    153125}
    154 
  • trunk/packages/vizservers/nanovis/Texture2D.h

    r2818 r2831  
    1414 * ======================================================================
    1515 */
    16 
    17 #ifndef _TEXTURE_2D_H_
    18 #define _TEXTURE_2D_H_
     16#ifndef TEXTURE2D_H
     17#define TEXTURE2D_H
    1918
    2019#include <GL/glew.h>
     
    2322{
    2423public:
    25   int width;
    26   int height;
     24    Texture2D();
    2725
    28   GLuint type;
    29   GLuint id;
    30   GLuint interp_type;
    31   int n_components;
     26    Texture2D(int width, int height,
     27              GLuint type = GL_FLOAT,
     28              GLuint interp = GL_LINEAR,
     29              int numComponents = 4,
     30              void *data = NULL);
    3231
    33   Texture2D();
    34   Texture2D(int width, int height, GLuint type, GLuint interp, int n, float* data);
    35   ~Texture2D();
    36        
    37   void activate();
    38   void deactivate();
    39   void enable();
    40   void disable();
    41   GLuint initialize(float* data);
    42   static void check_max_size();
    43   static void check_max_unit();
     32    ~Texture2D();
     33
     34    GLuint initialize(void *data);
     35
     36    void update(void *data);
     37
     38    void activate();
     39
     40    void deactivate();
     41
     42    static void check_max_size();
     43
     44    static void check_max_unit();
     45
     46    int width;
     47    int height;
     48
     49    int n_components;
     50
     51    bool gl_resource_allocated;
     52    GLuint id;
     53    GLuint type;
     54    GLuint interp_type;
    4455};
    4556
  • trunk/packages/vizservers/nanovis/Texture3D.cpp

    r2798 r2831  
    2323#include "config.h"
    2424
    25 Texture3D::Texture3D(){ id=0; gl_resource_allocated = false; }
     25Texture3D::Texture3D() :
     26    gl_resource_allocated(false),
     27    id(0)
     28{}
    2629
    27 Texture3D::Texture3D(int width, int height, int depth, GLuint type=GL_FLOAT, GLuint interp=GL_LINEAR, int components=4)
     30Texture3D::Texture3D(int width, int height, int depth,
     31                     GLuint type, GLuint interp,
     32                     int numComponents, void *data) :
     33    gl_resource_allocated(false),
     34    id(0)
    2835{
    29     assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT);
    30     assert(interp == GL_LINEAR || interp == GL_NEAREST);
    31        
    3236    this->width = width;
    3337    this->height = height;
     
    4852    this->type = type;
    4953    this->interp_type = interp;
    50     this->n_components = components;
     54    this->n_components = numComponents;
    5155
    52     this->id = 0;
    53     gl_resource_allocated = false;
     56    if (data != NULL)
     57        initialize(data);
    5458}
    5559
    56 void Texture3D::update(float* data)
     60Texture3D::~Texture3D()
    5761{
    58     //load texture with 16 bit half floating point precision if card is 6 series NV40
    59     //half float with linear interpolation is only supported by 6 series and up cards
    60     //If NV40 not defined, data is quantized to 8-bit from 32-bit.
    61     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    62 
    63     glBindTexture(GL_TEXTURE_3D, id);
    64     assert(id != (GLuint)-1);
    65 
    66     glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    67     glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    68     glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    69 
    70     if(interp_type==GL_LINEAR){
    71         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    72         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    73     }
    74     else{
    75         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    76         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    77     }
    78 
    79     //to do: add handling to more formats
    80     if(type==GL_FLOAT){
    81         switch(n_components){
    82 #ifdef NV40
    83         case 1:
    84             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    85             break;
    86         case 2:
    87             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    88             break;
    89         case 3:
    90             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    91             break;
    92         case 4:
    93             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    94             break;
    95 #else
    96         case 1:
    97             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    98             break;
    99         case 2:
    100             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    101             break;
    102         case 3:
    103             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    104             break;
    105         case 4:
    106             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    107             break;
    108 #endif
    109         default:
    110             break;
    111         }
    112     }
    113 
    114 
    115     assert(glGetError()==0);
    116        
    117     gl_resource_allocated = true;
    118 
     62    glDeleteTextures(1, &id);
    11963}
    12064
    121 GLuint Texture3D::initialize(float *data)
     65GLuint Texture3D::initialize(void *data)
    12266{
    123     if (id != 0) glDeleteTextures(1, &id);
     67    if (id != 0)
     68        glDeleteTextures(1, &id);
     69
     70    glGenTextures(1, &id);
     71
     72    update(data);
     73 
     74    return id;
     75}
     76
     77void Texture3D::update(void *data)
     78{
     79    assert(id > 0 && id != (GLuint)-1);
     80    glBindTexture(GL_TEXTURE_3D, id);
    12481
    12582    //load texture with 16 bit half floating point precision if card is 6 series NV40
     
    12885    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    12986
    130     glGenTextures(1, &id);
    131     glBindTexture(GL_TEXTURE_3D, id);
    132     assert(id != (GLuint)-1);
    133 
    13487    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    13588    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    13689    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    13790
    138     if(interp_type==GL_LINEAR){
    139         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    140         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    141     }
    142     else{
    143         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    144         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    145     }
     91    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, interp_type);
     92    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, interp_type);
    14693
    14794    //to do: add handling to more formats
    148     if(type==GL_FLOAT){
    149         switch(n_components){
    15095#ifdef NV40
    151         case 1:
    152             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    153             break;
    154         case 2:
    155             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    156             break;
    157         case 3:
    158             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    159             break;
    160         case 4:
    161             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    162             break;
    163 #else
    164         case 1:
    165             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data);
    166             break;
    167         case 2:
    168             glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    169             break;
    170         case 3:
    171             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data);
    172             break;
    173         case 4:
    174             glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data);
    175             break;
     96    if (type == GL_FLOAT) {
     97        GLuint targetFormat[5] = { -1, GL_LUMINANCE16F_ARB, GL_LUMINANCE_ALPHA16F_ARB, GL_RGB16F_ARB, GL_RGBA16F_ARB };
     98        GLuint format[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
     99        glTexImage3D(GL_TEXTURE_3D, 0, targetFormat[n_components],
     100                     width, height, depth, 0,
     101                     format[n_components], type, data);
     102    } else {
    176103#endif
    177         default:
    178             break;
    179         }
     104        GLuint format[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
     105        glTexImage3D(GL_TEXTURE_3D, 0, format[n_components],
     106                     width, height, depth, 0,
     107                     format[n_components], type, data);
     108#ifdef NV40
    180109    }
    181 
     110#endif
    182111
    183112    assert(glGetError()==0);
    184        
     113
    185114    gl_resource_allocated = true;
    186     return id;
    187115}
    188116
     
    198126}
    199127
    200 Texture3D::~Texture3D()
     128void Texture3D::check_max_size()
    201129{
    202     glDeleteTextures(1, &id);
    203 }
    204 
    205 void Texture3D::check_max_size(){
    206130    GLint max = 0;
    207131    glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &max);
    208        
    209     //TRACE("%d", glGetError());
     132
    210133    TRACE("max 3d texture size: %d\n", max);
    211134}
    212135
    213 void Texture3D::check_max_unit(){
     136void Texture3D::check_max_unit()
     137{
    214138    int max;
    215139    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
  • trunk/packages/vizservers/nanovis/Texture3D.h

    r2798 r2831  
    1414 * ======================================================================
    1515 */
    16 #ifndef _TEXTURE_3D_H_
    17 #define _TEXTURE_3D_H_
     16#ifndef TEXTURE3D_H
     17#define TEXTURE3D_H
    1818
    1919#include <GL/glew.h>
    20 #include "config.h"
    2120
    22 class Texture3D{
    23        
     21class Texture3D
     22{
     23public:
     24    Texture3D();
    2425
    25 public:
    26         int width;
    27         int height;
    28         int depth;
     26    Texture3D(int width, int height, int depth,
     27              GLuint type = GL_FLOAT,
     28              GLuint interp = GL_LINEAR,
     29              int numComponents = 4,
     30              void *data = NULL);
    2931
    30         double aspect_ratio_width;
    31         double aspect_ratio_height;
    32         double aspect_ratio_depth;
     32    ~Texture3D();
    3333
    34         GLuint type;
    35         GLuint interp_type;
    36         int n_components;
    37         bool gl_resource_allocated;
     34    GLuint initialize(void *data);
    3835
    39         GLuint id;
    40         GLuint tex_unit;
     36    void update(void *data);
    4137
    42         Texture3D();
    43         Texture3D(int width, int height, int depth, GLuint type, GLuint interp, int n);
    44         ~Texture3D();
    45        
    46         void activate();
    47         void deactivate();
    48         GLuint initialize(float* data);
    49         static void check_max_size();
    50         static void check_max_unit();
     38    void activate();
    5139
    52     void update(float* data);
     40    void deactivate();
    5341
     42    static void check_max_size();
     43
     44    static void check_max_unit();
     45
     46    int width;
     47    int height;
     48    int depth;
     49
     50    double aspect_ratio_width;
     51    double aspect_ratio_height;
     52    double aspect_ratio_depth;
     53
     54    int n_components;
     55
     56    bool gl_resource_allocated;
     57    GLuint id;
     58    GLuint type;
     59    GLuint interp_type;
     60    //GLuint tex_unit;
    5461};
    5562
  • trunk/packages/vizservers/nanovis/Trace.cpp

    r2822 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #include "nanovis.h"
    3 #include <Trace.h>
    42#include <stdio.h>
    53#include <stdarg.h>
     4#include <syslog.h>
    65
    76#include <GL/glew.h>
    87
    9 #include <syslog.h>
     8#include "nanovis.h"
     9#include "Trace.h"
    1010
    1111static const char *syslogLevels[] = {
  • trunk/packages/vizservers/nanovis/TransferFunction.cpp

    r2820 r2831  
    2121TransferFunction::TransferFunction(int size, float *data)
    2222{
    23     _tex = new Texture1D(size, GL_FLOAT);
    24 
    2523    // _size : # of slot, 4 : rgba
    2624    _size = size * 4;
    2725    _data = new float[_size];
    2826    memcpy(_data, data, sizeof(float) * _size);
    29     _tex->initialize_float_rgba(_data);
     27
     28    _tex = new Texture1D(size, GL_FLOAT, GL_LINEAR, 4, data);
    3029    _id = _tex->id;
    3130}
    32 
    3331
    3432TransferFunction::~TransferFunction()
     
    3836}
    3937
    40 void 
    41 TransferFunction::update(float* data)
     38void
     39TransferFunction::update(float *data)
    4240{
    4341    memcpy(_data, data, sizeof(float) * _size);
    44     _tex->update_float_rgba(_data);
     42    _tex->update(_data);
    4543}
    4644
    47 
    48 void
     45void
    4946TransferFunction::update(int size, float *data)
    5047{
  • trunk/packages/vizservers/nanovis/TransferFunction.h

    r2820 r2831  
    2424class TransferFunction : public R2Object
    2525{
    26     int _size;                  //the resolution of the color map, how many
     26public:
     27    TransferFunction(int size, float *data);
     28
     29    void update(float *data);
     30
     31    void update(int size, float *data);
     32
     33    GLuint id()
     34    {
     35        return _id;
     36    }
     37
     38    void id(GLuint id)
     39    {
     40        _id = id;
     41    }
     42
     43    Texture1D *getTexture()
     44    {
     45        return _tex;
     46    }
     47
     48    float *getData()
     49    {
     50        return _data;
     51    }
     52
     53    int getSize() const
     54    {
     55        return _size;
     56    }
     57
     58    const char *name() const
     59    {
     60        return _name;
     61    }
     62
     63    void name(const char *name)
     64    {
     65        _name = name;
     66    }
     67
     68    static void sample(float fraction, float *key, int count, Vector3 *keyValue, Vector3 *ret);
     69
     70    static void sample(float fraction, float *key, int count, float *keyValue, float *ret);
     71
     72protected :
     73    ~TransferFunction();
     74
     75private:
     76   int _size;                   //the resolution of the color map, how many
    2777                                //(RGBA) quadraples
    2878    float* _data;
     
    3080    const char *_name;
    3181    GLuint _id;                 //OpenGL's texture identifier
    32 
    33 protected :
    34     ~TransferFunction();
    35 
    36 public:
    37     TransferFunction(int size, float *data);
    38     void update(float *data);
    39     void update(int size, float *data);
    40     GLuint id(void) {
    41         return _id;
    42     }
    43     void id(GLuint id) {
    44         _id = id;
    45     }
    46     Texture1D* getTexture(void) {
    47         return _tex;
    48     }
    49     float* getData(void) {
    50         return _data;
    51     }
    52     int getSize() const {
    53         return _size;
    54     }
    55     const char *name(void) const {
    56         return _name;
    57     }
    58     void name(const char *name) {
    59         _name = name;
    60     }
    61 
    62     static void sample(float fraction, float *key, int count, Vector3 *keyValue, Vector3 *ret);
    63     static void sample(float fraction, float *key, int count, float *keyValue, float *ret);
    6482};
    6583
  • trunk/packages/vizservers/nanovis/Unirect.cpp

    r2827 r2831  
    1010
    1111extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
    12         float *valuePtr);
     12                           float *valuePtr);
     13
    1314extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *indexPtr);
    1415
  • trunk/packages/vizservers/nanovis/Unirect.h

    r2822 r2831  
    1313class Unirect2d;
    1414
    15 class Unirect3d {
     15class Unirect3d
     16{
     17public:
     18    Unirect3d(float xMin, float xMax, size_t xNum,
     19              float yMin, float yMax, size_t yNum,
     20              float zMin, float zMax, size_t zNum,
     21              size_t nValues, float *values, size_t nComponents) :
     22        _xNum(xNum), _yNum(yNum), _zNum(zNum),
     23        _nValues(nValues),
     24        _nComponents(nComponents),
     25        _xMin(xMin), _xMax(xMax),
     26        _yMin(yMin), _yMax(yMax),
     27        _zMin(zMin), _zMax(zMax),
     28        _xValueMin(FLT_MAX), _xValueMax(-FLT_MAX),
     29        _yValueMin(FLT_MAX), _yValueMax(-FLT_MAX),
     30        _zValueMin(FLT_MAX), _zValueMax(-FLT_MAX),
     31        _magMin(DBL_MAX), _magMax(-DBL_MAX),
     32        _xUnits(NULL), _yUnits(NULL), _zUnits(NULL), _vUnits(NULL),
     33        _values(NULL),
     34        _initialized(false)
     35    {
     36        _initialized = true;
     37    }
     38
     39    Unirect3d(size_t nComponents = 1) :
     40        _nValues(0),
     41        _nComponents(nComponents),
     42        _xValueMin(FLT_MAX), _xValueMax(-FLT_MAX),
     43        _yValueMin(FLT_MAX), _yValueMax(-FLT_MAX),
     44        _zValueMin(FLT_MAX), _zValueMax(-FLT_MAX),
     45        _magMin(DBL_MAX), _magMax(-DBL_MAX),
     46        _xUnits(NULL), _yUnits(NULL), _zUnits(NULL), _vUnits(NULL),
     47        _values(NULL),
     48        _initialized(false)
     49    {
     50        _nComponents = nComponents;
     51    }
     52
     53    ~Unirect3d()
     54    {
     55        if (_values != NULL) {
     56            free(_values);
     57        }
     58        if (_xUnits != NULL) {
     59            free(_xUnits);
     60        }
     61        if (_yUnits != NULL) {
     62            free(_yUnits);
     63        }
     64        if (_zUnits != NULL) {
     65            free(_zUnits);
     66        }
     67        if (_vUnits != NULL) {
     68            free(_vUnits);
     69        }
     70    }
     71
     72    size_t xNum()
     73    {
     74        return _xNum;
     75    }
     76
     77    size_t yNum()
     78    {
     79        return _yNum;
     80    }
     81
     82    size_t zNum()
     83    {
     84        return _zNum;
     85    }
     86
     87    float xMin()
     88    {
     89        return _xMin;
     90    }
     91
     92    float yMin()
     93    {
     94        return _yMin;
     95    }
     96
     97    float zMin()
     98    {
     99        return _zMin;
     100    }
     101
     102    float xMax()
     103    {
     104        return _xMax;
     105    }
     106
     107    float yMax()
     108    {
     109        return _yMax;
     110    }
     111
     112    float zMax()
     113    {
     114        return _zMax;
     115    }
     116
     117    float xValueMin()
     118    {
     119        return _xValueMin;
     120    }
     121
     122    float yValueMin()
     123    {
     124        return _yValueMin;
     125    }
     126
     127    float zValueMin()
     128    {
     129        return _zValueMin;
     130    }
     131
     132    float xValueMax()
     133    {
     134        return _xValueMax;
     135    }
     136
     137    float yValueMax()
     138    {
     139        return _yValueMax;
     140    }
     141
     142    float zValueMax()
     143    {
     144        return _zValueMax;
     145    }
     146
     147    size_t nComponents()
     148    {
     149        return _nComponents;
     150    }
     151
     152    const char *xUnits()
     153    {
     154        return _xUnits;
     155    }
     156
     157    const char *yUnits()
     158    {
     159        return _yUnits;
     160    }
     161    const char *zUnits()
     162    {
     163        return _zUnits;
     164    }
     165
     166    const char *vUnits()
     167    {
     168        return _vUnits;
     169    }
     170
     171    const float *values()
     172    {
     173        return _values;
     174    }
     175
     176    double magMin()
     177    {
     178        if (_magMin == DBL_MAX) {
     179            GetVectorRange();
     180        }
     181        TRACE("magMin=%g %g\n", _magMin, DBL_MAX);
     182        return _magMin;
     183    }
     184
     185    double magMax()
     186    {
     187        if (_magMax == -DBL_MAX) {
     188            GetVectorRange();
     189        }
     190        TRACE("magMax=%g %g\n", _magMax, -DBL_MAX);
     191        return _magMax;
     192    }
     193
     194    const float *SaveValues()
     195    {
     196        float *values;
     197        values = _values;
     198        _values = NULL;
     199        _nValues = 0;
     200        return values;
     201    }
     202
     203    size_t nValues()
     204    {
     205        return _nValues;
     206    }
     207
     208    int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
     209
     210    int ParseBuffer(Tcl_Interp *interp, Rappture::Buffer &buf);
     211
     212    bool ImportDx(Rappture::Outcome &result, size_t nComponents,
     213                  size_t length, char *string);
     214
     215    bool Convert(Unirect2d *dataPtr);
     216
     217    bool Resample(Rappture::Outcome &context, size_t nSamples = 30);
     218
     219    bool isInitialized()
     220    {
     221        return _initialized;
     222    }
     223
     224private:
     225    void GetVectorRange();
     226
    16227    size_t _xNum, _yNum, _zNum;
    17228    size_t _nValues;
     
    30241    float *_values;
    31242    bool _initialized;
    32     void GetVectorRange(void);
    33 
     243};
     244
     245class Unirect2d
     246{
    34247public:
    35     Unirect3d(float xMin, float xMax, size_t xNum,
    36               float yMin, float yMax, size_t yNum,
    37               float zMin, float zMax, size_t zNum,
    38               size_t nValues, float *values, size_t nComponents) :
    39         _xNum(xNum), _yNum(yNum), _zNum(zNum),
    40         _nValues(nValues),
    41         _nComponents(nComponents),
    42         _xMin(xMin),         _xMax(xMax),
    43         _yMin(yMin),         _yMax(yMax),
    44         _zMin(zMin),         _zMax(zMax),
    45         _xValueMin(FLT_MAX), _xValueMax(-FLT_MAX),
    46         _yValueMin(FLT_MAX), _yValueMax(-FLT_MAX),
    47         _zValueMin(FLT_MAX), _zValueMax(-FLT_MAX),
    48         _magMin(DBL_MAX),    _magMax(-DBL_MAX),
    49         _xUnits(NULL), _yUnits(NULL), _zUnits(NULL), _vUnits(NULL),
    50         _values(NULL),
    51         _initialized(false)
    52     {
    53         _initialized = true;
    54     }
    55 
    56     Unirect3d(size_t nComponents = 1) :
    57         _nValues(0),
    58         _nComponents(nComponents),
    59         _xValueMin(FLT_MAX), _xValueMax(-FLT_MAX),
    60         _yValueMin(FLT_MAX), _yValueMax(-FLT_MAX),
    61         _zValueMin(FLT_MAX), _zValueMax(-FLT_MAX),
    62         _magMin(DBL_MAX),    _magMax(-DBL_MAX),
    63         _xUnits(NULL), _yUnits(NULL), _zUnits(NULL), _vUnits(NULL),
    64         _values(NULL),
    65         _initialized(false)
    66     {
    67         _nComponents = nComponents;
    68     }
    69     ~Unirect3d(void) {
    70         if (_values != NULL) {
    71             free(_values);
    72         }
    73         if (_xUnits != NULL) {
    74             free(_xUnits);
    75         }
    76         if (_yUnits != NULL) {
    77             free(_yUnits);
    78         }
    79         if (_zUnits != NULL) {
    80             free(_zUnits);
    81         }
    82         if (_vUnits != NULL) {
    83             free(_vUnits);
    84         }
    85     }
    86     size_t xNum(void) {
    87         return _xNum;
    88     }
    89     size_t yNum(void) {
    90         return _yNum;
    91     }
    92     size_t zNum(void) {
    93         return _zNum;
    94     }
    95     float xMin(void) {
    96         return _xMin;
    97     }
    98     float yMin(void) {
    99         return _yMin;
    100     }
    101     float zMin(void) {
    102         return _zMin;
    103     }
    104     float xMax(void) {
    105         return _xMax;
    106     }
    107     float yMax(void) {
    108         return _yMax;
    109     }
    110     float zMax(void) {
    111         return _zMax;
    112     }
    113     float xValueMin(void) {
    114         return _xValueMin;
    115     }
    116     float yValueMin(void) {
    117         return _yValueMin;
    118     }
    119     float zValueMin(void) {
    120         return _zValueMin;
    121     }
    122     float xValueMax(void) {
    123         return _xValueMax;
    124     }
    125     float yValueMax(void) {
    126         return _yValueMax;
    127     }
    128     float zValueMax(void) {
    129         return _zValueMax;
    130     }
    131     size_t nComponents(void) {
    132         return _nComponents;
    133     }
    134     const char *xUnits(void) {
    135         return _xUnits;
    136     }
    137     const char *yUnits(void) {
    138         return _yUnits;
    139     }
    140     const char *zUnits(void) {
    141         return _zUnits;
    142     }
    143     const char *vUnits(void) {
    144         return _vUnits;
    145     }
    146     const float *values(void) {
    147         return _values;
    148     }
    149     double magMin(void) {
    150         if (_magMin == DBL_MAX) {
    151             GetVectorRange();
    152         }
    153         TRACE("magMin=%g %g\n", _magMin, DBL_MAX);
    154         return _magMin;
    155     }
    156     double magMax(void) {
    157         if (_magMax == -DBL_MAX) {
    158             GetVectorRange();
    159         }
    160         TRACE("magMax=%g %g\n", _magMax, -DBL_MAX);
    161         return _magMax;
    162     }
    163     const float *SaveValues(void) {
    164         float *values;
    165         values = _values;
    166         _values = NULL;
    167         _nValues = 0;
    168         return values;
    169     }
    170     size_t nValues(void) {
    171         return _nValues;
    172     }
     248    Unirect2d(size_t nComponents = 1) :
     249        _xNum(0), _yNum(0),
     250        _nValues(0),
     251        _nComponents(nComponents),
     252        _xUnits(NULL), _yUnits(NULL), _vUnits(NULL),
     253        _values(NULL),
     254        _initialized(false)
     255    {
     256    }
     257
     258    ~Unirect2d()
     259    {
     260        if (_values != NULL) {
     261            free(_values);
     262        }
     263        if (_xUnits != NULL) {
     264            free(_xUnits);
     265        }
     266        if (_yUnits != NULL) {
     267            free(_yUnits);
     268        }
     269        if (_vUnits != NULL) {
     270            free(_vUnits);
     271        }
     272    }
     273
     274    size_t xNum()
     275    {
     276        return _xNum;
     277    }
     278
     279    size_t yNum()
     280    {
     281        return _yNum;
     282    }
     283
     284    float xMin()
     285    {
     286        return _xMin;
     287    }
     288
     289    float yMin()
     290    {
     291        return _yMin;
     292    }
     293
     294    float xMax()
     295    {
     296        return _xMax;
     297    }
     298
     299    float yMax()
     300    {
     301        return _yMax;
     302    }
     303
     304    const char *xUnits()
     305    {
     306        return _xUnits;
     307    }
     308
     309    const char *yUnits()
     310    {
     311        return _yUnits;
     312    }
     313
     314    const char *vUnits()
     315    {
     316        return _vUnits;
     317    }
     318
     319    float *values()
     320    {
     321        return _values;
     322    }
     323
     324    float xValueMin()
     325    {
     326        return _xValueMin;
     327    }
     328
     329    float yValueMin()
     330    {
     331        return _yValueMin;
     332    }
     333
     334    float xValueMax()
     335    {
     336        return _xValueMax;
     337    }
     338
     339    float yValueMax()
     340    {
     341        return _yValueMax;
     342    }
     343
     344    size_t nComponents()
     345    {
     346        return _nComponents;
     347    }
     348
     349    float *transferValues()
     350    {
     351        float *values;
     352        values = _values;
     353        _values = NULL;
     354        _nValues = 0;
     355        return values;
     356    }
     357
     358    size_t nValues()
     359    {
     360        return _nValues;
     361    }
     362
    173363    int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
     364   
    174365    int ParseBuffer(Tcl_Interp *interp, Rappture::Buffer &buf);
    175 
    176     bool ImportDx(Rappture::Outcome &result, size_t nComponents,
    177                   size_t length, char *string);
    178     bool Convert(Unirect2d *dataPtr);
    179     bool Resample(Rappture::Outcome &context, size_t nSamples = 30);
    180     bool isInitialized(void) {
    181         return _initialized;
    182     }
    183 };
    184 
    185 class Unirect2d {
     366   
     367    bool isInitialized()
     368    {
     369        return _initialized;
     370    }
     371
     372private:
    186373    size_t _xNum, _yNum;
    187374    size_t _nValues;
     
    199386    float *_values;
    200387    bool _initialized;
    201 
    202 public:
    203     Unirect2d(size_t nComponents = 1) {
    204         _values = NULL;
    205         _initialized = false;
    206         _xNum = _yNum = 0;
    207         _nValues = 0;
    208         _xUnits = _yUnits = _vUnits = NULL;
    209         _nComponents = nComponents;
    210     }
    211     ~Unirect2d(void) {
    212         if (_values != NULL) {
    213             free(_values);
    214         }
    215         if (_xUnits != NULL) {
    216             free(_xUnits);
    217         }
    218         if (_yUnits != NULL) {
    219             free(_yUnits);
    220         }
    221         if (_vUnits != NULL) {
    222             free(_vUnits);
    223         }
    224     }
    225     size_t xNum(void) {
    226         return _xNum;
    227     }
    228     size_t yNum(void) {
    229         return _yNum;
    230     }
    231     float xMin(void) {
    232         return _xMin;
    233     }
    234     float yMin(void) {
    235         return _yMin;
    236     }
    237     float xMax(void) {
    238         return _xMax;
    239     }
    240     float yMax(void) {
    241         return _yMax;
    242     }
    243     const char *xUnits(void) {
    244         return _xUnits;
    245     }
    246     const char *yUnits(void) {
    247         return _yUnits;
    248     }
    249     const char *vUnits(void) {
    250         return _vUnits;
    251     }
    252     float *values(void) {
    253         return _values;
    254     }
    255     float xValueMin(void) {
    256         return _xValueMin;
    257     }
    258     float yValueMin(void) {
    259         return _yValueMin;
    260     }
    261     float xValueMax(void) {
    262         return _xValueMax;
    263     }
    264     float yValueMax(void) {
    265         return _yValueMax;
    266     }
    267     size_t nComponents(void) {
    268         return _nComponents;
    269     }
    270     float *transferValues(void) {
    271         float *values;
    272         values = _values;
    273         _values = NULL;
    274         _nValues = 0;
    275         return values;
    276     }
    277     size_t nValues(void) {
    278         return _nValues;
    279     }
    280     int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
    281     int ParseBuffer(Tcl_Interp *interp, Rappture::Buffer &buf);
    282     bool isInitialized(void) {
    283         return _initialized;
    284     }
    285388};
    286389
    287390}
    288391
    289 #endif /*_UNIRECT_H*/
    290 
     392#endif
     393
  • trunk/packages/vizservers/nanovis/VelocityArrowsSlice.cpp

    r2822 r2831  
    33
    44#include <GL/glew.h>
    5 #ifdef _WIN32
    6 #include <windows.h>
    7 #endif
    85#include <GL/gl.h>
    9 #ifdef WIN32
    10 #include <GL/glaux.h>
    11 #else
    126#ifdef HAVE_OPENCV_H
    137#include <opencv/cv.h>
     
    1610#include <opencv/highgui.h>
    1711#endif
    18 #endif
     12
     13#include <R2/R2FilePath.h>
    1914
    2015#include "VelocityArrowsSlice.h"
    21 
    22 #ifdef USE_NANOVIS_LIB
    2316#include "global.h"
    24 #include "R2/R2FilePath.h"
    25 #endif
    26 
    27 #define USE_VERTEX_BUFFER
    2817
    2918VelocityArrowsSlice::VelocityArrowsSlice()
     
    3827    //_renderMode = GLYPHS;
    3928    _renderMode = LINES;
    40        
     29
    4130    _tickCountForMinSizeAxis = 10;
    4231
    4332    _queryVelocityFP =
    44 #ifdef USE_NANOVIS_LIB
    4533        LoadCgSourceProgram(_context, "queryvelocity.cg", CG_PROFILE_FP30, "main");
    46 #else
    47         cgCreateProgramFromFile(_context, CG_SOURCE, "queryvelocity.cg",
    48                                 CG_PROFILE_FP30, "main", NULL);
    49     cgGLLoadProgram(_queryVelocityFP);
    50 #endif
     34
    5135    _qvVectorFieldParam = cgGetNamedParameter(_queryVelocityFP, "vfield");
    5236
     
    7054    /*
    7155      _particleVP =
    72 #ifdef USE_NANOVIS_LIB
    7356          LoadCgSourceProgram(_context, "velocityslicevp.cg", CG_PROFILE_VP40, "vpmain");
    74 #else
    75           cgCreateProgramFromFile(_context, CG_SOURCE, "velocityslicevp.cg",
    76                                   CG_PROFILE_VP40, "vpmain", NULL);
    77       cgGLLoadProgram(_particleVP);
    78 #endif
     57
    7958      _mvpParticleParam = cgGetNamedParameter(_particleVP, "mvp");
    8059      _mvParticleParam = cgGetNamedParameter(_particleVP, "modelview");
     
    8362      // TBD..
    8463      _particleFP =
    85 #ifdef USE_NANOVIS_LIB
    8664          LoadCgSourceProgram(_context, "velocityslicefp.cg", CG_PROFILE_FP40, "fpmain");
    87 #else
    88           cgCreateProgramFromFile(_context, CG_SOURCE, "velocityslicefp.cg",
    89                                   CG_PROFILE_FP40, "fpmain", NULL);
    90       cgGLLoadProgram(_particleFP);
    91 #endif
     65
    9266      _vectorParticleParam = cgGetNamedParameter(_particleVP, "vfield");
    9367    */
    9468
    95 #ifdef USE_NANOVIS_LIB
    96 
    97 #ifdef WIN32
    98     AUX_RGBImageRec *pTextureImage = auxDIBImageLoad("arrows.bmp");
    99     _arrowsTex->setPixels(CF_RGB, DT_UBYTE, pTextureImage->sizeX, pTextureImage->sizeY, (void*) pTextureImage->data);
    100 
    101     _arrowsTex = new Texture2D(pTextureImage->sizeX, pTextureImage->sizeY, GL_FLOAT, GL_LINEAR, 3, (void*) pTextureImage->data);
    102 
    103     //delete pTextureImage;
    104 #else
    10569    /*
    10670      TRACE("test1\n");
     
    11579      if (pTextureImage) {
    11680          TRACE("file(%s) has been loaded\n", path);
    117           _arrowsTex = new Texture2D(pTextureImage->width, pTextureImage->height, GL_FLOAT, GL_LINEAR, 3, (float*) pTextureImage->imageData);
     81          _arrowsTex = new Texture2D(pTextureImage->width, pTextureImage->height, GL_FLOAT, GL_LINEAR, 3, pTextureImage->imageData);
     82          //_arrowsTex->setWrapS(TW_MIRROR);
     83          //_arrowsTex->setWrapT(TW_MIRROR);
    11884          TRACE("file(%s) has been loaded\n", path);
    11985          //cvReleaseImage(&pTextureImage);
     
    12490    */
    12591
    126 #endif
    127 
    128 #else
    129     _arrowsTex = new Texture2D();
    130     _arrowsTex->setWrapS(TW_MIRROR);
    131     _arrowsTex->setWrapT(TW_MIRROR);
    132 #ifdef WIN32
    133     AUX_RGBImageRec *pTextureImage = auxDIBImageLoad("arrows.bmp");
    134     _arrowsTex->setPixels(CF_RGB, DT_UBYTE, pTextureImage->sizeX, pTextureImage->sizeY, (void*) pTextureImage->data);
    135 
    136     //delete pTextureImage;
    137 #else
    138     IplImage* pTextureImage = cvLoadImage("arrows_flip2.png");
    139     _arrowsTex->setPixels(CF_RGB, DT_UBYTE, pTextureImage->width, pTextureImage->height, (void*) pTextureImage->imageData);
    140 
    141     //cvReleaseImage(&pTextureImage);
    142 #endif
    143 
    144 #endif
    14592    _arrowColor.set(1, 1, 0);
    14693
     
    155102    glDeleteFramebuffersEXT(1, &_fbo);
    156103
    157 #ifdef USE_NANOVIS_LIB
    158104    delete _arrowsTex;
    159 #else
    160     _arrowsTex->unref();
    161 #endif
     105
    162106    cgDestroyProgram(_particleFP);
    163107    cgDestroyProgram(_particleVP);
     
    173117
    174118    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbo);
    175    
     119
    176120    glViewport(0, 0, _renderTargetWidth, _renderTargetHeight);
    177121    glMatrixMode(GL_PROJECTION);
     
    190134                 _renderTargetWidth, _renderTargetHeight, 0,
    191135                 GL_RGBA, GL_FLOAT, NULL);
    192  
     136
    193137    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    194138                              GL_TEXTURE_RECTANGLE_NV, _tex, 0);
     
    280224
    281225    glPushMatrix();
    282  
     226
    283227    glScalef(_vfXscale,_vfYscale, _vfZscale);
    284228    glTranslatef(-0.5f, -0.5f, -0.5f);
     
    317261                    pos = _samplingPositions[index];
    318262                    pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
    319                    
     263
    320264                    glVertex3f(pos.x, pos.y, pos.z);
    321265                    glVertex3f(pos2.x, pos2.y, pos2.z);
     
    328272                    pos = _samplingPositions[index];
    329273                    pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos;
    330                    
     274
    331275                    glVertex3f(pos.x, pos.y, pos.z);
    332276                    glVertex3f(pos2.x, pos2.y, pos2.z);
     
    344288        glPointSize(20);                               
    345289        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
    346        
    347 #ifdef USE_NANOVIS_LIB
     290
    348291        _arrowsTex->activate();
    349 #else
    350         _arrowsTex->bind(0);
    351292        glEnable(GL_TEXTURE_2D);
    352 #endif
     293
    353294        glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 0.0f );
    354        
     295
    355296        glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 1.0f);
    356297        glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, 100.0f);
    357298        glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
    358        
     299
    359300        cgGLBindProgram(_particleVP);
    360301        cgGLBindProgram(_particleFP);
    361302        cgGLEnableProfile(CG_PROFILE_VP40);
    362303        cgGLEnableProfile(CG_PROFILE_FP40);
    363        
     304
    364305        cgGLSetTextureParameter(_vectorParticleParam, _vectorFieldGraphicsID);
    365306        cgGLEnableTextureParameter(_vectorParticleParam);
    366        
    367        
     307
    368308        //cgSetParameter1f(_mvTanHalfFOVParam, -tan(_fov * 0.5) * _screenHeight * 0.5);
    369        
     309
    370310        cgGLSetStateMatrixParameter(_mvpParticleParam,
    371311                                    CG_GL_MODELVIEW_PROJECTION_MATRIX,
     
    374314                                    CG_GL_MODELVIEW_MATRIX,
    375315                                    CG_GL_MATRIX_IDENTITY);
    376        
     316
    377317        glEnableClientState(GL_VERTEX_ARRAY);
    378318        glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vertexBufferGraphicsID);
    379319        glVertexPointer(3, GL_FLOAT, 0, 0);
    380320        //glEnableClientState(GL_COLOR_ARRAY);
    381        
     321
    382322        // TBD..
    383323        glDrawArrays(GL_POINTS, 0, _pointCount);
    384324        glPointSize(1);
    385325        glDrawArrays(GL_POINTS, 0, _pointCount);
    386        
     326
    387327        glDisableClientState(GL_VERTEX_ARRAY);
    388        
     328
    389329        cgGLDisableProfile(CG_PROFILE_VP40);
    390330        cgGLDisableProfile(CG_PROFILE_FP40);
    391        
     331
    392332        glDepthMask(GL_TRUE);
    393        
     333
    394334        glDisable(GL_POINT_SPRITE_NV);
    395335        glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
    396        
     336
    397337        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    398338        glDisable(GL_BLEND);
    399 #ifdef USE_NANOVIS_LIB
    400         _arrowsTex->deactivate();
    401 #else
    402         _arrowsTex->unbind();
    403 #endif
     339        _arrowsTex->deactivate();
    404340    }
    405341    glPopMatrix();
    406342}
    407 
    408343
    409344void
     
    416351    _vfZscale = zScale;
    417352
    418     //_dirty = true;
    419 }
    420 
    421 void VelocityArrowsSlice::tickCountForMinSizeAxis(int tickCount)
    422 {
    423     _tickCountForMinSizeAxis = tickCount;
    424        
    425353    //_dirty = true;
    426354}
     
    561489    }
    562490}
    563 
    564 void VelocityArrowsSlice::slicePos(float pos)
    565 {
    566     _slicePos = pos;
    567     _dirty = true;
    568 }
  • trunk/packages/vizservers/nanovis/VelocityArrowsSlice.h

    r2822 r2831  
    77#include <vector>
    88
    9 #define USE_NANOVIS_LIB
    10 
    11 #ifdef USE_NANOVIS_LIB
    129#include "Texture2D.h"
    1310#include "Vector3.h"
    14 #else
    15 #include <vr3d/vrTexture2D.h>
    16 
    17 typedef vrTexture2D Texture2D;
    18 
    19 class Vector3
    20 {
    21 public:
    22     float x, y, z;
    23 
    24     Vector3() :
    25         x(0.0f), y(0.0f), z(0.0f)
    26     {}
    27 
    28     Vector3(float x1, float y1, float z1) :
    29         x(x1), y(y1), z(z1)
    30     {}
    31 
    32     Vector3 operator*(float scale)
    33     {
    34         Vector3 vec;
    35         vec.x = x * scale;
    36         vec.y = y * scale;
    37         vec.z = z * scale;
    38         return vec;
    39     }
    40 
    41     Vector3 scale(const Vector3& scale)
    42     {
    43         Vector3 vec;
    44         vec.x = x * scale.x;
    45         vec.y = y * scale.y;
    46         vec.z = z * scale.z;
    47         return vec;
    48     }
    49 
    50     Vector3 operator*(const Vector3& scale)
    51     {
    52         Vector3 vec;
    53         vec.x = x * scale.x;
    54         vec.y = y * scale.y;
    55         vec.z = z * scale.z;
    56         return vec;
    57     }
    58 
    59     friend Vector3 operator+(const Vector3& value1, const Vector3& value2);
    60 
    61     void set(float x1, float y1, float z1)
    62     {
    63         x = x1; y = y1; z = z1;
    64     }
    65 };
    66 
    67 inline Vector3 operator+(const Vector3& value1, const Vector3& value2)
    68 {
    69     return Vector3(value1.x + value2.x, value1.y + value2.y, value1.z + value2.z);
    70 }
    71 
    72 #endif
    73 
    7411
    7512class VelocityArrowsSlice
     
    8017        GLYPHS,
    8118    };
     19
     20    VelocityArrowsSlice();
     21
     22    ~VelocityArrowsSlice();
     23
     24    void vectorField(unsigned int vfGraphicsID, float xScale, float yScale, float zScale);
     25
     26    void axis(int axis);
     27
     28    int axis() const
     29    {
     30        return _axis;
     31    }
     32
     33    void slicePos(float pos)
     34    {
     35        _slicePos = pos;
     36        _dirty = true;
     37    }
     38
     39    float slicePos() const
     40    {
     41        return _slicePos;
     42    }
     43
     44    void queryVelocity();
     45
     46    void render();
     47
     48    void enabled(bool enabled)
     49    {
     50        _enabled = enabled;
     51    }
     52
     53    bool enabled() const
     54    {
     55        return _enabled;
     56    }
     57
     58    void tickCountForMinSizeAxis(int tickCount)
     59    {
     60        _tickCountForMinSizeAxis = tickCount;
     61    }
     62
     63    int tickCountForMinSizeAxis() const
     64    {
     65        return _tickCountForMinSizeAxis;
     66    }
     67
     68    void arrowColor(const Vector3& color)
     69    {
     70        _arrowColor = color;
     71    }
     72
     73    void renderMode(RenderMode mode)
     74    {
     75        _renderMode = mode;
     76        _dirty = true;
     77    }
     78
     79    RenderMode renderMode() const
     80    {
     81        return _renderMode;
     82    }
    8283
    8384private:
     
    133134
    134135    void createRenderTarget();
     136
    135137    void computeSamplingTicks();
    136 
    137 public:
    138     VelocityArrowsSlice();
    139     ~VelocityArrowsSlice();
    140 
    141     void vectorField(unsigned int vfGraphicsID, float xScale, float yScale, float zScale);
    142     void axis(int axis);
    143     int axis() const;
    144     void slicePos(float pos);
    145     float slicePos() const;
    146     void queryVelocity();
    147     void render();
    148     void enabled(bool enabled)
    149     {
    150         _enabled = enabled;
    151     }
    152     bool enabled() const
    153     {
    154         return _enabled;
    155     }
    156     void tickCountForMinSizeAxis(int tickCount);
    157     int tickCountForMinSizeAxis() const;
    158     void arrowColor(const Vector3& color);
    159     void renderMode(RenderMode mode);
    160     RenderMode renderMode() const;
    161138};
    162139
    163 inline int VelocityArrowsSlice::axis() const
    164 {
    165     return _axis;
    166 }
    167 
    168 inline float VelocityArrowsSlice::slicePos() const
    169 {
    170     return _slicePos;
    171 }
    172 
    173 
    174 inline int VelocityArrowsSlice::tickCountForMinSizeAxis() const
    175 {
    176     return _tickCountForMinSizeAxis;
    177 }
    178 
    179 inline void VelocityArrowsSlice::arrowColor(const Vector3& color)
    180 {
    181     _arrowColor = color;
    182 }
    183 
    184 inline void VelocityArrowsSlice::renderMode(VelocityArrowsSlice::RenderMode mode)
    185 {
    186     _renderMode = mode;
    187     _dirty = true;
    188 }
    189 
    190 inline VelocityArrowsSlice::RenderMode VelocityArrowsSlice::renderMode() const
    191 {
    192     return _renderMode;
    193 }
    194  
    195140#endif
  • trunk/packages/vizservers/nanovis/config.h

    r2827 r2831  
    3131 * we'll rely on developers to set this in their respective sandboxes.
    3232 */
    33 //#define PROTOTYPE             0
    34 #define PROTOTYPE               1
     33#define PROTOTYPE               0
    3534
    3635#define NEW_FLOW_ENGINE         1
  • trunk/packages/vizservers/nanovis/define.h

    r2822 r2831  
    1414 * ======================================================================
    1515 */
    16 #ifndef _DEFINE_H_
    17 #define _DEFINE_H_
     16#ifndef DEFINE_H
     17#define DEFINE_H
    1818
    1919#include <GL/glew.h>
  • trunk/packages/vizservers/nanovis/dxReader.cpp

    r2828 r2831  
    1818 * ======================================================================
    1919 */
    20 
    21 // common dx functions
    22 #include "dxReaderCommon.h"
    23 
    2420#include <stdio.h>
    2521#include <math.h>
     
    3127#include <unistd.h>
    3228
     29#include <RpField1D.h>
     30#include <RpFieldRect3D.h>
     31#include <RpFieldPrism3D.h>
     32
     33// common dx functions
     34#include "dxReaderCommon.h"
     35
    3336#include "nanovis.h"
    34 #include "RpField1D.h"
    35 #include "RpFieldRect3D.h"
    36 #include "RpFieldPrism3D.h"
    37 #include <Unirect.h>
    38 
    39 //transfer function headers
     37#include "Unirect.h"
    4038#include "ZincBlendeVolume.h"
    4139#include "NvZincBlendeReconstructor.h"
  • trunk/packages/vizservers/nanovis/global.h

    r2822 r2831  
    1111 * ======================================================================
    1212 */
    13 #ifndef _GLOBAL_H_
    14 #define _GLOBAL_H_
     13#ifndef GLOBAL_H
     14#define GLOBAL_H
    1515
    1616#include <GL/glew.h>
    1717#include <Cg/cgGL.h>
    1818
    19 #include <Trace.h>
     19#include "Trace.h"
    2020
    2121inline void
     
    4242
    4343extern CGprogram LoadCgSourceProgram(CGcontext context, const char *filename,
    44         CGprofile profile, const char *entryPoint);
     44                                     CGprofile profile, const char *entryPoint);
    4545
    4646#endif
  • trunk/packages/vizservers/nanovis/imgLoaders/BMPImageLoaderImpl.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #include "BMPImageLoaderImpl.h"
    3 #include "Image.h"
    42#include <stdio.h>
    53#include <memory.h>
    64#include <stdlib.h>
     5
     6#include "BMPImageLoaderImpl.h"
     7#include "Image.h"
    78
    89BMPImageLoaderImpl::BMPImageLoaderImpl()
     
    1516
    1617// I referred to cjbackhouse@hotmail.com                www.backhouse.tk
    17 Image* BMPImageLoaderImpl::load(const char* fileName)
     18Image *BMPImageLoaderImpl::load(const char *fileName)
    1819{
    1920    printf("BMP loader\n");
    2021    fflush(stdout);
    21     Image* image = 0;
     22    Image *image = NULL;
    2223
    2324    printf("opening image file \"%s\"\n", fileName);
    24     FILE* f = fopen(fileName, "rb");
     25    FILE *f = fopen(fileName, "rb");
    2526
    2627    if (!f)  {
     
    3132    char header[54];
    3233    if (fread(&header, 54, 1, f) != 1) {
    33         printf("can't read header of BMP file\n");
    34         return 0;
    35     };
     34        printf("can't read header of BMP file\n");
     35        return 0;
     36    }
    3637
    3738    if (header[0] != 'B' ||  header[1] != 'M') {
    38         printf("File is not BMP format\n");
    39         return 0;
     39        printf("File is not BMP format\n");
     40        return 0;
    4041    }
    4142
    4243    //it seems gimp sometimes makes its headers small, so we have to do
    4344    //this. hence all the fseeks
    44     int offset=*(unsigned int*)(header+10);
    45        
    46     const unsigned int width =*(int*) (header+18);
    47     const unsigned int height =*(int*) (header+22);
     45    int offset = *(unsigned int*)(header+10);
    4846
    49     int bits=int(header[28]);           //colourdepth
     47    const unsigned int width = *(int*)(header+18);
     48    const unsigned int height = *(int*)(header+22);
     49
     50    int bits = int(header[28]);           //colourdepth
    5051
    5152    printf("image width = %d height = %d bits=%d\n", width, height, bits);
    5253    fflush(stdout);
    53    
     54
    5455    image = new Image(width, height, _targetImageFormat,
    55                       Image::IMG_UNSIGNED_BYTE, 0);
     56                      Image::IMG_UNSIGNED_BYTE, NULL);
    5657
    5758    printf("image created\n");
    5859    fflush(stdout);
    5960
    60     unsigned char* bytes = (unsigned char*) image->getImageBuffer();
     61    unsigned char *bytes = (unsigned char *)image->getImageBuffer();
    6162    memset(bytes, 0, sizeof(unsigned char) * width * height * _targetImageFormat);
    6263
     
    6465    fflush(stdout);
    6566
    66     unsigned int x,y;
     67    unsigned int x, y;
    6768    unsigned char cols[256*4];  //colourtable
    68     switch(bits) {
     69    switch (bits) {
    6970    case 24:
    70         fseek(f,offset,SEEK_SET);
    71         if (_targetImageFormat == Image::IMG_RGB) {
    72             if (fread(bytes,width*height*3,1,f) != 1) {
    73                 fprintf(stderr, "can't read image data\n");
    74             }
    75             for(x=0;x<width*height*3;x+=3)  { //except the format is BGR, grr
    76                 unsigned char temp = bytes[x];
    77                 bytes[x] = bytes[x+2];
    78                 bytes[x+2] = temp;
    79             }
    80         } else if (_targetImageFormat == Image::IMG_RGBA) {
    81             char* buff = (char*) malloc(width * height * sizeof(unsigned char) * 3);
    82             if (fread(buff,width*height*3,1,f) != 1) {
    83                 fprintf(stderr, "can't read BMP image data\n");
    84             }
    85             for(x=0, y = 0;x<width*height*3;x+=3, y+=4)    {       //except the format is BGR, grr
    86                 bytes[y] = buff[x+2];
    87                 bytes[y+2] = buff[x];
    88                 bytes[y+3] = 255;
    89             }
    90             free(buff);
    91         }
    92         break;
     71        fseek(f, offset, SEEK_SET);
     72        if (_targetImageFormat == Image::IMG_RGB) {
     73            if (fread(bytes, width*height*3, 1, f) != 1) {
     74                fprintf(stderr, "can't read image data\n");
     75            }
     76            for (x = 0; x < width*height*3; x += 3)  { //except the format is BGR, grr
     77                unsigned char temp = bytes[x];
     78                bytes[x] = bytes[x+2];
     79                bytes[x+2] = temp;
     80            }
     81        } else if (_targetImageFormat == Image::IMG_RGBA) {
     82            char *buff = (char*)malloc(width * height * sizeof(unsigned char) * 3);
     83            if (fread(buff, width*height*3, 1, f) != 1) {
     84                fprintf(stderr, "can't read BMP image data\n");
     85            }
     86            for (x = 0, y = 0; x < width*height*3; x += 3, y += 4) {       //except the format is BGR, grr
     87                bytes[y] = buff[x+2];
     88                bytes[y+2] = buff[x];
     89                bytes[y+3] = 255;
     90            }
     91            free(buff);
     92        }
     93        break;
    9394    case 32:
    94         fseek(f,offset,SEEK_SET);
    95         if (_targetImageFormat == Image::IMG_RGBA) {
    96             if (fread(bytes,width*height*4,1,f) != 1) {
    97                 fprintf(stderr, "can't read image data\n");
    98             }
    99             for(x=0;x<width*height*4;x+=4)  { //except the format is BGR, grr
    100                 unsigned char temp = bytes[x];
    101                 bytes[x] = bytes[x+2];
    102                 bytes[x+2] = temp;
    103             }
    104         }
    105         else if (_targetImageFormat == Image::IMG_RGB) {
    106             char* buff = (char*) malloc(width * height * sizeof(unsigned char) * 3);
    107             if (fread(buff,width*height*4,1,f) != 1) {
    108                 fprintf(stderr, "can't read BMP image data\n");
    109             }
    110             for(x=0, y = 0;x<width*height*4;x+=4, y+=3)     {       //except the format is BGR, grr
    111                 bytes[y] = buff[x+2];
    112                 bytes[y+2] = buff[x];
    113             }
    114             free(buff);
    115         }
    116         break;
     95        fseek(f, offset, SEEK_SET);
     96        if (_targetImageFormat == Image::IMG_RGBA) {
     97            if (fread(bytes, width*height*4, 1, f) != 1) {
     98                fprintf(stderr, "can't read image data\n");
     99            }
     100            for (x = 0; x < width*height*4; x += 4)  { //except the format is BGR, grr
     101                unsigned char temp = bytes[x];
     102                bytes[x] = bytes[x+2];
     103                bytes[x+2] = temp;
     104            }
     105        } else if (_targetImageFormat == Image::IMG_RGB) {
     106            char *buff = (char*)malloc(width * height * sizeof(unsigned char) * 3);
     107            if (fread(buff, width*height*4, 1, f) != 1) {
     108                fprintf(stderr, "can't read BMP image data\n");
     109            }
     110            for (x = 0, y = 0; x < width*height*4; x += 4, y += 3) {       //except the format is BGR, grr
     111                bytes[y] = buff[x+2];
     112                bytes[y+2] = buff[x];
     113            }
     114            free(buff);
     115        }
     116        break;
    117117    case 8:
    118         if (fread(cols,256 * 4,1,f) != 1) {
    119             fprintf(stderr, "can't read colortable from BMP file\n");
    120         }
    121         fseek(f,offset,SEEK_SET); 
    122         for(y=0;y<height;++y) { //(Notice 4bytes/col for some reason)
    123             for(x=0;x<width;++x) {
    124                 unsigned char byte;                 
    125                 if (fread(&byte,1,1,f) != 1) {
    126                     fprintf(stderr, "error reading BMP file\n");
    127                 }
    128                 for(int c=0; c< 3; ++c) {
    129                     //bytes[(y*width+x)*3+c] = cols[byte*4+2-c];        //and look up in the table
    130                     bytes[(y*width+x)*_targetImageFormat + c] = cols[byte*4+2-c];       //and look up in the table
    131                 }
    132             }
    133         }
    134         break;
    135         /*
    136           case(4):
    137           fread(cols,16*4,1,f);
    138           fseek(f,offset,SEEK_SET);
    139           for(y=0;y<256;++y)
    140           for(x=0;x<256;x+=2)
    141           {
    142           BYTE byte;
    143           fread(&byte,1,1,f);                                               //as above, but need to exract two
    144          
    145           for(c=0;c<_targetImageFormat;++c)                                         //pixels from each byte
    146           bmp.pixel(x,y,c)=cols[byte/16*4+2-c];
     118        if (fread(cols, 256 * 4, 1, f) != 1) {
     119            fprintf(stderr, "can't read colortable from BMP file\n");
     120        }
     121        fseek(f,offset,SEEK_SET); 
     122        for (y = 0; y < height; ++y) {  //(Notice 4bytes/col for some reason)
     123            for (x = 0; x < width; ++x) {
     124                unsigned char byte;                 
     125                if (fread(&byte, 1, 1, f) != 1) {
     126                    fprintf(stderr, "error reading BMP file\n");
     127                }
     128                for (int c = 0; c < 3; ++c) {
     129                    //bytes[(y*width+x)*3+c] = cols[byte*4+2-c];        //and look up in the table
     130                    bytes[(y*width+x)*_targetImageFormat + c] = cols[byte*4+2-c];       //and look up in the table
     131                }
     132            }
     133        }
     134        break;
     135    }
    147136
    148           for(c=0;c<_targetImageFormat;++c)
    149           bmp.pixel(x+1,y,c)=cols[byte%16*4+2-c];
    150         */
    151     }
    152    
    153137    printf("image initialized\n");
    154138    fflush(stdout);
  • trunk/packages/vizservers/nanovis/imgLoaders/BMPImageLoaderImpl.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __BMP_IMAGE_LOADER_IMPL_H__
    3 #define __BMP_IMAGE_LOADER_IMPL_H__
     2#ifndef BMP_IMAGE_LOADER_IMPL_H
     3#define BMP_IMAGE_LOADER_IMPL_H
    44
    55#include <ImageLoaderImpl.h>
    66
    7 class BMPImageLoaderImpl : public ImageLoaderImpl {
    8 public :
     7class BMPImageLoaderImpl : public ImageLoaderImpl
     8{
     9public:
    910    BMPImageLoaderImpl();
    10     ~BMPImageLoaderImpl();
    1111
    12 public :
    13     virtual Image* load(const char* fileName);
     12    virtual ~BMPImageLoaderImpl();
    1413
     14    virtual Image *load(const char *fileName);
    1515};
    16 #endif /* __BMP_IMAGE_LOADER_IMPL_H__ */
     16#endif
  • trunk/packages/vizservers/nanovis/imgLoaders/Image.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #include "Image.h"
    32#include <memory.h>
    43#include <stdlib.h>
    54
     5#include "Image.h"
     6
    67Image::Image(const unsigned int width, const unsigned int height,
    7              const ImageFormat format, const Image::DataType type, void* data ) :
    8     _width(width), 
    9     _height(height), 
     8             const ImageFormat format, const Image::DataType type, void *data) :
     9    _width(width),
     10    _height(height),
    1011    _format(format),
    11     _dataType(type) 
     12    _dataType(type)
    1213{
    13     switch (type)
    14     {
    15     case IMG_UNSIGNED_BYTE :
     14    switch (type) {
     15    case IMG_UNSIGNED_BYTE:
    1616        _dataTypeByteSize = 1;
    1717        break;
    18     case IMG_FLOAT :
     18    case IMG_FLOAT:
    1919        _dataTypeByteSize = 4;
    2020        break;
     
    2424    _dataBuffer = malloc(width * height * format * _dataTypeByteSize);
    2525
    26     if (data != 0)
    27     {
     26    if (data != NULL) {
    2827        memcpy(_dataBuffer, data, width *height * format * _dataTypeByteSize);
    29     }
    30     else
    31     {
     28    } else {
    3229        memset(_dataBuffer, 0, width * height * format * _dataTypeByteSize);
    3330    }
    3431}
    35 
    3632
    3733Image::~Image()
  • trunk/packages/vizservers/nanovis/imgLoaders/Image.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __IMAGE_H__
    3 #define __IMAGE_H__
     2#ifndef IMAGE_H
     3#define IMAGE_H
    44
    5 class Image {
    6 public :
     5class Image
     6{
     7public:
    78    enum DataType {
    89        IMG_UNSIGNED_BYTE,
     
    1516    };
    1617
    17 private :
     18    Image(const unsigned int width, const unsigned int height,
     19          const ImageFormat format, const DataType dataType, void *data = NULL);
     20
     21    ~Image();
     22
     23    unsigned int getWidth() const
     24    {
     25        return _width;
     26    }
     27
     28    unsigned int getHeight() const
     29    {
     30        return _height;
     31    }
     32
     33    unsigned int getComponentCount() const
     34    {
     35        return (unsigned int)_format;
     36    }
     37
     38    unsigned int getDataTypeByteSize() const
     39    {
     40        return _dataTypeByteSize;
     41    }
     42
     43    DataType getDataType() const
     44    {
     45        return _dataType;
     46    }
     47
     48    void *getImageBuffer()
     49    {
     50        return _dataBuffer;
     51    }
     52
     53private:
    1854    const unsigned int _width;
    1955    const unsigned int _height;
     
    2157    DataType _dataType;
    2258    unsigned int _dataTypeByteSize;
    23     void* _dataBuffer;
    24 public :
    25 
    26     Image(const unsigned int width, const unsigned int height, const ImageFormat format, const DataType dataType, void* data = 0);
    27     ~Image();
    28 
    29     unsigned int getWidth() const;
    30     unsigned int getHeight() const;
    31     unsigned int getComponentCount() const;
    32     unsigned int getDataTypeByteSize() const;
    33     DataType getDataType() const;
    34     void* getImageBuffer();
     59    void *_dataBuffer;
    3560};
    3661
    37 inline  void* Image::getImageBuffer()
    38 {
    39     return _dataBuffer;
    40 }
     62#endif
    4163
    42 inline unsigned int Image::getWidth() const
    43 {
    44     return _width;
    45 }
    46 
    47 inline unsigned int Image::getHeight() const
    48 {
    49     return _height;
    50 }
    51 
    52 inline unsigned int Image::getComponentCount() const
    53 {
    54     return (unsigned int) _format;
    55 }
    56 
    57 inline Image::DataType Image::getDataType() const
    58 {
    59     return _dataType;
    60 }
    61 
    62 inline unsigned int Image::getDataTypeByteSize() const
    63 {
    64     return _dataTypeByteSize;
    65 }
    66 
    67 #endif //
    68 
  • trunk/packages/vizservers/nanovis/imgLoaders/ImageLoader.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2#include <stdio.h>
     3
     4#include <map>
     5#include <string>
     6
    27#include "ImageLoader.h"
    38#include "ImageLoaderImpl.h"
    4 #include <map>
    5 #include <string>
    6 #include <stdio.h>
    79
    8 ImageLoader::ImageLoader()
    9     : _loaderImpl(0)
     10ImageLoader::ImageLoader() :
     11    _loaderImpl(NULL)
    1012{
    1113}
    1214
    13 Image* ImageLoader::load(const char* fileName)
     15Image *ImageLoader::load(const char* fileName, const Image::ImageFormat format)
    1416{
    15     if (_loaderImpl)
    16     {
    17         _loaderImpl->_targetImageFormat = Image::IMG_RGB;
    18         return _loaderImpl->load(fileName);
    19     }
    20    
    21     return 0;
    22 }
    23 
    24 Image* ImageLoader::load(const char* fileName, const Image::ImageFormat format)
    25 {
    26     if (_loaderImpl)
    27     {
     17    if (_loaderImpl) {
    2818        _loaderImpl->_targetImageFormat = format;
    2919        return _loaderImpl->load(fileName);
    3020    }
    31    
     21
    3222    return 0;
    3323}
    34 
    35 
  • trunk/packages/vizservers/nanovis/imgLoaders/ImageLoader.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __IMAGE_LOADER_H__
    3 #define __IMAGE_LOADER_H__
     2#ifndef IMAGE_LOADER_H
     3#define IMAGE_LOADER_H
    44
    55#include <map>
     6
    67#include <Image.h>
    78
     
    910class Image;
    1011
    11 class ImageLoader {
     12class ImageLoader
     13{
     14public:
    1215    friend class ImageLoaderFactory;
    1316
    14     ImageLoaderImpl* _loaderImpl;
    15 public :
    1617    ImageLoader();
    1718
    18 public :
    19     Image* load(const char* fileName);
    20     Image* load(const char* fileName, const Image::ImageFormat targetFormat);
     19    Image *load(const char *fileName, const Image::ImageFormat targetFormat = Image::IMG_RGB);
    2120
    22 private :
    23     void setLoaderImpl(ImageLoaderImpl* loaderImpl);
     21private:
     22    void setLoaderImpl(ImageLoaderImpl *loaderImpl)
     23    {
     24        _loaderImpl = loaderImpl;
     25    }
     26
     27    ImageLoaderImpl * _loaderImpl;
    2428};
    2529
    26 inline void ImageLoader::setLoaderImpl(ImageLoaderImpl* loaderImpl)
    27 {
    28     _loaderImpl= loaderImpl;
    29 }
     30#endif
    3031
    31 #endif //
    32 
  • trunk/packages/vizservers/nanovis/imgLoaders/ImageLoaderFactory.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2#include <stdio.h>
     3
     4#include <map>
     5#include <string>
     6
    27#include "ImageLoader.h"
    38#include "ImageLoaderImpl.h"
    49#include "ImageLoaderFactory.h"
    5 #include <map>
    6 #include <string>
    7 #include <stdio.h>
    810
    9 ImageLoaderFactory* ImageLoaderFactory::_instance = 0;
     11ImageLoaderFactory *ImageLoaderFactory::_instance = NULL;
    1012
    1113ImageLoaderFactory::ImageLoaderFactory()
     
    1315}
    1416
    15 ImageLoaderFactory* ImageLoaderFactory::getInstance()
     17ImageLoaderFactory *ImageLoaderFactory::getInstance()
    1618{
    17     if (_instance == 0)
    18     {
     19    if (_instance == NULL) {
    1920        _instance = new ImageLoaderFactory();
    2021    }
     
    2324}
    2425
    25 void ImageLoaderFactory::addLoaderImpl(const std::string& ext, ImageLoaderImpl* loaderImpl)
     26void ImageLoaderFactory::addLoaderImpl(const std::string& ext, ImageLoaderImpl *loaderImpl)
    2627{
    27     std::map< std::string, ImageLoaderImpl*>::iterator iter;
     28    std::map<std::string, ImageLoaderImpl *>::iterator iter;
    2829    iter = _loaderImpls.find(ext);
    29     if (iter == _loaderImpls.end())
    30     {
     30    if (iter == _loaderImpls.end()) {
    3131        _loaderImpls[ext] = loaderImpl;
    32     }
    33     else
    34     {
    35         printf("conflick data loader for .%s files\n", ext.c_str());
     32    } else {
     33        printf("conflicting data loader for .%s files\n", ext.c_str());
    3634        return;
    3735    }
    3836}
    3937
    40 ImageLoader* ImageLoaderFactory::createLoader(const std::string& ext)
     38ImageLoader *ImageLoaderFactory::createLoader(const std::string& ext)
    4139{
    42     std::map< std::string, ImageLoaderImpl*>::iterator iter;
     40    std::map<std::string, ImageLoaderImpl *>::iterator iter;
    4341    iter = _loaderImpls.find(ext);
    44     if (iter != _loaderImpls.end())
    45     {
    46         ImageLoader* imageLoader = new ImageLoader();
     42    if (iter != _loaderImpls.end()) {
     43        ImageLoader *imageLoader = new ImageLoader();
    4744        imageLoader->setLoaderImpl((*iter).second);
    4845        return imageLoader;
    49     }
    50     else
    51     {
     46    } else {
    5247        printf("%s file not supported\n", ext.c_str());
    5348    }
  • trunk/packages/vizservers/nanovis/imgLoaders/ImageLoaderFactory.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __IMAGE_LOADER_FACTORY_H__
    3 #define __IMAGE_LOADER_FACTORY_H__
     2#ifndef IMAGE_LOADER_FACTORY_H
     3#define IMAGE_LOADER_FACTORY_H
    44
    55#include <map>
     
    1010class ImageLoader;
    1111
    12 class ImageLoaderFactory {
    13     std::map< std::string, ImageLoaderImpl*> _loaderImpls;
     12class ImageLoaderFactory
     13{
     14public:
     15    void addLoaderImpl(const std::string& ext, ImageLoaderImpl *loaderImpl);
     16    ImageLoader *createLoader(const std::string& ext);
    1417
    15     static ImageLoaderFactory* _instance;
     18    static ImageLoaderFactory *getInstance();
     19
    1620protected :
    1721    ImageLoaderFactory();
    1822    ~ImageLoaderFactory();
    1923
    20 public :
    21     static ImageLoaderFactory* getInstance();
    22 
    23 public :
    24     void addLoaderImpl(const std::string& ext, ImageLoaderImpl* loaderImpl);
    25     ImageLoader* createLoader(const std::string& ext);
     24private:
     25    std::map<std::string, ImageLoaderImpl *> _loaderImpls;
     26    static ImageLoaderFactory *_instance;
    2627};
    2728
    28 #endif //
     29#endif
  • trunk/packages/vizservers/nanovis/imgLoaders/ImageLoaderImpl.cpp

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2#include <stdio.h>
     3
    24#include "ImageLoaderImpl.h"
    3 #include <stdio.h>
    45
    56ImageLoaderImpl::ImageLoaderImpl()
     
    1011{
    1112}
    12 
    13 Image* ImageLoaderImpl::load(const char* filename)
    14 {
    15     Image* image = 0;
    16     printf("abstrac function is called ImageLoaderImpl::load\n");
    17     fflush(stdout);
    18     return image;
    19 }
  • trunk/packages/vizservers/nanovis/imgLoaders/ImageLoaderImpl.h

    r2798 r2831  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __IMAGE_LOADER_IMPL_H__
    3 #define __IMAGE_LOADER_IMPL_H__
     2#ifndef IMAGE_LOADER_IMPL_H
     3#define IMAGE_LOADER_IMPL_H
    44
    55#include <Image.h>
    66
    7 class ImageLoaderImpl {
     7class ImageLoaderImpl
     8{
     9public:
    810    friend class ImageLoader;
    911
    10 protected :
     12    ImageLoaderImpl();
     13
     14    virtual ~ImageLoaderImpl();
     15
     16protected:
    1117    Image::ImageFormat _targetImageFormat;
    1218
    13 public :
    14     ImageLoaderImpl();
    15     virtual ~ImageLoaderImpl();
    16 
    17 public :
    18     virtual Image* load(const char* fileName);
     19public:
     20    virtual Image *load(const char *fileName) = 0;
    1921};
    2022
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r2828 r2831  
    1919#include <errno.h>
    2020#include <fcntl.h>
    21 #include <fstream>
    2221#include <getopt.h>
    23 #include <iostream>
    24 #include <cmath>
    2522#include <memory.h>
    2623#include <signal.h>
    27 #include <sstream>
    28 #include <cstdio>
    29 #include <cstdlib>
    30 #include <string>
    3124#include <sys/resource.h>
    3225#include <sys/stat.h>
     
    3831#include <unistd.h>
    3932
     33#include <cstdlib>
     34#include <cstdio>
     35#include <cmath>
     36
     37#include <iostream>
     38#include <fstream>
     39#include <sstream>
     40#include <string>
     41
     42#include <RpField1D.h>
     43#include <RpFieldRect3D.h>
     44#include <RpFieldPrism3D.h>
     45#include <RpEncode.h>
     46
     47#include <R2/R2FilePath.h>
     48#include <R2/R2Fonts.h>
     49
     50#include <vrutil/vrFilePath.h>
     51
     52#include <BMPImageLoaderImpl.h>
     53#include <ImageLoaderFactory.h>
     54
     55#include <GL/glew.h>
     56#include <GL/glut.h>
     57
     58#include "nanovis.h"
     59#include "define.h"
     60
     61#include "FlowCmd.h"
     62#include "Grid.h"
     63#include "HeightMap.h"
     64#include "NvCamera.h"
     65#include "NvColorTableRenderer.h"
     66#include "NvEventLog.h"
     67#include "NvFlowVisRenderer.h"
     68#include "NvLIC.h"
     69#include "NvZincBlendeReconstructor.h"
     70#include "PerfQuery.h"
     71#include "PlaneRenderer.h"
    4072#ifdef USE_POINTSET_RENDERER
    4173#include "PointSetRenderer.h"
    4274#include "PointSet.h"
    4375#endif
    44 
    45 #include <NvLIC.h>
    46 #include <Trace.h>
    47 
    48 #include "nanovis.h"
    49 #include "define.h"
    50 #include "RpField1D.h"
    51 #include "RpFieldRect3D.h"
    52 #include "RpFieldPrism3D.h"
    53 #include "RpEncode.h"
    54 
     76#include "RenderContext.h"
     77#include "Switch.h"
     78#include "Trace.h"
     79#include "Unirect.h"
     80#include "VelocityArrowsSlice.h"
     81#include "VolumeInterpolator.h"
     82#include "VolumeRenderer.h"
    5583#include "ZincBlendeVolume.h"
    56 #include "NvColorTableRenderer.h"
    57 #include "NvEventLog.h"
    58 #include "NvZincBlendeReconstructor.h"
    59 #include "NvFlowVisRenderer.h"
    60 #include "HeightMap.h"
    61 #include "Grid.h"
    62 #include "VolumeInterpolator.h"
    63 #include <RenderContext.h>
    64 #include <vrutil/vrFilePath.h>
    65 
    66 #include <BMPImageLoaderImpl.h>
    67 #include <ImageLoaderFactory.h>
    68 
    69 // R2 headers
    70 #include <R2/R2FilePath.h>
    71 #include <R2/R2Fonts.h>
    72 
    73 #include "Unirect.h"
    74 #include "Switch.h"
    75 #include "FlowCmd.h"
    7684
    7785#define SIZEOF_BMP_HEADER   54
     
    105113Grid *NanoVis::grid = NULL;
    106114int NanoVis::updir = Y_POS;
    107 NvCamera* NanoVis::cam = NULL;
     115NvCamera *NanoVis::cam = NULL;
    108116Tcl_HashTable NanoVis::volumeTable;
    109117Tcl_HashTable NanoVis::heightmapTable;
    110 VolumeRenderer* NanoVis::vol_renderer = NULL;
     118VolumeRenderer *NanoVis::vol_renderer = NULL;
    111119#ifdef USE_POINTSET_RENDERER
    112 PointSetRenderer* NanoVis::pointset_renderer = NULL;
    113 std::vector<PointSet*> NanoVis::pointSet;
    114 #endif
    115 PlaneRenderer* NanoVis::plane_render = NULL;
    116 Texture2D* NanoVis::plane[10];
    117 NvColorTableRenderer* NanoVis::color_table_renderer = NULL;
     120PointSetRenderer *NanoVis::pointset_renderer = NULL;
     121std::vector<PointSet *> NanoVis::pointSet;
     122#endif
     123PlaneRenderer *NanoVis::plane_renderer = NULL;
     124// pointers to 2D planes, currently handle up 10
     125Texture2D *NanoVis::plane[10];
     126NvColorTableRenderer *NanoVis::color_table_renderer = NULL;
    118127
    119128#ifndef NEW_FLOW_ENGINE
    120 NvParticleRenderer* NanoVis::flowVisRenderer = NULL;
     129NvParticleRenderer *NanoVis::flowVisRenderer = NULL;
    121130#else
    122 NvFlowVisRenderer* NanoVis::flowVisRenderer = NULL;
    123 #endif
    124 VelocityArrowsSlice* NanoVis::velocityArrowsSlice = 0;
    125 
    126 graphics::RenderContext* NanoVis::renderContext = NULL;
    127 NvLIC* NanoVis::licRenderer = NULL;
    128 R2Fonts* NanoVis::fonts;
     131NvFlowVisRenderer *NanoVis::flowVisRenderer = NULL;
     132#endif
     133VelocityArrowsSlice *NanoVis::velocityArrowsSlice = 0;
     134
     135graphics::RenderContext *NanoVis::renderContext = NULL;
     136NvLIC *NanoVis::licRenderer = NULL;
     137R2Fonts *NanoVis::fonts;
    129138
    130139FILE *NanoVis::stdin = NULL;
     
    140149
    141150//frame buffer for final rendering
    142 GLuint NanoVis::final_color_tex = 0;
    143 GLuint NanoVis::final_depth_rb = 0;
    144 GLuint NanoVis::final_fbo = 0;
     151GLuint NanoVis::_final_color_tex = 0;
     152GLuint NanoVis::_final_depth_rb = 0;
     153GLuint NanoVis::_final_fbo = 0;
    145154int NanoVis::render_window = 0;       /* GLUT handle for the render window */
    146155int NanoVis::win_width = NPIX;        /* Width of the render window */
     
    177186Tcl_HashTable NanoVis::tfTable;
    178187
    179 // pointers to 2D planes, currently handle up 10
    180 
    181 
    182 PerfQuery* perf;                        //perfromance counter
     188PerfQuery *perf;                        //perfromance counter
    183189
    184190CGprogram m_passthru_fprog;
     
    509515    int old_height = win_height;
    510516
    511     plane_render->set_screen_size(width, height);
     517    plane_renderer->set_screen_size(width, height);
    512518    resize_offscreen_buffer(width, height);
    513519
     
    518524    }
    519525    plane[0] = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data);
    520     int index = plane_render->add_plane(plane[0], tf);
    521     plane_render->set_active_plane(index);
     526    int index = plane_renderer->add_plane(plane[0], tf);
     527    plane_renderer->set_active_plane(index);
    522528
    523529    offscreen_buffer_capture();
    524530    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    525     plane_render->render();
     531    plane_renderer->render();
    526532
    527533    // INSOO
     
    539545        assert(nWritten == 1);
    540546    }
    541     plane_render->remove_plane(index);
     547    plane_renderer->remove_plane(index);
    542548    resize_offscreen_buffer(old_width, old_height);
    543549
     
    553559    TRACE("in init_offscreen_buffer\n");
    554560    // Initialize a fbo for final display.
    555     glGenFramebuffersEXT(1, &final_fbo);
    556    
    557     glGenTextures(1, &final_color_tex);
    558     glBindTexture(GL_TEXTURE_2D, final_color_tex);
    559    
     561    glGenFramebuffersEXT(1, &_final_fbo);
     562
     563    glGenTextures(1, &_final_color_tex);
     564    glBindTexture(GL_TEXTURE_2D, _final_color_tex);
     565
    560566    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    561567    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
    567573                 GL_RGB, GL_INT, NULL);
    568574#endif
    569     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
    570     glGenRenderbuffersEXT(1, &final_depth_rb);
    571     glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
     575    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _final_fbo);
     576    glGenRenderbuffersEXT(1, &_final_depth_rb);
     577    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _final_depth_rb);
    572578    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
    573579                             win_width, win_height);
    574580    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    575                               GL_TEXTURE_2D, final_color_tex, 0);
     581                              GL_TEXTURE_2D, _final_color_tex, 0);
    576582    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
    577                                  GL_RENDERBUFFER_EXT, final_depth_rb);
     583                                 GL_RENDERBUFFER_EXT, _final_depth_rb);
    578584
    579585    GLenum status;
     
    585591    // Check framebuffer completeness at the end of initialization.
    586592    //CHECK_FRAMEBUFFER_STATUS();
    587    
     593
    588594    //assert(glGetError()==0);
    589595    TRACE("leaving init_offscreen_buffer\n");
    590596}
    591 
    592597
    593598//resize the offscreen buffer
     
    601606    win_width = w;
    602607    win_height = h;
    603    
     608
    604609    if (fonts) {
    605610        fonts->resize(w, h);
    606611    }
    607612    TRACE("screen_buffer size: %d %d\n", w, h);
    608    
     613
    609614    if (screen_buffer != NULL) {
    610615        delete [] screen_buffer;
    611616        screen_buffer = NULL;
    612617    }
    613    
     618
    614619    screen_buffer = new unsigned char[4*win_width*win_height];
    615620    assert(screen_buffer != NULL);
    616621   
    617622    //delete the current render buffer resources
    618     glDeleteTextures(1, &final_color_tex);
    619     glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
    620     glDeleteRenderbuffersEXT(1, &final_depth_rb);
     623    glDeleteTextures(1, &_final_color_tex);
     624    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _final_depth_rb);
     625    glDeleteRenderbuffersEXT(1, &_final_depth_rb);
    621626
    622627    TRACE("before deleteframebuffers\n");
    623     glDeleteFramebuffersEXT(1, &final_fbo);
     628    glDeleteFramebuffersEXT(1, &_final_fbo);
    624629
    625630    TRACE("reinitialize FBO\n");
    626631    //Reinitialize final fbo for final display
    627     glGenFramebuffersEXT(1, &final_fbo);
    628 
    629     glGenTextures(1, &final_color_tex);
    630     glBindTexture(GL_TEXTURE_2D, final_color_tex);
     632    glGenFramebuffersEXT(1, &_final_fbo);
     633
     634    glGenTextures(1, &_final_color_tex);
     635    glBindTexture(GL_TEXTURE_2D, _final_color_tex);
    631636
    632637    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
    640645#endif
    641646    TRACE("before bindframebuffer\n");
    642     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
     647    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _final_fbo);
    643648    TRACE("after bindframebuffer\n");
    644     glGenRenderbuffersEXT(1, &final_depth_rb);
    645     glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
     649    glGenRenderbuffersEXT(1, &_final_depth_rb);
     650    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _final_depth_rb);
    646651    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
    647652                             win_width, win_height);
    648653    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    649                               GL_TEXTURE_2D, final_color_tex, 0);
     654                              GL_TEXTURE_2D, _final_color_tex, 0);
    650655    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
    651                                  GL_RENDERBUFFER_EXT, final_depth_rb);
    652    
     656                                 GL_RENDERBUFFER_EXT, _final_depth_rb);
     657
    653658    GLenum status;
    654659    if (!CheckFBO(&status)) {
     
    661666    //change the camera setting
    662667    cam->set_screen_size(0, 0, win_width, win_height);
    663     plane_render->set_screen_size(win_width, win_height);
     668    plane_renderer->set_screen_size(win_width, win_height);
    664669
    665670    TRACE("leaving resize_offscreen_buffer(%d, %d)\n", w, h);
     
    677682    int w = 300;
    678683    int h = 200;
    679     float* data = new float[w*h];
     684    float *data = new float[w*h];
    680685
    681686    //procedurally make a gradient plane
    682     for(int j=0; j<h; j++){
    683         for(int i=0; i<w; i++){
     687    for (int j = 0; j < h; j++){
     688        for (int i = 0; i < w; i++){
    684689            data[w*j+i] = float(i)/float(w);
    685690        }
    686691    }
     692
    687693    NanoVis::plane[0] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, data);
    688694    delete[] data;
     
    820826    // create
    821827    renderContext = new graphics::RenderContext();
    822    
     828
    823829    //create an 2D plane renderer
    824     plane_render = new PlaneRenderer(g_context, win_width, win_height);
     830    plane_renderer = new PlaneRenderer(g_context, win_width, win_height);
    825831#if PROTOTYPE
    826832    make_test_2D_data();
    827 #endif  /* PROTOTYPE */
    828     plane_render->add_plane(plane[0], get_transfunc("default"));
     833    plane_renderer->add_plane(plane[0], get_transfunc("default"));
     834#endif
    829835
    830836    //assert(glGetError()==0);
     
    11921198    glEnable(GL_TEXTURE_2D);
    11931199    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    1194     glBindTexture(GL_TEXTURE_2D, final_color_tex);
     1200    glBindTexture(GL_TEXTURE_2D, _final_color_tex);
    11951201
    11961202    glViewport(0, 0, win_width, win_height);
     
    12121218    TRACE("leaving display_offscreen_buffer\n");
    12131219}
    1214 
    1215 
    12161220
    12171221#if 0
     
    12961300#endif
    12971301
    1298 
    12991302void
    13001303draw_3d_axis()
     
    16371640        //perf->disable();
    16381641
    1639         TRACE("in display: render heightmap\n");
    1640         Tcl_HashEntry *hPtr;
    1641         Tcl_HashSearch iter;
    1642         for (hPtr = Tcl_FirstHashEntry(&heightmapTable, &iter); hPtr != NULL;
    1643              hPtr = Tcl_NextHashEntry(&iter)) {
    1644             HeightMap *hmPtr;
    1645             hmPtr = (HeightMap *)Tcl_GetHashValue(hPtr);
    1646             if (hmPtr->isVisible()) {
    1647                 hmPtr->render(renderContext);
     1642        if (heightmapTable.numEntries > 0) {
     1643            TRACE("in display: render heightmap\n");
     1644            Tcl_HashEntry *hPtr;
     1645            Tcl_HashSearch iter;
     1646            for (hPtr = Tcl_FirstHashEntry(&heightmapTable, &iter); hPtr != NULL;
     1647                 hPtr = Tcl_NextHashEntry(&iter)) {
     1648                HeightMap *hmPtr;
     1649                hmPtr = (HeightMap *)Tcl_GetHashValue(hPtr);
     1650                if (hmPtr->isVisible()) {
     1651                    hmPtr->render(renderContext);
     1652                }
    16481653            }
    16491654        }
     
    16521657        //2D rendering mode
    16531658        perf->enable();
    1654         plane_render->render();
     1659        plane_renderer->render();
    16551660        perf->disable();
    16561661    }
    1657     TRACE("in display: render heightmap\n");
     1662
    16581663    perf->reset();
    16591664    CHECK_FRAMEBUFFER_STATUS();
     
    17551760                1.0f);
    17561761            NanoVis::flowVisRenderer->activateVectorField(vf_name);
    1757            
     1762
    17581763            //////////////////////////////////
    17591764            // ADD Particle Injection Plane1
     
    17681773            NanoVis::flowVisRenderer->setParticleColor(vf_name, plane_name2, color2);
    17691774            NanoVis::flowVisRenderer->initialize(vf_name);
    1770            
     1775
    17711776            NanoVis::flowVisRenderer->activatePlane(vf_name, plane_name1);
    17721777            NanoVis::flowVisRenderer->activatePlane(vf_name, plane_name2);
    1773            
    1774             NanoVis::licRenderer->setVectorField(volPtr->id,
    1775                                 *(volPtr->get_location()),
    1776                                 1.0f / volPtr->aspect_ratio_width,
    1777                                 1.0f / volPtr->aspect_ratio_height,
    1778                                 1.0f / volPtr->aspect_ratio_depth,
    1779                                 volPtr->wAxis.max());
     1778
     1779            NanoVis::licRenderer->
     1780                setVectorField(volPtr->id,
     1781                               *(volPtr->get_location()),
     1782                               1.0f / volPtr->aspect_ratio_width,
     1783                               1.0f / volPtr->aspect_ratio_height,
     1784                               1.0f / volPtr->aspect_ratio_depth,
     1785                               volPtr->wAxis.max());
    17801786        }
    17811787    }
     
    23532359
    23542360    /*
    2355       plane_render->set_screen_size(width, height);
     2361      plane_renderer->set_screen_size(width, height);
    23562362
    23572363      // generate data for the legend
     
    23612367      }
    23622368      plane[0] = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data);
    2363       int index = plane_render->add_plane(plane[0], tf);
    2364       plane_render->set_active_plane(index);
     2369      int index = plane_renderer->add_plane(plane[0], tf);
     2370      plane_renderer->set_active_plane(index);
    23652371
    23662372      offscreen_buffer_capture();
    23672373      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    23682374
    2369       //plane_render->render();
     2375      //plane_renderer->render();
    23702376      // INSOO : is going to implement here for the topview of the heightmap
    23712377      heightmap->render(renderContext);
     
    23842390    //ppm_write(prefix);
    23852391    //write(1, "\n", 1);
    2386     //plane_render->remove_plane(index);
     2392    //plane_renderer->remove_plane(index);
    23872393
    23882394    // CURRENT
  • trunk/packages/vizservers/nanovis/nanovis.h

    r2822 r2831  
    1414 * ======================================================================
    1515 */
    16 #ifndef __NANOVIS_H__
    17 #define __NANOVIS_H__
     16#ifndef NANOVIS_H
     17#define NANOVIS_H
    1818
    1919#include <tcl.h>
    2020
    2121#include <GL/glew.h>
    22 #include <GL/glut.h>
    23 #include <Cg/cgGL.h>
    24 #include <stdlib.h>
     22
    2523#include <math.h>
    26 #include <time.h>
     24#include <stddef.h> // For size_t
     25#include <stdio.h>
     26
     27#include <vector>
    2728#include <iostream>
    28 #include <stdio.h>
    29 #include <assert.h>
    30 #include <float.h>
    31 #include <getopt.h>
    32 #include <stdio.h>
    33 #include <math.h>
    34 #include <fstream>
    35 #include <sstream>
    36 #include <string>
    37 #include <sys/time.h>
    38 #include <sys/types.h>
    39 #include <unistd.h>
    40 #include <fcntl.h>
    41 #include <signal.h>
    4229
    4330#include <rappture.h>
     
    4532#include "define.h"
    4633#include "global.h"
    47 
    48 #include "NvCamera.h"
    49 #include "ConvexPolygon.h"
    50 #include "Texture3D.h"
    51 #include "Texture2D.h"
    52 #include "Texture1D.h"
    53 #include "TransferFunction.h"
    54 #include "Mat4x4.h"
    55 #include "Volume.h"
    56 #include "NvParticleRenderer.h"
    57 #include "NvFlowVisRenderer.h"
    58 #include "PerfQuery.h"
    59 #include "Event.h"
    60 #include "VolumeRenderer.h"
    61 #include "PlaneRenderer.h"
    62 #include "NvColorTableRenderer.h"
    63 #include "PointSetRenderer.h"
    64 #include "PointSet.h"
    65 #include "HeightMap.h"
    66 #include "Grid.h"
    67 #include "VolumeRenderer.h"
    68 #include "VelocityArrowsSlice.h"
    69 
    7034#include "config.h"
    7135
     
    7943#define SCALE 3.0       //scale for background pattern. small value -> fine texture
    8044
     45namespace graphics {
     46    class RenderContext;
     47}
     48
     49class VolumeRenderer;
     50class PointSetRenderer;
     51class NvParticleRenderer;
     52class NvFlowVisRenderer;
     53class PlaneRenderer;
     54class VelocityArrowsSlice;
     55class NvLIC;
     56class PointSet;
     57class Texture2D;
     58class NvColorTableRenderer;
     59class HeightMap;
    8160class NvVectorField;
     61class Grid;
     62class R2Fonts;
     63class NvCamera;
     64class TransferFunction;
     65class Volume;
     66class FlowCmd;
     67class FlowIterator;
    8268
    8369struct Vector2 {
     
    8571    float mag()
    8672    {
    87         return sqrt(x*x+y*y);
     73        return sqrt(x*x + y*y);
    8874    }
    8975};
     
    9177struct RegGrid2 {
    9278    int width, height;
    93     Vector2* field;
    94    
     79    Vector2 *field;
     80
    9581    RegGrid2(int w, int h)
    9682    {
     
    11197};
    11298
    113 class NvLIC;
    114 class FlowCmd;
    115 class FlowIterator;
    116 
    11799class NanoVis
    118100{
    119     //frame buffer for final rendering
    120     static GLuint final_fbo, final_color_tex, final_depth_rb;
    121 
    122101public:
    123     static VolumeRenderer* vol_renderer;
    124     static PointSetRenderer* pointset_renderer;
     102    enum NanoVisFlags {
     103        REDRAW_PENDING = (1 << 0),
     104        MAP_FLOWS = (1 << 1),
     105        MAP_VOLUMES = (1 << 2),
     106        MAP_HEIGHTMAPS = (1 << 3),
     107    };
     108
     109    static VolumeRenderer *vol_renderer;
     110    static PointSetRenderer *pointset_renderer;
    125111#ifndef NEW_FLOW_ENGINE
    126     static NvParticleRenderer* flowVisRenderer;
     112    static NvParticleRenderer *flowVisRenderer;
    127113#else
    128     static NvFlowVisRenderer* flowVisRenderer;
     114    static NvFlowVisRenderer *flowVisRenderer;
    129115#endif
    130     static VelocityArrowsSlice* velocityArrowsSlice;
    131     static NvLIC* licRenderer;
    132     static std::vector<PointSet*> pointSet;
    133     static PlaneRenderer* plane_render;
     116    static VelocityArrowsSlice *velocityArrowsSlice;
     117    static NvLIC *licRenderer;
     118    static PlaneRenderer *plane_renderer;
     119    static std::vector<PointSet *> pointSet;
    134120
    135121    /**
    136      *  pointers to 2D planes, currently handle up 10
     122     *  pointers to 2D planes
    137123     */
    138     static Texture2D* plane[10];
    139     static NvColorTableRenderer* color_table_renderer;
    140     static graphics::RenderContext* renderContext;
    141     static std::vector<HeightMap*> heightMap;
    142     static unsigned char* screen_buffer;
     124    static Texture2D *plane[];
     125    static NvColorTableRenderer *color_table_renderer;
     126    static graphics::RenderContext *renderContext;
     127    static std::vector<HeightMap *> heightMap;
     128    static unsigned char *screen_buffer;
    143129    static Tcl_HashTable volumeTable;
    144130    static Tcl_HashTable heightmapTable;
    145     static std::vector<NvVectorField*> flow;
    146     static Grid* grid;
    147     static R2Fonts* fonts;
     131    static std::vector<NvVectorField *> flow;
     132    static Grid *grid;
     133    static R2Fonts *fonts;
    148134    static int updir;
    149135    static NvCamera *cam;
     
    165151    static Tcl_DString cmdbuffer;
    166152
    167     static TransferFunction* get_transfunc(const char *name);
    168     static TransferFunction* DefineTransferFunction(const char *name,
    169         size_t n, float *data);
    170     static void SetVolumeRanges(void);
    171     static void SetHeightmapRanges(void);
    172     static void init(const char* path);
    173     static void initGL(void);
    174     static void init_lic(void);
    175     static void init_offscreen_buffer(void);
     153    static TransferFunction *get_transfunc(const char *name);
     154    static TransferFunction *DefineTransferFunction(const char *name,
     155                                                    size_t n, float *data);
     156    static void SetVolumeRanges();
     157    static void SetHeightmapRanges();
     158    static void init(const char *path);
     159    static void initGL();
     160    static void init_lic();
     161    static void init_offscreen_buffer();
    176162    static void initParticle();
    177163    static void resize_offscreen_buffer(int w, int h);
     
    183169    static void ppm_write(const char *prefix);
    184170    static void sendDataToClient(const char *command, const char *data,
    185         size_t dlen);
     171                                 size_t dlen);
    186172    static void bmp_write(const char *prefix);
    187173    static void bmp_write_to_file(int frame_number, const char* directory_name);
    188     static void display(void);
    189     static void idle(void);
    190     static void update(void);
     174    static void display();
     175    static void idle();
     176    static void update();
    191177    static void display_offscreen_buffer();
    192178    static int render_legend(TransferFunction *tf, double min, double max,
    193         int width, int height, const char* volArg);
     179                             int width, int height, const char *volArg);
    194180    static Volume *load_volume(const char *tag, int width, int height,
    195                 int depth, int n, float* data, double vmin, double vmax,
    196                 double nzero_min);
    197     static void xinetd_listen(void);
    198     static int render_2d_contour(HeightMap* heightmap, int width, int height);
     181                               int depth, int n, float* data, double vmin, double vmax,
     182                               double nzero_min);
     183    static void xinetd_listen();
     184    static int render_2d_contour(HeightMap *heightmap, int width, int height);
    199185    static void pan(float dx, float dy);
    200186
     
    216202    static void offscreen_buffer_capture()
    217203    {
    218         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
     204        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _final_fbo);
    219205    }
    220206
     
    227213    static FlowCmd *FirstFlow(FlowIterator *iterPtr);
    228214    static FlowCmd *NextFlow(FlowIterator *iterPtr);
    229     static void InitFlows(void);
    230     static int GetFlow(Tcl_Interp *interp, Tcl_Obj *objPtr, 
    231                        FlowCmd **flowPtrPtr);
     215    static void InitFlows();
     216    static int GetFlow(Tcl_Interp *interp, Tcl_Obj *objPtr,
     217                       FlowCmd **flowPtrPtr);
    232218    static int CreateFlow(Tcl_Interp *interp, Tcl_Obj *objPtr);
    233219    static void DeleteFlows(Tcl_Interp *interp);
    234     static bool MapFlows(void);
    235     static void RenderFlows(void);
    236     static void ResetFlows(void);
    237     static bool UpdateFlows(void);
    238     static void AdvectFlows(void);
    239     enum NanoVisFlags {
    240         REDRAW_PENDING=(1<<0),
    241         MAP_FLOWS=(1<<1),
    242         MAP_VOLUMES=(1<<2),
    243         MAP_HEIGHTMAPS=(1<<3),
    244     };
     220    static bool MapFlows();
     221    static void RenderFlows();
     222    static void ResetFlows();
     223    static bool UpdateFlows();
     224    static void AdvectFlows();
     225
    245226    static void EventuallyRedraw(unsigned int flag = 0);
    246227    static void remove_volume(Volume *volPtr);
    247228    static Tcl_HashTable tfTable;
     229
     230private:
     231    //frame buffer for final rendering
     232    static GLuint _final_fbo, _final_color_tex, _final_depth_rb;
    248233};
    249234
    250235extern Volume *load_volume_stream(Rappture::Outcome &status, const char *tag,
    251                         std::iostream& fin);
    252 extern Volume *load_volume_stream_odx(Rappture::Outcome &status,
    253         const char *tag, const char *buf, int nBytes);
    254 extern Volume *load_volume_stream2(Rappture::Outcome &status, const char *tag,
    255         std::iostream& fin);
    256 
    257 extern Volume *load_vector_stream(Rappture::Outcome &result, const char *tag,
    258         size_t length, char *bytes);
    259 extern Volume *load_vector_stream2(Rappture::Outcome &result, const char *tag,
    260         size_t length, char *bytes);
    261 
    262 
    263 #endif  /* __NANOVIS_H__ */
     236                                  std::iostream& fin);
     237
     238extern Volume *load_volume_stream_odx(Rappture::Outcome& status,
     239                                      const char *tag, const char *buf, int nBytes);
     240
     241extern Volume *load_volume_stream2(Rappture::Outcome & status, const char *tag,
     242                                   std::iostream& fin);
     243
     244extern Volume *load_vector_stream(Rappture::Outcome& result, const char *tag,
     245                                  size_t length, char *bytes);
     246
     247extern Volume *load_vector_stream2(Rappture::Outcome& result, const char *tag,
     248                                   size_t length, char *bytes);
     249
     250#endif
Note: See TracChangeset for help on using the changeset viewer.