示例#1
0
void
avtVolumeRenderer::Initialize(vtkDataSet *ds)
{
    StackTimer t("avtVolumeRenderer::Initialize");

    vtkDataArray *data = 0, *opac = 0;
    if(!VolumeGetScalars(atts, ds, data, opac))
        return;

    VolumeGetVariableExtents(atts, data,
        this->varmin, this->varmax, 
        this->vmin, this->vmax, this->vsize);

    // Get the opacity variable's extents.
    VolumeGetOpacityExtents(atts, opac,
        this->omin, this->omax, this->osize);

    // calculate gradient
    if (ds->GetDataObjectType() == VTK_RECTILINEAR_GRID)
    {
        if (atts.GetLightingFlag() && gm == NULL) // make sure the gradient was invalidated first
        { 
            vtkRectilinearGrid *grid = (vtkRectilinearGrid*)ds;
            int dims[3];
            grid->GetDimensions(dims);

            int nels = dims[0] * dims[1] * dims[2];
            gx  = new float[nels];
            gy  = new float[nels];
            gz  = new float[nels];
            gm  = new float[nels];
            gmn = new float[nels];
            hs = NULL;
            float ghostval = omax+osize;
            gm_max = VolumeCalculateGradient(atts, grid, opac, gx, gy, gz, gm, gmn, ghostval);
        }
    }
    else
    {
        // If we have a lighting+no gradient then calculate the gradient.
        // Also do it if we have a default compact variable name since setting
        // the hs variable happens in that case and its generation is tied to
        // gradient calculation.
        if(gm == NULL)
        {
            int nels = ds->GetNumberOfPoints();
            gx  = new float[nels];
            gy  = new float[nels];
            gz  = new float[nels];
            gm  = new float[nels];
            gmn = new float[nels];
            hs = new float[nels];
            float ghostval = omax+osize;

            bool calcHS = atts.GetCompactVariable() == "default";
            if(!calcHS)
            {
                vtkDataArray *compactSupport = 
                    VolumeGetScalar(ds, atts.GetCompactVariable().c_str());
                if (compactSupport != NULL)
                {   //assign h values
                    for (int i = 0; i<nels; i++)    
                        hs[i] = fabs(compactSupport->GetTuple1(i));
                }
                else
                    calcHS = true;
            }

            gm_max = VolumeCalculateGradient_SPH(ds, opac, 
                gx, gy, gz, gm, gmn, hs, calcHS, ghostval);
            
            //Set the extents for the compact support variables;
            hs_size = nels;
            hs_min = hs[0]; hs_max = hs[0];
            for (int i = 0; i < nels; i++)
            {
                if ( hs[i] < hs_min )
                    hs_min = hs[i];
                if ( hs[i] > hs_max )
                    hs_max = hs[i];
            }
        }
    }

    data->Delete();
    opac->Delete();
    initialized = true;
} 
示例#2
0
void
avtLowerResolutionVolumeFilter::CalculateHistograms(vtkDataSet *ds)
{
    const char *mName = "avtLowerResolutionVolumeFilter::CalculateHistograms: ";
    vtkDataArray *data = 0, *opac = 0;
    if(VolumeGetScalars(atts, ds, data, opac))
    {
        debug5 << mName << "Computing histograms" << endl;
        int nels = data->GetNumberOfTuples();

        // Get the opacity variable's extents.
        float omin = 0.f, omax = 0.f, osize = 0.f;
        VolumeGetOpacityExtents(atts, opac, omin, omax, osize);
        float ghostval = omax+osize;

        //
        // In this mode, we calculate "gm" so we can do the histogram and then
        // we throw away "gm". It's not that big a deal anymore because the
        // gradient calculation is much faster than it used to be.
        //
        vtkFloatArray *gm = vtkFloatArray::New();
        gm->SetNumberOfTuples(nels);
        gm->SetName("gm");
        if(ds->GetDataObjectType() == VTK_RECTILINEAR_GRID)
        {
            VolumeCalculateGradient(atts, (vtkRectilinearGrid *)ds, opac, 
                                0, // gx
                                0, // gy
                                0, // gz
                                (float *)gm->GetVoidPointer(0),
                                0, // gmn
                                ghostval);
        }
        else
        {
            // Since SPH gradient is slow, only calculate it when we have a
            // 2D transfer function since that's the only time we need it for
            // histogram calculation.
            if(atts.GetTransferFunctionDim() == 1)
            {
                memset(gm->GetVoidPointer(0), 0, sizeof(float)*nels);
            }
            else
            {
                VolumeCalculateGradient_SPH(ds, opac, 
                                            0, // gx
                                            0, // gy
                                            0, // gz
                                            (float *)gm->GetVoidPointer(0),
                                            0, // gmn
                                            0, // hs
                                            true,
                                            ghostval);
            }
        }

        if(hist2 != 0)
            delete [] hist2;
        hist2 = new float[hist_size * hist_size];
        if(hist == 0)
            delete [] hist;
        hist = new float[hist_size];
        VolumeHistograms(atts, data, gm, hist, hist2, hist_size);
        gm->Delete();

        data->Delete();
        opac->Delete();
    }
    else
    {
         debug5 << mName << "Could not get scalars or opacity needed to "
                            "calculate the histogram"
                << endl;
    }
}