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

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

Found memory leak in reset_patterns

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