source: nanovis/branches/1.2/Unirect.h @ 5304

Last change on this file since 5304 was 4904, checked in by ldelgass, 9 years ago

Merge serveral changes from trunk. Does not include threading, world space
changes, etc.

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