Ignore:
Timestamp:
Mar 25, 2013 1:17:55 PM (11 years ago)
Author:
ldelgass
Message:

Use normalizeScalar common function where possible. Also, don't set NaNs? to
-1 in unnormalized data since -1 could be a valid data value. Need to make
sure gradient filtering properly handles NaNs?.

Location:
trunk/packages/vizservers/nanovis
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/ReaderCommon.cpp

    r3502 r3574  
    3131
    3232void
    33 normalizeScalar(float *fdata, int count, float min, float max)
     33normalizeScalar(float *data, int count, int stride, double vmin, double vmax)
    3434{
    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);
    4143        }
    4244    }
     
    4850 * This technique is fairly expensive in terms of memory and
    4951 * 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
    5066 */
    5167float *
    52 computeGradient(float *fdata,
    53                 int width, int height, int depth,
     68computeGradient(float *data,
     69                int nx, int ny, int nz,
    5470                float dx, float dy, float dz,
    5571                float min, float max)
    5672{
    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 };
    6277    float spacing[3] = { dx, dy, dz };
    63     computeGradients(tempGradients, fdata, sizes, spacing, DATRAW_FLOAT);
     78    computeGradients(tempGradients, data, sizes, spacing, DATRAW_FLOAT);
    6479    filterGradients(tempGradients, sizes);
    6580    quantizeGradients(tempGradients, gradients, sizes, DATRAW_FLOAT);
    6681    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);
    6984    free(gradients);
    70     return data;
     85    return dataOut;
    7186}
    7287
     
    92107 */
    93108void
    94 computeSimpleGradient(float *data, int nx, int ny, int nz,
     109computeSimpleGradient(float *data,
     110                      int nx, int ny, int nz,
    95111                      float dx, float dy, float dz)
    96112{
  • trunk/packages/vizservers/nanovis/ReaderCommon.h

    r3502 r3574  
    1111
    1212extern void
    13 normalizeScalar(float *fdata, int count, float min, float max);
     13normalizeScalar(float *data, int count, int stride, double min, double max);
    1414
    1515extern float *
    16 computeGradient(float *fdata,
    17                 int width, int height, int depth,
     16computeGradient(float *data,
     17                int nx, int ny, int nz,
    1818                float dx, float dy, float dz,
    1919                float min, float max);
    2020
    2121extern void
    22 computeSimpleGradient(float *data, int nx, int ny, int nz,
     22computeSimpleGradient(float *data,
     23                      int nx, int ny, int nz,
    2324                      float dx = 1.0f, float dy = 1.0f, float dz = 1.0f);
    2425
  • trunk/packages/vizservers/nanovis/VtkReader.cpp

    r3569 r3574  
    378378
    379379#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);
    396383        computeSimpleGradient(data, nx, ny, nz,
    397384                              dx, dy, dz);
     
    453440                    }
    454441#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?)
    457443                    cdata[ngen] = v;
    458444#else // !FILTER_GRADIENTS
  • trunk/packages/vizservers/nanovis/dxReader.cpp

    r3502 r3574  
    288288
    289289        // make sure that we read all of the expected points
    290         if (nread != nx*ny*nz) {
     290        if (nread != npts) {
    291291            result.addError("inconsistent data: expected %d points"
    292                             " but found %d points", nx*ny*nz, nread);
     292                            " but found %d points", npts, nread);
    293293            return NULL;
    294294        }
    295295
    296296#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);
    313300        computeSimpleGradient(data, nx, ny, nz,
    314301                              dx, dy, dz);
     
    370357                    }
    371358#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?)
    374360                    cdata[ngen] = v;
    375361#else // !FILTER_GRADIENTS
     
    422408
    423409        // make sure that we read all of the expected points
    424         if (nread != nxy*nz) {
     410        if (nread != npts) {
    425411            result.addError("inconsistent data: expected %d points"
    426                             " but found %d points", nxy*nz, nread);
     412                            " but found %d points", npts, nread);
    427413            return NULL;
    428414        }
Note: See TracChangeset for help on using the changeset viewer.