14 #include <QPushButton>
38 RegistrationBaseWidget(services, parent,
"org_custusx_registration_method_commandline_elastix_widget",
"ElastiX Registration"),
39 mRegisterButton(NULL),
40 mParameterFileWidget0(NULL),
41 mFilePreviewWidget(NULL),
42 mTimedAlgorithmProgressBar(NULL),
56 void ElastixWidget::createUI()
59 connect(mElastixManager.get(), SIGNAL(elastixChanged()),
this, SLOT(elastixChangedSlot()));
61 mRegisterButton =
new QPushButton(
"Register");
62 connect(mRegisterButton, SIGNAL(clicked()),
this, SLOT(registerSlot()));
64 QVBoxLayout* topLayout =
new QVBoxLayout(
this);
65 topLayout->setMargin(0);
67 mOptionsWidget = this->createOptionsWidget();
68 mOptionsWidget->setVisible(
settings()->value(
"registration/elastixShowDetails").toBool());
71 mTimedAlgorithmProgressBar->
attach(mElastixManager->getExecuter());
73 QGridLayout* entryLayout =
new QGridLayout;
74 entryLayout->setColumnStretch(1, 1);
81 new LabeledComboBoxWidget(
this, mElastixManager->getParameters()->getCurrentPreset(), entryLayout, 2);
83 QHBoxLayout* buttonsLayout =
new QHBoxLayout;
84 buttonsLayout->addWidget(mRegisterButton);
87 QIcon(
":/icons/open_icon_library/system-run-5.png"),
88 "Details",
"Show Elastix Settings Details",
89 SLOT(toggleDetailsSlot()),
92 topLayout->addLayout(entryLayout);
93 topLayout->addLayout(buttonsLayout);
94 topLayout->addWidget(mOptionsWidget, 1);
95 topLayout->addStretch();
96 topLayout->addWidget(mTimedAlgorithmProgressBar);
98 this->elastixChangedSlot();
101 void ElastixWidget::toggleDetailsSlot()
103 mOptionsWidget->setVisible(!mOptionsWidget->isVisible());
104 settings()->
setValue(
"registration/elastixShowDetails", mOptionsWidget->isVisible());
107 QWidget* ElastixWidget::createOptionsWidget()
109 QWidget* retval =
new QWidget(
this);
110 QGridLayout* layout =
new QGridLayout(retval);
111 layout->setMargin(0);
118 layout->addWidget(
new QLabel(
"Parameter File",
this), line, 0);
119 mParameterFileWidget0 =
new FileSelectWidget(
this);
120 connect(mParameterFileWidget0, SIGNAL(fileSelected(QString)),
this, SLOT(userParameterFileSelected(QString)));
121 layout->addWidget(mParameterFileWidget0, line, 1, 1, 2);
124 QWidget* executableWidget =
sscCreateDataWidget(
this, mElastixManager->getParameters()->getActiveExecutable());
125 layout->addWidget(executableWidget, line, 0, 1, 3);
128 QHBoxLayout* buttonsLayout =
new QHBoxLayout;
129 layout->addLayout(buttonsLayout, line, 0, 1, 3);
131 buttonsLayout->addWidget(
new CheckBoxWidget(
this, mElastixManager->getDisplayProcessMessages()));
132 buttonsLayout->addWidget(
new CheckBoxWidget(
this, mElastixManager->getDisableRendering()));
135 QIcon(
":/icons/preset_remove.png"),
136 "Delete the current preset",
"",
137 SLOT(deletePresetSlot()),
141 QIcon(
":/icons/preset_save.png"),
142 "Add the current setting as a preset",
"",
143 SLOT(savePresetSlot()),
148 mFilePreviewWidget =
new FilePreviewWidget(
this);
150 mFilePreviewWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
151 layout->addWidget(mFilePreviewWidget, line, 0, 1, 3);
161 void ElastixWidget::savePresetSlot()
165 QString newName = par->getPresetNameSuggesion();
168 QString text = QInputDialog::getText(
this,
"Save Preset",
169 "Custom Preset Name", QLineEdit::Normal,
171 if (!ok || text.isEmpty())
174 par->saveCurrentPreset(text);
177 void ElastixWidget::deletePresetSlot()
179 mElastixManager->getParameters()->removeCurrentPreset();
182 void ElastixWidget::userParameterFileSelected(QString filename)
184 mElastixManager->getParameters()->getActiveParameterFile0()->setValue(filename);
187 void ElastixWidget::recurseParameterFolders(QString root, QStringList* retval)
190 folder.setFilter(QDir::AllDirs|QDir::NoDotAndDotDot);
191 QFileInfoList info = folder.entryInfoList();
192 for (
int i=0; i<info.size(); ++i)
194 QString current = info[i].absoluteFilePath();
195 if (current.endsWith(
"/par"))
197 retval->append(current);
200 this->recurseParameterFolders(current, retval);
204 void ElastixWidget::elastixChangedSlot()
207 EmbeddedFilepath par0 = par->getActiveParameterFile0()->getEmbeddedPath();
208 QStringList folders = par0.getRootPaths();
209 QStringList parfolders;
210 for (
int i=0; i<folders.size(); ++i)
211 this->recurseParameterFolders(folders[i], &parfolders);
213 mParameterFileWidget0->
setPaths(parfolders);
214 QStringList nameFilters;
217 mParameterFileWidget0->
setFilename(par0.getAbsoluteFilepath());
223 void ElastixWidget::registerSlot()
225 mElastixManager->execute();