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