1 /*=========================================================================
4 Module: $RCSfile: vvToolMedianFilter.cxx,v $
6 Date: $Date: 2010/04/26 18:21:55 $
7 Version: $Revision: 1.2 $
8 Author : Bharath Navalpakkam (Bharath.Navalpakkam@creatis.insa-lyon.fr)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS http://www.creatis.insa-lyon.fr
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.
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.
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/>.
26 =========================================================================*/
28 #include "vvToolMedianFilter.h"
29 #include "vvSlicerManager.h"
31 #include "vvToolInputSelectorWidget.h"
32 #include <clitkMedianImageGenericFilter.h>
35 //------------------------------------------------------------------------------
36 // Create the tool and automagically
37 ADD_TOOL(vvToolMedianFilter);
38 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
41 vvToolMedianFilter::vvToolMedianFilter(vvMainWindowBase * parent, Qt::WindowFlags f)
42 :vvToolWidgetBase(parent,f),
43 vvToolBase<vvToolMedianFilter>(parent),
44 Ui::vvToolMedianFilter()
49 Ui_vvToolMedianFilter::setupUi(mToolWidget);
51 mFilter = new clitk::MedianImageGenericFilter<args_info_clitkMedianImageFilter>;
57 // Set how many inputs are needed for this tool
58 AddInputSelector("Select one image", mFilter);
61 //------------------------------------------------------------------------------
62 vvToolMedianFilter::~vvToolMedianFilter() {
64 //------------------------------------------------------------------------------
65 void vvToolMedianFilter::Initialize() {
66 SetToolName("MedianFilter");
67 SetToolMenuName("MedianFilter");
68 SetToolIconFilename(":common/icons/ducky.png");
69 SetToolTip("Make 'MedianFilter' on an image.");
71 //------------------------------------------------------------------------------
73 void vvToolMedianFilter::apply() {
76 if (!mCurrentSlicerManager) close();
77 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
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);
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();
93 //------------------------------------------------------------------------------
94 void vvToolMedianFilter::GetArgsInfoFromGUI() {
95 /* //KEEP THIS FOR READING GGO FROM FILE
97 std::string a = "toto";
98 char * const* argv = new char*;
100 struct cmdline_parser_params p;
101 p.check_required = 0;
102 int good = cmdline_parser_ext(argc, argv, &args_info, &p);
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;
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)
124 horizontalSlider_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()));
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()));
141 //-----------------------------------------------------------------------------
143 void vvToolMedianFilter::UpdateH1slider()
146 mArgsInfo.radius_arg[0]=horizontalSlider->value();
147 spinBox->setValue(mArgsInfo.radius_arg[0]);
149 void vvToolMedianFilter::UpdateH2slider()
151 mArgsInfo.radius_arg[1]=horizontalSlider_2->value();
152 spinBox_2->setValue(mArgsInfo.radius_arg[1]);
154 void vvToolMedianFilter::UpdateH3slider()
156 mArgsInfo.radius_arg[2]=horizontalSlider_3->value();
157 spinBox_3->setValue(mArgsInfo.radius_arg[2]);