source: trunk/packages/vizservers/vtkvis/RpMolecule.h @ 3195

Last change on this file since 3195 was 3195, checked in by ldelgass, 11 years ago

Require VTK >= 5.8

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2004-2012  HUBzero Foundation, LLC
4 *
5 * Author: Leif Delgass <ldelgass@purdue.edu>
6 */
7
8#ifndef __RAPPTURE_VTKVIS_MOLECULE_H__
9#define __RAPPTURE_VTKVIS_MOLECULE_H__
10
11#include <vtkSmartPointer.h>
12#include <vtkLookupTable.h>
13#include <vtkPolyDataMapper.h>
14#include <vtkActor.h>
15#include <vtkActor2D.h>
16#include <vtkAssembly.h>
17#include <vtkGlyph3DMapper.h>
18#include <vtkTransformPolyDataFilter.h>
19#include <vtkCylinderSource.h>
20#include <vtkLineSource.h>
21#include <vtkLabelPlacementMapper.h>
22
23#include "ColorMap.h"
24#include "RpVtkGraphicsObject.h"
25
26namespace Rappture {
27namespace VtkVis {
28
29/**
30 * \brief Ball and stick Molecule
31 *
32 * The data format for this class is based on the VisIt Molecule
33 * plot.  It consists of a vtkPolyData with atom coordinates as
34 * points and vertices and bonds as lines.  A scalar array named
35 * "element" can be included as point data to specify atomic
36 * numbers to use in coloring (via the "elementDefault" ColorMap)
37 * and scaling atoms.  If the scalar array is not named
38 * "element," it will be color-mapped as a standard scalar field.
39 */
40class Molecule : public VtkGraphicsObject {
41public:
42    enum AtomScaling {
43        NO_ATOM_SCALING,
44        VAN_DER_WAALS_RADIUS,
45        COVALENT_RADIUS,
46        ATOMIC_RADIUS
47    };
48    enum BondStyle {
49        BOND_STYLE_CYLINDER,
50        BOND_STYLE_LINE
51    };
52    enum ColorMode {
53        COLOR_BY_ELEMENTS,
54        COLOR_BY_SCALAR,
55        COLOR_BY_VECTOR_MAGNITUDE,
56        COLOR_BY_VECTOR_X,
57        COLOR_BY_VECTOR_Y,
58        COLOR_BY_VECTOR_Z,
59        COLOR_CONSTANT
60    };
61    enum BondColorMode {
62        BOND_COLOR_BY_ELEMENTS,
63        BOND_COLOR_CONSTANT
64    };
65
66    Molecule();
67    virtual ~Molecule();
68
69    virtual const char *getClassName() const
70    {
71        return "Molecule";
72    }
73
74    virtual vtkProp *getOverlayProp()
75    {
76        return _labelProp;
77    }
78
79    virtual void setDataSet(DataSet *dataSet,
80                            Renderer *renderer);
81
82    virtual void setClippingPlanes(vtkPlaneCollection *planes);
83
84    void setColorMode(ColorMode mode, DataSet::DataAttributeType type,
85                      const char *name, double range[2] = NULL);
86
87    void setColorMode(ColorMode mode,
88                      const char *name, double range[2] = NULL);
89
90    void setColorMode(ColorMode mode);
91
92    void setColorMap(ColorMap *colorMap);
93
94    /**
95     * \brief Return the ColorMap in use
96     */
97    ColorMap *getColorMap()
98    {
99        return _colorMap;
100    }
101
102    void updateColorMap();
103
104    virtual void updateRanges(Renderer *renderer);
105
106    void setAtomScaling(AtomScaling state);
107
108    void setAtomRadiusScale(double scale);
109
110    void setBondRadiusScale(double scale);
111
112    virtual void setVisibility(bool state);
113
114    virtual void setOpacity(double opacity);
115
116    void setAtomVisibility(bool state);
117
118    void setAtomLabelVisibility(bool state);
119
120    void setBondVisibility(bool state);
121
122    void setBondStyle(BondStyle style);
123
124    void setBondColor(float color[3]);
125
126    void setBondColorMode(BondColorMode mode);
127
128    static ColorMap *createElementColorMap();
129
130private:
131    virtual void initProp();
132    virtual void update();
133
134    void setupBondPolyData();
135
136    static void addLabelArray(vtkDataSet *dataSet);
137
138    static void addRadiusArray(vtkDataSet *dataSet, AtomScaling scaling, double scaleFactor);
139
140    float _bondColor[3];
141    double _radiusScale;
142    AtomScaling _atomScaling;
143    bool _labelsOn;
144    ColorMap *_colorMap;
145    ColorMode _colorMode;
146    std::string _colorFieldName;
147    DataSet::DataAttributeType _colorFieldType;
148    double _colorFieldRange[2];
149    double _vectorMagnitudeRange[2];
150    double _vectorComponentRange[3][2];
151    Renderer *_renderer;
152
153    vtkSmartPointer<vtkLookupTable> _lut;
154    vtkSmartPointer<vtkActor> _atomProp;
155    vtkSmartPointer<vtkActor> _bondProp;
156    vtkSmartPointer<vtkActor2D> _labelProp;
157    vtkSmartPointer<vtkPolyData> _bondPD;
158    vtkSmartPointer<vtkCylinderSource> _cylinderSource;
159    vtkSmartPointer<vtkTransformPolyDataFilter>_cylinderTrans;
160    vtkSmartPointer<vtkLineSource> _lineSource;
161    vtkSmartPointer<vtkGlyph3DMapper> _atomMapper;
162    vtkSmartPointer<vtkGlyph3DMapper> _bondMapper;
163    vtkSmartPointer<vtkLabelPlacementMapper> _labelMapper;
164};
165
166}
167}
168
169#endif
Note: See TracBrowser for help on using the repository browser.