Computer Assisted Medical Intervention Tool Kit  version 5.2
SimpleElastixRegistrationAction.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 #ifndef SIMPLEELASTIXREGISTRATIONACTION_H
26 #define SIMPLEELASTIXREGISTRATIONACTION_H
27 
28 #include <Action.h>
29 #include <ImageComponent.h>
30 
31 #include "ElastixRegistrationAPI.h"
32 
41  Q_OBJECT
42 
43 public:
46 
49 
51  virtual QWidget* getWidget() override;
52 
54  enum TransformationType { TRANSLATION, AFFINE, B_SPLINE };
55  Q_ENUM(TransformationType)
56 
57  enum MetricType { ADVANCED_MEAN_SQUARES, ADVANCED_NORMALIZED_CORRELATION, ADVANCED_MATTES_MUTUAL_INFORMATION, NORMALIZED_MUTUAL_INFORMATION };
58  Q_ENUM(MetricType)
59 
60 
61  virtual bool event(QEvent* e) override;
62 
63 public slots:
69  virtual camitk::Action::ApplyStatus apply() override;
70 
71 private:
73 // virtual void process();
74 
75 private:
76  // last run results
77  int lastExitCode;
78  QString lastStdOutput;
79  QString lastProcessError;
80 
81  // used to map item id with component for the "Fixed Image" and "Moving Image" combo box properties
82  QList<camitk::ImageComponent*> imageComponentList;
83 
84  // update the elastix version property
85  void updateElastixVersion();
86 
87  // ask the elastix executable path to the user, return true if the path is correct
88  void defineElastixExecutable();
89 
90  // return the current test name using images names and parameter values
91  QString defaultResultName() const;
92 
93  // name of the transformation computed by elastix
94  // As the computed transformation deforms the moving image into the fixed image,
95  // the transformation is a transform from moving to fixed, i.e., {}^{fixed} T_{moving}.
96  // The name should therefore be "moving_to_fixed" where "moving" is the moving image
97  // component name and "fixed" is the fixed image component name
98  QString transformName() const;
99 
100  // save the given image component to the given path (preserving the filename)
101  // returns the file name without the path if succeed, empty string otherwise
102  QString saveComponentAs(camitk::ImageComponent* comp, QString path) const;
103 
104  // create the elastix parameter file from the current properties, return true if the parameter file was created without error
105  bool createParameterFile(QFileInfo parameterFileInfo, QString initialization, QString transformType, QString similarityMetric) const;
106 
107  // run elastix with the given parameter in the given directory, return true if elastix exit with code 0
108  bool runElastix(QStringList arguments, QString workingDirectory = "");
109 
110  // Copy the resulting image and logs to the moving image file directory
111  // if everything went well returns the new mhd file to open
112  QString copyResults(QString tempDir) const;
113 
114  // copy the given oldName file (name without dir) from source directory
115  // to newName file in the destination directory
116  bool copyFile(QString oldName, QDir source, QString newName, QDir destination) const;
117 
118  // replace searchString by replacementString in fileName (given as full absolute path)
119  bool replaceInFile(const QString& fileName, const QString& searchString, const QString& replacementString) const;
120 };
121 #endif // SIMPLEELASTIXREGISTRATIONACTION_H
#define ELASTIX_REGISTRATION_API
Definition: ElastixRegistrationAPI.h:8
Perform a registration.
Definition: SimpleElastixRegistrationAction.h:40
TransformationType
Possible Transformation.
Definition: SimpleElastixRegistrationAction.h:54
@ AFFINE
Definition: SimpleElastixRegistrationAction.h:54
MetricType
Definition: SimpleElastixRegistrationAction.h:57
@ ADVANCED_MATTES_MUTUAL_INFORMATION
Definition: SimpleElastixRegistrationAction.h:57
This class describes what is a generic Action extension.
Definition: ActionExtension.h:57
Action class is an abstract class that enables you to build a action (generally on a component).
Definition: Action.h:209
ApplyStatus
describes what happened during the application of an algorithm (i.e. results of the apply method)
Definition: Action.h:225
virtual camitk::Action::ApplyStatus apply()=0
This method is called when the action has to be applied on the target list (get the target lists usin...
virtual QWidget * getWidget()
This method has to be redefined in your Action only if:
Definition: Action.cpp:168
The manager of the Image Volume data.
Definition: ImageComponent.h:77