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