Skip to content

Commit c678ba2

Browse files
committed
refactor: make DrawPane more readable
1 parent 100514a commit c678ba2

File tree

3 files changed

+78
-71
lines changed

3 files changed

+78
-71
lines changed

include/gui.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,30 @@ class MyApp : public wxApp
1616
virtual bool OnInit();
1717
};
1818

19-
class BasicDrawPane : public wxPanel
19+
class DrawPane : public wxPanel
2020
{
2121

2222
public:
23-
BasicDrawPane(wxPanel *, cv::Size);
23+
DrawPane(wxPanel *, cv::Size);
2424

25-
CLD cld;
26-
cv::Mat dis;
27-
std::string processingS;
2825
void render();
26+
void set_mode(std::string);
27+
cv::Mat &image();
28+
CLD &cld();
2929
DECLARE_EVENT_TABLE()
30+
3031
private:
32+
std::string mode_;
3133
wxClientDC dc_;
34+
CLD cld_;
35+
cv::Mat dis_;
3236
};
3337

3438
class MyFrame : public wxFrame
3539
{
3640
public:
3741
MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
38-
BasicDrawPane *drawPane;
42+
DrawPane *drawPane;
3943
wxPanel *dp; // drawpane Container
4044
wxSlider *slider_rho;
4145
wxSlider *slider_ETFkernel;

src/gui.cpp

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
9797
dp->SetSizer(dps);
9898

9999

100-
drawPane = new BasicDrawPane(dp, cv::Size(256, 256));
100+
drawPane = new DrawPane(dp, cv::Size(256, 256));
101101
dps->Add(drawPane, 1, wxEXPAND);
102102

103103
// wxTextCtrl: http://docs.wxwidgets.org/trunk/classwx_text_ctrl.html
@@ -132,32 +132,32 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
132132
new wxStaticBox(controlpanel, -1, wxT("Line Parameters"), wxDefaultPosition, wxDefaultSize, wxTE_RICH2);
133133
wxStaticBoxSizer *st_paint_sizer = new wxStaticBoxSizer(st_paint, wxVERTICAL);
134134

135-
s.Printf("Noise (rho) : %.3f", drawPane->cld.rho);
135+
s.Printf("Noise (rho): %.3f", drawPane->cld().rho);
136136
slider_rho_t = new wxStaticText(controlpanel, SLIDER_RHO_T, s, wxDefaultPosition, wxDefaultSize, 0);
137137
st_paint_sizer->Add(slider_rho_t, 0, wxEXPAND | wxLEFT, 10);
138138
slider_rho = new wxSlider(
139-
controlpanel, SLIDER_RHO, int(drawPane->cld.rho * 10000), 9000, 10000, wxDefaultPosition, wxDefaultSize, 0);
139+
controlpanel, SLIDER_RHO, int(drawPane->cld().rho * 10000), 9000, 10000, wxDefaultPosition, wxDefaultSize, 0);
140140
st_paint_sizer->Add(slider_rho, 0, wxEXPAND | wxLEFT, 10);
141141

142-
s.Printf("Degree of coherence (sigma_m): %.3f", drawPane->cld.sigma_m);
142+
s.Printf("Degree of coherence (sigma_m): %.3f", drawPane->cld().sigma_m);
143143
slider_sigma1_t = new wxStaticText(controlpanel, SLIDER_SIGMA_M_T, s, wxDefaultPosition, wxDefaultSize, 0);
144144
st_paint_sizer->Add(slider_sigma1_t, 0, wxEXPAND | wxLEFT, 10);
145-
slider_sigma1 = new wxSlider(controlpanel, SLIDER_SIGMA_M, int(drawPane->cld.sigma_m * 1000), 10, 10000,
145+
slider_sigma1 = new wxSlider(controlpanel, SLIDER_SIGMA_M, int(drawPane->cld().sigma_m * 1000), 10, 10000,
146146
wxDefaultPosition, wxDefaultSize, 0);
147147
st_paint_sizer->Add(slider_sigma1, 0, wxEXPAND | wxLEFT, 10);
148148

149-
s.Printf("Line width (sigma_c): %.3f", drawPane->cld.sigma_c);
149+
s.Printf("Line width (sigma_c): %.3f", drawPane->cld().sigma_c);
150150
slider_sigma2_t = new wxStaticText(controlpanel, SLIDER_SIGMA_C_T, s, wxDefaultPosition, wxDefaultSize, 0);
151151
st_paint_sizer->Add(slider_sigma2_t, 0, wxEXPAND | wxLEFT, 10);
152-
slider_sigma2 = new wxSlider(controlpanel, SLIDER_SIGMA_C, int(drawPane->cld.sigma_c * 1000), 10, 10000,
152+
slider_sigma2 = new wxSlider(controlpanel, SLIDER_SIGMA_C, int(drawPane->cld().sigma_c * 1000), 10, 10000,
153153
wxDefaultPosition, wxDefaultSize, 0);
154154
st_paint_sizer->Add(slider_sigma2, 0, wxEXPAND | wxLEFT, 10);
155155

156-
s.Printf("Thresholding (tau) : %.3f", drawPane->cld.tau);
156+
s.Printf("Thresholding (tau): %.3f", drawPane->cld().tau);
157157
slider_t_t = new wxStaticText(controlpanel, SLIDER_TAU_T, s, wxDefaultPosition, wxDefaultSize, 0);
158158
st_paint_sizer->Add(slider_t_t, 0, wxEXPAND | wxLEFT, 10);
159159
slider_t = new wxSlider(
160-
controlpanel, SLIDER_TAU, int(drawPane->cld.tau * 10000), 4000, 10000, wxDefaultPosition, wxDefaultSize, 0);
160+
controlpanel, SLIDER_TAU, int(drawPane->cld().tau * 10000), 4000, 10000, wxDefaultPosition, wxDefaultSize, 0);
161161
st_paint_sizer->Add(slider_t, 0, wxEXPAND | wxLEFT, 10);
162162

163163

@@ -209,7 +209,7 @@ void MyFrame::OnOpenSrc(wxCommandEvent &event)
209209
return; // the user changed idea...
210210
} else {
211211
processingBox->SetValue(MODE_ORIGINIAL_IMAGE);
212-
drawPane->processingS = MODE_ORIGINIAL_IMAGE;
212+
drawPane->set_mode(MODE_ORIGINIAL_IMAGE);
213213

214214
s.Printf("Load Img - %s", openFileDialog.GetFilename());
215215
addlog(s, wxColour(*wxBLUE));
@@ -224,9 +224,9 @@ void MyFrame::OnOpenSrc(wxCommandEvent &event)
224224
wxLogError("Cannot open file '%s'.", openFileDialog.GetPath());
225225
return;
226226
}
227-
drawPane->cld.readSrc((const char *)openFileDialog.GetPath().mb_str());
227+
drawPane->cld().readSrc((const char *)openFileDialog.GetPath().mb_str());
228228

229-
wxSize img(drawPane->cld.originalImg.cols, drawPane->cld.originalImg.rows);
229+
wxSize img(drawPane->cld().originalImg.cols, drawPane->cld().originalImg.rows);
230230
dp->SetMinSize(img);
231231
this->Layout();
232232

@@ -251,8 +251,9 @@ void MyFrame::OnSaveResult(wxCommandEvent &event)
251251
return;
252252
}
253253

254-
cv::cvtColor(drawPane->dis, drawPane->dis, CV_BGR2RGB);
255-
cv::imwrite((const char *)saveFileDialog.GetPath().mb_str(), drawPane->dis);
254+
cv::Mat res = drawPane->image().clone();
255+
cv::cvtColor(drawPane->image(), res, CV_BGR2RGB);
256+
cv::imwrite((const char *)saveFileDialog.GetPath().mb_str(), res);
256257
}
257258

258259

@@ -265,11 +266,11 @@ void MyFrame::OnStart(wxCommandEvent &event)
265266

266267
void MyFrame::OnClean(wxCommandEvent &event)
267268
{
268-
drawPane->cld.init(cv::Size(300, 300));
269+
drawPane->cld().init(cv::Size(300, 300));
269270
ETF_iteration = FDoG_iteration = 0;
270271
drawPane->render();
271272

272-
wxSize img(drawPane->cld.originalImg.cols, drawPane->cld.originalImg.rows);
273+
wxSize img(drawPane->cld().originalImg.cols, drawPane->cld().originalImg.rows);
273274
dp->SetMinSize(img);
274275
this->Layout();
275276

@@ -287,14 +288,14 @@ void MyFrame::OnClean(wxCommandEvent &event)
287288
void MyFrame::OnSolveIt(wxCommandEvent &event)
288289
{
289290
addlog("[CLD] Computing CLD...", wxColour(*wxBLUE));
290-
drawPane->cld.genCLD();
291+
drawPane->cld().genCLD();
291292
addlog("[CLD] done", wxColour(*wxBLUE));
292293
}
293294

294295
void MyFrame::OnRefineETF(wxCommandEvent &event)
295296
{
296297
addlog("[ETF] Refining ETF...", wxColour(*wxBLUE));
297-
(drawPane->cld).etf.refine_ETF(ETF_kernel);
298+
(drawPane->cld()).etf.refine_ETF(ETF_kernel);
298299
addlog("[ETF] Done", wxColour(*wxBLUE));
299300

300301
wxString s;
@@ -305,8 +306,8 @@ void MyFrame::OnRefineETF(wxCommandEvent &event)
305306
void MyFrame::OnIterativeFDoG(wxCommandEvent &event)
306307
{
307308
addlog("[CLD] Iterative FDoG...", wxColour(*wxBLUE));
308-
(drawPane->cld).combineImage();
309-
(drawPane->cld).genCLD();
309+
(drawPane->cld()).combineImage();
310+
(drawPane->cld()).genCLD();
310311
addlog("[CLD] Done", wxColour(*wxBLUE));
311312

312313
wxString s;
@@ -318,17 +319,13 @@ void MyFrame::OnIterativeFDoG(wxCommandEvent &event)
318319
//Comboboxes
319320
void MyFrame::OnProcessingBox(wxCommandEvent &event)
320321
{
321-
wxString s = processingBox->GetValue();
322-
drawPane->processingS = s;
322+
std::string s = processingBox->GetValue();
323+
drawPane->set_mode(s);
323324

324-
if (s == MODE_ETF || s == MODE_ETF_DEBUG) {
325-
render_loop_on = true;
326-
} else {
327-
render_loop_on = false;
328-
}
325+
render_loop_on = (s == MODE_ETF) || (s == MODE_ETF_DEBUG);
329326

330327
if (s == MODE_CLD) {
331-
drawPane->cld.genCLD();
328+
drawPane->cld().genCLD();
332329
wxString s;
333330
s.Printf("FDoG: %d iterations", FDoG_iteration);
334331
SetStatusText(s, 2);
@@ -344,51 +341,51 @@ void MyFrame::OnSliderETFkernel(wxCommandEvent &event)
344341
{
345342
wxString s;
346343
ETF_kernel = slider_ETFkernel->GetValue();
347-
s.Printf("ETF kernel size : %d", ETF_kernel);
344+
s.Printf("ETF kernel size: %d", ETF_kernel);
348345
slider_ETFkernel_t->SetLabel(s);
349346
}
350347

351348
void MyFrame::OnSliderRho(wxCommandEvent &event)
352349
{
353350
wxString s;
354-
drawPane->cld.rho = slider_rho->GetValue() / 10000.0;
355-
s.Printf("Noise(rho) : %.3f", drawPane->cld.rho);
351+
drawPane->cld().rho = slider_rho->GetValue() / 10000.0;
352+
s.Printf("Noise (rho): %.3f", drawPane->cld().rho);
356353
slider_rho_t->SetLabel(s);
357354

358-
drawPane->cld.genCLD();
355+
drawPane->cld().genCLD();
359356
drawPane->render();
360357
}
361358

362359
void MyFrame::OnSliderSigmaM(wxCommandEvent &event)
363360
{
364361
wxString s;
365-
drawPane->cld.sigma_m = slider_sigma1->GetValue() / 1000.0;
366-
s.Printf("Degree of coherence(sigma_m): %.3f", drawPane->cld.sigma_m);
362+
drawPane->cld().sigma_m = slider_sigma1->GetValue() / 1000.0;
363+
s.Printf("Degree of coherence (sigma_m): %.3f", drawPane->cld().sigma_m);
367364
slider_sigma1_t->SetLabel(s);
368365

369-
drawPane->cld.genCLD();
366+
drawPane->cld().genCLD();
370367
drawPane->render();
371368
}
372369

373370
void MyFrame::OnSliderSigmaC(wxCommandEvent &event)
374371
{
375372
wxString s;
376-
drawPane->cld.sigma_c = slider_sigma2->GetValue() / 1000.0;
377-
s.Printf("Line width(sigma_c): %.3f", drawPane->cld.sigma_c);
373+
drawPane->cld().sigma_c = slider_sigma2->GetValue() / 1000.0;
374+
s.Printf("Line width (sigma_c): %.3f", drawPane->cld().sigma_c);
378375
slider_sigma2_t->SetLabel(s);
379376

380-
drawPane->cld.genCLD();
377+
drawPane->cld().genCLD();
381378
drawPane->render();
382379
}
383380

384381
void MyFrame::OnSliderTau(wxCommandEvent &event)
385382
{
386-
drawPane->cld.tau = slider_t->GetValue() / 10000.0;
383+
drawPane->cld().tau = slider_t->GetValue() / 10000.0;
387384
wxString s;
388-
s.Printf("Thresholding(Tau) : %.3f", drawPane->cld.tau);
385+
s.Printf("Thresholding (tau): %.3f", drawPane->cld().tau);
389386
slider_t_t->SetLabel(s);
390387

391-
drawPane->cld.binaryThresholding(drawPane->cld.FDoG, drawPane->cld.result, drawPane->cld.tau);
388+
drawPane->cld().binaryThresholding(drawPane->cld().FDoG, drawPane->cld().result, drawPane->cld().tau);
392389
drawPane->render();
393390
}
394391

@@ -428,38 +425,44 @@ void MyFrame::onIdle(wxIdleEvent &evt)
428425
}
429426
#pragma endregion
430427

431-
#pragma region BasicDrawPane
432-
BasicDrawPane::BasicDrawPane(wxPanel *parent, cv::Size s)
433-
: cld(s)
428+
#pragma region DrawPane
429+
DrawPane::DrawPane(wxPanel *parent, cv::Size s)
430+
: cld_(s)
434431
, wxPanel(parent)
435432
, dc_(wxClientDC(this))
436433
{
437434
}
438435

439436
// Main Render(iteration) Section
440-
void BasicDrawPane::render()
437+
void DrawPane::render()
441438
{
442-
dis = cld.originalImg.clone();
443-
cv::cvtColor(dis, dis, CV_GRAY2BGR);
444-
445-
if (processingS == MODE_ETF) {
446-
dis = postprocess::visualizeETF(cld.etf.flowField);
447-
dis.convertTo(dis, CV_8UC1, 255);
448-
cv::cvtColor(dis, dis, CV_GRAY2BGR);
449-
} else if (processingS == MODE_ETF_DEBUG) {
450-
dis = postprocess::visualizeFlowfield(cld.etf.flowField);
451-
dis.convertTo(dis, CV_8UC3, 255);
452-
cv::cvtColor(dis, dis, CV_RGB2BGR);
453-
} else if (processingS == MODE_CLD) {
454-
dis = cld.result.clone();
455-
cv::cvtColor(dis, dis, CV_GRAY2BGR);
456-
} else if (processingS == MODE_ANTI_ALIASING) {
457-
dis = cld.result.clone();
458-
dis = postprocess::antiAlias(dis);
459-
cv::cvtColor(dis, dis, CV_GRAY2BGR);
439+
dis_ = cld_.originalImg.clone();
440+
cv::cvtColor(dis_, dis_, CV_GRAY2BGR);
441+
442+
if (mode_ == MODE_ETF) {
443+
dis_ = postprocess::visualizeETF(cld_.etf.flowField);
444+
dis_.convertTo(dis_, CV_8UC1, 255);
445+
cv::cvtColor(dis_, dis_, CV_GRAY2BGR);
446+
} else if (mode_ == MODE_ETF_DEBUG) {
447+
dis_ = postprocess::visualizeFlowfield(cld_.etf.flowField);
448+
dis_.convertTo(dis_, CV_8UC3, 255);
449+
cv::cvtColor(dis_, dis_, CV_RGB2BGR);
450+
} else if (mode_ == MODE_CLD) {
451+
dis_ = cld_.result.clone();
452+
cv::cvtColor(dis_, dis_, CV_GRAY2BGR);
453+
} else if (mode_ == MODE_ANTI_ALIASING) {
454+
dis_ = cld_.result.clone();
455+
dis_ = postprocess::antiAlias(dis_);
456+
cv::cvtColor(dis_, dis_, CV_GRAY2BGR);
460457
}
461458

462-
wxBitmap bmp(wxImage(dis.cols, dis.rows, dis.data, true));
459+
wxBitmap bmp(wxImage(dis_.cols, dis_.rows, dis_.data, true));
463460
dc_.DrawBitmap(bmp, 0, 0);
464461
}
462+
463+
CLD &DrawPane::cld() { return cld_; }
464+
465+
cv::Mat &DrawPane::image() { return dis_; }
466+
467+
void DrawPane::set_mode(std::string s) { mode_ = s; }
465468
#pragma endregion

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "include/gui.h"
22

33
// clang-format off
4-
BEGIN_EVENT_TABLE(BasicDrawPane, wxPanel)
4+
BEGIN_EVENT_TABLE(DrawPane, wxPanel)
55

66
END_EVENT_TABLE()
77

0 commit comments

Comments
 (0)