1 #include "milxQtRegistrationWindow.h"    26     int ret = elx::xoutSetup(
"", 
false, 
false);
    29         QMessageBox msgBox(QMessageBox::Critical, 
"Elastix Initialisation Error", 
"Error while initializing Elastix logging system. Elastix registration might fail.", QMessageBox::NoButton);
    56     setWindowModality(Qt::ApplicationModal);
    57     setWindowTitle(tr(
"Registration option"));
    61     algoList << 
"Affine (ITK)" << 
"Demon (ITK)";
    64     algoList << 
"F3D (Nifti)" << 
"Aladin (Nifti)";
    68     algoList << 
"Affine (Elastix)" << 
"BSpline (Elastix)";
    71     this->
ui.comboBoxAlgo->addItems(algoList);
    75     this->
ui.checkBoxCreateAtlas->setVisible(
false);
    76     this->
ui.checkBoxDeformationF->setVisible(
false);
    77     this->
ui.checkBoxSimilarities->setVisible(
false);
    84     if (
ui.comboBoxAlgo->currentText().compare(
"Affine (ITK)") == 0) 
return AffineItk;
    85     else if (
ui.comboBoxAlgo->currentText().compare(
"Demon (ITK)") == 0) 
return DemonItk;
    86     else if (
ui.comboBoxAlgo->currentText().compare(
"F3D (Nifti)") == 0) 
return F3DNifti;
    87     else if (
ui.comboBoxAlgo->currentText().compare(
"Aladin (Nifti)") == 0) 
return AladinNifti;
    88     else if (
ui.comboBoxAlgo->currentText().compare(
"Affine (Elastix)") == 0) 
return ElastixAffine;
    89     else if (
ui.comboBoxAlgo->currentText().compare(
"BSpline (Elastix)") == 0) 
return ElastixBSpline;
    99     if (this->
ui.inputDirectoryBrowser->text() == 
"")
   105     this->
ui.comboBoxAlgo->setCurrentIndex(regType);
   108     if (regType == AffineItk || regType == DemonItk)
   110         this->
ui.btnAdvancedOptions->setVisible(
false);
   114         this->
ui.btnAdvancedOptions->setVisible(
true);
   118     if (regType == F3DNifti)
   120         this->
ui.checkBoxDeformationF->setVisible(
true);
   121         this->
ui.checkBoxDeformationF->setEnabled(
true);
   122         this->
ui.checkBoxDeformationF->setChecked(
false);
   127         this->
ui.checkBoxDeformationF->setVisible(
false);
   128         this->
ui.checkBoxDeformationF->setEnabled(
false);
   129         this->
ui.checkBoxDeformationF->setChecked(
false);
   145     disconnect(this->
ui.comboBoxRef, SIGNAL(currentIndexChanged(
int)), 
this, SLOT(referenceComboChange(
int)));
   155         bool oneImageChecked = 
false;
   156         for (
int i = 0; i < 
images.size(); i++)
   158             if (
images[i]->isChecked()) {
   159                 oneImageChecked = 
true;
   165         if (oneImageChecked == 
false)
   167             for (
int i = 0; i < 
images.size(); i++)
   169                 if (!
images[i]->isRef()) {
   170                     images[i]->setChecked(
true);
   178     this->
ui.comboBoxRef->clear();
   179     this->
ui.listWidget->clear();
   182     for (
int i = 0; i < 
images.size(); i++)
   184         QString itemName = 
images[i]->getPath();
   187         this->
ui.comboBoxRef->addItem(itemName);
   190         QListWidgetItem* item = 
new QListWidgetItem(itemName);
   191         item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
   194         if (
images[i]->isChecked()) {
   195             item->setCheckState(Qt::Checked);
   197             item->setCheckState(Qt::Unchecked);
   202             item->setFlags(item->flags() ^ Qt::ItemIsEnabled);
   203             this->
ui.comboBoxRef->setCurrentIndex(i);
   207         this->
ui.listWidget->addItem(item);
   211     connect(this->
ui.comboBoxRef, SIGNAL(currentIndexChanged(
int)), 
this, SLOT(referenceComboChange(
int)));
   240     for (
int j = 0; j < 
images.size(); j++)
   242         if (
images[j]->getPath() == path)
   255     this->
ui.checkBoxDeformationF->setDisabled(
true);
   256     this->
ui.comboBoxAlgo->setDisabled(
true);
   257     this->
ui.comboBoxRef->setDisabled(
true);
   258     this->
ui.btnOk->setDisabled(
true);
   259     this->
ui.listWidget->setDisabled(
true);
   260     this->
ui.btnAdvancedOptions->setDisabled(
true);
   261     this->
ui.checkBoxCreateAtlas->setDisabled(
true);
   262     this->
ui.checkBoxOpenResults->setDisabled(
true);
   263     this->
ui.btnAddImage->setDisabled(
true);
   264     this->
ui.btnBrowse->setDisabled(
true);
   265     this->
ui.btnSelectAll->setDisabled(
true);
   266     this->
ui.btnUnselectAll->setDisabled(
true);
   267     this->
ui.clearList->setDisabled(
true);
   268     this->
ui.checkBoxSimilarities->setDisabled(
true);
   271     for (
int row = 0; row < this->
ui.listWidget->count(); row++)
   273         QListWidgetItem *item = this->
ui.listWidget->item(row);
   274         item->setFlags(item->flags() ^ Qt::ItemIsEnabled);
   282     this->
ui.checkBoxDeformationF->setDisabled(
false);
   283     this->
ui.comboBoxAlgo->setDisabled(
false);
   284     this->
ui.comboBoxRef->setDisabled(
false);
   285     this->
ui.btnOk->setDisabled(
false);
   286     this->
ui.listWidget->setDisabled(
false);
   287     this->
ui.btnAdvancedOptions->setDisabled(
false);
   288     this->
ui.checkBoxCreateAtlas->setDisabled(
false);
   289     this->
ui.checkBoxOpenResults->setDisabled(
false);
   290     this->
ui.btnAddImage->setDisabled(
false);
   291     this->
ui.btnBrowse->setDisabled(
false);
   292     this->
ui.btnSelectAll->setDisabled(
false);
   293     this->
ui.btnUnselectAll->setDisabled(
false);
   294     this->
ui.clearList->setDisabled(
false);
   295     this->
ui.checkBoxSimilarities->setDisabled(
false);
   298     for (
int row = 0; row < this->
ui.listWidget->count(); row++)
   300         QListWidgetItem *item = this->
ui.listWidget->item(row);
   301         item->setFlags(item->flags() ^ Qt::ItemIsEnabled);
   326     params.cpp2Def = this->
ui.checkBoxDeformationF->isChecked();
   353     QString outputFoldPath;
   357     for (indexRef = 0; indexRef < 
images.size(); indexRef++)
   359         if (
images[indexRef]->isRef() == 
true)
   369         outputFoldPath = QDir(QFileInfo(
images[indexRef]->getPath()).absolutePath() + 
"/regoutput").absolutePath();
   375         outputFoldPath = QDir(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation) + 
"/regoutput").absolutePath();
   378     return outputFoldPath;
   385     if (
images.size() == 0) 
return;
   391     int refIndex = this->
ui.comboBoxRef->currentIndex();
   393     if (refIndex >= 0 && refIndex < 
images.size())
   400     bool computeSimilarities = 
false;
   401     if (this->
ui.checkBoxSimilarities->isChecked())
   403         computeSimilarities = 
true;
   407     QString outFolder = this->
ui.inputDirectoryBrowser->text();
   408     if (!QDir(outFolder).exists())
   417     for (
int i = 0; i < this->
ui.listWidget->count(); i++)
   420         QListWidgetItem *item = this->
ui.listWidget->item(i);
   421         if ((item->flags() & Qt::ItemIsEnabled) && item->checkState())
   423             images[i]->setChecked(
true);
   427             images[i]->setChecked(
false);
   431         images[i]->setReference(ref);
   434         images[i]->setOutputFolder(QDir(outFolder).absolutePath());
   437         images[i]->setRegType(type);
   443         if (type == AffineItk)
   447         else if (type == DemonItk)
   451         else if (type == AladinNifti)
   455         else if (type == F3DNifti)
   459         else if (type == ElastixAffine)
   463         else if (type == ElastixBSpline)
   469         images[i]->setComputeSimilarities(computeSimilarities);
   475 void milxQtRegistrationWindow::createConnections()
   477     connect(this->
ui.comboBoxRef, SIGNAL(currentIndexChanged(
int)), 
this, SLOT(referenceComboChange(
int)));
   478     connect(this->
ui.comboBoxAlgo, SIGNAL(currentIndexChanged(
int)), 
this, SLOT(algoComboChange(
int)));
   479     connect(this->
ui.btnAdvancedOptions, SIGNAL(clicked()), 
this, SLOT(advancedOptionsClicked()));
   480     connect(this->
ui.btnAddImage, SIGNAL(clicked()), 
this, SLOT(addImageClicked()));
   481     connect(this->
ui.btnSelectAll, SIGNAL(clicked()), 
this, SLOT(selectAllClicked()));
   482     connect(this->
ui.btnUnselectAll, SIGNAL(clicked()), 
this, SLOT(unselectAllClicked()));
   483     connect(this->
ui.btnBrowse, SIGNAL(clicked()), 
this, SLOT(browseBtnClicked()));
   484     connect(this->
ui.clearList, SIGNAL(clicked()), 
this, SLOT(clearList()));
   487     connect(this->
regAlgos, SIGNAL(averageCompleted()), 
this, SLOT(averageComputed()));
   490     connect(this->
regAlgos, SIGNAL(error(QString, QString)), 
this, SLOT(
regError(QString, QString)));
   502     connect(image, SIGNAL(done()), 
this, SLOT(regComplete()));
   503     connect(image, SIGNAL(error(QString, QString)), 
this, SLOT(
regError(QString, QString)));
   512 void milxQtRegistrationWindow::averageComputed()
   526 void milxQtRegistrationWindow::clearList()
   538 void milxQtRegistrationWindow::addImageClicked()
   540     QFileDialog fileOpener;
   541     fileOpener.setFileMode(QFileDialog::ExistingFiles);
   542     QStringList filenames = fileOpener.getOpenFileNames(
this, 
"Add File(s)", QString(), 
"Nifti (*.nii *.nii.gz)");
   544     for (
int i = 0; i < filenames.size(); i++)
   557 void milxQtRegistrationWindow::selectAllClicked()
   559     for (
int row = 0; row < this->
ui.listWidget->count(); row++)
   561         QListWidgetItem *item = this->
ui.listWidget->item(row);
   563         if ((item->flags() & Qt::ItemIsEnabled))
   565             item->setCheckState(Qt::Checked);
   571 void milxQtRegistrationWindow::unselectAllClicked()
   573     for (
int row = 0; row < this->
ui.listWidget->count(); row++)
   575         QListWidgetItem *item = this->
ui.listWidget->item(row);
   577         if ((item->flags() & Qt::ItemIsEnabled))
   579             item->setCheckState(Qt::Unchecked);
   585 void milxQtRegistrationWindow::browseBtnClicked()
   588     dialog.setFileMode(QFileDialog::Directory);
   589     dialog.setOption(QFileDialog::ShowDirsOnly);
   590     QString folder = dialog.getExistingDirectory(
this, tr(
"Select an output folder"));
   591     if (!folder.isEmpty())
   593         this->
ui.inputDirectoryBrowser->setText(folder);
   598 void milxQtRegistrationWindow::advancedOptionsClicked()
   606 void milxQtRegistrationWindow::algoComboChange(
int newIndex)
   608     if (newIndex == AffineItk)
   612     else if (newIndex == DemonItk)
   616     else if (newIndex == AladinNifti)
   620     else if (newIndex == F3DNifti)
   624     else if (newIndex == ElastixAffine)
   628     else if (newIndex == ElastixBSpline)
   636 void milxQtRegistrationWindow::referenceComboChange(
int newIndex)
   639     for (
int i = 0; i < 
images.size(); i++)
   641         images[i]->setIsRef(
false);
   645             images[i]->setIsRef(
true);
   654 void milxQtRegistrationWindow::accept()
   659         QMessageBox msgBox(QMessageBox::Critical, 
"Registration", 
"Error you need at least two images (a reference and and image to register).", QMessageBox::NoButton);
   665     QString outputDir = this->
ui.inputDirectoryBrowser->text();
   666     if (!QFile::exists(outputDir))
   669         QMessageBox::StandardButton reply;
   670         reply = QMessageBox::question(
this, 
"Directory Creation", 
"The directory \"" + outputDir + 
"\" doesn't exist, do you want to create it ?", QMessageBox::Yes | QMessageBox::No);
   671         if (reply == QMessageBox::Yes)
   673             QDir().mkdir(outputDir);
   678     if (!QDir(outputDir).exists())
   680         QMessageBox msgBox(QMessageBox::Critical, 
"Registration", 
"Error the output directory path doesn't exist or is invalid.", QMessageBox::NoButton);
   686     bool oneImageChecked = 
false;
   687     for (
int i = 0; i < 
images.size(); i++)
   689         if (
images[i]->isChecked() == 
true) {
   690             oneImageChecked = 
true;
   695     if (!oneImageChecked)
   698         QMessageBox msgBox(QMessageBox::Critical, 
"Registration", 
"Error, at least one image should be checked", QMessageBox::NoButton);
   720 void milxQtRegistrationWindow::reject()
   728 void milxQtRegistrationWindow::regComplete()
   738     QMessageBox msgBox(QMessageBox::Critical, 
"Registration error in function " + functionName, errorMsg, QMessageBox::NoButton);
   742     if (functionName == 
"average()" || functionName == 
"computeAtlas()") {
   764     for (i = 0; i < 
images.size(); i++)
   766         if (
images[i]->isChecked())
   768             images[i]->startRegistration();
   780         if (this->
ui.checkBoxSimilarities->isChecked())
   808 void milxQtRegistrationWindow::writeSimilarities()
   812     for (indexRef = 0; indexRef < 
images.size(); indexRef++)
   814         if (
images[indexRef]->isRef())
   821     for (
int i = 0; i < 2; i++)
   825         QString similarityFile;
   828             similarityFile = 
images[indexRef]->createSimilarityFileBefore();
   830             similarityFile = 
images[indexRef]->createSimilarityFileAfter();
   833         QFile file(similarityFile);
   835         if (file.open(QIODevice::ReadWrite))
   837             QTextStream stream(&file);
   839             stream << 
"Reference;Registered Image;Output Image;Computation Time;NMI;SSD;NCC;LNCC\n";
   842             for (
int j = 0; j < 
images.size(); j++)
   849                         similarities = 
images[j]->similarities_before;
   851                         similarities = 
images[j]->similarities_after;
   854                     stream << 
images[indexRef]->getPath() << 
";";
   855                     stream << 
images[j]->getPath() << 
";";
   856                     stream << 
images[j]->getOutputPath() << 
";";
   861                         stream << 
images[j]->getDuration() << 
";";
   864                     stream << similarities.
nmi << 
";";
   865                     stream << similarities.
ssd << 
";";
   866                     stream << similarities.
ncc << 
";";
   867                     stream << similarities.
lncc;
   879 void milxQtRegistrationWindow::computeAtlas()
   882     QStringList filenames;
   885     for (
int i = 0; i < 
images.size(); i++)
   887         if (
images[i]->isWorkDone())
   889             filenames.append(
images[i]->getOutputPath());
   902         regError(
"computeAtlas()", 
"Unable to create the atlas file");
   918     QMessageBox msgBox(QMessageBox::Information, 
"Registration", 
"Registration completed !", QMessageBox::NoButton);
   922     for (
int i = 0; i < 
images.size(); i++)
   928     if (!this->
ui.checkBoxOpenResults->isChecked())
   930         QString folder = QDir(this->
ui.inputDirectoryBrowser->text()).absolutePath();
   931         QDesktopServices::openUrl(QUrl::fromLocalFile(folder));
 void updateOpenImages()
Update the list of open images in SMILI. 
bool isFloatingPointImage()
Returns true if image is a floating point (float) image. 
Contain all the values of similarity measurement. 
Contain all the informations and functions required to register an image. 
bool computeAverage
Do we need to compute the average of the registrations. 
QString getDefaultOutputFolder()
Return the default output folder. 
void enableUI()
Enable the user interface. 
void regError(QString functionName, QString errorMsg)
An error happened during the registration or average function. 
milxQtRegistrationParams getParamsDemonItk()
Return the parameters for a Itk Demon registration. 
bool workInProgress
Is there any work in progress. 
bool isImageInList(QString path)
Is the image already listed in our list of images. 
milxQtRegistrationParams getParamsAladinNifti()
Return the parameters for an Nifti Aladin registration. 
milxQtRegistrationAlgos * regAlgos
reg algorithm to compute average 
void workCompleted()
Everything has been completed. 
This class represents the MILX Qt Image Display object using VTK. 
void updateImageListCombo()
Update the list of images in the combo box. 
milxQtRegistrationParams getParamsAladinNifti()
Get the advanced parameter of a Nifti Aladin registration. 
milxQtRegistrationAdvancedOptions * advancedOptionsWindow
Advanced options window. 
void updateParameters()
Update images parameters, set the values of the form to images. 
RegType getCurrentAlgo()
Return the current algorithm selected in the combo box. 
int getNumberOfWindows()
Return the number of windows in the current tab. 
void reset(RegType algo)
Reset the advanced form to the algorithm in parameter. 
virtual ~milxQtRegistrationWindow()
The standard destructor. 
milxQtRegistrationParams getParamsElastixBSpline()
Return the parameters for a Elastix BSpline registration. 
void performRegistrations()
Perform the next registration. 
This class is the advanced options form for the registration. 
QString createAtlasFile()
Create the file for the atlas and return the filepath. 
double ncc
Normalized Cross Correlation. 
milxQtRegistrationWindow(QWidget *theParent)
The standard constructor. 
bool loadFile(const QString &filename)
Opens a file for viewing in the current tab. 
milxQtRegistrationParams getParamsF3DNifti()
Return the parameters for a Nifti F3D registration. 
void setAlgo(RegType regType)
Set the type of algorithm and change the form accordingly (display the correct fields) ...
double ssd
Sum Squared Difference. 
milxQtRegistrationParams getParamsElastixAffine()
Get the advanced parameters of an Elastix Affine registration. 
milxQtImage * nextImage()
Get the next image opened in the current tab. 
QString getName()
Returns the name of the data. 
QWidgetList getListOfWindows()
Get a list of widgets/windows that are in the current tab. 
milxQtRegistrationParams getParamsElastixBSpline()
Get the advanced parameters of an Elastix BSpline registration. 
double nmi
Normalize mutual information. 
milxQtRegistrationParams getParamsElastixAffine()
Return the parameters for a Elastix Affine registration. 
milxQtMain * MainWindow
Main window of SMILIX. 
double lncc
Localy Normalized Cross Correlation. 
void setIsRef(bool)
Set the image as the reference. 
void disableUI()
Disable the user interface. 
void initialiseWindowTraversal()
Initialise the window iterator to the first window opened. 
void addImage(milxQtRegistration *)
Add an image to our list of images. 
QString atlasPath
Path to the outputed atlas. 
This class represents the MILX Qt Main Window object using Qt. 
milxQtRegistrationParams getParamsF3DNifti()
Get the advanced parameter of a Nifti F3D registration. 
QList< milxQtRegistration * > images
List of images for the combobox and list of selectable images. 
milxQtRegistrationParams getParamsAffineItk()
Return the parameters for a Itk Affine registration. 
Ui::dlgRegistrationWindow ui
User interface. 
bool openResults
Store if we need to open the results. 
void initUI()
The standard constructor.