1 /*=========================================================================
4 Module: $RCSfile: vvToolMedianFilter.cxx,v $
6 Date: $Date: 2010/05/18 16:20:57 $
7 Version: $Revision: 1.4 $
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()
65 //------------------------------------------------------------------------------
66 void vvToolMedianFilter::Initialize()
68 SetToolName("MedianFilter");
69 SetToolMenuName("MedianFilter");
70 SetToolIconFilename(":common/icons/ducky.png");
71 SetToolTip("Make 'MedianFilter' on an image.");
72 SetToolExperimental(true);
74 //------------------------------------------------------------------------------
76 void vvToolMedianFilter::apply()
80 if (!mCurrentSlicerManager) close();
81 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
83 clitk::MedianImageGenericFilter<args_info_clitkMedianImageFilter>::Pointer filter =
84 clitk::MedianImageGenericFilter<args_info_clitkMedianImageFilter>::New();
85 filter->SetInputVVImage(mCurrentImage);
86 filter->SetArgsInfo(mArgsInfo);
87 filter->EnableReadOnDisk(false);
90 vvImage::Pointer output = filter->GetOutputVVImage();
91 std::ostringstream osstream;
92 osstream << "MedianFiltered_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
93 AddImage(output,osstream.str());
94 QApplication::restoreOverrideCursor();
97 //------------------------------------------------------------------------------
98 void vvToolMedianFilter::GetArgsInfoFromGUI()
100 /* //KEEP THIS FOR READING GGO FROM FILE
102 std::string a = "toto";
103 char * const* argv = new char*;
105 struct cmdline_parser_params p;
106 p.check_required = 0;
107 int good = cmdline_parser_ext(argc, argv, &args_info, &p);
110 mArgsInfo.radius_given=0;
111 mArgsInfo.verbose_flag = false;
112 // mArgsInfo.radius_arg = new int[3];
113 // Required (even if not used)
114 mArgsInfo.input_given = 0;
115 mArgsInfo.output_given = 0;
116 mArgsInfo.input_arg=new char;
117 mArgsInfo.output_arg = new char;
118 mArgsInfo.config_given=0;
119 mArgsInfo.verbose_given=0;
121 //------------------------------------------------------------------------------
122 void vvToolMedianFilter::InputIsSelected(vvSlicerManager *m)
124 mCurrentSlicerManager =m;
125 // Specific for this gui
126 mArgsInfo.radius_arg = new int[3];
127 int checkdimensions=mCurrentSlicerManager->GetDimension();
128 if(checkdimensions<3) {
129 horizontalSlider_3->hide();
131 mArgsInfo.radius_arg[2]=0;
132 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(UpdateH1slider()));
133 connect(horizontalSlider_2, SIGNAL(valueChanged(int)), this, SLOT(UpdateH2slider()));
135 horizontalSlider->show();
136 horizontalSlider_2->show();
137 horizontalSlider_3->show();
138 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(UpdateH1slider()));
139 connect(horizontalSlider_2, SIGNAL(valueChanged(int)), this, SLOT(UpdateH2slider()));
140 connect(horizontalSlider_3, SIGNAL(valueChanged(int)), this, SLOT(UpdateH3slider()));
144 //-----------------------------------------------------------------------------
146 void vvToolMedianFilter::UpdateH1slider()
149 mArgsInfo.radius_arg[0]=horizontalSlider->value();
150 spinBox->setValue(mArgsInfo.radius_arg[0]);
152 void vvToolMedianFilter::UpdateH2slider()
154 mArgsInfo.radius_arg[1]=horizontalSlider_2->value();
155 spinBox_2->setValue(mArgsInfo.radius_arg[1]);
157 void vvToolMedianFilter::UpdateH3slider()
159 mArgsInfo.radius_arg[2]=horizontalSlider_3->value();
160 spinBox_3->setValue(mArgsInfo.radius_arg[2]);