pointpredicatehistogrampropertywidget.cpp 9.56 KB
Newer Older
1 2 3 4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
6 7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8 9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================


26
#include "cgt/assert.h"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

#include "pointpredicatehistogrampropertywidget.h"
#include "core/tools/stringutils.h"

#include <QPainter>
#include <QPen>
#include <QBrush>

#include <QGridLayout>

namespace campvis {

    PointPredicateHistogramPropertyWidget::PointPredicateHistogramPropertyWidget(PointPredicateHistogramProperty* property, DataContainer* dc, QWidget* parent /*= 0*/)
        : AbstractPropertyWidget(property, true, dc, parent)
        , _pcw(0)
    {
        QWidget* mainWidget = new QWidget(this);
        QGridLayout* layout = new QGridLayout();
        mainWidget->setLayout(layout);

        QStringList predicateList;
        predicateList.push_back(tr("Intensity Range"));
        predicateList.push_back(tr("Gradient Magnitude Range"));
        predicateList.push_back(tr("Gradient Orientation"));
51
        predicateList.push_back(tr("Silhouette View"));
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        predicateList.push_back(tr("SNR Range"));
        predicateList.push_back(tr("Vesselness Range"));
        //predicateList.push_back(tr("Ultrasound Confidence Range"));
        predicateList.push_back(tr("Segment ID"));

        _lwPredicates = new QListWidget(mainWidget);
        _lwPredicates->addItems(predicateList);
        _lwPredicates->setSelectionBehavior(QAbstractItemView::SelectRows);
        _lwPredicates->setSelectionMode(QAbstractItemView::ExtendedSelection);
        _lwPredicates->setMaximumHeight(128);
        layout->addWidget(_lwPredicates, 0, 0, 1, 3);

        QWidget* narf = new QWidget(this);
        QHBoxLayout *nl = new QHBoxLayout();
        narf->setLayout(nl);
        nl->setMargin(0);

        _btnAdd = new QPushButton("Add Predicate");
        nl->addWidget(_btnAdd);

        _btnReset = new QPushButton("Reset Predicates");
        nl->addWidget(_btnReset);

        layout->addWidget(narf, 1, 0, 1, 3);

77 78
        //_lwPredicates->setVisible(false);
        //narf->setVisible(false);
79
        
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 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 137 138 139 140 141
        _slHue = new QSlider(Qt::Vertical, mainWidget);
        _slHue->setMinimum(0);
        _slHue->setMaximum(100);
        layout->addWidget(_slHue, 3, 0);

        QLabel* lblHue = new QLabel("Hue");
        layout->addWidget(lblHue, 4, 0);

        _slSaturation = new QSlider(Qt::Vertical, mainWidget);
        _slSaturation->setMinimum(0);
        _slSaturation->setMaximum(100);
        layout->addWidget(_slSaturation, 3, 1);

        QLabel* lblSaturation = new QLabel("Sat");
        layout->addWidget(lblSaturation, 4, 1);

        _canvas = new PointPredicateRenderArea(property, this);
        layout->addWidget(_canvas, 3, 2, 2, 1);

        _pcw = new PropertyCollectionWidget(this);
        layout->addWidget(_pcw, 5, 0, 1, 3);

        addWidget(mainWidget);

        getProp()->s_headerChanged.connect(this, &PointPredicateHistogramPropertyWidget::onHistogramHeaderChanged);

        connect(_btnAdd, SIGNAL(clicked(bool)), this, SLOT(onBtnAddClicked(bool)));
        connect(_btnReset, SIGNAL(clicked(bool)), this, SLOT(onBtnResetClicked(bool)));
        connect(_canvas, SIGNAL(selectedPredicateChanged(AbstractPointPredicate*)), this, SLOT(onSelectedPredicateChanged(AbstractPointPredicate*)));
        connect(_slHue, SIGNAL(valueChanged(int)), this, SLOT(onHueValueChanged(int)));
        connect(_slSaturation, SIGNAL(valueChanged(int)), this, SLOT(onSaturationValueChanged(int)));
    }

    PointPredicateHistogramPropertyWidget::~PointPredicateHistogramPropertyWidget() {
        getProp()->s_headerChanged.disconnect(this);
    }

    void PointPredicateHistogramPropertyWidget::updateWidgetFromProperty() {
        _canvas->update();
    }

    void PointPredicateHistogramPropertyWidget::onSelectedPredicateChanged(AbstractPointPredicate* predicate) {
        _selectedPredicate = predicate;
        _pcw->updatePropCollection(_selectedPredicate, _dataContainer);

        if (_selectedPredicate == nullptr) {
            _slHue->setEnabled(false);
            _slHue->setValue(0);
            _slSaturation->setEnabled(false);
            _slSaturation->setValue(0);
        }
        else {
            _slHue->setEnabled(true);
            _slSaturation->setEnabled(true);

            _slHue->setValue(_selectedPredicate->p_color.getValue().x * 100);
            _slSaturation->setValue(_selectedPredicate->p_color.getValue().y * 100);
        }
    }

    void PointPredicateHistogramPropertyWidget::onHueValueChanged(int value) {
        if (_selectedPredicate != nullptr) {
142
            cgt::vec2 c = _selectedPredicate->p_color.getValue();
143 144 145 146 147 148 149
            c.x = static_cast<float>(value) / 100.f;
            _selectedPredicate->p_color.setValue(c);
        }
    }

    void PointPredicateHistogramPropertyWidget::onSaturationValueChanged(int value) {
        if (_selectedPredicate != nullptr) {
150
            cgt::vec2 c = _selectedPredicate->p_color.getValue();
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
            c.y = static_cast<float>(value) / 100.f;
            _selectedPredicate->p_color.setValue(c);
        }
    }

    void PointPredicateHistogramPropertyWidget::onBtnAddClicked(bool) {
        QList<QListWidgetItem*> selectedItems = _lwPredicates->selectedItems();
        if (selectedItems.empty())
            return;

        AbstractPointPredicate* predicateToAdd = nullptr;
        if (selectedItems.count() > 1) {
            std::vector<AbstractPointPredicate*> preds;
            for (int i = 0; i < selectedItems.size(); ++i)
                preds.push_back(createPredicate(selectedItems[i]));

            std::string title = preds.front()->getTitle();
            std::string name = preds.front()->getName();
            for (size_t i = 1; i < preds.size(); ++i) {
                title += " & " + preds[i]->getTitle();
                name += "_" + preds[i]->getName();
            }

            predicateToAdd = new AndCombinedPointPredicate(name, title, preds);
        }
        else {
            predicateToAdd = createPredicate(selectedItems[0]);
        }
        getProp()->getPredicateHistogram()->addPredicate(predicateToAdd);
    }

    AbstractPointPredicate* PointPredicateHistogramPropertyWidget::createPredicate(QListWidgetItem* item) {
        size_t numPreds = getProp()->getPredicateHistogram()->getPredicates().size();
        AbstractPointPredicate* vpToAdd = nullptr;

        if (item->text() == tr("Intensity Range")) {
            vpToAdd = new RangePointPredicate("intensity", "Intensity", "Intensity Range");
        }
        else if (item->text() == tr("Gradient Magnitude Range")) {
            vpToAdd = new RangePointPredicate("gradientMagnitude", "GradMag", "Gradient Magnitude Range");
        }
        else if (item->text() == tr("Gradient Orientation")) {
            vpToAdd = new RangePointPredicate("gradientAngle", "GradAngle", "Gradient Angle");
194 195
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setMaxValue(cgt::vec2(180.f, 180.f));
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(cgt::vec2(80.f, 100.f));
196 197 198
        }
        else if (item->text() == tr("Silhouette View")) {
            vpToAdd = new RangePointPredicate("viewAngle", "Silhouette", "Silhouette View");
199 200
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setMaxValue(cgt::vec2(180.f, 180.f));
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(cgt::vec2(85.f, 95.f));
201 202 203
        }
        else if (item->text() == tr("SNR Range")) {
            vpToAdd = new RangePointPredicate("snr", "SNR", "SNR Range");
204 205
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setMaxValue(cgt::vec2(10.f, 10.f));
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(cgt::vec2(0.f, 10.f));
206 207 208 209 210 211 212 213 214 215 216
        }
        else if (item->text() == tr("Vesselness Range")) {
            vpToAdd = new RangePointPredicate("vesselness", "Vesselness", "Vesselness Range");
        }
        else if (item->text() == tr("Ultrasound Confidence Range")) {
            vpToAdd = new RangePointPredicate("confidence", "Confidence", "Confidence Range");
        }
        else if (item->text() == tr("Segment ID")) {
            vpToAdd = new LabelBitPointPredicate("label", "Label" + StringUtils::toString(numPreds), "Label ID " + StringUtils::toString(numPreds));
        }
        else {
217
            cgtAssert(false, "This should not happen.");
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
        }

        return vpToAdd;
    }

    void PointPredicateHistogramPropertyWidget::onHistogramHeaderChanged() {
        emit s_propertyChanged(_property);
    }

    void PointPredicateHistogramPropertyWidget::onBtnResetClicked(bool) {
        getProp()->getPredicateHistogram()->resetPredicates();
    }


}