dvrvis.cpp 6.93 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
33
34
35
36
37
38
#include "dvrvis.h"

#include "tgt/event/keyevent.h"
#include "tgt/glcontext.h"
#include "core/datastructures/imagedataconverter.h"

namespace TUMVis {

    DVRVis::DVRVis()
        : VisualizationPipeline()
39
        , _camera("camera", "Camera")
40
41
        , _imageReader()
        , _eepGenerator(_renderTargetSize)
schultezub's avatar
schultezub committed
42
        , _drrraycater(_renderTargetSize)
schultezub's avatar
schultezub committed
43
        , _simpleRaycaster(_renderTargetSize)
schultezub's avatar
schultezub committed
44
        , _clRaycaster(_renderTargetSize)
45
        , _trackballEH(0)
46
    {
47
48
49
50
51
52
53
54
        addProperty(&_camera);

        // TODO: remove this ugly hack: automatically adapt near/far plane to volume extent.
        tgt::Camera c;
        c.setFarDist(512.f);
        _camera.setValue(c);

        _trackballEH = new TrackballNavigationEventHandler(&_camera, _renderTargetSize.getValue());
55
56
        _eventHandlers.push_back(_trackballEH);

57
58
        _processors.push_back(&_imageReader);
        _processors.push_back(&_eepGenerator);
schultezub's avatar
schultezub committed
59
        _processors.push_back(&_drrraycater);
schultezub's avatar
schultezub committed
60
        _processors.push_back(&_simpleRaycaster);
schultezub's avatar
schultezub committed
61
        _processors.push_back(&_clRaycaster);
62
63
64
    }

    DVRVis::~DVRVis() {
65
        delete _trackballEH;
66
67
68
69
70
    }

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

71
72
73
        _camera.addSharedProperty(&_eepGenerator._camera);
        _camera.addSharedProperty(&_drrraycater._camera);
        _camera.addSharedProperty(&_simpleRaycaster._camera);
74
        _camera.addSharedProperty(&_clRaycaster._camera);
75

76
77
78
        _imageReader._url.setValue("D:\\Medical Data\\smallHeart.mhd");
        _imageReader._targetImageID.setValue("reader.output");

schultezub's avatar
schultezub committed
79
        _eepGenerator._entryImageID.addSharedProperty(&_drrraycater._entryImageID);
schultezub's avatar
schultezub committed
80
        _eepGenerator._entryImageID.addSharedProperty(&_simpleRaycaster._entryImageID);
schultezub's avatar
schultezub committed
81
82
        _eepGenerator._entryImageID.addSharedProperty(&_clRaycaster._entryImageID);

schultezub's avatar
schultezub committed
83
        _eepGenerator._exitImageID.addSharedProperty(&_drrraycater._exitImageID);
schultezub's avatar
schultezub committed
84
        _eepGenerator._exitImageID.addSharedProperty(&_simpleRaycaster._exitImageID);
schultezub's avatar
schultezub committed
85
        _eepGenerator._exitImageID.addSharedProperty(&_clRaycaster._exitImageID);
schultezub's avatar
schultezub committed
86

schultezub's avatar
schultezub committed
87
88
89
        _drrraycater._targetImageID.setValue("drr.output");
        _drrraycater._sourceImageID.setValue("eep.input");

schultezub's avatar
schultezub committed
90
91
92
        _simpleRaycaster._targetImageID.setValue("dvr.output");
        _simpleRaycaster._sourceImageID.setValue("eep.input");

schultezub's avatar
schultezub committed
93
94
95
        _clRaycaster._targetImageID.setValue("clr.output");
        _clRaycaster._sourceImageID.setValue("clr.input");

96
97
98
99
        _eepGenerator._sourceImageID.setValue("eep.input");
        _eepGenerator._entryImageID.setValue("eep.entry");
        _eepGenerator._exitImageID.setValue("eep.exit");

100
        _renderTargetID.setValue("dvr.output");
101
102
103

        _imageReader.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
        _eepGenerator.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
schultezub's avatar
schultezub committed
104
        _drrraycater.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
schultezub's avatar
schultezub committed
105
        _simpleRaycaster.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
schultezub's avatar
schultezub committed
106
        _clRaycaster.s_invalidated.connect<DVRVis>(this, &DVRVis::onProcessorInvalidated);
107
108
109
110
111
112
113
114
115
    }

    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()) {
116
            executeProcessor(&_imageReader);
117
118
119

            // convert data
            DataContainer::ScopedTypedData<ImageData> img(_data, "reader.output");
schultezub's avatar
schultezub committed
120
121
122
123
            ImageDataLocal* local = ImageDataConverter::tryConvert<ImageDataLocal>(img);
            if (local != 0) {
                _data.addData("clr.input", local);
            }
124
125
126
127
128
129
130
            {
                tgt::GLContextScopedLock lock(_canvas->getContext());
                ImageDataGL* gl = ImageDataConverter::tryConvert<ImageDataGL>(img);
                if (gl != 0) {
                    _data.addData("eep.input", gl);
                }

131
132
133
                tgt::Bounds volumeExtent = img->getWorldBounds();
                tgt::vec3 pos = volumeExtent.center() - tgt::vec3(0, 0, tgt::length(volumeExtent.diagonal()));
                _trackballEH->setCenter(volumeExtent.center());
134
                _trackballEH->reinitializeCamera(pos, volumeExtent.center(), _camera.getValue().getUpVector());
135
            }
136
137
        }
        if (! _eepGenerator.getInvalidationLevel().isValid()) {
138
            lockGLContextAndExecuteProcessor(&_eepGenerator);
139
        }
schultezub's avatar
schultezub committed
140
        if (! _eepGenerator.getInvalidationLevel().isValid() || !_drrraycater.getInvalidationLevel().isValid()) {
141
            lockGLContextAndExecuteProcessor(&_drrraycater);
schultezub's avatar
schultezub committed
142
        }
schultezub's avatar
schultezub committed
143
        if (! _eepGenerator.getInvalidationLevel().isValid() || !_simpleRaycaster.getInvalidationLevel().isValid()) {
144
            lockGLContextAndExecuteProcessor(&_simpleRaycaster);
schultezub's avatar
schultezub committed
145
        }
schultezub's avatar
schultezub committed
146
        if (! _eepGenerator.getInvalidationLevel().isValid() || !_clRaycaster.getInvalidationLevel().isValid()) {
147
            lockGLContextAndExecuteProcessor(&_clRaycaster);
schultezub's avatar
schultezub committed
148
        }
149
150
151
152
153
154
155
    }

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

}