source: nanovis/tags/1.2.2/Flow.h @ 5724

Last change on this file since 5724 was 5489, checked in by ldelgass, 9 years ago

Move cumulative flow min/max magnitude to Flow.

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
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 "Unirect.h"
28#include "Volume.h"
29#include "TransferFunction.h"
30
31namespace nv {
32
33struct 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
49class Flow
50{
51public:
52    Flow(Tcl_Interp *interp, const char *name);
53
54    ~Flow();
55
56    void getBounds(vrmath::Vector3f& min,
57                   vrmath::Vector3f& max,
58                   bool onlyVisible);
59
60    FlowParticles *createParticles(const char *particlesName);
61
62    FlowParticles *getParticles(const char *particlesName);
63
64    void deleteParticles(const char *particlesName);
65
66    void getParticlesNames(std::vector<std::string>& names);
67
68    void render();
69
70    void advect();
71
72    void resetParticles();
73
74    void initializeParticles();
75
76    FlowBox *createBox(const char *boxName);
77
78    FlowBox *getBox(const char *boxName);
79
80    void deleteBox(const char *boxName);
81
82    void getBoxNames(std::vector<std::string>& names);
83
84    float *getScaledVector();
85
86    Volume *makeVolume(float *data);
87
88    bool scaleVectorField();
89
90    bool visible()
91    {
92        return !_sv.isHidden;
93    }
94
95    const char *name() const
96    {
97        return _name.c_str();
98    }
99
100    bool isDataLoaded()
101    {
102        return (_data != NULL);
103    }
104
105    Unirect3d *data()
106    {
107        return _data;
108    }
109
110    void data(Unirect3d *unirect)
111    {
112        if (_data != NULL) {
113            delete _data;
114        }
115        _data = unirect;
116    }
117
118    FlowSliceAxis getSliceAxis()
119    {
120        return _sv.slicePos.axis;
121    }
122
123    TransferFunction *getTransferFunction()
124    {
125        return _sv.transferFunction;
126    }
127
128    float getRelativePosition()
129    {
130        return getRelativePosition(&_sv.slicePos);
131    }
132
133#if 0
134    void setSliceAxis(FlowSliceAxis axis)
135    {
136        _sv.slicePos.axis = axis;
137        if (NanoVis::licRenderer != NULL) {
138            NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis);
139        }
140        if (NanoVis::velocityArrowsSlice != NULL) {
141            NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis);
142        }
143    }
144
145    void setCurrentPosition(float position)
146    {
147        _sv.slicePos.value = position;
148        if (NanoVis::licRenderer != NULL) {
149            NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value);
150        }
151        if (NanoVis::velocityArrowsSlice != NULL) {
152            NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value);
153        }
154    }
155
156    void setLICActive(bool state)
157    {
158        _sv.sliceVisible = state;
159        if (NanoVis::licRenderer != NULL) {
160            NanoVis::licRenderer->setVectorField(_volume);
161            NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis);
162            NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value);
163            NanoVis::licRenderer->visible(state);
164        }
165    }
166
167    void setArrowsActive(bool state)
168        _sv.showArrows = state;
169        if (NanoVis::velocityArrowsSlice != NULL) {
170            NanoVis::velocityArrowsSlice->setVectorField(_volume);
171            NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis);
172            NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value);
173            NanoVis::velocityArrowsSlice->visible(_sv.showArrows);
174        }
175    }
176#endif
177    const Volume *getVolume() const
178    {
179        return _volume;
180    }
181
182    int parseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
183    {
184        if (nv::ParseSwitches(interp, _switches, objc, objv, &_sv,
185                              SWITCH_DEFAULTS) < 0) {
186            return TCL_ERROR;
187        }
188        return TCL_OK;
189    }
190
191    Tcl_Command getCommandToken()
192    {
193        return _cmdToken;
194    }
195
196    static float getRelativePosition(FlowPosition *pos);
197
198    static bool updatePending;
199    static double magMin, magMax;
200
201private:
202    typedef std::string ParticlesId;
203    typedef std::string BoxId;
204    typedef std::tr1::unordered_map<ParticlesId, FlowParticles *> ParticlesHashmap;
205    typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap;
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    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 SwitchSpec _switches[];
253};
254
255}
256
257#endif
Note: See TracBrowser for help on using the repository browser.