volumerenderer.cpp 8.03 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
    VolumeRenderer::VolumeRenderer(IVec2Property* viewportSizeProp, RaycastingProcessor* raycaster)
39
        : 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_profileRaycaster("ProfileRaycaster", "Profile Raycaster's Execution Time", false)
        , _timerQueryRaycaster(0)
45
46
        , p_pgProps("PGGProps", "Proxy Geometry Generator", AbstractProcessor::VALID)
        , p_eepProps("EEPProps", "Entry/Exit Points Generator", AbstractProcessor::VALID)
47
        , p_raycasterProps("RaycasterProps", "Raycaster", AbstractProcessor::VALID)
48
        , _pgGenerator()
49
        , _eepGenerator(viewportSizeProp)
50
        , _raycaster(raycaster)
51
    {
52
53
        _raycaster->setViewportSizeProperty(viewportSizeProp);

54
        addProperty(&p_inputVolume);
55
        addProperty(&_raycaster->p_transferFunction);
56
        addProperty(&p_outputImage);
57
        addProperty(&p_profileRaycaster);
58

59
60
61
62
63
64
65
66
67
68
69
70
71
        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);
72

73
74
75
76
77
78
79
        p_raycasterProps.addPropertyCollection(*_raycaster);
        _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);
80
81
        addProperty(&p_raycasterProps);

82
83
84
        // setup shared properties
        p_inputVolume.addSharedProperty(&_pgGenerator.p_sourceImageID);
        p_inputVolume.addSharedProperty(&_eepGenerator.p_sourceImageID);
85
        p_inputVolume.addSharedProperty(&_raycaster->p_sourceImageID);
86
87

        p_camera.addSharedProperty(&_eepGenerator.p_camera);
88
        p_camera.addSharedProperty(&_raycaster->p_camera);
89

90
        p_outputImage.addSharedProperty(&_raycaster->p_targetImageID);
91

92
        p_inputVolume.s_changed.connect(this, &VolumeRenderer::onPropertyChanged);
93
94
95
96
97
98
99
100
101
102
    }

    VolumeRenderer::~VolumeRenderer() {

    }

    void VolumeRenderer::init() {
        VisualizationProcessor::init();
        _pgGenerator.init();
        _eepGenerator.init();
103
        _raycaster->init();
104

105
        p_lqMode.addSharedProperty(&_raycaster->p_lqMode);
106

107
108
        _pgGenerator.s_invalidated.connect(this, &VolumeRenderer::onProcessorInvalidated);
        _eepGenerator.s_invalidated.connect(this, &VolumeRenderer::onProcessorInvalidated);
109
        _raycaster->s_invalidated.connect(this, &VolumeRenderer::onProcessorInvalidated);
110
111

        glGenQueries(1, &_timerQueryRaycaster);
112
113
114
    }

    void VolumeRenderer::deinit() {
115
116
        glDeleteQueries(1, &_timerQueryRaycaster);

117
118
        _pgGenerator.s_invalidated.disconnect(this);
        _eepGenerator.s_invalidated.disconnect(this);
119
        _raycaster->s_invalidated.disconnect(this);
120

121
122
        _pgGenerator.deinit();
        _eepGenerator.deinit();
123
        _raycaster->deinit();
124

125
126
127
        VisualizationProcessor::deinit();
    }

128
    void VolumeRenderer::updateResult(DataContainer& data) {
129
130
131
        if (getInvalidationLevel() & PG_INVALID) {
            _pgGenerator.process(data);
        }
132
        if (getInvalidationLevel() & EEP_INVALID) {
133
134
            _eepGenerator.process(data);
        }
135
        if (getInvalidationLevel() & RAYCASTER_INVALID) {
136
137
138
139
140
141
142
143
144
145
146
147
            if (p_profileRaycaster.getValue()) {
                glBeginQuery(GL_TIME_ELAPSED, _timerQueryRaycaster);
                _raycaster->process(data);
                glEndQuery(GL_TIME_ELAPSED);

                GLuint64 timer_result;
                glGetQueryObjectui64v(_timerQueryRaycaster, GL_QUERY_RESULT, &timer_result);
                LINFO("Raycaster Execution time: " << static_cast<double>(timer_result) / 1e06 << "ms.");
            }
            else {
                _raycaster->process(data);
            }            
148
149
150
151
152
153
154
        }

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

    void VolumeRenderer::onProcessorInvalidated(AbstractProcessor* processor) {
        if (processor == &_pgGenerator) {
155
            invalidate(PG_INVALID | EEP_INVALID | RAYCASTER_INVALID);
156
157
        }
        else if (processor == &_eepGenerator) {
158
            invalidate(EEP_INVALID | RAYCASTER_INVALID);
159
        }
160
        else if (processor == _raycaster) {
161
162
163
164
165
166
167
168
169
            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");
170
171
            _eepGenerator.p_geometryID.setValue(p_outputImage.getValue() + ".geometry");

172
            _eepGenerator.p_entryImageID.setValue(p_outputImage.getValue() + ".entrypoints");
173
            _raycaster->p_entryImageID.setValue(p_outputImage.getValue() + ".entrypoints");
174

175
            _eepGenerator.p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints");
176
            _raycaster->p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints");
177
178
179
180
        }
        VisualizationProcessor::onPropertyChanged(prop);
    }

181
182
    void VolumeRenderer::setViewportSizeProperty(IVec2Property* viewportSizeProp) {
        _eepGenerator.setViewportSizeProperty(viewportSizeProp);
183
        _raycaster->setViewportSizeProperty(viewportSizeProp);
184
185
186
187

        VisualizationProcessor::setViewportSizeProperty(viewportSizeProp);
    }

188
189
190
191
    void VolumeRenderer::updateProperties(DataContainer& dataContainer) {
        // nothing to do here
    }

192
193
194
    RaycastingProcessor* VolumeRenderer::getRaycastingProcessor() {
        return _raycaster;
    }
195
196
}