source: trunk/packages/vizservers/nanovis/Flow.h @ 3630

Last change on this file since 3630 was 3630, checked in by ldelgass, 7 years ago

Nanovis refactoring to fix problems with scaling and multiple results.
Do rendering in world space to properly place and scale multiple data sets.
Also fix flows to reduce resets of animations. More work toward removing
Cg dependency. Fix panning to convert viewport coords to world coords.

  • 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 "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 scaleVectorField();
86
87    bool visible()
88    {
89        return !_sv.isHidden;
90    }
91
92    const char *name() const
93    {
94        return _name.c_str();
95    }
96
97    bool isDataLoaded()
98    {
99        return (_data != NULL);
100    }
101
102    Rappture::Unirect3d *data()
103    {
104        return _data;
105    }
106
107    void data(Rappture::Unirect3d *data)
108    {
109        if (_data != NULL) {
110            delete _data;
111        }
112        _data = data;
113    }
114
115    FlowSliceAxis getAxis()
116    {
117        return _sv.slicePos.axis;
118    }
119
120    TransferFunction *getTransferFunction()
121    {
122        return _sv.transferFunction;
123    }
124#if 0
125    void setAxis(FlowSliceAxis axis)
126    {
127        _sv.slicePos.axis = axis;
128        if (NanoVis::licRenderer != NULL) {
129            NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis);
130        }
131        if (NanoVis::velocityArrowsSlice != NULL) {
132            NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis);
133        }
134    }
135
136    void setCurrentPosition(float position)
137    {
138        _sv.slicePos.value = position;
139        if (NanoVis::licRenderer != NULL) {
140            NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value);
141        }
142        if (NanoVis::velocityArrowsSlice != NULL) {
143            NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value);
144        }
145    }
146
147    void setLICActive(bool state)
148    {
149        _sv.sliceVisible = state;
150        if (NanoVis::licRenderer != NULL) {
151            NanoVis::licRenderer->setVectorField(_volume);
152            NanoVis::licRenderer->setSliceAxis(_sv.slicePos.axis);
153            NanoVis::licRenderer->setSlicePosition(_sv.slicePos.value);
154            NanoVis::licRenderer->visible(state);
155        }
156    }
157
158    void setArrowsActive(bool state)
159        _sv.showArrows = state;
160        if (NanoVis::velocityArrowsSlice != NULL) {
161            NanoVis::velocityArrowsSlice->setVectorField(_volume);
162            NanoVis::velocityArrowsSlice->setSliceAxis(_sv.slicePos.axis);
163            NanoVis::velocityArrowsSlice->setSlicePosition(_sv.slicePos.value);
164            NanoVis::velocityArrowsSlice->visible(_sv.showArrows);
165        }
166    }
167#endif
168    const Volume *getVolume() const
169    {
170        return _volume;
171    }
172
173    int parseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
174    {
175        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
176                                    SWITCH_DEFAULTS) < 0) {
177            return TCL_ERROR;
178        }
179        return TCL_OK;
180    }
181
182    bool configure();
183
184    Tcl_Command getCommandToken()
185    {
186        return _cmdToken;
187    }
188
189    float getRelativePosition(FlowPosition *pos);
190
191    static bool updatePending;
192    static double magMin, magMax;
193
194private:
195    typedef std::string ParticlesId;
196    typedef std::string BoxId;
197    typedef std::tr1::unordered_map<ParticlesId, FlowParticles *> ParticlesHashmap;
198    typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap;
199
200    float *getScaledVector();
201
202    Volume *makeVolume(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     * Uniform rectangular data
222     * representing the mesh and vector
223     * field values.  These values are
224     * kept to regenerate the volume
225     * associated with the flow. */
226    Rappture::Unirect3d *_data;
227
228    /**
229     * The volume associated with the
230     * flow.  This isn't the same thing as
231     * a normal volume displayed. */
232    Volume *_volume;
233
234    /**
235     * For each field there can be one or
236     * more particle injection planes
237     * where the particles are injected
238     * into the flow. */
239    ParticlesHashmap _particlesTable;
240
241    /**
242     * A table of boxes.  There maybe
243     * zero or more boxes associated
244     * with each field. */
245    BoxHashmap _boxTable;
246
247    FlowValues _sv;
248
249    static Rappture::SwitchSpec _switches[];
250};
251
252}
253
254#endif
Note: See TracBrowser for help on using the repository browser.