Changeset 2455 for trunk


Ignore:
Timestamp:
Sep 1, 2011, 11:40:10 AM (13 years ago)
Author:
ldelgass
Message:

Add option to turn on wireframe outline of DataSet? bounds

Location:
trunk/packages/vizservers/vtkvis
Files:
5 edited

Legend:

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

    r2454 r2455  
    3232    _name(name),
    3333    _visible(true),
     34    _opacity(1),
    3435    _cellSizeAverage(0)
    3536{
     
    4344
    4445/**
     46 * \brief Create and initialize a VTK Prop to render the outline
     47 */
     48void DataSet::initProp()
     49{
     50    if (_prop == NULL) {
     51        _prop = vtkSmartPointer<vtkActor>::New();
     52        vtkProperty *property = _prop->GetProperty();
     53        property->EdgeVisibilityOff();
     54        property->SetOpacity(_opacity);
     55        property->SetAmbient(.2);
     56        property->LightingOff();
     57        _prop->SetVisibility((_visible ? 1 : 0));
     58    }
     59}
     60
     61/**
     62 * \brief Create and initialize a wireframe outline
     63 */
     64void DataSet::showOutline(bool state)
     65{
     66    if (state) {
     67        if (_outlineFilter == NULL) {
     68            _outlineFilter = vtkSmartPointer<vtkOutlineFilter>::New();
     69            _outlineFilter->SetInput(_dataSet);
     70        }
     71        if (_outlineMapper == NULL) {
     72            _outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
     73            _outlineMapper->SetInputConnection(_outlineFilter->GetOutputPort());
     74        }
     75        initProp();
     76        _prop->SetMapper(_outlineMapper);
     77    } else {
     78        if (_prop != NULL) {
     79            _prop->SetMapper(NULL);
     80        }
     81        if (_outlineMapper != NULL) {
     82            _outlineMapper = NULL;
     83        }
     84        if (_outlineFilter != NULL) {
     85            _outlineFilter = NULL;
     86        }
     87    }
     88}
     89
     90/**
     91 * \brief Set opacity of DataSet outline
     92 *
     93 * This method is used for record-keeping and opacity of the
     94 * DataSet bounds outline.  The renderer controls opacity
     95 * of other related graphics objects.
     96 */
     97void DataSet::setOpacity(double opacity)
     98{
     99    _opacity = opacity;
     100    if (_prop != NULL) {
     101        _prop->GetProperty()->SetOpacity(opacity);
     102    }
     103}
     104
     105/**
    45106 * \brief Set visibility flag in DataSet
    46107 *
    47  * This method is used for record-keeping.  The renderer controls
    48  * the visibility of related graphics objects.
     108 * This method is used for record-keeping and visibility of the
     109 * DataSet bounds outline.  The renderer controls visibility
     110 * of other related graphics objects.
    49111 */
    50112void DataSet::setVisibility(bool state)
    51113{
    52114    _visible = state;
     115    if (_prop != NULL) {
     116        _prop->SetVisibility((state ? 1 : 0));
     117    }
    53118}
    54119
  • trunk/packages/vizservers/vtkvis/RpVtkDataSet.h

    r2454 r2455  
    1212#include <vtkDataSet.h>
    1313#include <vtkDataSetReader.h>
     14#include <vtkProp.h>
     15#include <vtkActor.h>
     16#include <vtkOutlineFilter.h>
     17#include <vtkPolyDataMapper.h>
    1418
    1519#include <string>
     
    7478    bool getVectorValue(double x, double y, double z, double vector[3]) const;
    7579
     80    void setOpacity(double opacity);
     81
     82    /**
     83     * \brief Get the opacity setting for the DataSet
     84     *
     85     * This method is used for record-keeping.  The renderer controls
     86     * the visibility of related graphics objects.
     87     */
     88    inline double getOpacity()
     89    {
     90        return _opacity;
     91    }
     92
    7693    void setVisibility(bool state);
    7794
    7895    bool getVisibility() const;
     96
     97    void showOutline(bool state);
     98
     99    /**
     100     * \brief Return the VTK prop object for the outline
     101     */
     102    inline vtkProp *getProp()
     103    {
     104        return _prop;
     105    }
    79106
    80107private:
     
    84111    void print() const;
    85112
     113    void initProp();
     114
    86115    std::string _name;
    87116    vtkSmartPointer<vtkDataSet> _dataSet;
    88117    bool _visible;
     118    double _opacity;
    89119    double _cellSizeRange[2];
    90120    double _cellSizeAverage;
     121    vtkSmartPointer<vtkOutlineFilter> _outlineFilter;
     122    vtkSmartPointer<vtkActor> _prop;
     123    vtkSmartPointer<vtkPolyDataMapper> _outlineMapper;
    91124};
    92125
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp

    r2453 r2455  
    646646        deleteVolume(itr->second->getName());
    647647 
     648        if (itr->second->getProp() != NULL) {
     649            _renderer->RemoveViewProp(itr->second->getProp());
     650        }
     651
    648652        TRACE("After deleting graphics objects");
    649653
     
    77367740    bounds[5] = -DBL_MAX;
    77377741
     7742    for (DataSetHashmap::iterator itr = _dataSets.begin();
     7743             itr != _dataSets.end(); ++itr) {
     7744        if ((!onlyVisible || itr->second->getVisibility()) &&
     7745            itr->second->getProp() != NULL)
     7746            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
     7747    }
    77387748    for (Contour2DHashmap::iterator itr = _contour2Ds.begin();
    77397749             itr != _contour2Ds.end(); ++itr) {
    7740         if (!onlyVisible || itr->second->getVisibility())
     7750        if ((!onlyVisible || itr->second->getVisibility()) &&
     7751            itr->second->getProp() != NULL)
    77417752            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77427753    }
    77437754    for (Contour3DHashmap::iterator itr = _contour3Ds.begin();
    77447755             itr != _contour3Ds.end(); ++itr) {
    7745         if (!onlyVisible || itr->second->getVisibility())
     7756        if ((!onlyVisible || itr->second->getVisibility()) &&
     7757            itr->second->getProp() != NULL)
    77467758            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77477759    }
    77487760    for (GlyphsHashmap::iterator itr = _glyphs.begin();
    77497761             itr != _glyphs.end(); ++itr) {
    7750         if (!onlyVisible || itr->second->getVisibility())
     7762        if ((!onlyVisible || itr->second->getVisibility()) &&
     7763            itr->second->getProp() != NULL)
    77517764            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77527765    }
    77537766    for (HeightMapHashmap::iterator itr = _heightMaps.begin();
    77547767             itr != _heightMaps.end(); ++itr) {
    7755         if (!onlyVisible || itr->second->getVisibility())
     7768        if ((!onlyVisible || itr->second->getVisibility()) &&
     7769            itr->second->getProp() != NULL)
    77567770            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77577771    }
    77587772    for (LICHashmap::iterator itr = _lics.begin();
    77597773             itr != _lics.end(); ++itr) {
    7760         if (!onlyVisible || itr->second->getVisibility())
     7774        if ((!onlyVisible || itr->second->getVisibility()) &&
     7775            itr->second->getProp() != NULL)
    77617776            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77627777    }
    77637778    for (MoleculeHashmap::iterator itr = _molecules.begin();
    77647779             itr != _molecules.end(); ++itr) {
    7765         if (!onlyVisible || itr->second->getVisibility())
     7780        if ((!onlyVisible || itr->second->getVisibility()) &&
     7781            itr->second->getProp() != NULL)
    77667782            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77677783    }
    77687784    for (PolyDataHashmap::iterator itr = _polyDatas.begin();
    77697785             itr != _polyDatas.end(); ++itr) {
    7770         if (!onlyVisible || itr->second->getVisibility())
     7786        if ((!onlyVisible || itr->second->getVisibility()) &&
     7787            itr->second->getProp() != NULL)
    77717788            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77727789    }
    77737790    for (PseudoColorHashmap::iterator itr = _pseudoColors.begin();
    77747791             itr != _pseudoColors.end(); ++itr) {
    7775         if (!onlyVisible || itr->second->getVisibility())
     7792        if ((!onlyVisible || itr->second->getVisibility()) &&
     7793            itr->second->getProp() != NULL)
    77767794            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77777795    }
    77787796    for (StreamlinesHashmap::iterator itr = _streamlines.begin();
    77797797             itr != _streamlines.end(); ++itr) {
    7780         if (!onlyVisible || itr->second->getVisibility())
     7798        if ((!onlyVisible || itr->second->getVisibility()) &&
     7799            itr->second->getProp() != NULL)
    77817800            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77827801    }
    77837802    for (VolumeHashmap::iterator itr = _volumes.begin();
    77847803             itr != _volumes.end(); ++itr) {
    7785         if (!onlyVisible || itr->second->getVisibility())
     7804        if ((!onlyVisible || itr->second->getVisibility()) &&
     7805            itr->second->getProp() != NULL)
    77867806            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    77877807    }
     
    81448164 * \brief Set the opacity of the specified DataSet's associated graphics objects
    81458165 */
    8146 void Renderer::setOpacity(const DataSetId& id, double opacity)
    8147 {
     8166void Renderer::setDataSetOpacity(const DataSetId& id, double opacity)
     8167{
     8168    DataSetHashmap::iterator itr;
     8169
     8170    bool doAll = false;
     8171
     8172    if (id.compare("all") == 0) {
     8173        itr = _dataSets.begin();
     8174        doAll = true;
     8175    } else {
     8176        itr = _dataSets.find(id);
     8177    }
     8178    if (itr == _dataSets.end()) {
     8179        ERROR("Unknown dataset %s", id.c_str());
     8180        return;
     8181    }
     8182
     8183    do {
     8184        itr->second->setOpacity(opacity);
     8185    } while (doAll && ++itr != _dataSets.end());
     8186
    81488187    if (id.compare("all") == 0 || getContour2D(id) != NULL)
    81498188        setContour2DOpacity(id, opacity);
     
    81668205    if (id.compare("all") == 0 || getVolume(id) != NULL)
    81678206        setVolumeOpacity(id, opacity);
     8207
     8208    _needsRedraw = true;
    81688209}
    81698210
     
    81718212 * \brief Turn on/off rendering of the specified DataSet's associated graphics objects
    81728213 */
    8173 void Renderer::setVisibility(const DataSetId& id, bool state)
     8214void Renderer::setDataSetVisibility(const DataSetId& id, bool state)
    81748215{
    81758216    DataSetHashmap::iterator itr;
     
    82128253    if (id.compare("all") == 0 || getVolume(id) != NULL)
    82138254        setVolumeVisibility(id, state);
     8255
     8256    _needsRedraw = true;
    82148257}
    82158258
     
    82178260 * \brief Toggle rendering of actors' bounding box
    82188261 */
    8219 void Renderer::showBounds(bool state)
    8220 {
    8221     if (state) {
    8222         ; // TODO: Add bounding box actor/mapper
    8223     } else {
    8224         ; // TODO: Remove bounding box actor/mapper
    8225     }
     8262void Renderer::setDataSetShowBounds(const DataSetId& id, bool state)
     8263{
     8264    DataSetHashmap::iterator itr;
     8265
     8266    bool doAll = false;
     8267
     8268    if (id.compare("all") == 0) {
     8269        itr = _dataSets.begin();
     8270        doAll = true;
     8271    } else {
     8272        itr = _dataSets.find(id);
     8273    }
     8274    if (itr == _dataSets.end()) {
     8275        ERROR("Unknown dataset %s", id.c_str());
     8276        return;
     8277    }
     8278
     8279    do {
     8280        if (!state && itr->second->getProp()) {
     8281            _renderer->RemoveViewProp(itr->second->getProp());
     8282        }
     8283
     8284        itr->second->showOutline(state);
     8285
     8286        if (state) {
     8287            _renderer->AddViewProp(itr->second->getProp());
     8288        }
     8289    } while (doAll && ++itr != _dataSets.end());
     8290
     8291    initCamera();
     8292    _needsRedraw = true;
    82268293}
    82278294
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2453 r2455  
    136136    bool getVectorValue(const DataSetId& id, double x, double y, double z, double vector[3]);
    137137
    138     void setOpacity(const DataSetId& id, double opacity);
    139 
    140     void setVisibility(const DataSetId& id, bool state);
     138    void setDataSetShowBounds(const DataSetId& id, bool state);
     139
     140    void setDataSetOpacity(const DataSetId& id, double opacity);
     141
     142    void setDataSetVisibility(const DataSetId& id, bool state);
    141143
    142144    void setUseCumulativeDataRange(bool state, bool onlyVisible = false);
     
    195197
    196198    void setBackgroundColor(float color[3]);
    197 
    198     void showBounds(bool state);
    199199
    200200    void setClipPlane(Axis axis, double ratio, int direction);
  • trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp

    r2453 r2455  
    15041504    if (objc == 4) {
    15051505        const char *name = Tcl_GetString(objv[3]);
    1506         g_renderer->setOpacity(name, opacity);
    1507     } else {
    1508         g_renderer->setOpacity("all", opacity);
     1506        g_renderer->setDataSetOpacity(name, opacity);
     1507    } else {
     1508        g_renderer->setDataSetOpacity("all", opacity);
     1509    }
     1510    return TCL_OK;
     1511}
     1512
     1513static int
     1514DataSetOutlineOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1515                 Tcl_Obj *const *objv)
     1516{
     1517    bool state;
     1518    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1519        return TCL_ERROR;
     1520    }
     1521    if (objc == 4) {
     1522        const char *name = Tcl_GetString(objv[3]);
     1523        g_renderer->setDataSetShowBounds(name, state);
     1524    } else {
     1525        g_renderer->setDataSetShowBounds("all", state);
    15091526    }
    15101527    return TCL_OK;
     
    15691586    if (objc == 4) {
    15701587        const char *name = Tcl_GetString(objv[3]);
    1571         g_renderer->setVisibility(name, state);
    1572     } else {
    1573         g_renderer->setVisibility("all", state);
     1588        g_renderer->setDataSetVisibility(name, state);
     1589    } else {
     1590        g_renderer->setDataSetVisibility("all", state);
    15741591    }
    15751592    return TCL_OK;
     
    15831600    {"maprange",  1, DataSetMapRangeOp, 3, 3, "value"},
    15841601    {"names",     1, DataSetNamesOp, 2, 2, ""},
    1585     {"opacity",   1, DataSetOpacityOp, 3, 4, "value ?name?"},
     1602    {"opacity",   2, DataSetOpacityOp, 3, 4, "value ?name?"},
     1603    {"outline",   2, DataSetOutlineOp, 3, 4, "bool ?name?"},
    15861604    {"scalar",    1, DataSetActiveScalarsOp, 3, 4, "scalarName ?name?"},
    15871605    {"vector",    2, DataSetActiveVectorsOp, 3, 4, "vectorName ?name?"},
Note: See TracChangeset for help on using the changeset viewer.