dvrvis.cpp 10.3 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 TUMVis Visualization Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge (christian.szb@in.tum.de)
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

29
30
31
32
#include "dvrvis.h"

#include "tgt/event/keyevent.h"
#include "tgt/glcontext.h"
33
#include "tgt/qt/qtcontextmanager.h"
34
#include "core/datastructures/imagedataconverter.h"
35
36
#include "core/classification/geometrytransferfunction.h"
#include "core/classification/tfgeometry.h"
37
38
39
40
41

namespace TUMVis {

    DVRVis::DVRVis()
        : VisualizationPipeline()
42
        , _camera("camera", "Camera")
43
        , _imageReader()
44
        , _pgGenerator()
schultezub's avatar
schultezub committed
45
46
        , _vmgGenerator()
        , _vmRenderer(_renderTargetSize)
47
        , _eepGenerator(_renderTargetSize)
48
        , _vmEepGenerator(_renderTargetSize)
49
50
        , _dvrNormal(_renderTargetSize)
        , _dvrVM(_renderTargetSize)
51
        , _depthDarkening(_renderTargetSize)
52
        , _combine(_renderTargetSize)
53
        , _trackballEH(0)
54
    {
55
56
57
        addProperty(&_camera);

        _trackballEH = new TrackballNavigationEventHandler(&_camera, _renderTargetSize.getValue());
58
59
        _eventHandlers.push_back(_trackballEH);

60
        _processors.push_back(&_imageReader);
61
        _processors.push_back(&_pgGenerator);
schultezub's avatar
schultezub committed
62
63
        _processors.push_back(&_vmgGenerator);
        _processors.push_back(&_vmRenderer);
64
        _processors.push_back(&_eepGenerator);
65
        _processors.push_back(&_vmEepGenerator);
66
67
        _processors.push_back(&_dvrNormal);
        _processors.push_back(&_dvrVM);
68
        _processors.push_back(&_depthDarkening);
69
        _processors.push_back(&_combine);
70
71
72
    }

    DVRVis::~DVRVis() {
73
        delete _trackballEH;
74
75
76
77
78
    }

    void DVRVis::init() {
        VisualizationPipeline::init();

schultezub's avatar
schultezub committed
79
80
        _camera.addSharedProperty(&_vmgGenerator._camera);
        _camera.addSharedProperty(&_vmRenderer._camera);
81
        _camera.addSharedProperty(&_eepGenerator._camera);
82
        _camera.addSharedProperty(&_vmEepGenerator._camera);
83
84
        _camera.addSharedProperty(&_dvrNormal._camera);
        _camera.addSharedProperty(&_dvrVM._camera);
85

86
87
88
        _imageReader._url.setValue("D:\\Medical Data\\smallHeart.mhd");
        _imageReader._targetImageID.setValue("reader.output");

89
90
        _dvrNormal._targetImageID.setValue("drr.output");
        _dvrNormal._sourceImageID.setValue("eep.input");
schultezub's avatar
schultezub committed
91

92
93
94
95
96
        GeometryTransferFunction* dvrTF = new GeometryTransferFunction(128, tgt::vec2(0.f, .05f));
        dvrTF->addGeometry(TFGeometry::createQuad(tgt::vec2(.4f, .42f), tgt::col4(255, 0, 0, 255), tgt::col4(255, 0, 0, 255)));
        dvrTF->addGeometry(TFGeometry::createQuad(tgt::vec2(.45f, .5f), tgt::col4(0, 255, 0, 255), tgt::col4(0, 255, 0, 255)));
        _dvrNormal._transferFunction.replaceTF(dvrTF);

97
98
        _dvrVM._targetImageID.setValue("dvr.output");
        _dvrVM._sourceImageID.setValue("eep.input");
schultezub's avatar
schultezub committed
99

100
        _eepGenerator._sourceImageID.setValue("eep.input");
101
        _vmEepGenerator._sourceImageID.setValue("eep.input");
102
103
        _pgGenerator._sourceImageID.setValue("eep.input");

104
        _vmRenderer._renderTargetID.connect(&_combine._mirrorRenderID);
105
106
107
108
        _vmEepGenerator._entryImageID.setValue("vm.eep.entry");
        _vmEepGenerator._exitImageID.setValue("vm.eep.exit");
        _vmEepGenerator._enableMirror.setValue(true);

109
110
111
112
113
        // not the most beautiful way... *g*
        // this will all get better with scripting support.
        static_cast<BoolProperty*>(_vmEepGenerator.getProperty("applyMask"))->setValue(true);
        _vmRenderer._renderTargetID.connect(static_cast<DataNameProperty*>(_vmEepGenerator.getProperty("maskID")));

114
        _renderTargetID.setValue("combine");
115

116
117
        _pgGenerator._geometryID.connect(&_vmEepGenerator._geometryID);
        _vmgGenerator._mirrorID.connect(&_vmEepGenerator._mirrorID);
schultezub's avatar
schultezub committed
118
        _vmgGenerator._mirrorID.connect(&_vmRenderer._geometryID);
119
120
121
        _vmgGenerator._mirrorCenter.setValue(tgt::vec3(0.f, 0.f, -20.f));
        _vmgGenerator._poi.setValue(tgt::vec3(40.f, 40.f, 40.f));
        _vmgGenerator._size.setValue(60.f);
schultezub's avatar
schultezub committed
122

123
124
        _eepGenerator._entryImageID.connect(&_dvrNormal._entryImageID);
        _vmEepGenerator._entryImageID.connect(&_dvrVM._entryImageID);
schultezub's avatar
schultezub committed
125

126
127
        _eepGenerator._exitImageID.connect(&_dvrNormal._exitImageID);
        _vmEepGenerator._exitImageID.connect(&_dvrVM._exitImageID);
schultezub's avatar
schultezub committed
128

129
130
131
        _dvrVM._targetImageID.connect(&_combine._mirrorImageID);
        _combine._targetImageID.setValue("combine");

132
133
134
        _dvrNormal._targetImageID.connect(&_depthDarkening._inputImage);
        _depthDarkening._outputImage.connect(&_combine._normalImageID);

135
        _imageReader.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
schultezub's avatar
schultezub committed
136
137
        _vmgGenerator.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
        _vmRenderer.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
schultezub's avatar
schultezub committed
138
        _pgGenerator.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
139
        _eepGenerator.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
140
        _vmEepGenerator.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
141
142
        _dvrNormal.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
        _dvrVM.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
143
        _depthDarkening.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
144
        _combine.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
145
146
147

        _trackballEH->setViewportSize(_renderTargetSize.getValue());
        _renderTargetSize.s_changed.connect<DVRVis>(this, &DVRVis::onRenderTargetSizeChanged);
148
149
150
151
152
153
154
155
156
    }

    void DVRVis::execute() {
        {
            tbb::spin_mutex::scoped_lock lock(_localMutex);
            _invalidationLevel.setValid();
            // TODO:    think whether we want to lock all processors already here.
        }
        if (! _imageReader.getInvalidationLevel().isValid()) {
157
            executeProcessor(&_imageReader);
158
159
160

            // convert data
            DataContainer::ScopedTypedData<ImageData> img(_data, "reader.output");
schultezub's avatar
schultezub committed
161
162
163
164
            ImageDataLocal* local = ImageDataConverter::tryConvert<ImageDataLocal>(img);
            if (local != 0) {
                _data.addData("clr.input", local);
            }
165
166
167
168
169
170
            {
                tgt::GLContextScopedLock lock(_canvas->getContext());
                ImageDataGL* gl = ImageDataConverter::tryConvert<ImageDataGL>(img);
                if (gl != 0) {
                    _data.addData("eep.input", gl);
                }
171
            }
172
173
174
175
            CtxtMgr.releaseCurrentContext();

            tgt::Bounds volumeExtent = img->getWorldBounds();
            tgt::vec3 pos = volumeExtent.center() - tgt::vec3(0, 0, tgt::length(volumeExtent.diagonal()));
176
177
            
            _trackballEH->setSceneBounds(volumeExtent);
178
179
            _trackballEH->setCenter(volumeExtent.center());
            _trackballEH->reinitializeCamera(pos, volumeExtent.center(), _camera.getValue().getUpVector());
180

181
        }
182
183
184
        if (! _pgGenerator.getInvalidationLevel().isValid()) {
            executeProcessor(&_pgGenerator);
        }
schultezub's avatar
schultezub committed
185
186
187
188
189
190
        if (! _vmgGenerator.getInvalidationLevel().isValid()) {
            executeProcessor(&_vmgGenerator);
        }
        if (! _vmRenderer.getInvalidationLevel().isValid()) {
            lockGLContextAndExecuteProcessor(&_vmRenderer);
        }
191
        if (! _eepGenerator.getInvalidationLevel().isValid()) {
192
            lockGLContextAndExecuteProcessor(&_eepGenerator);
193
        }
194
195
196
        if (! _vmEepGenerator.getInvalidationLevel().isValid()) {
            lockGLContextAndExecuteProcessor(&_vmEepGenerator);
        }
197
198
        if (!_dvrNormal.getInvalidationLevel().isValid()) {
            lockGLContextAndExecuteProcessor(&_dvrNormal);
199
            lockGLContextAndExecuteProcessor(&_depthDarkening);
schultezub's avatar
schultezub committed
200
        }
201
202
        if (!_dvrVM.getInvalidationLevel().isValid()) {
            lockGLContextAndExecuteProcessor(&_dvrVM);
203
            lockGLContextAndExecuteProcessor(&_combine);
schultezub's avatar
schultezub committed
204
        }
205
206
207
        if (!_depthDarkening.getInvalidationLevel().isValid()) {
            lockGLContextAndExecuteProcessor(&_depthDarkening);
        }
208
209
210
        if (!_combine.getInvalidationLevel().isValid()) {
            lockGLContextAndExecuteProcessor(&_combine);
        }
211
212
213
214
215
216
    }

    const std::string DVRVis::getName() const {
        return "DVRVis";
    }

217
218
    void DVRVis::onRenderTargetSizeChanged(const AbstractProperty* prop) {
        _trackballEH->setViewportSize(_renderTargetSize.getValue());
219
220
        float ratio = static_cast<float>(_renderTargetSize.getValue().x) / static_cast<float>(_renderTargetSize.getValue().y);
        _camera.setWindowRatio(ratio);
221
222
    }

223
}