transferfunctionpropertywidget.cpp 7.59 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
#include "application/campvisapplication.h"
35
#include "core/datastructures/imagerepresentationlocal.h"
36

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

schultezub's avatar
schultezub committed
43
namespace campvis {
schultezub's avatar
schultezub committed
44
    TransferFunctionPropertyWidget::TransferFunctionPropertyWidget(TransferFunctionProperty* property, QWidget* parent /*= 0*/)
45
        : AbstractPropertyWidget(property, false, parent)
schultezub's avatar
schultezub committed
46
47
48
49
50
51
        , _widget(0)
        , _gridLayout(0)
        , _lblDomain(0)
        , _spinDomainLeft(0)
        , _spinDomainRight(0)
        , _btnEditTF(0)
schultezub's avatar
schultezub committed
52
        , _dockWidget(0)
schultezub's avatar
schultezub committed
53
        , _editor(0)
schultezub's avatar
schultezub committed
54
55
56
57
58
59
60
61
62
63
    {
        _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);
64
        _spinDomainLeft->setMinimum(-10000);
schultezub's avatar
schultezub committed
65
66
67
68
69
        _spinDomainLeft->setDecimals(2);
        _spinDomainLeft->setSingleStep(0.01);
        _gridLayout->addWidget(_spinDomainLeft, 0, 1);

        _spinDomainRight = new QDoubleSpinBox(_widget);
70
        _spinDomainRight->setMaximum(10000);
schultezub's avatar
schultezub committed
71
72
73
74
        _spinDomainRight->setDecimals(2);
        _spinDomainRight->setSingleStep(0.01);
        _gridLayout->addWidget(_spinDomainRight, 0, 2);

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

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

        addWidget(_widget);

83
        onTransferFunctionImageHandleChanged();
84
        updateWidgetFromProperty();
85
86
        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
    void TransferFunctionPropertyWidget::onTransferFunctionImageHandleChanged() {
        DataHandle dh = static_cast<TransferFunctionProperty*>(_property)->getTF()->getImageHandle();
        if (dh.getData() != 0) {
101
            const ImageRepresentationLocal* idl = dynamic_cast<const ImageRepresentationLocal*>(dh.getData());
102
103
            if (idl != 0) {
                Interval<float> intensityInterval = idl->getNormalizedIntensityRange();
104
105
//                 _spinDomainLeft->setMinimum(intensityInterval.getLeft());
//                 _spinDomainRight->setMaximum(intensityInterval.getRight());
106
107
108
109
            }
        }
    }

schultezub's avatar
schultezub committed
110
111
112
113
114
115
    void TransferFunctionPropertyWidget::updateWidgetFromProperty() {
        TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
        AbstractTransferFunction* tf = prop->getTF();
        const tgt::vec2& domain = tf->getIntensityDomain();

        _spinDomainLeft->blockSignals(true);
116
        _spinDomainLeft->setMaximum(domain.y);
schultezub's avatar
schultezub committed
117
118
119
120
        _spinDomainLeft->setValue(domain.x);
        _spinDomainLeft->blockSignals(false);

        _spinDomainRight->blockSignals(true);
121
        _spinDomainRight->setMinimum(domain.x);
schultezub's avatar
schultezub committed
122
123
124
125
126
127
        _spinDomainRight->setValue(domain.y);
        _spinDomainRight->blockSignals(false);
    }

    void TransferFunctionPropertyWidget::onDomainChanged(double value) {
        TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
schultezub's avatar
schultezub committed
128
        ++_ignorePropertyUpdates;
129
130
        _spinDomainLeft->setMaximum(_spinDomainRight->value());
        _spinDomainRight->setMinimum(_spinDomainLeft->value());
schultezub's avatar
schultezub committed
131
132
        tgt::vec2 newDomain(static_cast<float>(_spinDomainLeft->value()), static_cast<float>(_spinDomainRight->value()));
        prop->getTF()->setIntensityDomain(newDomain);
schultezub's avatar
schultezub committed
133
        --_ignorePropertyUpdates;
schultezub's avatar
schultezub committed
134
135
136
    }

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

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

144
145
146
147
            static_cast<CampVisApplication*>(qApp)->registerDockWidget(Qt::BottomDockWidgetArea, _dockWidget);
        } else {
          _dockWidget->setVisible(true);
        }
schultezub's avatar
schultezub committed
148
149
    }

150
151
152
153
154
155
    void TransferFunctionPropertyWidget::onFitClicked(bool checked) {
        TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
        AbstractTransferFunction* tf = prop->getTF();

        DataHandle dh = tf->getImageHandle();
        if (dh.getData() != 0) {
156
            const ImageRepresentationLocal* idl = static_cast<const ImageData*>(dh.getData())->getRepresentation<ImageRepresentationLocal>();
157
158
159
160
161
162
163
            if (idl != 0) {
                Interval<float> intensityInterval = idl->getNormalizedIntensityRange();
                tf->setIntensityDomain(tgt::vec2(intensityInterval.getLeft(), intensityInterval.getRight()));
            }
        }
    }

schultezub's avatar
schultezub committed
164
165

}