source: trunk/packages/vizservers/nanovis/FlowCmd.h @ 2730

Last change on this file since 2730 was 2096, checked in by ldelgass, 13 years ago

Normalize line endings, set eol-style to native on *.cpp, *.h files

  • Property svn:eol-style set to native
File size: 9.1 KB
Line 
1
2/*
3 * ----------------------------------------------------------------------
4 * FlowCmd.h
5 *
6 *      This modules creates the Tcl interface to the nanovis server.  The
7 *      communication protocol of the server is the Tcl language.  Commands
8 *      given to the server by clients are executed in a safe interpreter and
9 *      the resulting image rendered offscreen is returned as BMP-formatted
10 *      image data.
11 *
12 * ======================================================================
13 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
14 *           Insoo Woo <iwoo@purdue.edu>
15 *           Michael McLennan <mmclennan@purdue.edu>
16 *           Purdue Rendering and Perceptualization Lab (PURPL)
17 *
18 *  Copyright (c) 2004-2006  Purdue Research Foundation
19 *
20 *  See the file "license.terms" for information on usage and
21 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
22 * ======================================================================
23 */
24
25struct FlowColor {
26    float r, g, b, a;
27};
28
29struct FlowPosition {
30    float value;
31    unsigned int flags;
32    int axis;
33};
34
35struct FlowPoint {
36    float x, y, z;
37};
38
39struct FlowParticlesValues {
40    FlowPosition position;              /* Position on axis of particle
41                                         * plane */
42    FlowColor color;                    /* Color of particles */
43    int isHidden;                       /* Indicates if particle injection
44                                         * plane is active or not. */
45    float particleSize;                 /* Size of the particles. */
46};
47
48struct FlowParticlesIterator {
49    Tcl_HashEntry *hashPtr;
50    Tcl_HashSearch hashSearch;
51};
52
53class FlowParticles {
54    const char *_name;                  /* Name of particle injection
55                                         * plane. Actual character string is
56                                         * stored in hash table. */
57    Tcl_HashEntry *_hashPtr;
58    NvParticleRenderer *_rendererPtr;   /* Particle renderer. */
59    FlowParticlesValues _sv;
60
61    static Rappture::SwitchSpec _switches[];
62public:
63
64    FlowParticles(const char *name, Tcl_HashEntry *hPtr);
65    ~FlowParticles(void);
66    const char *name(void) {
67        return _name;
68    }
69    void disconnect(void) {
70        _hashPtr = NULL;
71    }
72    bool visible(void) {
73        return !_sv.isHidden;
74    }
75    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) {
76        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
77                SWITCH_DEFAULTS) < 0) {
78            return TCL_ERROR;
79        }
80        return TCL_OK;
81    }
82    void Advect(void) {
83        assert(_rendererPtr->active());
84        _rendererPtr->advect();
85    }
86    void Render(void);
87    void Reset(void) {
88        _rendererPtr->reset();
89    }
90    void Initialize(void) {
91        _rendererPtr->initialize();
92    }
93    void SetVectorField(Volume *volPtr) {
94        _rendererPtr->setVectorField(volPtr->id,
95            volPtr->location(),
96            1.0f,
97            volPtr->height / (float)volPtr->width,
98            volPtr->depth  / (float)volPtr->width,
99            volPtr->wAxis.max());
100    }
101    void Configure(void);
102};
103
104struct FlowBoxIterator {
105    Tcl_HashEntry *hashPtr;
106    Tcl_HashSearch hashSearch;
107};
108
109struct FlowBoxValues {
110    float position;                     /* Position on axis of particle
111                                         * plane */
112    FlowPoint corner1, corner2;         /* Coordinates of the box. */
113   
114    FlowColor color;                    /* Color of particles */
115    float lineWidth;
116    int isHidden;                       /* Indicates if particle injection
117                                         * plance is active or not. */
118};
119
120class FlowBox {
121    const char *_name;                  /* Name of this box in the hash
122                                         * table. */
123    Tcl_HashEntry *_hashPtr;            /* Pointer to this entry in the hash
124                                         * table of boxes. */
125    FlowBoxValues _sv;
126    static Rappture::SwitchSpec _switches[];
127public:
128
129    FlowBox(const char *name, Tcl_HashEntry *hPtr);
130    ~FlowBox(void) {
131        Rappture::FreeSwitches(_switches, &_sv, 0);
132        if (_hashPtr != NULL) {
133            Tcl_DeleteHashEntry(_hashPtr);
134        }
135    }
136    const char *name(void) {
137        return _name;
138    }
139    bool visible(void) {
140        return !_sv.isHidden;
141    }
142    void disconnect(void) {
143        _hashPtr = NULL;
144    }
145    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) {
146        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
147                SWITCH_DEFAULTS) < 0) {
148            return TCL_ERROR;
149        }
150        return TCL_OK;
151    }
152    void Render(Volume *volPtr);
153};
154
155struct FlowValues {
156    TransferFunction *tfPtr;
157    FlowPosition slicePos;
158    int showArrows;
159    int sliceVisible;
160    int showVolume;
161    int showOutline;
162    int isHidden;
163    /* The following are settings for the volume.*/
164    float diffuse;
165    float specular;
166    float opacity;
167};
168
169struct FlowIterator {
170    Tcl_HashEntry *hashPtr;
171    Tcl_HashSearch hashSearch;
172};
173
174class FlowCmd {
175    Tcl_Interp *_interp;
176    Tcl_HashEntry *_hashPtr;
177    const char *_name;                  /* Name of the flow.  This may differ
178                                         * from the name of the command
179                                         * associated with the flow, if the
180                                         * command was renamed. */
181    Tcl_Command _cmdToken;              /* Command associated with the flow.
182                                         * When the command is deleted, so is
183                                         * the flow. */
184    Rappture::Unirect3d *_dataPtr;      /* Uniform rectangular data
185                                         * representing the mesh and vector
186                                         * field values.  These values are
187                                         * kept to regenerate the volume
188                                         * associated with the flow. */
189    Volume *_volPtr;                    /* The volume associated with the
190                                         * flow.  This isn't the same thing as
191                                         * a normal volume displayed. */
192
193    NvVectorField *_fieldPtr;           /* Vector field generated from the
194                                         * above volume. */
195
196    Tcl_HashTable _particlesTable;      /* For each field there can be one or
197                                         * more particle injection planes
198                                         * where the particles are injected
199                                         * into the flow. */
200
201    Tcl_HashTable _boxTable;            /* A table of boxes.  There maybe
202                                         * zero or more boxes associated
203                                         * with each field. */
204
205    void Configure(void);
206
207    static Rappture::SwitchSpec _switches[];
208    FlowValues _sv;
209
210    void RenderBoxes(void);
211public:
212    static Rappture::SwitchSpec videoSwitches[];
213    enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z };
214    FlowCmd(Tcl_Interp *interp, const char *name, Tcl_HashEntry *hPtr);
215    ~FlowCmd(void);
216
217    int CreateParticles(Tcl_Interp *interp, Tcl_Obj *objPtr);
218    int GetParticles(Tcl_Interp *interp, Tcl_Obj *objPtr,
219                     FlowParticles **particlePtrPtr);
220    void Render(void);
221    void Advect(void);
222    void ResetParticles(void);
223    void InitializeParticles(void);
224
225    FlowParticles *FirstParticles(FlowParticlesIterator *iterPtr);
226    FlowParticles *NextParticles(FlowParticlesIterator *iterPtr);
227
228    int CreateBox(Tcl_Interp *interp, Tcl_Obj *objPtr);
229    int GetBox(Tcl_Interp *interp, Tcl_Obj *objPtr, FlowBox **boxPtrPtr);
230    FlowBox *FirstBox(FlowBoxIterator *iterPtr);
231    FlowBox *NextBox(FlowBoxIterator *iterPtr);
232
233    float *GetScaledVector(void);
234    Volume *MakeVolume(float *data);
235   
236    void InitVectorField(void);
237
238    NvVectorField *VectorField(void) {
239        return _fieldPtr;
240    }
241
242    bool ScaleVectorField(void);
243
244    bool visible(void) {
245        return !_sv.isHidden;
246    }
247    const char *name(void) {
248        return _name;
249    }
250    void disconnect(void) {
251        _hashPtr = NULL;
252    }
253    bool isDataLoaded(void) {
254        return (_dataPtr != NULL);
255    }
256    Rappture::Unirect3d *data(void) {
257        return _dataPtr;
258    }
259    void data(Rappture::Unirect3d *dataPtr) {
260        if (_dataPtr != NULL) {
261            delete _dataPtr;
262        }
263        _dataPtr = dataPtr;
264    }
265    void ActivateSlice(void) {
266        /* Must set axis before offset or position goes to wrong axis. */
267        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
268        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
269        NanoVis::licRenderer->active(true);
270    }
271    void DeactivateSlice(void) {
272        NanoVis::licRenderer->active(false);
273    }
274    SliceAxis GetAxis(void) {
275        return (SliceAxis)_sv.slicePos.axis;
276    }
277    TransferFunction *GetTransferFunction(void) {
278        return _sv.tfPtr;
279    }
280    float GetRelativePosition(void);
281    void SetAxis(void) {
282        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
283    }
284    void SetAxis(FlowCmd::SliceAxis axis) {
285        _sv.slicePos.axis = axis;
286        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
287    }
288    void SetCurrentPosition(float position) {
289        _sv.slicePos.value = position;
290        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
291    }
292    void SetCurrentPosition(void) {
293        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
294    }
295    void SetActive(bool state) {
296        _sv.sliceVisible = state;
297        NanoVis::licRenderer->active(state);
298    }
299    void SetActive(void) {
300        NanoVis::licRenderer->active(_sv.sliceVisible);
301    }
302    void SetVectorField(NvVectorField *fieldPtr) {
303        DeleteVectorField();
304        _fieldPtr = fieldPtr;
305    }
306    void DeleteVectorField(void) {
307        if (_fieldPtr != NULL) {
308            delete _fieldPtr;
309            _fieldPtr = NULL;
310        }
311    }
312    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) {
313        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
314                SWITCH_DEFAULTS) < 0) {
315            return TCL_ERROR;
316        }
317        return TCL_OK;
318    }
319    static float GetRelativePosition(FlowPosition *posPtr);
320};
321
322extern int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes);
323
324extern int GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
325        bool *boolPtr);
326extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
327        float *floatPtr);
328extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
329        int *axisPtr);
330extern int GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
331        Volume **volumePtrPtr);
332
333
Note: See TracBrowser for help on using the repository browser.