forked from frankyeh/UNet-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
202 lines (179 loc) · 7.18 KB
/
mainwindow.cpp
File metadata and controls
202 lines (179 loc) · 7.18 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
194
195
196
197
198
199
200
201
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "optiontablewidget.hpp"
#include <QSettings>
#include <QMovie>
#include <QMessageBox>
#include <QStandardPaths>
#include "console.h"
#include "TIPL/tipl.hpp"
#include <QSettings>
QSettings settings("settings.ini",QSettings::IniFormat);
extern std::vector<std::string> gpu_names;
extern std::vector<std::string> seg_template_list;
extern std::vector<std::vector<std::string> > atlas_file_name_list;
void gen_list(std::vector<std::string>& network_list);
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->option_widget_layout->addWidget(option = new OptionTableWidget(*this,ui->option_widget,":/options.txt"));
ui->postproc_widget_layout->addWidget(eval_option = new OptionTableWidget(*this,ui->postproc_widget,":/postproc.txt"));
connect(eval_option,SIGNAL(run_action(QString)),this,SLOT(run_action(QString)));
ui->postproc_widget->hide();
ui->option_widget->hide();
ui->tabWidget->setCurrentIndex(0);
ui->training_gif->setMovie(new QMovie(":/icons/icons/processing.gif"));
ui->evaluate_gif->setMovie(new QMovie(":/icons/icons/processing.gif"));
ui->eval_label_slider->setVisible(false);
ui->view1->setScene(&train_scene1);
ui->view2->setScene(&train_scene2);
ui->eval_view1->setScene(&eval_scene1);
ui->eval_view2->setScene(&eval_scene2);
ui->error_view->setScene(&error_scene);
v2c1.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
v2c1.set_range(0.0f,1.0f);
v2c2.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
v2c2.set_range(0.0f,1.0f);
eval_v2c1.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
eval_v2c1.set_range(0.0f,1.0f);
eval_v2c2.two_color(tipl::rgb(0,0,0),tipl::rgb(255,255,255));
eval_v2c2.set_range(0.0f,1.0f);
ui->eval_contrast->hide();
// populate device list
{
QStringList device_list;
device_list << "CPU";
torch::set_num_threads(std::thread::hardware_concurrency());
if constexpr (tipl::use_cuda)
{
if (torch::cuda::is_available())
{
for(int i = 0;i < gpu_names.size();++i)
device_list << gpu_names[i].c_str();
}
}
ui->train_device->addItems(device_list);
ui->evaluate_device->addItems(device_list);
ui->train_device->setCurrentIndex(device_list.size() > 1 ? 1:0);
ui->evaluate_device->setCurrentIndex(ui->evaluate_device->count()-1);
}
// populate networks
{
ui->evaluate_builtin_networks->addItem("select or open...");
QDir dir(QCoreApplication::applicationDirPath() + "/unet");
dir.setNameFilters(QStringList() << "*.nz");
QFileInfoList files = dir.entryInfoList(QDir::Files);
for (const QFileInfo& fileInfo : files)
ui->evaluate_builtin_networks->addItem(fileInfo.fileName().remove(".nz"));
ui->evaluate_builtin_networks->setCurrentText(settings.value("eval_network").toString());
}
//populate template
{
ui->template_list->addItem("none");
for(const auto& each: seg_template_list)
ui->template_list->addItem(QString::fromStdString(tipl::remove_all_suffix(std::filesystem::path(each).filename().string())));
ui->template_list->setCurrentIndex(0);
}
auto workdir_list = settings.value("WORK_PATH").toStringList();
if (!settings.contains("WORK_PATH"))
ui->workDir->addItem(QDir::currentPath());
tipl::qt::working_dirs << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
tipl::qt::working_dirs << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
tipl::qt::working_dirs << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
for(auto each : workdir_list)
if(QFileInfo(each).exists())
{
ui->workDir->addItem(each);
tipl::qt::working_dirs << QUrl::fromLocalFile(each);
}
timer = new QTimer(this);
timer->setInterval(100);
connect(timer, SIGNAL(timeout()), this, SLOT(training()));
eval_timer = new QTimer(this);
eval_timer->setInterval(1500);
connect(eval_timer, SIGNAL(timeout()), this, SLOT(evaluating()));
qApp->installEventFilter(this);
}
MainWindow::~MainWindow()
{
QStringList workdir_list;
for (int index = 0;index < 10 && index < ui->workDir->count();++index)
workdir_list << ui->workDir->itemText(index);
std::swap(workdir_list[0],workdir_list[ui->workDir->currentIndex()]);
settings.setValue("WORK_PATH", workdir_list);
settings.setValue("eval_network",ui->evaluate_builtin_networks->currentText());
qApp->removeEventFilter(this);
delete ui;
}
void MainWindow::add_work_dir(QString dir)
{
if(ui->workDir->findText(dir) != -1)
ui->workDir->removeItem(ui->workDir->findText(dir));
ui->workDir->insertItem(0,dir);
ui->workDir->setCurrentIndex(0);
if(tipl::qt::working_dirs.indexOf(dir) != -1)
tipl::qt::working_dirs.remove(tipl::qt::working_dirs.indexOf(dir));
tipl::qt::working_dirs << dir;
}
extern console_stream console;
void MainWindow::on_eval_view_dim_currentIndexChanged(int index)
{
auto currentRow = ui->evaluate_list->currentRow();
if(currentRow >= 0 && currentRow < eval_I1_buffer.size() && !eval_I1_buffer[currentRow].empty())
{
ui->eval_pos->setMaximum(eval_I1_buffer[currentRow].shape()[index]-1);
ui->eval_pos->setValue(ui->eval_pos->maximum()/2);
}
}
void MainWindow::on_view_dim_currentIndexChanged(int index)
{
ui->pos->setMaximum(I1.shape()[index]-1);
ui->pos->setValue(ui->pos->maximum()/2);
}
void MainWindow::on_label_slider_valueChanged(int value)
{
on_pos_valueChanged(ui->pos->value());
}
void MainWindow::on_eval_label_slider_valueChanged(int value)
{
on_eval_pos_valueChanged(ui->eval_pos->value());
}
void MainWindow::on_error_x_size_valueChanged(int arg1){plot_error();}
void MainWindow::on_error_y_size_valueChanged(int arg1){plot_error();}
void MainWindow::on_evaluate_output_currentIndexChanged(int index)
{
if(index != 0)
ui->template_list->setCurrentIndex(0);
ui->atlas_label->setVisible(index == 0);
ui->template_list->setVisible(index == 0);
ui->atlas_list->setVisible(index == 0);
}
void MainWindow::on_template_list_currentIndexChanged(int index)
{
if(index > 0 && index <= atlas_file_name_list.size())
{
ui->atlas_list->clear();
for(const auto& each : atlas_file_name_list[index-1])
ui->atlas_list->addItem(QString::fromStdString(tipl::remove_all_suffix(std::filesystem::path(each).filename().string())));
ui->atlas_list->setCurrentIndex(0);
ui->atlas_list->show();
}
else
ui->atlas_list->hide();
}
void MainWindow::on_browseDir_clicked()
{
QString filename = QFileDialog::getExistingDirectory(this,"Browse Directory",
ui->workDir->currentText());
if ( filename.isEmpty() )
return;
add_work_dir(filename);
}
void MainWindow::on_console_clicked()
{
static Console* con(0);
if(!con)
con = new Console(this);
con->showNormal();
}