Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

genericimagereader.cpp 7.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

#include "genericimagereader.h"

#include <fstream>

#include "tgt/filesystem.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationdisk.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
#include "core/tools/textfileparser.h"


namespace campvis {
    const std::string GenericImageReader::loggerCat_ = "CAMPVis.modules.io.MhdImageReader";

    GenericImageReader::GenericImageReader() 
        : AbstractProcessor()
        , p_url("url", "Image URL", "")
47
    {
48
49
50
        addProperty(&p_url);
        p_url.s_changed.connect(this, &GenericImageReader::onUrlPropertyChanged);

51
52
53
54
55
56
        this->addReader(new CsvdImageReader());        
        this->addReader(new LtfImageReader());
        this->addReader(new MhdImageReader());
        this->addReader(new RawImageReader());
        this->addReader(new VtkImageReader());

57

58
59
60
61
        this->_ext = "";
        this->_currentlyVisible = nullptr;
    }
    
62
63
64
    GenericImageReader::~GenericImageReader() {
    }

65
66
67
68
69
    void GenericImageReader::init() {

    }

    void GenericImageReader::deinit() {
70
        for(std::map<AbstractImageReader*, MetaProperty*>::iterator it = this->_readers.begin(); it != this->_readers.end(); ++it) {
71
72
73
74
            if (nullptr != it->first) delete it->first;
            if (nullptr != it->second) delete it->second;
        }
    }
75
    void GenericImageReader::updateResult(DataContainer& data) {
76
77
        std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(this->_ext));
        if(it != this->_readers.end()) {
78
79
80
81
82
83
            if (this->_currentlyVisible != it->second) {
                if(nullptr != this->_currentlyVisible) {
                    this->_currentlyVisible->setVisible(false);
                }
                (it->second)->setVisible(true);
                this->_currentlyVisible = it->second;
84
            }
85
            (it->first)->process(data);
86
87
88
        }
        return;
    }
89
90
    void GenericImageReader::setVisibibility(const std::string& extention, bool visibility) {
        std::string _ext = extention;
91
        std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(_ext));
92
93
        if(it != this->_readers.end()) {
            if(nullptr != this->_currentlyVisible) {
94
                this->_currentlyVisible->setVisible(!visibility);
95
            }
96
            (it->second)->setVisible(visibility);
97
            this->_currentlyVisible = it->second;
98
            //(it->first)->process(data);
99
100
101
102
103
104
105
106
107
108
109
110
        }
        return;
    }
    void GenericImageReader::setURL(std::string p_url) {
        this->p_url.setValue(p_url);

        std::string url = this->p_url.getValue();
        size_t extPos = url.rfind('.');
        if (extPos != std::string::npos) {
            this->_ext = url.substr(extPos);
        }

111
112
113
        std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(this->_ext));
        if(it != this->_readers.end()) {
            (it->first)->p_url.setValue(this->p_url.getValue());
114
115
116
117
118
119
120
121
122
123
124
125
126
        }
        return;
    }

    void GenericImageReader::setURL(StringProperty p_url) {
        return this->setURL(p_url.getValue());
    }
    
    void GenericImageReader::setURL(const char* p_url) {
        return this->setURL(std::string(p_url));
    }

    void GenericImageReader::setTargetImageId(DataNameProperty& targetImageId) {
127
128
129
130
        std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(this->_ext));
        if(it != this->_readers.end()) {
            (it->first)->p_targetImageID.setValue(targetImageId.getValue());
            std::set<AbstractProperty*> sharedProperties = targetImageId.getSharedProperties();
131
            for(std::set<AbstractProperty*>::iterator jt = sharedProperties.begin(); jt != sharedProperties.end(); ++jt) {
132
                (it->first)->p_targetImageID.addSharedProperty(*jt);
133
134
135
136
137
138
139
140
141
            }
        }
        return;
    }
    
    void GenericImageReader::setTargetImageId(const char* imageId) {
        return this->setTargetImageId(std::string(imageId));
    }
    void GenericImageReader::setTargetImageId(std::string imageId) {
142
143
144
        std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(this->_ext));
        if(it != this->_readers.end()) {
            (it->first)->p_targetImageID.setValue(imageId);
145
146
147
148
149
        }
        return;
    }

    void GenericImageReader::setTargetImageIdSharedProperty(DataNameProperty* sharedProperty) {
150
151
152
        std::map<AbstractImageReader*, MetaProperty*>::iterator it = std::find_if(this->_readers.begin(), this->_readers.end(), checkExt(this->_ext));
        if(it != this->_readers.end()) {
            (it->first)->p_targetImageID.addSharedProperty(sharedProperty);
153
154
155
156
157
158
159
160
        }
        return;
    }

    int GenericImageReader::addReader(AbstractImageReader* reader) {
        MetaProperty* meta = new MetaProperty(reader->getName()+"MetaProp", reader->getName());
        meta->addPropertyCollection(*reader);
        meta->setVisible(false);
161
162
163
164
165
166
167
168
169


        StringProperty* sp = dynamic_cast<StringProperty*>(meta->getProperty("url"));
        tgtAssert(sp != 0, "This should not happen.");
        if (sp != 0) {
            p_url.addSharedProperty(sp);
            sp->setVisible(false);
        }

170
171
172
        this->addProperty(meta);
        this->_readers.insert(std::pair<AbstractImageReader*, MetaProperty*>(reader, meta));
        return 0;
173
174
    }

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
    void GenericImageReader::onUrlPropertyChanged(const AbstractProperty*) {
        // first set visibility of old extension to false
        setVisibibility(_ext, false);

        // now update extension
        const std::string& url = this->p_url.getValue();
        size_t extPos = url.rfind('.');
        if (extPos != std::string::npos) {
            this->_ext = url.substr(extPos);
        }

        // set visibility of new extension's properties to true
        setVisibibility(_ext, true);

    }

    void GenericImageReader::adjustToNewExtension() {

    }

195
}