Changeset 2402 for trunk/packages


Ignore:
Timestamp:
Aug 22, 2011, 2:15:12 AM (13 years ago)
Author:
ldelgass
Message:
  • Let graphics objects handle DataSet? cumulative range changes, track vectors as well as scalars, also supply cumulative ranges in setDataSet()
  • Be more consistent about naming enums and commands for vectors
  • Add constructor arguments to some graphics objects to speed initialization (eliminates some pipeline changes)
  • Apply a scale factor to glyphs based on cell sizes
  • Add line glyph shape
  • Don't delete ColorMaps? in use
  • Update graphics objects when a ColorMap? is edited
Location:
trunk/packages/vizservers/vtkvis
Files:
28 edited

Legend:

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

    r2332 r2402  
    219219        }
    220220        if (itr2 == _controlPoints.end()) {
     221#ifdef DEBUG
    221222            TRACE("val: %g Range: %g - 1 Color: %g %g %g", value, itr->value,
    222223                  itr->color[0], itr->color[1], itr->color[2]);
     224#endif
    223225            memcpy(color, itr->color, sizeof(double)*3);
    224226        } else {
     
    226228            assert(value >= itr->value && value <= itr2->value);
    227229            lerp(color, *itr, *itr2, value);
     230#ifdef DEBUG
    228231            TRACE("val: %g Range: %g - %g Color: %g %g %g", value, itr->value, itr2->value,
    229232                  color[0], color[1], color[2]);
     233#endif
    230234        }
    231235        if (oitr2 == _opacityControlPoints.end()) {
     236#ifdef DEBUG
    232237            TRACE("val: %g Range: %g - 1 Alpha %g", value, oitr->value,
    233238                  oitr->alpha);
     239#endif
    234240            color[3] = oitr->alpha;
    235241        } else {
     
    237243            assert(value >= oitr->value && value <= oitr2->value);
    238244            lerp(&color[3], *oitr, *oitr2, value);
     245#ifdef DEBUG
    239246            TRACE("val: %g Range: %g - %g Alpha: %g", value, oitr->value, oitr2->value,
    240247                  color[3]);
     248#endif
    241249        }
    242250        _lookupTable->SetTableValue(i, color);
  • trunk/packages/vizservers/vtkvis/Makefile.in

    r2348 r2402  
    131131PPMWriter.o: PPMWriter.h Trace.h
    132132RpContour2D.o: RpContour2D.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
    133 RpContour3D.o: RpContour3D.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
     133RpContour3D.o: RpContour3D.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    134134RpGlyphs.o: RpGlyphs.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    135 RpHeightMap.o: RpHeightMap.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
    136 RpLIC.o: RpLIC.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h RpVtkRenderServer.h
     135RpHeightMap.o: RpHeightMap.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
     136RpLIC.o: RpLIC.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h RpVtkRenderServer.h
    137137RpMolecule.o: RpMolecule.h RpMoleculeData.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    138138RpPolyData.o: RpPolyData.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
    139 RpPseudoColor.o: RpPseudoColor.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
    140 RpStreamlines.o: RpStreamlines.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
     139RpPseudoColor.o: RpPseudoColor.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
     140RpStreamlines.o: RpStreamlines.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    141141RpVolume.o: RpVolume.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    142142RpVtkDataSet.o: RpVtkDataSet.h Trace.h
  • trunk/packages/vizservers/vtkvis/RpContour2D.cpp

    r2328 r2402  
    2525using namespace Rappture::VtkVis;
    2626
    27 Contour2D::Contour2D() :
     27Contour2D::Contour2D(int numContours) :
    2828    VtkGraphicsObject(),
    29     _numContours(0)
    30 {
    31     _dataRange[0] = 0;
    32     _dataRange[1] = 1;
     29    _numContours(numContours)
     30{
     31}
     32
     33Contour2D::Contour2D(const std::vector<double>& contours) :
     34    VtkGraphicsObject(),
     35    _numContours(contours.size()),
     36    _contours(contours)
     37{
    3338}
    3439
     
    4146        TRACE("Deleting Contour2D with NULL DataSet");
    4247#endif
    43 }
    44 
    45 /**
    46  * \brief Specify input DataSet used to extract contours
    47  */
    48 void Contour2D::setDataSet(DataSet *dataSet)
    49 {
    50     if (_dataSet != dataSet) {
    51         _dataSet = dataSet;
    52 
    53         if (_dataSet != NULL) {
    54             double dataRange[2];
    55             _dataSet->getDataRange(dataRange);
    56             _dataRange[0] = dataRange[0];
    57             _dataRange[1] = dataRange[1];
    58         }
    59 
    60         update();
    61     }
    6248}
    6349
     
    175161}
    176162
     163void Contour2D::updateRanges(bool useCumulative,
     164                             double scalarRange[2],
     165                             double vectorMagnitudeRange[2],
     166                             double vectorComponentRange[3][2])
     167{
     168    if (useCumulative) {
     169        _dataRange[0] = scalarRange[0];
     170        _dataRange[1] = scalarRange[1];
     171    } else if (_dataSet != NULL) {
     172        _dataSet->getScalarRange(_dataRange);
     173    } else {
     174        WARN("updateRanges called before setDataSet");
     175    }
     176
     177    if (_contours.empty() && _numContours > 0) {
     178        // Contour isovalues need to be recomputed
     179        update();
     180    }
     181}
     182
    177183/**
    178184 * \brief Specify number of evenly spaced contour lines to render
     
    185191    _numContours = numContours;
    186192
    187     if (_dataSet != NULL) {
    188         double dataRange[2];
    189         _dataSet->getDataRange(dataRange);
    190         _dataRange[0] = dataRange[0];
    191         _dataRange[1] = dataRange[1];
    192     }
    193 
    194     update();
    195 }
    196 
    197 /**
    198  * \brief Specify number of evenly spaced contour lines to render
    199  * between the given range (including range endpoints)
    200  *
    201  * Will override any existing contours
    202  */
    203 void Contour2D::setContours(int numContours, double range[2])
    204 {
    205     _contours.clear();
    206     _numContours = numContours;
    207 
    208     _dataRange[0] = range[0];
    209     _dataRange[1] = range[1];
    210 
    211193    update();
    212194}
  • trunk/packages/vizservers/vtkvis/RpContour2D.h

    r2328 r2402  
    2727class Contour2D : public VtkGraphicsObject {
    2828public:
    29     Contour2D();
     29    Contour2D(int numContours);
     30
     31    Contour2D(const std::vector<double>& contours);
     32
    3033    virtual ~Contour2D();
    3134
     
    3538    }
    3639
    37     virtual void setDataSet(DataSet *dataset);
    38 
    3940    virtual void setClippingPlanes(vtkPlaneCollection *planes);
    4041
    4142    void setContours(int numContours);
    42 
    43     void setContours(int numContours, double range[2]);
    4443
    4544    void setContourList(const std::vector<double>& contours);
     
    4948    const std::vector<double>& getContourList() const;
    5049
     50    virtual void updateRanges(bool useCumulative,
     51                              double scalarRange[2],
     52                              double vectorMagnitudeRange[2],
     53                              double vectorComponentRange[3][2]);
     54
    5155private:
     56    Contour2D();
     57
    5258    virtual void initProp();
    5359    virtual void update();
     
    5561    int _numContours;
    5662    std::vector<double> _contours;
    57     double _dataRange[2];
    5863
    5964    vtkSmartPointer<vtkContourFilter> _contourFilter;
  • trunk/packages/vizservers/vtkvis/RpContour3D.cpp

    r2328 r2402  
    2525using namespace Rappture::VtkVis;
    2626
    27 Contour3D::Contour3D() :
     27Contour3D::Contour3D(int numContours) :
    2828    VtkGraphicsObject(),
    29     _numContours(0)
    30 {
    31     _dataRange[0] = 0;
    32     _dataRange[1] = 1;
     29    _numContours(numContours),
     30    _colorMap(NULL)
     31{
     32    _color[0] = 0.0f;
     33    _color[1] = 0.0f;
     34    _color[2] = 1.0f;
     35}
     36
     37Contour3D::Contour3D(const std::vector<double>& contours) :
     38    VtkGraphicsObject(),
     39    _numContours(contours.size()),
     40    _contours(contours),
     41    _colorMap(NULL)
     42{
    3343    _color[0] = 0.0f;
    3444    _color[1] = 0.0f;
     
    4454        TRACE("Deleting Contour3D with NULL DataSet");
    4555#endif
    46 }
    47 
    48 /**
    49  * \brief Specify input DataSet used to extract contours
    50  */
    51 void Contour3D::setDataSet(DataSet *dataSet)
    52 {
    53     if (_dataSet != dataSet) {
    54         _dataSet = dataSet;
    55 
    56         if (_dataSet != NULL) {
    57             double dataRange[2];
    58             _dataSet->getDataRange(dataRange);
    59             _dataRange[0] = dataRange[0];
    60             _dataRange[1] = dataRange[1];
    61         }
    62 
    63         update();
    64     }
    6556}
    6657
     
    8576
    8677/**
    87  * \brief Get the VTK colormap lookup table in use
    88  */
    89 vtkLookupTable *Contour3D::getLookupTable()
    90 { 
    91     return _lut;
     78 * \brief Called when the color map has been edited
     79 */
     80void Contour3D::updateColorMap()
     81{
     82    setColorMap(_colorMap);
    9283}
    9384
     
    9586 * \brief Associate a colormap lookup table with the DataSet
    9687 */
    97 void Contour3D::setLookupTable(vtkLookupTable *lut)
    98 {
    99     if (lut == NULL) {
     88void Contour3D::setColorMap(ColorMap *cmap)
     89{
     90    if (cmap == NULL)
     91        return;
     92
     93    _colorMap = cmap;
     94 
     95    if (_lut == NULL) {
    10096        _lut = vtkSmartPointer<vtkLookupTable>::New();
    101     } else {
    102         _lut = lut;
    103     }
    104 
    105     if (_contourMapper != NULL) {
    106         _contourMapper->UseLookupTableScalarRangeOn();
    107         _contourMapper->SetLookupTable(_lut);
    108     }
     97        if (_contourMapper != NULL) {
     98            _contourMapper->UseLookupTableScalarRangeOn();
     99            _contourMapper->SetLookupTable(_lut);
     100        }
     101    }
     102
     103    _lut->DeepCopy(cmap->getLookupTable());
     104    _lut->SetRange(_dataRange);
    109105}
    110106
     
    198194    }
    199195
    200     if (ds->GetPointData() == NULL ||
    201         ds->GetPointData()->GetScalars() == NULL) {
    202         if (_lut == NULL) {
    203             _lut = vtkSmartPointer<vtkLookupTable>::New();
    204         }
    205     } else {
    206         vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable();
    207         TRACE("Data set scalars lookup table: %p\n", lut);
    208         if (_lut == NULL) {
    209             if (lut)
    210                 _lut = lut;
    211             else
    212                 _lut = vtkSmartPointer<vtkLookupTable>::New();
    213         }
    214     }
    215 
    216     if (_lut != NULL) {
    217         _lut->SetRange(_dataRange);
    218 
    219         _contourMapper->SetColorModeToMapScalars();
    220         _contourMapper->UseLookupTableScalarRangeOn();
    221         _contourMapper->SetLookupTable(_lut);
     196    if (_lut == NULL) {
     197        setColorMap(ColorMap::getDefault());
    222198    }
    223199
     
    228204}
    229205
     206void Contour3D::updateRanges(bool useCumulative,
     207                             double scalarRange[2],
     208                             double vectorMagnitudeRange[2],
     209                             double vectorComponentRange[3][2])
     210{
     211    if (useCumulative) {
     212        _dataRange[0] = scalarRange[0];
     213        _dataRange[1] = scalarRange[1];
     214    } else if (_dataSet != NULL) {
     215        _dataSet->getScalarRange(_dataRange);
     216    }
     217
     218    if (_lut != NULL) {
     219        _lut->SetRange(_dataRange);
     220    }
     221
     222    if (_contours.empty() && _numContours > 0) {
     223        // Need to recompute isovalues
     224        update();
     225    }
     226}
     227
    230228/**
    231229 * \brief Specify number of evenly spaced isosurfaces to render
     
    238236    _numContours = numContours;
    239237
    240     if (_dataSet != NULL) {
    241         double dataRange[2];
    242         _dataSet->getDataRange(dataRange);
    243         _dataRange[0] = dataRange[0];
    244         _dataRange[1] = dataRange[1];
    245     }
    246 
    247     update();
    248 }
    249 
    250 /**
    251  * \brief Specify number of evenly spaced isosurfaces to render
    252  * between the given range (including range endpoints)
    253  *
    254  * Will override any existing contours
    255  */
    256 void Contour3D::setContours(int numContours, double range[2])
    257 {
    258     _contours.clear();
    259     _numContours = numContours;
    260 
    261     _dataRange[0] = range[0];
    262     _dataRange[1] = range[1];
    263 
    264238    update();
    265239}
  • trunk/packages/vizservers/vtkvis/RpContour3D.h

    r2328 r2402  
    1818#include <vector>
    1919
     20#include "ColorMap.h"
    2021#include "RpVtkGraphicsObject.h"
    2122
     
    2829class Contour3D : public VtkGraphicsObject {
    2930public:
    30     Contour3D();
     31    Contour3D(int numContours);
     32
     33    Contour3D(const std::vector<double>& contours);
     34
    3135    virtual ~Contour3D();
    3236
     
    3640    }
    3741
    38     virtual void setDataSet(DataSet *dataset);
    39 
    4042    virtual void setClippingPlanes(vtkPlaneCollection *planes);
    4143
    4244    void setContours(int numContours);
    43 
    44     void setContours(int numContours, double range[2]);
    4545
    4646    void setContourList(const std::vector<double>& contours);
     
    5050    const std::vector<double>& getContourList() const;
    5151
    52     void setLookupTable(vtkLookupTable *lut);
     52    void setColorMap(ColorMap *colorMap);
    5353
    54     vtkLookupTable *getLookupTable();
     54    /**
     55     * \brief Return the ColorMap in use
     56     */
     57    ColorMap *getColorMap()
     58    {
     59        return _colorMap;
     60    }
     61
     62    void updateColorMap();
     63
     64    virtual void updateRanges(bool useCumulative,
     65                              double scalarRange[2],
     66                              double vectorMagnitudeRange[2],
     67                              double vectorComponentRange[3][2]);
    5568
    5669private:
     70    Contour3D();
     71
    5772    virtual void initProp();
    5873    virtual void update();
     
    6075    int _numContours;
    6176    std::vector<double> _contours;
    62     double _dataRange[2];
     77    ColorMap *_colorMap;
    6378
    6479    vtkSmartPointer<vtkContourFilter> _contourFilter;
  • trunk/packages/vizservers/vtkvis/RpGlyphs.cpp

    r2393 r2402  
    1414#include <vtkProperty.h>
    1515#include <vtkGlyph3D.h>
     16#include <vtkLineSource.h>
    1617#include <vtkArrowSource.h>
    1718#include <vtkConeSource.h>
     
    1920#include <vtkPlatonicSolidSource.h>
    2021#include <vtkSphereSource.h>
     22#include <vtkTransform.h>
    2123#include <vtkPolyDataMapper.h>
     24#include <vtkTransformPolyDataFilter.h>
    2225
    2326#include "RpGlyphs.h"
     
    2629using namespace Rappture::VtkVis;
    2730
    28 Glyphs::Glyphs() :
     31Glyphs::Glyphs(GlyphShape shape) :
    2932    VtkGraphicsObject(),
    30     _glyphShape(ARROW),
     33    _glyphShape(shape),
     34    _scalingMode(SCALE_BY_VECTOR_MAGNITUDE),
     35    _dataScale(1.0),
    3136    _scaleFactor(1.0),
    32     _colorMode(COLOR_BY_SCALAR)
     37    _colorMode(COLOR_BY_SCALAR),
     38    _colorMap(NULL)
    3339{
    3440    _faceCulling = true;
     
    3945}
    4046
     47void Glyphs::setDataSet(DataSet *dataSet,
     48                        bool useCumulative,
     49                        double scalarRange[2],
     50                        double vectorMagnitudeRange[2],
     51                        double vectorComponentRange[3][2])
     52{
     53    if (_dataSet != dataSet) {
     54        _dataSet = dataSet;
     55
     56        if (useCumulative) {
     57            _dataRange[0] = scalarRange[0];
     58            _dataRange[1] = scalarRange[1];
     59            _vectorMagnitudeRange[0] = vectorMagnitudeRange[0];
     60            _vectorMagnitudeRange[1] = vectorMagnitudeRange[1];
     61            for (int i = 0; i < 3; i++) {
     62                _vectorComponentRange[i][0] = vectorComponentRange[i][0];
     63                _vectorComponentRange[i][1] = vectorComponentRange[i][1];
     64            }
     65        } else {
     66            _dataSet->getScalarRange(_dataRange);
     67            _dataSet->getVectorRange(_vectorMagnitudeRange);
     68            for (int i = 0; i < 3; i++) {
     69                _dataSet->getVectorRange(_vectorComponentRange[i], i);
     70            }
     71        }
     72
     73        update();
     74    }
     75}
     76
    4177/**
    4278 * \brief Set the shape of the glyphs
     
    4581{
    4682    _glyphShape = shape;
     83
     84    // Note: using vtkTransformPolyDataFilter instead of the vtkGlyph3D's
     85    // SourceTransform because of a bug: vtkGlyph3D doesn't transform normals
     86    // by the SourceTransform, so the lighting would be wrong
     87
    4788    switch (_glyphShape) {
     89    case LINE:
     90        _glyphSource = vtkSmartPointer<vtkLineSource>::New();
     91        break;
    4892    case ARROW:
    49         _glyphSource = vtkSmartPointer<vtkArrowSource>::New();
    50         break;
     93        _glyphSource = vtkSmartPointer<vtkArrowSource>::New();
     94        break;
    5195    case CONE:
    52         _glyphSource = vtkSmartPointer<vtkConeSource>::New();
    53         break;
     96        _glyphSource = vtkSmartPointer<vtkConeSource>::New();
     97        break;
    5498    case CUBE:
    55         _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    56         vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToCube();
    57         break;
    58     case CYLINDER:
    59         _glyphSource = vtkSmartPointer<vtkCylinderSource>::New();
    60         break;
     99        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
     100        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToCube();
     101        break;
     102    case CYLINDER: {
     103        vtkSmartPointer<vtkCylinderSource> csource = vtkSmartPointer<vtkCylinderSource>::New();
     104        vtkCylinderSource::SafeDownCast(csource)->SetResolution(6);
     105        _glyphSource = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
     106        _glyphSource->SetInputConnection(csource->GetOutputPort());
     107        vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     108        trans->RotateZ(-90.0);
     109        vtkTransformPolyDataFilter::SafeDownCast(_glyphSource)->SetTransform(trans);
     110      }
     111        break;
    61112    case DODECAHEDRON:
    62         _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    63         vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToDodecahedron();
    64         break;
     113        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
     114        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToDodecahedron();
     115        break;
    65116    case ICOSAHEDRON:
    66         _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    67         vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToIcosahedron();
    68         break;
     117        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
     118        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToIcosahedron();
     119        break;
    69120    case OCTAHEDRON:
    70         _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    71         vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToOctahedron();
    72         break;
     121        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
     122        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToOctahedron();
     123        break;
    73124    case SPHERE:
    74         _glyphSource = vtkSmartPointer<vtkSphereSource>::New();
    75         break;
     125        _glyphSource = vtkSmartPointer<vtkSphereSource>::New();
     126        break;
    76127    case TETRAHEDRON:
    77         _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    78         vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToTetrahedron();
    79         break;
     128        // FIXME: need to rotate inital orientation
     129        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
     130        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToTetrahedron();
     131        break;
    80132    default:
    81         ERROR("Unknown glyph shape: %d", _glyphShape);
    82         return;
     133        ERROR("Unknown glyph shape: %d", _glyphShape);
     134        return;
    83135    }
    84136
     
    92144
    93145    if (_glyphGenerator != NULL) {
    94         _glyphGenerator->SetSourceConnection(_glyphSource->GetOutputPort());
     146        _glyphGenerator->SetSourceConnection(_glyphSource->GetOutputPort());
    95147    }
    96148}
     
    136188
    137189    if (ds->GetPointData()->GetVectors() != NULL) {
    138         _glyphGenerator->SetScaleModeToScaleByVector();
     190        TRACE("Setting scale mode to vector magnitude");
     191        _scalingMode = SCALE_BY_VECTOR_MAGNITUDE;
     192        _glyphGenerator->SetScaleModeToScaleByVector();
     193        _glyphGenerator->SetRange(_vectorMagnitudeRange);
    139194    } else {
    140         _glyphGenerator->SetScaleModeToScaleByScalar();
    141     }
    142     _glyphGenerator->SetScaleFactor(_scaleFactor);
     195        TRACE("Setting scale mode to scalar");
     196        _scalingMode = SCALE_BY_SCALAR;
     197        _glyphGenerator->SetScaleModeToScaleByScalar();
     198        _glyphGenerator->SetRange(_dataRange);
     199    }
     200
     201    // Normalize sizes to [0,1] * ScaleFactor
     202    _glyphGenerator->ClampingOn();
     203
     204    double cellSizeRange[2];
     205    double avgSize;
     206    _dataSet->getCellSizeRange(cellSizeRange, &avgSize);
     207    //_dataScale = cellSizeRange[0] + (cellSizeRange[1] - cellSizeRange[0])/2.;
     208    _dataScale = avgSize;
     209
     210    TRACE("Cell size range: %g,%g, Data scale factor: %g",
     211          cellSizeRange[0], cellSizeRange[1], _dataScale);
     212
     213    _glyphGenerator->SetScaleFactor(_scaleFactor * _dataScale);
    143214    _glyphGenerator->ScalingOn();
    144215
     
    146217        TRACE("Setting color mode to vector magnitude");
    147218        _glyphGenerator->SetColorModeToColorByVector();
    148         _colorMode = COLOR_BY_VECTOR;
     219        _colorMode = COLOR_BY_VECTOR_MAGNITUDE;
    149220    } else {
    150221        TRACE("Setting color mode to scalar");
     
    152223        _colorMode = COLOR_BY_SCALAR;
    153224    }
    154     if (_glyphShape == SPHERE) {
    155         _glyphGenerator->OrientOff();
    156     }
    157225
    158226    if (_pdMapper == NULL) {
     
    161229        _pdMapper->ScalarVisibilityOn();
    162230    }
     231
    163232    _pdMapper->SetInputConnection(_glyphGenerator->GetOutputPort());
    164233
    165     if (ds->GetPointData() == NULL ||
    166         ds->GetPointData()->GetScalars() == NULL) {
    167         if (_lut == NULL) {
    168             _lut = vtkSmartPointer<vtkLookupTable>::New();
    169         }
    170     } else {
    171         vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable();
    172         TRACE("Data set scalars lookup table: %p\n", lut);
    173         if (_lut == NULL) {
    174             if (lut)
    175                 _lut = lut;
    176             else
    177                 _lut = vtkSmartPointer<vtkLookupTable>::New();
    178         }
    179     }
    180 
    181     if (ds->GetPointData()->GetScalars() == NULL) {
    182         double dataRange[2];
    183         _dataSet->getVectorMagnitudeRange(dataRange);
    184         _lut->SetRange(dataRange);
    185         //_pdMapper->SetScalarModeToUsePointFieldData();
    186         //_pdMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
    187     } else {
    188         double dataRange[2];
    189         _dataSet->getDataRange(dataRange);
    190         _lut->SetRange(dataRange);
    191         //_pdMapper->SetScalarModeToDefault();
    192     }
    193 
    194     //_lut->SetVectorModeToMagnitude();
    195     _pdMapper->SetLookupTable(_lut);
    196     _pdMapper->UseLookupTableScalarRangeOn();
     234    if (_lut == NULL) {
     235        setColorMap(ColorMap::getDefault());
     236    }
    197237
    198238    getActor()->SetMapper(_pdMapper);
     
    205245void Glyphs::setScalingMode(ScalingMode mode)
    206246{
     247    _scalingMode = mode;
    207248    if (_glyphGenerator != NULL) {
    208249        switch (mode) {
    209         case SCALE_BY_SCALAR:
     250        case SCALE_BY_SCALAR: {
     251            _glyphGenerator->SetRange(_dataRange);
    210252            _glyphGenerator->SetScaleModeToScaleByScalar();
    211             _glyphGenerator->ScalingOn();
    212             break;
    213         case SCALE_BY_VECTOR:
     253        }
     254            break;
     255        case SCALE_BY_VECTOR_MAGNITUDE: {
     256            _glyphGenerator->SetRange(_vectorMagnitudeRange);
    214257            _glyphGenerator->SetScaleModeToScaleByVector();
    215             _glyphGenerator->ScalingOn();
    216             break;
    217         case SCALE_BY_VECTOR_COMPONENTS:
     258        }
     259            break;
     260        case SCALE_BY_VECTOR_COMPONENTS: {
     261            double sizeRange[2];
     262            sizeRange[0] = _vectorComponentRange[0][0];
     263            sizeRange[1] = _vectorComponentRange[0][1];
     264            sizeRange[0] = min2(sizeRange[0], _vectorComponentRange[1][0]);
     265            sizeRange[1] = max2(sizeRange[1], _vectorComponentRange[1][1]);
     266            sizeRange[0] = min2(sizeRange[0], _vectorComponentRange[2][0]);
     267            sizeRange[1] = max2(sizeRange[1], _vectorComponentRange[2][1]);
     268            _glyphGenerator->SetRange(sizeRange);
    218269            _glyphGenerator->SetScaleModeToScaleByVectorComponents();
    219             _glyphGenerator->ScalingOn();
     270        }
    220271            break;
    221272        case SCALING_OFF:
    222273        default:
    223274            _glyphGenerator->SetScaleModeToDataScalingOff();
    224             _glyphGenerator->ScalingOff();
    225         }
    226         _pdMapper->Update();
     275        }
    227276    }
    228277}
     
    239288            _glyphGenerator->SetColorModeToColorByScale();
    240289            _pdMapper->ScalarVisibilityOn();
    241             break;
    242         case COLOR_BY_VECTOR: {
     290            double dataRange[2];
     291            dataRange[0] = 0;
     292            dataRange[1] = 1;
     293            _lut->SetRange(dataRange);
     294            break;
     295        case COLOR_BY_VECTOR_MAGNITUDE: {
    243296            _glyphGenerator->SetColorModeToColorByVector();
    244            _pdMapper->ScalarVisibilityOn();
    245             double dataRange[2];
    246             _dataSet->getVectorMagnitudeRange(dataRange);
    247             _lut->SetRange(dataRange);
     297            _pdMapper->ScalarVisibilityOn();
     298            _lut->SetRange(_vectorMagnitudeRange);
    248299        }
    249300            break;
    250301        case COLOR_BY_SCALAR: {
    251302            _glyphGenerator->SetColorModeToColorByScalar();
    252            _pdMapper->ScalarVisibilityOn();
    253             double dataRange[2];
    254             _dataSet->getDataRange(dataRange);
    255             _lut->SetRange(dataRange);
     303            _pdMapper->ScalarVisibilityOn();
     304            _lut->SetRange(_dataRange);
    256305        }
    257306            break;
     
    260309            _pdMapper->ScalarVisibilityOff();
    261310        }
    262         _pdMapper->Update();
    263     }
     311     }
    264312}
    265313
     
    271319    _scaleFactor = scale;
    272320    if (_glyphGenerator != NULL) {
    273         _glyphGenerator->SetScaleFactor(scale);
    274         _pdMapper->Update();
    275     }
    276 }
    277 
    278 /**
    279  * \brief Get the VTK colormap lookup table in use
    280  */
    281 vtkLookupTable *Glyphs::getLookupTable()
    282 {
    283     return _lut;
     321        _glyphGenerator->SetScaleFactor(_scaleFactor * _dataScale);
     322    }
     323}
     324
     325void Glyphs::updateRanges(bool useCumulative,
     326                          double scalarRange[2],
     327                          double vectorMagnitudeRange[2],
     328                          double vectorComponentRange[3][2])
     329{
     330    if (useCumulative) {
     331        _dataRange[0] = scalarRange[0];
     332        _dataRange[1] = scalarRange[1];
     333        _vectorMagnitudeRange[0] = vectorMagnitudeRange[0];
     334        _vectorMagnitudeRange[1] = vectorMagnitudeRange[1];
     335        for (int i = 0; i < 3; i++) {
     336            _vectorComponentRange[i][0] = vectorComponentRange[i][0];
     337            _vectorComponentRange[i][1] = vectorComponentRange[i][1];
     338        }
     339    } else {
     340        _dataSet->getScalarRange(_dataRange);
     341        _dataSet->getVectorRange(_vectorMagnitudeRange);
     342        for (int i = 0; i < 3; i++) {
     343            _dataSet->getVectorRange(_vectorComponentRange[i], i);
     344        }
     345    }
     346
     347    // Need to update color map ranges and/or active vector field
     348    setColorMode(_colorMode);
     349    setScalingMode(_scalingMode);
     350}
     351
     352/**
     353 * \brief Called when the color map has been edited
     354 */
     355void Glyphs::updateColorMap()
     356{
     357    setColorMap(_colorMap);
    284358}
    285359
     
    287361 * \brief Associate a colormap lookup table with the DataSet
    288362 */
    289 void Glyphs::setLookupTable(vtkLookupTable *lut)
    290 {
    291     if (lut == NULL) {
     363void Glyphs::setColorMap(ColorMap *cmap)
     364{
     365    if (cmap == NULL)
     366        return;
     367
     368    _colorMap = cmap;
     369 
     370    if (_lut == NULL) {
    292371        _lut = vtkSmartPointer<vtkLookupTable>::New();
    293     } else {
    294         _lut = lut;
    295     }
     372        if (_pdMapper != NULL) {
     373            _pdMapper->UseLookupTableScalarRangeOn();
     374            _pdMapper->SetLookupTable(_lut);
     375        }
     376    }
     377
     378    _lut->DeepCopy(cmap->getLookupTable());
    296379
    297380    switch (_colorMode) {
    298     case COLOR_BY_VECTOR: {
     381    case COLOR_BY_SCALE: {
    299382        double dataRange[2];
    300         _dataSet->getVectorMagnitudeRange(dataRange);
     383        dataRange[0] = 0;
     384        dataRange[1] = 1;
    301385        _lut->SetRange(dataRange);
    302386    }
    303387        break;
     388    case COLOR_BY_VECTOR_MAGNITUDE:
     389        _lut->SetRange(_vectorMagnitudeRange);
     390        break;
    304391    case COLOR_BY_SCALAR:
    305     default: {
    306         double dataRange[2];
    307         _dataSet->getDataRange(dataRange);
    308         _lut->SetRange(dataRange);
    309     }
    310         break;
    311     }
    312 
    313     if (_pdMapper != NULL) {
    314         _pdMapper->SetLookupTable(_lut);
     392    default:
     393        _lut->SetRange(_dataRange);
     394        break;
    315395    }
    316396}
  • trunk/packages/vizservers/vtkvis/RpGlyphs.h

    r2393 r2402  
    3939        DODECAHEDRON,
    4040        ICOSAHEDRON,
     41        LINE,
    4142        OCTAHEDRON,
    4243        SPHERE,
     
    4546    enum ScalingMode {
    4647        SCALE_BY_SCALAR,
    47         SCALE_BY_VECTOR,
     48        SCALE_BY_VECTOR_MAGNITUDE,
    4849        SCALE_BY_VECTOR_COMPONENTS,
    4950        SCALING_OFF
     
    5253        COLOR_BY_SCALE,
    5354        COLOR_BY_SCALAR,
    54         COLOR_BY_VECTOR,
     55        COLOR_BY_VECTOR_MAGNITUDE,
    5556        COLOR_CONSTANT
    5657    };
    5758
    58     Glyphs();
     59    Glyphs(GlyphShape shape);
    5960    virtual ~Glyphs();
    6061
     
    6364        return "Glyphs";
    6465    }
     66
     67    virtual void setDataSet(DataSet *dataSet,
     68                            bool useCumulative,
     69                            double scalarRange[2],
     70                            double vectorMagnitudeRange[2],
     71                            double vectorComponentRange[3][2]);
    6572
    6673    virtual void setClippingPlanes(vtkPlaneCollection *planes);
     
    7481    void setScaleFactor(double scale);
    7582
    76     void setLookupTable(vtkLookupTable *lut);
     83    void setColorMap(ColorMap *colorMap);
    7784
    78     vtkLookupTable *getLookupTable();
     85    /**
     86     * \brief Return the ColorMap in use
     87     */
     88    ColorMap *getColorMap()
     89    {
     90        return _colorMap;
     91    }
     92
     93    void updateColorMap();
     94
     95    virtual void updateRanges(bool useCumulative,
     96                              double scalarRange[2],
     97                              double vectorMagnitudeRange[2],
     98                              double vectorComponentRange[3][2]);
    7999
    80100private:
     101    Glyphs();
    81102    virtual void update();
     103    static inline double min2(double a, double b)
     104    {
     105        return ((a < b) ? a : b);
     106    }
     107    static inline double max2(double a, double b)
     108    {
     109        return ((a > b) ? a : b);
     110    }
    82111
    83112    GlyphShape _glyphShape;
     113    ScalingMode _scalingMode;
     114    double _dataScale;
    84115    double _scaleFactor;
    85116    ColorMode _colorMode;
     117    ColorMap *_colorMap;
     118    double _vectorMagnitudeRange[2];
     119    double _vectorComponentRange[3][2];
    86120
    87121    vtkSmartPointer<vtkLookupTable> _lut;
  • trunk/packages/vizservers/vtkvis/RpHeightMap.cpp

    r2328 r2402  
    3535#define MESH_POINT_CLOUDS
    3636
    37 HeightMap::HeightMap() :
     37HeightMap::HeightMap(int numContours) :
    3838    VtkGraphicsObject(),
    39     _numContours(0),
     39    _numContours(numContours),
     40    _colorMap(NULL),
    4041    _contourEdgeWidth(1.0),
    4142    _warpScale(1.0),
     
    4344    _pipelineInitialized(false)
    4445{
    45     _dataRange[0] = 0.0;
    46     _dataRange[1] = 1.0;
     46    _contourEdgeColor[0] = 1.0f;
     47    _contourEdgeColor[1] = 0.0f;
     48    _contourEdgeColor[2] = 0.0f;
     49}
     50
     51HeightMap::HeightMap(const std::vector<double>& contours) :
     52    VtkGraphicsObject(),
     53    _numContours(contours.size()),
     54    _contours(contours),
     55    _colorMap(NULL),
     56    _contourEdgeWidth(1.0),
     57    _warpScale(1.0),
     58    _sliceAxis(Z_AXIS),
     59    _pipelineInitialized(false)
     60{
    4761    _contourEdgeColor[0] = 1.0f;
    4862    _contourEdgeColor[1] = 0.0f;
     
    6074}
    6175
    62 /**
    63  * \brief Specify input DataSet with scalars to colormap
    64  *
    65  * Currently the DataSet must be image data (2D uniform grid)
    66  */
    67 void HeightMap::setDataSet(DataSet *dataSet)
     76void HeightMap::setDataSet(DataSet *dataSet,
     77                           bool useCumulative,
     78                           double scalarRange[2],
     79                           double vectorMagnitudeRange[2],
     80                           double vectorComponentRange[3][2])
    6881{
    6982    if (_dataSet != dataSet) {
     
    7184
    7285        if (_dataSet != NULL) {
    73             double dataRange[2];
    74             _dataSet->getDataRange(dataRange);
    75             _dataRange[0] = dataRange[0];
    76             _dataRange[1] = dataRange[1];
     86            if (useCumulative) {
     87                _dataRange[0] = scalarRange[0];
     88                _dataRange[1] = scalarRange[1];
     89            } else {
     90                dataSet->getScalarRange(_dataRange);
     91            }
    7792
    7893            // Compute a data scaling factor to make maximum
     
    331346    _pipelineInitialized = true;
    332347
    333     if (ds->GetPointData() == NULL ||
    334         ds->GetPointData()->GetScalars() == NULL) {
    335         ERROR("No scalar point data in dataset %s", _dataSet->getName().c_str());
    336         if (_lut == NULL) {
    337             _lut = vtkSmartPointer<vtkLookupTable>::New();
    338         }
    339     } else {
    340         vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable();
    341         TRACE("Data set scalars lookup table: %p\n", lut);
    342         if (_lut == NULL) {
    343             if (lut)
    344                 _lut = lut;
    345             else {
    346                 _lut = vtkSmartPointer<vtkLookupTable>::New();
    347             }
    348         }
    349     }
    350 
    351     _lut->SetRange(_dataRange);
     348    if (_lut == NULL) {
     349        setColorMap(ColorMap::getDefault());
     350    }
     351    //_dsMapper->InterpolateScalarsBeforeMappingOn();
    352352
    353353    initProp();
    354 
    355     _dsMapper->SetColorModeToMapScalars();
    356     _dsMapper->UseLookupTableScalarRangeOn();
    357     _dsMapper->SetLookupTable(_lut);
    358     //_dsMapper->InterpolateScalarsBeforeMappingOn();
    359354
    360355    _contourFilter->ComputeNormalsOff();
     
    615610
    616611/**
    617  * \brief Get the VTK colormap lookup table in use
    618  */
    619 vtkLookupTable *HeightMap::getLookupTable()
    620 { 
    621     return _lut;
     612 * \brief Called when the color map has been edited
     613 */
     614void HeightMap::updateColorMap()
     615{
     616    setColorMap(_colorMap);
    622617}
    623618
     
    625620 * \brief Associate a colormap lookup table with the DataSet
    626621 */
    627 void HeightMap::setLookupTable(vtkLookupTable *lut)
    628 {
    629     if (lut == NULL) {
     622void HeightMap::setColorMap(ColorMap *cmap)
     623{
     624    if (cmap == NULL)
     625        return;
     626
     627    _colorMap = cmap;
     628 
     629    if (_lut == NULL) {
    630630        _lut = vtkSmartPointer<vtkLookupTable>::New();
    631     } else {
    632         _lut = lut;
    633     }
    634 
    635     if (_dsMapper != NULL) {
    636         _dsMapper->UseLookupTableScalarRangeOn();
    637         _dsMapper->SetLookupTable(_lut);
     631        if (_dsMapper != NULL) {
     632            _dsMapper->UseLookupTableScalarRangeOn();
     633            _dsMapper->SetLookupTable(_lut);
     634        }
     635    }
     636
     637    _lut->DeepCopy(cmap->getLookupTable());
     638    _lut->SetRange(_dataRange);
     639}
     640
     641void HeightMap::updateRanges(bool useCumulative,
     642                             double scalarRange[2],
     643                             double vectorMagnitudeRange[2],
     644                             double vectorComponentRange[3][2])
     645{
     646    if (useCumulative) {
     647        _dataRange[0] = scalarRange[0];
     648        _dataRange[1] = scalarRange[1];
     649    } else if (_dataSet != NULL) {
     650        _dataSet->getScalarRange(_dataRange);
     651    }
     652
     653    if (_lut != NULL) {
     654        _lut->SetRange(_dataRange);
     655    }
     656
     657    if (_contours.empty() && _numContours > 0) {
     658        // Need to recompute isovalues
     659        update();
    638660    }
    639661}
     
    644666 * Will override any existing contours
    645667 */
    646 void  HeightMap::setContours(int numContours)
     668void HeightMap::setContours(int numContours)
    647669{
    648670    _contours.clear();
    649671    _numContours = numContours;
    650 
    651     if (_dataSet != NULL) {
    652         double dataRange[2];
    653         _dataSet->getDataRange(dataRange);
    654         _dataRange[0] = dataRange[0];
    655         _dataRange[1] = dataRange[1];
    656     }
    657 
    658     update();
    659 }
    660 
    661 /**
    662  * \brief Specify number of evenly spaced contour lines to render
    663  * between the given range (including range endpoints)
    664  *
    665  * Will override any existing contours
    666  */
    667 void  HeightMap::setContours(int numContours, double range[2])
    668 {
    669     _contours.clear();
    670     _numContours = numContours;
    671 
    672     _dataRange[0] = range[0];
    673     _dataRange[1] = range[1];
    674672
    675673    update();
     
    681679 * Will override any existing contours
    682680 */
    683 void  HeightMap::setContourList(const std::vector<double>& contours)
     681void HeightMap::setContourList(const std::vector<double>& contours)
    684682{
    685683    _contours = contours;
     
    692690 * \brief Get the number of contours
    693691 */
    694 int  HeightMap::getNumContours() const
     692int HeightMap::getNumContours() const
    695693{
    696694    return _numContours;
     
    701699 * was specified in place of a list)
    702700 */
    703 const std::vector<double>&  HeightMap::getContourList() const
     701const std::vector<double>& HeightMap::getContourList() const
    704702{
    705703    return _contours;
  • trunk/packages/vizservers/vtkvis/RpHeightMap.h

    r2328 r2402  
    2525#include <vector>
    2626
     27#include "ColorMap.h"
    2728#include "RpVtkGraphicsObject.h"
    2829
     
    4142    };
    4243
    43     HeightMap();
     44    HeightMap(int numContours);
     45
     46    HeightMap(const std::vector<double>& contours);
     47
    4448    virtual ~HeightMap();
    4549
     
    4953    }
    5054
    51     virtual void setDataSet(DataSet *dataset);
     55    virtual void setDataSet(DataSet *dataset,
     56                            bool useCumulative,
     57                            double scalarRange[2],
     58                            double vectorMagnitudeRange[2],
     59                            double vectorComponentRange[3][2]);
    5260
    5361    virtual void setLighting(bool state);
     
    7583    const std::vector<double>& getContourList() const;
    7684
    77     void setLookupTable(vtkLookupTable *lut);
     85    void setColorMap(ColorMap *colorMap);
    7886
    79     vtkLookupTable *getLookupTable();
     87    /**
     88     * \brief Return the ColorMap in use
     89     */
     90    ColorMap *getColorMap()
     91    {
     92        return _colorMap;
     93    }
     94
     95    void updateColorMap();
     96
     97    virtual void updateRanges(bool useCumulative,
     98                              double scalarRange[2],
     99                              double vectorMagnitudeRange[2],
     100                              double vectorComponentRange[3][2]);
    80101
    81102    void setContourVisibility(bool state);
     
    86107
    87108private:
     109    HeightMap();
     110
    88111    virtual void initProp();
    89112    virtual void update();
     
    94117    int _numContours;
    95118    std::vector<double> _contours;
    96     double _dataRange[2];
     119    ColorMap *_colorMap;
    97120
    98     float _edgeColor[3];
    99121    float _contourEdgeColor[3];
    100     float _edgeWidth;
    101122    float _contourEdgeWidth;
    102123    double _warpScale;
  • trunk/packages/vizservers/vtkvis/RpLIC.cpp

    r2328 r2402  
    2727LIC::LIC() :
    2828    VtkGraphicsObject(),
    29     _sliceAxis(Z_AXIS)
     29    _sliceAxis(Z_AXIS),
     30    _colorMap(NULL)
    3031{
    3132}
     
    5657
    5758    vtkDataSet *ds = _dataSet->getVtkDataSet();
    58 
    59     double dataRange[2];
    60     _dataSet->getDataRange(dataRange);
    61 
    62     TRACE("DataSet type: %s, range: %g - %g", _dataSet->getVtkType(),
    63           dataRange[0], dataRange[1]);
    6459
    6560    vtkSmartPointer<vtkCellDataToPointData> cellToPtData;
     
    189184    }
    190185
     186    if (_lut == NULL) {
     187        setColorMap(ColorMap::getDefault());
     188    }
     189
    191190    initProp();
    192191    getActor()->SetMapper(_mapper);
     
    311310
    312311/**
    313  * \brief Get the VTK colormap lookup table in use
    314  */
    315 vtkLookupTable *LIC::getLookupTable()
    316 { 
    317     return _lut;
     312 * \brief Called when the color map has been edited
     313 */
     314void LIC::updateColorMap()
     315{
     316    setColorMap(_colorMap);
    318317}
    319318
     
    321320 * \brief Associate a colormap lookup table with the DataSet
    322321 */
    323 void LIC::setLookupTable(vtkLookupTable *lut)
    324 {
    325     if (lut == NULL) {
     322void LIC::setColorMap(ColorMap *cmap)
     323{
     324    if (cmap == NULL)
     325        return;
     326
     327    _colorMap = cmap;
     328 
     329    if (_lut == NULL) {
    326330        _lut = vtkSmartPointer<vtkLookupTable>::New();
    327     } else {
    328         _lut = lut;
    329     }
    330 
    331     if (_mapper != NULL) {
    332         _mapper->SetLookupTable(_lut);
     331        if (_mapper != NULL) {
     332            _mapper->UseLookupTableScalarRangeOn();
     333            _mapper->SetLookupTable(_lut);
     334        }
     335    }
     336
     337    _lut->DeepCopy(cmap->getLookupTable());
     338    _lut->SetRange(_dataRange);
     339}
     340
     341void LIC::updateRanges(bool useCumulative,
     342                       double scalarRange[2],
     343                       double vectorMagnitudeRange[2],
     344                       double vectorComponentRange[3][2])
     345{
     346    if (useCumulative) {
     347        _dataRange[0] = scalarRange[0];
     348        _dataRange[1] = scalarRange[1];
     349    } else if (_dataSet != NULL) {
     350        _dataSet->getScalarRange(_dataRange);
     351    }
     352
     353    if (_lut != NULL) {
     354        _lut->SetRange(_dataRange);
    333355    }
    334356}
  • trunk/packages/vizservers/vtkvis/RpLIC.h

    r2328 r2402  
    1919#include <vtkLookupTable.h>
    2020
     21#include "ColorMap.h"
    2122#include "RpVtkGraphicsObject.h"
    2223
     
    4950    void selectVolumeSlice(Axis axis, double ratio);
    5051
    51     void setLookupTable(vtkLookupTable *lut);
     52    void setColorMap(ColorMap *colorMap);
    5253
    53     vtkLookupTable *getLookupTable();
     54    /**
     55     * \brief Return the ColorMap in use
     56     */
     57    ColorMap *getColorMap()
     58    {
     59        return _colorMap;
     60    }
     61
     62    void updateColorMap();
     63
     64    virtual void updateRanges(bool useCumulative,
     65                              double scalarRange[2],
     66                              double vectorMagnitudeRange[2],
     67                              double vectorComponentRange[3][2]);
    5468
    5569private:
     
    5872
    5973    Axis _sliceAxis;
     74    ColorMap *_colorMap;
    6075
    6176    vtkSmartPointer<vtkLookupTable> _lut;
  • trunk/packages/vizservers/vtkvis/RpMolecule.cpp

    r2393 r2402  
    2727Molecule::Molecule() :
    2828    VtkGraphicsObject(),
    29     _atomScaling(NO_ATOM_SCALING)
     29    _atomScaling(NO_ATOM_SCALING),
     30    _colorMap(NULL)
    3031{
    3132    _faceCulling = true;
     
    8687    vtkDataSet *ds = _dataSet->getVtkDataSet();
    8788
    88     double dataRange[2];
    89     _dataSet->getDataRange(dataRange);
    90 
    91     if (ds->GetPointData() == NULL ||
    92         ds->GetPointData()->GetScalars() == NULL) {
    93         WARN("No scalar point data in dataset %s", _dataSet->getName().c_str());
    94         if (_lut == NULL) {
    95             _lut = vtkSmartPointer<vtkLookupTable>::New();
    96             _lut->DeepCopy(ColorMap::getDefault()->getLookupTable());
    97             _lut->SetRange(dataRange);
    98         }
    99     } else {
    100         vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable();
    101         TRACE("Data set scalars lookup table: %p\n", lut);
    102         if (_lut == NULL) {
    103             if (lut) {
    104                 _lut = lut;
    105                 if (strcmp(ds->GetPointData()->GetScalars()->GetName(), "element") == 0) {
    106                     double range[2];
    107                     range[0] = 0;
    108                     range[1] = NUM_ELEMENTS+1;
    109                     _lut->SetRange(range);
    110                 } else {
    111                     _lut->SetRange(dataRange);
    112                 }
    113             } else {
    114                 if (strcmp(ds->GetPointData()->GetScalars()->GetName(), "element") == 0) {
    115                     _lut = ColorMap::getElementDefault()->getLookupTable();
    116                 } else {
    117                     _lut = vtkSmartPointer<vtkLookupTable>::New();
    118                     _lut->DeepCopy(ColorMap::getDefault()->getLookupTable());
    119                     _lut->SetRange(dataRange);
    120                 }
    121             }
    122         }
    123     }
    124 
    12589    if (_atomMapper == NULL) {
    12690        _atomMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    12791        _atomMapper->SetResolveCoincidentTopologyToPolygonOffset();
    12892        _atomMapper->ScalarVisibilityOn();
    129         _atomMapper->SetColorModeToMapScalars();
    130         _atomMapper->UseLookupTableScalarRangeOn();
    131         _atomMapper->SetLookupTable(_lut);
    13293    }
    13394    if (_bondMapper == NULL) {
     
    13596        _bondMapper->SetResolveCoincidentTopologyToPolygonOffset();
    13697        _bondMapper->ScalarVisibilityOn();
    137         _bondMapper->SetColorModeToMapScalars();
    138         _bondMapper->UseLookupTableScalarRangeOn();
    139         _bondMapper->SetLookupTable(_lut);
     98    }
     99
     100    if (_lut == NULL) {
     101        if (ds->GetPointData() == NULL ||
     102            ds->GetPointData()->GetScalars() == NULL ||
     103            strcmp(ds->GetPointData()->GetScalars()->GetName(), "element") != 0) {
     104            WARN("No element array in dataset %s", _dataSet->getName().c_str());
     105            setColorMap(ColorMap::getDefault());
     106        } else {
     107            TRACE("Using element default colormap");
     108            setColorMap(ColorMap::getElementDefault());
     109        }
    140110    }
    141111
     
    197167}
    198168
    199 /**
    200  * \brief Get the VTK colormap lookup table in use
    201  */
    202 vtkLookupTable *Molecule::getLookupTable()
    203 {
    204     return _lut;
     169void Molecule::updateRanges(bool useCumulative,
     170                            double scalarRange[2],
     171                            double vectorMagnitudeRange[2],
     172                            double vectorComponentRange[3][2])
     173{
     174    if (useCumulative) {
     175        _dataRange[0] = scalarRange[0];
     176        _dataRange[1] = scalarRange[1];
     177    } else if (_dataSet != NULL) {
     178        _dataSet->getScalarRange(_dataRange);
     179    }
     180
     181    if (_lut != NULL) {
     182        vtkDataSet *ds = _dataSet->getVtkDataSet();
     183        if (ds == NULL)
     184            return;
     185        if (ds->GetPointData() == NULL ||
     186            ds->GetPointData()->GetScalars() == NULL ||
     187            strcmp(ds->GetPointData()->GetScalars()->GetName(), "element") != 0) {
     188            _lut->SetRange(_dataRange);
     189        }
     190    }
     191}
     192
     193/**
     194 * \brief Called when the color map has been edited
     195 */
     196void Molecule::updateColorMap()
     197{
     198    setColorMap(_colorMap);
    205199}
    206200
     
    208202 * \brief Associate a colormap lookup table with the DataSet
    209203 */
    210 void Molecule::setLookupTable(vtkLookupTable *lut)
    211 {
    212     if (lut == NULL) {
     204void Molecule::setColorMap(ColorMap *cmap)
     205{
     206    if (cmap == NULL)
     207        return;
     208
     209    _colorMap = cmap;
     210 
     211    if (_lut == NULL) {
    213212        _lut = vtkSmartPointer<vtkLookupTable>::New();
    214     } else {
    215         _lut = lut;
    216     }
    217 
    218     if (_atomMapper != NULL) {
    219         _atomMapper->UseLookupTableScalarRangeOn();
    220         _atomMapper->SetLookupTable(_lut);
    221     }
    222     if (_bondMapper != NULL) {
    223         _bondMapper->UseLookupTableScalarRangeOn();
    224         _bondMapper->SetLookupTable(_lut);
     213        if (_atomMapper != NULL) {
     214            _atomMapper->UseLookupTableScalarRangeOn();
     215            _atomMapper->SetLookupTable(_lut);
     216        }
     217        if (_bondMapper != NULL) {
     218            _bondMapper->UseLookupTableScalarRangeOn();
     219            _bondMapper->SetLookupTable(_lut);
     220        }
     221    }
     222
     223    _lut->DeepCopy(cmap->getLookupTable());
     224    _lut->Modified();
     225
     226    // Element color maps need to retain their range
     227    // Only set LUT range if we are not coloring by element
     228    vtkDataSet *ds = _dataSet->getVtkDataSet();
     229    if (ds == NULL)
     230        return;
     231    if (ds->GetPointData() == NULL ||
     232        ds->GetPointData()->GetScalars() == NULL ||
     233        strcmp(ds->GetPointData()->GetScalars()->GetName(), "element") != 0) {
     234        _lut->SetRange(_dataRange);
    225235    }
    226236}
     
    284294}
    285295
     296/**
     297 * \brief Add a scalar array to dataSet with sizes for the elements
     298 * specified in the "element" scalar array
     299 */
    286300void Molecule::addRadiusArray(vtkDataSet *dataSet, AtomScaling scaling)
    287301{
     
    323337}
    324338
     339/**
     340 * \brief Create a color map to map atomic numbers to element colors
     341 */
    325342ColorMap *Molecule::createElementColorMap()
    326343{
    327     ColorMap *elementLUT = new ColorMap("elementDefault");
     344    ColorMap *elementCmap = new ColorMap("elementDefault");
    328345    ColorMap::ControlPoint cp[NUM_ELEMENTS+1];
    329346
    330     elementLUT->setNumberOfTableEntries(NUM_ELEMENTS+1);
     347    elementCmap->setNumberOfTableEntries(NUM_ELEMENTS+1);
    331348    for (int i = 0; i <= NUM_ELEMENTS; i++) {
    332349        cp[i].value = i/((double)(NUM_ELEMENTS+1));
     
    334351            cp[i].color[c] = ((double)g_elementColors[i][c])/255.;
    335352        }
    336         elementLUT->addControlPoint(cp[i]);
     353        elementCmap->addControlPoint(cp[i]);
    337354    }
    338355    ColorMap::OpacityControlPoint ocp[2];
     
    341358    ocp[1].value = 1.0;
    342359    ocp[1].alpha = 1.0;
    343     elementLUT->addOpacityControlPoint(ocp[0]);
    344     elementLUT->addOpacityControlPoint(ocp[1]);
    345     elementLUT->build();
     360    elementCmap->addOpacityControlPoint(ocp[0]);
     361    elementCmap->addOpacityControlPoint(ocp[1]);
     362    elementCmap->build();
    346363    double range[2];
    347364    range[0] = 0;
    348365    range[1] = NUM_ELEMENTS+1;
    349     elementLUT->getLookupTable()->SetRange(range);
    350 
    351     return elementLUT;
    352 }
     366    elementCmap->getLookupTable()->SetRange(range);
     367
     368    return elementCmap;
     369}
  • trunk/packages/vizservers/vtkvis/RpMolecule.h

    r2328 r2402  
    5252    virtual void setClippingPlanes(vtkPlaneCollection *planes);
    5353
    54     void setLookupTable(vtkLookupTable *lut);
     54    void setColorMap(ColorMap *colorMap);
    5555
    56     vtkLookupTable *getLookupTable();
     56    /**
     57     * \brief Return the ColorMap in use
     58     */
     59    ColorMap *getColorMap()
     60    {
     61        return _colorMap;
     62    }
     63
     64    void updateColorMap();
     65
     66    virtual void updateRanges(bool useCumulative,
     67                              double scalarRange[2],
     68                              double vectorMagnitudeRange[2],
     69                              double vectorComponentRange[3][2]);
    5770
    5871    void setAtomScaling(AtomScaling state);
     
    7184
    7285    AtomScaling _atomScaling;
     86    ColorMap *_colorMap;
    7387
    7488    vtkSmartPointer<vtkLookupTable> _lut;
  • trunk/packages/vizservers/vtkvis/RpPolyData.cpp

    r2393 r2402  
    109109                // to get the grid boundary as a PolyData
    110110                vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     111                gf->UseStripsOn();
    111112                gf->SetInputConnection(mesher->GetOutputPort());
    112113                gf->ReleaseDataFlagOn();
     
    121122        TRACE("DataSet is not a PolyData");
    122123        vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     124        gf->UseStripsOn();
    123125        gf->SetInput(ds);
    124126        gf->ReleaseDataFlagOn();
  • trunk/packages/vizservers/vtkvis/RpPseudoColor.cpp

    r2328 r2402  
    2929
    3030PseudoColor::PseudoColor() :
    31     VtkGraphicsObject()
     31    VtkGraphicsObject(),
     32    _colorMap(NULL)
    3233{
    3334}
     
    7071
    7172    vtkDataSet *ds = _dataSet->getVtkDataSet();
    72 
    73     double dataRange[2];
    74     _dataSet->getDataRange(dataRange);
    7573
    7674    // Mapper, actor to render color-mapped data set
     
    136134    }
    137135
    138     if (ds->GetPointData() == NULL ||
    139         ds->GetPointData()->GetScalars() == NULL) {
    140         WARN("No scalar point data in dataset %s", _dataSet->getName().c_str());
    141         if (_lut == NULL) {
    142             _lut = vtkSmartPointer<vtkLookupTable>::New();
    143         }
    144     } else {
    145         vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable();
    146         TRACE("Data set scalars lookup table: %p\n", lut);
    147         if (_lut == NULL) {
    148             if (lut)
    149                 _lut = lut;
    150             else
    151                 _lut = vtkSmartPointer<vtkLookupTable>::New();
    152         }
    153     }
    154 
    155     _lut->SetRange(dataRange);
    156 
    157     _dsMapper->SetColorModeToMapScalars();
    158     _dsMapper->UseLookupTableScalarRangeOn();
    159     _dsMapper->SetLookupTable(_lut);
     136    if (_lut == NULL) {
     137        setColorMap(ColorMap::getDefault());
     138    }
    160139    //_dsMapper->InterpolateScalarsBeforeMappingOn();
    161140
     
    165144}
    166145
    167 /**
    168  * \brief Get the VTK colormap lookup table in use
    169  */
    170 vtkLookupTable *PseudoColor::getLookupTable()
    171 {
    172     return _lut;
     146void PseudoColor::updateRanges(bool useCumulative,
     147                               double scalarRange[2],
     148                               double vectorMagnitudeRange[2],
     149                               double vectorComponentRange[3][2])
     150{
     151    if (useCumulative) {
     152        _dataRange[0] = scalarRange[0];
     153        _dataRange[1] = scalarRange[1];
     154    } else if (_dataSet != NULL) {
     155        _dataSet->getScalarRange(_dataRange);
     156    }
     157
     158    if (_lut != NULL) {
     159        _lut->SetRange(_dataRange);
     160    }
     161}
     162
     163/**
     164 * \brief Called when the color map has been edited
     165 */
     166void PseudoColor::updateColorMap()
     167{
     168    setColorMap(_colorMap);
    173169}
    174170
     
    176172 * \brief Associate a colormap lookup table with the DataSet
    177173 */
    178 void PseudoColor::setLookupTable(vtkLookupTable *lut)
    179 {
    180     if (lut == NULL) {
     174void PseudoColor::setColorMap(ColorMap *cmap)
     175{
     176    if (cmap == NULL)
     177        return;
     178
     179    _colorMap = cmap;
     180 
     181    if (_lut == NULL) {
    181182        _lut = vtkSmartPointer<vtkLookupTable>::New();
    182     } else {
    183         _lut = lut;
    184     }
    185 
    186     if (_dsMapper != NULL) {
    187         _dsMapper->UseLookupTableScalarRangeOn();
    188         _dsMapper->SetLookupTable(_lut);
    189     }
     183        if (_dsMapper != NULL) {
     184            _dsMapper->UseLookupTableScalarRangeOn();
     185            _dsMapper->SetLookupTable(_lut);
     186        }
     187    }
     188
     189    _lut->DeepCopy(cmap->getLookupTable());
     190    _lut->SetRange(_dataRange);
    190191}
    191192
  • trunk/packages/vizservers/vtkvis/RpPseudoColor.h

    r2328 r2402  
    1515#include <vtkPlaneCollection.h>
    1616
     17#include "ColorMap.h"
    1718#include "RpVtkGraphicsObject.h"
    18 #include "RpVtkDataSet.h"
    1919
    2020namespace Rappture {
     
    3838    virtual void setClippingPlanes(vtkPlaneCollection *planes);
    3939
    40     void setLookupTable(vtkLookupTable *lut);
     40    void setColorMap(ColorMap *colorMap);
    4141
    42     vtkLookupTable *getLookupTable();
     42    /**
     43     * \brief Return the ColorMap in use
     44     */
     45    ColorMap *getColorMap()
     46    {
     47        return _colorMap;
     48    }
     49
     50    void updateColorMap();
     51
     52    virtual void updateRanges(bool useCumulative,
     53                              double scalarRange[2],
     54                              double vectorMagnitudeRange[2],
     55                              double vectorComponentRange[3][2]);
    4356
    4457private:
    4558    virtual void initProp();
    4659    virtual void update();
     60
     61    ColorMap *_colorMap;
    4762
    4863    vtkSmartPointer<vtkLookupTable> _lut;
  • trunk/packages/vizservers/vtkvis/RpStreamlines.cpp

    r2393 r2402  
    3636    _lineType(LINES),
    3737    _colorMode(COLOR_BY_VECTOR_MAGNITUDE),
     38    _colorMap(NULL),
    3839    _seedVisible(true)
    3940{
     
    5152Streamlines::~Streamlines()
    5253{
     54}
     55
     56void Streamlines::setDataSet(DataSet *dataSet,
     57                             bool useCumulative,
     58                             double scalarRange[2],
     59                             double vectorMagnitudeRange[2],
     60                             double vectorComponentRange[3][2])
     61{
     62    if (_dataSet != dataSet) {
     63        _dataSet = dataSet;
     64
     65        if (useCumulative) {
     66            _dataRange[0] = scalarRange[0];
     67            _dataRange[1] = scalarRange[1];
     68            _vectorMagnitudeRange[0] = vectorMagnitudeRange[0];
     69            _vectorMagnitudeRange[1] = vectorMagnitudeRange[1];
     70            for (int i = 0; i < 3; i++) {
     71                _vectorComponentRange[i][0] = vectorComponentRange[i][0];
     72                _vectorComponentRange[i][1] = vectorComponentRange[i][1];
     73            }
     74        } else {
     75            _dataSet->getScalarRange(_dataRange);
     76            _dataSet->getVectorRange(_vectorMagnitudeRange);
     77            for (int i = 0; i < 3; i++) {
     78                _dataSet->getVectorRange(_vectorComponentRange[i], i);
     79            }
     80        }
     81
     82        update();
     83    }
    5384}
    5485
     
    201232
    202233    vtkDataSet *ds = _dataSet->getVtkDataSet();
    203     double dataRange[2];
    204     _dataSet->getVectorMagnitudeRange(dataRange);
     234
    205235    double bounds[6];
    206236    _dataSet->getBounds(bounds);
     
    294324    _seedActor->SetMapper(_seedMapper);
    295325
    296     _lut = vtkSmartPointer<vtkLookupTable>::New();
    297     _lut->SetRange(dataRange);
    298     _lut->SetVectorModeToMagnitude();
    299 
    300     _pdMapper->SetScalarModeToUsePointFieldData();
    301     if (ds->GetPointData() != NULL &&
    302         ds->GetPointData()->GetVectors() != NULL) {
    303         TRACE("Vector name: '%s'", ds->GetPointData()->GetVectors()->GetName());
    304         _pdMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
    305     }
    306     _pdMapper->SetColorModeToMapScalars();
    307     _pdMapper->UseLookupTableScalarRangeOn();
    308     _pdMapper->SetLookupTable(_lut);
     326    if (_lut == NULL) {
     327        setColorMap(ColorMap::getDefault());
     328    }
     329
     330    setColorMode(_colorMode);
    309331
    310332    _linesActor->SetMapper(_pdMapper);
     
    759781}
    760782
     783void Streamlines::updateRanges(bool useCumulative,
     784                               double scalarRange[2],
     785                               double vectorMagnitudeRange[2],
     786                               double vectorComponentRange[3][2])
     787{
     788    if (useCumulative) {
     789        _dataRange[0] = scalarRange[0];
     790        _dataRange[1] = scalarRange[1];
     791        _vectorMagnitudeRange[0] = vectorMagnitudeRange[0];
     792        _vectorMagnitudeRange[1] = vectorMagnitudeRange[1];
     793        for (int i = 0; i < 3; i++) {
     794            _vectorComponentRange[i][0] = vectorComponentRange[i][0];
     795            _vectorComponentRange[i][1] = vectorComponentRange[i][1];
     796        }
     797    } else {
     798        _dataSet->getScalarRange(_dataRange);
     799        _dataSet->getVectorRange(_vectorMagnitudeRange);
     800        for (int i = 0; i < 3; i++) {
     801            _dataSet->getVectorRange(_vectorComponentRange[i], i);
     802        }
     803    }
     804
     805    // Need to update color map ranges and/or active vector field
     806    setColorMode(_colorMode);
     807}
     808
    761809void Streamlines::setColorMode(ColorMode mode)
    762810{
     
    772820        _pdMapper->SetScalarModeToDefault();
    773821        if (_lut != NULL) {
    774             double dataRange[2];
    775             _dataSet->getDataRange(dataRange);
    776             _lut->SetRange(dataRange);
     822            _lut->SetRange(_dataRange);
    777823        }
    778824    }
     
    786832        }
    787833        if (_lut != NULL) {
    788             double dataRange[2];
    789             _dataSet->getVectorMagnitudeRange(dataRange);
    790             TRACE("vmag range: %g %g", dataRange[0], dataRange[1]);
    791             _lut->SetRange(dataRange);
     834            _lut->SetRange(_vectorMagnitudeRange);
    792835            _lut->SetVectorModeToMagnitude();
    793836        }
     
    802845        }
    803846        if (_lut != NULL) {
    804             double dataRange[2];
    805             _dataSet->getVectorComponentRange(dataRange, 0);
    806             _lut->SetRange(dataRange);
     847            _lut->SetRange(_vectorComponentRange[0]);
    807848            _lut->SetVectorModeToComponent();
    808849            _lut->SetVectorComponent(0);
     
    817858        }
    818859        if (_lut != NULL) {
    819             double dataRange[2];
    820             _dataSet->getVectorComponentRange(dataRange, 1);
    821             _lut->SetRange(dataRange);
     860            _lut->SetRange(_vectorComponentRange[1]);
    822861            _lut->SetVectorModeToComponent();
    823862            _lut->SetVectorComponent(1);
     
    832871        }
    833872        if (_lut != NULL) {
    834             double dataRange[2];
    835             _dataSet->getVectorComponentRange(dataRange, 2);
    836             TRACE("vz range: %g %g", dataRange[0], dataRange[1]);
    837             _lut->SetRange(dataRange);
     873            _lut->SetRange(_vectorComponentRange[2]);
    838874            _lut->SetVectorModeToComponent();
    839875            _lut->SetVectorComponent(2);
     
    848884
    849885/**
    850  * \brief Get the VTK colormap lookup table in use
    851  */
    852 vtkLookupTable *Streamlines::getLookupTable()
    853 { 
    854     return _lut;
     886 * \brief Called when the color map has been edited
     887 */
     888void Streamlines::updateColorMap()
     889{
     890    setColorMap(_colorMap);
    855891}
    856892
     
    858894 * \brief Associate a colormap lookup table with the DataSet
    859895 */
    860 void Streamlines::setLookupTable(vtkLookupTable *lut)
    861 {
    862     if (lut == NULL) {
     896void Streamlines::setColorMap(ColorMap *cmap)
     897{
     898    if (cmap == NULL)
     899        return;
     900
     901    _colorMap = cmap;
     902 
     903    if (_lut == NULL) {
    863904        _lut = vtkSmartPointer<vtkLookupTable>::New();
    864     } else {
    865         _lut = lut;
    866     }
     905        if (_pdMapper != NULL) {
     906            _pdMapper->UseLookupTableScalarRangeOn();
     907            _pdMapper->SetLookupTable(_lut);
     908        }
     909    }
     910
     911    _lut->DeepCopy(cmap->getLookupTable());
    867912
    868913    switch (_colorMode) {
    869     case COLOR_BY_VECTOR_MAGNITUDE: {
    870         double dataRange[2];
    871         _dataSet->getVectorMagnitudeRange(dataRange);
     914    case COLOR_CONSTANT:
     915    case COLOR_BY_SCALAR:
     916        _lut->SetRange(_dataRange);
     917        break;
     918    case COLOR_BY_VECTOR_MAGNITUDE:
    872919        _lut->SetVectorModeToMagnitude();
    873         _lut->SetRange(dataRange);
    874     }
    875         break;
    876     case COLOR_BY_VECTOR_X: {
    877         double dataRange[2];
    878         _dataSet->getVectorComponentRange(dataRange, 0);
     920        _lut->SetRange(_vectorMagnitudeRange);
     921        break;
     922    case COLOR_BY_VECTOR_X:
    879923        _lut->SetVectorModeToComponent();
    880924        _lut->SetVectorComponent(0);
    881         _lut->SetRange(dataRange);
    882     }
    883         break;
    884     case COLOR_BY_VECTOR_Y: {
    885         double dataRange[2];
    886         _dataSet->getVectorComponentRange(dataRange, 1);
     925        _lut->SetRange(_vectorComponentRange[0]);
     926        break;
     927    case COLOR_BY_VECTOR_Y:
    887928        _lut->SetVectorModeToComponent();
    888929        _lut->SetVectorComponent(1);
    889         _lut->SetRange(dataRange);
    890     }
    891         break;
    892     case COLOR_BY_VECTOR_Z: {
    893         double dataRange[2];
    894         _dataSet->getVectorComponentRange(dataRange, 2);
     930        _lut->SetRange(_vectorComponentRange[1]);
     931        break;
     932    case COLOR_BY_VECTOR_Z:
    895933        _lut->SetVectorModeToComponent();
    896934        _lut->SetVectorComponent(2);
    897         _lut->SetRange(dataRange);
    898     }
     935        _lut->SetRange(_vectorComponentRange[2]);
    899936        break;
    900937    default:
    901938         break;
    902     }
    903 
    904     if (_pdMapper != NULL) {
    905         _pdMapper->SetLookupTable(_lut);
    906939    }
    907940}
  • trunk/packages/vizservers/vtkvis/RpStreamlines.h

    r2393 r2402  
    1818#include <vtkAssembly.h>
    1919
     20#include "ColorMap.h"
    2021#include "RpVtkGraphicsObject.h"
    2122
     
    5152        return "Streamlines";
    5253    }
     54
     55    virtual void setDataSet(DataSet *dataSet,
     56                            bool useCumulative,
     57                            double scalarRange[2],
     58                            double vectorMagnitudeRange[2],
     59                            double vectorComponentRange[3][2]);
    5360
    5461    virtual void setLighting(bool state);
     
    95102    void setColorMode(ColorMode mode);
    96103
    97     void setLookupTable(vtkLookupTable *lut);
     104    void setColorMap(ColorMap *colorMap);
    98105
    99     vtkLookupTable *getLookupTable();
     106    /**
     107     * \brief Return the ColorMap in use
     108     */
     109    ColorMap *getColorMap()
     110    {
     111        return _colorMap;
     112    }
     113
     114    void updateColorMap();
     115
     116    virtual void updateRanges(bool useCumulative,
     117                              double scalarRange[2],
     118                              double vectorMagnitudeRange[2],
     119                              double vectorComponentRange[3][2]);
    100120
    101121    void setSeedVisibility(bool state);
     
    120140    LineType _lineType;
    121141    ColorMode _colorMode;
    122     float _color[3];
     142    ColorMap *_colorMap;
    123143    float _seedColor[3];
    124144    bool _seedVisible;
     145    double _vectorMagnitudeRange[2];
     146    double _vectorComponentRange[3][2];
    125147
    126148    vtkSmartPointer<vtkLookupTable> _lut;
  • trunk/packages/vizservers/vtkvis/RpVolume.cpp

    r2328 r2402  
    6363    vtkDataSet *ds = _dataSet->getVtkDataSet();
    6464
    65     double dataRange[2];
    66     _dataSet->getDataRange(dataRange);
    67 
    68     TRACE("DataSet type: %s, range: %g - %g", _dataSet->getVtkType(),
    69           dataRange[0], dataRange[1]);
    70 
    7165    if (vtkImageData::SafeDownCast(ds) != NULL) {
    7266        // Image data required for these mappers
     
    113107        WARN("No scalar point data in dataset %s", _dataSet->getName().c_str());
    114108    }
     109
    115110    if (_colorMap == NULL) {
    116         _colorMap = ColorMap::getVolumeDefault();
     111        setColorMap(ColorMap::getVolumeDefault());
    117112    }
    118 
    119     vtkVolumeProperty *volProperty = getVolume()->GetProperty();
    120     volProperty->SetColor(_colorMap->getColorTransferFunction(dataRange));
    121     volProperty->SetScalarOpacity(_colorMap->getOpacityTransferFunction(dataRange));
    122113
    123114    getVolume()->SetMapper(_volumeMapper);
    124115    _volumeMapper->Update();
     116}
     117
     118void Volume::updateRanges(bool useCumulative,
     119                          double scalarRange[2],
     120                          double vectorMagnitudeRange[2],
     121                          double vectorComponentRange[3][2])
     122{
     123    if (useCumulative) {
     124        _dataRange[0] = scalarRange[0];
     125        _dataRange[1] = scalarRange[1];
     126    } else if (_dataSet != NULL) {
     127        _dataSet->getScalarRange(_dataRange);
     128    }
     129
     130    if (getVolume() != NULL) {
     131        getVolume()->GetProperty()->SetColor(_colorMap->getColorTransferFunction(_dataRange));
     132        getVolume()->GetProperty()->SetScalarOpacity(_colorMap->getOpacityTransferFunction(_dataRange));
     133    }
     134}
     135void Volume::updateColorMap()
     136{
     137    setColorMap(_colorMap);
    125138}
    126139
     
    131144{
    132145    _colorMap = cmap;
     146
    133147    if (getVolume() != NULL) {
    134         double dataRange[2];
    135         _dataSet->getDataRange(dataRange);
    136         getVolume()->GetProperty()->SetColor(_colorMap->getColorTransferFunction(dataRange));
    137         getVolume()->GetProperty()->SetScalarOpacity(_colorMap->getOpacityTransferFunction(dataRange));
    138     }
    139 }
    140 
    141 /**
    142  * \brief Assign a color map (transfer function) to use in rendering the Volume and
    143  * specify a scalar range for the map
    144  */
    145 void Volume::setColorMap(ColorMap *cmap, double dataRange[2])
    146 {
    147     _colorMap = cmap;
    148     if (getVolume() != NULL) {
    149         getVolume()->GetProperty()->SetColor(_colorMap->getColorTransferFunction(dataRange));
    150         getVolume()->GetProperty()->SetScalarOpacity(_colorMap->getOpacityTransferFunction(dataRange));
     148        getVolume()->GetProperty()->SetColor(_colorMap->getColorTransferFunction(_dataRange));
     149        getVolume()->GetProperty()->SetScalarOpacity(_colorMap->getOpacityTransferFunction(_dataRange));
    151150    }
    152151}
  • trunk/packages/vizservers/vtkvis/RpVolume.h

    r2328 r2402  
    4949    void setColorMap(ColorMap *cmap);
    5050
    51     void setColorMap(ColorMap *cmap, double dataRange[2]);
     51    ColorMap *getColorMap();
    5252
    53     ColorMap *getColorMap();
     53    void updateColorMap();
     54
     55    virtual void updateRanges(bool useCumulative,
     56                              double scalarRange[2],
     57                              double vectorMagnitudeRange[2],
     58                              double vectorComponentRange[3][2]);
    5459
    5560private:
  • trunk/packages/vizservers/vtkvis/RpVtkDataSet.cpp

    r2393 r2402  
    77
    88#include <cstring>
     9#include <cfloat>
     10#include <cmath>
    911
    1012#include <vtkCharArray.h>
     
    1820#include <vtkPointData.h>
    1921#include <vtkCellData.h>
     22#include <vtkCell.h>
    2023#include <vtkLookupTable.h>
    2124
     
    6972
    7073    reader->SetFileName(filename);
     74    reader->ReadAllNormalsOn();
     75    //reader->ReadAllTCoordsOn();
    7176    reader->ReadAllScalarsOn();
     77    //reader->ReadAllColorScalarsOn();
    7278    reader->ReadAllVectorsOn();
     79    //reader->ReadAllTensorsOn();
    7380    reader->ReadAllFieldsOn();
    7481    return setData(reader);
     
    93100    reader->SetInputArray(dataSetString);
    94101    reader->ReadFromInputStringOn();
     102    reader->ReadAllNormalsOn();
     103    //reader->ReadAllTCoordsOn();
    95104    reader->ReadAllScalarsOn();
     105    //reader->ReadAllColorScalarsOn();
    96106    reader->ReadAllVectorsOn();
     107    //reader->ReadAllTensorsOn();
    97108    reader->ReadAllFieldsOn();
    98109
     
    103114}
    104115
    105 /**
    106  * \brief Read dataset using supplied reader
    107  *
    108  * Pipeline information is removed from the resulting
    109  * vtkDataSet, so that the reader and its data can be
    110  * released
    111  */
    112 bool DataSet::setData(vtkDataSetReader *reader)
    113 {
    114     // Force reading data set
    115     reader->SetLookupTableName("");
    116     reader->Update();
    117 
    118     _dataSet = reader->GetOutput();
    119     _dataSet->SetPipelineInformation(NULL);
    120 
     116void DataSet::print() const
     117{
    121118    TRACE("DataSet class: %s", _dataSet->GetClassName());
    122 #ifdef WANT_TRACE
    123     double dataRange[2];
    124     getDataRange(dataRange);
     119
    125120    double bounds[6];
    126121    getBounds(bounds);
    127 #endif
    128     TRACE("Scalar Range: %.12e, %.12e", dataRange[0], dataRange[1]);
     122
     123    // Topology
    129124    TRACE("DataSet bounds: %g %g %g %g %g %g",
    130125          bounds[0], bounds[1],
     
    132127          bounds[4], bounds[5]);
    133128    TRACE("Points: %d Cells: %d", _dataSet->GetNumberOfPoints(), _dataSet->GetNumberOfCells());
     129
     130    double dataRange[2];
     131    if (_dataSet->GetPointData() != NULL) {
     132        TRACE("PointData arrays: %d", _dataSet->GetPointData()->GetNumberOfArrays());
     133        for (int i = 0; i < _dataSet->GetPointData()->GetNumberOfArrays(); i++) {
     134            _dataSet->GetPointData()->GetArray(i)->GetRange(dataRange, -1);
     135            TRACE("PointData[%d]: '%s' comp:%d, (%g,%g)", i,
     136                  _dataSet->GetPointData()->GetArrayName(i),
     137                  _dataSet->GetPointData()->GetArray(i)->GetNumberOfComponents(),
     138                  dataRange[0], dataRange[1]);
     139        }
     140    }
     141    if (_dataSet->GetCellData() != NULL) {
     142        TRACE("CellData arrays: %d", _dataSet->GetCellData()->GetNumberOfArrays());
     143        for (int i = 0; i < _dataSet->GetCellData()->GetNumberOfArrays(); i++) {
     144            _dataSet->GetCellData()->GetArray(i)->GetRange(dataRange, -1);
     145            TRACE("CellData[%d]: '%s' comp:%d, (%g,%g)", i,
     146                  _dataSet->GetCellData()->GetArrayName(i),
     147                  _dataSet->GetCellData()->GetArray(i)->GetNumberOfComponents(),
     148                  dataRange[0], dataRange[1]);
     149        }
     150    }
     151    if (_dataSet->GetFieldData() != NULL) {
     152        TRACE("FieldData arrays: %d", _dataSet->GetFieldData()->GetNumberOfArrays());
     153        for (int i = 0; i < _dataSet->GetFieldData()->GetNumberOfArrays(); i++) {
     154            _dataSet->GetFieldData()->GetArray(i)->GetRange(dataRange, -1);
     155            TRACE("FieldData[%d]: '%s' comp:%d, tuples:%d (%g,%g)", i,
     156                  _dataSet->GetFieldData()->GetArrayName(i),
     157                  _dataSet->GetFieldData()->GetArray(i)->GetNumberOfComponents(),
     158                  _dataSet->GetFieldData()->GetArray(i)->GetNumberOfTuples(),
     159                  dataRange[0], dataRange[1]);
     160        }
     161    }
     162}
     163
     164/**
     165 * \brief Read dataset using supplied reader
     166 *
     167 * Pipeline information is removed from the resulting
     168 * vtkDataSet, so that the reader and its data can be
     169 * released
     170 */
     171bool DataSet::setData(vtkDataSetReader *reader)
     172{
     173    // Force reading data set
     174    reader->SetLookupTableName("");
     175    reader->Update();
     176
     177    _dataSet = reader->GetOutput();
     178    _dataSet->SetPipelineInformation(NULL);
     179
     180    if (_dataSet->GetPointData() != NULL &&
     181        _dataSet->GetPointData()->GetScalars() != NULL &&
     182        _dataSet->GetPointData()->GetScalars()->GetLookupTable() != NULL) {
     183        ERROR("No lookup table should be specified in DataSets");
     184    }
     185
     186#ifdef WANT_TRACE
     187    print();
     188#endif
    134189    return true;
    135190}
     
    145200    _dataSet->SetPipelineInformation(NULL);
    146201
    147     TRACE("DataSet class: %s", _dataSet->GetClassName());
     202    if (_dataSet->GetPointData() != NULL &&
     203        _dataSet->GetPointData()->GetScalars() != NULL &&
     204        _dataSet->GetPointData()->GetScalars()->GetLookupTable() != NULL) {
     205        ERROR("No lookup table should be specified in DataSets");
     206    }
     207
    148208#ifdef WANT_TRACE
    149     double dataRange[2];
    150     getDataRange(dataRange);
    151     double bounds[6];
    152     getBounds(bounds);
     209    print();
    153210#endif
    154     TRACE("Scalar Range: %.12e, %.12e", dataRange[0], dataRange[1]);
    155     TRACE("DataSet bounds: %g %g %g %g %g %g",
    156           bounds[0], bounds[1],
    157           bounds[2], bounds[3],
    158           bounds[4], bounds[5]);
    159     TRACE("Points: %d Cells: %d", _dataSet->GetNumberOfPoints(), _dataSet->GetNumberOfCells());
    160211    return true;
    161212}
     
    190241    }
    191242
    192     TRACE("DataSet class: %s", _dataSet->GetClassName());
    193243#ifdef WANT_TRACE
    194     double dataRange[2];
    195     getDataRange(dataRange);
    196     double bounds[6];
    197     getBounds(bounds);
     244    print();
    198245#endif   
    199     TRACE("Scalar Range: %.12e, %.12e", dataRange[0], dataRange[1]);
    200     TRACE("DataSet bounds: %g %g %g %g %g %g",
    201           bounds[0], bounds[1],
    202           bounds[2], bounds[3],
    203           bounds[4], bounds[5]);
    204246    return _dataSet;
    205247}
     
    280322 * \brief Get the range of scalar values in the DataSet
    281323 */
     324void DataSet::getScalarRange(double minmax[2]) const
     325{
     326    _dataSet->GetScalarRange(minmax);
     327}
     328
     329#if 0
     330/**
     331 * \brief Get the range of scalar values in the DataSet
     332 */
    282333void DataSet::getDataRange(double minmax[2]) const
    283334{
    284335    _dataSet->GetScalarRange(minmax);
    285336}
    286 
    287 /**
    288  * \brief Get the range of scalar values (or vector magnitudes) for
    289  * the named field in the DataSet
    290  */
    291 void DataSet::getDataRange(double minmax[2], const char *fieldName) const
    292 {
    293     if (_dataSet == NULL)
    294         return;
    295     if (_dataSet->GetPointData() != NULL &&
    296         _dataSet->GetPointData()->GetArray(fieldName) != NULL) {
    297         _dataSet->GetPointData()->GetArray(fieldName)->GetRange(minmax, -1);
    298     } else if (_dataSet->GetCellData() != NULL &&
    299         _dataSet->GetCellData()->GetArray(fieldName) != NULL) {
    300         _dataSet->GetCellData()->GetArray(fieldName)->GetRange(minmax, -1);
    301     } else if (_dataSet->GetFieldData() != NULL &&
    302         _dataSet->GetFieldData()->GetArray(fieldName) != NULL) {
    303         _dataSet->GetFieldData()->GetArray(fieldName)->GetRange(minmax, -1);
    304     }
    305 }
    306 
    307 /**
    308  * \brief Get the range of vector magnitudes in the DataSet
    309  */
    310 void DataSet::getVectorMagnitudeRange(double minmax[2]) const
    311 {
    312     if (_dataSet == NULL)
    313         return;
    314     if (_dataSet->GetPointData() != NULL &&
    315         _dataSet->GetPointData()->GetVectors() != NULL) {
    316         _dataSet->GetPointData()->GetVectors()->GetRange(minmax, -1);
    317     } else if (_dataSet->GetCellData() != NULL &&
    318                _dataSet->GetCellData()->GetVectors() != NULL) {
    319         _dataSet->GetCellData()->GetVectors()->GetRange(minmax, -1);
    320     }
    321 }
     337#endif
    322338
    323339/**
    324340 * \brief Get the range of a vector component in the DataSet
    325  */
    326 void DataSet::getVectorComponentRange(double minmax[2], int component) const
     341 *
     342 * \param[out] minmax The data range
     343 * \param[in] component The field component, -1 means magnitude
     344 */
     345void DataSet::getVectorRange(double minmax[2], int component) const
    327346{
    328347    if (_dataSet == NULL)
     
    338357
    339358/**
     359 * \brief Get the range of values for the named field in the DataSet
     360 *
     361 * \param[out] minmax The data range
     362 * \param[in] fieldName The array name
     363 * \param[in] component The field component, -1 means magnitude
     364 */
     365void DataSet::getDataRange(double minmax[2], const char *fieldName, int component) const
     366{
     367    if (_dataSet == NULL)
     368        return;
     369    if (_dataSet->GetPointData() != NULL &&
     370        _dataSet->GetPointData()->GetArray(fieldName) != NULL) {
     371        _dataSet->GetPointData()->GetArray(fieldName)->GetRange(minmax, component);
     372    } else if (_dataSet->GetCellData() != NULL &&
     373        _dataSet->GetCellData()->GetArray(fieldName) != NULL) {
     374        _dataSet->GetCellData()->GetArray(fieldName)->GetRange(minmax, component);
     375    } else if (_dataSet->GetFieldData() != NULL &&
     376        _dataSet->GetFieldData()->GetArray(fieldName) != NULL) {
     377        _dataSet->GetFieldData()->GetArray(fieldName)->GetRange(minmax, component);
     378    }
     379}
     380
     381/**
    340382 * \brief Get the bounds the DataSet
    341383 */
     
    343385{
    344386    _dataSet->GetBounds(bounds);
     387}
     388
     389/**
     390 * \brief Get the range of cell AABB diagonal lengths the DataSet
     391 */
     392void DataSet::getCellSizeRange(double minmax[6], double *average) const
     393{
     394    if (_dataSet == NULL ||
     395        _dataSet->GetNumberOfCells() < 1) {
     396        minmax[0] = 1;
     397        minmax[1] = 1;
     398        *average = 1;
     399        return;
     400    }
     401
     402    minmax[0] = DBL_MAX;
     403    minmax[1] = -DBL_MAX;
     404
     405    *average = 0;
     406    for (int i = 0; i < _dataSet->GetNumberOfCells(); i++) {
     407        double length2 = _dataSet->GetCell(i)->GetLength2();
     408        if (length2 < minmax[0])
     409            minmax[0] = length2;
     410        if (length2 > minmax[1])
     411            minmax[1] = length2;
     412        *average += length2;
     413    }
     414    if (minmax[0] == DBL_MAX)
     415        minmax[0] = 1;
     416    if (minmax[1] == -DBL_MAX)
     417        minmax[1] = 1;
     418
     419    minmax[0] = sqrt(minmax[0]);
     420    minmax[1] = sqrt(minmax[1]);
     421    *average = sqrt(*average/((double)_dataSet->GetNumberOfCells()));
    345422}
    346423
  • trunk/packages/vizservers/vtkvis/RpVtkDataSet.h

    r2393 r2402  
    4949    bool setActiveVectors(const char *name);
    5050
    51     void getDataRange(double minmax[2]) const;
     51    void getScalarRange(double minmax[2]) const;
    5252
    53     void getDataRange(double minmax[2], const char *fieldName) const;
     53    //void getDataRange(double minmax[2]) const;
    5454
    55     void getVectorMagnitudeRange(double minmax[2]) const;
     55    void getDataRange(double minmax[2], const char *fieldName, int component = -1) const;
    5656
    57     void getVectorComponentRange(double minmax[2], int component) const;
     57    void getVectorRange(double minmax[2], int component = -1) const;
    5858
    5959    void getBounds(double bounds[6]) const;
     60
     61    void getCellSizeRange(double minmax[6], double *average) const;
    6062
    6163    double getDataValue(double x, double y, double z) const;
     
    6769private:
    6870    DataSet();
     71    void print() const;
    6972
    7073    std::string _name;
  • trunk/packages/vizservers/vtkvis/RpVtkGraphicsObject.h

    r2393 r2402  
    5050        _faceCulling(false)
    5151    {
     52        _dataRange[0] = 0;
     53        _dataRange[1] = 1;
    5254        _color[0] = 1.0f;
    5355        _color[1] = 1.0f;
     
    7072     *
    7173     * Default implementation calls update()
     74     *
     75     * \param[in] dataSet DataSet to use in rendering
    7276     */
    7377    virtual void setDataSet(DataSet *dataSet)
     
    7579        if (_dataSet != dataSet) {
    7680            _dataSet = dataSet;
     81
    7782            update();
    7883        }
     84    }
     85
     86    /**
     87     * \brief Specify input DataSet and information on cumulative data ranges
     88     *
     89     * Default implementation calls update() and stores scalarRange to
     90     * _dataRange based on cumulative range settings
     91     *
     92     * \param[in] dataSet DataSet to use in rendering
     93     * \param[in] useCumulative Whether the cumulative data ranges should be
     94     * used in place of the dataSet's ranges
     95     * \param[in] scalarRange Current cumulative scalar data range
     96     * \param[in] vectorMagnitudeRange Current cumulative vector magnitude data range
     97     * \param[in] vectorComponentRange Current cumulative vector component data ranges
     98     */
     99    virtual void setDataSet(DataSet *dataSet,
     100                            bool useCumulative,
     101                            double scalarRange[2],
     102                            double vectorMagnitudeRange[2],
     103                            double vectorComponentRange[3][2])
     104    {
     105        if (_dataSet != dataSet) {
     106            _dataSet = dataSet;
     107
     108            if (useCumulative) {
     109                _dataRange[0] = scalarRange[0];
     110                _dataRange[1] = scalarRange[1];
     111            } else {
     112                dataSet->getScalarRange(_dataRange);
     113            }
     114
     115            update();
     116        }
     117    }
     118
     119    /**
     120     * \brief Called when scalar or vector field changes (e.g. active field) or
     121     * cumulative ranges or settings change
     122     *
     123     * \param[in] useCumulative Whether the cumulative data ranges should be
     124     * used in place of the dataSet's ranges
     125     * \param[in] scalarRange Current cumulative scalar data range
     126     * \param[in] vectorMagnitudeRange Current cumulative vector magnitude data range
     127     * \param[in] vectorComponentRange Current cumulative vector component data ranges
     128     */
     129    virtual void updateRanges(bool useCumulative,
     130                              double scalarRange[2],
     131                              double vectorMagnitudeRange[2],
     132                              double vectorComponentRange[3][2])
     133    {
    79134    }
    80135
     
    171226            double angle = vtkMath::DegreesFromRadians(2.0 * acos(quat[0]));
    172227            double axis[3];
    173             double denom = sqrt(1. - quat[0] * quat[0]);
    174             axis[0] = quat[1] / denom;
    175             axis[1] = quat[2] / denom;
    176             axis[2] = quat[3] / denom;
     228            if (angle < 1.0e-6) {
     229                axis[0] = 1;
     230                axis[1] = 0;
     231                axis[2] = 0;
     232            } else {
     233                double denom = sqrt(1. - quat[0] * quat[0]);
     234                axis[0] = quat[1] / denom;
     235                axis[1] = quat[2] / denom;
     236                axis[2] = quat[3] / denom;
     237             }
    177238            setOrientation(angle, axis);
    178239        }
     
    589650        }
    590651    }
     652
     653    /**
     654     * \brief Toggle culling of selected CullFace
     655     */
     656    virtual void setCulling(bool state)
     657    {
     658        _faceCulling = state;
     659        if (state && _opacity < 1.0)
     660            return;
     661        if (getActor() != NULL) {
     662            setCulling(getActor()->GetProperty(), state);
     663         } else if (getAssembly() != NULL) {
     664            vtkProp3DCollection *props = getAssembly()->GetParts();
     665            vtkProp3D *prop;
     666            props->InitTraversal();
     667            while ((prop = props->GetNextProp3D()) != NULL) {
     668                if (vtkActor::SafeDownCast(prop) != NULL) {
     669                    setCulling(vtkActor::SafeDownCast(prop)->GetProperty(), state);
     670                }
     671            }
     672        }
     673    }
     674
     675    /**
     676     * \brief Specify which face(s) to cull when culling is enabled
     677     */
     678    virtual void setCullFace(CullFace cull)
     679    {
     680        _cullFace = cull;
     681        setCulling(_faceCulling);
     682    }
     683
     684    /**
     685     * \brief Subclasses need to implement setting clipping planes in their mappers
     686     */
     687    virtual void setClippingPlanes(vtkPlaneCollection *planes) = 0;
     688
     689protected:
     690    /**
     691     * \brief Create and initialize a VTK Prop to render the object
     692     */
     693    virtual void initProp()
     694    {
     695        if (_prop == NULL) {
     696            _prop = vtkSmartPointer<vtkActor>::New();
     697            vtkProperty *property = getActor()->GetProperty();
     698            property->EdgeVisibilityOff();
     699            property->SetOpacity(_opacity);
     700            property->SetAmbient(.2);
     701            if (!_lighting)
     702                property->LightingOff();
     703            if (_faceCulling && _opacity == 1.0) {
     704                setCulling(property, true);
     705            }
     706        }
     707    }
     708
     709    /**
     710     * \brief Subclasses implement this to create the VTK pipeline
     711     * on a state change (e.g. new DataSet)
     712     */
     713    virtual void update() = 0;
    591714
    592715    /**
     
    613736    }
    614737
    615     /**
    616      * \brief Toggle culling of selected CullFace
    617      */
    618     virtual void setCulling(bool state)
    619     {
    620         _faceCulling = state;
    621         if (state && _opacity < 1.0)
    622             return;
    623         if (getActor() != NULL) {
    624             setCulling(getActor()->GetProperty(), state);
    625          } else if (getAssembly() != NULL) {
    626             vtkProp3DCollection *props = getAssembly()->GetParts();
    627             vtkProp3D *prop;
    628             props->InitTraversal();
    629             while ((prop = props->GetNextProp3D()) != NULL) {
    630                 if (vtkActor::SafeDownCast(prop) != NULL) {
    631                     setCulling(vtkActor::SafeDownCast(prop)->GetProperty(), state);
    632                 }
    633             }
    634         }
    635     }
    636 
    637     virtual void setCullFace(CullFace cull)
    638     {
    639         _cullFace = cull;
    640         setCulling(_faceCulling);
    641     }
    642 
    643     /**
    644      * \brief Subclasses need to implement setting clipping planes in their mappers
    645      */
    646     virtual void setClippingPlanes(vtkPlaneCollection *planes) = 0;
    647 
    648 protected:
    649     /**
    650      * \brief Create and initialize a VTK Prop to render the object
    651      */
    652     virtual void initProp()
    653     {
    654         if (_prop == NULL) {
    655             _prop = vtkSmartPointer<vtkActor>::New();
    656             vtkProperty *property = getActor()->GetProperty();
    657             property->EdgeVisibilityOff();
    658             property->SetOpacity(_opacity);
    659             property->SetAmbient(.2);
    660             if (!_lighting)
    661                 property->LightingOff();
    662             if (_faceCulling && _opacity == 1.0) {
    663                 setCulling(property, true);
    664             }
    665         }
    666     }
    667 
    668     /**
    669      * \brief Subclasses implement this to create the VTK pipeline
    670      * on a state change (e.g. new DataSet)
    671      */
    672     virtual void update() = 0;
    673 
    674738    DataSet *_dataSet;
     739    double _dataRange[2];
    675740    double _opacity;
    676741    float _color[3];
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp

    r2393 r2402  
    6969    _cameraOrientation[2] = 0.0;
    7070    _cameraOrientation[3] = 0.0;
    71     _cumulativeDataRange[0] = 0.0;
    72     _cumulativeDataRange[1] = 1.0;
     71    _cumulativeScalarRange[0] = 0.0;
     72    _cumulativeScalarRange[1] = 1.0;
     73    _cumulativeVectorMagnitudeRange[0] = 0.0;
     74    _cumulativeVectorMagnitudeRange[1] = 1.0;
     75    for (int i = 0; i < 3; i++) {
     76        _cumulativeVectorComponentRange[i][0] = 0.0;
     77        _cumulativeVectorComponentRange[i][1] = 1.0;
     78    }
    7379    // clipping planes to prevent overdrawing axes
    7480    _activeClipPlanes = vtkSmartPointer<vtkPlaneCollection>::New();
     
    263269    } while (doAll && itr != _contour2Ds.end());
    264270
     271    initCamera();
    265272    _needsRedraw = true;
    266273}
     
    299306    } while (doAll && itr != _contour3Ds.end());
    300307
     308    initCamera();
    301309    _needsRedraw = true;
    302310}
     
    335343    } while (doAll && itr != _glyphs.end());
    336344
     345    initCamera();
    337346    _needsRedraw = true;
    338347}
     
    371380    } while (doAll && itr != _heightMaps.end());
    372381
     382    initCamera();
    373383    _needsRedraw = true;
    374384}
     
    407417    } while (doAll && itr != _lics.end());
    408418
     419    initCamera();
    409420    _needsRedraw = true;
    410421}
     
    443454    } while (doAll && itr != _molecules.end());
    444455
     456    initCamera();
    445457    _needsRedraw = true;
    446458}
     
    479491    } while (doAll && itr != _polyDatas.end());
    480492
     493    initCamera();
    481494    _needsRedraw = true;
    482495}
     
    515528    } while (doAll && itr != _pseudoColors.end());
    516529
     530    initCamera();
    517531    _needsRedraw = true;
    518532}
     
    551565    } while (doAll && itr != _streamlines.end());
    552566
     567    initCamera();
    553568    _needsRedraw = true;
    554569}
     
    587602    } while (doAll && itr != _volumes.end());
    588603
     604    initCamera();
    589605    _needsRedraw = true;
    590606}
     
    634650
    635651    // Update cumulative data range
    636     collectDataRanges(_cumulativeDataRange, _cumulativeRangeOnlyVisible);
    637     updateRanges(_useCumulativeRange);
    638 
     652    updateRanges();
     653
     654    initCamera();
    639655    _needsRedraw = true;
    640656}
     
    649665    DataSetHashmap::iterator itr = _dataSets.find(id);
    650666    if (itr == _dataSets.end()) {
     667#ifdef DEBUG
    651668        TRACE("DataSet not found: %s", id.c_str());
     669#endif
    652670        return NULL;
    653671    } else
     
    663681    if (ds) {
    664682        bool ret = ds->setDataFile(filename);
    665         collectDataRanges(_cumulativeDataRange, _cumulativeRangeOnlyVisible);
    666         updateRanges(_useCumulativeRange);
     683        updateRanges();
    667684        _needsRedraw = true;
    668685        return ret;
     
    679696    if (ds) {
    680697        bool ret = ds->setData(data, nbytes);
    681         collectDataRanges(_cumulativeDataRange, _cumulativeRangeOnlyVisible);
    682         updateRanges(_useCumulativeRange);
     698        updateRanges();
    683699        _needsRedraw = true;
    684700        return ret;
     
    712728
    713729    if (ret) {
    714         collectDataRanges(_cumulativeDataRange, _cumulativeRangeOnlyVisible);
    715         updateRanges(_useCumulativeRange);
     730         updateRanges();
    716731        _needsRedraw = true;
    717732    }
     
    745760
    746761    if (ret) {
    747         collectDataRanges(_cumulativeDataRange, _cumulativeRangeOnlyVisible);
    748         updateRanges(_useCumulativeRange);
     762        updateRanges();
    749763        _needsRedraw = true;
    750764    }
     
    762776        _useCumulativeRange = state;
    763777        _cumulativeRangeOnlyVisible = onlyVisible;
    764         collectDataRanges(_cumulativeDataRange, _cumulativeRangeOnlyVisible);
    765         updateRanges(_useCumulativeRange);
     778        updateRanges();
    766779        _needsRedraw = true;
    767780    }
    768781}
    769782
    770 void Renderer::resetAxes()
     783void Renderer::resetAxes(double bounds[6])
    771784{
    772785    TRACE("Resetting axes");
     
    793806            _renderer->AddViewProp(_cubeAxesActor);
    794807        }
    795         double bounds[6];
    796         collectBounds(bounds, false);
    797         _cubeAxesActor->SetBounds(bounds);
     808        if (bounds == NULL) {
     809            double newBounds[6];
     810            collectBounds(newBounds, false);
     811            _cubeAxesActor->SetBounds(newBounds);
     812        } else {
     813            _cubeAxesActor->SetBounds(bounds);
     814        }
    798815    }
    799816}
     
    11371154
    11381155/**
    1139  * \brief Add a color map for use in the Renderer
     1156 * \brief Notify graphics objects that color map has changed
     1157 */
     1158void Renderer::updateColorMap(ColorMap *cmap)
     1159{
     1160    for (Contour3DHashmap::iterator itr = _contour3Ds.begin();
     1161         itr != _contour3Ds.end(); ++itr) {
     1162        if (itr->second->getColorMap() == cmap) {
     1163            itr->second->updateColorMap();
     1164            _needsRedraw = true;
     1165        }
     1166    }
     1167    for (GlyphsHashmap::iterator itr = _glyphs.begin();
     1168         itr != _glyphs.end(); ++itr) {
     1169        if (itr->second->getColorMap() == cmap) {
     1170            itr->second->updateColorMap();
     1171            _needsRedraw = true;
     1172        }
     1173    }
     1174    for (HeightMapHashmap::iterator itr = _heightMaps.begin();
     1175         itr != _heightMaps.end(); ++itr) {
     1176        if (itr->second->getColorMap() == cmap) {
     1177            itr->second->updateColorMap();
     1178            _needsRedraw = true;
     1179        }
     1180    }
     1181    for (LICHashmap::iterator itr = _lics.begin();
     1182         itr != _lics.end(); ++itr) {
     1183        if (itr->second->getColorMap() == cmap) {
     1184            itr->second->updateColorMap();
     1185            _needsRedraw = true;
     1186        }
     1187    }
     1188    for (MoleculeHashmap::iterator itr = _molecules.begin();
     1189         itr != _molecules.end(); ++itr) {
     1190        if (itr->second->getColorMap() == cmap) {
     1191            itr->second->updateColorMap();
     1192            _needsRedraw = true;
     1193        }
     1194    }
     1195    for (PseudoColorHashmap::iterator itr = _pseudoColors.begin();
     1196         itr != _pseudoColors.end(); ++itr) {
     1197        if (itr->second->getColorMap() == cmap) {
     1198            itr->second->updateColorMap();
     1199            _needsRedraw = true;
     1200        }
     1201    }
     1202    for (StreamlinesHashmap::iterator itr = _streamlines.begin();
     1203         itr != _streamlines.end(); ++itr) {
     1204        if (itr->second->getColorMap() == cmap) {
     1205            itr->second->updateColorMap();
     1206            _needsRedraw = true;
     1207        }
     1208    }
     1209    for (VolumeHashmap::iterator itr = _volumes.begin();
     1210         itr != _volumes.end(); ++itr) {
     1211        if (itr->second->getColorMap() == cmap) {
     1212            itr->second->updateColorMap();
     1213            _needsRedraw = true;
     1214        }
     1215    }
     1216}
     1217
     1218/**
     1219 * \brief Check if a ColorMap is in use by graphics objects
     1220 */
     1221bool Renderer::colorMapUsed(ColorMap *cmap)
     1222{
     1223    for (Contour3DHashmap::iterator itr = _contour3Ds.begin();
     1224         itr != _contour3Ds.end(); ++itr) {
     1225        if (itr->second->getColorMap() == cmap)
     1226            return true;
     1227    }
     1228    for (GlyphsHashmap::iterator itr = _glyphs.begin();
     1229         itr != _glyphs.end(); ++itr) {
     1230        if (itr->second->getColorMap() == cmap)
     1231            return true;
     1232    }
     1233    for (HeightMapHashmap::iterator itr = _heightMaps.begin();
     1234         itr != _heightMaps.end(); ++itr) {
     1235        if (itr->second->getColorMap() == cmap)
     1236            return true;
     1237    }
     1238    for (LICHashmap::iterator itr = _lics.begin();
     1239         itr != _lics.end(); ++itr) {
     1240        if (itr->second->getColorMap() == cmap)
     1241            return true;
     1242    }
     1243    for (MoleculeHashmap::iterator itr = _molecules.begin();
     1244         itr != _molecules.end(); ++itr) {
     1245        if (itr->second->getColorMap() == cmap)
     1246            return true;
     1247    }
     1248    for (PseudoColorHashmap::iterator itr = _pseudoColors.begin();
     1249         itr != _pseudoColors.end(); ++itr) {
     1250        if (itr->second->getColorMap() == cmap)
     1251            return true;
     1252    }
     1253    for (StreamlinesHashmap::iterator itr = _streamlines.begin();
     1254         itr != _streamlines.end(); ++itr) {
     1255        if (itr->second->getColorMap() == cmap)
     1256            return true;
     1257    }
     1258    for (VolumeHashmap::iterator itr = _volumes.begin();
     1259         itr != _volumes.end(); ++itr) {
     1260        if (itr->second->getColorMap() == cmap)
     1261            return true;
     1262    }
     1263    return false;
     1264}
     1265
     1266/**
     1267 * \brief Add/replace a ColorMap for use in the Renderer
    11401268 */
    11411269void Renderer::addColorMap(const ColorMapId& id, ColorMap *colorMap)
     
    11441272        colorMap->build();
    11451273        if (getColorMap(id) != NULL) {
    1146             WARN("Replacing existing ColorMap %s", id.c_str());
    1147             deleteColorMap(id);
    1148         }
    1149         _colorMaps[id] = colorMap;
     1274            TRACE("Replacing existing ColorMap %s", id.c_str());
     1275            // Copy to current colormap to avoid invalidating
     1276            // pointers in graphics objects using the color map
     1277            *_colorMaps[id] = *colorMap;
     1278            delete colorMap;
     1279            // Notify graphics objects of change
     1280            updateColorMap(_colorMaps[id]);
     1281        } else
     1282            _colorMaps[id] = colorMap;
    11501283    } else {
    11511284        ERROR("NULL ColorMap");
     
    11911324
    11921325    do {
     1326        if (itr->second->getName().compare("default") == 0 ||
     1327            itr->second->getName().compare("volumeDefault") == 0 ||
     1328            itr->second->getName().compare("elementDefault") == 0) {
     1329            if (id.compare("all") != 0) {
     1330                WARN("Cannot delete a default color map");
     1331            }
     1332            continue;
     1333        } else if (colorMapUsed(itr->second)) {
     1334            WARN("Cannot delete color map '%s', it is in use", itr->second->getName().c_str());
     1335            continue;
     1336        }
     1337
    11931338        TRACE("Deleting ColorMap %s", itr->second->getName().c_str());
    11941339
    1195         // TODO: Check if color map is used in PseudoColors?
    11961340        delete itr->second;
    11971341        itr = _colorMaps.erase(itr);
     
    12201364        _legendRenderWindow->DoubleBufferOff();
    12211365        _legendRenderWindow->OffScreenRenderingOn();
     1366#else
     1367        _legendRenderWindow->DoubleBufferOn();
     1368        _legendRenderWindow->SwapBuffersOff();
    12221369#endif
    12231370    }
     
    12391386    vtkSmartPointer<vtkLookupTable> lut = colorMap->getLookupTable();
    12401387    if (dataSetID.compare("all") == 0) {
    1241         lut->SetRange(_cumulativeDataRange);
     1388        lut->SetRange(_cumulativeScalarRange);
    12421389    } else {
    12431390        DataSet *dataSet = getDataSet(dataSetID);
    12441391        if (dataSet == NULL) {
    1245             lut->SetRange(_cumulativeDataRange);
     1392            lut->SetRange(_cumulativeScalarRange);
    12461393        } else {
    12471394            double range[2];
    1248             dataSet->getDataRange(range);
     1395            dataSet->getScalarRange(range);
    12491396            lut->SetRange(range);
    12501397        }
     
    13101457 * \brief Create a new Contour2D and associate it with the named DataSet
    13111458 */
    1312 void Renderer::addContour2D(const DataSetId& id)
     1459void Renderer::addContour2D(const DataSetId& id, int numContours)
    13131460{
    13141461    DataSetHashmap::iterator itr;
     
    13351482        }
    13361483
    1337         Contour2D *contour = new Contour2D();
     1484        Contour2D *contour = new Contour2D(numContours);
    13381485        _contour2Ds[dsID] = contour;
    13391486
    1340         contour->setDataSet(ds);
     1487        contour->setDataSet(ds,
     1488                            _useCumulativeRange,
     1489                            _cumulativeScalarRange,
     1490                            _cumulativeVectorMagnitudeRange,
     1491                            _cumulativeVectorComponentRange);
    13411492
    13421493        _renderer->AddViewProp(contour->getProp());
     
    13481499
    13491500/**
     1501 * \brief Create a new Contour2D and associate it with the named DataSet
     1502 */
     1503void Renderer::addContour2D(const DataSetId& id, const std::vector<double>& contours)
     1504{
     1505    DataSetHashmap::iterator itr;
     1506
     1507    bool doAll = false;
     1508
     1509    if (id.compare("all") == 0) {
     1510        itr = _dataSets.begin();
     1511    } else {
     1512        itr = _dataSets.find(id);
     1513    }
     1514    if (itr == _dataSets.end()) {
     1515        ERROR("Unknown dataset %s", id.c_str());
     1516        return;
     1517    }
     1518
     1519    do {
     1520        DataSet *ds = itr->second;
     1521        const DataSetId& dsID = ds->getName();
     1522
     1523        if (getContour2D(dsID)) {
     1524            WARN("Replacing existing Contour2D %s", dsID.c_str());
     1525            deleteContour2D(dsID);
     1526        }
     1527
     1528        Contour2D *contour = new Contour2D(contours);
     1529        _contour2Ds[dsID] = contour;
     1530
     1531        contour->setDataSet(ds,
     1532                            _useCumulativeRange,
     1533                            _cumulativeScalarRange,
     1534                            _cumulativeVectorMagnitudeRange,
     1535                            _cumulativeVectorComponentRange);
     1536
     1537        _renderer->AddViewProp(contour->getProp());
     1538    } while (doAll && ++itr != _dataSets.end());
     1539
     1540    initCamera();
     1541    _needsRedraw = true;
     1542}
     1543
     1544/**
    13501545 * \brief Get the Contour2D associated with a named DataSet
    13511546 */
     
    13551550
    13561551    if (itr == _contour2Ds.end()) {
     1552#ifdef DEBUG
    13571553        TRACE("Contour2D not found: %s", id.c_str());
     1554#endif
    13581555        return NULL;
    13591556    } else
     
    15221719
    15231720    do {
    1524         if (_useCumulativeRange) {
    1525             itr->second->setContours(numContours, _cumulativeDataRange);
    1526         } else {
    1527             itr->second->setContours(numContours);
    1528         }
     1721        itr->second->setContours(numContours);
    15291722    } while (doAll && ++itr != _contour2Ds.end());
    15301723
     
    16991892 * \brief Create a new Contour3D and associate it with the named DataSet
    17001893 */
    1701 void Renderer::addContour3D(const DataSetId& id)
     1894void Renderer::addContour3D(const DataSetId& id, int numContours)
    17021895{
    17031896    DataSetHashmap::iterator itr;
     
    17241917        }
    17251918
    1726         Contour3D *contour = new Contour3D();
     1919        Contour3D *contour = new Contour3D(numContours);
    17271920        _contour3Ds[dsID] = contour;
    17281921
    1729         contour->setDataSet(ds);
    1730 
    1731         // Use the default color map
    1732         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    1733         ColorMap *cmap = getColorMap("default");
    1734         lut->DeepCopy(cmap->getLookupTable());
    1735         if (_useCumulativeRange) {
    1736             lut->SetRange(_cumulativeDataRange);
    1737         } else {
    1738             double range[2];
    1739             ds->getDataRange(range);
    1740             lut->SetRange(range);
    1741         }
    1742 
    1743         contour->setLookupTable(lut);
     1922        contour->setDataSet(ds,
     1923                            _useCumulativeRange,
     1924                            _cumulativeScalarRange,
     1925                            _cumulativeVectorMagnitudeRange,
     1926                            _cumulativeVectorComponentRange);
    17441927
    17451928        _renderer->AddViewProp(contour->getProp());
     
    17531936
    17541937/**
     1938 * \brief Create a new Contour3D and associate it with the named DataSet
     1939 */
     1940void Renderer::addContour3D(const DataSetId& id,const std::vector<double>& contours)
     1941{
     1942    DataSetHashmap::iterator itr;
     1943
     1944    bool doAll = false;
     1945
     1946    if (id.compare("all") == 0) {
     1947        itr = _dataSets.begin();
     1948    } else {
     1949        itr = _dataSets.find(id);
     1950    }
     1951    if (itr == _dataSets.end()) {
     1952        ERROR("Unknown dataset %s", id.c_str());
     1953        return;
     1954    }
     1955
     1956    do {
     1957        DataSet *ds = itr->second;
     1958        const DataSetId& dsID = ds->getName();
     1959
     1960        if (getContour3D(dsID)) {
     1961            WARN("Replacing existing Contour3D %s", dsID.c_str());
     1962            deleteContour3D(dsID);
     1963        }
     1964
     1965        Contour3D *contour = new Contour3D(contours);
     1966        _contour3Ds[dsID] = contour;
     1967
     1968        contour->setDataSet(ds,
     1969                            _useCumulativeRange,
     1970                            _cumulativeScalarRange,
     1971                            _cumulativeVectorMagnitudeRange,
     1972                            _cumulativeVectorComponentRange);
     1973
     1974        _renderer->AddViewProp(contour->getProp());
     1975    } while (doAll && ++itr != _dataSets.end());
     1976
     1977    if (_cameraMode == IMAGE)
     1978        setCameraMode(PERSPECTIVE);
     1979    initCamera();
     1980    _needsRedraw = true;
     1981}
     1982
     1983/**
    17551984 * \brief Get the Contour3D associated with a named DataSet
    17561985 */
     
    17601989
    17611990    if (itr == _contour3Ds.end()) {
     1991#ifdef DEBUG
    17621992        TRACE("Contour3D not found: %s", id.c_str());
     1993#endif
    17631994        return NULL;
    17641995    } else
     
    19272158
    19282159    do {
    1929         if (_useCumulativeRange) {
    1930             itr->second->setContours(numContours, _cumulativeDataRange);
    1931         } else {
    1932             itr->second->setContours(numContours);
    1933         }
    1934     } while (doAll && ++itr != _contour3Ds.end());
     2160        itr->second->setContours(numContours);
     2161     } while (doAll && ++itr != _contour3Ds.end());
    19352162
    19362163    initCamera();
     
    20522279              itr->second->getDataSet()->getName().c_str());
    20532280
    2054         // Make a copy of the generic colormap lookup table, so
    2055         // data range can be set in the copy table to match the
    2056         // dataset being plotted
    2057         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    2058         lut->DeepCopy(cmap->getLookupTable());
    2059 
    2060         if (_useCumulativeRange) {
    2061             lut->SetRange(_cumulativeDataRange);
    2062         } else {
    2063             if (itr->second->getDataSet() != NULL) {
    2064                 double range[2];
    2065                 itr->second->getDataSet()->getDataRange(range);
    2066                 lut->SetRange(range);
    2067             }
    2068         }
    2069 
    2070         itr->second->setLookupTable(lut);
     2281        itr->second->setColorMap(cmap);
    20712282    } while (doAll && ++itr != _contour3Ds.end());
    20722283
     
    22402451 * \brief Create a new Glyphs and associate it with the named DataSet
    22412452 */
    2242 void Renderer::addGlyphs(const DataSetId& id)
     2453void Renderer::addGlyphs(const DataSetId& id, Glyphs::GlyphShape shape)
    22432454{
    22442455    DataSetHashmap::iterator itr;
     
    22652476        }
    22662477
    2267         Glyphs *glyphs = new Glyphs();
     2478        Glyphs *glyphs = new Glyphs(shape);
    22682479        _glyphs[dsID] = glyphs;
    22692480
    2270         glyphs->setDataSet(ds);
    2271 
    2272         // Use the default color map
    2273         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    2274         ColorMap *cmap = getColorMap("default");
    2275         lut->DeepCopy(cmap->getLookupTable());
    2276         if (_useCumulativeRange) {
    2277             lut->SetRange(_cumulativeDataRange);
    2278         } else {
    2279             double range[2];
    2280             ds->getDataRange(range);
    2281             lut->SetRange(range);
    2282         }
    2283 
    2284         glyphs->setLookupTable(lut);
     2481        glyphs->setDataSet(ds,
     2482                           _useCumulativeRange,
     2483                           _cumulativeScalarRange,
     2484                           _cumulativeVectorMagnitudeRange,
     2485                           _cumulativeVectorComponentRange);
    22852486
    22862487        _renderer->AddViewProp(glyphs->getProp());
     
    23022503
    23032504    if (itr == _glyphs.end()) {
     2505#ifdef DEBUG
    23042506        TRACE("Glyphs not found: %s", id.c_str());
     2507#endif
    23052508        return NULL;
    23062509    } else
     
    25062709              itr->second->getDataSet()->getName().c_str());
    25072710
    2508         // Make a copy of the generic colormap lookup table, so
    2509         // data range can be set in the copy table to match the
    2510         // dataset being plotted
    2511         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    2512         lut->DeepCopy(cmap->getLookupTable());
    2513 
    2514         if (_useCumulativeRange) {
    2515             lut->SetRange(_cumulativeDataRange);
    2516         } else {
    2517             if (itr->second->getDataSet() != NULL) {
    2518                 double range[2];
    2519                 itr->second->getDataSet()->getDataRange(range);
    2520                 lut->SetRange(range);
    2521             }
    2522         }
    2523 
    2524         itr->second->setLookupTable(lut);
     2711        itr->second->setColorMap(cmap);
    25252712    } while (doAll && ++itr != _glyphs.end());
    25262713
     
    28333020 * \brief Create a new HeightMap and associate it with the named DataSet
    28343021 */
    2835 void Renderer::addHeightMap(const DataSetId& id)
     3022void Renderer::addHeightMap(const DataSetId& id, int numContours)
    28363023{
    28373024    DataSetHashmap::iterator itr;
     
    28583045        }
    28593046
    2860         HeightMap *hmap = new HeightMap();
     3047        HeightMap *hmap = new HeightMap(numContours);
    28613048        _heightMaps[dsID] = hmap;
    28623049
    2863         hmap->setDataSet(ds);
    2864 
    2865         // Use the default color map
    2866         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    2867         ColorMap *cmap = getColorMap("default");
    2868         lut->DeepCopy(cmap->getLookupTable());
    2869         if (_useCumulativeRange) {
    2870             lut->SetRange(_cumulativeDataRange);
    2871         } else {
    2872             double range[2];
    2873             ds->getDataRange(range);
    2874             lut->SetRange(range);
    2875         }
    2876 
    2877         hmap->setLookupTable(lut);
     3050        hmap->setDataSet(ds,
     3051                         _useCumulativeRange,
     3052                         _cumulativeScalarRange,
     3053                         _cumulativeVectorMagnitudeRange,
     3054                         _cumulativeVectorComponentRange);
    28783055
    28793056        _renderer->AddViewProp(hmap->getProp());
     
    28883065
    28893066/**
     3067 * \brief Create a new HeightMap and associate it with the named DataSet
     3068 */
     3069void Renderer::addHeightMap(const DataSetId& id, const std::vector<double>& contours)
     3070{
     3071    DataSetHashmap::iterator itr;
     3072
     3073    bool doAll = false;
     3074
     3075    if (id.compare("all") == 0) {
     3076        itr = _dataSets.begin();
     3077    } else {
     3078        itr = _dataSets.find(id);
     3079    }
     3080    if (itr == _dataSets.end()) {
     3081        ERROR("Unknown dataset %s", id.c_str());
     3082        return;
     3083    }
     3084
     3085    do {
     3086        DataSet *ds = itr->second;
     3087        const DataSetId& dsID = ds->getName();
     3088
     3089        if (getHeightMap(dsID)) {
     3090            WARN("Replacing existing HeightMap %s", dsID.c_str());
     3091            deleteHeightMap(dsID);
     3092        }
     3093
     3094        HeightMap *hmap = new HeightMap(contours);
     3095        _heightMaps[dsID] = hmap;
     3096
     3097        hmap->setDataSet(ds,
     3098                         _useCumulativeRange,
     3099                         _cumulativeScalarRange,
     3100                         _cumulativeVectorMagnitudeRange,
     3101                         _cumulativeVectorComponentRange);
     3102
     3103        _renderer->AddViewProp(hmap->getProp());
     3104    } while (doAll && ++itr != _dataSets.end());
     3105
     3106    if (_cameraMode == IMAGE)
     3107        setCameraMode(PERSPECTIVE);
     3108    initCamera();
     3109
     3110    _needsRedraw = true;
     3111}
     3112
     3113/**
    28903114 * \brief Get the HeightMap associated with a named DataSet
    28913115 */
     
    28953119
    28963120    if (itr == _heightMaps.end()) {
     3121#ifdef DEBUG
    28973122        TRACE("HeightMap not found: %s", id.c_str());
     3123#endif
    28983124        return NULL;
    28993125    } else
     
    31313357              itr->second->getDataSet()->getName().c_str());
    31323358
    3133         // Make a copy of the generic colormap lookup table, so
    3134         // data range can be set in the copy table to match the
    3135         // dataset being plotted
    3136         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    3137         lut->DeepCopy(cmap->getLookupTable());
    3138 
    3139         if (_useCumulativeRange) {
    3140             lut->SetRange(_cumulativeDataRange);
    3141         } else {
    3142             if (itr->second->getDataSet() != NULL) {
    3143                 double range[2];
    3144                 itr->second->getDataSet()->getDataRange(range);
    3145                 lut->SetRange(range);
    3146             }
    3147         }
    3148 
    3149         itr->second->setLookupTable(lut);
     3359        itr->second->setColorMap(cmap);
    31503360    } while (doAll && ++itr != _heightMaps.end());
    31513361
     
    31743384
    31753385    do {
    3176         if (_useCumulativeRange) {
    3177             itr->second->setContours(numContours, _cumulativeDataRange);
    3178         } else {
    3179             itr->second->setContours(numContours);
    3180         }
     3386        itr->second->setContours(numContours);
    31813387    } while (doAll && ++itr != _heightMaps.end());
    31823388
     
    34903696        _lics[dsID] = lic;
    34913697
    3492         lic->setDataSet(ds);
     3698        lic->setDataSet(ds,
     3699                        _useCumulativeRange,
     3700                        _cumulativeScalarRange,
     3701                        _cumulativeVectorMagnitudeRange,
     3702                        _cumulativeVectorComponentRange);
    34933703
    34943704        _renderer->AddViewProp(lic->getProp());
     
    35093719
    35103720    if (itr == _lics.end()) {
     3721#ifdef DEBUG
    35113722        TRACE("LIC not found: %s", id.c_str());
     3723#endif
    35123724        return NULL;
    35133725    } else
     
    37153927              itr->second->getDataSet()->getName().c_str());
    37163928
    3717         // Make a copy of the generic colormap lookup table, so
    3718         // data range can be set in the copy table to match the
    3719         // dataset being plotted
    3720         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    3721         lut->DeepCopy(cmap->getLookupTable());
    3722 
    3723         if (_useCumulativeRange) {
    3724             lut->SetRange(_cumulativeDataRange);
    3725         } else {
    3726             if (itr->second->getDataSet() != NULL) {
    3727                 double range[2];
    3728                 itr->second->getDataSet()->getDataRange(range);
    3729                 lut->SetRange(range);
    3730             }
    3731         }
    3732 
    3733         itr->second->setLookupTable(lut);
     3929        itr->second->setColorMap(cmap);
    37343930    } while (doAll && ++itr != _lics.end());
    37353931
     
    39524148
    39534149    if (itr == _molecules.end()) {
     4150#ifdef DEBUG
    39544151        TRACE("Molecule not found: %s", id.c_str());
     4152#endif
    39554153        return NULL;
    39564154    } else
     
    41294327              itr->second->getDataSet()->getName().c_str());
    41304328
    4131         // Make a copy of the generic colormap lookup table, so
    4132         // data range can be set in the copy table to match the
    4133         // dataset being plotted
    4134         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    4135         lut->DeepCopy(cmap->getLookupTable());
    4136 
    4137         if (_useCumulativeRange) {
    4138             lut->SetRange(_cumulativeDataRange);
    4139         } else {
    4140             if (itr->second->getDataSet() != NULL) {
    4141                 double range[2];
    4142                 itr->second->getDataSet()->getDataRange(range);
    4143                 lut->SetRange(range);
    4144             }
    4145         }
    4146 
    4147         itr->second->setLookupTable(lut);
     4329        itr->second->setColorMap(cmap);
    41484330    } while (doAll && ++itr != _molecules.end());
    41494331
     
    44744656
    44754657    if (itr == _polyDatas.end()) {
     4658#ifdef DEBUG
    44764659        TRACE("PolyData not found: %s", id.c_str());
     4660#endif
    44774661        return NULL;
    44784662    } else
     
    48685052        _pseudoColors[dsID] = pc;
    48695053
    4870         pc->setDataSet(ds);
    4871 
    4872         // Use the default color map
    4873         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    4874         ColorMap *cmap = getColorMap("default");
    4875         lut->DeepCopy(cmap->getLookupTable());
    4876         if (_useCumulativeRange) {
    4877             lut->SetRange(_cumulativeDataRange);
    4878         } else {
    4879             double range[2];
    4880             ds->getDataRange(range);
    4881             lut->SetRange(range);
    4882         }
    4883 
    4884         pc->setLookupTable(lut);
     5054        pc->setDataSet(ds,
     5055                       _useCumulativeRange,
     5056                       _cumulativeScalarRange,
     5057                       _cumulativeVectorMagnitudeRange,
     5058                       _cumulativeVectorComponentRange);
    48855059
    48865060        _renderer->AddViewProp(pc->getProp());
     
    48995073
    49005074    if (itr == _pseudoColors.end()) {
     5075#ifdef DEBUG
    49015076        TRACE("PseudoColor not found: %s", id.c_str());
     5077#endif
    49025078        return NULL;
    49035079    } else
     
    50765252              itr->second->getDataSet()->getName().c_str());
    50775253
    5078         // Make a copy of the generic colormap lookup table, so
    5079         // data range can be set in the copy table to match the
    5080         // dataset being plotted
    5081         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    5082         lut->DeepCopy(cmap->getLookupTable());
    5083 
    5084         if (_useCumulativeRange) {
    5085             lut->SetRange(_cumulativeDataRange);
    5086         } else {
    5087             if (itr->second->getDataSet() != NULL) {
    5088                 double range[2];
    5089                 itr->second->getDataSet()->getDataRange(range);
    5090                 lut->SetRange(range);
    5091             }
    5092         }
    5093 
    5094         itr->second->setLookupTable(lut);
     5254        itr->second->setColorMap(cmap);
    50955255    } while (doAll && ++itr != _pseudoColors.end());
    50965256
     
    53275487        _streamlines[dsID] = streamlines;
    53285488
    5329         streamlines->setDataSet(ds);
    5330 
    5331         // Use the default color map
    5332         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    5333         ColorMap *cmap = getColorMap("default");
    5334         lut->DeepCopy(cmap->getLookupTable());
    5335 
    5336         if (_useCumulativeRange) {
    5337             lut->SetRange(_cumulativeDataRange);
    5338         } else {
    5339             double range[2];
    5340             ds->getDataRange(range);
    5341             lut->SetRange(range);
    5342         }
    5343         streamlines->setLookupTable(lut);
     5489        streamlines->setDataSet(ds,
     5490                                _useCumulativeRange,
     5491                                _cumulativeScalarRange,
     5492                                _cumulativeVectorMagnitudeRange,
     5493                                _cumulativeVectorComponentRange);
    53445494
    53455495        _renderer->AddViewProp(streamlines->getProp());
     
    53585508
    53595509    if (itr == _streamlines.end()) {
     5510#ifdef DEBUG
    53605511        TRACE("Streamlines not found: %s", id.c_str());
     5512#endif
    53615513        return NULL;
    53625514    } else
     
    59016053              itr->second->getDataSet()->getName().c_str());
    59026054
    5903         // Make a copy of the generic colormap lookup table, so
    5904         // data range can be set in the copy table to match the
    5905         // dataset being plotted
    5906         vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    5907         lut->DeepCopy(cmap->getLookupTable());
    5908 
    5909         if (_useCumulativeRange) {
    5910             lut->SetRange(_cumulativeDataRange);
    5911         } else {
    5912             if (itr->second->getDataSet() != NULL) {
    5913                 double range[2];
    5914                 itr->second->getDataSet()->getDataRange(range);
    5915                 lut->SetRange(range);
    5916             }
    5917         }
    5918 
    5919         itr->second->setLookupTable(lut);
     6055        itr->second->setColorMap(cmap);
    59206056    } while (doAll && ++itr != _streamlines.end());
    59216057
     
    61206256        _volumes[dsID] = volume;
    61216257
    6122         volume->setDataSet(ds);
    6123 
    6124         if (_useCumulativeRange) {
    6125             ColorMap *cmap = volume->getColorMap();
    6126             volume->setColorMap(cmap, _cumulativeDataRange);
    6127         }
     6258        volume->setDataSet(ds,
     6259                           _useCumulativeRange,
     6260                           _cumulativeScalarRange,
     6261                           _cumulativeVectorMagnitudeRange,
     6262                           _cumulativeVectorComponentRange );
    61286263
    61296264        _renderer->AddViewProp(volume->getProp());
     
    61446279
    61456280    if (itr == _volumes.end()) {
     6281#ifdef DEBUG
    61466282        TRACE("Volume not found: %s", id.c_str());
     6283#endif
    61476284        return NULL;
    61486285    } else
     
    63216458              itr->second->getDataSet()->getName().c_str());
    63226459
    6323         if (_useCumulativeRange) {
    6324             itr->second->setColorMap(cmap, _cumulativeDataRange);
    6325         } else {
    6326             itr->second->setColorMap(cmap);
    6327         }
     6460        itr->second->setColorMap(cmap);
    63286461    } while (doAll && ++itr != _volumes.end());
    63296462
     
    73507483/**
    73517484 * \brief Update data ranges for color-mapping and contours
    7352  *
    7353  * \param[in] useCumulative Use cumulative range of all DataSets
    7354  */
    7355 void Renderer::updateRanges(bool useCumulative)
    7356 {
     7485 */
     7486void Renderer::updateRanges()
     7487{
     7488    collectDataRanges();
     7489
    73577490    for (Contour2DHashmap::iterator itr = _contour2Ds.begin();
    73587491         itr != _contour2Ds.end(); ++itr) {
    7359         // Only need to update range if using evenly spaced contours
    7360         if (itr->second->getContourList().empty()) {
    7361             if (useCumulative) {
    7362                 itr->second->setContours(itr->second->getNumContours(), _cumulativeDataRange);
    7363             } else {
    7364                 itr->second->setContours(itr->second->getNumContours());
    7365             }
    7366         }
     7492        itr->second->updateRanges(_useCumulativeRange,
     7493                                  _cumulativeScalarRange,
     7494                                  _cumulativeVectorMagnitudeRange,
     7495                                  _cumulativeVectorComponentRange);
    73677496    }
    73687497    for (Contour3DHashmap::iterator itr = _contour3Ds.begin();
    73697498         itr != _contour3Ds.end(); ++itr) {
    7370         // Only need to update range if using evenly spaced contours
    7371         if (itr->second->getContourList().empty()) {
    7372             if (useCumulative) {
    7373                 itr->second->setContours(itr->second->getNumContours(), _cumulativeDataRange);
    7374             } else {
    7375                 itr->second->setContours(itr->second->getNumContours());
    7376             }
    7377         }
     7499        itr->second->updateRanges(_useCumulativeRange,
     7500                                  _cumulativeScalarRange,
     7501                                  _cumulativeVectorMagnitudeRange,
     7502                                  _cumulativeVectorComponentRange);
    73787503    }
    73797504    for (GlyphsHashmap::iterator itr = _glyphs.begin();
    73807505         itr != _glyphs.end(); ++itr) {
    7381         vtkLookupTable *lut = itr->second->getLookupTable();
    7382         if (lut) {
    7383             if (useCumulative) {
    7384                 lut->SetRange(_cumulativeDataRange);
    7385             } else {
    7386                 double range[2];
    7387                 if (itr->second->getDataSet()) {
    7388                     itr->second->getDataSet()->getDataRange(range);
    7389                     lut->SetRange(range);
    7390                 }
    7391             }
    7392         }
     7506        itr->second->updateRanges(_useCumulativeRange,
     7507                                  _cumulativeScalarRange,
     7508                                  _cumulativeVectorMagnitudeRange,
     7509                                  _cumulativeVectorComponentRange);
    73937510    }
    73947511    for (HeightMapHashmap::iterator itr = _heightMaps.begin();
    73957512         itr != _heightMaps.end(); ++itr) {
    7396         vtkLookupTable *lut = itr->second->getLookupTable();
    7397         if (lut) {
    7398             if (useCumulative) {
    7399                 lut->SetRange(_cumulativeDataRange);
    7400             } else {
    7401                 double range[2];
    7402                 if (itr->second->getDataSet()) {
    7403                     itr->second->getDataSet()->getDataRange(range);
    7404                     lut->SetRange(range);
    7405                 }
    7406             }
    7407         }
    7408         // Only need to update contour range if using evenly spaced contours
    7409         if (itr->second->getContourList().empty()) {
    7410             if (useCumulative) {
    7411                 itr->second->setContours(itr->second->getNumContours(), _cumulativeDataRange);
    7412             } else {
    7413                 itr->second->setContours(itr->second->getNumContours());
    7414             }
    7415         }
     7513        itr->second->updateRanges(_useCumulativeRange,
     7514                                  _cumulativeScalarRange,
     7515                                  _cumulativeVectorMagnitudeRange,
     7516                                  _cumulativeVectorComponentRange);
    74167517    }
    74177518    for (LICHashmap::iterator itr = _lics.begin();
    74187519         itr != _lics.end(); ++itr) {
    7419         vtkLookupTable *lut = itr->second->getLookupTable();
    7420         if (lut) {
    7421             if (useCumulative) {
    7422                 lut->SetRange(_cumulativeDataRange);
    7423             } else {
    7424                 double range[2];
    7425                 if (itr->second->getDataSet()) {
    7426                     itr->second->getDataSet()->getDataRange(range);
    7427                     lut->SetRange(range);
    7428                 }
    7429             }
    7430         }
     7520        itr->second->updateRanges(_useCumulativeRange,
     7521                                  _cumulativeScalarRange,
     7522                                  _cumulativeVectorMagnitudeRange,
     7523                                  _cumulativeVectorComponentRange);
     7524    }
     7525    for (MoleculeHashmap::iterator itr = _molecules.begin();
     7526         itr != _molecules.end(); ++itr) {
     7527        itr->second->updateRanges(_useCumulativeRange,
     7528                                  _cumulativeScalarRange,
     7529                                  _cumulativeVectorMagnitudeRange,
     7530                                  _cumulativeVectorComponentRange);
    74317531    }
    74327532    for (PseudoColorHashmap::iterator itr = _pseudoColors.begin();
    74337533         itr != _pseudoColors.end(); ++itr) {
    7434         vtkLookupTable *lut = itr->second->getLookupTable();
    7435         if (lut) {
    7436             if (useCumulative) {
    7437                 lut->SetRange(_cumulativeDataRange);
    7438             } else {
    7439                 double range[2];
    7440                 if (itr->second->getDataSet()) {
    7441                     itr->second->getDataSet()->getDataRange(range);
    7442                     lut->SetRange(range);
    7443                 }
    7444             }
    7445         }
     7534        itr->second->updateRanges(_useCumulativeRange,
     7535                                  _cumulativeScalarRange,
     7536                                  _cumulativeVectorMagnitudeRange,
     7537                                  _cumulativeVectorComponentRange);
    74467538    }
    74477539    for (StreamlinesHashmap::iterator itr = _streamlines.begin();
    74487540         itr != _streamlines.end(); ++itr) {
    7449         vtkLookupTable *lut = itr->second->getLookupTable();
    7450         if (lut) {
    7451             if (useCumulative) {
    7452                 lut->SetRange(_cumulativeDataRange);
    7453             } else {
    7454                 double range[2];
    7455                 if (itr->second->getDataSet()) {
    7456                     itr->second->getDataSet()->getDataRange(range);
    7457                     lut->SetRange(range);
    7458                 }
    7459             }
    7460         }
     7541        itr->second->updateRanges(_useCumulativeRange,
     7542                                  _cumulativeScalarRange,
     7543                                  _cumulativeVectorMagnitudeRange,
     7544                                  _cumulativeVectorComponentRange);
    74617545    }
    74627546    for (VolumeHashmap::iterator itr = _volumes.begin();
    74637547         itr != _volumes.end(); ++itr) {
    7464         ColorMap *cmap = itr->second->getColorMap();
    7465         if (cmap) {
    7466             if (useCumulative) {
    7467                 itr->second->setColorMap(cmap, _cumulativeDataRange);
    7468             } else {
    7469                 itr->second->setColorMap(cmap);
    7470             }
    7471         }
     7548        itr->second->updateRanges(_useCumulativeRange,
     7549                                  _cumulativeScalarRange,
     7550                                  _cumulativeVectorMagnitudeRange,
     7551                                  _cumulativeVectorComponentRange);
     7552    }
     7553}
     7554
     7555void Renderer::collectDataRanges()
     7556{
     7557    collectScalarRanges(_cumulativeScalarRange,
     7558                        _cumulativeRangeOnlyVisible);
     7559    collectVectorMagnitudeRanges(_cumulativeVectorMagnitudeRange,
     7560                                 _cumulativeRangeOnlyVisible);
     7561    for (int i = 0; i < 3; i++) {
     7562        collectVectorComponentRanges(_cumulativeVectorComponentRange[i], i,
     7563                                     _cumulativeRangeOnlyVisible);
    74727564    }
    74737565}
     
    74797571 * \param[in] onlyVisible Only collect range of visible DataSets
    74807572 */
    7481 void Renderer::collectDataRanges(double *range, bool onlyVisible)
     7573void Renderer::collectScalarRanges(double *range, bool onlyVisible)
    74827574{
    74837575    range[0] = DBL_MAX;
     
    74887580        if (!onlyVisible || itr->second->getVisibility()) {
    74897581            double r[2];
    7490             itr->second->getDataRange(r);
     7582            itr->second->getScalarRange(r);
    74917583            range[0] = min2(range[0], r[0]);
    74927584            range[1] = max2(range[1], r[1]);
     
    74987590        range[1] = 1;
    74997591}
     7592
     7593/**
     7594 * \brief Collect cumulative data range of all DataSets
     7595 *
     7596 * \param[inout] range Data range of all DataSets
     7597 * \param[in] onlyVisible Only collect range of visible DataSets
     7598 */
     7599void Renderer::collectVectorMagnitudeRanges(double *range, bool onlyVisible)
     7600{
     7601    range[0] = DBL_MAX;
     7602    range[1] = -DBL_MAX;
     7603
     7604    for (DataSetHashmap::iterator itr = _dataSets.begin();
     7605         itr != _dataSets.end(); ++itr) {
     7606        if (!onlyVisible || itr->second->getVisibility()) {
     7607            double r[2];
     7608            itr->second->getVectorRange(r);
     7609            range[0] = min2(range[0], r[0]);
     7610            range[1] = max2(range[1], r[1]);
     7611        }
     7612    }
     7613    if (range[0] == DBL_MAX)
     7614        range[0] = 0;
     7615    if (range[1] == -DBL_MAX)
     7616        range[1] = 1;
     7617}
     7618
     7619/**
     7620 * \brief Collect cumulative data range of all DataSets
     7621 *
     7622 * \param[inout] range Data range of all DataSets
     7623 * \param[in] onlyVisible Only collect range of visible DataSets
     7624 */
     7625void Renderer::collectVectorComponentRanges(double *range, int component, bool onlyVisible)
     7626{
     7627    range[0] = DBL_MAX;
     7628    range[1] = -DBL_MAX;
     7629
     7630    for (DataSetHashmap::iterator itr = _dataSets.begin();
     7631         itr != _dataSets.end(); ++itr) {
     7632        if (!onlyVisible || itr->second->getVisibility()) {
     7633            double r[2];
     7634            itr->second->getVectorRange(r, component);
     7635            range[0] = min2(range[0], r[0]);
     7636            range[1] = max2(range[1], r[1]);
     7637        }
     7638    }
     7639    if (range[0] == DBL_MAX)
     7640        range[0] = 0;
     7641    if (range[1] == -DBL_MAX)
     7642        range[1] = 1;
     7643 }
    75007644
    75017645/**
     
    75387682    case ORTHO:
    75397683        _renderer->GetActiveCamera()->ParallelProjectionOn();
    7540         resetAxes();
     7684        resetAxes(bounds);
    75417685        _renderer->ResetCamera(bounds);
    75427686        //computeScreenWorldCoords();
     
    75447688    case PERSPECTIVE:
    75457689        _renderer->GetActiveCamera()->ParallelProjectionOff();
    7546         resetAxes();
     7690        resetAxes(bounds);
    75477691        _renderer->ResetCamera(bounds);
    75487692        //computeScreenWorldCoords();
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2393 r2402  
    232232    // 2D Contour plots
    233233
    234     void addContour2D(const DataSetId& id);
     234    void addContour2D(const DataSetId& id, int numContours);
     235
     236    void addContour2D(const DataSetId& id, const std::vector<double>& contours);
    235237
    236238    void deleteContour2D(const DataSetId& id);
     
    264266    // 3D Contour (isosurface) plots
    265267
    266     void addContour3D(const DataSetId& id);
     268    void addContour3D(const DataSetId& id, int numContours);
     269
     270    void addContour3D(const DataSetId& id, const std::vector<double>& contours);
    267271
    268272    void deleteContour3D(const DataSetId& id);
     
    304308    // Glyphs
    305309
    306     void addGlyphs(const DataSetId& id);
     310    void addGlyphs(const DataSetId& id, Glyphs::GlyphShape shape);
    307311
    308312    void deleteGlyphs(const DataSetId& id);
     
    348352    // Height maps
    349353
    350     void addHeightMap(const DataSetId& id);
     354    void addHeightMap(const DataSetId& id, int numContours);
     355
     356    void addHeightMap(const DataSetId& id, const std::vector<double>& contours);
    351357
    352358    void deleteHeightMap(const DataSetId& id);
     
    650656    void collectBounds(double *bounds, bool onlyVisible);
    651657
    652     void collectDataRanges(double *range, bool onlyVisible);
    653 
    654     void updateRanges(bool useCumulative);
     658    void collectDataRanges();
     659
     660    void collectScalarRanges(double *range, bool onlyVisible);
     661
     662    void collectVectorMagnitudeRanges(double *range, bool onlyVisible);
     663
     664    void collectVectorComponentRanges(double *range, int component, bool onlyVisible);
     665
     666    void updateRanges();
     667
     668    void updateColorMap(ColorMap *cmap);
     669
     670    bool colorMapUsed(ColorMap *cmap);
    655671
    656672    void setCameraFromMatrix(vtkCamera *camera, vtkMatrix4x4 &mat);
     
    664680    void initCamera();
    665681    void initAxes();
    666     void resetAxes();
     682    void resetAxes(double bounds[6] = NULL);
    667683    void setCameraClippingPlanes();
    668684
     
    678694    bool _useCumulativeRange;
    679695    bool _cumulativeRangeOnlyVisible;
    680     double _cumulativeDataRange[2];
     696    double _cumulativeScalarRange[2];
     697    double _cumulativeVectorMagnitudeRange[2];
     698    double _cumulativeVectorComponentRange[3][2];
    681699
    682700    ColorMapHashmap _colorMaps;
  • trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp

    r2393 r2402  
    625625    if (objc == 5) {
    626626        const char *name = Tcl_GetString(objv[4]);
    627         g_renderer->addContour2D(name);
    628         g_renderer->setContour2DContourList(name, contourList);
    629     } else {
    630         g_renderer->addContour2D("all");
    631         g_renderer->setContour2DContourList("all", contourList);
     627        g_renderer->addContour2D(name, contourList);
     628    } else {
     629        g_renderer->addContour2D("all", contourList);
    632630    }
    633631    return TCL_OK;
     
    644642    if (objc == 5) {
    645643        const char *name = Tcl_GetString(objv[4]);
    646         g_renderer->addContour2D(name);
    647         g_renderer->setContour2DContours(name, numContours);
    648     } else {
    649         g_renderer->addContour2D("all");
    650         g_renderer->setContour2DContours("all", numContours);
     644        g_renderer->addContour2D(name, numContours);
     645    } else {
     646        g_renderer->addContour2D("all", numContours);
    651647    }
    652648    return TCL_OK;
     
    882878    if (objc == 5) {
    883879        const char *name = Tcl_GetString(objv[4]);
    884         g_renderer->addContour3D(name);
    885         g_renderer->setContour3DContourList(name, contourList);
    886     } else {
    887         g_renderer->addContour3D("all");
    888         g_renderer->setContour3DContourList("all", contourList);
     880        g_renderer->addContour3D(name, contourList);
     881    } else {
     882        g_renderer->addContour3D("all", contourList);
    889883    }
    890884    return TCL_OK;
     
    901895    if (objc == 5) {
    902896        const char *name = Tcl_GetString(objv[4]);
    903         g_renderer->addContour3D(name);
    904         g_renderer->setContour3DContours(name, numContours);
    905     } else {
    906         g_renderer->addContour3D("all");
    907         g_renderer->setContour3DContours("all", numContours);
     897        g_renderer->addContour3D(name, numContours);
     898    } else {
     899        g_renderer->addContour3D("all", numContours);
    908900    }
    909901    return TCL_OK;
     
    12711263#else
    12721264    size_t bytesRead = fread(data, 1, nbytes, g_fIn);
    1273     TRACE("bytesRead: %d '%c'", bytesRead, data[0]);
     1265    TRACE("bytesRead: %d", bytesRead);
    12741266    if (bytesRead < (size_t)nbytes) {
    12751267        free(data);
     
    14681460    } else if (shapeOpt[0] == 'i' && strcmp(shapeOpt, "icosahedron") == 0) {
    14691461        shape = Glyphs::ICOSAHEDRON;
     1462    } else if (shapeOpt[0] == 'l' && strcmp(shapeOpt, "line") == 0) {
     1463        shape = Glyphs::LINE;
    14701464    } else if (shapeOpt[0] == 'o' && strcmp(shapeOpt, "octahedron") == 0) {
    14711465        shape = Glyphs::OCTAHEDRON;
     
    14821476    if (objc == 4) {
    14831477        const char *name = Tcl_GetString(objv[3]);
    1484         g_renderer->addGlyphs(name);
    1485         g_renderer->setGlyphsShape(name, shape);
    1486     } else {
    1487         g_renderer->addGlyphs("all");
    1488         g_renderer->setGlyphsShape("all", shape);
     1478        g_renderer->addGlyphs(name, shape);
     1479    } else {
     1480        g_renderer->addGlyphs("all", shape);
    14891481    }
    14901482    return TCL_OK;
     
    15361528    } else if (str[0] == 's' && strcmp(str, "scalar") == 0) {
    15371529        mode = Glyphs::COLOR_BY_SCALAR;
    1538     } else if (str[0] == 'v' && strcmp(str, "vector") == 0) {
    1539         mode = Glyphs::COLOR_BY_VECTOR;
     1530    } else if (str[0] == 'v' && strcmp(str, "vmag") == 0) {
     1531        mode = Glyphs::COLOR_BY_VECTOR_MAGNITUDE;
    15401532    } else {
    15411533        Tcl_AppendResult(interp, "bad color mode option \"", str,
    1542                          "\": should be one of: 'scale', 'scalar', 'vector', 'ccolor'", (char*)NULL);
     1534                         "\": should be one of: 'scale', 'scalar', 'vmag', 'ccolor'", (char*)NULL);
    15431535        return TCL_ERROR;
    15441536    }
     
    17351727    if (str[0] == 's' && strcmp(str, "scalar") == 0) {
    17361728        mode = Glyphs::SCALE_BY_SCALAR;
    1737     } else if (str[0] == 'v' && strcmp(str, "vector") == 0) {
    1738         mode = Glyphs::SCALE_BY_VECTOR;
    1739     } else if (str[0] == 'v' && strcmp(str, "vector_comp") == 0) {
     1729    } else if (str[0] == 'v' && strcmp(str, "vmag") == 0) {
     1730        mode = Glyphs::SCALE_BY_VECTOR_MAGNITUDE;
     1731    } else if (str[0] == 'v' && strcmp(str, "vcomp") == 0) {
    17401732        mode = Glyphs::SCALE_BY_VECTOR_COMPONENTS;
    17411733    } else if (str[0] == 'o' && strcmp(str, "off") == 0) {
     
    17431735    } else {
    17441736        Tcl_AppendResult(interp, "bad scaling mode option \"", str,
    1745                          "\": should be one of: 'scalar', 'vector', 'vector_comp', 'off'", (char*)NULL);
     1737                         "\": should be one of: 'scalar', 'vmag', 'vcomp', 'off'", (char*)NULL);
    17461738        return TCL_ERROR;
    17471739    }
     
    17741766    } else if (shapeOpt[0] == 'i' && strcmp(shapeOpt, "icosahedron") == 0) {
    17751767        shape = Glyphs::ICOSAHEDRON;
     1768    } else if (shapeOpt[0] == 'l' && strcmp(shapeOpt, "line") == 0) {
     1769        shape = Glyphs::LINE;
    17761770    } else if (shapeOpt[0] == 'o' && strcmp(shapeOpt, "octahedron") == 0) {
    17771771        shape = Glyphs::OCTAHEDRON;
     
    17821776    } else {
    17831777        Tcl_AppendResult(interp, "bad shape option \"", shapeOpt,
    1784                          "\": should be one of: 'arrow', 'cone', 'cube', 'cylinder', 'dodecahedron', 'icosahedron', 'octahedron', 'sphere', 'tetrahedron'", (char*)NULL);
     1778                         "\": should be one of: 'arrow', 'cone', 'cube', 'cylinder', 'dodecahedron', 'icosahedron', 'line', 'octahedron', 'sphere', 'tetrahedron'", (char*)NULL);
    17851779        return TCL_ERROR;
    17861780    }
     
    18881882    if (objc == 5) {
    18891883        const char *name = Tcl_GetString(objv[4]);
    1890         g_renderer->addHeightMap(name);
    1891         g_renderer->setHeightMapContourList(name, contourList);
    1892     } else {
    1893         g_renderer->addHeightMap("all");
    1894         g_renderer->setHeightMapContourList("all", contourList);
     1884        g_renderer->addHeightMap(name, contourList);
     1885    } else {
     1886        g_renderer->addHeightMap("all", contourList);
    18951887    }
    18961888    return TCL_OK;
     
    19071899    if (objc == 5) {
    19081900        const char *name = Tcl_GetString(objv[4]);
    1909         g_renderer->addHeightMap(name);
    1910         g_renderer->setHeightMapContours(name, numContours);
    1911     } else {
    1912         g_renderer->addHeightMap("all");
    1913         g_renderer->setHeightMapContours("all", numContours);
     1901        g_renderer->addHeightMap(name, numContours);
     1902    } else {
     1903        g_renderer->addHeightMap("all", numContours);
    19141904    }
    19151905    return TCL_OK;
     
    44294419        iov[1].iov_len = nBytes;
    44304420        iov[2].iov_base = (char *)"\n";
    4431         iov[2].iov_len = 1;
     4421        iov[2].iov_len = strlen((char *)iov[2].iov_base);
    44324422        if (writev(fdOut, iov, 3) < 0) {
    44334423            ERROR("write failed: %s", strerror(errno));
  • trunk/packages/vizservers/vtkvis/protocol.txt

    r2393 r2402  
    128128glyphs ccolor r g b <?datasetName?>
    129129glyphs colormap <colorMapName> <?dataSetName?>
    130 glyphs colormode <scale|scalar|vector|ccolor> <?dataSetName?>
     130glyphs colormode <scale|scalar|vmag|ccolor> <?dataSetName?>
    131131       Set the color mode: color by scale, scalar field or
    132132       vector magnitude -- uses the current color map
     
    142142glyphs pos <x> <y> <z> <?dataSetName?>
    143143glyphs scale <sx> <sy> <sz> <?dataSetName?>
    144 glyphs shape <arrow|cone|cube|cylinder|dodecahedron|icosahedron|octahedron|sphere|tetrahedron> <?datasetName?>
    145 glyphs smode <scalar|vector|vector_comp|off> <?dataSetName?>
     144glyphs shape <arrow|cone|cube|cylinder|dodecahedron|icosahedron|line|octahedron|sphere|tetrahedron> <?datasetName?>
     145glyphs smode <scalar|vmag|vcomp|off> <?dataSetName?>
    146146       Set the scaling mode: use the scalar field, vector magnitude
    147147       (uniform scale), vector components, or disable scaling
Note: See TracChangeset for help on using the changeset viewer.