1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
20 #include "vvToolPlastimatch.h"
21 #include "vvSlicerManager.h"
23 #include "vvToolInputSelectorWidget.h"
29 #include <QMessageBox>
31 //------------------------------------------------------------------------------
32 // Create the tool and automagically (I like this word) insert it in
33 // the main window menu.
34 ADD_TOOL(vvToolPlastimatch);
35 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
39 void vvToolPlastimatch::Initialize()
41 SetToolName("Plastimatch");
42 SetToolMenuName("Plastimatch");
43 SetToolIconFilename(":/common/icons/plastimatch.png");
44 SetToolTip("Image registration with Plastimatch (G. Sharp).");
45 SetToolExperimental(true);
47 //------------------------------------------------------------------------------
50 //------------------------------------------------------------------------------
51 vvToolPlastimatch::vvToolPlastimatch(vvMainWindowBase * parent, Qt::WindowFlags f)
52 :vvToolWidgetBase(parent,f),
53 vvToolBase<vvToolPlastimatch>(parent),
54 Ui::vvToolPlastimatch()
57 Ui_vvToolPlastimatch::setupUi(mToolWidget);
59 // Connect signals & slots
62 // Set how many inputs are needed for this tool
63 AddInputSelector("Select fixed (reference) image");
64 AddInputSelector("Select moving image");
66 //------------------------------------------------------------------------------
69 //------------------------------------------------------------------------------
70 vvToolPlastimatch::~vvToolPlastimatch()
73 //------------------------------------------------------------------------------
76 //------------------------------------------------------------------------------
77 bool vvToolPlastimatch::close()
79 return vvToolWidgetBase::close();
81 //------------------------------------------------------------------------------
84 //------------------------------------------------------------------------------
85 void vvToolPlastimatch::closeEvent(QCloseEvent *event) {
88 //------------------------------------------------------------------------------
91 //------------------------------------------------------------------------------
92 void vvToolPlastimatch::reject()
94 DD("vvToolPlastimatch::reject");
95 return vvToolWidgetBase::reject();
97 //------------------------------------------------------------------------------
100 //------------------------------------------------------------------------------
101 void vvToolPlastimatch::InputIsSelected(std::vector<vvSlicerManager *> & m)
103 DD("vvToolPlastimatch::InputIsSelected");
105 // Get input images (vvImage)
106 m_InputSlicerManagers = m;
107 m_Fixed = m[0]->GetImage();
108 m_Moving = m[1]->GetImage();
111 if (m_Fixed->GetNumberOfDimensions() != 3) {
112 QMessageBox::information(this, tr("Error"), tr("Sorry, fixed image should be 3D"));
116 if (m_Moving->GetNumberOfDimensions() != 3) {
117 QMessageBox::information(this, tr("Errror"), tr("Sorry, moving image should be 3D"));
122 // We cannot used vvImageToITK directly because we need to cast to
125 // Convert input to float
126 m_FixedVTK = m_Fixed->GetFirstVTKImageData();
127 m_MovingVTK = m_Moving->GetFirstVTKImageData();
128 DD(m_Fixed->GetScalarTypeAsITKString());
129 if (m_Fixed->GetScalarTypeAsITKString() != "float") {
131 m_FixedVTK = CopyAndCastToFloatFrom(m_Fixed->GetFirstVTKImageData());
132 m_MovingVTK = CopyAndCastToFloatFrom(m_Moving->GetFirstVTKImageData());
135 // Convert vtk to itk
136 typedef itk::Image<float, 3> FloatImageType;
137 m_FixedITK = ItkImageFromVtk<3, float>(m_FixedVTK);
138 m_MovingITK = ItkImageFromVtk<3, float>(m_MovingVTK);
140 m_FixedITK->Print(std::cout);
141 m_MovingITK->Print(std::cout);
143 //------------------------------------------------------------------------------
146 //------------------------------------------------------------------------------
147 void vvToolPlastimatch::GetOptionsFromGUI()
149 DD("vvToolPlastimatch::GetOptionsFromGUI");
153 //------------------------------------------------------------------------------
156 //------------------------------------------------------------------------------
157 void vvToolPlastimatch::apply()
159 DD("vvToolPlastimatch::apply");
161 if (!mCurrentSlicerManager) close();
162 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
165 // Create the command string
166 char *command_string =
170 "grid_spac=100 100 100\n"
174 // Prepare the registration
176 Plm_registration_context *prc = plm_registration_context_create ();
177 plm_registration_set_fixed (prc, m_FixedITK);
178 plm_registration_set_moving (prc, m_MovingITK);
179 plm_registration_set_command_string (prc, command_string);
182 // Run the registration
183 plm_registration_execute (prc);
184 if (plm_registration_get_status (prc) != 0) {
188 // Get registration outputs
189 plm_registration_get_warped_image (prc, &m_WarpedImageITK);
190 plm_registration_get_vector_field (prc, &m_DeformationField);
193 plm_registration_context_destroy (prc);
196 // Get warped output and display it
197 if (m_WarpedImageITK) {
198 m_WarpedImage = vvImageFromITK<3, float>(m_WarpedImageITK);
199 std::ostringstream osstream;
200 osstream << "plm_warped_" << m_InputSlicerManagers[1]->GetFileName() << ".mhd";
201 AddImage(m_WarpedImage, osstream.str());
204 DD("TODO get and display DVF");
207 QMessageBox::information(this, "Error", "No result ...");
211 QApplication::restoreOverrideCursor();
214 //------------------------------------------------------------------------------