slicevis.cpp 5.54 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, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 
// 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.
// 
// ================================================================================================

schultezub's avatar
schultezub committed
30
31
#include "slicevis.h"

schultezub's avatar
schultezub committed
32
#include "tgt/event/keyevent.h"
schultezub's avatar
schultezub committed
33
#include "core/datastructures/imagedataconverter.h"
34
35
#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"
schultezub's avatar
schultezub committed
36

schultezub's avatar
schultezub committed
37
namespace campvis {
schultezub's avatar
schultezub committed
38

39
40
    SliceVis::SliceVis()
        : VisualizationPipeline()
41
        , _imageReader()
42
43
        , _gvg()
        , _lhh()
44
        , _sliceExtractor(_effectiveRenderTargetSize)
45
        , _wheelHandler(&_sliceExtractor.p_sliceNumber)
46
        , _tfWindowingHandler(&_sliceExtractor.p_transferFunction)
schultezub's avatar
schultezub committed
47
    {
48
49
50
51
52
        addProcessor(&_imageReader);
//         addProcessor(&_gvg);
//         addProcessor(&_lhh);
        addProcessor(&_sliceExtractor);
        addEventHandler(&_wheelHandler);
53
        addEventHandler(&_tfWindowingHandler);
schultezub's avatar
schultezub committed
54
55
56
    }

    SliceVis::~SliceVis() {
schultezub's avatar
schultezub committed
57
58
59
60
61
    }

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

62
63
        _imageReader.p_url.setValue("D:\\Medical Data\\Dentalscan\\dental.mhd");
        _imageReader.p_targetImageID.setValue("reader.output");
schultezub's avatar
schultezub committed
64

65
        _gvg.p_inputVolume.setValue("se.input");
66

67
//         _lhh.p_inputVolume.setValue("se.input");
68
//         _gvg._outputGradients.connect(&_lhh._inputGradients);
69

70
71
        _sliceExtractor.p_sourceImageID.setValue("se.input");
        _sliceExtractor.p_sliceNumber.setValue(0);
72

73
        // TODO: replace this hardcoded domain by automatically determined from image min/max values
74
75
76
        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
77
78

        _renderTargetID.setValue("renderTarget");
79
        _renderTargetID.addSharedProperty(&(_sliceExtractor.p_targetImageID));
80

schultezub's avatar
schultezub committed
81
        _imageReader.s_invalidated.connect<SliceVis>(this, &SliceVis::onProcessorInvalidated);
82
        _gvg.s_invalidated.connect<SliceVis>(this, &SliceVis::onProcessorInvalidated);
schultezub's avatar
schultezub committed
83
        _sliceExtractor.s_invalidated.connect<SliceVis>(this, &SliceVis::onProcessorInvalidated);
schultezub's avatar
schultezub committed
84
85
86
    }

    void SliceVis::execute() {
87
88
89
        {
            tbb::spin_mutex::scoped_lock lock(_localMutex);
            _invalidationLevel.setValid();
90
            // TODO:    think whether we want to lock all processors already here.
91
92
        }
        if (! _imageReader.getInvalidationLevel().isValid()) {
93
            executeProcessor(&_imageReader);
schultezub's avatar
schultezub committed
94

95
            // convert data
96
            DataContainer::ScopedTypedData<ImageData> img(_data, "reader.output");
97
98
            ImageDataLocal* local = ImageDataConverter::tryConvert<ImageDataLocal>(img);
            if (local != 0) {
99
100
                DataHandle dh = _data.addData("se.input", local);
                _sliceExtractor.p_transferFunction.getTF()->setImageHandle(dh);
101
102
            }
        }
103
104
105
106
107
108
//         if (! _gvg.getInvalidationLevel().isValid()) {
//             executeProcessor(&_gvg);
//         }
//         if (! _lhh.getInvalidationLevel().isValid()) {
//             lockGLContextAndExecuteProcessor(&_lhh);
//         }
109
        if (! _sliceExtractor.getInvalidationLevel().isValid()) {
110
            lockGLContextAndExecuteProcessor(&_sliceExtractor);
schultezub's avatar
schultezub committed
111
112
        }
    }
schultezub's avatar
schultezub committed
113

schultezub's avatar
schultezub committed
114
115
116
117
    void SliceVis::keyEvent(tgt::KeyEvent* e) {
        if (e->pressed()) {
            switch (e->keyCode()) {
                case tgt::KeyEvent::K_UP:
118
                    _sliceExtractor.p_sliceNumber.increment();
schultezub's avatar
schultezub committed
119
120
                    break;
                case tgt::KeyEvent::K_DOWN:
121
                    _sliceExtractor.p_sliceNumber.decrement();
schultezub's avatar
schultezub committed
122
123
124
                    break;
            }
        }
schultezub's avatar
schultezub committed
125
126
    }

127
128
129
130
    const std::string SliceVis::getName() const {
        return "SliceVis";
    }

schultezub's avatar
schultezub committed
131
}