Ignore:
Timestamp:
Mar 25, 2013, 1:17:55 PM (12 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?.

File:
1 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{
Note: See TracChangeset for help on using the changeset viewer.