]> Creatis software - clitk.git/blob - vv/vvToolMIP.cxx
MIP tool using David's framework
[clitk.git] / vv / vvToolMIP.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolMIP.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/10/26 12:37:58 $
7   Version:   $Revision: 1.1 $
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   delete mFilter;
65 }
66 //------------------------------------------------------------------------------
67 void vvToolMIP::Initialize()
68 {
69   SetToolName("MIP");
70   SetToolMenuName("Maximum Intensity Projection");
71   SetToolIconFilename(":common/icons/ducky.png");
72   SetToolTip("Compute the maximum intensity projection of an image.");
73   SetToolExperimental(true);
74 }
75 //------------------------------------------------------------------------------
76
77 void vvToolMIP::apply()
78 {
79   if (!mCurrentSlicerManager) close();
80   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
81   // Main filter
82   clitk::MIPGenericFilter::args_info_type args_info;
83   cmdline_parser_clitkMIP_init(&args_info);
84   args_info.dimension_arg=this->dimensionSpinBox->value();
85   args_info.dimension_given=true;
86   clitk::MIPGenericFilter* filter= dynamic_cast<clitk::MIPGenericFilter*>(mFilter);
87   filter->SetArgsInfo(args_info);
88   filter->SetInputVVImage(mCurrentImage);
89   filter->Update();
90   vvImage::Pointer output = filter->GetOutputVVImage();
91   std::ostringstream osstream;
92   osstream << "MIPed_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
93   AddImage(output,osstream.str());
94   QApplication::restoreOverrideCursor();
95   close();
96 }
97 //------------------------------------------------------------------------------
98 void vvToolMIP::InputIsSelected(vvSlicerManager *m)
99 {
100   mCurrentSlicerManager =m;
101   this->dimensionSpinBox->setMaximum(m->GetDimension()-1);
102 }
103
104 //-----------------------------------------------------------------------------