SMILX  1.01
milxQtRegistrationAdvancedOptions.cpp
1 #include "milxQtRegistrationAdvancedOptions.h"
2 
3 #include <QCheckBox>
4 #include <QLineEdit>
5 #include <QLabel>
6 #include <QVBoxLayout>
7 #include <QGroupBox>
8 
10 {
11  ui.setupUi(this);
12 
13  setWindowModality(Qt::ApplicationModal);
14  setWindowTitle(tr("Registration Advanced Options"));
15 
17  reset(F3DNifti);
18 }
19 
20 milxQtRegistrationAdvancedOptions::~milxQtRegistrationAdvancedOptions()
21 {
22 
23 }
24 
25 // Reset the interface
27 {
28  QSettings settings("Smili", "Registration Plugin");
29  currentAlgo = algo;
30 
31 
32  if (algo == F3DNifti)
33  {
34  ui.titleSplinesOptions->setVisible(true);
35  ui.descriptionSplinesOptions->setVisible(true);
36  ui.sx->setVisible(true);
37  ui.sy->setVisible(true);
38  ui.sz->setVisible(true);
39  ui.spinBoxSx->setVisible(true);
40  ui.spinBoxSy->setVisible(true);
41  ui.spinBoxSz->setVisible(true);
42  ui.vSpacerSplines->changeSize(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed);
43  ui.vSpacerOptimisations->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
44  ui.vSpacerSymApproach->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
45 
46  ui.optimisationsForm->setVerticalSpacing(7);
47  ui.lblMaxIt->setVisible(true);
48  ui.spinBoxMaxIt->setVisible(true);
49  ui.lblLn->setVisible(true);
50  ui.spinBoxLn->setVisible(true);
51  ui.lblLp->setVisible(true);
52  ui.spinBoxLp->setVisible(true);
53  ui.checkBoxNopy->setVisible(true);
54  ui.lblPctOfBlock->setVisible(false);
55  ui.spinBoxPctBlock->setVisible(false);
56  ui.checkBoxRigOnly->setVisible(false);
57  ui.checkBoxAffDirect->setVisible(false);
58 
59  ui.titleSymmetricApproach->setVisible(true);
60  ui.checkBoxSym->setVisible(true);
61 
62  ui.lblParameterFile->setVisible(false);
63  ui.lblParameterFileExplanation->setVisible(false);
64  ui.lineParameterFile->setVisible(false);
65  ui.btnBrowseParameterFile->setVisible(false);
66  ui.lblPctOfBlock->setVisible(false);
67  ui.btnClearParameterFile->setVisible(false);
68 
69  ui.spinBoxSx->setValue(settings.value("F3D/sx", -5).toFloat());
70  ui.spinBoxSy->setValue(settings.value("F3D/sy", -5).toFloat());
71  ui.spinBoxSz->setValue(settings.value("F3D/sz", -5).toFloat());
72 
73  ui.spinBoxMaxIt->setValue(settings.value("F3D/maxit", 300).toInt());
74  ui.spinBoxLn->setValue(settings.value("F3D/ln", 3).toInt());
75  ui.spinBoxLp->setValue(settings.value("F3D/lp", 3).toInt());
76 
77  ui.checkBoxNopy->setChecked(settings.value("F3D/nopy", false).toBool());
78  ui.checkBoxSym->setChecked(settings.value("F3D/sym", false).toBool());
79  }
80 
81  else if (algo == AladinNifti)
82  {
83  ui.titleSplinesOptions->setVisible(false);
84  ui.descriptionSplinesOptions->setVisible(false);
85  ui.sx->setVisible(false);
86  ui.sy->setVisible(false);
87  ui.sz->setVisible(false);
88  ui.spinBoxSx->setVisible(false);
89  ui.spinBoxSy->setVisible(false);
90  ui.spinBoxSz->setVisible(false);
91  ui.checkBoxNopy->setVisible(false);
92 
93  ui.vSpacerSplines->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
94  ui.vSpacerOptimisations->changeSize(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed);
95  ui.vSpacerSymApproach->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
96 
97  ui.optimisationsForm->setVerticalSpacing(7);
98  ui.lblMaxIt->setVisible(true);
99  ui.spinBoxMaxIt->setVisible(true);
100  ui.lblLn->setVisible(true);
101  ui.spinBoxLn->setVisible(true);
102  ui.lblLp->setVisible(true);
103  ui.spinBoxLp->setVisible(true);
104  ui.checkBoxNopy->setVisible(false);
105  ui.lblPctOfBlock->setVisible(true);
106  ui.spinBoxPctBlock->setVisible(true);
107  ui.checkBoxRigOnly->setVisible(true);
108  ui.checkBoxAffDirect->setVisible(true);
109 
110  ui.titleSymmetricApproach->setVisible(true);
111  ui.checkBoxSym->setVisible(true);
112 
113  ui.lblParameterFile->setVisible(false);
114  ui.lblParameterFileExplanation->setVisible(false);
115  ui.lineParameterFile->setVisible(false);
116  ui.btnBrowseParameterFile->setVisible(false);
117  ui.btnClearParameterFile->setVisible(false);
118 
119  ui.spinBoxMaxIt->setValue(settings.value("aladin/maxit", 5).toInt());
120  ui.spinBoxLn->setValue(settings.value("aladin/ln", 3).toInt());
121  ui.spinBoxLp->setValue(settings.value("aladin/lp", 3).toInt());
122  ui.spinBoxPctBlock->setValue(settings.value("aladin/%v", 50).toFloat());
123 
124  ui.checkBoxAffDirect->setChecked(settings.value("aladin/aF3Direct", false).toBool());
125  ui.checkBoxRigOnly->setChecked(settings.value("aladin/rigOnly", false).toBool());
126  ui.checkBoxSym->setChecked(settings.value("aladin/sym", true).toBool());
127  }
128 
129  else if (algo == ElastixAffine || algo == ElastixBSpline)
130  {
131  ui.titleSplinesOptions->setVisible(false);
132  ui.descriptionSplinesOptions->setVisible(false);
133  ui.sx->setVisible(false);
134  ui.sy->setVisible(false);
135  ui.sz->setVisible(false);
136  ui.spinBoxSx->setVisible(false);
137  ui.spinBoxSy->setVisible(false);
138  ui.spinBoxSz->setVisible(false);
139  ui.checkBoxNopy->setVisible(false);
140 
141  ui.vSpacerSplines->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
142  ui.vSpacerOptimisations->changeSize(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed);
143  ui.vSpacerSymApproach->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
144 
145  ui.optimisationsForm->setVerticalSpacing(0);
146  ui.lblMaxIt->setVisible(true);
147  ui.spinBoxMaxIt->setVisible(true);
148  ui.lblLn->setVisible(false);
149  ui.spinBoxLn->setVisible(false);
150  ui.lblLp->setVisible(false);
151  ui.spinBoxLp->setVisible(false);
152  ui.checkBoxNopy->setVisible(false);
153  ui.lblPctOfBlock->setVisible(false);
154  ui.spinBoxPctBlock->setVisible(false);
155  ui.checkBoxRigOnly->setVisible(false);
156  ui.checkBoxAffDirect->setVisible(false);
157 
158  ui.titleSymmetricApproach->setVisible(false);
159  ui.checkBoxSym->setVisible(false);
160 
161  ui.lblParameterFile->setVisible(true);
162  ui.lineParameterFile->setVisible(true);
163  ui.lblParameterFileExplanation->setVisible(true);
164  ui.btnBrowseParameterFile->setVisible(true);
165  ui.btnClearParameterFile->setVisible(true);
166 
167  if (algo == ElastixAffine)
168  {
169  ui.spinBoxMaxIt->setValue(settings.value("elastixAffine/maxit", 250).toInt());
170  ui.lineParameterFile->setText(settings.value("elastixAffine/parameterFile", "").toString());
171  }
172  else if (algo == ElastixBSpline)
173  {
174  ui.spinBoxMaxIt->setValue(settings.value("elastixBSpline/maxit", 500).toInt());
175  ui.lineParameterFile->setText(settings.value("elastixBSpline/parameterFile", "").toString());
176  }
177  }
178 
179  this->resize(10, 10);
180 }
181 
182 // Create connections with the user interface
184 {
185  connect(this->ui.btnBrowseParameterFile, SIGNAL(clicked()), this, SLOT(browseBtnClicked()));
186  connect(this->ui.btnClearParameterFile, SIGNAL(clicked()), this, SLOT(clearFileBtnClicked()));
187 }
188 
189 void milxQtRegistrationAdvancedOptions::browseBtnClicked()
190 {
191  QFileDialog fileOpener;
192  fileOpener.setFileMode(QFileDialog::ExistingFile);
193  QString filename = fileOpener.getOpenFileName(this, tr("Select File"));
194  this->ui.lineParameterFile->setText(filename);
195 }
196 
197 void milxQtRegistrationAdvancedOptions::clearFileBtnClicked()
198 {
199  this->ui.lineParameterFile->setText("");
200 }
201 
202 
204 {
206 
207  if (this->ui.lineParameterFile->text() != "" && QFile::exists(this->ui.lineParameterFile->text()))
208  {
209  params.parameterFile = this->ui.lineParameterFile->text();
210  params.customParameterFile = true;
211 
212  return params;
213  }
214 
215  // Default parameters
216  params.parametersTxt =
217  "(FixedInternalImagePixelType \"float\")\r\n"
218  "(MovingInternalImagePixelType \"float\")\r\n"
219  "(UseDirectionCosines \"true\")\r\n"
220  "(Registration \"MultiResolutionRegistration\")\r\n"
221  "(Interpolator \"BSplineInterpolator\")\r\n"
222  "(ResampleInterpolator \"FinalBSplineInterpolator\")\r\n"
223  "(Resampler \"DefaultResampler\")\r\n"
224  "(FixedImagePyramid \"FixedRecursiveImagePyramid\")\r\n"
225  "(MovingImagePyramid \"MovingRecursiveImagePyramid\")\r\n"
226  "(Optimizer \"AdaptiveStochasticGradientDescent\")\r\n"
227  "(Transform \"AffineTransform\")\r\n"
228  "(Metric \"AdvancedMattesMutualInformation\")\r\n"
229  "(AutomaticScalesEstimation \"true\")\r\n"
230  "(AutomaticTransformInitialization \"true\")\r\n"
231  "(HowToCombineTransforms \"Compose\")\r\n"
232  "(NumberOfHistogramBins 32)\r\n"
233  "(ErodeMask \"false\")\r\n"
234  "(NumberOfResolutions 4)\r\n"
235  "(MaximumNumberOfIterations " + QString::number(ui.spinBoxMaxIt->value()) + ")\r\n"
236  "(NumberOfSpatialSamples 2048)\r\n"
237  "(NewSamplesEveryIteration \"true\")\r\n"
238  "(ImageSampler \"Random\")\r\n"
239  "(BSplineInterpolationOrder 1)\r\n"
240  "(FinalBSplineInterpolationOrder 3)\r\n"
241  "(DefaultPixelValue 0)\r\n"
242  "(WriteResultImage \"true\")\r\n"
243  "(ResultImageFormat \"nii\")\r\n";
244 
245  return params;
246 }
247 
248 
250 {
252 
253  if (this->ui.lineParameterFile->text() != "" && QFile::exists(this->ui.lineParameterFile->text()))
254  {
255  params.parameterFile = this->ui.lineParameterFile->text();
256  params.customParameterFile = true;
257 
258  return params;
259  }
260 
261  // Default parameters
262  params.parametersTxt =
263  "(FixedInternalImagePixelType \"float\")\r\n"
264  "(MovingInternalImagePixelType \"float\")\r\n"
265  "(UseDirectionCosines \"true\")\r\n"
266  "(Registration \"MultiResolutionRegistration\")\r\n"
267  "(Interpolator \"BSplineInterpolator\")\r\n"
268  "(ResampleInterpolator \"FinalBSplineInterpolator\")\r\n"
269  "(Resampler \"DefaultResampler\")\r\n"
270  "(FixedImagePyramid \"FixedRecursiveImagePyramid\")\r\n"
271  "(MovingImagePyramid \"MovingRecursiveImagePyramid\")\r\n"
272  "(Optimizer \"AdaptiveStochasticGradientDescent\")\r\n"
273  "(Transform \"BSplineTransform\")\r\n"
274  "(Metric \"AdvancedMattesMutualInformation\")\r\n"
275  "(FinalGridSpacingInPhysicalUnits 16)\r\n"
276  "(HowToCombineTransforms \"Compose\")\r\n"
277  "(NumberOfHistogramBins 32)\r\n"
278  "(ErodeMask \"false\")\r\n"
279  "(NumberOfResolutions 4)\r\n"
280  "(MaximumNumberOfIterations " + QString::number(ui.spinBoxMaxIt->value()) + ")\r\n"
281  "(NumberOfSpatialSamples 2048)\r\n"
282  "(NewSamplesEveryIteration \"true\")\r\n"
283  "(ImageSampler \"Random\")\r\n"
284  "(BSplineInterpolationOrder 1)\r\n"
285  "(FinalBSplineInterpolationOrder 3)\r\n"
286  "(DefaultPixelValue 0)\r\n"
287  "(WriteResultImage \"true\")\r\n"
288  "(ResultImageFormat \"nii\")\r\n";
289 
290 
291  return params;
292 }
293 
294 
296 {
298 
299  if (currentAlgo != F3DNifti)
300  {
301  this->reset(F3DNifti);
302  }
303 
304  // Get input Sx
305  params.spacing[0] = ui.spinBoxSx->value();
306 
307  // Get input Sy
308  params.spacing[1] = ui.spinBoxSy->value();
309 
310  // Get input Sz
311  params.spacing[2] = ui.spinBoxSz->value();
312 
313  // Get input max it level
314  params.maxit = ui.spinBoxMaxIt->value();
315 
316  // Get input nb level
317  params.ln = ui.spinBoxLn->value();
318 
319  // Get input first levels
320  params.lp = ui.spinBoxLp->value();
321 
322  // Get input use pyramidal approach
323  params.nopy = ui.checkBoxNopy->isChecked();
324 
325  // Get input ise symmetric approach
326  params.useSym = ui.checkBoxSym->isChecked();
327 
328  return params;
329 }
330 
331 
333 {
335 
336  if (currentAlgo != AladinNifti)
337  {
338  this->reset(AladinNifti);
339  }
340 
341  // Get input max it level
342  params.maxit = ui.spinBoxMaxIt->value();
343 
344  // Get input nb level
345  params.ln = ui.spinBoxLn->value();
346 
347  // Get input first levels
348  params.lp = ui.spinBoxLp->value();
349 
350  // Get percentage of block
351  params.percentBlock = ui.spinBoxPctBlock->value();
352 
353  // Aladin direct
354  params.affineDirect = ui.checkBoxAffDirect->isChecked();
355 
356  // Rigid only
357  params.rigOnly = ui.checkBoxRigOnly->isChecked();
358 
359  // Get input ise symmetric approach
360  params.useSym = ui.checkBoxSym->isChecked();
361 
362  return params;
363 }
364 
365 
366 // Btn Ok clicked
368 {
369  // Save parameters
370  QSettings settings("Smili", "Registration Plugin");
371 
372  if (currentAlgo == F3DNifti)
373  {
374  settings.setValue("F3D/sx", ui.spinBoxSx->value());
375  settings.setValue("F3D/sy", ui.spinBoxSy->value());
376  settings.setValue("F3D/sz", ui.spinBoxSz->value());
377 
378  settings.setValue("F3D/maxit", ui.spinBoxMaxIt->value());
379  settings.setValue("F3D/ln", ui.spinBoxLn->value());
380  settings.setValue("F3D/lp", ui.spinBoxLp->value());
381 
382  settings.setValue("F3D/nopy", ui.checkBoxNopy->isChecked());
383  settings.setValue("F3D/sym", ui.checkBoxSym->isChecked());
384  }
385  else if (currentAlgo == AladinNifti)
386  {
387  settings.setValue("aladin/maxit", ui.spinBoxMaxIt->value());
388  settings.setValue("aladin/ln", ui.spinBoxLn->value());
389  settings.setValue("aladin/lp", ui.spinBoxLp->value());
390  settings.setValue("aladin/%v", ui.spinBoxPctBlock->value());
391 
392  settings.setValue("aladin/aF3Direct", ui.checkBoxAffDirect->isChecked());
393  settings.setValue("aladin/rigOnly", ui.checkBoxRigOnly->isChecked());
394  settings.setValue("aladin/sym", ui.checkBoxSym->isChecked());
395  }
396  else if (currentAlgo == ElastixAffine)
397  {
398  settings.setValue("elastixAffine/maxit", ui.spinBoxMaxIt->value());
399  settings.setValue("elastixAffine/parameterFile", ui.lineParameterFile->text());
400  }
401  else if (currentAlgo == ElastixBSpline)
402  {
403  settings.setValue("elastixBSpline/maxit", 500);
404  settings.setValue("elastixBSpline/parameterFile", ui.lineParameterFile->text());
405  }
406 
407  // Close the window
408  this->close();
409  this->hide();
410 }
411 
412 // Btn Cancel clicked
414 {
415  // Close the window
416  this->close();
417  this->hide();
418 }
Ui::dlgRegistrationAdvancedOptions ui
User interface.
milxQtRegistrationAdvancedOptions(QDialog *theParent=0)
The standard constructor.
milxQtRegistrationParams getParamsAladinNifti()
Get the advanced parameter of a Nifti Aladin registration.
void reset(RegType algo)
Reset the advanced form to the algorithm in parameter.
milxQtRegistrationParams getParamsElastixAffine()
Get the advanced parameters of an Elastix Affine registration.
milxQtRegistrationParams getParamsElastixBSpline()
Get the advanced parameters of an Elastix BSpline registration.
void createConnections()
Create connections with UI.
milxQtRegistrationParams getParamsF3DNifti()
Get the advanced parameter of a Nifti F3D registration.