Changeset 3574 for trunk/packages/vizservers/nanovis
- Timestamp:
- Mar 25, 2013 1:17:55 PM (11 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/ReaderCommon.cpp
r3502 r3574 31 31 32 32 void 33 normalizeScalar(float * fdata, int count, float min, floatmax)33 normalizeScalar(float *data, int count, int stride, double vmin, double vmax) 34 34 { 35 float v = max - min; 36 if (v != 0.0f) { 37 for (int i = 0; i < count; ++i) { 38 if (fdata[i] != -1.0) { 39 fdata[i] = (fdata[i] - min)/ v; 40 } 35 double dv = vmax - vmin; 36 dv = (dv == 0.0) ? 1.0 : 0.0; 37 for (int pt = 0, i = 0; pt < count; ++pt, i += stride) { 38 double v = data[i]; 39 if (isnan(v)) { 40 data[i] = -1.0f; 41 } else if (data[i] >= min) { 42 data[i] = (float)((v - vmin)/ dv); 41 43 } 42 44 } … … 48 50 * This technique is fairly expensive in terms of memory and 49 51 * running time due to the filter extent. 52 * 53 * \param data Data array with X the fastest running, stride of 54 * 1 float 55 * \param nx number of values in X direction 56 * \param ny number of values in Y direction 57 * \param nz number of values in Z direction 58 * \param dx Size of voxels in X direction 59 * \param dy Size of voxels in Y direction 60 * \param dz Size of voxels in Z direction 61 * \param min Minimum value in data 62 * \param max Maximum value in data 63 * \return Returns a float array with stride of 4 floats 64 * containing the normalized scalar and the x,y,z components of 65 * the (normalized) gradient vector 50 66 */ 51 67 float * 52 computeGradient(float * fdata,53 int width, int height, int depth,68 computeGradient(float *data, 69 int nx, int ny, int nz, 54 70 float dx, float dy, float dz, 55 71 float min, float max) 56 72 { 57 float *gradients = (float *)malloc(width * height * depth * 3 * 58 sizeof(float)); 59 float *tempGradients = (float *)malloc(width * height * depth * 3 * 60 sizeof(float)); 61 int sizes[3] = { width, height, depth }; 73 int npts = nx * ny * nz; 74 float *gradients = (float *)malloc(npts * 3 * sizeof(float)); 75 float *tempGradients = (float *)malloc(npts * 3 * sizeof(float)); 76 int sizes[3] = { nx, ny, nz }; 62 77 float spacing[3] = { dx, dy, dz }; 63 computeGradients(tempGradients, fdata, sizes, spacing, DATRAW_FLOAT);78 computeGradients(tempGradients, data, sizes, spacing, DATRAW_FLOAT); 64 79 filterGradients(tempGradients, sizes); 65 80 quantizeGradients(tempGradients, gradients, sizes, DATRAW_FLOAT); 66 81 free(tempGradients); 67 normalizeScalar( fdata, width * height * depth, min, max);68 float *data = merge(fdata, gradients, width * height * depth);82 normalizeScalar(data, npts, 1, min, max); 83 float *dataOut = merge(data, gradients, npts); 69 84 free(gradients); 70 return data ;85 return dataOut; 71 86 } 72 87 … … 92 107 */ 93 108 void 94 computeSimpleGradient(float *data, int nx, int ny, int nz, 109 computeSimpleGradient(float *data, 110 int nx, int ny, int nz, 95 111 float dx, float dy, float dz) 96 112 { -
trunk/packages/vizservers/nanovis/ReaderCommon.h
r3502 r3574 11 11 12 12 extern void 13 normalizeScalar(float * fdata, int count, float min, floatmax);13 normalizeScalar(float *data, int count, int stride, double min, double max); 14 14 15 15 extern float * 16 computeGradient(float * fdata,17 int width, int height, int depth,16 computeGradient(float *data, 17 int nx, int ny, int nz, 18 18 float dx, float dy, float dz, 19 19 float min, float max); 20 20 21 21 extern void 22 computeSimpleGradient(float *data, int nx, int ny, int nz, 22 computeSimpleGradient(float *data, 23 int nx, int ny, int nz, 23 24 float dx = 1.0f, float dy = 1.0f, float dz = 1.0f); 24 25 -
trunk/packages/vizservers/nanovis/VtkReader.cpp
r3569 r3574 378 378 379 379 #ifndef DOWNSAMPLE_DATA 380 double dv = vmax - vmin; 381 if (dv == 0.0) { 382 dv = 1.0; 383 } 384 385 int ngen = 0; 386 const int step = 4; 387 for (int i = 0; i < npts; ++i) { 388 double v = data[ngen]; 389 // scale all values [0-1], -1 => out of bounds 390 v = (isnan(v)) ? -1.0 : (v - vmin)/dv; 391 392 data[ngen] = v; 393 ngen += step; 394 } 395 380 381 // scale all values [0-1], -1 => out of bounds 382 normalizeScalar(data, npts, 4, vmin, vmax); 396 383 computeSimpleGradient(data, nx, ny, nz, 397 384 dx, dy, dz); … … 453 440 } 454 441 #ifdef FILTER_GRADIENTS 455 // NOT normalized, -1 => out of bounds 456 v = (isnan(v)) ? -1.0 : v; 442 // NOT normalized, may have NaNs (FIXME: how does gradient filter handle NaN?) 457 443 cdata[ngen] = v; 458 444 #else // !FILTER_GRADIENTS -
trunk/packages/vizservers/nanovis/dxReader.cpp
r3502 r3574 288 288 289 289 // make sure that we read all of the expected points 290 if (nread != n x*ny*nz) {290 if (nread != npts) { 291 291 result.addError("inconsistent data: expected %d points" 292 " but found %d points", n x*ny*nz, nread);292 " but found %d points", npts, nread); 293 293 return NULL; 294 294 } 295 295 296 296 #ifndef DOWNSAMPLE_DATA 297 double dv = vmax - vmin; 298 if (dv == 0.0) { 299 dv = 1.0; 300 } 301 302 int ngen = 0; 303 const int step = 4; 304 for (int i = 0; i < nx*ny*nz; ++i) { 305 double v = data[ngen]; 306 // scale all values [0-1], -1 => out of bounds 307 v = (isnan(v)) ? -1.0 : (v - vmin)/dv; 308 309 data[ngen] = v; 310 ngen += step; 311 } 312 297 298 // scale all values [0-1], -1 => out of bounds 299 normalizeScalar(data, npts, 4, vmin, vmax); 313 300 computeSimpleGradient(data, nx, ny, nz, 314 301 dx, dy, dz); … … 370 357 } 371 358 #ifdef FILTER_GRADIENTS 372 // NOT normalized, -1 => out of bounds 373 v = (isnan(v)) ? -1.0 : v; 359 // NOT normalized, may have NaNs (FIXME: how does gradient filter handle NaN?) 374 360 cdata[ngen] = v; 375 361 #else // !FILTER_GRADIENTS … … 422 408 423 409 // make sure that we read all of the expected points 424 if (nread != n xy*nz) {410 if (nread != npts) { 425 411 result.addError("inconsistent data: expected %d points" 426 " but found %d points", n xy*nz, nread);412 " but found %d points", npts, nread); 427 413 return NULL; 428 414 }
Note: See TracChangeset
for help on using the changeset viewer.