1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Authors: |
---|
6 | * Wei Qiao <qiaow@purdue.edu> |
---|
7 | * Insoo Woo <iwoo@purdue.edu> |
---|
8 | * George A. Howlett <gah@purdue.edu> |
---|
9 | * Leif Delgass <ldelgass@purdue.edu> |
---|
10 | */ |
---|
11 | #ifndef NV_FLOW_H |
---|
12 | #define NV_FLOW_H |
---|
13 | |
---|
14 | #include <tr1/unordered_map> |
---|
15 | #include <vector> |
---|
16 | #include <string> |
---|
17 | |
---|
18 | #include <tcl.h> |
---|
19 | |
---|
20 | #include <vrmath/Vector3f.h> |
---|
21 | |
---|
22 | #include "Switch.h" |
---|
23 | #include "FlowTypes.h" |
---|
24 | #include "FlowParticles.h" |
---|
25 | #include "FlowBox.h" |
---|
26 | #include "LIC.h" |
---|
27 | #include "VelocityArrowsSlice.h" |
---|
28 | #include "Volume.h" |
---|
29 | #include "TransferFunction.h" |
---|
30 | |
---|
31 | namespace nv { |
---|
32 | |
---|
33 | class Unirect3d; |
---|
34 | |
---|
35 | struct FlowValues { |
---|
36 | TransferFunction *transferFunction; |
---|
37 | FlowPosition slicePos; |
---|
38 | int showArrows; |
---|
39 | int sliceVisible; |
---|
40 | int showVolume; |
---|
41 | int showOutline; |
---|
42 | int isHidden; |
---|
43 | int twoSidedLighting; |
---|
44 | float ambient; ///< Ambient volume shading |
---|
45 | float diffuse; ///< Diffuse volume shading |
---|
46 | float specular; ///< Specular level volume shading |
---|
47 | float specularExp; ///< Specular exponent volume shading |
---|
48 | float opacity; ///< Volume opacity scaling |
---|
49 | }; |
---|
50 | |
---|
51 | class Flow |
---|
52 | { |
---|
53 | public: |
---|
54 | Flow(Tcl_Interp *interp, const char *name); |
---|
55 | |
---|
56 | ~Flow(); |
---|
57 | |
---|
58 | void getBounds(vrmath::Vector3f& min, |
---|
59 | vrmath::Vector3f& max, |
---|
60 | bool onlyVisible); |
---|
61 | |
---|
62 | FlowParticles *createParticles(const char *particlesName); |
---|
63 | |
---|
64 | FlowParticles *getParticles(const char *particlesName); |
---|
65 | |
---|
66 | void deleteParticles(const char *particlesName); |
---|
67 | |
---|
68 | void getParticlesNames(std::vector<std::string>& names); |
---|
69 | |
---|
70 | void render(); |
---|
71 | |
---|
72 | void advect(); |
---|
73 | |
---|
74 | void resetParticles(); |
---|
75 | |
---|
76 | void initializeParticles(); |
---|
77 | |
---|
78 | FlowBox *createBox(const char *boxName); |
---|
79 | |
---|
80 | FlowBox *getBox(const char *boxName); |
---|
81 | |
---|
82 | void deleteBox(const char *boxName); |
---|
83 | |
---|
84 | void getBoxNames(std::vector<std::string>& names); |
---|
85 | |
---|
86 | bool visible() |
---|
87 | { |
---|
88 | return !_sv.isHidden; |
---|
89 | } |
---|
90 | |
---|
91 | const char *name() const |
---|
92 | { |
---|
93 | return _name.c_str(); |
---|
94 | } |
---|
95 | |
---|
96 | bool isDataLoaded() |
---|
97 | { |
---|
98 | return (_volume != NULL); |
---|
99 | } |
---|
100 | |
---|
101 | void getVectorRange(double range[]) |
---|
102 | { |
---|
103 | range[0] = _volume->wAxis.min(); |
---|
104 | range[1] = _volume->wAxis.max(); |
---|
105 | } |
---|
106 | |
---|
107 | void data(Unirect3d *unirect); |
---|
108 | |
---|
109 | void data(Volume *volume); |
---|
110 | |
---|
111 | FlowSliceAxis getSliceAxis() |
---|
112 | { |
---|
113 | return _sv.slicePos.axis; |
---|
114 | } |
---|
115 | |
---|
116 | TransferFunction *getTransferFunction() |
---|
117 | { |
---|
118 | return _sv.transferFunction; |
---|
119 | } |
---|
120 | #if 0 |
---|
121 | void setSliceAxis(FlowSliceAxis axis) |
---|
122 | { |
---|
123 | _sv.slicePos.axis = axis; |
---|
124 | if (NanoVis::licRenderer != NULL) { |
---|
125 | NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis); |
---|
126 | } |
---|
127 | if (NanoVis::velocityArrowsSlice != NULL) { |
---|
128 | NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis); |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | void setCurrentPosition(float position) |
---|
133 | { |
---|
134 | _sv.slicePos.value = position; |
---|
135 | if (NanoVis::licRenderer != NULL) { |
---|
136 | NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value); |
---|
137 | } |
---|
138 | if (NanoVis::velocityArrowsSlice != NULL) { |
---|
139 | NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | void setLICActive(bool state) |
---|
144 | { |
---|
145 | _sv.sliceVisible = state; |
---|
146 | if (NanoVis::licRenderer != NULL) { |
---|
147 | NanoVis::licRenderer->setVectorField(_volume); |
---|
148 | NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis); |
---|
149 | NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value); |
---|
150 | NanoVis::licRenderer->visible(state); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | void setArrowsActive(bool state) |
---|
155 | _sv.showArrows = state; |
---|
156 | if (NanoVis::velocityArrowsSlice != NULL) { |
---|
157 | NanoVis::velocityArrowsSlice->setVectorField(_volume); |
---|
158 | NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis); |
---|
159 | NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value); |
---|
160 | NanoVis::velocityArrowsSlice->visible(_sv.showArrows); |
---|
161 | } |
---|
162 | } |
---|
163 | #endif |
---|
164 | const Volume *getVolume() const |
---|
165 | { |
---|
166 | return _volume; |
---|
167 | } |
---|
168 | |
---|
169 | int parseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) |
---|
170 | { |
---|
171 | if (nv::ParseSwitches(interp, _switches, objc, objv, &_sv, |
---|
172 | SWITCH_DEFAULTS) < 0) { |
---|
173 | return TCL_ERROR; |
---|
174 | } |
---|
175 | return TCL_OK; |
---|
176 | } |
---|
177 | |
---|
178 | bool configure(); |
---|
179 | |
---|
180 | Tcl_Command getCommandToken() |
---|
181 | { |
---|
182 | return _cmdToken; |
---|
183 | } |
---|
184 | |
---|
185 | float getRelativePosition(FlowPosition *pos); |
---|
186 | |
---|
187 | static bool updatePending; |
---|
188 | static double magMin, magMax; |
---|
189 | |
---|
190 | private: |
---|
191 | typedef std::string ParticlesId; |
---|
192 | typedef std::string BoxId; |
---|
193 | typedef std::tr1::unordered_map<ParticlesId, FlowParticles *> ParticlesHashmap; |
---|
194 | typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap; |
---|
195 | |
---|
196 | void initVolume(); |
---|
197 | |
---|
198 | bool scaleVectorField(); |
---|
199 | |
---|
200 | float *getScaledVector(Unirect3d *unirect); |
---|
201 | |
---|
202 | Volume *makeVolume(Unirect3d *unirect, float *data); |
---|
203 | |
---|
204 | void renderBoxes(); |
---|
205 | |
---|
206 | Tcl_Interp *_interp; |
---|
207 | /** |
---|
208 | * Name of the flow. This may differ |
---|
209 | * from the name of the command |
---|
210 | * associated with the flow, if the |
---|
211 | * command was renamed. */ |
---|
212 | std::string _name; |
---|
213 | |
---|
214 | /** |
---|
215 | * Command associated with the flow. |
---|
216 | * When the command is deleted, so is |
---|
217 | * the flow. */ |
---|
218 | Tcl_Command _cmdToken; |
---|
219 | |
---|
220 | /** |
---|
221 | * The volume associated with the |
---|
222 | * flow. This isn't the same thing as |
---|
223 | * a normal volume displayed. */ |
---|
224 | Volume *_volume; |
---|
225 | |
---|
226 | /** |
---|
227 | * For each field there can be one or |
---|
228 | * more particle injection planes |
---|
229 | * where the particles are injected |
---|
230 | * into the flow. */ |
---|
231 | ParticlesHashmap _particlesTable; |
---|
232 | |
---|
233 | /** |
---|
234 | * A table of boxes. There maybe |
---|
235 | * zero or more boxes associated |
---|
236 | * with each field. */ |
---|
237 | BoxHashmap _boxTable; |
---|
238 | |
---|
239 | FlowValues _sv; |
---|
240 | |
---|
241 | static SwitchSpec _switches[]; |
---|
242 | }; |
---|
243 | |
---|
244 | } |
---|
245 | |
---|
246 | #endif |
---|