Esempio n. 1
0
std::shared_ptr<Volume> TMIP::iteration(Shader& s, std::shared_ptr<Volume> vol, std::shared_ptr<Volume> target,
                                        std::vector<std::shared_ptr<Volume>>::const_iterator start,
                                        std::vector<std::shared_ptr<Volume>>::const_iterator end) {
    shader_.activate();

    TextureUnitContainer cont;
    utilgl::bindAndSetUniforms(shader_, cont, *vol, "volume");
    int i = 1;
    for (auto v = start; v != end; ++v) {
        if (i >= maxSamplers_) break;
        std::string id = (i == 0) ? "" : toString(i);
        utilgl::bindAndSetUniforms(shader_, cont, *(v->get()), "volume" + id);
        i++;
    }

    const size3_t dim{vol->getDimensions()};
    fbo_.activate();
    glViewport(0, 0, static_cast<GLsizei>(dim.x), static_cast<GLsizei>(dim.y));

    VolumeGL* outVolumeGL = volume0_->getEditableRepresentation<VolumeGL>();
    if (inport_.isChanged()) {
        fbo_.attachColorTexture(outVolumeGL->getTexture().get(), 0);
    }

    utilgl::multiDrawImagePlaneRect(static_cast<int>(dim.z));

    shader_.deactivate();
    fbo_.deactivate();

    return vol;
}
Esempio n. 2
0
void VolumeRAM2GLConverter::update(const DataRepresentation* source, DataRepresentation* destination) {
    const VolumeRAM* volumeSrc = static_cast<const VolumeRAM*>(source);
    VolumeGL* volumeDst = static_cast<VolumeGL*>(destination);

    if (volumeSrc->getDimensions() != volumeDst->getDimensions()) {
        volumeDst->setDimensions(volumeSrc->getDimensions());
    }

    volumeDst->getTexture()->upload(volumeSrc->getData());
}
Esempio n. 3
0
void VolumeGLProcessor::process() {
    bool reattach = false;

    if (internalInvalid_) {
        reattach = true;
        internalInvalid_ = false;
        const DataFormatBase* format = dataFormat_?dataFormat_:inport_.getData()->getDataFormat();
        volume_ = std::make_shared<Volume>(inport_.getData()->getDimensions(), format);
        volume_->setModelMatrix(inport_.getData()->getModelMatrix());
        volume_->setWorldMatrix(inport_.getData()->getWorldMatrix());
        // pass meta data on
        volume_->copyMetaDataFrom(*inport_.getData());
        volume_->dataMap_ = inport_.getData()->dataMap_;
        outport_.setData(volume_);
    }

    shader_.activate();

    TextureUnitContainer cont;
    utilgl::bindAndSetUniforms(shader_, cont, *inport_.getData(), "volume");

    preProcess();

    const size3_t dim{inport_.getData()->getDimensions()};
    fbo_.activate();
    glViewport(0, 0, static_cast<GLsizei>(dim.x), static_cast<GLsizei>(dim.y));
    if (reattach) {
        VolumeGL* outVolumeGL = volume_->getEditableRepresentation<VolumeGL>();
        fbo_.attachColorTexture(outVolumeGL->getTexture().get(), 0);
    }

    utilgl::multiDrawImagePlaneRect(static_cast<int>(dim.z));

    shader_.deactivate();
    fbo_.deactivate();

    postProcess();
}
Esempio n. 4
0
void LightVolumeGL::process() {
    bool lightColorChanged = false;

    if (lightSource_.isChanged()) {
        lightColorChanged = lightSourceChanged();
    }

    bool reattach = false;

    if (internalVolumesInvalid_ || lightColorChanged || inport_.isChanged()) {
        reattach = volumeChanged(lightColorChanged);
    }

    VolumeGL* outVolumeGL = volume_->getEditableRepresentation<VolumeGL>();
    TextureUnit volUnit;
    const VolumeGL* inVolumeGL = inport_.getData()->getRepresentation<VolumeGL>();
    inVolumeGL->bindTexture(volUnit.getEnum());
    TextureUnit transFuncUnit;
    const Layer* tfLayer = transferFunction_.get().getData();
    const LayerGL* transferFunctionGL = tfLayer->getRepresentation<LayerGL>();
    transferFunctionGL->bindTexture(transFuncUnit.getEnum());
    TextureUnit lightVolUnit[2];
    propParams_[0].vol->bindTexture(lightVolUnit[0].getEnum());
    propParams_[1].vol->bindTexture(lightVolUnit[1].getEnum());
    propagationShader_.activate();
    propagationShader_.setUniform("volume_", volUnit.getUnitNumber());
    utilgl::setShaderUniforms(propagationShader_, *inport_.getData(), "volumeParameters_");
    propagationShader_.setUniform("transferFunc_", transFuncUnit.getUnitNumber());
    propagationShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    propagationShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);

    BufferObjectArray* rectArray = utilgl::enableImagePlaneRect();

    //Perform propagation passes
    for (int i=0; i<2; ++i) {
        propParams_[i].fbo->activate();
        glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

        if (reattach)
            propParams_[i].fbo->attachColorTexture(propParams_[i].vol->getTexture().get(), 0);

        propagationShader_.setUniform("lightVolume_", lightVolUnit[i].getUnitNumber());
        propagationShader_.setUniform("permutationMatrix_", propParams_[i].axisPermutation);

        if (lightSource_.getData()->getLightSourceType() == LightSourceType::LIGHT_POINT) {
            propagationShader_.setUniform("lightPos_", lightPos_);
            propagationShader_.setUniform("permutedLightMatrix_", propParams_[i].axisPermutationLight);
        }
        else {
            propagationShader_.setUniform("permutedLightDirection_", propParams_[i].permutedLightDirection);
        }

        for (unsigned int z=0; z<volumeDimOut_.z; ++z) {
            glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_3D, propParams_[i].vol->getTexture()->getID(), 0, z);
            propagationShader_.setUniform("sliceNum_", static_cast<GLint>(z));
            glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
            glFlush();
        }

        propParams_[i].fbo->deactivate();
    }

    utilgl::disableImagePlaneRect(rectArray);

    propagationShader_.deactivate();
    mergeShader_.activate();
    mergeShader_.setUniform("lightVolume_", lightVolUnit[0].getUnitNumber());
    mergeShader_.setUniform("lightVolumeSec_", lightVolUnit[1].getUnitNumber());
    mergeShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    mergeShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);
    mergeShader_.setUniform("permMatInv_", propParams_[0].axisPermutationINV);
    mergeShader_.setUniform("permMatInvSec_", propParams_[1].axisPermutationINV);
    mergeShader_.setUniform("blendingFactor_", blendingFactor_);
    //Perform merge pass
    mergeFBO_->activate();
    glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

    if (reattach)
        mergeFBO_->attachColorTexture(outVolumeGL->getTexture().get(), 0);

    utilgl::multiDrawImagePlaneRect(static_cast<int>(volumeDimOut_.z));
    mergeShader_.deactivate();
    mergeFBO_->deactivate();
}
Esempio n. 5
0
DataRepresentation* VolumeRAM2GLConverter::createFrom(const DataRepresentation* source) {
    const VolumeRAM* volumeRAM = static_cast<const VolumeRAM*>(source);
    VolumeGL* volume = new VolumeGL(volumeRAM->getDimensions(), volumeRAM->getDataFormat(), false);
    volume->getTexture()->initialize(volumeRAM->getData());
    return volume;
}