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 | |
---|
19 | namespace nv { |
---|
20 | |
---|
21 | class Unirect2d; |
---|
22 | |
---|
23 | class Unirect3d |
---|
24 | { |
---|
25 | public: |
---|
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 | #ifdef USE_DX_READER |
---|
226 | bool importDx(size_t nComponents, size_t length, char *string); |
---|
227 | #endif |
---|
228 | |
---|
229 | bool convert(Unirect2d *dataPtr); |
---|
230 | |
---|
231 | bool isInitialized() |
---|
232 | { |
---|
233 | return _initialized; |
---|
234 | } |
---|
235 | |
---|
236 | private: |
---|
237 | void getVectorRange(); |
---|
238 | |
---|
239 | size_t _xNum, _yNum, _zNum; |
---|
240 | size_t _nValues; |
---|
241 | size_t _nComponents; |
---|
242 | float _xMin, _xMax, _yMin, _yMax, _zMin, _zMax; |
---|
243 | float _xValueMin, _xValueMax; |
---|
244 | float _yValueMin, _yValueMax; |
---|
245 | float _zValueMin, _zValueMax; |
---|
246 | double _magMin, _magMax; /* Range of magnitudes of vector |
---|
247 | * data. */ |
---|
248 | char *_xUnits; |
---|
249 | char *_yUnits; |
---|
250 | char *_zUnits; |
---|
251 | char *_vUnits; |
---|
252 | |
---|
253 | float *_values; |
---|
254 | bool _initialized; |
---|
255 | }; |
---|
256 | |
---|
257 | class Unirect2d |
---|
258 | { |
---|
259 | public: |
---|
260 | Unirect2d(size_t nComponents = 1) : |
---|
261 | _xNum(0), _yNum(0), |
---|
262 | _nValues(0), |
---|
263 | _nComponents(nComponents), |
---|
264 | _xUnits(NULL), _yUnits(NULL), _vUnits(NULL), |
---|
265 | _values(NULL), |
---|
266 | _initialized(false) |
---|
267 | { |
---|
268 | } |
---|
269 | |
---|
270 | ~Unirect2d() |
---|
271 | { |
---|
272 | if (_values != NULL) { |
---|
273 | free(_values); |
---|
274 | } |
---|
275 | if (_xUnits != NULL) { |
---|
276 | free(_xUnits); |
---|
277 | } |
---|
278 | if (_yUnits != NULL) { |
---|
279 | free(_yUnits); |
---|
280 | } |
---|
281 | if (_vUnits != NULL) { |
---|
282 | free(_vUnits); |
---|
283 | } |
---|
284 | } |
---|
285 | |
---|
286 | size_t xNum() |
---|
287 | { |
---|
288 | return _xNum; |
---|
289 | } |
---|
290 | |
---|
291 | size_t yNum() |
---|
292 | { |
---|
293 | return _yNum; |
---|
294 | } |
---|
295 | |
---|
296 | float xMin() |
---|
297 | { |
---|
298 | return _xMin; |
---|
299 | } |
---|
300 | |
---|
301 | float yMin() |
---|
302 | { |
---|
303 | return _yMin; |
---|
304 | } |
---|
305 | |
---|
306 | float xMax() |
---|
307 | { |
---|
308 | return _xMax; |
---|
309 | } |
---|
310 | |
---|
311 | float yMax() |
---|
312 | { |
---|
313 | return _yMax; |
---|
314 | } |
---|
315 | |
---|
316 | const char *xUnits() |
---|
317 | { |
---|
318 | return _xUnits; |
---|
319 | } |
---|
320 | |
---|
321 | const char *yUnits() |
---|
322 | { |
---|
323 | return _yUnits; |
---|
324 | } |
---|
325 | |
---|
326 | const char *vUnits() |
---|
327 | { |
---|
328 | return _vUnits; |
---|
329 | } |
---|
330 | |
---|
331 | float *values() |
---|
332 | { |
---|
333 | return _values; |
---|
334 | } |
---|
335 | |
---|
336 | float xValueMin() |
---|
337 | { |
---|
338 | return _xValueMin; |
---|
339 | } |
---|
340 | |
---|
341 | float yValueMin() |
---|
342 | { |
---|
343 | return _yValueMin; |
---|
344 | } |
---|
345 | |
---|
346 | float xValueMax() |
---|
347 | { |
---|
348 | return _xValueMax; |
---|
349 | } |
---|
350 | |
---|
351 | float yValueMax() |
---|
352 | { |
---|
353 | return _yValueMax; |
---|
354 | } |
---|
355 | |
---|
356 | size_t nComponents() |
---|
357 | { |
---|
358 | return _nComponents; |
---|
359 | } |
---|
360 | |
---|
361 | void getBounds(vrmath::Vector3f& bboxMin, |
---|
362 | vrmath::Vector3f& bboxMax) const |
---|
363 | { |
---|
364 | bboxMin.set(_xMin, _yMin, 0); |
---|
365 | bboxMax.set(_xMax, _yMax, 0); |
---|
366 | } |
---|
367 | |
---|
368 | float *transferValues() |
---|
369 | { |
---|
370 | float *values; |
---|
371 | values = _values; |
---|
372 | _values = NULL; |
---|
373 | _nValues = 0; |
---|
374 | return values; |
---|
375 | } |
---|
376 | |
---|
377 | size_t nValues() |
---|
378 | { |
---|
379 | return _nValues; |
---|
380 | } |
---|
381 | |
---|
382 | int loadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv); |
---|
383 | |
---|
384 | int parseBuffer(Tcl_Interp *interp, const char *bytes, size_t len); |
---|
385 | |
---|
386 | bool isInitialized() |
---|
387 | { |
---|
388 | return _initialized; |
---|
389 | } |
---|
390 | |
---|
391 | private: |
---|
392 | size_t _xNum, _yNum; |
---|
393 | size_t _nValues; |
---|
394 | size_t _nComponents; |
---|
395 | |
---|
396 | float _xMin, _xMax; |
---|
397 | float _yMin, _yMax; |
---|
398 | float _xValueMin, _xValueMax; |
---|
399 | float _yValueMin, _yValueMax; |
---|
400 | |
---|
401 | char *_xUnits; |
---|
402 | char *_yUnits; |
---|
403 | char *_vUnits; |
---|
404 | |
---|
405 | float *_values; |
---|
406 | bool _initialized; |
---|
407 | }; |
---|
408 | |
---|
409 | } |
---|
410 | |
---|
411 | #endif |
---|