CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxElastixWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxElastixWidget.h"
34 
35 #include <QPushButton>
36 #include <QLabel>
37 #include <QSpinBox>
38 
39 #include "cxTypeConversions.h"
40 
41 #include "cxTimedAlgorithm.h"
44 #include "cxFileSelectWidget.h"
46 #include "cxCheckBoxWidget.h"
47 #include "cxSettings.h"
49 #include "cxElastixExecuter.h"
50 #include "cxStringProperty.h"
51 #include "cxFilePathProperty.h"
52 #include "cxDataLocations.h"
53 #include "cxHelperWidgets.h"
54 
55 namespace cx
56 {
57 
58 ElastixWidget::ElastixWidget(RegServices services, QWidget* parent) :
59  RegistrationBaseWidget(services, parent, "org_custusx_registration_method_commandline_elastix_widget", "ElastiX Registration")
60 {
61  this->setModified();
62 }
63 
65 {
66  if (!mElastixManager)
67  {
68  this->createUI();
69  }
70 }
71 
72 void ElastixWidget::createUI()
73 {
74  mElastixManager.reset(new ElastixManager(mServices));
75  connect(mElastixManager.get(), SIGNAL(elastixChanged()), this, SLOT(elastixChangedSlot()));
76 
77  mRegisterButton = new QPushButton("Register");
78  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
79 
80  QVBoxLayout* topLayout = new QVBoxLayout(this);
81  topLayout->setMargin(0);
82 
83  mOptionsWidget = this->createOptionsWidget();
84  mOptionsWidget->setVisible(settings()->value("registration/elastixShowDetails").toBool());
85 
86  mTimedAlgorithmProgressBar = new cx::TimedAlgorithmProgressBar;
87  mTimedAlgorithmProgressBar->attach(mElastixManager->getExecuter());
88 
89  QGridLayout* entryLayout = new QGridLayout;
90  entryLayout->setColumnStretch(1, 1);
91 
93  new LabeledComboBoxWidget(this, mFixedImage, entryLayout, 0);
95  new LabeledComboBoxWidget(this, mMovingImage, entryLayout, 1);
96 
97  new LabeledComboBoxWidget(this, mElastixManager->getParameters()->getCurrentPreset(), entryLayout, 2);
98 
99  QHBoxLayout* buttonsLayout = new QHBoxLayout;
100  buttonsLayout->addWidget(mRegisterButton);
101 
102  this->createAction(this,
103  QIcon(":/icons/open_icon_library/system-run-5.png"),
104  "Details", "Show Elastix Settings Details",
105  SLOT(toggleDetailsSlot()),
106  buttonsLayout);
107 
108  topLayout->addLayout(entryLayout);
109  topLayout->addLayout(buttonsLayout);
110  topLayout->addWidget(mOptionsWidget, 1);
111  topLayout->addStretch();
112  topLayout->addWidget(mTimedAlgorithmProgressBar);
113 
114  this->elastixChangedSlot();
115 }
116 
117 void ElastixWidget::toggleDetailsSlot()
118 {
119  mOptionsWidget->setVisible(!mOptionsWidget->isVisible());
120  settings()->setValue("registration/elastixShowDetails", mOptionsWidget->isVisible());
121 }
122 
123 QWidget* ElastixWidget::createOptionsWidget()
124 {
125  QWidget* retval = new QWidget(this);
126  QGridLayout* layout = new QGridLayout(retval);
127  layout->setMargin(0);
128 
129  int line = 0;
130 
131  layout->addWidget(this->createHorizontalLine(), line, 0, 1, 3);
132  ++line;
133 
134  layout->addWidget(new QLabel("Parameter File", this), line, 0);
135  mParameterFileWidget0 = new FileSelectWidget(this);
136  connect(mParameterFileWidget0, SIGNAL(fileSelected(QString)), this, SLOT(userParameterFileSelected(QString)));
137  layout->addWidget(mParameterFileWidget0, line, 1, 1, 2);
138  ++line;
139 
140  QWidget* executableWidget = sscCreateDataWidget(this, mElastixManager->getParameters()->getActiveExecutable());
141  layout->addWidget(executableWidget, line, 0, 1, 3);
142  ++line;
143 
144  QHBoxLayout* buttonsLayout = new QHBoxLayout;
145  layout->addLayout(buttonsLayout, line, 0, 1, 3);
146 
147  buttonsLayout->addWidget(new CheckBoxWidget(this, mElastixManager->getDisplayProcessMessages()));
148  buttonsLayout->addWidget(new CheckBoxWidget(this, mElastixManager->getDisableRendering()));
149 
150  this->createAction(this,
151  QIcon(":/icons/preset_remove.png"),
152  "Delete the current preset", "",
153  SLOT(deletePresetSlot()),
154  buttonsLayout);
155 
156  this->createAction(this,
157  QIcon(":/icons/preset_save.png"),
158  "Add the current setting as a preset", "",
159  SLOT(savePresetSlot()),
160  buttonsLayout);
161 
162  ++line;
163 
164  mFilePreviewWidget = new FilePreviewWidget(this);
165  mFilePreviewWidget->setSyntaxHighLighter<ElastixSyntaxHighlighter>();
166  mFilePreviewWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
167  layout->addWidget(mFilePreviewWidget, line, 0, 1, 3);
168  ++line;
169 
170  return retval;
171 }
172 
174 {}
175 
176 
177 void ElastixWidget::savePresetSlot()
178 {
179  ElastixParametersPtr par = mElastixManager->getParameters();
180 
181  QString newName = par->getPresetNameSuggesion();
182 
183  bool ok;
184  QString text = QInputDialog::getText(this, "Save Preset",
185  "Custom Preset Name", QLineEdit::Normal,
186  newName, &ok);
187  if (!ok || text.isEmpty())
188  return;
189 
190  par->saveCurrentPreset(text);
191 }
192 
193 void ElastixWidget::deletePresetSlot()
194 {
195  mElastixManager->getParameters()->removeCurrentPreset();
196 }
197 
198 void ElastixWidget::userParameterFileSelected(QString filename)
199 {
200  mElastixManager->getParameters()->getActiveParameterFile0()->setValue(filename);
201 }
202 
203 void ElastixWidget::recurseParameterFolders(QString root, QStringList* retval)
204 {
205  QDir folder(root);
206  folder.setFilter(QDir::AllDirs|QDir::NoDotAndDotDot);
207  QFileInfoList info = folder.entryInfoList();
208  for (int i=0; i<info.size(); ++i)
209  {
210  QString current = info[i].absoluteFilePath();
211  if (current.endsWith("/par"))
212  {
213  retval->append(current);
214  }
215 
216  this->recurseParameterFolders(current, retval);
217  }
218 }
219 
220 void ElastixWidget::elastixChangedSlot()
221 {
222  ElastixParametersPtr par = mElastixManager->getParameters();
223  EmbeddedFilepath par0 = par->getActiveParameterFile0()->getEmbeddedPath();
224  QStringList folders = par0.getRootPaths();
225  QStringList parfolders;
226  for (int i=0; i<folders.size(); ++i)
227  this->recurseParameterFolders(folders[i], &parfolders);
228 
229  mParameterFileWidget0->setPaths(parfolders);
230  QStringList nameFilters;
231  nameFilters << "*";
232  mParameterFileWidget0->setNameFilter(nameFilters);
233  mParameterFileWidget0->setFilename(par0.getAbsoluteFilepath());
234 
235 
236  mFilePreviewWidget->previewFileSlot(par0.getAbsoluteFilepath());
237 }
238 
239 void ElastixWidget::registerSlot()
240 {
241  mElastixManager->execute();
242 }
243 
244 
245 
246 } /* namespace cx */
void setNameFilter(QStringList filter)
virtual void prePaintEvent()
Composite widget for string selection.
Show progress for a TimedBaseAlgorithm.
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:129
boost::shared_ptr< ElastixParameters > ElastixParametersPtr
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:79
Manager for interfacing to the ElastiX registration package.
virtual void previewFileSlot(const QString &absoluteFilePath)
static QFrame * createHorizontalLine()
Creates a horizontal line which can be inserted into widgets.
void setFilename(QString name)
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
void attach(TimedAlgorithmPtr algorithm)
void setPaths(QStringList paths)
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
PatientModelServicePtr patientModelService
ElastixWidget(RegServices services, QWidget *parent=NULL)
RegistrationServicePtr registrationService
Definition: cxRegServices.h:60