Esempio n. 1
0
std::shared_ptr<Layer> CImgLayerReader::readData(std::string filePath) {
    if (!filesystem::fileExists(filePath)) {
        std::string newPath = filesystem::addBasePath(filePath);

        if (filesystem::fileExists(newPath)) {
            filePath = newPath;
        } else {
            throw DataReaderException("Error could not find input file: " + filePath, IvwContext);
        }
    }

    auto layer = std::make_shared<Layer>();
    auto layerDisk = std::make_shared<LayerDisk>(filePath);
    layerDisk->setLoader(new CImgLayerRAMLoader(layerDisk.get()));
    layer->addRepresentation(layerDisk);
    return layer;
}
Esempio n. 2
0
std::shared_ptr<Volume> IvfVolumeReader::readData(std::string filePath) {
    if (!filesystem::fileExists(filePath)) {
        std::string newPath = filesystem::addBasePath(filePath);

        if (filesystem::fileExists(newPath)) {
            filePath = newPath;
        } else {
            throw DataReaderException("Error could not find input file: " + filePath, IvwContext);
        }
    }

    std::string fileDirectory = filesystem::getFileDirectory(filePath);
    auto volume = std::make_shared<Volume>();
    Deserializer d(InviwoApplication::getPtr(), filePath);
    d.deserialize("RawFile", rawFile_);
    rawFile_ = fileDirectory + "/" + rawFile_;
    std::string formatFlag("");
    d.deserialize("Format", formatFlag);
    format_ = DataFormatBase::get(formatFlag);
    mat4 basisAndOffset;
    d.deserialize("BasisAndOffset", basisAndOffset);
    volume->setModelMatrix(basisAndOffset);
    mat4 worldTransform;
    d.deserialize("WorldTransform", worldTransform);
    volume->setWorldMatrix(worldTransform);
    d.deserialize("Dimension", dimensions_);
    volume->setDimensions(dimensions_);

    d.deserialize("DataRange", volume->dataMap_.dataRange);
    d.deserialize("ValueRange", volume->dataMap_.valueRange);
    d.deserialize("Unit", volume->dataMap_.valueUnit);

    volume->getMetaDataMap()->deserialize(d);
    littleEndian_ = volume->getMetaData<BoolMetaData>("LittleEndian", littleEndian_);
    auto vd = std::make_shared<VolumeDisk>(filePath, dimensions_, format_);

    auto loader = util::make_unique<RawVolumeRAMLoader>(rawFile_, filePos_, dimensions_,
                                                        littleEndian_, format_);
    vd->setLoader(loader.release());

    volume->addRepresentation(vd);
    return volume;
}
Esempio n. 3
0
std::shared_ptr<Volume> CImgVolumeReader::readData(std::string filePath) {
    if (!filesystem::fileExists(filePath)) {
        std::string newPath = filesystem::addBasePath(filePath);

        if (filesystem::fileExists(newPath)) {
            filePath = newPath;
        }
        else {
            throw DataReaderException("Error could not find input file: " + filePath, IvwContext);
        }
    }

    auto volume = std::make_shared<Volume>();
    auto volumeDisk = std::make_shared<VolumeDisk>(filePath);
    volumeDisk->setLoader(new CImgVolumeRAMLoader(volumeDisk.get()));
    volume->addRepresentation(volumeDisk);

    return volume;
}
Esempio n. 4
0
Volume::Volume(std::shared_ptr<VolumeRepresentation> in)
    : Data<VolumeRepresentation>(in->getDataFormat())
    , StructuredGridEntity<3>(in->getDimensions())
    , dataMap_(in->getDataFormat()) {
    addRepresentation(in);
}
QModelNode::QModelNode(const QDomElement& xmlNode, int row, SceneTreeModel* model, QSceneNode* parentNode) :
	QSceneNode(xmlNode, row, model, parentNode)
{
	setObjectName("Model");	
	addRepresentation();
}
QTerrainNode::QTerrainNode(const QDomElement& xmlNode, int row, SceneTreeModel* model, QSceneNode* parentNode) :
	QSceneNode(xmlNode, row, model, parentNode), m_heightMapID(0), m_materialID(0)
{
	setObjectName("Terrain");	
	addRepresentation();
}
Esempio n. 7
0
Layer::Layer(std::shared_ptr<LayerRepresentation> in)
    : Data<LayerRepresentation>(in->getDataFormat())
    , StructuredGridEntity<2>(in->getDimensions())
    , layerType_(in->getLayerType()) {
    addRepresentation(in);
}
Esempio n. 8
0
std::shared_ptr<Volume> MPVMVolumeReader::readData(std::string filePath) {
    if (!filesystem::fileExists(filePath)) {
        std::string newPath = filesystem::addBasePath(filePath);

        if (filesystem::fileExists(newPath)) {
            filePath = newPath;
        } else {
            throw DataReaderException("Error could not find input file: " + filePath, IvwContext);
        }
    }

    std::string fileDirectory = filesystem::getFileDirectory(filePath);

    // Read the mpvm file content

    std::string textLine;
    std::vector<std::string> files;
    {
        std::ifstream f(filePath.c_str());
        while (!f.eof()) {
            getline(f, textLine);
            textLine = trim(textLine);
            files.push_back(textLine);
        };
    }

    if (files.empty())
        throw DataReaderException("Error: No PVM files found in " + filePath, IvwContext);

    if (files.size() > 4)
        throw DataReaderException("Error: Maximum 4 pvm files are supported, file: " + filePath,
                                  IvwContext);

    // Read all pvm volumes
    std::vector<std::shared_ptr<Volume>> volumes;
    for (size_t i = 0; i < files.size(); i++) {
        auto newVol = PVMVolumeReader::readPVMData(fileDirectory + files[i]);
        if (newVol)
            volumes.push_back(newVol);
        else
            LogWarn("Could not load " << fileDirectory << files[i]);
    }

    if (volumes.empty())
        throw DataReaderException("No PVM volumes could be read from file: " + filePath,
                                  IvwContext);

    if (volumes.size() == 1) {
        printPVMMeta(*volumes[0], fileDirectory + files[0]);
        return volumes[0];
    }

    // Make sure dimension and format match
    const DataFormatBase* format = volumes[0]->getDataFormat();
    size3_t mdim = volumes[0]->getDimensions();
    for (size_t i = 1; i < volumes.size(); i++) {
        if (format != volumes[i]->getDataFormat() || mdim != volumes[i]->getDimensions()) {
            LogWarn("PVM volumes did not have the same format or dimensions, using first volume.");
            printPVMMeta(*volumes[0], fileDirectory + files[0]);
            return volumes[0];
        }
    }

    // Create new format
    const DataFormatBase* mformat =
        DataFormatBase::get(format->getNumericType(), volumes.size(), format->getSize() * 8);

    // Create new volume
    auto volume = std::make_shared<Volume>();
    glm::mat3 basis = volumes[0]->getBasis();
    volume->setBasis(basis);
    volume->setOffset(-0.5f * (basis[0] + basis[1] + basis[2]));
    volume->setDimensions(mdim);
    volume->dataMap_.initWithFormat(mformat);
    volume->setDataFormat(mformat);
    volume->copyMetaDataFrom(*volumes[0]);

    // Merge descriptions but ignore the rest
    if (auto metaData = volume->getMetaData<StringMetaData>("description")) {
        std::string descStr = metaData->get();
        for (size_t i = 1; i < volumes.size(); i++) {
            metaData = volumes[0]->getMetaData<StringMetaData>("description");
            if (metaData) descStr = descStr + ", " + metaData->get();
        }
        volume->setMetaData<StringMetaData>("description", descStr);
    }

    // Create RAM volume
    auto mvolRAM = createVolumeRAM(mdim, mformat);
    unsigned char* dataPtr = static_cast<unsigned char*>(mvolRAM->getData());

    std::vector<const unsigned char*> volumesDataPtr;
    for (size_t i = 0; i < volumes.size(); i++) {
        volumesDataPtr.push_back(static_cast<const unsigned char*>(
            volumes[i]->getRepresentation<VolumeRAM>()->getData()));
    }

    // Copy the data from the other volumes to the new multichannel volume
    size_t mbytes = mformat->getSize();
    size_t bytes = format->getSize();
    size_t dims = mdim.x * mdim.y * mdim.z;
    size_t vsize = volumesDataPtr.size();
    for (size_t i = 0; i < dims; i++) {
        for (size_t j = 0; j < vsize; j++) {
            for (size_t b = 0; b < bytes; b++) {
                dataPtr[i * mbytes + (j * bytes) + b] = volumesDataPtr[j][i * bytes + b];
            }
        }
    }

    volume->addRepresentation(mvolRAM);
    printPVMMeta(*volume, filePath);
    return volume;
}