Example #1
0
void
avtIntegrationRF::GetRayValue(const avtRay *ray,
                               unsigned char rgb[3], float depth)
{
    //
    // Some compilers do very poor optimizations, so make sure that we don't
    // do an offset from the pointer at each step by creating automatic
    // variables and using those.
    //
    const int     numSamples  = ray->numSamples;
    const bool   *validSample = ray->validSample;

    const float  *sample      = ray->sample[primaryVariableIndex];

    double sum    = 0.;
    double divisor = distance/numSamples;

    int firstValid = -1;
    for (int i = 0 ; i < numSamples ; i++)
    {
        if (validSample[i])
        {
            if (firstValid < 0)
                firstValid = i;
            sum += sample[i] * divisor;
        }
    }

    //
    // Store off the raw values into a buffer for use later.
    //
    int index = pixelIndexJ * windowSize[0] + pixelIndexI;
    vals[index] = sum;

    //
    // Now map the sum to a grey scale intensity
    //
    double rel_val = (sum - min*distance) / (max*distance - min*distance);
    if (rel_val >= 1.)
        rel_val = 1.;
    if (rel_val <= 0.)
        rel_val = 0.;
    unsigned char intensity = (unsigned char) (rel_val*255);

    int maxSample = IndexOfDepth(depth, numSamples);
    if (maxSample >= firstValid)
    {
        rgb[0] = intensity;
        rgb[1] = intensity;
        rgb[2] = intensity;
    }
    else
    {
        // Leave the color as is...
        ;
    }
}
Example #2
0
void
avtMIPRangeRF::GetRayValue(const avtRay *ray, 
                           unsigned char rgb[3], double depth)
{
    double curMax = -1. * DBL_MAX;
    int    maxInd = -1;

    //
    // Some compilers do very poor optimizations, so make sure that we don't
    // do an offset from the pointer at each step by creating automatic
    // variables and using those.
    //
    const int     numSamples  = ray->numSamples;
    const bool   *validSample = ray->validSample;

    // Only handle one variable, even if there is more.
    const double  *sample      = ray->sample[0];

    int depthIndex = IndexOfDepth(depth, numSamples);

    for (int i = 0 ; i < depthIndex ; i++)
    {
        if (validSample[i])
        {
            if (sample[i] >= thresholdMin && sample[i] <= thresholdMax)
            {
                if (curMax < sample[i])
                {
                    curMax = sample[i];
                    maxInd = i;
                }
            }
        }
    }

    if (maxInd != -1)
    {
        pix->GetColor(curMax, 1., rgb);
        lighting->AddLighting(maxInd, ray, rgb);
    }
}
void
avtDistanceToValueRF::GetRayValue(const avtRay *ray,
                                  unsigned char rgb[3], double depth)
{
    //
    // Some compilers do very poor optimizations, so make sure that we don't
    // do an offset from the pointer at each step by creating automatic
    // variables and using those.
    //
    const int     numSamples  = ray->numSamples;
    const bool   *validSample = ray->validSample;

    // Only handle one variable, even if there is more.
    const double  *sample      = ray->sample[0];

    int depthIndex = IndexOfDepth(depth, numSamples);

    double distance;

    int     location = -1;
    for (int i = 0 ; i < depthIndex ; i++)
    {
        if (validSample[i])
        {
            if (sample[i] == criticalValue)
            {
                location = i;
                distance = (double) i;
                break;
            }
            if (validSample[i+1])
            {
                if (sample[i] < criticalValue && criticalValue < sample[i+1])
                {
                    double in_between = (criticalValue - sample[i]) /
                                        (sample[i+1] - sample[i]);
                    distance = ((double) i) + in_between;
                    location = (in_between > 0.5 ? i+1 : i);
                    break;
                }
                if (sample[i] > criticalValue && criticalValue > sample[i+1])
                {
                    double in_between = (sample[i] - criticalValue) /
                                        (sample[i] - sample[i+1]);
                    distance = ((double) i) + in_between;
                    location = (in_between > 0.5 ? i+1 : i);
                    break;
                }
            }
        }
    }
            
    if (location != -1)
    {
        //
        // We have already found the distance, so let's the color and then
        // shade it.
        //
        pix->GetColor(distance, 1., rgb);
        lighting->AddLighting(location, ray, rgb);
    }
}
Example #4
0
void
avtCompositeRF::GetRayValue(const avtRay *ray, 
                            unsigned char rgb[3], double depth)
{
    //
    // Some compilers do very poor optimizations, so make sure that we don't
    // do an offset from the pointer at each step by creating automatic
    // variables and using those.
    //
    const int     numSamples  = ray->numSamples;
    const bool   *validSample = ray->validSample;

    // For right now, only work with one variable.
    const double  *sample      = ray->sample[colorVariableIndex];
    const double  *sample2     = ray->sample[opacityVariableIndex];
    const double  *weight      = NULL;
    double        min_weight  = 0.;
    double        min_weight_denom = 0.;
    if (weightVariableIndex >= 0)
    {
        weight = ray->sample[weightVariableIndex];
        min_weight = avtPointExtractor::GetMinimumWeightCutoff();
        if (min_weight > 0.)
            min_weight_denom = 1./min_weight;
    }

    int maxSample = IndexOfDepth(depth, numSamples);

    static double threshold = 254./255.;

    double opacity = 0.;
    double trgb[3];
    trgb[0] = 0.;
    trgb[1] = 0.;
    trgb[2] = 0.;
    int z;
    double distanceToReachFullOpacity = 1./250.;
    double distanceCoveredPerSample = 1./maxSample;
    double oneSamplesContribution = distanceCoveredPerSample/distanceToReachFullOpacity;
    for (z = 0 ; z < maxSample ; z++)
    {
        if (validSample[z])
        {
            float opacityValue;
            float value;
            float diffRGB = 0;
            float diffAlpha = 0;
            RGBA colorLow, colorHigh, opacLow, opacHigh;

            if (trilinearSampling == true){
                value = map->QuantizeValF(sample[z]);
                diffRGB = value - ((int)value);
                colorLow = table[(int)value];
                colorHigh = table[(int)value+1];

                value = secondaryMap->QuantizeValF(sample2[z]);
                diffAlpha = value - ((int)value);
                opacLow = secondaryTable[(int)value];
                opacHigh = secondaryTable[(int)value+1];
            }

            const RGBA &color = table[map->Quantize(sample[z])];
            const RGBA &opac = secondaryTable[secondaryMap->Quantize(sample2[z])];

            if (trilinearSampling == false)
                opacityValue = opac.A;
            else
                opacityValue = (1.0-diffAlpha)*opacLow.A + diffAlpha*opacHigh.A;

            //
            // Only calculate further when we get non-zero opacity.
            //
            if (opacityValue > 0)
            {
                double tableOpac = opac.A;
                if (weight != NULL)
                {
                    if (weight[z] < min_weight)
                        tableOpac *= weight[z]*min_weight_denom;
                }
                double samplesOpacity = tableOpac;
                if (trilinearSampling == false){
                    samplesOpacity = tableOpac * oneSamplesContribution;
                    samplesOpacity = (samplesOpacity > 1. ? 1. : samplesOpacity);
                }
                unsigned char rgb[3] = { color.R, color.G, color.B };
                if (trilinearSampling == false)
                    lighting->AddLighting(z, ray, rgb);
                else {
                    unsigned char rgbLow[3] = { colorLow.R, colorLow.G, colorLow.B };
                    unsigned char rgbHigh[3] = { colorHigh.R, colorHigh.G, colorHigh.B };
                    rgb[0] = (1.0-diffRGB)*rgbLow[0] + diffRGB*rgbHigh[0];
                    rgb[1] = (1.0-diffRGB)*rgbLow[1] + diffRGB*rgbHigh[1];
                    rgb[2] = (1.0-diffRGB)*rgbLow[2] + diffRGB*rgbHigh[2];
                    lighting->AddLightingHeadlight(z, ray, rgb, 1.0, matProperties);
                }

                double ff = (1-opacity)*samplesOpacity;
                trgb[0] = trgb[0] + ff*rgb[0];
                trgb[1] = trgb[1] + ff*rgb[1];
                trgb[2] = trgb[2] + ff*rgb[2];

                opacity = opacity + ff;
            }
            if (opacity > threshold)
            {
                break;
            }
        }
    }

    if (z >= maxSample)
    {
        //
        // The pixel is not completely opaque, so incorporate the background.
        //
        trgb[0] = trgb[0] + (unsigned char)((1-opacity)*rgb[0]);
        trgb[1] = trgb[1] + (unsigned char)((1-opacity)*rgb[1]);
        trgb[2] = trgb[2] + (unsigned char)((1-opacity)*rgb[2]);
    }

    //
    // Copy the temporary rgb into the output rgb.
    //
    rgb[0] = (unsigned char) trgb[0];
    rgb[1] = (unsigned char) trgb[1];
    rgb[2] = (unsigned char) trgb[2];
}