Exemple #1
0
void Processor::deserialize(XmlDeserializer& s) {
    // meta data
    metaDataContainer_.deserialize(s);

    // misc settings
    s.deserialize("name", id_);
    guiName_ = id_;

    // deserialize properties
    PropertyOwner::deserialize(s);


    // ---
    // the following entities are static resources that should not be dynamically created by the serializer
    //
    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);

    // deserialize inports using a temporary map
    map<string, Port*> inportMap;
    for (vector<Port*>::const_iterator it = inports_.begin(); it != inports_.end(); ++it)
        inportMap[(*it)->getID()] = *it;
    try {
        s.deserialize("Inports", inportMap, "Port", "name");
    }
    catch (XmlSerializationNoSuchDataException& /*e*/){
        // port key missing => just ignore
        s.removeLastError();
    }

    // deserialize outports using a temporary map
    map<string, Port*> outportMap;
    for (vector<Port*>::const_iterator it = outports_.begin(); it != outports_.end(); ++it)
        outportMap[(*it)->getID()] = *it;
    try {
        s.deserialize("Outports", outportMap, "Port", "name");
    }
    catch (XmlSerializationNoSuchDataException& /*e*/){
        // port key missing => just ignore
        s.removeLastError();
    }

    // deserialize interaction handlers using a temporary map
    map<string, InteractionHandler*> handlerMap;
    const std::vector<InteractionHandler*>& handlers = getInteractionHandlers();
    for (vector<InteractionHandler*>::const_iterator it = handlers.begin(); it != handlers.end(); ++it)
        handlerMap[(*it)->getID()] = *it;
    try {
        s.deserialize("InteractionHandlers", handlerMap, "Handler", "name");
    }
    catch (XmlSerializationNoSuchDataException& /*e*/){
        // interaction handler key missing => just ignore
        s.removeLastError();
    }

    s.setUsePointerContentSerialization(usePointerContentSerialization);
    // --- static resources end ---

    firstProcessAfterDeserialization_ = true;
}
Exemple #2
0
/**
 * Tests serialization and deserialization of cascaded STL containers
 * like @c std::vector or @c std::map.
 */
void testComplexSTL() {
    std::map<int, std::string> m1, m2, m3;
    m2[1] = "one";
    m3[2] = "two";
    m3[3] = "three";

    std::vector<std::map<int, std::string> > v;
    v.push_back(m1);
    v.push_back(m2);
    v.push_back(m3);

    std::stringstream stream;

    XmlSerializer s;
    s.serialize("v", v);
    s.write(stream);

    // Reset all variables to default values...
    v.clear();
    test(v.size() == 0, "vector is not empty");

    XmlDeserializer d;
    d.read(stream);
    d.deserialize("v", v);

    test(v.size() == 3, "not all vector item deserialized");
    test(v[0].size() == 0, "incorrect size of first vector item");
    test(v[1].size() == 1, "incorrect size of second vector item");
    test(v[2].size() == 2, "incorrect size of third vector item");
    test(v[1][1] == "one", "first item of second vector item incorrect deserialized");
    test(v[2][2] == "two", "first item of thrid vector item incorrect deserialized");
    test(v[2][3] == "three", "second item of third vector item incorrect deserialized");
}
Exemple #3
0
bool deserializeSettings(PropertyOwner* po, const std::string& filename) {
    std::ifstream stream;
    stream.open(filename.c_str(), std::ios_base::in);
    if(stream.fail()) {
        stream.close();
        return false;
    }
    else {
        XmlDeserializer xmlDeserializer;
        try {
            xmlDeserializer.read(stream);
            po->deserialize(xmlDeserializer);
            stream.close();
        }
        catch (XmlSerializationNoSuchDataException) {
            // no data present => ignore
            xmlDeserializer.removeLastError();
            return false;
        }
        catch (SerializationException &e) {
            LWARNINGC("VoreenSettingsDialog", std::string("Deserialization failed: ") + e.what());
            return false;
        }
    }
    return true;
}
Exemple #4
0
/**
 * Tests serialization and deserialization of a @c std::map.
 */
void testMap() {
    std::map<int, std::string> m;
    m[1] = "one";
    m[2] = "two";
    m[3] = "three";

    std::stringstream stream;

    XmlSerializer s;
    s.serialize("m", m);
    s.write(stream);

    // Reset all variables to default values...
    m.clear();
    test(m.size() == 0, "map is not empty");

    XmlDeserializer d;
    d.read(stream);
    d.deserialize("m", m);

    test(m.size() == 3, "not all map items deserialized");
    test(m[1] == "one", "first pair incorrect deserialized");
    test(m[2] == "two", "second pair incorrect deserialized");
    test(m[3] == "three", "third pair incorrect deserialized");
}
Exemple #5
0
/**
 * Tests serialization and deserialization of pointers to abstract classes.
 */
void testIAbstractSerializable() {
    Abstract* a = new Specific();
    dynamic_cast<Specific*>(a)->i = 1;

    std::stringstream stream;

    AbstractFactory factory;

    XmlSerializer s;
    s.registerFactory(&factory);
    s.serialize("Abstract", a);
    s.write(stream);

    // Reset all variables to default values...
    delete a;
    a = 0;

    XmlDeserializer d;
    d.registerFactory(&factory);
    d.read(stream);
    d.deserialize("Abstract", a);

    test(a != 0, "a still null");
    Specific* specific = dynamic_cast<Specific*>(a);
    test(specific != 0, "cast to Specific* not possible");
    test(specific->i, 1, "a incorrect deserialized");

    delete a;
}
void VolumeURLListProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    std::vector<std::string> urlList = value_;
    std::map<std::string, bool> selectMap = selectionMap_;
    s.deserialize("VolumeURLs", urlList, "url");

    try {
        s.deserialize("Selection", selectMap, "entry", "url");
    }
    catch (SerializationException& e) {
        s.removeLastError();
        LWARNING("Failed to deserialize selection map: " << e.what());
    }

    // convert URLs to absolute path
    std::string basePath = tgt::FileSystem::dirName(s.getDocumentPath());
    for (size_t i=0; i<urlList.size(); i++) {
        std::string url = urlList[i];
        std::string urlConv = VolumeURL::convertURLToAbsolutePath(url, basePath);
        urlList[i] = urlConv;
        if (selectMap.find(url) != selectMap.end()) {
            bool selected = selectMap[url];
            selectMap.erase(url);
            selectMap.insert(std::pair<std::string, bool>(urlConv, selected));
        }
    }

    value_ = urlList;
    selectionMap_ = selectMap;

    invalidate();
}
Exemple #7
0
void VolumeHistogramIntensityGradient::deserialize(XmlDeserializer& s) {
    s.deserialize("values", histValues_);
    s.deserialize("maxValue", maxValue_);
    s.deserialize("significantRangeIntensity", significantRangeIntensity_);
    s.deserialize("significantRangeGradient", significantRangeGradient_);
    s.deserialize("scaleFactor", scaleFactor_);
}
Exemple #8
0
void FontProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    int fontSize;
    std::string fontName;
    std::string fontTypeName;
    tgt::Font::FontType fontType;
    std::string textAlignmentName;
    tgt::Font::TextAlignment textAlignment;
    std::string verticalTextAlignmentName;
    tgt::Font::VerticalTextAlignment verticalTextAlignment;
    float lineWidth;

    s.deserialize("fontType", fontTypeName);
    fontType = tgt::Font::getFontType(fontTypeName);
    s.deserialize("fontSize", fontSize);
    s.deserialize("fontName", fontName);
    fontName = tgt::FileSystem::fileName(fontName);
    s.deserialize("textAlignment", textAlignmentName);
    textAlignment = tgt::Font::getTextAlignment(textAlignmentName);
    s.deserialize("verticalTextAlignment", verticalTextAlignmentName);
    verticalTextAlignment = tgt::Font::getVerticalTextAlignment(verticalTextAlignmentName);
    s.deserialize("lineWidth", lineWidth);

    if (!fontName.empty() && fontType != tgt::Font::NIL) {
        delete value_;
        set(new tgt::Font(VoreenApplication::app()->getFontPath(fontName), fontSize, fontType, lineWidth, textAlignment, verticalTextAlignment));
    }
}
Exemple #9
0
void Property::deserialize(XmlDeserializer& s) {
    if (serializeValue_)
        return;

    // deserialize level-of-detail, if available
    try {
        int lod;
        s.deserialize("lod", lod);
        lod_ = static_cast<LODSetting>(lod);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
        lod_ = USER;
    }

    // deserialize gui name, if available
    try {
        std::string temp;
        s.deserialize("guiName", temp);
        guiName_ = temp;
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }

    metaDataContainer_.deserialize(s);
}
void PlotDataFitFunction::FittingValues::deserialize(XmlDeserializer& s){
    int value;
    s.deserialize("regressionType",value);
    regressionType = static_cast<FunctionLibrary::RegressionType>(value);
    s.deserialize("column",column);
    mse = -1;
    s.deserialize("Dimension",dimension);
}
Exemple #11
0
void Animation::deserialize(XmlDeserializer& s) {
    s.deserialize("processors", processors_, "Processor");
    s.deserialize("undoSteps", undoSteps_);
    s.deserialize("fps", fps_);
    s.deserialize("duration", duration_);
    s.deserialize("currentTime", currentTime_);
    s.deserialize("isRendering", isRendering_);
}
Exemple #12
0
void OpenCLSource::deserialize(XmlDeserializer& s) {
    //current format:
    s.deserialize("programModified", programModified_);
    s.deserialize("programFilename", programFilename_);
    programFilename_ = tgt::FileSystem::absolutePath(
        tgt::FileSystem::dirName(s.getDocumentPath())) + "/" + programFilename_;
    if (programModified_)
        s.deserialize("programSource", programSource_);
}
void OctreeBrickPoolManagerDiskLimitedRam::deserialize(XmlDeserializer& s) {
    OctreeBrickPoolManagerDisk::deserialize(s);

    s.deserialize("maxRamUsed", maxRamUsed_);
    s.deserialize("nextVirtualMemoryAddress", nextVirtualMemoryAddress_);

    //set brick vector of buffers in the ram
    brickBuffersInRAM_ = std::vector<brickBufferInRAM>(maxRamUsed_/getBrickBufferSizeInBytes(),brickBufferInRAM());
    bricksOfBuffersInUsage_ = std::vector<size_t>(maxRamUsed_/getBrickBufferSizeInBytes(),0);
}
Exemple #14
0
void FaceGeometry::deserialize(XmlDeserializer& s) {
    s.deserialize("vertices", vertices_);
    try {
        s.deserialize("normal", normal_);
        normalIsSet_ = true;
    }
    catch (...) {
        s.removeLastError();
        normalIsSet_ = false;
    }
    setHasChanged(true);
}
void VolumeURLProperty::deserialize(XmlDeserializer& s) {
    std::string relativeURL;
    s.deserialize("url", relativeURL);
    if (relativeURL.empty())
        value_ = "";
    else {
        std::string basePath = tgt::FileSystem::dirName(s.getDocumentPath());
        value_ = VolumeURL::convertURLToAbsolutePath(relativeURL, basePath);
    }

    Property::deserialize(s);
}
Exemple #16
0
void TransFunc1DKeys::deserialize(XmlDeserializer& s) {
    TransFunc::deserialize(s);

    // deserialize keys...
    s.deserialize("Keys", keys_, "key");

    // deserialize thresholds...
    s.deserialize("lower", lowerThreshold_);
    s.deserialize("upper", upperThreshold_);

    s.optionalDeserialize("domain", domain_, tgt::vec2(0.0f, 1.0f));
}
Exemple #17
0
void OptionPropertyBase::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    std::string id;
    s.deserialize("value", id);
    try {
        select(id);
    }
    catch (Condition::ValidationFailed& /*e*/) {
        s.addError("Invalid option value: " + id);
    }
}
void ColorMapProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    ColorMap cm = ColorMap::createColdHot();
    s.deserialize("colors", cm);
    try {
        value_ = cm;
    }
    catch (Condition::ValidationFailed& e) {
        s.addError(e);
    }
}
void PlotEntitiesProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    int value, loadStrategy;
    s.deserialize("entities", value);
    entities_ = static_cast<PlotEntitySettings::Entity>(value);
    s.deserialize("xCI", xColumnIndex_);
    s.deserialize("yCI", yColumnIndex_);
    s.deserialize("colorMap", colorMap_);
    s.deserialize("plotEntitySettingsVector", value_, "plotEntitySettings");
    s.deserialize("loadStrategy",loadStrategy);
    loadStrategy_ = static_cast<PlotEntitiesProperty::loadStrategy>(loadStrategy);
}
Exemple #20
0
void PropertyState::applyStateToProperty(Property* prop) const {
    tgtAssert(prop->getOwner()->getName() == propertyOwner_, "Property owner's name is different");
    tgtAssert(prop->getGuiName() == propertyName_, "Property's name is different");
    tgtAssert(prop->getID() == propertyID_, "Property's ID is different");

    XmlDeserializer d;

    std::stringstream stream(propertyValue_);
    d.read(stream);

    prop->deserializeValue(d);
    prop->invalidate();
}
void TemplatePropertyTimeline<Camera>::deserialize(XmlDeserializer& s) {
    s.deserialize("activeOnRendering", activeOnRendering_);
    PropertyOwner* propertyOwner = 0;
    s.deserialize("propertyOwner", propertyOwner);
    std::string propertyId;
    s.deserialize("propertyId", propertyId);
    if (propertyOwner)
        property_ = dynamic_cast<CameraProperty*>(propertyOwner->getProperty(propertyId));
    else
        LERRORC("TemplatePropertyTimeline<Camera>", "deserialize(): no property owner");
    s.deserialize("duration", duration_);
    s.deserialize("timeline", timeline_);
}
Exemple #22
0
void VolumeHistogramIntensity::deserialize(XmlDeserializer& s) {
    try {
        s.deserialize("histograms", histograms_, "channel");
    }
    catch (SerializationException& /*e*/) {
        // try to deserialize old format (single channel)
        Histogram1D hist;
        s.deserialize("histogram", hist);

        histograms_.clear();
        histograms_.push_back(hist);
    }
}
void LightSourceProperty::deserialize(XmlDeserializer& s) {
    FloatVec4Property::deserialize(s);
    try {
        s.deserialize("Center", curCenter_);
        s.deserialize("LightPos", lightPos_);
        s.deserialize("FollowCam", followCam_);
        s.deserialize("MaxDist", maxDist_);
    }
    catch(SerializationException&) {
        // TODO necessary?
        lightPos_ = tgt::vec4(get().xyz(), 1.f);
        s.removeLastError();
    }
}
void AnimatedProcessor::deserialize(XmlDeserializer& s) {
    s.deserialize("processor", processor_);
    s.deserialize("properties", properties_, "Property");

    // We need to remove timelines for properties that do not exist (any more)
    std::vector<PropertyTimeline*>::iterator it = properties_.begin();
    while (it != properties_.end()) {
        if ((*it)->getProperty() == 0) {
            delete *it;
            it = properties_.erase(it);
        } else {
            ++it;
        }
    }
}
void TransFuncProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    TransFunc* tf = 0;
    s.deserialize("TransferFunction", tf);
    set(tf);

    try {
        int fittingStrategy = domainFittingStrategy_;
        s.deserialize("domainFittingStrategy", fittingStrategy);
        domainFittingStrategy_ = (DomainAutoFittingStrategy)fittingStrategy;
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }
}
Exemple #26
0
/**
 * Tests that deserialization of not serialized data attempt
 * leads to an @c XmlSerializationNoSuchDataException.
 */
void testNoSuchDataException() {
    std::stringstream stream;

    XmlSerializer s;
    s.write(stream);

    XmlDeserializer d;
    d.read(stream);
    int i;
    try {
        d.deserialize("NotExistentKey", i);
        test(false, "No exception on deserialization of not existent key");
    }
    catch (XmlSerializationNoSuchDataException&) {
    }
}
Exemple #27
0
void PropertyVector::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    // deserialize the properties of the processor
    typedef std::map<std::string, Property*> PropertyMapType;

    PropertyMapType propertyMap;
    for (std::vector<Property*>::const_iterator it = properties_.begin(); it != properties_.end(); ++it) {
        propertyMap[(*it)->getID()] = *it;
    }

    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);
    s.deserialize("ElementProperties", propertyMap, "Property", "name");
    s.setUsePointerContentSerialization(usePointerContentSerialization);
}
Exemple #28
0
void EventPropertyBase::deserialize(XmlDeserializer& s) {

    Property::deserialize(s);

    try {
        bool enabled, shareEvents;
        s.deserialize("enabled", enabled);
        s.deserialize("shareEvents", shareEvents);
        enabled_ = enabled;
        shareEvents_ = shareEvents;
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    try {
        int mouseAction = 0;
        int mouseButtons = 0;
        s.deserialize("mouseAction", mouseAction);
        s.deserialize("mouseButtons", mouseButtons);
        mouseAction_ = static_cast<tgt::MouseEvent::MouseAction>(mouseAction);
        mouseButtons_ = static_cast<tgt::MouseEvent::MouseButtons>(mouseButtons);
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    try {
        int keyCode = 0;
        s.deserialize("keyCode", keyCode);
        keyCode_ = static_cast<tgt::KeyEvent::KeyCode>(keyCode);
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    try {
        int modifier = 0;
        s.deserialize("modifier", modifier);
        modifier_ = static_cast<tgt::Event::Modifier>(modifier);
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    notifyChangeListener();
}
Exemple #29
0
void PropertyOwner::deserialize(XmlDeserializer& s) {
    // create temporary property map for deserialization
    std::map<std::string, Property*> propertyMap;
    for (std::vector<Property*>::const_iterator it = properties_.begin(); it != properties_.end(); ++it)
        propertyMap[(*it)->getID()] = *it;

    // deserialize properties
    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);
    try {
        s.deserialize("Properties", propertyMap, "Property", "name");
    }
    catch (SerializationException& e) {
        LWARNING(e.what());
    }
    s.setUsePointerContentSerialization(usePointerContentSerialization);
}
void  OctreeBrickPoolManagerDisk::deserialize(XmlDeserializer& s) {
    OctreeBrickPoolManagerBase::deserialize(s);

    s.deserialize("maxSingleBufferSizeBytes", maxBufferSizeBytes_);
    s.deserialize("singleBufferSizeBytes",    singleBufferSizeBytes_);
    s.deserialize("numBrickSlotsPerBuffer", numBrickSlotsPerBuffer_);

    s.deserialize("bufferFiles", bufferFiles_);
    s.deserialize("brickPoolPath", brickPoolPath_);
    s.deserialize("bufferFilePrefix", bufferFilePrefix_);

    s.deserialize("nextVirtualMemoryAddress", nextVirtualMemoryAddress_);

    // check brick pool path
    if (!tgt::FileSystem::dirExists(brickPoolPath_))
        throw VoreenException("Brick pool path does not exist: " + brickPoolPath_);

    // make sure that buffer files are present
    if (bufferFiles_.empty())
        throw VoreenException("No brick buffer files");
    for (size_t i=0; i<bufferFiles_.size(); i++) {
        if (!tgt::FileSystem::fileExists(bufferFiles_.at(i)))
            throw VoreenException("Missing brick buffer file: " + bufferFiles_.at(i));
    }

    // check ram limit vs. buffer size
    if (2*singleBufferSizeBytes_ > ramLimitInBytes_)
        throw VoreenException("RAM memory limit is smaller than two times the size of a buffer. At least two buffer files have to fit in the RAM. "
            "[" + itos(ramLimitInBytes_) + " bytes < 2*" + itos(singleBufferSizeBytes_) + " bytes]");

    // init buffer vector
    maxNumBuffersInRAM_ = ramLimitInBytes_/singleBufferSizeBytes_;
    for (size_t i = 0; i < bufferFiles_.size(); i++)
        bufferVector_.push_back(new BufferEntry(numBrickSlotsPerBuffer_, 0, 0));
}