sliceextractor.cpp 5.12 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.
// 
// ================================================================================================

schultezub's avatar
schultezub committed
29
30
#include "sliceextractor.h"
#include "tgt/logmanager.h"
31
#include "tgt/shadermanager.h"
schultezub's avatar
schultezub committed
32
#include "tgt/textureunit.h"
33

schultezub's avatar
schultezub committed
34
#include "core/datastructures/imagedata.h"
schultezub's avatar
schultezub committed
35
36
37
#include "core/datastructures/imagedatagl.h"
#include "core/datastructures/imagedatarendertarget.h"
#include "core/datastructures/imagedataconverter.h"
schultezub's avatar
schultezub committed
38

39
40
#include "core/classification/simpletransferfunction.h"

41
42
#include "core/tools/quadrenderer.h"

schultezub's avatar
schultezub committed
43
44
45
namespace TUMVis {
    const std::string SliceExtractor::loggerCat_ = "TUMVis.modules.vis.SliceExtractor";

schultezub's avatar
schultezub committed
46
47
    SliceExtractor::SliceExtractor(GenericProperty<tgt::ivec2>& canvasSize)
        : VisualizationProcessor(canvasSize)
schultezub's avatar
schultezub committed
48
49
        , _sourceImageID("sourceImageID", "Input Image", "")
        , _targetImageID("targetImageID", "Output Image", "")
50
        , _sliceNumber("sliceNumber", "Slice Number", 0, 0, 0)
51
        , _transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256))
schultezub's avatar
schultezub committed
52
        , _shader(0)
schultezub's avatar
schultezub committed
53
    {
schultezub's avatar
schultezub committed
54
55
56
57
        addProperty(&_sourceImageID);
        addProperty(&_targetImageID);
        addProperty(&_sliceNumber);
        addProperty(&_transferFunction);
schultezub's avatar
schultezub committed
58
59
60
61
62
63
    }

    SliceExtractor::~SliceExtractor() {

    }

schultezub's avatar
schultezub committed
64
    void SliceExtractor::init() {
schultezub's avatar
schultezub committed
65
        VisualizationProcessor::init();
schultezub's avatar
schultezub committed
66
67
68
        _shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/vis/sliceextractor.frag", "", false);
    }

69
    void SliceExtractor::deinit() {
schultezub's avatar
schultezub committed
70
        VisualizationProcessor::deinit();
71
72
73
        ShdrMgr.dispose(_shader);
    }

schultezub's avatar
schultezub committed
74
    void SliceExtractor::process(DataContainer& data) {
75
        DataContainer::ScopedTypedData<ImageDataLocal> img(data, _sourceImageID.getValue());
schultezub's avatar
schultezub committed
76
77
78

        if (img != 0) {
            if (img->getDimensionality() == 3) {
79
                updateProperties(img);
schultezub's avatar
schultezub committed
80
81
82
                const tgt::svec3& imgSize = img->getSize();
                ImageDataLocal* slice = img->getSubImage(tgt::svec3(0, 0, _sliceNumber.getValue()), tgt::svec3(imgSize.x-1, imgSize.y-1, _sliceNumber.getValue()));
                ImageDataGL* glData = ImageDataConverter::tryConvert<ImageDataGL>(slice);
83
                ImageDataRenderTarget* rt = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
schultezub's avatar
schultezub committed
84

schultezub's avatar
schultezub committed
85
                _shader->activate();
86
                tgt::TextureUnit inputUnit, tfUnit;
schultezub's avatar
schultezub committed
87
                glData->bind(_shader, inputUnit);
88
                _transferFunction.getTF()->bind(_shader, tfUnit);
schultezub's avatar
schultezub committed
89

schultezub's avatar
schultezub committed
90
91
                rt->activate();
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
92
93
94
                _shader->setAttributeLocation(0, "in_Position");
                _shader->setAttributeLocation(1, "in_TexCoords");
                QuadRdr.renderQuad();
schultezub's avatar
schultezub committed
95
96
97
                rt->deactivate();

                _shader->deactivate();
98
                tgt::TextureUnit::setZeroUnit();
schultezub's avatar
schultezub committed
99
100
101
102

                data.addData(_targetImageID.getValue(), rt);
                delete slice;
                delete glData;
schultezub's avatar
schultezub committed
103
104
105
106
107
108
109
110
            }
            else {
                LERROR("Input image must have dimensionality of 3.");
            }
        }
        else {
            LERROR("No suitable input image found.");
        }
111
112

        _invalidationLevel.setValid();
schultezub's avatar
schultezub committed
113
    }
114
115
116
117
118
119
120
121

    void SliceExtractor::updateProperties(const ImageData* img) {
        const tgt::svec3& imgSize = img->getSize();
        if (_sliceNumber.getMaxValue() != imgSize.z - 1){
            _sliceNumber.setMaxValue(imgSize.z - 1);
        }
    }

schultezub's avatar
schultezub committed
122
}