source: nanovis/trunk/Flow.h @ 5587

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

Some fixes from release branch

  • Property svn:eol-style set to native
File size: 6.0 KB
RevLine 
[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 */
[3613]11#ifndef NV_FLOW_H
12#define NV_FLOW_H
[3597]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"
[3611]26#include "LIC.h"
[3630]27#include "VelocityArrowsSlice.h"
[3597]28#include "Unirect.h"
29#include "Volume.h"
30#include "TransferFunction.h"
31
[3611]32namespace nv {
33
[3597]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    {
[3935]97        return (_volume != NULL);
[3597]98    }
99
[3935]100    void getVectorRange(double range[])
[3597]101    {
[3935]102        range[0] = _volume->wAxis.min();
103        range[1] = _volume->wAxis.max();
[3597]104    }
105
[4056]106    void data(Unirect3d *unirect)
[3597]107    {
[3935]108        float *vdata = getScaledVector(unirect);
109        _volume = makeVolume(unirect, vdata);
110        delete [] vdata;
[3936]111        delete unirect;
[3935]112        initVolume();
113        scaleVectorField();
[3597]114    }
115
[3935]116    void data(Volume *volume)
117    {
118        _volume = volume;
119        initVolume();
120        scaleVectorField();
121    }
122
[5587]123    FlowSliceAxis getSliceAxis()
[3597]124    {
[3630]125        return _sv.slicePos.axis;
[3597]126    }
127
128    TransferFunction *getTransferFunction()
129    {
130        return _sv.transferFunction;
131    }
[3630]132#if 0
[4899]133    void setSliceAxis(FlowSliceAxis axis)
[3597]134    {
135        _sv.slicePos.axis = axis;
[3630]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        }
[3597]142    }
143
144    void setCurrentPosition(float position)
145    {
146        _sv.slicePos.value = position;
[3630]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        }
[3597]153    }
154
[3630]155    void setLICActive(bool state)
[3597]156    {
157        _sv.sliceVisible = state;
[3630]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        }
[3597]164    }
165
[3630]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        }
[3597]174    }
[3630]175#endif
[3597]176    const Volume *getVolume() const
177    {
178        return _volume;
179    }
180
181    int parseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
182    {
[4056]183        if (nv::ParseSwitches(interp, _switches, objc, objv, &_sv,
184                              SWITCH_DEFAULTS) < 0) {
[3597]185            return TCL_ERROR;
186        }
187        return TCL_OK;
188    }
189
[3630]190    bool configure();
191
[3597]192    Tcl_Command getCommandToken()
193    {
194        return _cmdToken;
195    }
196
[3630]197    float getRelativePosition(FlowPosition *pos);
[3597]198
[3630]199    static bool updatePending;
200    static double magMin, magMax;
201
[3597]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
[3935]208    void initVolume();
[3597]209
[3935]210    bool scaleVectorField();
[3630]211
[4056]212    float *getScaledVector(Unirect3d *unirect);
[3935]213
[4056]214    Volume *makeVolume(Unirect3d *unirect, float *data);
[3935]215
[3597]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
[4056]253    static SwitchSpec _switches[];
[3597]254};
255
[3611]256}
257
[3597]258#endif
Note: See TracBrowser for help on using the repository browser.