source: nanovis/branches/1.1/Unirect.h @ 4883

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

some cleanups

  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2004-2013  HUBzero Foundation, LLC
4 *
5 * Author: George A. Howlett <gah@purdue.edu>
6 */
7#ifndef UNIRECT_H
8#define UNIRECT_H
9
10#include <float.h>
11
12#include <tcl.h>
13
14#include <rappture.h>
15
16#include "Trace.h"
17
18namespace Rappture {
19
20class Unirect2d;
21
22class Unirect3d
23{
24public:
25    Unirect3d(float xMin, float xMax, size_t xNum,
26              float yMin, float yMax, size_t yNum,
27              float zMin, float zMax, size_t zNum,
28              size_t nValues, float *values, size_t nComponents) :
29        _xNum(xNum), _yNum(yNum), _zNum(zNum),
30        _nValues(nValues),
31        _nComponents(nComponents),
32        _xMin(xMin), _xMax(xMax),
33        _yMin(yMin), _yMax(yMax),
34        _zMin(zMin), _zMax(zMax),
35        _xValueMin(FLT_MAX), _xValueMax(-FLT_MAX),
36        _yValueMin(FLT_MAX), _yValueMax(-FLT_MAX),
37        _zValueMin(FLT_MAX), _zValueMax(-FLT_MAX),
38        _magMin(DBL_MAX), _magMax(-DBL_MAX),
39        _xUnits(NULL), _yUnits(NULL), _zUnits(NULL), _vUnits(NULL),
40        _values(NULL),
41        _initialized(false)
42    {
43        _initialized = true;
44    }
45
46    Unirect3d(size_t nComponents = 1) :
47        _nValues(0),
48        _nComponents(nComponents),
49        _xValueMin(FLT_MAX), _xValueMax(-FLT_MAX),
50        _yValueMin(FLT_MAX), _yValueMax(-FLT_MAX),
51        _zValueMin(FLT_MAX), _zValueMax(-FLT_MAX),
52        _magMin(DBL_MAX), _magMax(-DBL_MAX),
53        _xUnits(NULL), _yUnits(NULL), _zUnits(NULL), _vUnits(NULL),
54        _values(NULL),
55        _initialized(false)
56    {
57        _nComponents = nComponents;
58    }
59
60    ~Unirect3d()
61    {
62        if (_values != NULL) {
63            free(_values);
64        }
65        if (_xUnits != NULL) {
66            free(_xUnits);
67        }
68        if (_yUnits != NULL) {
69            free(_yUnits);
70        }
71        if (_zUnits != NULL) {
72            free(_zUnits);
73        }
74        if (_vUnits != NULL) {
75            free(_vUnits);
76        }
77    }
78
79    size_t xNum()
80    {
81        return _xNum;
82    }
83
84    size_t yNum()
85    {
86        return _yNum;
87    }
88
89    size_t zNum()
90    {
91        return _zNum;
92    }
93
94    float xMin()
95    {
96        return _xMin;
97    }
98
99    float yMin()
100    {
101        return _yMin;
102    }
103
104    float zMin()
105    {
106        return _zMin;
107    }
108
109    float xMax()
110    {
111        return _xMax;
112    }
113
114    float yMax()
115    {
116        return _yMax;
117    }
118
119    float zMax()
120    {
121        return _zMax;
122    }
123
124    float xValueMin()
125    {
126        return _xValueMin;
127    }
128
129    float yValueMin()
130    {
131        return _yValueMin;
132    }
133
134    float zValueMin()
135    {
136        return _zValueMin;
137    }
138
139    float xValueMax()
140    {
141        return _xValueMax;
142    }
143
144    float yValueMax()
145    {
146        return _yValueMax;
147    }
148
149    float zValueMax()
150    {
151        return _zValueMax;
152    }
153
154    size_t nComponents()
155    {
156        return _nComponents;
157    }
158
159    const char *xUnits()
160    {
161        return _xUnits;
162    }
163
164    const char *yUnits()
165    {
166        return _yUnits;
167    }
168    const char *zUnits()
169    {
170        return _zUnits;
171    }
172
173    const char *vUnits()
174    {
175        return _vUnits;
176    }
177
178    const float *values()
179    {
180        return _values;
181    }
182
183    double magMin()
184    {
185        if (_magMin == DBL_MAX) {
186            getVectorRange();
187        }
188        return _magMin;
189    }
190
191    double magMax()
192    {
193        if (_magMax == -DBL_MAX) {
194            getVectorRange();
195        }
196        return _magMax;
197    }
198
199    const float *SaveValues()
200    {
201        float *values;
202        values = _values;
203        _values = NULL;
204        _nValues = 0;
205        return values;
206    }
207
208    size_t nValues()
209    {
210        return _nValues;
211    }
212
213    int loadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
214
215    int parseBuffer(Tcl_Interp *interp, Rappture::Buffer &buf);
216
217    bool importDx(Rappture::Outcome &result, size_t nComponents,
218                  size_t length, char *string);
219
220    bool convert(Unirect2d *dataPtr);
221
222    bool resample(Rappture::Outcome &context, size_t nSamples = 30);
223
224    bool isInitialized()
225    {
226        return _initialized;
227    }
228
229private:
230    void getVectorRange();
231
232    size_t _xNum, _yNum, _zNum;
233    size_t _nValues;
234    size_t _nComponents;
235    float _xMin, _xMax, _yMin, _yMax, _zMin, _zMax;
236    float _xValueMin, _xValueMax;
237    float _yValueMin, _yValueMax;
238    float _zValueMin, _zValueMax;
239    double _magMin, _magMax;                /* Range of magnitudes of vector
240                                         * data. */
241    char *_xUnits;
242    char *_yUnits;
243    char *_zUnits;
244    char *_vUnits;
245
246    float *_values;
247    bool _initialized;
248};
249
250class Unirect2d
251{
252public:
253    Unirect2d(size_t nComponents = 1) :
254        _xNum(0), _yNum(0),
255        _nValues(0),
256        _nComponents(nComponents),
257        _xUnits(NULL), _yUnits(NULL), _vUnits(NULL),
258        _values(NULL),
259        _initialized(false)
260    {
261    }
262
263    ~Unirect2d()
264    {
265        if (_values != NULL) {
266            free(_values);
267        }
268        if (_xUnits != NULL) {
269            free(_xUnits);
270        }
271        if (_yUnits != NULL) {
272            free(_yUnits);
273        }
274        if (_vUnits != NULL) {
275            free(_vUnits);
276        }
277    }
278
279    size_t xNum()
280    {
281        return _xNum;
282    }
283
284    size_t yNum()
285    {
286        return _yNum;
287    }
288
289    float xMin()
290    {
291        return _xMin;
292    }
293
294    float yMin()
295    {
296        return _yMin;
297    }
298
299    float xMax()
300    {
301        return _xMax;
302    }
303
304    float yMax()
305    {
306        return _yMax;
307    }
308
309    const char *xUnits()
310    {
311        return _xUnits;
312    }
313
314    const char *yUnits()
315    {
316        return _yUnits;
317    }
318
319    const char *vUnits()
320    {
321        return _vUnits;
322    }
323
324    float *values()
325    {
326        return _values;
327    }
328
329    float xValueMin()
330    {
331        return _xValueMin;
332    }
333
334    float yValueMin()
335    {
336        return _yValueMin;
337    }
338
339    float xValueMax()
340    {
341        return _xValueMax;
342    }
343
344    float yValueMax()
345    {
346        return _yValueMax;
347    }
348
349    size_t nComponents()
350    {
351        return _nComponents;
352    }
353
354    float *transferValues()
355    {
356        float *values;
357        values = _values;
358        _values = NULL;
359        _nValues = 0;
360        return values;
361    }
362
363    size_t nValues()
364    {
365        return _nValues;
366    }
367
368    int loadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
369
370    int parseBuffer(Tcl_Interp *interp, Rappture::Buffer &buf);
371
372    bool isInitialized()
373    {
374        return _initialized;
375    }
376
377private:
378    size_t _xNum, _yNum;
379    size_t _nValues;
380    size_t _nComponents;
381
382    float _xMin, _xMax;
383    float _yMin, _yMax;
384    float _xValueMin, _xValueMax;
385    float _yValueMin, _yValueMax;
386
387    char *_xUnits;
388    char *_yUnits;
389    char *_vUnits;
390
391    float *_values;
392    bool _initialized;
393};
394
395}
396
397#endif
Note: See TracBrowser for help on using the repository browser.