]> Creatis software - clitk.git/blob - vv/vvToolMedianFilter.cxx
Added Manual Registration Tool with updated Median Filter tool
[clitk.git] / vv / vvToolMedianFilter.cxx
1     /*=========================================================================
2
3       Program:   vv
4       Module:    $RCSfile: vvToolMedianFilter.cxx,v $
5       Language:  C++
6       Date:      $Date: 2010/04/26 18:21:55 $
7       Version:   $Revision: 1.2 $
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 "vvToolMedianFilter.h"
29     #include "vvSlicerManager.h"
30     #include "vvSlicer.h"
31     #include "vvToolInputSelectorWidget.h"
32     #include <clitkMedianImageGenericFilter.h>
33
34
35     //------------------------------------------------------------------------------
36     // Create the tool and automagically 
37     ADD_TOOL(vvToolMedianFilter);
38     //------------------------------------------------------------------------------
39
40     //------------------------------------------------------------------------------
41     vvToolMedianFilter::vvToolMedianFilter(vvMainWindowBase * parent, Qt::WindowFlags f) 
42       :vvToolWidgetBase(parent,f), 
43       vvToolBase<vvToolMedianFilter>(parent), 
44       Ui::vvToolMedianFilter()
45       {         
46         
47       // Setup the UI
48     
49     Ui_vvToolMedianFilter::setupUi(mToolWidget);
50     
51     mFilter = new clitk::MedianImageGenericFilter<args_info_clitkMedianImageFilter>;
52     
53
54
55       // Main filter 
56
57       // Set how many inputs are needed for this tool
58   AddInputSelector("Select one image", mFilter);
59     }
60
61     //------------------------------------------------------------------------------
62     vvToolMedianFilter::~vvToolMedianFilter() {
63     }
64     //------------------------------------------------------------------------------
65     void vvToolMedianFilter::Initialize() {
66       SetToolName("MedianFilter");
67       SetToolMenuName("MedianFilter");
68       SetToolIconFilename(":common/icons/ducky.png");
69       SetToolTip("Make 'MedianFilter' on an image.");
70     }
71     //------------------------------------------------------------------------------
72
73   void vvToolMedianFilter::apply() {
74
75      GetArgsInfoFromGUI();
76     if (!mCurrentSlicerManager) close();
77   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
78   // Main filter
79   clitk::MedianImageGenericFilter<args_info_clitkMedianImageFilter>::Pointer filter = 
80      clitk::MedianImageGenericFilter<args_info_clitkMedianImageFilter>::New();
81    filter->SetInputVVImage(mCurrentImage);
82    filter->SetArgsInfo(mArgsInfo);
83    filter->EnableReadOnDisk(false);
84    filter->Update();
85   // Output
86   vvImage::Pointer output = filter->GetOutputVVImage();
87   std::ostringstream osstream;
88   osstream << "MedianFiltered_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
89   AddImage(output,osstream.str()); 
90   QApplication::restoreOverrideCursor();
91   close();
92   }
93     //------------------------------------------------------------------------------
94   void vvToolMedianFilter::GetArgsInfoFromGUI() {
95     /* //KEEP THIS FOR READING GGO FROM FILE
96       int argc=1;
97       std::string a = "toto";
98       char * const* argv = new char*;
99       //a.c_str();
100       struct cmdline_parser_params p;
101       p.check_required = 0;
102       int good = cmdline_parser_ext(argc, argv, &args_info, &p);
103     DD(good);
104     */
105     mArgsInfo.radius_given=0;
106     mArgsInfo.verbose_flag = false;
107    // mArgsInfo.radius_arg = new int[3];
108   // Required (even if not used)
109     mArgsInfo.input_given = 0;
110     mArgsInfo.output_given = 0;
111     mArgsInfo.input_arg=new char;
112     mArgsInfo.output_arg = new char;
113     mArgsInfo.config_given=0;
114     mArgsInfo.verbose_given=0;
115   }
116   //------------------------------------------------------------------------------
117 void vvToolMedianFilter::InputIsSelected(vvSlicerManager *m){
118   mCurrentSlicerManager =m;
119   // Specific for this gui
120     mArgsInfo.radius_arg = new int[3];
121   int checkdimensions=mCurrentSlicerManager->GetDimension();
122   if(checkdimensions<3)
123   {
124    horizontalSlider_3->hide();
125    spinBox_3->hide();
126    mArgsInfo.radius_arg[2]=0;
127    connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(UpdateH1slider()));
128    connect(horizontalSlider_2, SIGNAL(valueChanged(int)), this, SLOT(UpdateH2slider())); 
129   }
130   else
131   {
132   horizontalSlider->show();
133   horizontalSlider_2->show();  
134   horizontalSlider_3->show();
135   connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(UpdateH1slider()));
136   connect(horizontalSlider_2, SIGNAL(valueChanged(int)), this, SLOT(UpdateH2slider()));
137   connect(horizontalSlider_3, SIGNAL(valueChanged(int)), this, SLOT(UpdateH3slider()));   
138   }
139 }
140
141 //-----------------------------------------------------------------------------
142
143 void vvToolMedianFilter::UpdateH1slider()
144 {
145   
146   mArgsInfo.radius_arg[0]=horizontalSlider->value();
147   spinBox->setValue(mArgsInfo.radius_arg[0]);
148 }
149 void vvToolMedianFilter::UpdateH2slider()
150 {
151   mArgsInfo.radius_arg[1]=horizontalSlider_2->value(); 
152   spinBox_2->setValue(mArgsInfo.radius_arg[1]);
153 }
154 void vvToolMedianFilter::UpdateH3slider()
155 {
156   mArgsInfo.radius_arg[2]=horizontalSlider_3->value(); 
157   spinBox_3->setValue(mArgsInfo.radius_arg[2]);
158 }