void TransFuncEditorIntensityPet::loadTransferFunction() {
    // create filter with supported file formats
    QString filter = "transfer function (";
    for (size_t i = 0; i < transferFuncIntensity_->getLoadFileFormats().size(); ++i) {
        std::string temp = "*." + transferFuncIntensity_->getLoadFileFormats()[i] + " ";
        filter.append(temp.c_str());
    }
    filter.replace(filter.length()-1, 1, ")");

    QString fileName = getOpenFileName(filter);
    if (!fileName.isEmpty()) {
        if (transferFuncIntensity_->load(fileName.toStdString()) &&
            transferFuncGradient_->load(fileName.toStdString()))
        {
            if (!transferFunctionCorrect()) {
                rectifyTransferFunction();
                std::string error = "The transfer function contains keys which alpha value is not ";
                error += "255.\nThe alpha value of these keys will be set to 255.";
                QMessageBox::critical(this, tr("Error"), tr(error.c_str()));
                LINFO(error);
            }
            ranges_.clear();
            currentRange_ = tgt::ivec2(0, maximumIntensity_);
            oldThreshold_ = tgt::vec2(0.f, 1.f);
            if (transferFuncIntensity_->getThresholds() != tgt::vec2(0.f, 1.f))
                restoreThresholds();

            updateTransferFunction();
        }
        else {
            QMessageBox::critical(this, tr("Error"), "The selected transfer function could not be loaded.");
            LERROR("The selected transfer function could not be loaded. Maybe the file is corrupt.");
        }
    }
}
Exemplo n.º 2
0
void TransFunc1DRampEditor::updateFromProperty() {

    // check whether new transfer function object has been assigned
    if (property_->get() != transferFuncIntensity_) {
        transferFuncIntensity_ = dynamic_cast<TransFunc1DKeys*>(property_->get());

        // ramp only applicable for two keys
        if (transferFuncIntensity_ && transferFuncIntensity_->getNumKeys() > 2)
            transferFuncIntensity_ = 0;

        // propagate transfer function to mapping canvas and texture painter
        texturePainter_->setTransFunc(transferFuncIntensity_);
        transCanvas_->setTransFunc(transferFuncIntensity_);

        // disable, if tf type unsupported
        if (property_->get() && !transferFuncIntensity_) {
            if (isEnabled()) {
                LWARNING("Current transfer function not supported by this editor. Disabling.");
                setEnabled(false);
            }
        }
    }

    // check whether the volume associated with the TransFuncProperty has changed
    const VolumeBase* newHandle = property_->getVolumeHandle();
    if (newHandle != volumeHandle_) {
        volumeHandle_ = newHandle;
        volumeChanged();
    }

    if (transferFuncIntensity_) {
        setEnabled(true);

        // update treshold widgets from tf
        restoreThresholds();

        // repaint control elements
        repaintAll();
    }
    else {
        setEnabled(false);
    }

}
Exemplo n.º 3
0
void TransFunc1DRampEditor::loadTransferFunction() {

    if (!transferFuncIntensity_) {
        LWARNING("No valid transfer function assigned");
        return;
    }

    //create filter with supported file formats
    QString filter = "transfer function (";
    for (size_t i = 0; i < transferFuncIntensity_->getLoadFileFormats().size(); ++i) {
        std::string temp = "*." + transferFuncIntensity_->getLoadFileFormats()[i] + " ";
        filter.append(temp.c_str());
    }
    filter.replace(filter.length()-1, 1, ")");

    QString fileName = getOpenFileName(filter);
    if (!fileName.isEmpty()) {
        if (transferFuncIntensity_->load(fileName.toStdString())) {
            if (transferFuncIntensity_->getNumKeys() > 2) {
                clearButtonClicked();
                std::string error = "The loaded transfer function contains more than 2 keys.\n";
                error += "The editor does not support this kind of transfer functions.\n";
                error += "The transfer function is reset to default.";
                QMessageBox::critical(this, tr("Error"), tr(error.c_str()));
                LERROR(error);
            }
            else {
                restoreThresholds();
                updateTransferFunction();
            }
        }
        else {
            QMessageBox::critical(this, tr("Error"),
                                  tr("The selected transfer function could not be loaded."));
            LERROR("The selected transfer function could not be loaded. Maybe the file is corrupt.");
        }
    }
}
void TransFuncEditorIntensityPet::updateFromProperty() {
    // check whether the volume associated with the TransFuncProperty has changed
    const VolumeHandleBase* newHandle = property_->getVolumeHandle();
    if (newHandle != volumeHandle_) {
        volumeHandle_ = newHandle;
        volumeChanged();
    }

    if (transferFuncGradient_) {
        transferFuncGradient_->resize(maximumIntensity_ + 1);

        bool emitRepaint = false;
        // adjust tf when not all keys have maximum alpha
        if (!transferFunctionCorrect()) {
            LINFO("The transfer function contains keys that don't have maximum alpha. "
                   << "The alpha value of these keys is set to 255.");
            rectifyTransferFunction();

            emitRepaint = true;
        }

        // update threshold control elements when necessary
        if (transferFuncIntensity_->getThresholds() != tgt::vec2(0.f, 1.f)) {
            restoreThresholds();
            emitRepaint = true;
        }

        if (emitRepaint) {
            property_->notifyChange();
            emit transferFunctionChanged();
        }

        // repaint control elements
        repaintAll();
    }
    else
        resetEditor();
}