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

dvrvis.cpp 7.11 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
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
#include "dvrvis.h"

#include "tgt/event/keyevent.h"
28
#include "core/datastructures/imagedata.h"
29

schultezub's avatar
schultezub committed
30
31
#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"
32

schultezub's avatar
schultezub committed
33
namespace campvis {
34

35
36
    DVRVis::DVRVis(DataContainer* dc)
        : AutoEvaluationPipeline(dc)
37
        , _camera("Camera", "Camera")
38
        , _lsp()
39
        , _imageReader()
40
        , _pgGenerator()
schultezub's avatar
schultezub committed
41
        , _vmgGenerator()
42
43
44
45
46
47
48
        , _vmRenderer(&_canvasSize)
        , _eepGenerator(&_canvasSize)
        , _vmEepGenerator(&_canvasSize)
        , _dvrNormal(&_canvasSize)
        , _dvrVM(&_canvasSize)
        , _depthDarkening(&_canvasSize)
        , _combine(&_canvasSize)
49
        , _trackballEH(0)
50
    {
51
        addProperty(_camera);
52

53
        _trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
54
55
56
        _trackballEH->addLqModeProcessor(&_dvrNormal);
        _trackballEH->addLqModeProcessor(&_dvrVM);
        _trackballEH->addLqModeProcessor(&_depthDarkening);
57
        addEventListenerToBack(_trackballEH);
58

59
        addProcessor(&_lsp);
60
61
62
63
64
65
66
67
68
69
        addProcessor(&_imageReader);
        addProcessor(&_pgGenerator);
        addProcessor(&_vmgGenerator);
        addProcessor(&_vmRenderer);
        addProcessor(&_eepGenerator);
        addProcessor(&_vmEepGenerator);
        addProcessor(&_dvrNormal);
        addProcessor(&_dvrVM);
        addProcessor(&_depthDarkening);
        addProcessor(&_combine);
70
71
72
    }

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

    void DVRVis::init() {
77
        AutoEvaluationPipeline::init();
78
79
        
        _imageReader.s_validated.connect(this, &DVRVis::onProcessorValidated);
80

81
82
83
84
85
86
        _camera.addSharedProperty(&_vmgGenerator.p_camera);
        _camera.addSharedProperty(&_vmRenderer.p_camera);
        _camera.addSharedProperty(&_eepGenerator.p_camera);
        _camera.addSharedProperty(&_vmEepGenerator.p_camera);
        _camera.addSharedProperty(&_dvrNormal.p_camera);
        _camera.addSharedProperty(&_dvrVM.p_camera);
87

88
        _imageReader.p_url.setValue(ShdrMgr.completePath("/modules/vis/sampledata/smallHeart.mhd"));
89
        _imageReader.p_targetImageID.setValue("reader.output");
90
91
92
93
94
        _imageReader.p_targetImageID.addSharedProperty(&_eepGenerator.p_sourceImageID);
        _imageReader.p_targetImageID.addSharedProperty(&_vmEepGenerator.p_sourceImageID);
        _imageReader.p_targetImageID.addSharedProperty(&_dvrVM.p_sourceImageID);
        _imageReader.p_targetImageID.addSharedProperty(&_dvrNormal.p_sourceImageID);
        _imageReader.p_targetImageID.addSharedProperty(&_pgGenerator.p_sourceImageID);
95

96
        _dvrNormal.p_targetImageID.setValue("drr.output");
97
        _dvrVM.p_targetImageID.setValue("dvr.output");
schultezub's avatar
schultezub committed
98

99
100
101
102
103
        Geometry1DTransferFunction* dvrTF = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .05f));
        dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.12f, .15f), tgt::col4(85, 0, 0, 128), tgt::col4(255, 0, 0, 128)));
        dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.19f, .28f), tgt::col4(89, 89, 89, 155), tgt::col4(89, 89, 89, 155)));
        dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.41f, .51f), tgt::col4(170, 170, 128, 64), tgt::col4(192, 192, 128, 64)));
        _dvrNormal.p_transferFunction.replaceTF(dvrTF);
104

105
106
107
        Geometry1DTransferFunction* vmTF = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .05f));
        vmTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.41f, .51f), tgt::col4(170, 170, 128, 64), tgt::col4(192, 192, 128, 64)));
        _dvrVM.p_transferFunction.replaceTF(vmTF);
108

109
        _vmRenderer.p_renderTargetID.addSharedProperty(&_combine.p_mirrorRenderID);
110
111
112
        _vmEepGenerator.p_entryImageID.setValue("vm.eep.entry");
        _vmEepGenerator.p_exitImageID.setValue("vm.eep.exit");
        _vmEepGenerator.p_enableMirror.setValue(true);
113

114
115
116
        // not the most beautiful way... *g*
        // this will all get better with scripting support.
        static_cast<BoolProperty*>(_vmEepGenerator.getProperty("applyMask"))->setValue(true);
117
        _vmRenderer.p_renderTargetID.addSharedProperty(static_cast<DataNameProperty*>(_vmEepGenerator.getProperty("maskID")));
118
        _vmRenderer.p_renderMode.selectByOption(GL_POLYGON);
119

120
        _renderTargetID.setValue("combine");
121

122
123
124
125
        _pgGenerator.p_geometryID.addSharedProperty(&_vmEepGenerator.p_geometryID);
        _pgGenerator.p_geometryID.addSharedProperty(&_eepGenerator.p_geometryID);
        _vmgGenerator.p_mirrorID.addSharedProperty(&_vmEepGenerator.p_mirrorID);
        _vmgGenerator.p_mirrorID.addSharedProperty(&_vmRenderer.p_geometryID);
126
        _vmgGenerator.p_mirrorCenter.setValue(tgt::vec3(0.f, 0.f, -20.f));
127
128
        _vmgGenerator.p_poi.setValue(tgt::vec3(50.f, 80.f, 15.f));
        _vmgGenerator.p_size.setValue(128.f);
schultezub's avatar
schultezub committed
129

130
131
        _eepGenerator.p_entryImageID.addSharedProperty(&_dvrNormal.p_entryImageID);
        _vmEepGenerator.p_entryImageID.addSharedProperty(&_dvrVM.p_entryImageID);
schultezub's avatar
schultezub committed
132

133
134
        _eepGenerator.p_exitImageID.addSharedProperty(&_dvrNormal.p_exitImageID);
        _vmEepGenerator.p_exitImageID.addSharedProperty(&_dvrVM.p_exitImageID);
schultezub's avatar
schultezub committed
135

136
        _dvrVM.p_targetImageID.addSharedProperty(&_combine.p_mirrorImageID);
137
        _combine.p_targetImageID.setValue("combine");
138

139
140
        _dvrNormal.p_targetImageID.addSharedProperty(&_depthDarkening.p_inputImage);
        _depthDarkening.p_outputImage.addSharedProperty(&_combine.p_normalImageID);
141
142
    }

143
    void DVRVis::deinit() {
144
        _canvasSize.s_changed.disconnect(this);
145
        AutoEvaluationPipeline::deinit();
146
147
    }

148
149
150
    void DVRVis::onProcessorValidated(AbstractProcessor* processor) {
        if (processor == &_imageReader) {
            // update camera
151
            ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
152
            if (img != 0) {
153
                _trackballEH->reinitializeCamera(img);
154
            }
schultezub's avatar
schultezub committed
155
        }
156
157
    }

158

159
}