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 5.81 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
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

#include "genericimagereader.h"

#include <fstream>

29
#include "cgt/filesystem.h"
30
31
32
33
34
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationdisk.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
#include "core/tools/textfileparser.h"

35
#include "modules/io/processors/amirameshreader.h"
36
37
38
39
40
41
#include "modules/io/processors/csvdimagereader.h"
#include "modules/io/processors/ltfimagereader.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/io/processors/niftiimagereader.h"
#include "modules/io/processors/rawimagereader.h"
#include "modules/io/processors/vtkimagereader.h"
42
43

namespace campvis {
44
45
46
47
48
49
50
51
52
53
54
55
56
    namespace {
        struct checkExtension {
            checkExtension(const std::string& str) : _str(str) {}

            bool operator()(const std::pair<AbstractImageReader*, MetaProperty*>& v) const { 
                return v.first->acceptsExtension(this->_str); 
            }

        private:
            std::string _str;
        };
    }

Hossain Mahmud's avatar
Hossain Mahmud committed
57
    const std::string GenericImageReader::loggerCat_ = "CAMPVis.modules.io.GenericImageReader";
58
59
60

    GenericImageReader::GenericImageReader() 
        : AbstractProcessor()
61
62
        , p_url("Url", "Image URL", "", StringProperty::OPEN_FILENAME)
        , p_targetImageID("TargetImageName", "Target Image ID", "AbstractImageReader.output", DataNameProperty::WRITE)
63
        , _currentlyVisible(nullptr)
64
65
    {
        addProperty(p_url);
66
        addProperty(p_targetImageID);
67
68
        p_url.s_changed.connect(this, &GenericImageReader::onUrlPropertyChanged);

69
        addReader(new AmiraMeshReader());        
70
71
72
73
74
75
        addReader(new CsvdImageReader());        
        addReader(new LtfImageReader());
        addReader(new MhdImageReader());
        addReader(new NiftiImageReader());
        addReader(new RawImageReader());
        addReader(new VtkImageReader());
76

77
#ifdef CAMPVIS_HAS_MODULE_DEVIL
78
        addReader(new DevilImageReader());
79
#endif
80
81
82
    }
    
    GenericImageReader::~GenericImageReader() {
83
        for (auto it = _readers.begin(); it != _readers.end(); ++it) {
84
85
86
            delete it->second;
            delete it->first;
        }
87
88
89
90
91
92
93
    }

    void GenericImageReader::init() {

    }

    void GenericImageReader::deinit() {
94
        for(std::map<AbstractImageReader*, MetaProperty*>::iterator it = _readers.begin(); it != _readers.end(); ++it) {
95
96
97
98
99
100
            // deinit MetaProperty first!
            if (nullptr != it->second) {
                it->second->deinit();
            }
            // then we can delete the reader!
            if (nullptr != it->first) {
101
                it->first->deinit();
102
            }
103
104
105
106
        }
    }

    void GenericImageReader::updateResult(DataContainer& data) {
107
108
109
110
        const std::string extension = cgt::FileSystem::fileExtension(p_url.getValue());
        auto it = findReader(extension);

        if (it != this->_readers.end()) {
111
            it->first->process(data);
112
113
114
        }
    }

115
116
117
118
119
120
121
122
123
    void GenericImageReader::updateVisibility(const std::string& extension) {
        if (_currentlyVisible != nullptr) {
            _currentlyVisible->setVisible(false);
            _currentlyVisible = nullptr;
        }

        auto it = findReader(extension);
        if (it != this->_readers.end()) {
            it->second->setVisible(true);
124
125
126
127
            this->_currentlyVisible = it->second;
        }
    }

128
    void GenericImageReader::addReader(AbstractImageReader* reader) {
129
        MetaProperty* meta = new MetaProperty(reader->getName() + "MetaProp", reader->getName());
130
        meta->addPropertyCollection(*reader);
131
        meta->setVisible(false);
132
        this->addProperty(*meta);
133

134
135
136
137
        p_url.addSharedProperty(&reader->p_url);
        reader->p_url.setVisible(false);
        p_targetImageID.addSharedProperty(&reader->p_targetImageID);
        reader->p_targetImageID.setVisible(false);
138

139
        _readers.insert(std::pair<AbstractImageReader*, MetaProperty*>(reader, meta));
140
141
    }

Hossain Mahmud's avatar
Hossain Mahmud committed
142
    void GenericImageReader::onUrlPropertyChanged(const AbstractProperty* prop) {
143
        // now update extension
144
145
        std::string extension = cgt::FileSystem::fileExtension(p_url.getValue());
        updateVisibility(extension);
146
147
    }

148
149
150
151
    std::map<AbstractImageReader*, MetaProperty*>::const_iterator GenericImageReader::findReader(const std::string& extension) const {
        auto it = std::find_if(_readers.begin(), _readers.end(), checkExtension(extension));
        if (it == _readers.end())
            it = std::find_if(_readers.begin(), _readers.end(), checkExtension("raw"));
152

153
        return it;
154
155
    }

156
}