1 #include "milxQtRegistration.h" 2 #include "milxQtFile.h" 17 this->
startTime = QDateTime::currentMSecsSinceEpoch();
19 if (this->
type == AffineItk)
24 else if (this->
type == DemonItk)
30 else if (this->
type == AladinNifti)
35 else if (this->
type == F3DNifti)
42 else if (this->
type == ElastixAffine)
47 else if (this->
type == ElastixBSpline)
60 QString filename = QFileInfo(
path).baseName();
63 params.floatingName =
createFile(QDir::tempPath() + QDir::separator() +
"smili_reg_img_XXXXXX.nii.gz");
64 params.referenceName =
createFile(QDir::tempPath() + QDir::separator() +
"smili_reg_ref_XXXXXX.nii.gz");
70 if (
params.referenceName ==
"" ||
params.floatingName ==
"" ||
params.outputName ==
"")
76 if (this->
type == F3DNifti)
79 params.cppOutputName =
createFile(QDir::tempPath() + QDir::separator() +
"smili_reg_cpp_XXXXXX.nii.gz");
80 if (
params.cppOutputName ==
"")
89 if (
params.defOutputName ==
"")
97 if ((this->
type == ElastixAffine || this->
type == ElastixBSpline) &&
params.customParameterFile ==
false)
99 params.parameterFile =
createFile(QDir::tempPath() + QDir::separator() +
"elastix_reg_params_XXXXXX.txt");
100 if (
params.parameterFile ==
"")
107 if ((this->
type == ElastixAffine || this->
type == ElastixBSpline) &&
params.customParameterFile ==
false)
110 QFile outputFile(
params.parameterFile);
111 outputFile.open(QIODevice::WriteOnly);
114 if (!outputFile.isOpen()) {
116 algoError(
"createFiles()",
"Unable to write elastix parameter file: \"" +
params.parameterFile +
"\"");
119 QTextStream outStream(&outputFile);
120 outStream <<
params.parametersTxt;
140 QString strTypeAlgo =
"unknownalgo";
141 if (this->
type == AffineItk) strTypeAlgo =
"affineitk";
142 if (this->
type == DemonItk) strTypeAlgo =
"demonitk";
143 if (this->
type == F3DNifti) strTypeAlgo =
"f3dnifti";
144 if (this->
type == AladinNifti) strTypeAlgo =
"aladinnifti";
145 if (this->
type == ElastixAffine) strTypeAlgo =
"elastixaffine";
146 if (this->
type == ElastixBSpline) strTypeAlgo =
"elastixbspline";
154 QString filename = QFileInfo(
path).baseName();
161 QString filename = QFileInfo(
path).baseName();
168 QString filename = QFileInfo(
path).baseName();
175 QByteArray byteArray = src.toAscii();
176 strncpy(dest, byteArray.data(), FILENAME_MAX);
182 if (istheref ==
true) {
230 QTemporaryFile tmpFile(pathTemplate);
231 tmpFile.setAutoRemove(
false);
232 if (!tmpFile.open()) {
233 algoError(
"createFile()",
"Unable to create temporary file with template: \"" + pathTemplate +
"\".\n");
240 return tmpFile.fileName();
246 if (
params.floatingName !=
"") {
247 if (QFile::exists(
params.floatingName))
249 QFile::remove(
params.floatingName);
253 if (
params.referenceName !=
"") {
254 if (QFile::exists(
params.referenceName))
256 QFile::remove(
params.referenceName);
260 if (
params.cppOutputName !=
"") {
261 if (QFile::exists(
params.cppOutputName))
263 QFile::remove(
params.cppOutputName);
268 if (
params.customParameterFile ==
false &&
params.parameterFile !=
"")
270 if (QFile::exists(
params.parameterFile))
272 QFile::remove(
params.parameterFile);
278 params.referenceName =
"";
279 params.cppOutputName =
"";
280 params.parameterFile =
"";
289 this->
stopTime = QDateTime::currentMSecsSinceEpoch();
311 this->
regAlgos->similarities_async(
this);
337 emit
error(functionName, errorMsg);
342 void milxQtRegistration::cpp2defCompleted()
348 this->
regAlgos->similarities_async(
this);
360 void milxQtRegistration::similaritiesComputed()
429 connect(this->
regAlgos, SIGNAL(cpp2defCompleted()),
this, SLOT(cpp2defCompleted()));
432 connect(this->
regAlgos, SIGNAL(similaritiesComputed()),
this, SLOT(similaritiesComputed()));
int createFiles()
Create the files required for the registration.
QString getAlgoName()
Return the name of the current algorithm.
void init(QString)
Initialise the class/object with default parameters.
bool isOpened()
Is the image open in SMILi.
bool isChecked()
Is the image checked (if we have to perform a registration)
void copyAndReplace(QString src, QString dst)
Copy and replace.
milxQtImage * window
MilxQt window of the image, if the image is already opened in SMILI.
Contain all the informations and functions required to register an image.
void affine_async(milxQtRegistrationParams params)
Perform a ITK affine registration asynchroniously.
~milxQtRegistration()
The standard destructor.
void algoError(QString functionName, QString errorMsg)
The registration and transformations have been done.
QString getPath()
Get the path of the file.
bool saveImage(const QString filename, vtkImageData *data)
Saves data as an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI, HDR etc.
bool openedImage
Is the image already opened in SMILI.
This class represents the MILX Qt Image Display object using VTK.
void copyPath(char dest[FILENAME_MAX], QString src)
Copy a path from a QString to a char *.
void deleteTmpFiles()
Delete the temporary files.
void done()
The registration and transformations have been done.
This class represents the MILX Qt File I/O object using VTK/ITK/Qt.
void setReference(milxQtRegistration *)
Set the reference image.
bool workDone
Is the registration done.
void registrationCompleted()
The registration is completed.
void printDebug(QString msg)
Debug message wrapper for console.
QString createSimilarityFileBefore()
Create the similarity file containing the similarity after the registration was performed and return ...
void setOpenResults(bool open)
Open the results after the registration.
bool openResults
Do we have to open the results after the registration.
bool isRef()
Is the image the reference image.
void printInfo(QString msg)
Info message wrapper for console.
bool isWorkDone()
Is the registration/deformation field calculation completed.
milxQtMain * MainWindow
Main window of SMILI.
RegType type
Type of the registration.
void setComputeSimilarities(bool)
Set if we should compute the similarities.
QString createAtlasFile()
Create the file for the atlas and return the filepath.
void setParams(milxQtRegistrationParams)
Set the registration parameters.
double ncc
Normalized Cross Correlation.
QString createFile(QString pathtemplate)
Create a file and return the path.
milxQtSimilarities similarities_after
Similarities after the registration.
bool loadFile(const QString &filename)
Opens a file for viewing in the current tab.
bool openImage(const QString filename, vtkImageData *data)
Opens an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI, HDR etc.
bool isRefImg
Is this image the reference image.
bool checked
Is the image checked: do we need to perform a registration.
void setOutputFolder(QString)
Set the output folder for the registration.
double ssd
Sum Squared Difference.
bool isLoaded()
Is the data successfully loaded? Use this to check if all is ok with data display.
QString path
Path of the image.
bool computeSimilarities
Do we have to compute similarities.
QString createSimilarityFileAfter()
Create the similarity file containing the similarity after the registration was performed and return ...
QString getName()
Returns the name of the data.
milxQtRegistrationParams params
Parameters for registration.
qint64 startTime
Time start of the registration.
milxQtRegistration * reference
Reference image for the registration.
milxQtImage * getImage()
Return the image object for registration.
void setChecked(bool)
Do we have to perform a registration on this image (is the image check in the form) ...
double nmi
Normalize mutual information.
milxQtSimilarities similarities_before
Similarities before the registration.
qint64 getDuration()
Return the duration of the registration in milliseconds.
void demon_async(milxQtRegistrationParams params)
Perform a ITK demon registration asynchroniously.
void setRegType(RegType)
Set the registration type.
double lncc
Localy Normalized Cross Correlation.
void error(QString functionName, QString errorMsg)
The registration and transformations have been done.
void setIsRef(bool)
Set the image as the reference.
milxQtRegistration(QObject *parent, milxQtImage *imageWindow, milxQtMain *mainW)
The standard constructor.
int startRegistration()
Start the registrationf.
QString getOutputFolder()
Return the path of the output folder.
qint64 stopTime
Time the registration ended.
milxQtRegistrationAlgos * regAlgos
Class containing the algorithms for the registration.
This class represents the MILX Qt Main Window object using Qt.
void reset()
Reset the class (It will be like no registration happened)
QString getOutputPath()
Return the path of the output file.
QString outputFolder
Path of the output folder.