openclpipeline.cpp 5.54 KB
Newer Older
schultezub's avatar
schultezub committed
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
29
30
31
32
33
34
// ================================================================================================
// 
// This file is part of the CAMPVis Software 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
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// 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.
// 
// ================================================================================================

#include "openclpipeline.h"

#include "tgt/event/keyevent.h"
#include "tgt/glcontext.h"
#include "tgt/qt/qtcontextmanager.h"
35
#include "core/datastructures/imagedata.h"
36
37
#include "core/datastructures/genericimagerepresentationlocal.h"

schultezub's avatar
schultezub committed
38
39
40
41
42
43
#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"

namespace campvis {

    OpenCLPipeline::OpenCLPipeline()
44
        : AutoEvaluationPipeline()
schultezub's avatar
schultezub committed
45
46
47
        , _camera("camera", "Camera")
        , _imageReader()
        , _pgGenerator()
48
49
        , _eepGenerator(&_canvasSize)
        , _clRaycaster(&_canvasSize)
schultezub's avatar
schultezub committed
50
51
52
53
        , _trackballEH(0)
    {
        addProperty(&_camera);

54
        _trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
55
        _trackballEH->addLqModeProcessor(&_clRaycaster);
56
        addEventListenerToBack(_trackballEH);
schultezub's avatar
schultezub committed
57
58
59
60
61
62
63
64
65
66
67
68

        addProcessor(&_imageReader);
        addProcessor(&_pgGenerator);
        addProcessor(&_eepGenerator);
        addProcessor(&_clRaycaster);
    }

    OpenCLPipeline::~OpenCLPipeline() {
        delete _trackballEH;
    }

    void OpenCLPipeline::init() {
69
        AutoEvaluationPipeline::init();
schultezub's avatar
schultezub committed
70
71
72
73
74
75
76

        _camera.addSharedProperty(&_eepGenerator.p_camera);
        _camera.addSharedProperty(&_clRaycaster._camera);

        //_imageReader.p_url.setValue("D:\\Medical Data\\Dentalscan\\dental.mhd");
        _imageReader.p_url.setValue("D:\\Medical Data\\smallHeart.mhd");
        _imageReader.p_targetImageID.setValue("reader.output");
77
        _imageReader.p_targetImageID.connect(&_pgGenerator.p_sourceImageID);
78
        _imageReader.p_targetImageID.connect(&_eepGenerator.p_sourceImageID);
79
        _imageReader.s_validated.connect(this, &OpenCLPipeline::onProcessorValidated);
schultezub's avatar
schultezub committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

        _clRaycaster._targetImageID.setValue("cl.output");
        _clRaycaster._sourceImageID.setValue("clr.input");

         Geometry1DTransferFunction* dvrTF = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .05f));
         dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.4f, .42f), tgt::col4(255, 0, 0, 255), tgt::col4(255, 0, 0, 255)));
         dvrTF->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.45f, .5f), tgt::col4(0, 255, 0, 255), tgt::col4(0, 255, 0, 255)));
         _clRaycaster._transferFunction.replaceTF(dvrTF);



        _renderTargetID.setValue("cl.output");

        _pgGenerator.p_geometryID.connect(&_eepGenerator.p_geometryID);

        _eepGenerator.p_entryImageID.connect(&_clRaycaster._entryImageID);
        _eepGenerator.p_exitImageID.connect(&_clRaycaster._exitImageID);
    }

99
    void OpenCLPipeline::deinit() {
100
        _canvasSize.s_changed.disconnect(this);
101
        AutoEvaluationPipeline::deinit();
102
103
104
105
106
    }

    const std::string OpenCLPipeline::getName() const {
        return "OpenCLPipeline";
    }
schultezub's avatar
schultezub committed
107

108
109
110
    void OpenCLPipeline::onProcessorValidated(AbstractProcessor* processor) {
        if (processor == &_imageReader) {
            // update camera
111
            ImageRepresentationLocal::ScopedRepresentation img(_data, "reader.output");
schultezub's avatar
schultezub committed
112
            if (img != 0) {
113
114
115
116
                size_t numElements = img->getNumElements();
                float* asFloats = new float[numElements];
                for (size_t i = 0; i < numElements; ++i)
                    asFloats[i] = img->getElementNormalized(i, 0);
117
                ImageData* id = new ImageData(img->getDimensionality(), img->getSize(), img->getParent()->getNumChannels());
118
                GenericImageRepresentationLocal<float, 1>* imageWithFloats = GenericImageRepresentationLocal<float, 1>::create(id, asFloats);
119
120

                DataHandle dh = _data.addData("clr.input", id);
121
                _trackballEH->reinitializeCamera(img->getParent());
schultezub's avatar
schultezub committed
122
123
124
125
126
127
128
            }
        }
    }



}