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

pointpredicateevaluator.cpp 8.01 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//      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 "pointpredicateevaluator.h"
26
27
28
#include "cgt/logmanager.h"
#include "cgt/shadermanager.h"
#include "cgt/textureunit.h"
29

30
#include "core/datastructures/cameradata.h"
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/renderdata.h"
#include "core/pipeline/processordecoratorbackground.h"

#include "core/classification/simpletransferfunction.h"
#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"

#include "core/tools/quadrenderer.h"

namespace campvis {
    const std::string PointPredicateEvaluator::loggerCat_ = "CAMPVis.modules.vis.PointPredicateEvaluator";


    PointPredicateEvaluator::PointPredicateEvaluator(IVec2Property* viewportSizeProp)
        : VisualizationProcessor(viewportSizeProp)
        , p_inputImage("InputImage", "Input Image", "", DataNameProperty::READ)
        , p_inputLabels("InputLabels", "Input Label Image", "", DataNameProperty::READ)
        , p_inputSnr("InputSnr", "Input SNR", "", DataNameProperty::READ)
        , p_inputVesselness("InputVesselness", "Input Vesselness", "", DataNameProperty::READ)
        , p_inputConfidence("InputConfidence", "Input Confidence", "", DataNameProperty::READ)
53
        , p_camera("Camera", "Camera ID", "camera", DataNameProperty::READ)
54
55
56
57
58
59
60
61
62
        , p_outputImage("OutputImage", "Output Image", "predicatemask", DataNameProperty::WRITE)
        , p_histogram("PredicateHistogram", "Point Predicate Histogram")
        , _shader(0)
    {
        addProperty(p_inputImage, INVALID_PROPERTIES | INVALID_RESULT);
        addProperty(p_inputLabels, INVALID_PROPERTIES | INVALID_RESULT);
        addProperty(p_inputSnr);
        addProperty(p_inputVesselness);
        addProperty(p_inputConfidence);
63
        addProperty(p_camera);
64
65
66
67
68
69
70
71
72
73
        addProperty(p_outputImage);

        addProperty(p_histogram);
    }

    PointPredicateEvaluator::~PointPredicateEvaluator() {

    }

    void PointPredicateEvaluator::init() {
74
        p_histogram.getPredicateHistogram()->setPredicateFunctionArgumentString("in float intensity, in float gradientMagnitude, in float gradientAngle, float viewAngle, in float snr, in float vesselness, in float confidence, in uint label");
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        VisualizationProcessor::init();

        _shader = ShdrMgr.loadWithCustomGlslVersion("core/glsl/passthrough.vert", "", "modules/advancedusvis/glsl/pointpredicateevaluator.frag", generateHeader(), "400");
        p_histogram.s_headerChanged.connect(this, &PointPredicateEvaluator::onHistogramHeaderChanged);
    }

    void PointPredicateEvaluator::deinit() {
        p_histogram.s_headerChanged.disconnect(this);
        ShdrMgr.dispose(_shader);
        VisualizationProcessor::deinit();
    }

    void PointPredicateEvaluator::updateResult(DataContainer& dataContainer) {
        ImageRepresentationGL::ScopedRepresentation img(dataContainer, p_inputImage.getValue());
        ImageRepresentationGL::ScopedRepresentation labels(dataContainer, p_inputLabels.getValue());
        ImageRepresentationGL::ScopedRepresentation snr(dataContainer, p_inputSnr.getValue());
        ImageRepresentationGL::ScopedRepresentation vesselness(dataContainer, p_inputVesselness.getValue());
        ImageRepresentationGL::ScopedRepresentation confidence(dataContainer, p_inputConfidence.getValue());

        if (img && labels && snr && vesselness && confidence) {
95
96
            const cgt::svec3& size = img->getSize();
            cgt::ivec2 viewportSize = size.xy();
97

98
            cgt::TextureUnit inputUnit, labelUnit, snrUnit, vesselnessUnit, confidenceUnit;
99
100
            inputUnit.activate();

101
102
103
            const cgt::Texture* tex = img->getTexture();
            if (tex->getFilter() != cgt::Texture::MIPMAP) {
                const_cast<cgt::Texture*>(tex)->setFilter(cgt::Texture::MIPMAP);
104
105
106
107
108
109
110
111
112
113
                LGL_ERROR;
                glGenerateMipmap(GL_TEXTURE_3D);
                LGL_ERROR;
                glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                LGL_ERROR;
                glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
                LGL_ERROR;
            }

            // create texture for result
114
            cgt::Texture* resultTexture = new cgt::Texture(GL_TEXTURE_3D, cgt::ivec3(size), GL_R8UI, cgt::Texture::NEAREST);
115
            resultTexture->setWrapping(cgt::Texture::CLAMP_TO_EDGE);
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

            // activate shader and bind textures
            _shader->activate();
            _shader->setIgnoreUniformLocationError(true);
            p_histogram.getPredicateHistogram()->setupRenderShader(_shader);
            _shader->setIgnoreUniformLocationError(false);

            img->bind(_shader, inputUnit);
            labels->bind(_shader, labelUnit, "_labels", "_labelsParams");
            snr->bind(_shader, snrUnit, "_snr", "_snrParams");
            vesselness->bind(_shader, vesselnessUnit, "_vesselness", "_vesselnessParams");
            confidence->bind(_shader, confidenceUnit, "_confidence", "_confidenceParams");

            // activate FBO and attach texture
            _fbo->activate();
            glViewport(0, 0, static_cast<GLsizei>(viewportSize.x), static_cast<GLsizei>(viewportSize.y));

            // render quad to compute difference measure by shader
            for (int z = 0; z < static_cast<int>(size.z); ++z) {
                float zTexCoord = static_cast<float>(z)/static_cast<float>(size.z) + .5f/static_cast<float>(size.z);
                _shader->setUniform("_zTexCoord", zTexCoord);
                _fbo->attachTexture(resultTexture, GL_COLOR_ATTACHMENT0, 0, z);
                QuadRdr.renderQuad();
            }

            _fbo->detachAll();
            _fbo->deactivate();
            _shader->deactivate();

            // put resulting image into DataContainer
            ImageData* id = new ImageData(3, size, 1);
            ImageRepresentationGL::create(id, resultTexture);
            id->setMappingInformation(img->getParent()->getMappingInformation());
            dataContainer.addData(p_outputImage.getValue(), id);
            
151
            cgt::TextureUnit::setZeroUnit();
152
153
154
            LGL_ERROR;
        }
        else {
155
            LDEBUG("No suitable input image found.");
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
        }
    }

    void PointPredicateEvaluator::updateProperties(DataContainer dataContainer) {
    }

    std::string PointPredicateEvaluator::generateHeader() const {
        std::string toReturn = p_histogram.getPredicateHistogram()->getGlslHeader();
        return toReturn;
    }

    void PointPredicateEvaluator::onHistogramHeaderChanged() {
        invalidate(INVALID_SHADER);
    }

    void PointPredicateEvaluator::updateShader() {
        _shader->setHeaders(generateHeader());
        _shader->rebuild();
    }

}