当前位置: 首页>>代码示例>>C++>>正文


C++ tgt::svec3方法代码示例

本文整理汇总了C++中tgt::svec3方法的典型用法代码示例。如果您正苦于以下问题:C++ tgt::svec3方法的具体用法?C++ tgt::svec3怎么用?C++ tgt::svec3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tgt的用法示例。


在下文中一共展示了tgt::svec3方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tgtAssert

vec4 CPURaycaster::directRendering(const vec3& first, const vec3& last) {

    tgtAssert(transferFunc_.get(), "no transfunc");

    // retrieve intensity volume
    const Volume* volume = volumePort_.getData()->getRepresentation<Volume>();
    tgtAssert(volume, "no input volume");
    tgt::svec3 volDim = volume->getDimensions();
    tgt::vec3 volDimF = tgt::vec3((volume->getDimensions() - svec3(1)));

    // retrieve gradient volume, if 2D TF is to be applied
    const Volume* volumeGradient = 0;
    if (intensityGradientTF_) {
        volumeGradient = gradientVolumePort_.getData()->getRepresentation<Volume>();
        tgtAssert(volumeGradient, "no gradient volume");
        tgtAssert(volumeGradient->getNumChannels() >= 3, "gradient volume has less than three channels");
        tgtAssert(volumeGradient->getDimensions() == volDim, "dimensions mismatch");
    }

    // use dimension with the highest resolution for calculating the sampling step size
    float samplingStepSize = 1.f / (tgt::max(volDim) * samplingRate_.get());

    // retrieve tf texture
    tgt::Texture* tfTexture = transferFunc_.get()->getTexture();
    tfTexture->downloadTexture();

    // calculate ray parameters
    float tend;
    float t = 0.0f;
    vec3 direction = last - first;
    // if direction is a nullvector the entry- and exitparams are the same
    // so special handling for tend is needed, otherwise we divide by zero
    // furthermore both for-loops will cause only 1 pass overall.
    // The test whether last and first are nullvectors is already done in main-function
    // but however the framerates are higher with this test.
    if (direction == vec3(0.0f) && last != vec3(0.0f) && first != vec3(0.0f))
        tend = samplingStepSize / 2.0f;
    else {
        tend = length(direction);
        direction = normalize(direction);
    }
    
    // ray-casting loop
    vec4 result = vec4(0.0f);
    float depthT = -1.0f;
    bool finished = false;
    for (int loop=0; !finished && loop<255*255; ++loop) {
        vec3 sample = first + t * direction;
        float intensity = 0.f;
        if (texFilterMode_.getValue() == GL_NEAREST) 
            intensity = volume->getVoxelFloat(tgt::iround(sample*volDimF));
        else if (texFilterMode_.getValue() == GL_LINEAR) 
            intensity = volume->getVoxelFloatLinear(sample*volDimF);
        else 
            LERROR("Unknown texture filter mode");

        // no shading is applied
        vec4 color;
        if (!intensityGradientTF_)
            color = apply1DTF(tfTexture, intensity);
        else {
            tgt::vec3 grad;
            if (texFilterMode_.getValue() == GL_NEAREST) {
                tgt::ivec3 iSample = tgt::iround(sample*volDimF);
                grad.x = volumeGradient->getVoxelFloat(iSample, 0);
                grad.y = volumeGradient->getVoxelFloat(iSample, 1);
                grad.z = volumeGradient->getVoxelFloat(iSample, 2);
            }
            else if (texFilterMode_.getValue() == GL_LINEAR) {
                grad.x = volumeGradient->getVoxelFloatLinear(sample*volDimF, 0);
                grad.y = volumeGradient->getVoxelFloatLinear(sample*volDimF, 1);
                grad.z = volumeGradient->getVoxelFloatLinear(sample*volDimF, 2);
            }
            else 
                LERROR("Unknown texture filter mode");

            float gradMag = tgt::clamp(tgt::length(grad), 0.f, 1.f);
            color = apply2DTF(tfTexture, intensity, gradMag);
        }

        // perform compositing
        if (color.a > 0.0f) {
            // multiply alpha by samplingStepSize
            // to accommodate for variable sampling rate
            color.a *= samplingStepSize*200.f;
            vec3 result_rgb = vec3(result.elem) + (1.0f - result.a) * color.a * vec3(color.elem);
            result.a = result.a + (1.0f - result.a) * color.a;

            result.r = result_rgb.r;
            result.g = result_rgb.g;
            result.b = result_rgb.b;
        }

        // save first hit ray parameter for depth value calculation
        if (depthT < 0.0f && result.a > 0.0f)
            depthT = t;

        // early ray termination
        if (result.a >= 0.95f) {
             result.a = 1.0f;
//.........这里部分代码省略.........
开发者ID:bsmr-opengl,项目名称:voreen,代码行数:101,代码来源:cpuraycaster.cpp


注:本文中的tgt::svec3方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。