[3597] | 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 | |
---|
| 12 | #ifndef FLOW_H |
---|
| 13 | #define FLOW_H |
---|
| 14 | |
---|
| 15 | #include <tr1/unordered_map> |
---|
| 16 | #include <vector> |
---|
| 17 | #include <string> |
---|
| 18 | |
---|
| 19 | #include <tcl.h> |
---|
| 20 | |
---|
| 21 | #include <vrmath/Vector3f.h> |
---|
| 22 | |
---|
| 23 | #include "Switch.h" |
---|
| 24 | #include "FlowTypes.h" |
---|
| 25 | #include "FlowParticles.h" |
---|
| 26 | #include "FlowBox.h" |
---|
| 27 | #include "NvLIC.h" |
---|
| 28 | #include "NvParticleRenderer.h" |
---|
| 29 | #include "Unirect.h" |
---|
| 30 | #include "Volume.h" |
---|
| 31 | #include "TransferFunction.h" |
---|
| 32 | |
---|
| 33 | struct FlowValues { |
---|
| 34 | TransferFunction *transferFunction; |
---|
| 35 | FlowPosition slicePos; |
---|
| 36 | int showArrows; |
---|
| 37 | int sliceVisible; |
---|
| 38 | int showVolume; |
---|
| 39 | int showOutline; |
---|
| 40 | int isHidden; |
---|
| 41 | int twoSidedLighting; |
---|
| 42 | float ambient; ///< Ambient volume shading |
---|
| 43 | float diffuse; ///< Diffuse volume shading |
---|
| 44 | float specular; ///< Specular level volume shading |
---|
| 45 | float specularExp; ///< Specular exponent volume shading |
---|
| 46 | float opacity; ///< Volume opacity scaling |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | class Flow |
---|
| 50 | { |
---|
| 51 | public: |
---|
| 52 | enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z }; |
---|
| 53 | |
---|
| 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 | float *getScaledVector(); |
---|
| 87 | |
---|
| 88 | Volume *makeVolume(float *data); |
---|
| 89 | |
---|
| 90 | bool scaleVectorField(); |
---|
| 91 | |
---|
| 92 | bool visible() |
---|
| 93 | { |
---|
| 94 | return !_sv.isHidden; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | const char *name() const |
---|
| 98 | { |
---|
| 99 | return _name.c_str(); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | bool isDataLoaded() |
---|
| 103 | { |
---|
| 104 | return (_data != NULL); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | Rappture::Unirect3d *data() |
---|
| 108 | { |
---|
| 109 | return _data; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | void data(Rappture::Unirect3d *data) |
---|
| 113 | { |
---|
| 114 | if (_data != NULL) { |
---|
| 115 | delete _data; |
---|
| 116 | } |
---|
| 117 | _data = data; |
---|
| 118 | } |
---|
| 119 | #if 0 |
---|
| 120 | void activateSlice() |
---|
| 121 | { |
---|
| 122 | /* Must set axis before offset or position goes to wrong axis. */ |
---|
| 123 | NanoVis::licRenderer->setAxis(_sv.slicePos.axis); |
---|
| 124 | NanoVis::licRenderer->setOffset(_sv.slicePos.value); |
---|
| 125 | NanoVis::licRenderer->active(true); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void deactivateSlice() |
---|
| 129 | { |
---|
| 130 | NanoVis::licRenderer->active(false); |
---|
| 131 | } |
---|
| 132 | #endif |
---|
| 133 | SliceAxis getAxis() |
---|
| 134 | { |
---|
| 135 | return (SliceAxis)_sv.slicePos.axis; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | TransferFunction *getTransferFunction() |
---|
| 139 | { |
---|
| 140 | return _sv.transferFunction; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | float getRelativePosition(); |
---|
| 144 | |
---|
| 145 | void setAxis() |
---|
| 146 | { |
---|
| 147 | NanoVis::licRenderer->setAxis(_sv.slicePos.axis); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void setAxis(Flow::SliceAxis axis) |
---|
| 151 | { |
---|
| 152 | _sv.slicePos.axis = axis; |
---|
| 153 | NanoVis::licRenderer->setAxis(_sv.slicePos.axis); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | void setCurrentPosition(float position) |
---|
| 157 | { |
---|
| 158 | _sv.slicePos.value = position; |
---|
| 159 | NanoVis::licRenderer->setOffset(_sv.slicePos.value); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | void setCurrentPosition() |
---|
| 163 | { |
---|
| 164 | NanoVis::licRenderer->setOffset(_sv.slicePos.value); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | void setActive(bool state) |
---|
| 168 | { |
---|
| 169 | _sv.sliceVisible = state; |
---|
| 170 | NanoVis::licRenderer->active(state); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | void setActive() |
---|
| 174 | { |
---|
| 175 | NanoVis::licRenderer->active(_sv.sliceVisible); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | const Volume *getVolume() const |
---|
| 179 | { |
---|
| 180 | return _volume; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | int parseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) |
---|
| 184 | { |
---|
| 185 | if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv, |
---|
| 186 | SWITCH_DEFAULTS) < 0) { |
---|
| 187 | return TCL_ERROR; |
---|
| 188 | } |
---|
| 189 | return TCL_OK; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | Tcl_Command getCommandToken() |
---|
| 193 | { |
---|
| 194 | return _cmdToken; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | static float getRelativePosition(FlowPosition *pos); |
---|
| 198 | |
---|
| 199 | private: |
---|
| 200 | typedef std::string ParticlesId; |
---|
| 201 | typedef std::string BoxId; |
---|
| 202 | typedef std::tr1::unordered_map<ParticlesId, FlowParticles *> ParticlesHashmap; |
---|
| 203 | typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap; |
---|
| 204 | |
---|
| 205 | void configure(); |
---|
| 206 | |
---|
| 207 | void renderBoxes(); |
---|
| 208 | |
---|
| 209 | Tcl_Interp *_interp; |
---|
| 210 | /** |
---|
| 211 | * Name of the flow. This may differ |
---|
| 212 | * from the name of the command |
---|
| 213 | * associated with the flow, if the |
---|
| 214 | * command was renamed. */ |
---|
| 215 | std::string _name; |
---|
| 216 | |
---|
| 217 | /** |
---|
| 218 | * Command associated with the flow. |
---|
| 219 | * When the command is deleted, so is |
---|
| 220 | * the flow. */ |
---|
| 221 | Tcl_Command _cmdToken; |
---|
| 222 | |
---|
| 223 | /** |
---|
| 224 | * Uniform rectangular data |
---|
| 225 | * representing the mesh and vector |
---|
| 226 | * field values. These values are |
---|
| 227 | * kept to regenerate the volume |
---|
| 228 | * associated with the flow. */ |
---|
| 229 | Rappture::Unirect3d *_data; |
---|
| 230 | |
---|
| 231 | /** |
---|
| 232 | * The volume associated with the |
---|
| 233 | * flow. This isn't the same thing as |
---|
| 234 | * a normal volume displayed. */ |
---|
| 235 | Volume *_volume; |
---|
| 236 | |
---|
| 237 | /** |
---|
| 238 | * For each field there can be one or |
---|
| 239 | * more particle injection planes |
---|
| 240 | * where the particles are injected |
---|
| 241 | * into the flow. */ |
---|
| 242 | ParticlesHashmap _particlesTable; |
---|
| 243 | |
---|
| 244 | /** |
---|
| 245 | * A table of boxes. There maybe |
---|
| 246 | * zero or more boxes associated |
---|
| 247 | * with each field. */ |
---|
| 248 | BoxHashmap _boxTable; |
---|
| 249 | |
---|
| 250 | FlowValues _sv; |
---|
| 251 | |
---|
| 252 | static Rappture::SwitchSpec _switches[]; |
---|
| 253 | }; |
---|
| 254 | |
---|
| 255 | #endif |
---|