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

devilimagereader.cpp 6.03 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
schultezub's avatar
schultezub committed
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
10
// 
schultezub's avatar
schultezub committed
11
12
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
13
14
15
16
// 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
schultezub's avatar
schultezub committed
17
// 
18
19
20
21
// 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.
schultezub's avatar
schultezub committed
22
23
24
25
26
27
28
29
30
31
32
// 
// ================================================================================================

#include "devilimagereader.h"


#include <IL/il.h>
#include <cstring>

#include "tgt/logmanager.h"
#include "tgt/filesystem.h"
33
#include "tgt/shadermanager.h"
schultezub's avatar
schultezub committed
34
#include "tgt/texturereaderdevil.h"
35
#include "tgt/textureunit.h"
schultezub's avatar
schultezub committed
36

37
38
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationgl.h"
39
#include "core/datastructures/renderdata.h"
40
#include "core/datastructures/genericimagerepresentationlocal.h"
schultezub's avatar
schultezub committed
41

42
43
#include "core/tools/quadrenderer.h"

schultezub's avatar
schultezub committed
44
45
46
47

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

48
49
50
51
52
53
    GenericOption<std::string> importOptions[3] = {
        GenericOption<std::string>("rt", "Render Target"),
        GenericOption<std::string>("texture", "OpenGL Texture"),
        GenericOption<std::string>("localIntensity", "Local Intensity Image")
    };

54
55
    DevilImageReader::DevilImageReader(IVec2Property* viewportSizeProp)
        : VisualizationProcessor(viewportSizeProp)
schultezub's avatar
schultezub committed
56
57
        , p_url("url", "Image URL", "")
        , p_targetImageID("targetImageName", "Target Image ID", "DevilImageReader.output", DataNameProperty::WRITE)
58
        , p_importType("ImportType", "Import Type", importOptions, 3)
59
60
        , _shader(nullptr)
        , _devilTextureReader(nullptr)
schultezub's avatar
schultezub committed
61
62
63
    {
        addProperty(&p_url);
        addProperty(&p_targetImageID);
64
        addProperty(&p_importType);
schultezub's avatar
schultezub committed
65
66
67
68
69
70
71
72

        _devilTextureReader = new tgt::TextureReaderDevil();
    }

    DevilImageReader::~DevilImageReader() {
        delete _devilTextureReader;
    }

73
74
    void DevilImageReader::init() {
        VisualizationProcessor::init();
75
        _shader = ShdrMgr.load("core/glsl/passthrough.vert", "core/glsl/copyimage.frag", "#define NO_DEPTH\n");
76
77
78
79
80
81
82
83
84
        _shader->setAttributeLocation(0, "in_Position");
        _shader->setAttributeLocation(1, "in_TexCoord");
    }

    void DevilImageReader::deinit() {
        VisualizationProcessor::deinit();
        ShdrMgr.dispose(_shader);
    }

85
    void DevilImageReader::updateResult(DataContainer& data) {
schultezub's avatar
schultezub committed
86
87
        tgt::Texture* tex = _devilTextureReader->loadTexture(p_url.getValue(), tgt::Texture::LINEAR, false, true, true, false);
        if (tex != 0) {
88
            if (p_importType.getOptionValue() == "rt") {
89
90
91
                ImageData id (2, tex->getDimensions(), tex->getNumChannels());
                ImageRepresentationGL* image = ImageRepresentationGL::create(&id, tex);

92
                FramebufferActivationGuard fag(this);
93
94
95
                createAndAttachColorTexture();
                createAndAttachDepthTexture();

96
97
                _shader->activate();
                _shader->setIgnoreUniformLocationError(true);
98
99
                _shader->setUniform("_viewportSize", getEffectiveViewportSize());
                _shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(getEffectiveViewportSize()));
100
101
102
103
104
105
106
107
108
109
110
111
                _shader->setIgnoreUniformLocationError(false);
                tgt::TextureUnit texUnit;

                image->bind(_shader, texUnit, "_colorTexture");

                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                QuadRdr.renderQuad();

                _shader->deactivate();
                tgt::TextureUnit::setZeroUnit();
                LGL_ERROR;

112
                data.addData(p_targetImageID.getValue(), new RenderData(_fbo));
113
            }
114
            else if (p_importType.getOptionValue() == "texture") {
115
116
117
118
                ImageData* id = new ImageData(2, tex->getDimensions(), tex->getNumChannels());
                ImageRepresentationGL::create(id, tex);
                data.addData(p_targetImageID.getValue(), id);
            }
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
            else if (p_importType.getOptionValue() == "localIntensity") {
                // TODO: Clean up pre-MICCAI mess!
                glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
                tex->downloadTexture();
                size_t numElements = tgt::hmul(tex->getDimensions());
                ImageData* id = new ImageData(2, tex->getDimensions(), 1);

                // TODO: use macro magic to switch through the different data types and number of channels
                if (tex->getDataType() == GL_UNSIGNED_BYTE && tex->getNumChannels() == 3) {
                    tgt::Vector3<uint8_t>* data = reinterpret_cast<tgt::Vector3<uint8_t>*>(tex->getPixelData());
                    uint8_t* copy = new uint8_t[numElements];
                    for (size_t i = 0; i < numElements; ++i) {
                        copy[i] = data[i].x;
                    }
                    GenericImageRepresentationLocal<uint8_t, 1>::create(id, copy);
                }

                delete tex;
                data.addData(p_targetImageID.getValue(), id);
            }
schultezub's avatar
schultezub committed
139
        }
schultezub's avatar
schultezub committed
140
141
        else {
            LERROR("Could not load image.");
schultezub's avatar
schultezub committed
142
143
        }

144
        validate(INVALID_RESULT);
schultezub's avatar
schultezub committed
145
146
    }
}