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
167 const char *command_string =
171 "grid_spac=100 100 100\n"
176 // Prepare the registration
178 Plm_registration_context *prc = plm_registration_context_create ();
179 plm_registration_set_fixed (prc, m_FixedITK);
180 plm_registration_set_moving (prc, m_MovingITK);
181 plm_registration_set_command_string (prc, command_string);
184 // Run the registration
185 plm_registration_execute (prc);
186 if (plm_registration_get_status (prc) != 0) {
190 // Get registration outputs
191 plm_registration_get_warped_image (prc, &m_WarpedImageITK);
192 plm_registration_get_vector_field (prc, &m_DeformationField);
195 plm_registration_context_destroy (prc);
198 // Get warped output and display it
199 if (m_WarpedImageITK) {
200 m_WarpedImage = vvImageFromITK<3, float>(m_WarpedImageITK);
201 std::ostringstream osstream;
202 osstream << "plm_warped_" << m_InputSlicerManagers[1]->GetFileName() << ".mhd";
203 AddImage(m_WarpedImage, osstream.str());
206 DD("TODO get and display DVF");
209 QMessageBox::information(this, "Error", "No result ...");
213 QApplication::restoreOverrideCursor();
216 //------------------------------------------------------------------------------