void TransFuncMappingCanvasRamp::mouseMoveEvent(QMouseEvent* event) {
    unsetCursor();
    event->accept();
    mousePos_ = event->pos();

    vec2 sHit = vec2(event->x(), static_cast<float>(height()) - event->y());
    vec2 hit = stow(sHit);

    // return when no key was inserted or selected
    if (!dragging_)
        return;

    // keep location within valid texture coord range
    hit = tgt::clamp(hit, 0.f, 1.f);

    if (selectedKey_ != 0) {
        TransFuncMappingKey* leftKey = tf_->getKey(0);
        TransFuncMappingKey* rightKey = tf_->getKey(1);
        if (selectedKey_ == leftKey) {
            // obey ramp function restrictions:
            // left key has to stay left of right key
            hit.x = std::min<float>(hit.x, rightKey->getIntensity());
            // max width = 1.f, min center = 0.f
            float minX = rightKey->getIntensity() - 1.f;
            float maxY = std::min(-minX, 0.5f);
            hit.y = std::min(hit.y, maxY);
            if (rightKey->getIntensity() == 1.f) {
                minX = rightKey->getIntensity() - rightKey->getColorL().a / 255.f;
                hit.x = std::max(hit.x, minX);
            }
            // moving left upwards only allowed if at left border (ramp function)
            if (hit.x != 0.f)
                hit.y = 0.f;
        }
        else {
            // obey ramp function restrictions:
            // right key has to stay right of right key
            hit.x = std::max<float>(hit.x, leftKey->getIntensity());
            // max width = 1.f, max center = 1.f
            float maxX = leftKey->getIntensity() + 1.f;
            float minY = std::max(2.f - maxX, 0.5f);
            hit.y = std::max(hit.y, minY);
            if (leftKey->getIntensity() == 0.f) {
                float maxX = 1.f - leftKey->getColorL().a / 255.f;
                hit.x = std::min(hit.x, maxX);
            }
            // moving right downwards only allowed if at right border (ramp function)
            if (hit.x != 1.f)
                hit.y = 1.f;
        }
        selectedKey_->setIntensity(hit.x);
        selectedKey_->setAlphaL(hit.y);
        calcRampParameterFromKeys();
        updateCoordinates(event->pos(), vec2(hit.x, selectedKey_->getAlphaL()));
        repaint();
        emit changed();
    }
}
Serializable* KeyValueFactory::createType(const std::string& typeString) {
    using tgt::ivec2;
    using tgt::ivec3;
    using tgt::ivec4;
    using tgt::vec2;
    using tgt::vec3;
    using tgt::vec4;
    using tgt::mat2;
    using tgt::mat3;
    using tgt::mat4;

    if (typeString == "KeyValue_float")
        return new PropertyKeyValue<float>(0, 0);
    else if (typeString == "KeyValue_int")
        return new PropertyKeyValue<int>(0, 0);
    else if (typeString == "KeyValue_bool")
        return new PropertyKeyValue<bool>(0, 0);
    else if (typeString == "KeyValue_ivec2")
        return new PropertyKeyValue<ivec2>(ivec2(0), 0);
    else if (typeString == "KeyValue_ivec3")
        return new PropertyKeyValue<ivec3>(ivec3(0), 0);
    else if (typeString == "KeyValue_ivec4")
        return new PropertyKeyValue<ivec4>(ivec4(0), 0);
    else if (typeString == "KeyValue_vec2")
        return new PropertyKeyValue<vec2>(vec2(0.0f), 0);
    else if (typeString == "KeyValue_vec3")
        return new PropertyKeyValue<vec3>(vec3(0.0f), 0);
    else if (typeString == "KeyValue_vec4")
        return new PropertyKeyValue<vec4>(vec4(0.0f), 0);
    else if (typeString == "KeyValue_mat2")
        return new PropertyKeyValue<mat2>(mat2(0.0f), 0);
    else if (typeString == "KeyValue_mat3")
        return new PropertyKeyValue<mat3>(mat3(0.0f), 0);
    else if (typeString == "KeyValue_mat4")
        return new PropertyKeyValue<mat4>(mat4(0.0f), 0);
    else if (typeString == "KeyValue_Camera")
        return new PropertyKeyValue<tgt::Camera>(tgt::Camera(vec3(0.0f), vec3(0.0f), vec3(0.0f)), 0);
    else if (typeString == "KeyValue_string")
        return new PropertyKeyValue<std::string>("", 0);
    else if (typeString == "KeyValue_ShaderSource")
        return new PropertyKeyValue<ShaderSource>(ShaderSource(), 0);
    else if (typeString == "KeyValue_TransFunc")
        return new PropertyKeyValue<TransFunc*>(new TransFunc(), 0);
    else if (typeString == "KeyValue_VolumeCollection")
        return new PropertyKeyValue<VolumeCollection*>(new VolumeCollection(), 0);
    else if (typeString == "KeyValue_VolumeHandle")
        return new PropertyKeyValue<VolumeHandle*>(new VolumeHandle(), 0);
    else
        return 0;
}
Пример #3
0
tgt::MouseEvent* ScalingProcessor::transformMouseCoordinates(tgt::MouseEvent* e, int scalingMode, RenderPort* inport, RenderPort* outport ) const {
    float aspectRatioIn = (float)inport->getSize().x / (float)inport->getSize().y;
    float aspectRatioOut = (float)outport->getSize().x / (float)outport->getSize().y;
    vec2 scalingFactor(1.f);
    switch(scalingMode) {
        case 0:
            break;
        case 1:
            //map pixels 1:1
            scalingFactor = vec2((float)inport->getSize().x / (float)outport->getSize().x, (float)inport->getSize().y / (float)outport->getSize().y);
            break;
        case 2:
            //scale respecting aspect ratio and view all of the inport:
            if (aspectRatioOut < aspectRatioIn) {
                scalingFactor = vec2(1.0f, aspectRatioOut/aspectRatioIn);
            }
            else {
                scalingFactor = vec2(aspectRatioIn/aspectRatioOut, 1.0f);
            }
            break;
        case 3:
            //scale respecting aspect ratio and fill outport:
            if (aspectRatioOut < aspectRatioIn) {
                scalingFactor = vec2(aspectRatioIn/aspectRatioOut, 1.0f);
            }
            else {
                scalingFactor = vec2(1.0f, aspectRatioOut/aspectRatioIn);
            }
            break;
        case 4:
            //scale to height:
            scalingFactor = vec2(aspectRatioIn/aspectRatioOut, 1.0f);
            break;
        case 5:
            //scale to width:
            scalingFactor = vec2(1.0f, aspectRatioIn*aspectRatioOut);
            break;
        default:
            break;
    }

    // compute transformation
    vec2 pixelOffset = ((1.f - scalingFactor) * vec2(outport->getSize())) / 2.f;
    vec2 pixelScale = (vec2(outport->getSize())*scalingFactor) / vec2(inport_.getSize());
    vec2 trafoCoords = (vec2(e->coord()) - pixelOffset)/pixelScale;

    // clone event and assign transformed coords
    tgt::MouseEvent* trafoEvent = new tgt::MouseEvent(*e);
    trafoEvent->setCoord(ivec2(trafoCoords));
    trafoEvent->setViewport(inport->getSize());
    return trafoEvent;
}
Пример #4
0
tgt::vec2 TrackballNavigation::scaleMouse(const tgt::ivec2& coords, const tgt::ivec2& viewport) const {
    return vec2( static_cast<float>(coords.x*2.f) / static_cast<float>(viewport.x) - 1.f,
                 1.f - static_cast<float>(coords.y*2.f) / static_cast<float>(viewport.y) );
}