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

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

Refactor texture classes, misc. cleanups, cut down on header pollution -- still
need to fix header deps in Makefile.in

  • Property svn:eol-style set to native
File size: 10.1 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
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#ifndef FLOWCMD_H
25#define FLOWCMD_H
26
27#include <tcl.h>
28
29#include "Switch.h"
30#include "NvLIC.h"
31#include "NvParticleRenderer.h"
32#include "NvVectorField.h"
33#include "Unirect.h"
34#include "Volume.h"
35
36struct FlowColor {
37    float r, g, b, a;
38};
39
40struct FlowPosition {
41    float value;
42    unsigned int flags;
43    int axis;
44};
45
46struct FlowPoint {
47    float x, y, z;
48};
49
50struct FlowParticlesValues {
51    FlowPosition position;              /* Position on axis of particle
52                                         * plane */
53    FlowColor color;                    /* Color of particles */
54    int isHidden;                       /* Indicates if particle injection
55                                         * plane is active or not. */
56    float particleSize;                 /* Size of the particles. */
57};
58
59struct FlowParticlesIterator {
60    Tcl_HashEntry *hashPtr;
61    Tcl_HashSearch hashSearch;
62};
63
64class FlowParticles
65{
66public:
67    FlowParticles(const char *name, Tcl_HashEntry *hPtr);
68
69    ~FlowParticles();
70
71    const char *name()
72    {
73        return _name;
74    }
75
76    void disconnect()
77    {
78        _hashPtr = NULL;
79    }
80
81    bool visible()
82    {
83        return !_sv.isHidden;
84    }
85
86    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
87    {
88        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
89                                    SWITCH_DEFAULTS) < 0) {
90            return TCL_ERROR;
91        }
92        return TCL_OK;
93    }
94
95    void Advect()
96    {
97        assert(_rendererPtr->active());
98        _rendererPtr->advect();
99    }
100
101    void Render();
102
103    void Reset()
104    {
105        _rendererPtr->reset();
106    }
107
108    void Initialize()
109    {
110        _rendererPtr->initialize();
111    }
112
113    void SetVectorField(Volume *volPtr)
114    {
115        _rendererPtr->
116            setVectorField(volPtr->id,
117                           volPtr->location(),
118                           1.0f,
119                           volPtr->height / (float)volPtr->width,
120                           volPtr->depth  / (float)volPtr->width,
121                           volPtr->wAxis.max());
122    }
123
124    void Configure();
125
126private:
127    const char *_name;                  /* Name of particle injection
128                                         * plane. Actual character string is
129                                         * stored in hash table. */
130    Tcl_HashEntry *_hashPtr;
131    NvParticleRenderer *_rendererPtr;   /* Particle renderer. */
132    FlowParticlesValues _sv;
133
134    static Rappture::SwitchSpec _switches[];
135};
136
137struct FlowBoxIterator {
138    Tcl_HashEntry *hashPtr;
139    Tcl_HashSearch hashSearch;
140};
141
142struct FlowBoxValues {
143    float position;                     /* Position on axis of particle
144                                         * plane */
145    FlowPoint corner1, corner2;         /* Coordinates of the box. */
146   
147    FlowColor color;                    /* Color of particles */
148    float lineWidth;
149    int isHidden;                       /* Indicates if particle injection
150                                         * plance is active or not. */
151};
152
153class FlowBox
154{
155public:
156    FlowBox(const char *name, Tcl_HashEntry *hPtr);
157
158    ~FlowBox()
159    {
160        Rappture::FreeSwitches(_switches, &_sv, 0);
161        if (_hashPtr != NULL) {
162            Tcl_DeleteHashEntry(_hashPtr);
163        }
164    }
165
166    const char *name()
167    {
168        return _name;
169    }
170
171    bool visible()
172    {
173        return !_sv.isHidden;
174    }
175
176    void disconnect()
177    {
178        _hashPtr = NULL;
179    }
180
181    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
182    {
183        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
184                                    SWITCH_DEFAULTS) < 0) {
185            return TCL_ERROR;
186        }
187        return TCL_OK;
188    }
189
190    void Render(Volume *volPtr);
191
192private:
193    const char *_name;                  /* Name of this box in the hash
194                                         * table. */
195    Tcl_HashEntry *_hashPtr;            /* Pointer to this entry in the hash
196                                         * table of boxes. */
197    FlowBoxValues _sv;
198    static Rappture::SwitchSpec _switches[];
199
200};
201
202struct FlowValues {
203    TransferFunction *tfPtr;
204    FlowPosition slicePos;
205    int showArrows;
206    int sliceVisible;
207    int showVolume;
208    int showOutline;
209    int isHidden;
210    /* The following are settings for the volume.*/
211    float diffuse;
212    float specular;
213    float opacity;
214};
215
216struct FlowIterator {
217    Tcl_HashEntry *hashPtr;
218    Tcl_HashSearch hashSearch;
219};
220
221class FlowCmd
222{
223public:
224    enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z };
225
226    FlowCmd(Tcl_Interp *interp, const char *name, Tcl_HashEntry *hPtr);
227
228    ~FlowCmd();
229
230    int CreateParticles(Tcl_Interp *interp, Tcl_Obj *objPtr);
231
232    int GetParticles(Tcl_Interp *interp, Tcl_Obj *objPtr,
233                     FlowParticles **particlePtrPtr);
234
235    void Render();
236
237    void Advect();
238
239    void ResetParticles();
240
241    void InitializeParticles();
242
243    FlowParticles *FirstParticles(FlowParticlesIterator *iterPtr);
244
245    FlowParticles *NextParticles(FlowParticlesIterator *iterPtr);
246
247    int CreateBox(Tcl_Interp *interp, Tcl_Obj *objPtr);
248
249    int GetBox(Tcl_Interp *interp, Tcl_Obj *objPtr, FlowBox **boxPtrPtr);
250
251    FlowBox *FirstBox(FlowBoxIterator *iterPtr);
252
253    FlowBox *NextBox(FlowBoxIterator *iterPtr);
254
255    float *GetScaledVector();
256
257    Volume *MakeVolume(float *data);
258   
259    void InitVectorField();
260
261    NvVectorField *VectorField()
262    {
263        return _fieldPtr;
264    }
265
266    bool ScaleVectorField();
267
268    bool visible()
269    {
270        return !_sv.isHidden;
271    }
272
273    const char *name()
274    {
275        return _name;
276    }
277
278    void disconnect()
279    {
280        _hashPtr = NULL;
281    }
282
283    bool isDataLoaded()
284    {
285        return (_dataPtr != NULL);
286    }
287
288    Rappture::Unirect3d *data()
289    {
290        return _dataPtr;
291    }
292
293    void data(Rappture::Unirect3d *dataPtr)
294    {
295        if (_dataPtr != NULL) {
296            delete _dataPtr;
297        }
298        _dataPtr = dataPtr;
299    }
300
301    void ActivateSlice()
302    {
303        /* Must set axis before offset or position goes to wrong axis. */
304        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
305        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
306        NanoVis::licRenderer->active(true);
307    }
308
309    void DeactivateSlice()
310    {
311        NanoVis::licRenderer->active(false);
312    }
313
314    SliceAxis GetAxis()
315    {
316        return (SliceAxis)_sv.slicePos.axis;
317    }
318
319    TransferFunction *GetTransferFunction()
320    {
321        return _sv.tfPtr;
322    }
323
324    float GetRelativePosition();
325
326    void SetAxis()
327    {
328        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
329    }
330
331    void SetAxis(FlowCmd::SliceAxis axis)
332    {
333        _sv.slicePos.axis = axis;
334        NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
335    }
336
337    void SetCurrentPosition(float position)
338    {
339        _sv.slicePos.value = position;
340        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
341    }
342
343    void SetCurrentPosition()
344    {
345        NanoVis::licRenderer->set_offset(_sv.slicePos.value);
346    }
347
348    void SetActive(bool state)
349    {
350        _sv.sliceVisible = state;
351        NanoVis::licRenderer->active(state);
352    }
353
354    void SetActive()
355    {
356        NanoVis::licRenderer->active(_sv.sliceVisible);
357    }
358
359    void SetVectorField(NvVectorField *fieldPtr)
360    {
361        DeleteVectorField();
362        _fieldPtr = fieldPtr;
363    }
364
365    void DeleteVectorField()
366    {
367        if (_fieldPtr != NULL) {
368            delete _fieldPtr;
369            _fieldPtr = NULL;
370        }
371    }
372
373    int ParseSwitches(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
374    {
375        if (Rappture::ParseSwitches(interp, _switches, objc, objv, &_sv,
376                                    SWITCH_DEFAULTS) < 0) {
377            return TCL_ERROR;
378        }
379        return TCL_OK;
380    }
381
382    static float GetRelativePosition(FlowPosition *posPtr);
383
384    static Rappture::SwitchSpec videoSwitches[];
385
386private:
387    void Configure();
388
389    void RenderBoxes();
390
391    Tcl_Interp *_interp;
392    Tcl_HashEntry *_hashPtr;
393    const char *_name;                  /* Name of the flow.  This may differ
394                                         * from the name of the command
395                                         * associated with the flow, if the
396                                         * command was renamed. */
397    Tcl_Command _cmdToken;              /* Command associated with the flow.
398                                         * When the command is deleted, so is
399                                         * the flow. */
400    Rappture::Unirect3d *_dataPtr;      /* Uniform rectangular data
401                                         * representing the mesh and vector
402                                         * field values.  These values are
403                                         * kept to regenerate the volume
404                                         * associated with the flow. */
405    Volume *_volPtr;                    /* The volume associated with the
406                                         * flow.  This isn't the same thing as
407                                         * a normal volume displayed. */
408
409    NvVectorField *_fieldPtr;           /* Vector field generated from the
410                                         * above volume. */
411
412    Tcl_HashTable _particlesTable;      /* For each field there can be one or
413                                         * more particle injection planes
414                                         * where the particles are injected
415                                         * into the flow. */
416
417    Tcl_HashTable _boxTable;            /* A table of boxes.  There maybe
418                                         * zero or more boxes associated
419                                         * with each field. */
420
421    static Rappture::SwitchSpec _switches[];
422    FlowValues _sv;
423};
424
425extern int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes);
426
427extern int GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
428                             bool *boolPtr);
429
430extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
431                           float *floatPtr);
432
433extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
434                          int *axisPtr);
435
436extern int GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
437                            Volume **volumePtrPtr);
438
439#endif
Note: See TracBrowser for help on using the repository browser.