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