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

Last change on this file since 1431 was 1431, checked in by gah, 15 years ago

fixup new flow visualization command structure

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