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