Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FilterDialogMean.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include <Gui/FilterDialogMean.hh>
26 
27 using namespace BIAS;
28 
29 template <class InputST, class OutputST>
32  wxWindow* parent,
33  wxWindowID id,
34  const wxString& title,
35  const wxString& name)
36 : FilterDialogBase<InputST, OutputST>(origImage, parent, id, title, name),
37  MeanFilter(Mean<InputST, OutputST>()),
38  OldParamVal(1)
39 {
40  this->SizeLabel = new wxStaticText(this,
41  wxID_STATIC,
42  wxT("Size:"),
43  wxDefaultPosition,
44  wxDefaultSize,
45  0);
46  this->SizeSpinCtrl = new wxSpinCtrl(this,
47  this->ID_SPINCTRL_MEAN,
48  wxEmptyString,
49  wxDefaultPosition,
50  wxDefaultSize,
51  wxSP_ARROW_KEYS,
52  1,
53  100,
54  1);
55  this->SizeSlider = new wxSlider(this,
56  this->ID_SLIDER_MEAN,
57  1,
58  1,
59  100,
60  wxDefaultPosition,
61  wxSize(300, -1),
62  wxSL_HORIZONTAL | wxSL_AUTOTICKS);
63 
64  // spinctrl, slider, spacer/spinctrl
65  wxBoxSizer* paramSizer = this->GetParamSizer();
66  paramSizer->Add(this->SizeLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
67  paramSizer->Add(this->SizeSpinCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
68  paramSizer->Add(this->SizeSlider, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxGROW, 5);
69 
70  this->Connect(BIAS::ID_BTN_FILTER_FDB,
71  wxEVT_COMMAND_BUTTON_CLICKED,
72  wxCommandEventHandler(FilterDialogMean::OnFilterButton));
73 
74  this->Connect(this->ID_SLIDER_MEAN,
75  wxEVT_SCROLL_CHANGED,
76  wxScrollEventHandler(FilterDialogMean::OnSlider));
77 
78  this->Connect(this->ID_SPINCTRL_MEAN,
79  wxEVT_COMMAND_SPINCTRL_UPDATED,
80  wxSpinEventHandler(FilterDialogMean::OnSpinCtrl));
81 
82  this->GetParent()->Disable();
83  this->CreateStatusBar(1);
84  this->GetSizer()->Fit(this);
85  this->Centre();
86 }
87 
88 
89 template <class InputST, class OutputST>
91 {
92  if (!this->GetParent()->IsEnabled()) {
93  this->GetParent()->Enable();
94  }
95 }
96 
97 
98 /******************************************************************************/
99 /* ============================== protected ================================= */
100 /******************************************************************************/
101 
102 template <class InputST, class OutputST>
104 ::OnFilterButton(wxCommandEvent& WXUNUSED(event))
105 {
106  // disable some buttons to avoid interference, e.g. pressing preview during
107  // filtering...
108  this->EnableSaveButton(false);
109  this->EnableFilterButton(false);
110  this->EnablePreviewButton(false);
111  this->EnableResetButton(false);
112  this->EnableCancelButton(false);
113 
114  unsigned int size = this->SizeSpinCtrl->GetValue();
115 
116  if ((size != this->OldParamVal) && (size > 1)) {
117 
118  this->MeanFilter.SetSize(size);
119  Image<OutputST> dstImg;
120 
121  if (0 != this->MeanFilter.Filter(this->GetOriginalImage(), dstImg)) {
122 
123  BIASERR("FilterDialogMean::OnFilterButton: Filter Error");
124  this->SetImageIsFiltered(false);
125  this->SetStatusText(wxT("ERROR during FILTER"));
126 
127  } else {
128 
129  this->SetFilteredImage(dstImg);
130  this->SetImageIsFiltered(true);
131  this->OldParamVal = size;
132  wxString msg;
133  msg.Printf(wxT("Image Successfully Filtered With Size: %i"), size);
134  this->SetStatusText(msg);
135 
136  }
137 
138  } else if ((size == 1) && (this->GetImageIsFiltered())) {
139 
140  this->CopyOriginalImage();
141  this->SetImageIsFiltered(false);
142  this->OldParamVal = 1;
143  this->SetStatusText(wxT("Reseted To Original Image Values"));
144 
145  } else { // size == 1 or size == OldParamVal
146 
147  this->SetStatusText(wxT("Nothing Done To The Filtered Image"));
148  }
149 
150  // enable the buttons again
151  this->EnableSaveButton();
152  this->EnableFilterButton();
153  this->EnablePreviewButton();
154  this->EnableResetButton();
155  this->EnableCancelButton();
156 }
157 
158 
159 template <class InputST, class OutputST>
161 ::OnResetButton(wxCommandEvent& event)
162 {
163  // call the Base's class OnResetButton() method and pass the event
165  this->SetImageIsFiltered(false);
166  this->SetStatusText(wxT("Filtered Image Reseted"));
167 }
168 
169 
170 /******************************************************************************/
171 /* =============================== private ================================== */
172 /******************************************************************************/
173 
174 template <class InputST, class OutputST>
176 ::OnSpinCtrl(wxSpinEvent& WXUNUSED(event))
177 {
178  this->SizeSlider->SetValue(this->SizeSpinCtrl->GetValue());
179 }
180 
181 
182 template <class InputST, class OutputST>
184 ::OnSlider(wxScrollEvent& WXUNUSED(event))
185 {
186  this->SizeSpinCtrl->SetValue(this->SizeSlider->GetValue());
187 }
188 
189 
190 /* =================== supported storagetype combinations =================== */
191 namespace BIAS{
194 //template class FilterDialogMean<float, unsigned char>;
195 template class FilterDialogMean<float, float>;
196 }
void OnFilterButton(wxCommandEvent &WXUNUSED(event))
concrete Implementation of the pure OnFilterButton() from the base class.
FilterDialogMean(const Image< InputST > &origImage, wxWindow *parent, wxWindowID id=BIAS::ID_WIN_MEAN, const wxString &title=wxT("Mean Filter Dialog"), const wxString &name=wxT("FilterDialogMean"))
void OnResetButton(wxCommandEvent &event)
Implementation of a Mean filter dialog.
Base class for all filter dialogs.
average mean filter
Definition: Mean.hh:41
virtual void OnResetButton(wxCommandEvent &WXUNUSED(event))
Reset the original image but it does not reset the given parameter(s)