/
QtRelabel.cpp
119 lines (100 loc) · 3.55 KB
/
QtRelabel.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
77
78
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
///////////////////////////////////////////////////////////////////////////////////////////////////
// Project: Espina Volume Editor
// Author: Félix de las Pozas Alvarez
//
// File: QtRelabel.cpp
// Purpose: modal dialog for configuring relabel options
// Notes:
///////////////////////////////////////////////////////////////////////////////////////////////////
// c++ includes
#include <sstream>
// Qt includes
#include <QListWidget>
#include <QListWidgetItem>
// project includes
#include "QtRelabel.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// QtRelabel class
//
QtRelabel::QtRelabel(QWidget *parent, Qt::WindowFlags f)
: QDialog {parent, f}
, m_modified {false}
, m_newlabel {false}
, m_maxcolors{0}
{
setupUi(this);
move(parent->geometry().center() - rect().center());
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtRelabel::setInitialOptions(const std::set<unsigned short> labels, std::shared_ptr<Metadata> data, std::shared_ptr<DataManager> dataManager)
{
newlabelbox->setSelectionMode(QAbstractItemView::SingleSelection);
m_maxcolors = dataManager->GetNumberOfLabels();
// add box items. Color 0 is background, so we will start from 1
newlabelbox->insertItem(0, "Background");
for (unsigned int i = 1; i < m_maxcolors; i++)
{
QPixmap icon(16, 16);
auto color = dataManager->GetColorComponents(i);
color.setAlphaF(1.0);
icon.fill(color);
auto text = QString("%1 %2").arg(QString(data->objectSegmentName(i).c_str())).arg(dataManager->GetScalarForLabel(i));
QListWidgetItem *item = new QListWidgetItem(QIcon(icon), text);
newlabelbox->addItem(item);
// hide already hidden/deleted labels
if (0LL == dataManager->GetNumberOfVoxelsForLabel(i))
{
item->setHidden(true);
}
}
newlabelbox->addItem("New label");
newlabelbox->setCurrentRow(m_maxcolors);
// fill selection label text and hide label if user selected just one label
if (labels.size() > 1)
{
selectionlabel->setText("Volume with multiple labels");
}
else
{
unsigned int tempLabel = 0;
if (labels.size() == 1)
{
tempLabel = labels.begin().operator *();
QPixmap icon(16, 16);
auto color = dataManager->GetColorComponents(tempLabel);
color.setAlphaF(1.0);
icon.fill(color);
auto text = QString("%1 %2").arg(QString(data->objectSegmentName(tempLabel).c_str())).arg(dataManager->GetScalarForLabel(tempLabel));
colorlabel->setPixmap(icon);
selectionlabel->setText(text);
newlabelbox->item(tempLabel)->setHidden(true);
}
else
{
selectionlabel->setText("Background voxels");
newlabelbox->item(0)->setHidden(true);
}
}
connect(acceptbutton, SIGNAL(accepted()), this, SLOT(AcceptedData()));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
bool QtRelabel::isModified() const
{
return m_modified;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
const unsigned short QtRelabel::selectedLabel() const
{
return static_cast<unsigned short int>(newlabelbox->currentRow());
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void QtRelabel::AcceptedData()
{
if (selectedLabel() == m_maxcolors) m_newlabel = true;
m_modified = true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
bool QtRelabel::isNewLabel() const
{
return m_newlabel;
}