2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

volumerenderer.cpp 7.13 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-2013, all rights reserved,
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
// 
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
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.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// 
// ================================================================================================

#include "volumerenderer.h"
#include "tgt/logmanager.h"
#include "tgt/shadermanager.h"
#include "tgt/textureunit.h"

#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationgl.h"

#include "core/classification/simpletransferfunction.h"

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

38
39
    VolumeRenderer::VolumeRenderer(IVec2Property* viewportSizeProp)
        : VisualizationProcessor(viewportSizeProp)
40
41
        , p_inputVolume("InputVolume", "Input Volume", "", DataNameProperty::READ, AbstractProcessor::VALID)
        , p_camera("Camera", "Camera", tgt::Camera(), AbstractProcessor::VALID)
42
        , p_outputImage("OutputImage", "Output Image", "vr.output", DataNameProperty::WRITE, AbstractProcessor::VALID)
43
44
        , p_pgProps("PGGProps", "Proxy Geometry Generator", AbstractProcessor::VALID)
        , p_eepProps("EEPProps", "Entry/Exit Points Generator", AbstractProcessor::VALID)
45
        , p_raycasterProps("RaycasterProps", "Raycaster", AbstractProcessor::VALID)
46
        , _pgGenerator()
47
48
        , _eepGenerator(viewportSizeProp)
        , _raycaster(viewportSizeProp)
49
50
51
52
    {
        addProperty(&p_inputVolume);
        addProperty(&_raycaster.p_transferFunction);
        addProperty(&p_outputImage);
53

54
55
56
57
58
59
60
61
62
63
64
65
66
        p_pgProps.addPropertyCollection(_pgGenerator);
        _pgGenerator.p_sourceImageID.setVisible(false);
        _pgGenerator.p_geometryID.setVisible(false);
        addProperty(&p_pgProps);

        p_eepProps.addPropertyCollection(_eepGenerator);
        _eepGenerator.p_lqMode.setVisible(false);
        _eepGenerator.p_camera.setVisible(false);
        _eepGenerator.p_sourceImageID.setVisible(false);
        _eepGenerator.p_geometryID.setVisible(false);
        _eepGenerator.p_entryImageID.setVisible(false);
        _eepGenerator.p_exitImageID.setVisible(false);
        addProperty(&p_eepProps);
67

68
        p_raycasterProps.addPropertyCollection(_raycaster);
69
70
71
72
73
74
        _raycaster.p_lqMode.setVisible(false);
        _raycaster.p_camera.setVisible(false);
        _raycaster.p_sourceImageID.setVisible(false);
        _raycaster.p_entryImageID.setVisible(false);
        _raycaster.p_exitImageID.setVisible(false);
        _raycaster.p_targetImageID.setVisible(false);
75
76
        addProperty(&p_raycasterProps);

77
78
79
80
81
82
83
84
85
86
        // setup shared properties
        p_inputVolume.addSharedProperty(&_pgGenerator.p_sourceImageID);
        p_inputVolume.addSharedProperty(&_eepGenerator.p_sourceImageID);
        p_inputVolume.addSharedProperty(&_raycaster.p_sourceImageID);

        p_camera.addSharedProperty(&_eepGenerator.p_camera);
        p_camera.addSharedProperty(&_raycaster.p_camera);

        p_outputImage.addSharedProperty(&_raycaster.p_targetImageID);

87
        p_inputVolume.s_changed.connect(this, &VolumeRenderer::onPropertyChanged);
88
89
90
91
92
93
94
95
96
97
98
99
    }

    VolumeRenderer::~VolumeRenderer() {

    }

    void VolumeRenderer::init() {
        VisualizationProcessor::init();
        _pgGenerator.init();
        _eepGenerator.init();
        _raycaster.init();

100
101
        p_lqMode.addSharedProperty(&_raycaster.p_lqMode);

102
103
104
105
106
107
        _pgGenerator.s_invalidated.connect(this, &VolumeRenderer::onProcessorInvalidated);
        _eepGenerator.s_invalidated.connect(this, &VolumeRenderer::onProcessorInvalidated);
        _raycaster.s_invalidated.connect(this, &VolumeRenderer::onProcessorInvalidated);
    }

    void VolumeRenderer::deinit() {
108
109
110
111
        _pgGenerator.s_invalidated.disconnect(this);
        _eepGenerator.s_invalidated.disconnect(this);
        _raycaster.s_invalidated.disconnect(this);

112
113
114
        _pgGenerator.deinit();
        _eepGenerator.deinit();
        _raycaster.deinit();
115

116
117
118
119
120
121
        VisualizationProcessor::deinit();
    }

    void VolumeRenderer::process(DataContainer& data) {
        if (getInvalidationLevel() & PG_INVALID) {
            _pgGenerator.process(data);
122
123
            _eepGenerator.process(data);
            _raycaster.process(data);
124
125
126
        }
        else if (getInvalidationLevel() & EEP_INVALID) {
            _eepGenerator.process(data);
127
            _raycaster.process(data);
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
        }
        else if (getInvalidationLevel() & RAYCASTER_INVALID) {
            _raycaster.process(data);
        }

        validate(INVALID_RESULT | PG_INVALID | EEP_INVALID | RAYCASTER_INVALID);
    }

    void VolumeRenderer::onProcessorInvalidated(AbstractProcessor* processor) {
        if (processor == &_pgGenerator) {
            invalidate(PG_INVALID);
        }
        else if (processor == &_eepGenerator) {
            invalidate(EEP_INVALID);
        }
        else if (processor == &_raycaster) {
            invalidate(RAYCASTER_INVALID);
        }

        invalidate(AbstractProcessor::INVALID_RESULT);
    }

    void VolumeRenderer::onPropertyChanged(const AbstractProperty* prop) {
        if (prop == &p_outputImage) {
            _pgGenerator.p_geometryID.setValue(p_outputImage.getValue() + ".geometry");
153
154
            _eepGenerator.p_geometryID.setValue(p_outputImage.getValue() + ".geometry");

155
            _eepGenerator.p_entryImageID.setValue(p_outputImage.getValue() + ".entrypoints");
156
157
            _raycaster.p_entryImageID.setValue(p_outputImage.getValue() + ".entrypoints");

158
            _eepGenerator.p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints");
159
            _raycaster.p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints");
160
        }
161
162
163
        else if (prop == &p_inputVolume) {
            invalidate(AbstractProcessor::INVALID_RESULT | PG_INVALID);
        }
164
165
166
        VisualizationProcessor::onPropertyChanged(prop);
    }

167
168
169
170
171
172
173
    void VolumeRenderer::setViewportSizeProperty(IVec2Property* viewportSizeProp) {
        _eepGenerator.setViewportSizeProperty(viewportSizeProp);
        _raycaster.setViewportSizeProperty(viewportSizeProp);

        VisualizationProcessor::setViewportSizeProperty(viewportSizeProp);
    }

174
175
}