]> Creatis software - clitk.git/blob - vv/vvToolPlastimatch.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvToolPlastimatch.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 // vv
20 #include "vvToolPlastimatch.h"
21 #include "vvSlicerManager.h"
22 #include "vvSlicer.h"
23 #include "vvToolInputSelectorWidget.h"
24
25 // Plastimatch 
26 // PUT INCLUDE HERE
27
28 // qt
29 #include <QMessageBox>
30
31 //------------------------------------------------------------------------------
32 // Create the tool and automagically (I like this word) insert it in
33 // the main window menu.
34 ADD_TOOL(vvToolPlastimatch);
35 //------------------------------------------------------------------------------
36
37
38 //------------------------------------------------------------------------------
39 void vvToolPlastimatch::Initialize()
40 {
41   SetToolName("Plastimatch");
42   SetToolMenuName("Plastimatch");
43   SetToolIconFilename(":/common/icons/plastimatch.png");
44   SetToolTip("Image registration with Plastimatch (G. Sharp).");
45   SetToolExperimental(true);
46 }
47 //------------------------------------------------------------------------------
48
49
50 //------------------------------------------------------------------------------
51 vvToolPlastimatch::vvToolPlastimatch(vvMainWindowBase * parent, Qt::WindowFlags f)
52   :vvToolWidgetBase(parent,f),
53    vvToolBase<vvToolPlastimatch>(parent),
54    Ui::vvToolPlastimatch()
55 {
56   // GUI Initialization
57   Ui_vvToolPlastimatch::setupUi(mToolWidget);
58
59   // Connect signals & slots
60   // TODO
61
62   // Set how many inputs are needed for this tool
63   AddInputSelector("Select fixed (reference) image");
64   AddInputSelector("Select moving image");
65 }
66 //------------------------------------------------------------------------------
67
68
69 //------------------------------------------------------------------------------
70 vvToolPlastimatch::~vvToolPlastimatch()
71 {
72 }
73 //------------------------------------------------------------------------------
74
75
76 //------------------------------------------------------------------------------
77 bool vvToolPlastimatch::close()
78 {
79   return vvToolWidgetBase::close();
80 }
81 //------------------------------------------------------------------------------
82
83
84 //------------------------------------------------------------------------------
85 void vvToolPlastimatch::closeEvent(QCloseEvent *event) {
86   event->accept();
87 }
88 //------------------------------------------------------------------------------
89
90
91 //------------------------------------------------------------------------------
92 void vvToolPlastimatch::reject()
93 {
94   DD("vvToolPlastimatch::reject");
95   return vvToolWidgetBase::reject();
96 }
97 //------------------------------------------------------------------------------
98
99
100 //------------------------------------------------------------------------------
101 void vvToolPlastimatch::InputIsSelected(std::vector<vvSlicerManager *> & m)
102 {
103   DD("vvToolPlastimatch::InputIsSelected");
104
105   // Get input images (vvImage)
106   m_InputSlicerManagers = m;
107   m_Fixed = m[0]->GetImage();
108   m_Moving = m[1]->GetImage();
109
110   // Check image
111   if (m_Fixed->GetNumberOfDimensions() != 3) {
112     QMessageBox::information(this, tr("Error"), tr("Sorry, fixed image should be 3D"));
113     close();
114     return;
115   }
116   if (m_Moving->GetNumberOfDimensions() != 3) {
117     QMessageBox::information(this, tr("Errror"), tr("Sorry, moving image should be 3D"));
118     close();
119     return;
120   }
121
122   // We cannot used vvImageToITK directly because we need to cast to
123   // float before
124
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") {
130     DD("Cast input");
131     m_FixedVTK = CopyAndCastToFloatFrom(m_Fixed->GetFirstVTKImageData());
132     m_MovingVTK = CopyAndCastToFloatFrom(m_Moving->GetFirstVTKImageData());
133   }
134
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);
139   
140   m_FixedITK->Print(std::cout);
141   m_MovingITK->Print(std::cout);  
142 }
143 //------------------------------------------------------------------------------
144
145
146 //------------------------------------------------------------------------------
147 void vvToolPlastimatch::GetOptionsFromGUI()
148 {
149   DD("vvToolPlastimatch::GetOptionsFromGUI");
150
151
152 }
153 //------------------------------------------------------------------------------
154
155
156 //------------------------------------------------------------------------------
157 void vvToolPlastimatch::apply()
158 {
159   DD("vvToolPlastimatch::apply");
160
161   if (!mCurrentSlicerManager) close();
162   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
163   GetOptionsFromGUI();
164
165   // Create the command string
166   /*
167   const char *command_string =
168     "[STAGE]\n"
169     "xform=bspline\n"
170     "max_its=30\n"
171     "grid_spac=100 100 100\n"
172     "res=4 4 2\n"
173     ;
174     */
175
176   // Prepare the registration
177   /*
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);
182
183
184   // Run the registration
185   plm_registration_execute (prc);
186   if (plm_registration_get_status (prc) != 0) {
187     // Handle error 
188   }
189
190   // Get registration outputs
191   plm_registration_get_warped_image (prc, &m_WarpedImageITK);
192   plm_registration_get_vector_field (prc, &m_DeformationField);
193
194   // Free the memory
195   plm_registration_context_destroy (prc);
196   */
197
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());
204     
205     // Get DVF 
206     DD("TODO get and display DVF");
207   }
208   else {
209     QMessageBox::information(this, "Error", "No result ...");
210   }
211
212   // End
213   QApplication::restoreOverrideCursor();
214   close();
215 }
216 //------------------------------------------------------------------------------
217
218