Example #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;
}
Example #2
0
void FileDialogProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    // An empty serialized value does not necessarily mean that it wasn't set, but could also mean that it was the
    // same path as the document path passed during serialization, which makes the relative path empty.  We need an
    // extra bool to remember if this was the case.
    try {
        bool noPathSet;
        s.deserialize("noPathSet", noPathSet);
        if(noPathSet) {
            set("");
            return;
        }
    }
    catch (XmlSerializationNoSuchDataException) {
        s.removeLastError();
    }

    std::string value;
    s.deserialize("value", value);

    // convert path relative to the document's path to an absolute one
    if (!s.getDocumentPath().empty())
        value = tgt::FileSystem::absolutePath(tgt::FileSystem::dirName(s.getDocumentPath()) + "/" + value);

    try {
        set(value);
    }
    catch (Condition::ValidationFailed& e) {
        s.addError(e);
    }
}
Example #3
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_);
}
Example #4
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);
}
Example #5
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));
    }
}
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();
}
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);
}
Example #8
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_);
}
Example #9
0
/**
 * Tests serialization and deserialization of tgt types.
 */
void testTgtData() {
    tgt::vec2 v2(1.0f, 2.0f);
    tgt::vec3 v3(3.0f, 4.0f, 5.0f);
    tgt::vec4 v4(6.0f, 7.0f, 8.0f, 9.0f);

    tgt::ivec2 iv2(1, 2);
    tgt::ivec3 iv3(3, 4, 5);
    tgt::ivec4 iv4(6, 7, 8, 9);

    std::stringstream stream;

    XmlSerializer s;
    s.serialize("v2", v2);
    s.serialize("v3", v3);
    s.serialize("v4", v4);
    s.serialize("iv2", iv2);
    s.serialize("iv3", iv3);
    s.serialize("iv4", iv4);
    s.write(stream);

    // Reset all variables to default values...
    v2 = tgt::vec2(0.0f, 0.0f);
    v3 = tgt::vec3(0.0f, 0.0f, 0.0f);
    v4 = tgt::vec4(0.0f, 0.0f, 0.0f, 0.0f);

    iv2 = tgt::ivec2(0, 0);
    iv3 = tgt::ivec3(0, 0, 0);
    iv4 = tgt::ivec4(0, 0, 0, 0);

    XmlDeserializer d;
    d.read(stream);
    d.deserialize("v2", v2);
    d.deserialize("v3", v3);
    d.deserialize("v4", v4);
    d.deserialize("iv2", iv2);
    d.deserialize("iv3", iv3);
    d.deserialize("iv4", iv4);

    test(v2.x, 1.0f, "v2.x incorrect deserialized");
    test(v2.y, 2.0f, "v2.y incorrect deserialized");
    test(v3.x, 3.0f, "v3.x incorrect deserialized");
    test(v3.y, 4.0f, "v3.y incorrect deserialized");
    test(v3.z, 5.0f, "v3.z incorrect deserialized");
    test(v4.x, 6.0f, "v4.x incorrect deserialized");
    test(v4.y, 7.0f, "v4.y incorrect deserialized");
    test(v4.z, 8.0f, "v4.z incorrect deserialized");
    test(v4.w, 9.0f, "v4.w incorrect deserialized");

    test(iv2.x, 1, "iv2.x incorrect deserialized");
    test(iv2.y, 2, "iv2.y incorrect deserialized");
    test(iv3.x, 3, "iv3.x incorrect deserialized");
    test(iv3.y, 4, "iv3.y incorrect deserialized");
    test(iv3.z, 5, "iv3.z incorrect deserialized");
    test(iv4.x, 6, "iv4.x incorrect deserialized");
    test(iv4.y, 7, "iv4.y incorrect deserialized");
    test(iv4.z, 8, "iv4.z incorrect deserialized");
    test(iv4.w, 9, "iv4.w incorrect deserialized");
}
Example #10
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);
}
Example #12
0
/**
 * Tests serialization and deserialization of user defined data classes which realizes
 * the @c Serializable interface.
 */
void testUserDefinedData() {
    UserDefinedData d;
    d.data = 1;
    UserDefinedData* dp = &d;
    UserDefinedData* dp2 = new UserDefinedData();
    dp2->data = 2;

    UserDefinedDataContainer dc;
    dc.data.data = 3;
    dc.datap = &dc.data;

    std::stringstream stream;

    try {
        XmlSerializer s;
        s.serialize("d", d);
        s.serialize("dp", dp);
        s.serialize("dp2", dp2);
        s.serialize("dc", dc);
        s.write(stream);
        delete dp2;
    }
    catch (...) {
        delete dp2;
        throw;
    }

    // Reset all variables to default values...
    d.data = 0;
    dp = 0;
    dp2 = 0;
    dc.data.data = 0;
    dc.datap = 0;

    XmlDeserializer de;
    de.read(stream);
    de.deserialize("d", d);
    de.deserialize("dp", dp);
    de.deserialize("dp2", dp2);
    de.deserialize("dc", dc);

    test(d.data, 1, "d incorrect deserialized");

    test(dp != 0, "dp still null");
    test(dp == &d, "dp does not point to d");

    test(dp2 != 0, "dp2 still null");
    test(dp2->data, 2, "dp2 incorrect deserialized");

    delete dp2;

    test(dc.data.data, 3, "dc incorrect deserialized");
    test(dc.datap != 0, "dc.datap still null");
    test(dc.datap == &dc.data, "dc.datap does not point to dc.data");
}
Example #13
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));
}
Example #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);
}
Example #15
0
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);
}
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_);
}
Example #17
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);
    }
}
Example #18
0
void Workspace::deserialize(XmlDeserializer& s) {
    // clear existing network and containers
    clear();

    try {
        s.deserialize("readonly", readOnly_);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
        readOnly_ = false;
    }

    // Deserialize network...
    s.deserialize("ProcessorNetwork", network_);

    // Deserialize animation if present...
    try {
        s.deserialize("Animation", animation_);
    } catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }

    if (animation_) {
        animation_->setNetwork(network_);

        // register this as observer on all propertytimelines for undo/redo
        const std::vector<AnimatedProcessor*> animproc = this->animation_->getAnimatedProcessors();
        std::vector<AnimatedProcessor*>::const_iterator it;
        for (it = animproc.begin();it != animproc.end();it++)
        {
            const std::vector<PropertyTimeline*> timelines = (*it)->getPropertyTimelines();
            std::vector<PropertyTimeline*>::const_iterator it2;
            for (it2 = timelines.begin();it2 != timelines.end(); ++it2) {
                (*it2)->registerUndoObserver(this->animation_);
            }
        }

        // register this as observer in the processornetwork to register added and removed processors
        ProcessorNetwork* net = const_cast<ProcessorNetwork*>(network_);
        net->addObserver(this->animation_);
    }

    try {
        s.deserialize("GlobalDescription", description_);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
        description_ = "";
    }
}
Example #19
0
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();
    }
}
Example #20
0
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;
        }
    }
}
Example #21
0
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();
    }
}
Example #22
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;
}
Example #23
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");
}
Example #24
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");
}
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));
}
Example #26
0
void PortConnection::PortEntry::deserialize(XmlDeserializer& s) {
    std::string name;
    Processor* processor;

    s.deserialize("name", name);
    s.deserialize("Processor", processor);

    // Was processor not deserialized?
    if (!processor)
        // Cancel port search, since we are not able to proceed...
        return;

    std::vector<Port*> ports = processor->getPorts();
    for (size_t i=0; i<ports.size(); ++i) {
        if (ports[i]->getID() == name) {
            port_ = ports[i];
            break;
        }
    }
}
Example #27
0
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);
    }
}
Example #28
0
void NumericProperty<T>::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    // deserialize value
    T value;
    s.deserialize("value", value);
    try {
        set(value);
    }
    catch (Condition::ValidationFailed& e) {
        s.addError(e);
    }

    // deserialize tracking mode, if available
    try {
        s.deserialize("tracking", tracking_);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }
}
Example #29
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 MutualInformationRegistration::deserialize(XmlDeserializer& s) {
    VolumeProcessor::deserialize(s);

    ParametersType parameters = transform_->GetParameters();
    ParametersType fixedParameters = transform_->GetFixedParameters();

    std::vector<double> params;
    std::vector<double> fixedParams;

    s.deserialize("parameters", params);
    s.deserialize("fixedParameters", fixedParams);

    for(size_t i=0; i<parameters.GetSize(); i++)
        parameters[i] = params[i];

    for(size_t i=0; i<fixedParameters.GetSize(); i++)
        fixedParameters[i] = fixedParams[i];

    transform_->SetParameters(parameters);
    transform_->SetFixedParameters(fixedParameters);
}