]> Creatis software - clitk.git/blob - vv/vvToolMIP.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvToolMIP.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
20   Program:   vv
21   Module:    $RCSfile: vvToolMIP.cxx,v $
22   Language:  C++
23   Date:      $Date: 2011/04/15 08:29:21 $
24   Version:   $Revision: 1.3 $
25   Author :   Bharath Navalpakkam (Bharath.Navalpakkam@creatis.insa-lyon.fr)
26
27   Copyright (C) 2010
28   Léon Bérard cancer center http://www.centreleonberard.fr
29   CREATIS                   http://www.creatis.insa-lyon.fr
30
31   This program is free software: you can redistribute it and/or modify
32   it under the terms of the GNU General Public License as published by
33   the Free Software Foundation, version 3 of the License.
34
35   This program is distributed in the hope that it will be useful,
36   but WITHOUT ANY WARRANTY; without even the implied warranty of
37   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38   GNU General Public License for more details.
39
40   You should have received a copy of the GNU General Public License
41   along with this program.  If not, see <http://www.gnu.org/licenses/>.
42
43   =========================================================================*/
44
45 #include <QMessageBox>
46 #include <QSpinBox>
47 #include <itkImage.h>
48 #include <itkMaximumProjectionImageFilter.h>
49
50 #include "vvToolMIP.h"
51 #include "vvSlicerManager.h"
52 #include "vvSlicer.h"
53 #include "vvToolInputSelectorWidget.h"
54 #include "clitkMIPGenericFilter.h"
55
56 //------------------------------------------------------------------------------
57 // Create the tool and automagically
58 ADD_TOOL(vvToolMIP);
59 //------------------------------------------------------------------------------
60
61 //------------------------------------------------------------------------------
62 vvToolMIP::vvToolMIP(vvMainWindowBase * parent, Qt::WindowFlags f)
63   :vvToolWidgetBase(parent,f),
64    vvToolBase<vvToolMIP>(parent),
65    Ui::vvToolMIP()
66 {
67   // Setup the UI
68   Ui_vvToolMIP::setupUi(mToolWidget);
69   //mFilter=clitk::MIPGenericFilter::New(); //Causes a segfault. Why? (joel 26/10/2010)
70   mFilter=new clitk::MIPGenericFilter;
71
72   // Main filter
73   // Set how many inputs are needed for this tool
74   //AddInputSelector("Select one image", mFilter);
75   AddInputSelector("Select one image");
76 }
77
78 //------------------------------------------------------------------------------
79 vvToolMIP::~vvToolMIP()
80 {
81 }
82 //------------------------------------------------------------------------------
83 void vvToolMIP::Initialize()
84 {
85   SetToolName("MIP");
86   SetToolMenuName("Maximum Intensity Projection");
87   SetToolIconFilename(":common/icons/mip.png");
88   SetToolTip("Compute the maximum intensity projection of an image.");
89   SetToolExperimental(false);
90 }
91 //------------------------------------------------------------------------------
92
93 void vvToolMIP::apply()
94 {
95   if (!mCurrentSlicerManager) close();
96   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
97   // Main filter
98   clitk::MIPGenericFilter::args_info_type args_info;
99   cmdline_parser_clitkMIP_init(&args_info);
100   args_info.dimension_arg=this->dimensionSpinBox->value();
101   args_info.dimension_given=true;
102   clitk::MIPGenericFilter* filter= dynamic_cast<clitk::MIPGenericFilter*>(mFilter.GetPointer());
103   filter->SetArgsInfo(args_info);
104   filter->SetInputVVImage(mCurrentImage);
105   filter->Update();
106   vvImage::Pointer output = filter->GetOutputVVImage();
107   std::ostringstream osstream;
108   osstream << "MIPed_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
109   AddImage(output,osstream.str());
110   QApplication::restoreOverrideCursor();
111   close();
112 }
113 //------------------------------------------------------------------------------
114 void vvToolMIP::InputIsSelected(vvSlicerManager *m)
115 {
116   mCurrentSlicerManager =m;
117   if (m->GetDimension() <3) {
118     QMessageBox::information(this, "Wrong image dimension","Sorry, only work with 3D or 4D images.");
119     close();
120     return;
121   }
122   this->dimensionSpinBox->setMaximum(m->GetDimension()-1);
123 }
124
125 //-----------------------------------------------------------------------------