<commit_before>/*********************************************************************************
 *
 * Inviwo - Interactive Visualization Workshop
 *
 * Copyright (c) 2014-2015 Inviwo Foundation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 *********************************************************************************/

#include "multichannelraycaster.h"
#include <inviwo/core/io/serialization/versionconverter.h>
#include <modules/opengl/volume/volumegl.h>
#include <modules/opengl/image/layergl.h>
#include <modules/opengl/glwrap/textureunit.h>
#include <modules/opengl/shaderutils.h>
#include <modules/opengl/textureutils.h>
#include <modules/opengl/volumeutils.h>
#include <inviwo/core/datastructures/volume/volume.h>

namespace inviwo {

ProcessorClassIdentifier(MultichannelRaycaster, "org.inviwo.MultichannelRaycaster");
ProcessorDisplayName(MultichannelRaycaster,  "Multichannel Raycaster");
ProcessorTags(MultichannelRaycaster, Tags::GL);
ProcessorCategory(MultichannelRaycaster, "Volume Rendering");
ProcessorCodeState(MultichannelRaycaster, CODE_STATE_EXPERIMENTAL);

MultichannelRaycaster::MultichannelRaycaster()
    : Processor()
    , shader_("multichannelraycaster.frag", false)
    , volumePort_("volume")
    , entryPort_("entry")
    , exitPort_("exit")
    , outport_("outport")
    , transferFunctions_("transfer-functions", "Transfer functions")
    , raycasting_("raycaster", "Raycasting")
    , camera_("camera", "Camera")
    , lighting_("lighting", "Lighting", &camera_)
    , positionIndicator_("positionindicator", "Position Indicator") {
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction1", "Channel 1", TransferFunction(), &volumePort_), false);
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction2", "Channel 2", TransferFunction(), &volumePort_), false);
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction3", "Channel 3", TransferFunction(), &volumePort_), false);
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction4", "Channel 4", TransferFunction(), &volumePort_), false);

    addPort(volumePort_, "VolumePortGroup");
    addPort(entryPort_, "ImagePortGroup1");
    addPort(exitPort_, "ImagePortGroup1");
    addPort(outport_, "ImagePortGroup1");

    addProperty(raycasting_);
    addProperty(camera_);
    addProperty(lighting_);
    addProperty(positionIndicator_);
    addProperty(transferFunctions_);
    
    volumePort_.onChange(this, &MultichannelRaycaster::initializeResources);
}

MultichannelRaycaster::~MultichannelRaycaster() {
    for (auto tf : transferFunctions_.getProperties()) {
        delete tf;
    }
}

void MultichannelRaycaster::initializeResources() {
    utilgl::addShaderDefines(&shader_, raycasting_);
    utilgl::addShaderDefines(&shader_, camera_);
    utilgl::addShaderDefines(&shader_, lighting_);
    utilgl::addShaderDefines(&shader_, positionIndicator_);

    if (volumePort_.hasData()) {
        size_t channels = volumePort_.getData()->getDataFormat()->getComponents();
        
        auto tfs = transferFunctions_.getPropertiesByType<TransferFunctionProperty>();
        for (size_t i = 0; i < tfs.size(); i++) {
            tfs[i]->setVisible(i < channels ? true : false);
        }
        
        std::stringstream ss;
        ss << channels;
        shader_.getFragmentShaderObject()->addShaderDefine("NUMBER_OF_CHANNELS", ss.str());

        std::stringstream ss2;
        for (size_t i = 0; i < channels; ++i) {
            ss2 << "color["<< i <<"] = APPLY_CLASSIFICATION(transferFunction" << i+1 << ", voxel[" << i << "]);";
        }
        shader_.getFragmentShaderObject()->addShaderDefine("SAMPLE_CHANNELS", ss2.str());
        shader_.build();
    }
}

void MultichannelRaycaster::process() {
    LGL_ERROR;
    utilgl::activateAndClearTarget(outport_);
    shader_.activate();

    TextureUnitContainer units;
    utilgl::bindAndSetUniforms(&shader_, units, volumePort_);
    utilgl::bindAndSetUniforms(&shader_, units, entryPort_, COLOR_DEPTH_PICKING);
    utilgl::bindAndSetUniforms(&shader_, units, exitPort_, COLOR_DEPTH);

    auto tfs = transferFunctions_.getPropertiesByType<TransferFunctionProperty>();
    size_t channels = volumePort_.getData()->getDataFormat()->getComponents();
    for (size_t channel = 0; channel < channels; channel++) {
        utilgl::bindAndSetUniforms(&shader_, units, *tfs[channel]);
    }
    utilgl::setUniforms(&shader_, outport_, camera_, lighting_, raycasting_, positionIndicator_);

    utilgl::singleDrawImagePlaneRect();

    shader_.deactivate();
    utilgl::deactivateCurrentTarget();
    LGL_ERROR;
}

void MultichannelRaycaster::deserialize(IvwDeserializer& d) {
    NodeVersionConverter vc([](TxElement* node) {
        TxElement* p1 = util::xmlGetElement(
            node, "InPorts/InPort&type=org.inviwo.ImageMultiInport&identifier=entry-points");
        if (p1) p1->SetAttribute("identifier", "entry");
        TxElement* p2 = util::xmlGetElement(
            node, "InPorts/InPort&type=org.inviwo.ImageMultiInport&identifier=exit-points");
        if (p2) p2->SetAttribute("identifier", "exit");
        return true;

    });

    d.convertVersion(&vc);
    Processor::deserialize(d);
}

}  // namespace<commit_msg>BaseGL: Jenkins fix<commit_after>/*********************************************************************************
 *
 * Inviwo - Interactive Visualization Workshop
 *
 * Copyright (c) 2014-2015 Inviwo Foundation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 *********************************************************************************/

#include "multichannelraycaster.h"
#include <inviwo/core/io/serialization/versionconverter.h>
#include <modules/opengl/volume/volumegl.h>
#include <modules/opengl/image/layergl.h>
#include <modules/opengl/glwrap/textureunit.h>
#include <modules/opengl/shaderutils.h>
#include <modules/opengl/textureutils.h>
#include <modules/opengl/volumeutils.h>
#include <inviwo/core/datastructures/volume/volume.h>

namespace inviwo {

ProcessorClassIdentifier(MultichannelRaycaster, "org.inviwo.MultichannelRaycaster");
ProcessorDisplayName(MultichannelRaycaster,  "Multichannel Raycaster");
ProcessorTags(MultichannelRaycaster, Tags::GL);
ProcessorCategory(MultichannelRaycaster, "Volume Rendering");
ProcessorCodeState(MultichannelRaycaster, CODE_STATE_EXPERIMENTAL);

MultichannelRaycaster::MultichannelRaycaster()
    : Processor()
    , shader_("multichannelraycaster.frag", false)
    , volumePort_("volume")
    , entryPort_("entry")
    , exitPort_("exit")
    , outport_("outport")
    , transferFunctions_("transfer-functions", "Transfer functions")
    , raycasting_("raycaster", "Raycasting")
    , camera_("camera", "Camera")
    , lighting_("lighting", "Lighting", &camera_)
    , positionIndicator_("positionindicator", "Position Indicator") {
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction1", "Channel 1", TransferFunction(), &volumePort_), false);
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction2", "Channel 2", TransferFunction(), &volumePort_), false);
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction3", "Channel 3", TransferFunction(), &volumePort_), false);
    transferFunctions_.addProperty(new TransferFunctionProperty(
        "transferFunction4", "Channel 4", TransferFunction(), &volumePort_), false);

    addPort(volumePort_, "VolumePortGroup");
    addPort(entryPort_, "ImagePortGroup1");
    addPort(exitPort_, "ImagePortGroup1");
    addPort(outport_, "ImagePortGroup1");

    addProperty(raycasting_);
    addProperty(camera_);
    addProperty(lighting_);
    addProperty(positionIndicator_);
    addProperty(transferFunctions_);
    
    volumePort_.onChange(this, &MultichannelRaycaster::initializeResources);
}

MultichannelRaycaster::~MultichannelRaycaster() {
    for (auto tf : transferFunctions_.getProperties()) {
        delete tf;
    }
}

void MultichannelRaycaster::initializeResources() {
    utilgl::addShaderDefines(&shader_, raycasting_);
    utilgl::addShaderDefines(&shader_, camera_);
    utilgl::addShaderDefines(&shader_, lighting_);
    utilgl::addShaderDefines(&shader_, positionIndicator_);

    if (volumePort_.hasData()) {
        size_t channels = volumePort_.getData()->getDataFormat()->getComponents();
        
        auto tfs = transferFunctions_.getPropertiesByType<TransferFunctionProperty>();
        for (size_t i = 0; i < tfs.size(); i++) {
            tfs[i]->setVisible(i < channels ? true : false);
        }
        
        std::stringstream ss;
        ss << channels;
        shader_.getFragmentShaderObject()->addShaderDefine("NUMBER_OF_CHANNELS", ss.str());

        std::stringstream ss2;
        for (size_t i = 0; i < channels; ++i) {
            ss2 << "color["<< i <<"] = APPLY_CLASSIFICATION(transferFunction" << i+1 << ", voxel[" << i << "]);";
        }
        shader_.getFragmentShaderObject()->addShaderDefine("SAMPLE_CHANNELS", ss2.str());
        shader_.build();
    }
}

void MultichannelRaycaster::process() {
    LGL_ERROR;
    utilgl::activateAndClearTarget(outport_);
    shader_.activate();

    TextureUnitContainer units;
    utilgl::bindAndSetUniforms(&shader_, units, volumePort_);
    utilgl::bindAndSetUniforms(&shader_, units, entryPort_, COLOR_DEPTH_PICKING);
    utilgl::bindAndSetUniforms(&shader_, units, exitPort_, COLOR_DEPTH);

    auto tfs = transferFunctions_.getPropertiesByType<TransferFunctionProperty>();
    size_t channels = volumePort_.getData()->getDataFormat()->getComponents();
    for (size_t channel = 0; channel < channels; channel++) {
        utilgl::bindAndSetUniforms(&shader_, units, *tfs[channel]);
    }
    utilgl::setUniforms(&shader_, outport_, camera_, lighting_, raycasting_, positionIndicator_);

    utilgl::singleDrawImagePlaneRect();

    shader_.deactivate();
    utilgl::deactivateCurrentTarget();
    LGL_ERROR;
}

void MultichannelRaycaster::deserialize(IvwDeserializer& d) {
    NodeVersionConverter vc([](TxElement* node) {
        if (TxElement* p1 = util::xmlGetElement(
            node, "InPorts/InPort&type=org.inviwo.ImageMultiInport&identifier=entry-points")) {
            p1->SetAttribute("identifier", "entry");
        } else if (TxElement* p2 = util::xmlGetElement(
            node, "InPorts/InPort&type=org.inviwo.ImageInport&identifier=entry-points")) {
            p2->SetAttribute("identifier", "entry");
        }
        
        
        if (TxElement* p1 = util::xmlGetElement(
            node, "InPorts/InPort&type=org.inviwo.ImageMultiInport&identifier=exit-points")) {
            p1->SetAttribute("identifier", "exit");
        } else if (TxElement* p2 = util::xmlGetElement(
            node, "InPorts/InPort&type=org.inviwo.ImageInport&identifier=exit-points")) {
            p2->SetAttribute("identifier", "exit");
        }
        
        return true;

    });

    d.convertVersion(&vc);
    Processor::deserialize(d);
}

}  // namespace
{'fraction_non_alphanumeric': 0.1369792810601069, 'fraction_numerical': 0.005124826121970862, 'mean_word_length': 4.686927560366361, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5758527', 'n_tokens_mistral': 3940, 'n_tokens_neox': 3744, 'n_words': 881}