Changeset 883 for trunk/vizservers


Ignore:
Timestamp:
Feb 13, 2008, 7:27:28 PM (17 years ago)
Author:
vrinside
Message:

Put Sobel operation for computing normal

Location:
trunk/vizservers/nanovis
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/vizservers/nanovis/dxReader.cpp

    r870 r883  
    3838#include "ZincBlendeVolume.h"
    3939#include "NvZincBlendeReconstructor.h"
     40#include "GradientFilter.h"
    4041
    4142//#define  _LOCAL_ZINC_TEST_
     43float* merge(float* scalar, float* gradient, int size)
     44{
     45        float* data = (float*) malloc(sizeof(float) * 4 * size);
     46
     47        Vector3* g = (Vector3*) gradient;
     48
     49        int ngen = 0, sindex = 0;
     50        for (sindex = 0; sindex <size; ++sindex)
     51        {
     52                data[ngen++] = scalar[sindex];
     53                data[ngen++] = g[sindex].x;
     54                data[ngen++] = g[sindex].y;
     55                data[ngen++] = g[sindex].z;
     56        }
     57        return data;
     58}
     59
     60void normalizeScalar(float* fdata, int count, float min, float max)
     61{
     62    float v = max - min;
     63    if (v != 0.0f)
     64    {
     65        for (int i = 0; i < count; ++i)
     66            fdata[i] = fdata[i] / v;
     67    }
     68}
     69
     70float* computeGradient(float* fdata, int width, int height, int depth, float min, float max)
     71{
     72                float* gradients = (float *)malloc(width * height * depth * 3 * sizeof(float));
     73                float* tempGradients = (float *)malloc(width * height * depth * 3 * sizeof(float));
     74                int sizes[3] = { width, height, depth };
     75                computeGradients(tempGradients, fdata, sizes, DATRAW_FLOAT);
     76                filterGradients(tempGradients, sizes);
     77                quantizeGradients(tempGradients, gradients, sizes, DATRAW_FLOAT);
     78                normalizeScalar(fdata, width * height * depth, min, max);
     79                float* data = merge(fdata, gradients, width * height * depth);
     80
     81        return data;
     82}
    4283
    4384/*
     
    746787#endif
    747788
     789            float *cdata = new float[nx*ny*nz];
     790            int ngen = 0;
     791            double nzero_min = 0.0;
     792            for (int iz=0; iz < nz; iz++) {
     793                double zval = z0 + iz*dmin;
     794                for (int iy=0; iy < ny; iy++) {
     795                    double yval = y0 + iy*dmin;
     796                    for (int ix=0; ix < nx; ix++)
     797                    {
     798                        double xval = x0 + ix*dmin;
     799                        double v = field.value(xval,yval,zval);
     800
     801                        if (v != 0.0f && v < nzero_min)
     802                        {
     803                            nzero_min = v;
     804                        }
     805
     806                        // scale all values [0-1], -1 => out of bounds
     807                        v = (isnan(v)) ? -1.0 : v;
     808
     809                        cdata[ngen] = v;
     810                        ++ngen;
     811                    }
     812                }
     813            }
     814
     815            float* data = computeGradient(cdata, nx, ny, nz, field.valueMin(), field.valueMax());
     816
     817            // Compute the gradient of this data.  BE CAREFUL: center
     818            /*
    748819            float *data = new float[4*nx*ny*nz];
    749820
     
    815886                }
    816887            }
     888            */
    817889
    818890            NanoVis::load_volume(index, nx, ny, nz, 4, data,
Note: See TracChangeset for help on using the changeset viewer.