Changeset 3693


Ignore:
Timestamp:
Jun 16, 2013 4:52:42 PM (8 years ago)
Author:
ldelgass
Message:

Add protocol to set atom/bond tesselation quality in molecules

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

Legend:

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

    r3676 r3693  
    242242
    243243            // Atoms
    244             vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
    245             sphereSource->SetRadius(1.0);
    246             sphereSource->SetThetaResolution(14);
    247             sphereSource->SetPhiResolution(14);
    248 
    249             _atomMapper->SetSourceConnection(sphereSource->GetOutputPort());
     244            if (_sphereSource == NULL) {
     245                _sphereSource = vtkSmartPointer<vtkSphereSource>::New();
     246                _sphereSource->SetRadius(1.0);
     247                _sphereSource->SetThetaResolution(14);
     248                _sphereSource->SetPhiResolution(14);
     249            }
     250
     251            _atomMapper->SetSourceConnection(_sphereSource->GetOutputPort());
    250252#ifdef USE_VTK6
    251253            _atomMapper->SetInputData(pd);
     
    662664}
    663665
     666void Molecule::setAtomQuality(double quality)
     667{
     668    if (_sphereSource == NULL)
     669        return;
     670
     671    if (quality > 10.0)
     672        quality = 10.0;
     673
     674    int thetaRes = (int)(quality * 14.0);
     675    int phiRes = (int)(quality * 14.0);
     676    if (thetaRes < 4) thetaRes = 4;
     677    if (phiRes < 3) phiRes = 3;
     678
     679    _sphereSource->SetThetaResolution(thetaRes);
     680    _sphereSource->SetPhiResolution(phiRes);
     681
     682    if (_atomMapper != NULL) {
     683        _atomMapper->Modified();
     684        _atomMapper->Update();
     685    }
     686}
     687
     688void Molecule::setBondQuality(double quality)
     689{
     690    if (_cylinderSource == NULL)
     691        return;
     692
     693    if (quality > 10.0)
     694        quality = 10.0;
     695
     696    int res = (int)(quality * 12.0);
     697    if (res < 3) res = 3;
     698
     699    _cylinderSource->SetResolution(res);
     700
     701    if (_bondMapper != NULL) {
     702        _bondMapper->Modified();
     703        _bondMapper->Update();
     704    }
     705}
     706
    664707void Molecule::setBondStyle(BondStyle style)
    665708{
  • trunk/packages/vizservers/vtkvis/Molecule.h

    r3641 r3693  
    1717#include <vtkGlyph3DMapper.h>
    1818#include <vtkTransformPolyDataFilter.h>
     19#include <vtkSphereSource.h>
    1920#include <vtkCylinderSource.h>
    2021#include <vtkLineSource.h>
     
    128129    void setBondColorMode(BondColorMode mode);
    129130
     131    void setAtomQuality(double quality);
     132
     133    void setBondQuality(double quality);
     134
    130135    static ColorMap *createElementColorMap();
    131136
     
    157162    vtkSmartPointer<vtkActor> _bondProp;
    158163    vtkSmartPointer<vtkActor2D> _labelProp;
     164    vtkSmartPointer<vtkSphereSource> _sphereSource;
    159165    vtkSmartPointer<vtkPolyData> _bondPD;
    160166    vtkSmartPointer<vtkCylinderSource> _cylinderSource;
  • trunk/packages/vizservers/vtkvis/Renderer.h

    r3683 r3693  
    742742    // Molecules
    743743
     744    void setMoleculeAtomQuality(const DataSetId& id, double quality);
     745
     746    void setMoleculeBondQuality(const DataSetId& id, double quality);
     747
    744748    void setMoleculeAtomRadiusScale(const DataSetId& id, double scale);
    745749
  • trunk/packages/vizservers/vtkvis/RendererCmd.cpp

    r3683 r3693  
    73327332
    73337333static int
     7334MoleculeAtomQualityOp(ClientData clientData, Tcl_Interp *interp, int objc,
     7335                      Tcl_Obj *const *objv)
     7336{
     7337    double quality;
     7338    if (Tcl_GetDoubleFromObj(interp, objv[2], &quality) != TCL_OK) {
     7339        return TCL_ERROR;
     7340    }
     7341    if (objc == 4) {
     7342        const char *name = Tcl_GetString(objv[3]);
     7343        g_renderer->setMoleculeAtomQuality(name, quality);
     7344    } else {
     7345        g_renderer->setMoleculeAtomQuality("all", quality);
     7346    }
     7347    return TCL_OK;
     7348}
     7349
     7350static int
    73347351MoleculeAtomScaleFactorOp(ClientData clientData, Tcl_Interp *interp, int objc,
    73357352                          Tcl_Obj *const *objv)
     
    74157432    } else {
    74167433        g_renderer->setMoleculeBondColor("all", color);
     7434    }
     7435    return TCL_OK;
     7436}
     7437
     7438static int
     7439MoleculeBondQualityOp(ClientData clientData, Tcl_Interp *interp, int objc,
     7440                      Tcl_Obj *const *objv)
     7441{
     7442    double quality;
     7443    if (Tcl_GetDoubleFromObj(interp, objv[2], &quality) != TCL_OK) {
     7444        return TCL_ERROR;
     7445    }
     7446    if (objc == 4) {
     7447        const char *name = Tcl_GetString(objv[3]);
     7448        g_renderer->setMoleculeBondQuality(name, quality);
     7449    } else {
     7450        g_renderer->setMoleculeBondQuality("all", quality);
    74177451    }
    74187452    return TCL_OK;
     
    77477781static Rappture::CmdSpec moleculeOps[] = {
    77487782    {"add",          2, MoleculeAddOp, 2, 3, "?dataSetName?"},
     7783    {"aquality",     2, MoleculeAtomQualityOp, 3, 4, "value ?dataSetName?"},
    77497784    {"ascale",       2, MoleculeAtomScaleFactorOp, 3, 4, "value ?dataSetName?"},
    77507785    {"atoms",        2, MoleculeAtomVisibilityOp, 3, 4, "bool ?dataSetName?"},
     
    77527787    {"bcolor",       3, MoleculeBondColorOp, 5, 6, "r g b ?dataSetName?"},
    77537788    {"bonds",        2, MoleculeBondVisibilityOp, 3, 4, "bool ?dataSetName?"},
     7789    {"bquality",     2, MoleculeBondQualityOp, 3, 4, "value ?dataSetName?"},
    77547790    {"bscale",       3, MoleculeBondScaleFactorOp, 3, 4, "value ?dataSetName?"},
    77557791    {"bstyle",       3, MoleculeBondStyleOp, 3, 4, "value ?dataSetName?"},
  • trunk/packages/vizservers/vtkvis/RendererGraphicsObjs.cpp

    r3683 r3693  
    22692269
    22702270/**
     2271 * \brief Set atom sphere resolution
     2272 */
     2273void Renderer::setMoleculeAtomQuality(const DataSetId& id, double quality)
     2274{
     2275    MoleculeHashmap::iterator itr;
     2276
     2277    bool doAll = false;
     2278
     2279    if (id.compare("all") == 0) {
     2280        itr = _molecules.begin();
     2281        if (itr == _molecules.end())
     2282            return;
     2283        doAll = true;
     2284    } else {
     2285        itr = _molecules.find(id);
     2286    }
     2287    if (itr == _molecules.end()) {
     2288        ERROR("Molecule not found: %s", id.c_str());
     2289        return;
     2290    }
     2291
     2292    do {
     2293        itr->second->setAtomQuality(quality);
     2294    } while (doAll && ++itr != _molecules.end());
     2295
     2296    sceneBoundsChanged();
     2297    _needsRedraw = true;
     2298}
     2299
     2300
     2301/**
     2302 * \brief Set bond cylinder resolution
     2303 */
     2304void Renderer::setMoleculeBondQuality(const DataSetId& id, double quality)
     2305{
     2306    MoleculeHashmap::iterator itr;
     2307
     2308    bool doAll = false;
     2309
     2310    if (id.compare("all") == 0) {
     2311        itr = _molecules.begin();
     2312        if (itr == _molecules.end())
     2313            return;
     2314        doAll = true;
     2315    } else {
     2316        itr = _molecules.find(id);
     2317    }
     2318    if (itr == _molecules.end()) {
     2319        ERROR("Molecule not found: %s", id.c_str());
     2320        return;
     2321    }
     2322
     2323    do {
     2324        itr->second->setBondQuality(quality);
     2325    } while (doAll && ++itr != _molecules.end());
     2326
     2327    sceneBoundsChanged();
     2328    _needsRedraw = true;
     2329}
     2330
     2331
     2332/**
    22712333 * \brief Set radius scale factor for atoms
    22722334 */
     
    30203082 * \param[in] data Bytes of VTK DataSet file
    30213083 * \param[in] nbytes Length of data array
     3084 * \param[in] maxPoints Maximum number of points to be used as seeds
    30223085 *
    30233086 * \return boolean indicating success or failure
  • trunk/packages/vizservers/vtkvis/Streamlines.cpp

    r3682 r3693  
    706706 *
    707707 * \param[in] seed vtkDataSet with points to use as seeds
     708 * \param[in] maxPoints Maximum number of points to be used as seeds
    708709 */
    709710void Streamlines::setSeedToMeshPoints(vtkDataSet *seed, int maxPoints)
  • trunk/packages/vizservers/vtkvis/protocol.txt

    r3683 r3693  
    591591
    592592molecule add <?datasetName?>
     593molecule aquality <val> <?datasetName?>
     594         Set atom sphere resolution quality val=[0,10], 1 is default
     595molecule ascale <val> <?datasetName?>
     596         Set atom scale factor
    593597molecule atoms <bool> <?datasetName?>
    594598         Toggle rendering of atoms
    595 molecule ascale <val> <?datasetName?>
    596          Set atom scale factor
    597599molecule bcmode <by_elements|constant> <?datasetName?>
    598600         Set bond color mode
     
    601603molecule bonds <bool> <?datasetName?>
    602604         Toggle rendering of bonds
     605molecule bquality <val> <?datasetName?>
     606         Set bond cylinder resolution quality val=[0,10], 1 is default
    603607molecule bscale <val> <?datasetName?>
    604608         Set bond scale factor
Note: See TracChangeset for help on using the changeset viewer.