source: nanovis/branches/1.1/Flow.h @ 4906

Last change on this file since 4906 was 4904, checked in by ldelgass, 5 years ago

Merge serveral changes from trunk. Does not include threading, world space
changes, etc.

  • 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
200private:
201    typedef std::string ParticlesId;
202    typedef std::string BoxId;
203    typedef std::tr1::unordered_map<ParticlesId, FlowParticles *> ParticlesHashmap;
204    typedef std::tr1::unordered_map<BoxId, FlowBox *> BoxHashmap;
205
206    void renderBoxes();
207
208    Tcl_Interp *_interp;
209    /**
210     * Name of the flow.  This may differ
211     * from the name of the command
212     * associated with the flow, if the
213     * command was renamed. */
214    std::string _name;
215
216    /**
217     * Command associated with the flow.
218     * When the command is deleted, so is
219     * the flow. */
220    Tcl_Command _cmdToken;
221
222    /**
223     * Uniform rectangular data
224     * representing the mesh and vector
225     * field values.  These values are
226     * kept to regenerate the volume
227     * associated with the flow. */
228    Unirect3d *_data;
229
230    /**
231     * The volume associated with the
232     * flow.  This isn't the same thing as
233     * a normal volume displayed. */
234    Volume *_volume;
235
236    /**
237     * For each field there can be one or
238     * more particle injection planes
239     * where the particles are injected
240     * into the flow. */
241    ParticlesHashmap _particlesTable;
242
243    /**
244     * A table of boxes.  There maybe
245     * zero or more boxes associated
246     * with each field. */
247    BoxHashmap _boxTable;
248
249    FlowValues _sv;
250
251    static SwitchSpec _switches[];
252};
253
254}
255
256#endif
Note: See TracBrowser for help on using the repository browser.