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

slicevis.cpp 3.6 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
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
26
#include "slicevis.h"

schultezub's avatar
schultezub committed
27
#include "tgt/event/keyevent.h"
28

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

schultezub's avatar
schultezub committed
32
namespace campvis {
schultezub's avatar
schultezub committed
33

34
35
    SliceVis::SliceVis(DataContainer* dc)
        : AutoEvaluationPipeline(dc)
36
        , _imageReader()
37
        , _sliceExtractor(&_canvasSize)
38
        , _wheelHandler(&_sliceExtractor.p_zSliceNumber)
39
        , _tfWindowingHandler(&_sliceExtractor.p_transferFunction)
schultezub's avatar
schultezub committed
40
    {
41
42
        addProcessor(&_imageReader);
        addProcessor(&_sliceExtractor);
43
44
        addEventListenerToBack(&_wheelHandler);
        addEventListenerToBack(&_tfWindowingHandler);
schultezub's avatar
schultezub committed
45
46
47
    }

    SliceVis::~SliceVis() {
schultezub's avatar
schultezub committed
48
49
50
    }

    void SliceVis::init() {
51
        AutoEvaluationPipeline::init();
schultezub's avatar
schultezub committed
52

53
        _imageReader.p_url.setValue(CAMPVIS_SOURCE_DIR "/modules/vis/sampledata/smallHeart.mhd");
54
        _imageReader.p_targetImageID.setValue("reader.output");
55
        _imageReader.p_targetImageID.addSharedProperty(&_sliceExtractor.p_sourceImageID);
56
        _imageReader.s_validated.connect(this, &SliceVis::onProcessorValidated);
schultezub's avatar
schultezub committed
57

58
        _sliceExtractor.p_xSliceNumber.setValue(0);
59
60
61
62

        Geometry1DTransferFunction* tf = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .08f));
        tf->addGeometry(TFGeometry1D::createQuad(tgt::vec2(0.f, 1.f), tgt::col4(0, 0, 0, 0), tgt::col4(255, 255, 255, 255)));
        _sliceExtractor.p_transferFunction.replaceTF(tf);
schultezub's avatar
schultezub committed
63
64

        _renderTargetID.setValue("renderTarget");
65
        _renderTargetID.addSharedProperty(&(_sliceExtractor.p_targetImageID));
schultezub's avatar
schultezub committed
66
67
    }

schultezub's avatar
schultezub committed
68
69
70
71
    void SliceVis::keyEvent(tgt::KeyEvent* e) {
        if (e->pressed()) {
            switch (e->keyCode()) {
                case tgt::KeyEvent::K_UP:
72
                    _sliceExtractor.p_xSliceNumber.increment();
schultezub's avatar
schultezub committed
73
74
                    break;
                case tgt::KeyEvent::K_DOWN:
75
                    _sliceExtractor.p_xSliceNumber.decrement();
schultezub's avatar
schultezub committed
76
                    break;
77
78
                default:
                    break;
schultezub's avatar
schultezub committed
79
80
            }
        }
schultezub's avatar
schultezub committed
81
82
    }

83
84
    void SliceVis::onProcessorValidated(AbstractProcessor* processor) {
        if (processor == &_imageReader) {
85
            ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
86
            if (img != 0) {
87
                _sliceExtractor.p_transferFunction.setImageHandle(img.getDataHandle());
88
89
90
91
            }
        }
    }

92
}