Exemplo n.º 1
0
void VolumeExport::exportVolume() {
    auto volume = volumePort_.getData();

    if (volume && !volumeFile_.get().empty()) {
        std::string fileExtension = filesystem::getFileExtension(volumeFile_.get());
        auto writer =
            DataWriterFactory::getPtr()->getWriterForTypeAndExtension<Volume>(fileExtension);

        if (writer) {
            try {
                writer->setOverwrite(overwrite_.get());
                writer->writeData(volume.get(), volumeFile_.get());
                LogInfo("Volume exported to disk: " << volumeFile_.get());
            } catch (DataWriterException const& e) {
                util::log(e.getContext(), e.getMessage(), LogLevel::Error);
            }
        } else {
            LogError("Error: Cound not find a writer for the specified extension and data type");
        }
    } else if (volumeFile_.get().empty()) {
        LogWarn("Error: Please specify a file to write to");
    } else if (!volume) {
        LogWarn("Error: Please connect a volume to export");
    }
}
Exemplo n.º 2
0
void ImageExport::processExport(){
    exportQueued_ = false;
    auto image = imagePort_.getData();

    if (image && !imageFile_.get().empty()) {
        const Layer* layer = image->getColorLayer();
        if (layer){
            std::string fileExtension = filesystem::getFileExtension(imageFile_.get());
            auto writer = 
                DataWriterFactory::getPtr()->getWriterForTypeAndExtension<Layer>(fileExtension);

            if (writer) {
                try {
                    writer->setOverwrite(overwrite_.get());
                    writer->writeData(layer, imageFile_.get());
                    LogInfo("Image color layer exported to disk: " << imageFile_.get());
                } catch (DataWriterException const& e) {
                    util::log(e.getContext(), e.getMessage(), LogLevel::Error);
                }
            } else {
                LogError("Error: Could not find a writer for the specified extension and data type");
            }
        }
        else {
            LogError("Error: Could not find color layer to write out");
        }
    } else if (imageFile_.get().empty()) {
        LogWarn("Error: Please specify a file to write to");
    } else if (!image) {
        LogWarn("Error: Please connect an image to export");
    }
}
void TransferFunctionPropertyDialog::exportTransferFunction() {
    InviwoFileDialog exportFileDialog(this, "Export transfer function",
        "transferfunction",
        InviwoApplication::getPtr()->getPath(InviwoApplication::PATH_TRANSFERFUNCTIONS)
    );    
    exportFileDialog.setAcceptMode(QFileDialog::AcceptSave);
    exportFileDialog.setFileMode(QFileDialog::AnyFile);
    exportFileDialog.addExtension("itf", "Inviwo Transfer Function");
    exportFileDialog.addExtension("png", "Transfer Function Image");
    exportFileDialog.addExtension("", "All files"); // this will add "All files (*)"

    if (exportFileDialog.exec()) {
        std::string file = exportFileDialog.selectedFiles().at(0).toLocal8Bit().constData();
        std::string extension = filesystem::getFileExtension(file);

        FileExtension fileExt = exportFileDialog.getSelectedFileExtension();

        if (fileExt.extension_.empty()) {
            // fall-back to standard inviwo TF format
            fileExt.extension_ = "itf";
        }

        // check whether file extension matches the selected one
        if (fileExt.extension_ != extension) {
            file.append(fileExt.extension_);
        }

        if (fileExt.extension_ == "png") {
            TransferFunction &tf = tfProperty_->get();
            const Layer* layer = tf.getData();
            vec2 texSize(tf.getTextureSize(), 1);
            const vec4* readData = static_cast<const vec4*>(layer->getRepresentation<LayerRAM>()->getData());
            Layer writeLayer(layer->getDimensions(), DataVec4UINT8::get());
            glm::u8vec4* writeData = static_cast<glm::u8vec4*>(writeLayer.getEditableRepresentation<LayerRAM>()->getData());
            
            for (std::size_t i=0; i<texSize.x * texSize.y; ++i) {
                for (int c=0; c<4; ++c) {
                    writeData[i][c] = static_cast<glm::u8>(std::min(std::max(readData[i][c] * 255.0f, 0.0f), 255.0f));
                }
            }

            auto writer =
                DataWriterFactory::getPtr()->getWriterForTypeAndExtension<Layer>(extension);

            if (writer) {
                try {
                    writer->setOverwrite(true);
                    writer->writeData(&writeLayer, file);
                } catch (DataWriterException const& e) {
                    util::log(e.getContext(), e.getMessage(), LogLevel::Error);
                }
            } else {
                LogError("Error: Cound not find a writer for the specified extension and data type");
            }
        }
        else if (fileExt.extension_ == "itf") {
            IvwSerializer serializer(file);
            tfProperty_->get().serialize(serializer);
            serializer.writeFile();
        }
    }
}