source: nanovis/trunk/Flow.h @ 4596

Last change on this file since 4596 was 4056, checked in by ldelgass, 11 years ago

Use nv namespace for internal classes (not Rappture) to make it easier to find
dependencies on the Rappture libraries.

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