transferfunctionpropertywidget.cpp 7.33 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 "transferfunctionpropertywidget.h"

schultezub's avatar
schultezub committed
32
33
#include "application/gui/properties/abstracttransferfunctioneditor.h"
#include "application/gui/properties/transferfunctioneditorfactory.h"
34
35
#include "core/datastructures/imagedatalocal.h"

schultezub's avatar
schultezub committed
36
37
38
39
40
41
#include <QDockWidget>
#include <QDoubleSpinBox>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>

schultezub's avatar
schultezub committed
42
namespace campvis {
schultezub's avatar
schultezub committed
43
44
45
46
47
48
49
50
    TransferFunctionPropertyWidget::TransferFunctionPropertyWidget(TransferFunctionProperty* property, QWidget* parent /*= 0*/)
        : AbstractPropertyWidget(property, parent)
        , _widget(0)
        , _gridLayout(0)
        , _lblDomain(0)
        , _spinDomainLeft(0)
        , _spinDomainRight(0)
        , _btnEditTF(0)
schultezub's avatar
schultezub committed
51
        , _dockWidget(0)
schultezub's avatar
schultezub committed
52
        , _editor(0)
schultezub's avatar
schultezub committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    {
        _widget = new QWidget(this);
        _gridLayout = new QGridLayout(_widget);
        _widget->setLayout(_gridLayout);

        _lblDomain = new QLabel("Intensity Domain: ", _widget);
        _gridLayout->addWidget(_lblDomain, 0, 0);


        _spinDomainLeft = new QDoubleSpinBox(_widget);
        _spinDomainLeft->setMinimum(0);
        _spinDomainLeft->setDecimals(2);
        _spinDomainLeft->setSingleStep(0.01);
        _gridLayout->addWidget(_spinDomainLeft, 0, 1);

        _spinDomainRight = new QDoubleSpinBox(_widget);
        _spinDomainRight->setMaximum(1);
        _spinDomainRight->setDecimals(2);
        _spinDomainRight->setSingleStep(0.01);
        _gridLayout->addWidget(_spinDomainRight, 0, 2);

        updateWidgetFromProperty();

76
77
78
        _btnFitDomainToImage = new QPushButton("Fit Intensity Domain to Image", _widget);
        _gridLayout->addWidget(_btnFitDomainToImage, 1, 0, 1, 3);

schultezub's avatar
schultezub committed
79
        _btnEditTF = new QPushButton("Edit Transfer Function", _widget);
80
        _gridLayout->addWidget(_btnEditTF, 2, 0, 1, 3);
schultezub's avatar
schultezub committed
81
82
83

        addWidget(_widget);

84
85
86
        onTransferFunctionImageHandleChanged();
        property->getTF()->s_imageHandleChanged.connect(this, &TransferFunctionPropertyWidget::onTransferFunctionImageHandleChanged);

schultezub's avatar
schultezub committed
87
88
89
        connect(_spinDomainLeft, SIGNAL(valueChanged(double)), this, SLOT(onDomainChanged(double)));
        connect(_spinDomainRight, SIGNAL(valueChanged(double)), this, SLOT(onDomainChanged(double)));
        connect(_btnEditTF, SIGNAL(clicked(bool)), this, SLOT(onEditClicked(bool)));
90
        connect(_btnFitDomainToImage, SIGNAL(clicked(bool)), this, SLOT(onFitClicked(bool)));
schultezub's avatar
schultezub committed
91
92
93
    }

    TransferFunctionPropertyWidget::~TransferFunctionPropertyWidget() {
94
        static_cast<TransferFunctionProperty*>(_property)->getTF()->s_imageHandleChanged.disconnect(this);
schultezub's avatar
schultezub committed
95
        delete _dockWidget;
schultezub's avatar
schultezub committed
96
97
    }

98
99
100
101
102
103
104
105
106
107
108
109
    void TransferFunctionPropertyWidget::onTransferFunctionImageHandleChanged() {
        DataHandle dh = static_cast<TransferFunctionProperty*>(_property)->getTF()->getImageHandle();
        if (dh.getData() != 0) {
            const ImageDataLocal* idl = dynamic_cast<const ImageDataLocal*>(dh.getData());
            if (idl != 0) {
                Interval<float> intensityInterval = idl->getNormalizedIntensityRange();
                _spinDomainLeft->setMinimum(intensityInterval.getLeft());
                _spinDomainRight->setMaximum(intensityInterval.getRight());
            }
        }
    }

schultezub's avatar
schultezub committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    void TransferFunctionPropertyWidget::updateWidgetFromProperty() {
        TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
        AbstractTransferFunction* tf = prop->getTF();
        const tgt::vec2& domain = tf->getIntensityDomain();

        _spinDomainLeft->blockSignals(true);
        _spinDomainLeft->setMaximum(domain.y);
        _spinDomainLeft->setValue(domain.x);
        _spinDomainLeft->blockSignals(false);

        _spinDomainRight->blockSignals(true);
        _spinDomainRight->setMinimum(domain.x);
        _spinDomainRight->setValue(domain.y);
        _spinDomainRight->blockSignals(false);
    }

    void TransferFunctionPropertyWidget::onDomainChanged(double value) {
        TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
        _ignorePropertyUpdates = true;
        _spinDomainLeft->setMaximum(_spinDomainRight->value());
        _spinDomainRight->setMinimum(_spinDomainLeft->value());
        tgt::vec2 newDomain(static_cast<float>(_spinDomainLeft->value()), static_cast<float>(_spinDomainRight->value()));
        prop->getTF()->setIntensityDomain(newDomain);
        _ignorePropertyUpdates = false;
    }

    void TransferFunctionPropertyWidget::onEditClicked(bool checked) {
schultezub's avatar
schultezub committed
137
138
139
140
141
142
143
144
145
        if (_editor == 0) {
            TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
            _editor = TransferFunctionEditorFactory::createEditor(prop->getTF());

            _dockWidget = new QDockWidget("Transfer Function Editor");
            _dockWidget->setWidget(_editor);
        }

        _dockWidget->setVisible(true);
schultezub's avatar
schultezub committed
146
147
    }

148
149
150
151
152
153
154
155
156
157
158
159
160
161
    void TransferFunctionPropertyWidget::onFitClicked(bool checked) {
        TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
        AbstractTransferFunction* tf = prop->getTF();

        DataHandle dh = tf->getImageHandle();
        if (dh.getData() != 0) {
            const ImageDataLocal* idl = dynamic_cast<const ImageDataLocal*>(dh.getData());
            if (idl != 0) {
                Interval<float> intensityInterval = idl->getNormalizedIntensityRange();
                tf->setIntensityDomain(tgt::vec2(intensityInterval.getLeft(), intensityInterval.getRight()));
            }
        }
    }

schultezub's avatar
schultezub committed
162
163

}