Changeset 2261 for trunk/packages


Ignore:
Timestamp:
May 26, 2011 11:29:27 PM (13 years ago)
Author:
ldelgass
Message:

Add GPU volume rendering support to vtkvis render server

Location:
trunk/packages/vizservers/vtkvis
Files:
2 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/ColorMap.cpp

    r2194 r2261  
    1010#include <cassert>
    1111#include <vtkLookupTable.h>
     12#include <vtkColorTransferFunction.h>
     13#include <vtkPiecewiseFunction.h>
    1214
    1315#include "ColorMap.h"
     
    1517
    1618using namespace Rappture::VtkVis;
     19
     20ColorMap *ColorMap::_default = NULL;
     21ColorMap *ColorMap::_volumeDefault = NULL;
    1722
    1823ColorMap::ColorMap(const std::string& name) :
     
    2126    _numTableEntries(256)
    2227{
     28    _colorTF = vtkSmartPointer<vtkColorTransferFunction>::New();
     29    _colorTF->ClampingOn();
     30    _opacityTF = vtkSmartPointer<vtkPiecewiseFunction>::New();
     31    _opacityTF->ClampingOn();
    2332}
    2433
     
    4352    assert(_lookupTable != NULL);
    4453    return _lookupTable;
     54}
     55
     56/**
     57 * \brief Return a newly allocated color transfer function with values
     58 * scaled to the given data range
     59 */
     60vtkSmartPointer<vtkColorTransferFunction>
     61ColorMap::getColorTransferFunction(double range[2])
     62{
     63    vtkSmartPointer<vtkColorTransferFunction> tf = vtkSmartPointer<vtkColorTransferFunction>::New();
     64    tf->DeepCopy(_colorTF);
     65    double tmp[6];
     66    for (int i = 0; i < tf->GetSize(); i++) {
     67        tf->GetNodeValue(i, tmp);
     68        tmp[0] = range[0] + tmp[0] * (range[1] - range[0]);
     69        tf->SetNodeValue(i, tmp);
     70    }
     71    return tf;
     72}
     73
     74/**
     75 * \brief Return a newly allocated opacity transfer function with values
     76 * scaled to the given data range
     77 */
     78vtkSmartPointer<vtkPiecewiseFunction>
     79ColorMap::getOpacityTransferFunction(double range[2])
     80{
     81    vtkSmartPointer<vtkPiecewiseFunction> tf = vtkSmartPointer<vtkPiecewiseFunction>::New();
     82    tf->DeepCopy(_opacityTF);
     83    double tmp[4];
     84    for (int i = 0; i < tf->GetSize(); i++) {
     85        tf->GetNodeValue(i, tmp);
     86        tmp[0] = range[0] + tmp[0] * (range[1] - range[0]);
     87        tf->SetNodeValue(i, tmp);
     88    }
     89    return tf;
    4590}
    4691
     
    72117    // If we reach here, our control point goes at the end
    73118    _controlPoints.insert(_controlPoints.end(), cp);
     119    _colorTF->AddRGBPoint(cp.value, cp.color[0], cp.color[1], cp.color[2]);
    74120}
    75121
     
    101147    // If we reach here, our control point goes at the end
    102148    _opacityControlPoints.insert(_opacityControlPoints.end(), cp);
     149    _opacityTF->AddPoint(cp.value, cp.alpha);
    103150}
    104151
     
    195242}
    196243
     244/**
     245 * \brief Perform linear interpolation of two color control points
     246 */
    197247void ColorMap::lerp(double *result, const ControlPoint& cp1, const ControlPoint& cp2, double value)
    198248{
     
    203253}
    204254
     255/**
     256 * \brief Perform linear interpolation of two opacity control points
     257 */
    205258void ColorMap::lerp(double *result, const OpacityControlPoint& cp1, const OpacityControlPoint& cp2, double value)
    206259{
     
    215268{
    216269    _controlPoints.clear();
     270    _colorTF->RemoveAllPoints();
    217271    _opacityControlPoints.clear();
     272    _opacityTF->RemoveAllPoints();
    218273    _lookupTable = NULL;
    219274}
     
    222277 * \brief Create a default ColorMap with a blue-cyan-green-yellow-red ramp
    223278 */
    224 ColorMap * ColorMap::createDefault()
    225 {
    226     ColorMap *colorMap = new ColorMap("default");
     279ColorMap * ColorMap::getDefault()
     280{
     281    if (_default != NULL) {
     282        return _default;
     283    }
     284
     285    _default = new ColorMap("default");
    227286    ControlPoint cp[5];
    228287    cp[0].value = 0.0;
     
    247306    cp[4].color[2] = 0.0;
    248307    for (int i = 0; i < 5; i++) {
    249         colorMap->addControlPoint(cp[i]);
     308        _default->addControlPoint(cp[i]);
    250309    }
    251310    OpacityControlPoint ocp[2];
     
    254313    ocp[1].value = 1.0;
    255314    ocp[1].alpha = 1.0;
    256     colorMap->addOpacityControlPoint(ocp[0]);
    257     colorMap->addOpacityControlPoint(ocp[1]);
    258     colorMap->build();
    259     return colorMap;
    260 }
     315    _default->addOpacityControlPoint(ocp[0]);
     316    _default->addOpacityControlPoint(ocp[1]);
     317    _default->build();
     318    return _default;
     319}
     320
     321/**
     322 * \brief Create a default ColorMap with a blue-cyan-green-yellow-red ramp
     323 * and transparent to opaque ramp
     324 */
     325ColorMap * ColorMap::getVolumeDefault()
     326{
     327    if (_volumeDefault != NULL) {
     328        return _volumeDefault;
     329    }
     330
     331    _volumeDefault = new ColorMap("volumeDefault");
     332    ControlPoint cp[5];
     333    cp[0].value = 0.0;
     334    cp[0].color[0] = 0.0;
     335    cp[0].color[1] = 0.0;
     336    cp[0].color[2] = 1.0;
     337    cp[1].value = 0.25;
     338    cp[1].color[0] = 0.0;
     339    cp[1].color[1] = 1.0;
     340    cp[1].color[2] = 1.0;
     341    cp[2].value = 0.5;
     342    cp[2].color[0] = 0.0;
     343    cp[2].color[1] = 1.0;
     344    cp[2].color[2] = 0.0;
     345    cp[3].value = 0.75;
     346    cp[3].color[0] = 1.0;
     347    cp[3].color[1] = 1.0;
     348    cp[3].color[2] = 0.0;
     349    cp[4].value = 1.0;
     350    cp[4].color[0] = 1.0;
     351    cp[4].color[1] = 0.0;
     352    cp[4].color[2] = 0.0;
     353    for (int i = 0; i < 5; i++) {
     354        _volumeDefault->addControlPoint(cp[i]);
     355    }
     356    OpacityControlPoint ocp[2];
     357    ocp[0].value = 0.0;
     358    ocp[0].alpha = 0.0;
     359    ocp[1].value = 1.0;
     360    ocp[1].alpha = 1.0;
     361    _volumeDefault->addOpacityControlPoint(ocp[0]);
     362    _volumeDefault->addOpacityControlPoint(ocp[1]);
     363    _volumeDefault->build();
     364    return _volumeDefault;
     365}
  • trunk/packages/vizservers/vtkvis/ColorMap.h

    r2194 r2261  
    1313#include <cstring>
    1414#include <vtkSmartPointer.h>
     15#include <vtkColorTransferFunction.h>
     16#include <vtkPiecewiseFunction.h>
    1517#include <vtkLookupTable.h>
    1618
     
    8486
    8587    const std::string& getName();
     88
    8689    vtkLookupTable *getLookupTable();
     90
     91    vtkSmartPointer<vtkColorTransferFunction> getColorTransferFunction(double range[2]);
     92
     93    vtkSmartPointer<vtkPiecewiseFunction> getOpacityTransferFunction(double range[2]);
    8794
    8895    void setNumberOfTableEntries(int numEntries);
     
    96103    void clear();
    97104
    98     static ColorMap* createDefault();
     105    static ColorMap *getDefault();
     106    static ColorMap *getVolumeDefault();
    99107
    100108private:
     109    static ColorMap *_default;
     110    static ColorMap *_volumeDefault;
     111
    101112    ColorMap();
    102113
     
    109120    bool _needsBuild;
    110121    int _numTableEntries;
     122    vtkSmartPointer<vtkColorTransferFunction> _colorTF;
     123    vtkSmartPointer<vtkPiecewiseFunction> _opacityTF;
    111124    vtkSmartPointer<vtkLookupTable> _lookupTable;
    112125};
  • trunk/packages/vizservers/vtkvis/Makefile.in

    r2260 r2261  
    2929
    3030VTK_LIB_DIR     = @VTK_LIB_DIR@
    31 VTK_LIB_SPEC    = -L$(VTK_LIB_DIR) -lvtkIO -lvtkWidgets -lvtkRendering -lvtkGraphics -lvtkCommon
     31VTK_LIB_SPEC    = -L$(VTK_LIB_DIR) -lvtkIO -lvtkWidgets -lvtkFiltering -lvtkVolumeRendering -lvtkRendering -lvtkHybrid -lvtkGraphics -lvtkImaging -lvtkCommon
    3232VTK_INC_SPEC    = @VTK_INC_SPEC@
    3333
     
    4545                $(VTK_INC_SPEC)
    4646
    47 USE_CUSTOM_AXES         = #yes
    48 USE_OFFSCREEN_RENDERING = yes
    4947DEBUG                   = #yes
    5048TRACE                   = #yes
     49USE_CUSTOM_AXES         = #yes
     50USE_GPU_RAYCASTING      = yes
     51USE_OFFSCREEN_RENDERING = yes
    5152
    5253EXTRA_CFLAGS    = -Wall -Wno-deprecated #vtk uses deprecated strstream header (instead of sstream)
     
    6566DEFINES         += -DUSE_OFFSCREEN_RENDERING
    6667endif
     68ifdef USE_GPU_RAYCASTING
     69DEFINES         += -DUSE_GPU_RAYCAST_MAPPER
     70endif
    6771CXX_SWITCHES    = $(CXXFLAGS) $(EXTRA_CFLAGS) $(DEFINES) $(INCLUDES)
    6872
     
    7579                RpPolyData.cpp \
    7680                RpPseudoColor.cpp \
     81                RpVolume.cpp \
    7782                RpVtkDataSet.cpp \
    7883                RpVtkRenderer.cpp\
     
    123128RpHeightMap.o: RpHeightMap.h RpVtkDataSet.h Trace.h
    124129RpPseudoColor.o: RpPseudoColor.h RpVtkDataSet.h Trace.h
     130RpVolume.o: RpVolume.h RpVtkDataSet.h ColorMap.h Trace.h
    125131RpVtkDataSet.o: RpVtkDataSet.h Trace.h
    126132RpVtkRenderer.o: RpVtkRenderer.h RpVtkDataSet.h RpPolyData.h RpPseudoColor.h RpContour2D.h ColorMap.h Trace.h
  • trunk/packages/vizservers/vtkvis/RpContour2D.cpp

    r2260 r2261  
    7373
    7474/**
    75  * \brief Get the VTK Actor for the contour lines
    76  */
    77 vtkProp *Contour2D::getActor()
     75 * \brief Get the VTK Prop for the contour lines
     76 */
     77vtkProp *Contour2D::getProp()
    7878{
    7979    return _contourActor;
     
    8181
    8282/**
    83  * \brief Create and initialize a VTK actor to render isolines
    84  */
    85 void Contour2D::initActor()
     83 * \brief Create and initialize a VTK Prop to render isolines
     84 */
     85void Contour2D::initProp()
    8686{
    8787    if (_contourActor == NULL) {
     
    105105    vtkDataSet *ds = _dataSet->getVtkDataSet();
    106106
    107     initActor();
     107    initProp();
    108108
    109109    // Contour filter to generate isolines
  • trunk/packages/vizservers/vtkvis/RpContour2D.h

    r2260 r2261  
    3434    DataSet *getDataSet();
    3535
    36     vtkProp *getActor();
     36    vtkProp *getProp();
    3737
    3838    void setContours(int numContours);
     
    6161
    6262private:
    63     void initActor();
     63    void initProp();
    6464    void update();
    6565
  • trunk/packages/vizservers/vtkvis/RpHeightMap.cpp

    r2260 r2261  
    4040    _warpScale(1.0)
    4141{
     42    _dataRange[0] = 0.0;
     43    _dataRange[1] = 1.0;
    4244    _edgeColor[0] = 0.0;
    4345    _edgeColor[1] = 0.0;
     
    245247    _lut->SetRange(_dataRange);
    246248
    247     initActors();
     249    initProp();
    248250
    249251    _dsMapper->UseLookupTableScalarRangeOn();
     
    384386
    385387/**
    386  * \brief Get the VTK Actor for the colormapped dataset
    387  */
    388 vtkProp *HeightMap::getActor()
     388 * \brief Get the VTK Prop for the colormapped dataset
     389 */
     390vtkProp *HeightMap::getProp()
    389391{
    390392    return _props;
     
    392394
    393395/**
    394  * \brief Create and initialize a VTK actor to render the colormapped dataset
    395  */
    396 void HeightMap::initActors()
     396 * \brief Create and initialize VTK Props to render the colormapped dataset
     397 */
     398void HeightMap::initProp()
    397399{
    398400    if (_dsActor == NULL) {
  • trunk/packages/vizservers/vtkvis/RpHeightMap.h

    r2260 r2261  
    4646    DataSet *getDataSet();
    4747
    48     vtkProp *getActor();
     48    vtkProp *getProp();
    4949
    5050    void selectVolumeSlice(Axis axis, double ratio);
     
    9090private:
    9191    vtkPolyData *initWarp(vtkPolyData *input);
    92     void initActors();
     92    void initProp();
    9393    void update();
    9494
  • trunk/packages/vizservers/vtkvis/RpPolyData.cpp

    r2260 r2261  
    1717#include <vtkDelaunay2D.h>
    1818#include <vtkDelaunay3D.h>
     19#include <vtkDataSetSurfaceFilter.h>
    1920
    2021#include "RpPolyData.h"
     
    4849
    4950/**
    50  * \brief Get the VTK Actor for the mesh
    51  */
    52 vtkProp *PolyData::getActor()
     51 * \brief Get the VTK Prop for the mesh
     52 */
     53vtkProp *PolyData::getProp()
    5354{
    5455    return _pdActor;
     
    5657
    5758/**
    58  * \brief Create and initialize a VTK actor to render a mesh
    59  */
    60 void PolyData::initActor()
     59 * \brief Create and initialize a VTK Prop to render a mesh
     60 */
     61void PolyData::initProp()
    6162{
    6263    if (_pdActor == NULL) {
     
    8081{
    8182    if (_dataSet != dataSet) {
    82         vtkDataSet *ds = dataSet->getVtkDataSet();
    83         if (!ds->IsA("vtkPolyData")) {
    84             ERROR("DataSet is not a PolyData");
    85             return;
    86         } else {
    87             TRACE("DataSet is a vtkPolyData");
    88             vtkPolyData *pd = vtkPolyData::SafeDownCast(ds);
    89             assert(pd);
    90             TRACE("Verts: %d Lines: %d Polys: %d Strips: %d",
     83        _dataSet = dataSet;
     84        update();
     85    }
     86}
     87
     88/**
     89 * \brief Returns the DataSet this PolyData renders
     90 */
     91DataSet *PolyData::getDataSet()
     92{
     93    return _dataSet;
     94}
     95
     96/**
     97 * \brief Internal method to re-compute contours after a state change
     98 */
     99void PolyData::update()
     100{
     101    if (_dataSet == NULL) {
     102        return;
     103    }
     104
     105    if (_pdMapper == NULL) {
     106        _pdMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
     107        _pdMapper->SetResolveCoincidentTopologyToPolygonOffset();
     108        _pdMapper->ScalarVisibilityOff();
     109    }
     110
     111    initProp();
     112    _pdActor->SetMapper(_pdMapper);
     113
     114    vtkDataSet *ds = _dataSet->getVtkDataSet();
     115    vtkPolyData *pd = vtkPolyData::SafeDownCast(ds);
     116    if (pd) {
     117        TRACE("Verts: %d Lines: %d Polys: %d Strips: %d",
    91118                  pd->GetNumberOfVerts(),
    92119                  pd->GetNumberOfLines(),
    93120                  pd->GetNumberOfPolys(),
    94121                  pd->GetNumberOfStrips());
    95         }
    96         _dataSet = dataSet;
    97         update();
    98     }
    99 }
    100 
    101 /**
    102  * \brief Returns the DataSet this PolyData renders
    103  */
    104 DataSet *PolyData::getDataSet()
    105 {
    106     return _dataSet;
    107 }
    108 
    109 /**
    110  * \brief Internal method to re-compute contours after a state change
    111  */
    112 void PolyData::update()
    113 {
    114     if (_dataSet == NULL) {
    115         return;
    116     }
    117 
    118     if (_pdMapper == NULL) {
    119         _pdMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    120         _pdMapper->SetResolveCoincidentTopologyToPolygonOffset();
    121         _pdMapper->ScalarVisibilityOff();
    122     }
    123 
    124     initActor();
    125     _pdActor->SetMapper(_pdMapper);
    126 
    127     vtkPolyData *pd = vtkPolyData::SafeDownCast(_dataSet->getVtkDataSet());
    128     assert(pd);
    129 
    130     if (pd->GetNumberOfLines() == 0 &&
    131         pd->GetNumberOfPolys() == 0 &&
    132         pd->GetNumberOfStrips() == 0) {
    133         // Point cloud
    134         if (_dataSet->is2D()) {
    135             vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New();
    136             mesher->SetInput(pd);
    137             _pdMapper->SetInput(mesher->GetOutput());
     122        // DataSet is a vtkPolyData
     123        if (pd->GetNumberOfLines() == 0 &&
     124            pd->GetNumberOfPolys() == 0 &&
     125            pd->GetNumberOfStrips() == 0) {
     126            // DataSet is a point cloud
     127            if (_dataSet->is2D()) {
     128                vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New();
     129                mesher->SetInput(pd);
     130                _pdMapper->SetInput(mesher->GetOutput());
     131            } else {
     132                vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New();
     133                mesher->SetInput(pd);
     134                // Delaunay3D returns an UnstructuredGrid, so feed it through a generic mapper
     135                // to get the grid boundary as a PolyData
     136                vtkSmartPointer<vtkDataSetMapper> dsMapper = vtkSmartPointer<vtkDataSetMapper>::New();
     137                dsMapper->SetInput(mesher->GetOutput());
     138                dsMapper->StaticOn();
     139                _pdMapper = dsMapper->GetPolyDataMapper();
     140                _pdMapper->SetResolveCoincidentTopologyToPolygonOffset();
     141                _pdMapper->ScalarVisibilityOff();
     142            }
    138143        } else {
    139             vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New();
    140             mesher->SetInput(pd);
    141             // Delaunay3D returns an UnstructuredGrid, so feed it through a generic mapper
    142             // to get the grid boundary as a PolyData
    143             vtkSmartPointer<vtkDataSetMapper> dsMapper =  vtkSmartPointer<vtkDataSetMapper>::New();
    144             dsMapper->SetInput(mesher->GetOutput());
    145             dsMapper->StaticOn();
    146             _pdMapper = dsMapper->GetPolyDataMapper();
    147             _pdMapper->SetResolveCoincidentTopologyToPolygonOffset();
    148             _pdMapper->ScalarVisibilityOff();
     144            // DataSet is a vtkPolyData with lines and/or polygons
     145            _pdMapper->SetInput(pd);
     146            _pdMapper->StaticOn();
    149147        }
    150148    } else {
     149        // DataSet is NOT a vtkPolyData
     150        WARN("DataSet is not a PolyData");
     151        vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     152        gf->SetInput(ds);
     153        gf->Update();
     154        pd = gf->GetOutput();
     155        assert(pd);
    151156        _pdMapper->SetInput(pd);
    152         _pdMapper->StaticOn();
    153157    }
    154158}
  • trunk/packages/vizservers/vtkvis/RpPolyData.h

    r2260 r2261  
    3232    DataSet *getDataSet();
    3333
    34     vtkProp *getActor();
     34    vtkProp *getProp();
    3535
    3636    void setVisibility(bool state);
     
    5555
    5656private:
    57     void initActor();
     57    void initProp();
    5858    void update();
    5959
  • trunk/packages/vizservers/vtkvis/RpPseudoColor.cpp

    r2260 r2261  
    173173    //_dsMapper->InterpolateScalarsBeforeMappingOn();
    174174
    175     initActor();
     175    initProp();
    176176    _dsActor->SetMapper(_dsMapper);
    177177}
    178178
    179179/**
    180  * \brief Get the VTK Actor for the colormapped dataset
    181  */
    182 vtkProp *PseudoColor::getActor()
     180 * \brief Get the VTK Prop for the colormapped dataset
     181 */
     182vtkProp *PseudoColor::getProp()
    183183{
    184184    return _dsActor;
     
    186186
    187187/**
    188  * \brief Create and initialize a VTK actor to render the colormapped dataset
    189  */
    190 void PseudoColor::initActor()
     188 * \brief Create and initialize a VTK Prop to render the colormapped dataset
     189 */
     190void PseudoColor::initProp()
    191191{
    192192    if (_dsActor == NULL) {
  • trunk/packages/vizservers/vtkvis/RpPseudoColor.h

    r2260 r2261  
    3434    DataSet *getDataSet();
    3535
    36     vtkProp *getActor();
     36    vtkProp *getProp();
    3737
    3838    void setLookupTable(vtkLookupTable *lut);
     
    5757
    5858private:
    59     void initActor();
     59    void initProp();
    6060    void update();
    6161
  • trunk/packages/vizservers/vtkvis/RpVtkDataSet.cpp

    r2260 r2261  
    2222    _visible(true)
    2323{
    24     _name = name;
    2524    _dataRange[0] = 0;
    2625    _dataRange[1] = 1;
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp

    r2260 r2261  
    101101    _renderWindow->SetSize(_windowWidth, _windowHeight);
    102102    _renderWindow->AddRenderer(_renderer);
    103     addColorMap("default", ColorMap::createDefault());
     103    addColorMap("default", ColorMap::getDefault());
     104    addColorMap("volumeDefault", ColorMap::getVolumeDefault());
    104105}
    105106
     
    131132    }
    132133    _polyDatas.clear();
     134    for (VolumeHashmap::iterator itr = _volumes.begin();
     135             itr != _volumes.end(); ++itr) {
     136        delete itr->second;
     137    }
     138    _volumes.clear();
    133139    for (DataSetHashmap::iterator itr = _dataSets.begin();
    134140             itr != _dataSets.end(); ++itr) {
     
    180186    do  {
    181187        PseudoColor *ps = itr->second;
    182         if (ps->getActor())
    183             _renderer->RemoveViewProp(ps->getActor());
     188        if (ps->getProp())
     189            _renderer->RemoveViewProp(ps->getProp());
    184190        delete ps;
    185191
     
    216222    do {
    217223        Contour2D *contour = itr->second;
    218         if (contour->getActor())
    219             _renderer->RemoveViewProp(contour->getActor());
     224        if (contour->getProp())
     225            _renderer->RemoveViewProp(contour->getProp());
    220226        delete contour;
    221227
     
    252258    do {
    253259        HeightMap *hmap = itr->second;
    254         if (hmap->getActor())
    255             _renderer->RemoveViewProp(hmap->getActor());
     260        if (hmap->getProp())
     261            _renderer->RemoveViewProp(hmap->getProp());
    256262        delete hmap;
    257263
     
    270276{
    271277    PolyDataHashmap::iterator itr;
    272    
     278
    273279    bool doAll = false;
    274280
     
    288294    do {
    289295        PolyData *polyData = itr->second;
    290         if (polyData->getActor())
    291             _renderer->RemoveViewProp(polyData->getActor());
     296        if (polyData->getProp())
     297            _renderer->RemoveViewProp(polyData->getProp());
    292298        delete polyData;
    293299
    294300        _polyDatas.erase(itr);
    295301    } while (doAll && ++itr != _polyDatas.end());
     302
     303    _needsRedraw = true;
     304}
     305
     306/**
     307 * \brief Remove the Volume for the specified DataSet
     308 *
     309 * The underlying Volume is deleted, freeing its memory
     310 */
     311void Renderer::deleteVolume(const DataSetId& id)
     312{
     313    VolumeHashmap::iterator itr;
     314
     315    bool doAll = false;
     316
     317    if (id.compare("all") == 0) {
     318        itr = _volumes.begin();
     319        doAll = true;
     320    } else {
     321        itr = _volumes.find(id);
     322    }
     323    if (itr == _volumes.end()) {
     324        ERROR("Volume not found: %s", id.c_str());
     325        return;
     326    }
     327
     328    TRACE("Deleting Volumes for %s", id.c_str());
     329
     330    do {
     331        Volume *volume = itr->second;
     332        if (volume->getProp())
     333            _renderer->RemoveViewProp(volume->getProp());
     334        delete volume;
     335
     336        _volumes.erase(itr);
     337    } while (doAll && ++itr != _volumes.end());
    296338
    297339    _needsRedraw = true;
     
    328370        deleteHeightMap(itr->second->getName());
    329371        deletePolyData(itr->second->getName());
     372        deleteVolume(itr->second->getName());
    330373   
    331374        TRACE("After deleting graphics objects");
     
    898941        pc->setLookupTable(lut);
    899942
    900         _renderer->AddViewProp(pc->getActor());
     943        _renderer->AddViewProp(pc->getProp());
    901944    } while (doAll && ++itr != _dataSets.end());
    902945
     
    920963
    921964/**
    922  * \brief Associate an existing named color map with a DataSet
     965 * \brief Associate an existing named color map with a PseudoColor for the given DataSet
    923966 */
    924967void Renderer::setPseudoColorColorMap(const DataSetId& id, const ColorMapId& colorMapId)
     
    947990
    948991    do {
    949         TRACE("Set color map: %s for dataset %s", colorMapId.c_str(),
     992        TRACE("Set PseudoColor color map: %s for dataset %s", colorMapId.c_str(),
    950993              itr->second->getDataSet()->getName().c_str());
    951994
     
    9731016
    9741017/**
    975  * \brief Get the color map (vtkLookupTable) for the given DataSet
    976  *
    977  * \return The associated lookup table or NULL if not found
    978  */
    979 vtkLookupTable *Renderer::getPseudoColorColorMap(const DataSetId& id)
    980 {
    981     PseudoColor *pc = getPseudoColor(id);
    982     if (pc)
    983         return pc->getLookupTable();
    984     else
    985         return NULL;
    986 }
    987 
    988 /**
    9891018 * \brief Set opacity of the PseudoColor for the given DataSet
    9901019 */
     
    11901219        contour->setDataSet(ds);
    11911220
    1192         _renderer->AddViewProp(contour->getActor());
     1221        _renderer->AddViewProp(contour->getProp());
    11931222    } while (doAll && ++itr != _dataSets.end());
    11941223
     
    14531482        hmap->setLookupTable(lut);
    14541483
    1455         _renderer->AddViewProp(hmap->getActor());
     1484        _renderer->AddViewProp(hmap->getProp());
    14561485    } while (doAll && ++itr != _dataSets.end());
    14571486
     
    15351564
    15361565/**
    1537  * \brief Associate an existing named color map with a DataSet
     1566 * \brief Associate an existing named color map with a HeightMap for the given DataSet
    15381567 */
    15391568void Renderer::setHeightMapColorMap(const DataSetId& id, const ColorMapId& colorMapId)
     
    15621591
    15631592    do {
    1564         TRACE("Set color map: %s for dataset %s", colorMapId.c_str(),
     1593        TRACE("Set HeightMap color map: %s for dataset %s", colorMapId.c_str(),
    15651594              itr->second->getDataSet()->getName().c_str());
    15661595
     
    15881617
    15891618/**
    1590  * \brief Get the height map's color map (vtkLookupTable) for the given DataSet
    1591  *
    1592  * \return The associated lookup table or NULL if not found
    1593  */
    1594 vtkLookupTable *Renderer::getHeightMapColorMap(const DataSetId& id)
    1595 {
    1596     HeightMap *hm = getHeightMap(id);
    1597     if (hm)
    1598         return hm->getLookupTable();
    1599     else
    1600         return NULL;
    1601 }
    1602 
    1603 /**
    16041619 * \brief Set the number of equally spaced contour isolines for the given DataSet
    16051620 */
     
    19401955        polyData->setDataSet(ds);
    19411956
    1942         _renderer->AddViewProp(polyData->getActor());
     1957        _renderer->AddViewProp(polyData->getProp());
    19431958    } while (doAll && ++itr != _dataSets.end());
    19441959
     
    19691984{
    19701985    PolyDataHashmap::iterator itr;
    1971    
     1986
    19721987    bool doAll = false;
    19731988
     
    19962011{
    19972012    PolyDataHashmap::iterator itr;
    1998    
     2013
    19992014    bool doAll = false;
    20002015
     
    20232038{
    20242039    PolyDataHashmap::iterator itr;
    2025    
     2040
    20262041    bool doAll = false;
    20272042
     
    20492064{
    20502065    PolyDataHashmap::iterator itr;
    2051    
     2066
    20522067    bool doAll = false;
    20532068
     
    20762091{
    20772092    PolyDataHashmap::iterator itr;
    2078    
     2093
    20792094    bool doAll = false;
    20802095
     
    21062121{
    21072122    PolyDataHashmap::iterator itr;
    2108    
     2123
    21092124    bool doAll = false;
    21102125
     
    21332148{
    21342149    PolyDataHashmap::iterator itr;
    2135    
     2150
    21362151    bool doAll = false;
    21372152
     
    21602175{
    21612176    PolyDataHashmap::iterator itr;
    2162    
     2177
    21632178    bool doAll = false;
    21642179
     
    21772192        itr->second->setLighting(state);
    21782193    } while (doAll && ++itr != _polyDatas.end());
     2194
     2195    _needsRedraw = true;
     2196}
     2197
     2198/**
     2199 * \brief Create a new Volume and associate it with the named DataSet
     2200 */
     2201void Renderer::addVolume(const DataSetId& id)
     2202{
     2203    DataSetHashmap::iterator itr;
     2204
     2205    bool doAll = false;
     2206
     2207    if (id.compare("all") == 0) {
     2208        itr = _dataSets.begin();
     2209    } else {
     2210        itr = _dataSets.find(id);
     2211    }
     2212    if (itr == _dataSets.end()) {
     2213        ERROR("Unknown dataset %s", id.c_str());
     2214        return;
     2215    }
     2216
     2217    do {
     2218        DataSet *ds = itr->second;
     2219        const DataSetId& dsID = ds->getName();
     2220
     2221        if (getVolume(dsID)) {
     2222            WARN("Replacing existing volume %s", dsID.c_str());
     2223            deleteVolume(dsID);
     2224        }
     2225
     2226        Volume *volume = new Volume();
     2227        _volumes[dsID] = volume;
     2228
     2229        volume->setDataSet(ds);
     2230
     2231        if (_useCumulativeRange) {
     2232            ColorMap *cmap = volume->getColorMap();
     2233            volume->setColorMap(cmap, _cumulativeDataRange);
     2234        }
     2235
     2236        _renderer->AddViewProp(volume->getProp());
     2237    } while (doAll && ++itr != _dataSets.end());
     2238
     2239    if (_cameraMode == IMAGE)
     2240        setCameraMode(PERSPECTIVE);
     2241    initCamera();
     2242    _needsRedraw = true;
     2243}
     2244
     2245/**
     2246 * \brief Get the Volume associated with a named DataSet
     2247 */
     2248Volume *Renderer::getVolume(const DataSetId& id)
     2249{
     2250    VolumeHashmap::iterator itr = _volumes.find(id);
     2251
     2252    if (itr == _volumes.end()) {
     2253        TRACE("Volume not found: %s", id.c_str());
     2254        return NULL;
     2255    } else
     2256        return itr->second;
     2257}
     2258
     2259/**
     2260 * \brief Associate an existing named color map with a Volume for the given DataSet
     2261 */
     2262void Renderer::setVolumeColorMap(const DataSetId& id, const ColorMapId& colorMapId)
     2263{
     2264    VolumeHashmap::iterator itr;
     2265
     2266    bool doAll = false;
     2267
     2268    if (id.compare("all") == 0) {
     2269        itr = _volumes.begin();
     2270        doAll = true;
     2271    } else {
     2272        itr = _volumes.find(id);
     2273    }
     2274
     2275    if (itr == _volumes.end()) {
     2276        ERROR("Volume not found: %s", id.c_str());
     2277        return;
     2278    }
     2279
     2280    ColorMap *cmap = getColorMap(colorMapId);
     2281    if (cmap == NULL) {
     2282        ERROR("Unknown colormap: %s", colorMapId.c_str());
     2283        return;
     2284    }
     2285
     2286    do {
     2287        TRACE("Set Volume color map: %s for dataset %s", colorMapId.c_str(),
     2288              itr->second->getDataSet()->getName().c_str());
     2289#ifdef notdef
     2290        // Make a copy of the generic colormap lookup table, so
     2291        // data range can be set in the copy table to match the
     2292        // dataset being plotted
     2293        vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
     2294        lut->DeepCopy(cmap->getLookupTable());
     2295
     2296        if (_useCumulativeRange) {
     2297            lut->SetRange(_cumulativeDataRange);
     2298        } else {
     2299            if (itr->second->getDataSet() != NULL) {
     2300                double range[2];
     2301                itr->second->getDataSet()->getDataRange(range);
     2302                lut->SetRange(range);
     2303            }
     2304        }
     2305#endif
     2306        itr->second->setColorMap(cmap);
     2307    } while (doAll && ++itr != _volumes.end());
     2308
     2309    _needsRedraw = true;
     2310}
     2311
     2312/**
     2313 * \brief Set Volume opacity scaling for the specified DataSet
     2314 */
     2315void Renderer::setVolumeOpacity(const DataSetId& id, double opacity)
     2316{
     2317    VolumeHashmap::iterator itr;
     2318
     2319    bool doAll = false;
     2320
     2321    if (id.compare("all") == 0) {
     2322        itr = _volumes.begin();
     2323        doAll = true;
     2324    } else {
     2325        itr = _volumes.find(id);
     2326    }
     2327    if (itr == _volumes.end()) {
     2328        ERROR("Volume not found: %s", id.c_str());
     2329        return;
     2330    }
     2331
     2332    do {
     2333        itr->second->setOpacity(opacity);
     2334    } while (doAll && ++itr != _volumes.end());
     2335
     2336    _needsRedraw = true;
     2337}
     2338
     2339/**
     2340 * \brief Turn on/off rendering of the Volume mapper for the given DataSet
     2341 */
     2342void Renderer::setVolumeVisibility(const DataSetId& id, bool state)
     2343{
     2344    VolumeHashmap::iterator itr;
     2345
     2346    bool doAll = false;
     2347
     2348    if (id.compare("all") == 0) {
     2349        itr = _volumes.begin();
     2350        doAll = true;
     2351    } else {
     2352        itr = _volumes.find(id);
     2353    }
     2354    if (itr == _volumes.end()) {
     2355        ERROR("Volume not found: %s", id.c_str());
     2356        return;
     2357    }
     2358
     2359    do {
     2360        itr->second->setVisibility(state);
     2361    } while (doAll && ++itr != _volumes.end());
     2362
     2363    _needsRedraw = true;
     2364}
     2365
     2366/**
     2367 * \brief Set volume ambient lighting/shading coefficient for the specified DataSet
     2368 */
     2369void Renderer::setVolumeAmbient(const DataSetId& id, double coeff)
     2370{
     2371    VolumeHashmap::iterator itr;
     2372
     2373    bool doAll = false;
     2374
     2375    if (id.compare("all") == 0) {
     2376        itr = _volumes.begin();
     2377        doAll = true;
     2378    } else {
     2379        itr = _volumes.find(id);
     2380    }
     2381    if (itr == _volumes.end()) {
     2382        ERROR("Volume not found: %s", id.c_str());
     2383        return;
     2384    }
     2385
     2386    do {
     2387        itr->second->setAmbient(coeff);
     2388    } while (doAll && ++itr != _volumes.end());
     2389
     2390    _needsRedraw = true;
     2391}
     2392
     2393/**
     2394 * \brief Set volume diffuse lighting/shading coefficient for the specified DataSet
     2395 */
     2396void Renderer::setVolumeDiffuse(const DataSetId& id, double coeff)
     2397{
     2398    VolumeHashmap::iterator itr;
     2399
     2400    bool doAll = false;
     2401
     2402    if (id.compare("all") == 0) {
     2403        itr = _volumes.begin();
     2404        doAll = true;
     2405    } else {
     2406        itr = _volumes.find(id);
     2407    }
     2408    if (itr == _volumes.end()) {
     2409        ERROR("Volume not found: %s", id.c_str());
     2410        return;
     2411    }
     2412
     2413    do {
     2414        itr->second->setDiffuse(coeff);
     2415    } while (doAll && ++itr != _volumes.end());
     2416
     2417    _needsRedraw = true;
     2418}
     2419
     2420/**
     2421 * \brief Set volume specular lighting/shading coefficient and power for the specified DataSet
     2422 */
     2423void Renderer::setVolumeSpecular(const DataSetId& id, double coeff, double power)
     2424{
     2425    VolumeHashmap::iterator itr;
     2426
     2427    bool doAll = false;
     2428
     2429    if (id.compare("all") == 0) {
     2430        itr = _volumes.begin();
     2431        doAll = true;
     2432    } else {
     2433        itr = _volumes.find(id);
     2434    }
     2435    if (itr == _volumes.end()) {
     2436        ERROR("Volume not found: %s", id.c_str());
     2437        return;
     2438    }
     2439
     2440    do {
     2441        itr->second->setSpecular(coeff, power);
     2442    } while (doAll && ++itr != _volumes.end());
     2443
     2444    _needsRedraw = true;
     2445}
     2446
     2447/**
     2448 * \brief Turn volume lighting/shading on/off for the specified DataSet
     2449 */
     2450void Renderer::setVolumeLighting(const DataSetId& id, bool state)
     2451{
     2452    VolumeHashmap::iterator itr;
     2453
     2454    bool doAll = false;
     2455
     2456    if (id.compare("all") == 0) {
     2457        itr = _volumes.begin();
     2458        doAll = true;
     2459    } else {
     2460        itr = _volumes.find(id);
     2461    }
     2462    if (itr == _volumes.end()) {
     2463        ERROR("Volume not found: %s", id.c_str());
     2464        return;
     2465    }
     2466
     2467    do {
     2468        itr->second->setLighting(state);
     2469    } while (doAll && ++itr != _volumes.end());
    21792470
    21802471    _needsRedraw = true;
     
    28053096             itr != _pseudoColors.end(); ++itr) {
    28063097        if (!onlyVisible || itr->second->getVisibility())
    2807             mergeBounds(bounds, bounds, itr->second->getActor()->GetBounds());
     3098            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    28083099    }
    28093100    for (Contour2DHashmap::iterator itr = _contours.begin();
    28103101             itr != _contours.end(); ++itr) {
    28113102        if (!onlyVisible || itr->second->getVisibility())
    2812             mergeBounds(bounds, bounds, itr->second->getActor()->GetBounds());
     3103            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    28133104    }
    28143105    for (HeightMapHashmap::iterator itr = _heightMaps.begin();
    28153106             itr != _heightMaps.end(); ++itr) {
    28163107        if (!onlyVisible || itr->second->getVisibility())
    2817             mergeBounds(bounds, bounds, itr->second->getActor()->GetBounds());
     3108            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    28183109    }
    28193110    for (PolyDataHashmap::iterator itr = _polyDatas.begin();
    28203111             itr != _polyDatas.end(); ++itr) {
    28213112        if (!onlyVisible || itr->second->getVisibility())
    2822             mergeBounds(bounds, bounds, itr->second->getActor()->GetBounds());
     3113            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
     3114    }
     3115    for (VolumeHashmap::iterator itr = _volumes.begin();
     3116             itr != _volumes.end(); ++itr) {
     3117        if (!onlyVisible || itr->second->getVisibility())
     3118            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    28233119    }
    28243120    for (int i = 0; i < 6; i++) {
     
    28933189            } else {
    28943190                itr->second->setContours(itr->second->getNumContours());
     3191            }
     3192        }
     3193    }
     3194    for (VolumeHashmap::iterator itr = _volumes.begin();
     3195         itr != _volumes.end(); ++itr) {
     3196        ColorMap *cmap = itr->second->getColorMap();
     3197        if (cmap) {
     3198            if (useCumulative) {
     3199                itr->second->setColorMap(cmap, _cumulativeDataRange);
     3200            } else {
     3201                itr->second->setColorMap(cmap);
    28953202            }
    28963203        }
     
    30273334    if (id.compare("all") == 0 || getPolyData(id) != NULL)
    30283335        setPolyDataOpacity(id, opacity);
     3336    if (id.compare("all") == 0 || getVolume(id) != NULL)
     3337        setVolumeOpacity(id, opacity);
    30293338}
    30303339
     
    30613370    if (id.compare("all") == 0 || getPolyData(id) != NULL)
    30623371        setPolyDataVisibility(id, state);
     3372    if (id.compare("all") == 0 || getVolume(id) != NULL)
     3373        setVolumeVisibility(id, state);
    30633374}
    30643375
     
    30873398            for (PolyDataHashmap::iterator itr = _polyDatas.begin();
    30883399                 itr != _polyDatas.end(); ++itr) {
     3400                itr->second->setClippingPlanes(_clippingPlanes);
     3401            }
     3402            for (VolumeHashmap::iterator itr = _volumes.begin();
     3403                 itr != _volumes.end(); ++itr) {
    30893404                itr->second->setClippingPlanes(_clippingPlanes);
    30903405            }
     
    31063421                itr->second->setClippingPlanes(NULL);
    31073422            }
     3423            for (VolumeHashmap::iterator itr = _volumes.begin();
     3424                 itr != _volumes.end(); ++itr) {
     3425                itr->second->setClippingPlanes(NULL);
     3426            }
    31083427        }
    31093428        _renderWindow->Render();
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2260 r2261  
    1010
    1111#include <vtkSmartPointer.h>
    12 #include <vtkLookupTable.h>
    1312#include <vtkCubeAxesActor.h>
    1413#ifdef USE_CUSTOM_AXES
     
    3231#include "RpHeightMap.h"
    3332#include "RpPolyData.h"
     33#include "RpVolume.h"
    3434#include "Trace.h"
    3535
     
    7878    typedef std::tr1::unordered_map<DataSetId, HeightMap *> HeightMapHashmap;
    7979    typedef std::tr1::unordered_map<DataSetId, PolyData *> PolyDataHashmap;
     80    typedef std::tr1::unordered_map<DataSetId, Volume *> VolumeHashmap;
    8081
    8182    // Data sets
     
    189190    void setPseudoColorColorMap(const DataSetId& id, const ColorMapId& colorMapId);
    190191
    191     vtkLookupTable *getPseudoColorColorMap(const DataSetId& id);
    192 
    193192    void setPseudoColorOpacity(const DataSetId& id, double opacity);
    194193
     
    238237
    239238    void setHeightMapColorMap(const DataSetId& id, const ColorMapId& colorMapId);
    240 
    241     vtkLookupTable *getHeightMapColorMap(const DataSetId& id);
    242239
    243240    void setHeightMapContours(const DataSetId& id, int numContours);
     
    286283
    287284    void setPolyDataLighting(const DataSetId& id, bool state);
     285
     286    // Volumes
     287
     288    void addVolume(const DataSetId& id);
     289
     290    void deleteVolume(const DataSetId& id);
     291
     292    Volume *getVolume(const DataSetId& id);
     293
     294    void setVolumeColorMap(const DataSetId& id, const ColorMapId& colorMapId);
     295
     296    void setVolumeOpacity(const DataSetId& id, double opacity);
     297
     298    void setVolumeVisibility(const DataSetId& id, bool state);
     299
     300    void setVolumeAmbient(const DataSetId& id, double coeff);
     301
     302    void setVolumeDiffuse(const DataSetId& id, double coeff);
     303
     304    void setVolumeSpecular(const DataSetId& id, double coeff, double power);
     305
     306    void setVolumeLighting(const DataSetId& id, bool state);
    288307
    289308private:
     
    338357    HeightMapHashmap _heightMaps;
    339358    PolyDataHashmap _polyDatas;
     359    VolumeHashmap _volumes;
    340360
    341361    CameraMode _cameraMode;
  • trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp

    r2260 r2261  
    17341734
    17351735    proc = Rappture::GetOpFromObj(interp, nScreenOps, screenOps,
     1736                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
     1737    if (proc == NULL) {
     1738        return TCL_ERROR;
     1739    }
     1740    return (*proc) (clientData, interp, objc, objv);
     1741}
     1742
     1743static int
     1744VolumeAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1745            Tcl_Obj *const *objv)
     1746{
     1747    if (objc == 3) {
     1748        const char *name = Tcl_GetString(objv[2]);
     1749        g_renderer->addVolume(name);
     1750    } else {
     1751        g_renderer->addVolume("all");
     1752    }
     1753    return TCL_OK;
     1754}
     1755
     1756static int
     1757VolumeColorMapOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1758                 Tcl_Obj *const *objv)
     1759{
     1760    const char *colorMapName = Tcl_GetString(objv[2]);
     1761    if (objc == 4) {
     1762        const char *dataSetName = Tcl_GetString(objv[3]);
     1763        g_renderer->setVolumeColorMap(dataSetName, colorMapName);
     1764    } else {
     1765        g_renderer->setVolumeColorMap("all", colorMapName);
     1766    }
     1767    return TCL_OK;
     1768}
     1769
     1770static int
     1771VolumeDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1772               Tcl_Obj *const *objv)
     1773{
     1774    if (objc == 3) {
     1775        const char *name = Tcl_GetString(objv[2]);
     1776        g_renderer->deleteVolume(name);
     1777    } else {
     1778        g_renderer->deleteVolume("all");
     1779    }
     1780    return TCL_OK;
     1781}
     1782
     1783static int
     1784VolumeLightingOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1785                 Tcl_Obj *const *objv)
     1786{
     1787    bool state;
     1788    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1789        return TCL_ERROR;
     1790    }
     1791    if (objc == 4) {
     1792        const char *name = Tcl_GetString(objv[3]);
     1793        g_renderer->setVolumeLighting(name, state);
     1794    } else {
     1795        g_renderer->setVolumeLighting("all", state);
     1796    }
     1797    return TCL_OK;
     1798}
     1799
     1800static int
     1801VolumeOpacityOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1802                Tcl_Obj *const *objv)
     1803{
     1804    double opacity;
     1805    if (Tcl_GetDoubleFromObj(interp, objv[2], &opacity) != TCL_OK) {
     1806        return TCL_ERROR;
     1807    }
     1808    if (objc == 4) {
     1809        const char *name = Tcl_GetString(objv[3]);
     1810        g_renderer->setVolumeOpacity(name, opacity);
     1811    } else {
     1812        g_renderer->setVolumeOpacity("all", opacity);
     1813    }
     1814    return TCL_OK;
     1815}
     1816
     1817static int
     1818VolumeShadingAmbientOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1819                       Tcl_Obj *const *objv)
     1820{
     1821    double coeff;
     1822    if (Tcl_GetDoubleFromObj(interp, objv[3], &coeff) != TCL_OK) {
     1823        return TCL_ERROR;
     1824    }
     1825
     1826    if (objc == 5) {
     1827        const char *name = Tcl_GetString(objv[4]);
     1828        g_renderer->setVolumeAmbient(name, coeff);
     1829    } else {
     1830        g_renderer->setVolumeAmbient("all", coeff);
     1831    }
     1832    return TCL_OK;
     1833}
     1834
     1835static int
     1836VolumeShadingDiffuseOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1837                       Tcl_Obj *const *objv)
     1838{
     1839    double coeff;
     1840    if (Tcl_GetDoubleFromObj(interp, objv[3], &coeff) != TCL_OK) {
     1841        return TCL_ERROR;
     1842    }
     1843
     1844    if (objc == 5) {
     1845        const char *name = Tcl_GetString(objv[4]);
     1846        g_renderer->setVolumeDiffuse(name, coeff);
     1847    } else {
     1848        g_renderer->setVolumeDiffuse("all", coeff);
     1849    }
     1850    return TCL_OK;
     1851}
     1852
     1853static int
     1854VolumeShadingSpecularOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1855                        Tcl_Obj *const *objv)
     1856{
     1857    double coeff, power;
     1858    if (Tcl_GetDoubleFromObj(interp, objv[3], &coeff) != TCL_OK ||
     1859        Tcl_GetDoubleFromObj(interp, objv[4], &power) != TCL_OK) {
     1860        return TCL_ERROR;
     1861    }
     1862
     1863    if (objc == 6) {
     1864        const char *name = Tcl_GetString(objv[5]);
     1865        g_renderer->setVolumeSpecular(name, coeff, power);
     1866    } else {
     1867        g_renderer->setVolumeSpecular("all", coeff, power);
     1868    }
     1869    return TCL_OK;
     1870}
     1871
     1872static Rappture::CmdSpec volumeShadingOps[] = {
     1873    {"ambient",  1, VolumeShadingAmbientOp, 4, 5, "coeff ?dataSetName?"},
     1874    {"diffuse",  1, VolumeShadingDiffuseOp, 4, 5, "coeff ?dataSetName?"},
     1875    {"specular", 1, VolumeShadingSpecularOp, 5, 6, "coeff power ?dataSetName?"}
     1876};
     1877static int nVolumeShadingOps = NumCmdSpecs(volumeShadingOps);
     1878
     1879static int
     1880VolumeShadingOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1881                Tcl_Obj *const *objv)
     1882{
     1883    Tcl_ObjCmdProc *proc;
     1884
     1885    proc = Rappture::GetOpFromObj(interp, nVolumeShadingOps, volumeShadingOps,
     1886                                  Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1887    if (proc == NULL) {
     1888        return TCL_ERROR;
     1889    }
     1890    return (*proc) (clientData, interp, objc, objv);
     1891}
     1892
     1893static int
     1894VolumeVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1895                Tcl_Obj *const *objv)
     1896{
     1897    bool state;
     1898    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1899        return TCL_ERROR;
     1900    }
     1901    if (objc == 4) {
     1902        const char *name = Tcl_GetString(objv[3]);
     1903        g_renderer->setVolumeVisibility(name, state);
     1904    } else {
     1905        g_renderer->setVolumeVisibility("all", state);
     1906    }
     1907    return TCL_OK;
     1908}
     1909
     1910static Rappture::CmdSpec volumeOps[] = {
     1911    {"add",      1, VolumeAddOp, 2, 3, "?dataSetName?"},
     1912    {"colormap", 1, VolumeColorMapOp, 3, 4, "colorMapName ?dataSetName?"},
     1913    {"delete",   1, VolumeDeleteOp, 2, 3, "?dataSetName?"},
     1914    {"lighting", 1, VolumeLightingOp, 3, 4, "bool ?dataSetName?"},
     1915    {"opacity",  1, VolumeOpacityOp, 3, 4, "val ?dataSetName?"},
     1916    {"shading",  1, VolumeShadingOp, 4, 6, "oper val ?dataSetName?"},
     1917    {"visible",  1, VolumeVisibleOp, 3, 4, "bool ?dataSetName?"}
     1918};
     1919static int nVolumeOps = NumCmdSpecs(volumeOps);
     1920
     1921static int
     1922VolumeCmd(ClientData clientData, Tcl_Interp *interp, int objc,
     1923          Tcl_Obj *const *objv)
     1924{
     1925    Tcl_ObjCmdProc *proc;
     1926
     1927    proc = Rappture::GetOpFromObj(interp, nVolumeOps, volumeOps,
    17361928                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
    17371929    if (proc == NULL) {
     
    18432035    Tcl_CreateObjCommand(interp, "pseudocolor", PseudoColorCmd, NULL, NULL);
    18442036    Tcl_CreateObjCommand(interp, "screen",      ScreenCmd,      NULL, NULL);
     2037    Tcl_CreateObjCommand(interp, "volume",      VolumeCmd,      NULL, NULL);
    18452038    return interp;
    18462039}
  • trunk/packages/vizservers/vtkvis/protocol.txt

    r2260 r2261  
    116116polydata wireframe <bool> <?datasetName?>
    117117
     118volume add <?datasetName?>
     119volume colormap <colorMapName> <?datasetName?>
     120volume delete <?datasetName?>
     121volume lighting <bool> <?datasetName?>
     122volume shading ambient <coeff> <?datasetName?>
     123volume shading diffuse <coeff> <?datasetName?>
     124volume shading specular <coeff> <power> <?datasetName?>
     125volume visible <bool> <?datasetName?>
     126
    118127================================================================================
    119128Replies:
Note: See TracChangeset for help on using the changeset viewer.